main.c 3.94 KB
Newer Older
1
[+ autogen5 template +]
2
[+INCLUDE (string-append "licenses/" (get "License") ".tpl") \+]
3
4
5
[+INCLUDE (string-append "indent.tpl") \+]
/* [+INVOKE EMACS-MODELINE MODE="C" \+] */
[+INVOKE START-INDENT\+]
6
7
/*
 * main.c
8
 * Copyright (C) [+(shell "date +%Y")+] [+Author+][+IF (get "Email")+] <[+Email+]>[+ENDIF+]
9
 * 
10
11
[+INVOKE LICENSE-DESCRIPTION PFX=" * " PROGRAM=(get "Name") OWNER=(get "Author") \+]
 */
12

13
#include <config.h>
Jean-Noel Guiheneuf's avatar
Jean-Noel Guiheneuf committed
14
#include <gtk/gtk.h>
15
16

[+IF (=(get "HaveI18n") "1")+]
17
#include <glib/gi18n.h>
18
19
[+ENDIF+]

20
[+IF (=(get "HaveBuilderUI") "1")+]
21
typedef struct _Private Private;
22
struct _Private
23
{
24
	/* ANJUTA: Widgets declaration for [+NameHLower+].ui - DO NOT REMOVE */
25
26
};

27
static Private* priv = NULL;
28

29
30
31
/* For testing purpose, define TEST to use the local (not installed) ui file */
#define TEST
#ifdef TEST
32
#define UI_FILE "src/[+NameHLower+].ui"
33
34
35
36
37
38
39
40
41
42
43
#else
[+IF (=(get "HaveWindowsSupport") "1")\+]
#ifdef G_OS_WIN32
#define UI_FILE ui_file
#else
[+ENDIF\+]
#define UI_FILE PACKAGE_DATA_DIR"/ui/[+NameHLower+].ui"
[+IF (=(get "HaveWindowsSupport") "1")\+]
#endif
[+ENDIF\+]
#endif
44
#define TOP_WINDOW "window"
45
46
47
48
49
50
51
52

/* Signal handlers */
/* Note: These may not be declared static because signal autoconnection
 * only works with non-static methods
 */

/* Called when the window is closed */
void
53
on_window_destroy (GtkWidget *widget, gpointer data)
54
55
56
57
58
{
	gtk_main_quit ();
}

static GtkWidget*
59
create_window (void)
60
{
61
62
63
64
65
66
67
[+IF (=(get "HaveWindowsSupport") "1")\+]
#if !defined(TEST) && defined(G_OS_WIN32)
	gchar *prefix = g_win32_get_package_installation_directory_of_module (NULL);
	gchar *datadir = g_build_filename (prefix, "share", PACKAGE, NULL);
	gchar *ui_file = g_build_filename (datadir, "ui", "[+NameHLower+].ui", NULL);
#endif
[+ENDIF\+]
68
	GtkWidget *window;
69
70
71
	GtkBuilder *builder;
	GError* error = NULL;

72
	/* Load UI from file */
73
74
75
	builder = gtk_builder_new ();
	if (!gtk_builder_add_from_file (builder, UI_FILE, &error))
	{
76
		g_critical ("Couldn't load builder file: %s", error->message);
77
78
79
		g_error_free (error);
	}

80
	/* Auto-connect signal handlers */
81
82
	gtk_builder_connect_signals (builder, NULL);

83
	/* Get the window object from the ui file */
84
85
86
87
88
89
90
	window = GTK_WIDGET (gtk_builder_get_object (builder, TOP_WINDOW));
        if (!window)
        {
                g_critical ("Widget \"%s\" is missing in file %s.",
				TOP_WINDOW,
				UI_FILE);
        }
91
92

	priv = g_malloc (sizeof (struct _Private));
93
	/* ANJUTA: Widgets initialization for [+NameHLower+].ui - DO NOT REMOVE */
94

95
	g_object_unref (builder);
96
97
98
99
100
101
102
103

[+IF (=(get "HaveWindowsSupport") "1")+]
#if !defined(TEST) && defined(G_OS_WIN32)
	g_free (prefix);
	g_free (datadir);
	g_free (ui_file);
#endif
[+ENDIF\+]
104
	
105
	return window;
106
107
}[+
ELSE+]
108
109
110
111
112
113
114
115
116
117
118
119
static GtkWidget*
create_window (void)
{
	GtkWidget *window;

	window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
	gtk_window_set_title (GTK_WINDOW (window), "[+Name+]");

	/* Exit when the window is closed */
	g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);
	
	return window;
120
121
}[+
ENDIF+]
122
123
124
125

int
main (int argc, char *argv[])
{
126
 	GtkWidget *window;
Jean-Noel Guiheneuf's avatar
Jean-Noel Guiheneuf committed
127

128
129
130
131
132
133
134
135
[+IF (=(get "HaveI18n") "1")+][+
IF (=(get "HaveWindowsSupport") "1")+]
#ifdef G_OS_WIN32
	gchar *prefix = g_win32_get_package_installation_directory_of_module (NULL);
	gchar *localedir = g_build_filename (prefix, "share", "locale", NULL);
#endif[+
ENDIF+]

136
#ifdef ENABLE_NLS
137
138
[+IF (=(get "HaveWindowsSupport") "1")+]
# ifndef G_OS_WIN32
139
	bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR);
140
141
142
143
144
145
# else
	bindtextdomain (GETTEXT_PACKAGE, localedir);
# endif[+
ELSE+]
	bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR);[+
ENDIF+]
146
147
	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
	textdomain (GETTEXT_PACKAGE);
148
149
#endif[+
ENDIF+]
Jean-Noel Guiheneuf's avatar
Jean-Noel Guiheneuf committed
150
151
	
	gtk_init (&argc, &argv);
Jean-Noel Guiheneuf's avatar
Jean-Noel Guiheneuf committed
152

153
154
	window = create_window ();
	gtk_widget_show (window);
Jean-Noel Guiheneuf's avatar
Jean-Noel Guiheneuf committed
155

156
	gtk_main ();
157

158
[+IF (=(get "HaveBuilderUI") "1")+]
159
160
161
162
163
164
165
166
167
168
169
	g_free (priv);[+
ENDIF+]
[+IF (=(get "HaveI18n") "1")+][+
IF (=(get "HaveWindowsSupport") "1")+]
#ifdef G_OS_WIN32
	g_free (prefix);
	g_free (localedir);
#endif[+
ENDIF+][+
ENDIF+]

170
	return 0;
171
}
172
[+INVOKE END-INDENT\+]