2 * (GLABELS) Label and Business Card Creation program for GNOME
4 * glabels.c: GLabels main module
6 * Copyright (C) 2001-2002 Jim Evins <evins@snaught.com>.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #include <libgnome/libgnome.h>
26 #include <libgnomeui/libgnomeui.h>
27 #include <libgnomeui/gnome-window-icon.h>
37 /*========================================================*/
38 /* Private macros and constants. */
39 /*========================================================*/
40 #define ICON_PIXMAP gnome_program_locate_file (NULL,\
41 GNOME_FILE_DOMAIN_APP_PIXMAP,\
42 "glabels/glabels-icon.png",\
45 /*========================================================*/
47 /*========================================================*/
48 static const struct poptOption options [] =
50 { "debug-view", '\0', POPT_ARG_NONE, &gl_debug_view, 0,
51 N_("Show view debugging messages."), NULL },
53 { "debug-item", '\0', POPT_ARG_NONE, &gl_debug_item, 0,
54 N_("Show item debugging messages."), NULL },
56 { "debug-print", '\0', POPT_ARG_NONE, &gl_debug_print, 0,
57 N_("Show printing debugging messages."), NULL },
59 { "debug-prefs", '\0', POPT_ARG_NONE, &gl_debug_prefs, 0,
60 N_("Show prefs debugging messages."), NULL },
62 { "debug-file", '\0', POPT_ARG_NONE, &gl_debug_file, 0,
63 N_("Show file debugging messages."), NULL },
65 { "debug-label", '\0', POPT_ARG_NONE, &gl_debug_label, 0,
66 N_("Show document debugging messages."), NULL },
68 { "debug-template", '\0', POPT_ARG_NONE, &gl_debug_template, 0,
69 N_("Show template debugging messages."), NULL },
71 { "debug-xml", '\0', POPT_ARG_NONE, &gl_debug_xml, 0,
72 N_("Show xml debugging messages."), NULL },
74 { "debug-merge", '\0', POPT_ARG_NONE, &gl_debug_merge, 0,
75 N_("Show document merge debugging messages."), NULL },
77 { "debug-commands", '\0', POPT_ARG_NONE, &gl_debug_commands, 0,
78 N_("Show commands debugging messages."), NULL },
80 { "debug-undo", '\0', POPT_ARG_NONE, &gl_debug_undo, 0,
81 N_("Show undo debugging messages."), NULL },
83 { "debug-recent", '\0', POPT_ARG_NONE, &gl_debug_recent, 0,
84 N_("Show recent debugging messages."), NULL },
86 { "debug-window", '\0', POPT_ARG_NONE, &gl_debug_window, 0,
87 N_("Show window debugging messages."), NULL },
89 { "debug-ui", '\0', POPT_ARG_NONE, &gl_debug_ui, 0,
90 N_("Show ui debugging messages."), NULL },
92 { "debug-media-select", '\0', POPT_ARG_NONE, &gl_debug_media_select, 0,
93 N_("Show media select widget debugging messages."), NULL },
95 { "debug-mini-preview", '\0', POPT_ARG_NONE, &gl_debug_mini_preview, 0,
96 N_("Show mini preview widget debugging messages."), NULL },
98 { "debug-wdgt", '\0', POPT_ARG_NONE, &gl_debug_wdgt, 0,
99 N_("Show widget debugging messages."), NULL },
101 { "debug", '\0', POPT_ARG_NONE, &gl_debug_all, 0,
102 N_("Turn on all debugging messages."), NULL },
104 {NULL, '\0', 0, NULL, 0}
107 /*========================================================*/
108 /* Local function prototypes */
109 /*========================================================*/
110 gint save_session_cb (GnomeClient *client,
112 GnomeRestartStyle save_style,
114 GnomeInteractStyle interact_style,
116 gpointer client_data);
118 void client_die_cb (GnomeClient *client,
119 gpointer client_data);
121 /****************************************************************************/
123 /****************************************************************************/
125 main (int argc, char **argv)
127 GValue value = { 0, };
128 GnomeProgram *program;
132 GList *file_list = NULL, *p;
136 bindtextdomain (GETTEXT_PACKAGE, GLABELS_LOCALEDIR);
137 bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
138 textdomain (GETTEXT_PACKAGE);
140 /* Initialize gnome program */
141 program = gnome_program_init ("glabels", VERSION,
142 LIBGNOMEUI_MODULE, argc, argv,
143 GNOME_PROGRAM_STANDARD_PROPERTIES,
144 GNOME_PARAM_POPT_TABLE, options,
152 /* Set default icon */
153 if (!g_file_test (ICON_PIXMAP, G_FILE_TEST_EXISTS))
155 g_warning ("Could not find %s", ICON_PIXMAP);
159 gnome_window_icon_set_default_from_file (ICON_PIXMAP);
162 /* Load user preferences */
164 gl_prefs_load_settings ();
171 if (bonobo_ui_init ("glabels", VERSION, &argc, argv) == FALSE) {
172 g_error (_("Could not initialize Bonobo!\n"));
175 client = gnome_master_client();
177 g_signal_connect (G_OBJECT (client), "save_yourself",
178 G_CALLBACK (save_session_cb),
181 g_signal_connect (G_OBJECT (client), "die",
182 G_CALLBACK (client_die_cb), NULL);
184 /* Parse args and build the list of files to be loaded at startup */
185 g_value_init (&value, G_TYPE_POINTER);
186 g_object_get_property (G_OBJECT (program),
187 GNOME_PARAM_POPT_CONTEXT, &value);
188 ctx = g_value_get_pointer (&value);
189 g_value_unset (&value);
190 args = (char**) poptGetArgs(ctx);
191 for (i = 0; args && args[i]; i++)
193 file_list = g_list_append (file_list, args[i]);
196 /* Open files or create empty top-level window. */
197 for (p = file_list; p; p = p->next) {
198 win = gl_window_new_from_file (p->data);
199 gtk_widget_show_all (win);
201 if ( gl_window_get_window_list() == NULL ) {
202 win = gl_window_new ();
203 gtk_widget_show_all (win);
205 g_list_free (file_list);
208 /* Begin main loop */
214 /*---------------------------------------------------------------------------*/
215 /* PRIVATE. "Save session" callback. */
216 /*---------------------------------------------------------------------------*/
217 gint save_session_cb (GnomeClient *client,
219 GnomeRestartStyle save_style,
221 GnomeInteractStyle interact_style,
223 gpointer client_data)
227 const GList *window_list;
232 argv[0] = (gchar *)client_data;
235 window_list = gl_window_get_window_list();
236 for ( p=(GList *)window_list; p != NULL; p=p->next ) {
237 window = GL_WINDOW(p->data);
238 if ( !gl_window_is_empty (window) ) {
239 label = GL_VIEW(window->view)->label;
240 argv[argc++] = gl_label_get_filename (label);
243 gnome_client_set_clone_command(client, argc, argv);
244 gnome_client_set_restart_command(client, argc, argv);
249 /*---------------------------------------------------------------------------*/
250 /* PRIVATE. "Die" callback. */
251 /*---------------------------------------------------------------------------*/
252 void client_die_cb (GnomeClient *client,
253 gpointer client_data)