]> git.sur5r.net Git - glabels/blob - glabels2/src/glabels.c
2004-01-06 Jim Evins <evins@snaught.com>
[glabels] / glabels2 / src / glabels.c
1 /*
2  *  (GLABELS) Label and Business Card Creation program for GNOME
3  *
4  *  glabels.c:  GLabels main module
5  *
6  *  Copyright (C) 2001-2002  Jim Evins <evins@snaught.com>.
7  *
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.
12  *
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.
17  *
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
21  */
22
23 #include <config.h>
24
25 #include <libgnome/libgnome.h>
26 #include <libgnomeui/libgnomeui.h>
27 #include <libgnomeui/gnome-window-icon.h>
28
29 #include "splash.h"
30 #include "stock.h"
31 #include "merge-init.h"
32 #include <libglabels/paper.h>
33 #include <libglabels/template.h>
34 #include "prefs.h"
35 #include "debug.h"
36 #include "window.h"
37
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",\
44                                                FALSE, NULL)
45
46 /*========================================================*/
47 /* Private globals                                        */
48 /*========================================================*/
49 static const struct poptOption options [] =
50 {
51         { "debug-view", '\0', POPT_ARG_NONE, &gl_debug_view, 0,
52           N_("Show view debugging messages."), NULL },
53
54         { "debug-item", '\0', POPT_ARG_NONE, &gl_debug_item, 0,
55           N_("Show item debugging messages."), NULL },
56
57         { "debug-print", '\0', POPT_ARG_NONE, &gl_debug_print, 0,
58           N_("Show printing debugging messages."), NULL },
59
60         { "debug-prefs", '\0', POPT_ARG_NONE, &gl_debug_prefs, 0,
61           N_("Show prefs debugging messages."), NULL },
62
63         { "debug-file", '\0', POPT_ARG_NONE, &gl_debug_file, 0,
64           N_("Show file debugging messages."), NULL },
65
66         { "debug-label", '\0', POPT_ARG_NONE, &gl_debug_label, 0,
67           N_("Show document debugging messages."), NULL },
68
69         { "debug-template", '\0', POPT_ARG_NONE, &gl_debug_template, 0,
70           N_("Show template debugging messages."), NULL },
71
72         { "debug-paper", '\0', POPT_ARG_NONE, &gl_debug_paper, 0,
73           N_("Show paper debugging messages."), NULL },
74
75         { "debug-xml", '\0', POPT_ARG_NONE, &gl_debug_xml, 0,
76           N_("Show xml debugging messages."), NULL },
77
78         { "debug-merge", '\0', POPT_ARG_NONE, &gl_debug_merge, 0,
79           N_("Show document merge debugging messages."), NULL },
80
81         { "debug-commands", '\0', POPT_ARG_NONE, &gl_debug_commands, 0,
82           N_("Show commands debugging messages."), NULL },
83
84         { "debug-undo", '\0', POPT_ARG_NONE, &gl_debug_undo, 0,
85           N_("Show undo debugging messages."), NULL },
86
87         { "debug-recent", '\0', POPT_ARG_NONE, &gl_debug_recent, 0,
88           N_("Show recent debugging messages."), NULL },
89
90         { "debug-window", '\0', POPT_ARG_NONE, &gl_debug_window, 0,
91           N_("Show window debugging messages."), NULL },
92
93         { "debug-ui", '\0', POPT_ARG_NONE, &gl_debug_ui, 0,
94           N_("Show ui debugging messages."), NULL },
95
96         { "debug-property-bar", '\0', POPT_ARG_NONE, &gl_debug_property_bar, 0,
97           N_("Show property_bar debugging messages."), NULL },
98
99         { "debug-media-select", '\0', POPT_ARG_NONE, &gl_debug_media_select, 0,
100           N_("Show media select widget debugging messages."), NULL },
101
102         { "debug-mini-preview", '\0', POPT_ARG_NONE, &gl_debug_mini_preview, 0,
103           N_("Show mini preview widget debugging messages."), NULL },
104
105         { "debug-pixbuf-cache", '\0', POPT_ARG_NONE, &gl_debug_pixbuf_cache, 0,
106           N_("Show pixbuf cache debugging messages."), NULL },
107
108         { "debug-editor", '\0', POPT_ARG_NONE, &gl_debug_editor, 0,
109           N_("Show widget debugging messages."), NULL },
110
111         { "debug-wdgt", '\0', POPT_ARG_NONE, &gl_debug_wdgt, 0,
112           N_("Show object editor debugging messages."), NULL },
113
114         { "debug", '\0', POPT_ARG_NONE, &gl_debug_all, 0,
115           N_("Turn on all debugging messages."), NULL },
116
117         {NULL, '\0', 0, NULL, 0}
118 };
119
120 /*========================================================*/
121 /* Local function prototypes                              */
122 /*========================================================*/
123 gint save_session_cb (GnomeClient        *client,
124                       gint                phase,
125                       GnomeRestartStyle   save_style,
126                       gint                shutdown,
127                       GnomeInteractStyle  interact_style,
128                       gint                fast,
129                       gpointer            client_data);
130
131 void client_die_cb   (GnomeClient        *client,
132                       gpointer            client_data);
133
134 /****************************************************************************/
135 /* main program                                                             */
136 /****************************************************************************/
137 int
138 main (int argc, char **argv)
139 {
140         GValue         value = { 0, };
141         GnomeProgram  *program;
142         GnomeClient   *client;
143         poptContext    ctx;
144         char         **args;
145         GList         *file_list = NULL, *p;
146         gint           i;
147         GtkWidget     *win;
148         gchar         *utf8_filename;
149
150         bindtextdomain (GETTEXT_PACKAGE, GLABELS_LOCALEDIR);
151         bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
152         textdomain (GETTEXT_PACKAGE);
153
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,
159                                       NULL);
160
161         /* Splash screen */
162         gl_splash ();
163
164         gl_stock_init();
165
166         /* Set default icon */
167         if (!g_file_test (ICON_PIXMAP, G_FILE_TEST_EXISTS))
168         {
169                 g_warning ("Could not find %s", ICON_PIXMAP);
170         }
171         else
172         {
173                 gnome_window_icon_set_default_from_file (ICON_PIXMAP);
174         }
175         
176         /* Initialize subsystems */
177         gl_paper_init();
178         gl_prefs_init ();
179         gl_template_init();
180         gl_merge_init();
181         gl_recent_init();
182         
183         if (bonobo_ui_init ("glabels", VERSION, &argc, argv) == FALSE) {
184                 g_error (_("Could not initialize Bonobo!\n"));
185         }
186
187         client = gnome_master_client();
188
189         g_signal_connect (G_OBJECT (client), "save_yourself",
190                           G_CALLBACK (save_session_cb),
191                           (gpointer)argv[0]);
192
193         g_signal_connect (G_OBJECT (client), "die",
194                           G_CALLBACK (client_die_cb), NULL);
195
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++) 
204         {
205                 utf8_filename = g_filename_to_utf8 (args[i], -1, NULL, NULL, NULL);
206                 if (utf8_filename)
207                         file_list = g_list_append (file_list, utf8_filename);
208         }
209
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);
214                 g_free (p->data);
215         }
216         if ( gl_window_get_window_list() == NULL ) {
217                 win = gl_window_new ();
218                 gtk_widget_show_all (win);
219         }
220         g_list_free (file_list);
221
222         
223         /* Begin main loop */
224         bonobo_main();
225                 
226         return 0;
227 }
228
229 /*---------------------------------------------------------------------------*/
230 /* PRIVATE.  "Save session" callback.                                        */
231 /*---------------------------------------------------------------------------*/
232 gint save_session_cb (GnomeClient        *client,
233                       gint                phase,
234                       GnomeRestartStyle   save_style,
235                       gint                shutdown,
236                       GnomeInteractStyle  interact_style,
237                       gint                fast,
238                       gpointer            client_data)
239 {
240         gchar       *argv[128];
241         gint         argc;
242         const GList *window_list;
243         GList       *p;
244         glWindow    *window;
245         glLabel     *label;
246
247         argv[0] = (gchar *)client_data;
248         argc = 1;
249
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);
256                 }
257         }
258         gnome_client_set_clone_command(client, argc, argv);
259         gnome_client_set_restart_command(client, argc, argv);
260         
261         return TRUE;
262 }
263
264 /*---------------------------------------------------------------------------*/
265 /* PRIVATE.  "Die" callback.                                                 */
266 /*---------------------------------------------------------------------------*/
267 void client_die_cb (GnomeClient *client,
268                     gpointer     client_data)
269 {
270         gl_file_exit ();
271 }
272
273