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>
31 #include "merge-init.h"
32 #include <libglabels/paper.h>
33 #include <libglabels/template.h>
38 /*========================================================*/
39 /* Private macros and constants. */
40 /*========================================================*/
41 #define ICON_PIXMAP gnome_program_locate_file (NULL,\
42 GNOME_FILE_DOMAIN_APP_PIXMAP,\
43 "glabels/glabels-icon.png",\
46 /*========================================================*/
48 /*========================================================*/
49 static const struct poptOption options [] =
51 { "debug-view", '\0', POPT_ARG_NONE, &gl_debug_view, 0,
52 N_("Show view debugging messages."), NULL },
54 { "debug-item", '\0', POPT_ARG_NONE, &gl_debug_item, 0,
55 N_("Show item debugging messages."), NULL },
57 { "debug-print", '\0', POPT_ARG_NONE, &gl_debug_print, 0,
58 N_("Show printing debugging messages."), NULL },
60 { "debug-prefs", '\0', POPT_ARG_NONE, &gl_debug_prefs, 0,
61 N_("Show prefs debugging messages."), NULL },
63 { "debug-file", '\0', POPT_ARG_NONE, &gl_debug_file, 0,
64 N_("Show file debugging messages."), NULL },
66 { "debug-label", '\0', POPT_ARG_NONE, &gl_debug_label, 0,
67 N_("Show document debugging messages."), NULL },
69 { "debug-template", '\0', POPT_ARG_NONE, &gl_debug_template, 0,
70 N_("Show template debugging messages."), NULL },
72 { "debug-paper", '\0', POPT_ARG_NONE, &gl_debug_paper, 0,
73 N_("Show paper debugging messages."), NULL },
75 { "debug-xml", '\0', POPT_ARG_NONE, &gl_debug_xml, 0,
76 N_("Show xml debugging messages."), NULL },
78 { "debug-merge", '\0', POPT_ARG_NONE, &gl_debug_merge, 0,
79 N_("Show document merge debugging messages."), NULL },
81 { "debug-commands", '\0', POPT_ARG_NONE, &gl_debug_commands, 0,
82 N_("Show commands debugging messages."), NULL },
84 { "debug-undo", '\0', POPT_ARG_NONE, &gl_debug_undo, 0,
85 N_("Show undo debugging messages."), NULL },
87 { "debug-recent", '\0', POPT_ARG_NONE, &gl_debug_recent, 0,
88 N_("Show recent debugging messages."), NULL },
90 { "debug-window", '\0', POPT_ARG_NONE, &gl_debug_window, 0,
91 N_("Show window debugging messages."), NULL },
93 { "debug-ui", '\0', POPT_ARG_NONE, &gl_debug_ui, 0,
94 N_("Show ui debugging messages."), NULL },
96 { "debug-property-bar", '\0', POPT_ARG_NONE, &gl_debug_property_bar, 0,
97 N_("Show property_bar debugging messages."), NULL },
99 { "debug-media-select", '\0', POPT_ARG_NONE, &gl_debug_media_select, 0,
100 N_("Show media select widget debugging messages."), NULL },
102 { "debug-mini-preview", '\0', POPT_ARG_NONE, &gl_debug_mini_preview, 0,
103 N_("Show mini preview widget debugging messages."), NULL },
105 { "debug-pixbuf-cache", '\0', POPT_ARG_NONE, &gl_debug_pixbuf_cache, 0,
106 N_("Show pixbuf cache debugging messages."), NULL },
108 { "debug-editor", '\0', POPT_ARG_NONE, &gl_debug_editor, 0,
109 N_("Show widget debugging messages."), NULL },
111 { "debug-wdgt", '\0', POPT_ARG_NONE, &gl_debug_wdgt, 0,
112 N_("Show object editor debugging messages."), NULL },
114 { "debug", '\0', POPT_ARG_NONE, &gl_debug_all, 0,
115 N_("Turn on all debugging messages."), NULL },
117 {NULL, '\0', 0, NULL, 0}
120 /*========================================================*/
121 /* Local function prototypes */
122 /*========================================================*/
123 gint save_session_cb (GnomeClient *client,
125 GnomeRestartStyle save_style,
127 GnomeInteractStyle interact_style,
129 gpointer client_data);
131 void client_die_cb (GnomeClient *client,
132 gpointer client_data);
134 /****************************************************************************/
136 /****************************************************************************/
138 main (int argc, char **argv)
140 GValue value = { 0, };
141 GnomeProgram *program;
145 GList *file_list = NULL, *p;
148 gchar *utf8_filename;
150 bindtextdomain (GETTEXT_PACKAGE, GLABELS_LOCALEDIR);
151 bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
152 textdomain (GETTEXT_PACKAGE);
154 /* Initialize gnome program */
155 program = gnome_program_init ("glabels", VERSION,
156 LIBGNOMEUI_MODULE, argc, argv,
157 GNOME_PROGRAM_STANDARD_PROPERTIES,
158 GNOME_PARAM_POPT_TABLE, options,
166 /* Set default icon */
167 if (!g_file_test (ICON_PIXMAP, G_FILE_TEST_EXISTS))
169 g_warning ("Could not find %s", ICON_PIXMAP);
173 gnome_window_icon_set_default_from_file (ICON_PIXMAP);
176 /* Initialize subsystems */
183 if (bonobo_ui_init ("glabels", VERSION, &argc, argv) == FALSE) {
184 g_error (_("Could not initialize Bonobo!\n"));
187 client = gnome_master_client();
189 g_signal_connect (G_OBJECT (client), "save_yourself",
190 G_CALLBACK (save_session_cb),
193 g_signal_connect (G_OBJECT (client), "die",
194 G_CALLBACK (client_die_cb), NULL);
196 /* Parse args and build the list of files to be loaded at startup */
197 g_value_init (&value, G_TYPE_POINTER);
198 g_object_get_property (G_OBJECT (program),
199 GNOME_PARAM_POPT_CONTEXT, &value);
200 ctx = g_value_get_pointer (&value);
201 g_value_unset (&value);
202 args = (char**) poptGetArgs(ctx);
203 for (i = 0; args && args[i]; i++)
205 utf8_filename = g_filename_to_utf8 (args[i], -1, NULL, NULL, NULL);
207 file_list = g_list_append (file_list, utf8_filename);
210 /* Open files or create empty top-level window. */
211 for (p = file_list; p; p = p->next) {
212 win = gl_window_new_from_file (p->data);
213 gtk_widget_show_all (win);
216 if ( gl_window_get_window_list() == NULL ) {
217 win = gl_window_new ();
218 gtk_widget_show_all (win);
220 g_list_free (file_list);
223 /* Begin main loop */
229 /*---------------------------------------------------------------------------*/
230 /* PRIVATE. "Save session" callback. */
231 /*---------------------------------------------------------------------------*/
232 gint save_session_cb (GnomeClient *client,
234 GnomeRestartStyle save_style,
236 GnomeInteractStyle interact_style,
238 gpointer client_data)
242 const GList *window_list;
247 argv[0] = (gchar *)client_data;
250 window_list = gl_window_get_window_list();
251 for ( p=(GList *)window_list; p != NULL; p=p->next ) {
252 window = GL_WINDOW(p->data);
253 if ( !gl_window_is_empty (window) ) {
254 label = GL_VIEW(window->view)->label;
255 argv[argc++] = gl_label_get_filename (label);
258 gnome_client_set_clone_command(client, argc, argv);
259 gnome_client_set_restart_command(client, argc, argv);
264 /*---------------------------------------------------------------------------*/
265 /* PRIVATE. "Die" callback. */
266 /*---------------------------------------------------------------------------*/
267 void client_die_cb (GnomeClient *client,
268 gpointer client_data)