]> git.sur5r.net Git - glabels/blob - glabels2/src/glabels.c
bc25158c90a43e759bfe168a98308b9d59d3887c
[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.h"
32 #include "template.h"
33 #include "prefs.h"
34 #include "debug.h"
35 #include "window.h"
36
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",\
43                                                FALSE, NULL)
44
45 /*========================================================*/
46 /* Private globals                                        */
47 /*========================================================*/
48 static const struct poptOption options [] =
49 {
50         { "debug-view", '\0', POPT_ARG_NONE, &gl_debug_view, 0,
51           N_("Show view debugging messages."), NULL },
52
53         { "debug-item", '\0', POPT_ARG_NONE, &gl_debug_item, 0,
54           N_("Show item debugging messages."), NULL },
55
56         { "debug-print", '\0', POPT_ARG_NONE, &gl_debug_print, 0,
57           N_("Show printing debugging messages."), NULL },
58
59         { "debug-prefs", '\0', POPT_ARG_NONE, &gl_debug_prefs, 0,
60           N_("Show prefs debugging messages."), NULL },
61
62         { "debug-file", '\0', POPT_ARG_NONE, &gl_debug_file, 0,
63           N_("Show file debugging messages."), NULL },
64
65         { "debug-label", '\0', POPT_ARG_NONE, &gl_debug_label, 0,
66           N_("Show document debugging messages."), NULL },
67
68         { "debug-template", '\0', POPT_ARG_NONE, &gl_debug_template, 0,
69           N_("Show template debugging messages."), NULL },
70
71         { "debug-xml", '\0', POPT_ARG_NONE, &gl_debug_xml, 0,
72           N_("Show xml debugging messages."), NULL },
73
74         { "debug-merge", '\0', POPT_ARG_NONE, &gl_debug_merge, 0,
75           N_("Show document merge debugging messages."), NULL },
76
77         { "debug-commands", '\0', POPT_ARG_NONE, &gl_debug_commands, 0,
78           N_("Show commands debugging messages."), NULL },
79
80         { "debug-undo", '\0', POPT_ARG_NONE, &gl_debug_undo, 0,
81           N_("Show undo debugging messages."), NULL },
82
83         { "debug-recent", '\0', POPT_ARG_NONE, &gl_debug_recent, 0,
84           N_("Show recent debugging messages."), NULL },
85
86         { "debug-window", '\0', POPT_ARG_NONE, &gl_debug_window, 0,
87           N_("Show window debugging messages."), NULL },
88
89         { "debug-ui", '\0', POPT_ARG_NONE, &gl_debug_ui, 0,
90           N_("Show ui debugging messages."), NULL },
91
92         { "debug-media-select", '\0', POPT_ARG_NONE, &gl_debug_media_select, 0,
93           N_("Show media select widget debugging messages."), NULL },
94
95         { "debug-mini-preview", '\0', POPT_ARG_NONE, &gl_debug_mini_preview, 0,
96           N_("Show mini preview widget debugging messages."), NULL },
97
98         { "debug-wdgt", '\0', POPT_ARG_NONE, &gl_debug_wdgt, 0,
99           N_("Show widget debugging messages."), NULL },
100
101         { "debug", '\0', POPT_ARG_NONE, &gl_debug_all, 0,
102           N_("Turn on all debugging messages."), NULL },
103
104         {NULL, '\0', 0, NULL, 0}
105 };
106
107 /*========================================================*/
108 /* Local function prototypes                              */
109 /*========================================================*/
110 gint save_session_cb (GnomeClient        *client,
111                       gint                phase,
112                       GnomeRestartStyle   save_style,
113                       gint                shutdown,
114                       GnomeInteractStyle  interact_style,
115                       gint                fast,
116                       gpointer            client_data);
117
118 void client_die_cb   (GnomeClient        *client,
119                       gpointer            client_data);
120
121 /****************************************************************************/
122 /* main program                                                             */
123 /****************************************************************************/
124 int
125 main (int argc, char **argv)
126 {
127         GValue         value = { 0, };
128         GnomeProgram  *program;
129         GnomeClient   *client;
130         poptContext    ctx;
131         char         **args;
132         GList         *file_list = NULL, *p;
133         gint           i;
134         GtkWidget     *win;
135
136         bindtextdomain (GETTEXT_PACKAGE, GLABELS_LOCALEDIR);
137         bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
138         textdomain (GETTEXT_PACKAGE);
139
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,
145                                       NULL);
146
147         /* Splash screen */
148         gl_splash ();
149
150         gl_stock_init();
151
152         /* Set default icon */
153         if (!g_file_test (ICON_PIXMAP, G_FILE_TEST_EXISTS))
154         {
155                 g_warning ("Could not find %s", ICON_PIXMAP);
156         }
157         else
158         {
159                 gnome_window_icon_set_default_from_file (ICON_PIXMAP);
160         }
161         
162         /* Load user preferences */
163         gl_prefs_init ();
164         gl_prefs_load_settings ();
165
166         gl_template_init();
167         gl_merge_init();
168         gl_merge_ui_init();
169         gl_recent_init();
170
171         if (bonobo_ui_init ("glabels", VERSION, &argc, argv) == FALSE) {
172                 g_error (_("Could not initialize Bonobo!\n"));
173         }
174
175         client = gnome_master_client();
176
177         g_signal_connect (G_OBJECT (client), "save_yourself",
178                           G_CALLBACK (save_session_cb),
179                           (gpointer)argv[0]);
180
181         g_signal_connect (G_OBJECT (client), "die",
182                           G_CALLBACK (client_die_cb), NULL);
183
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++) 
192         {
193                 file_list = g_list_append (file_list, args[i]);
194         }
195
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);
200         }
201         if ( gl_window_get_window_list() == NULL ) {
202                 win = gl_window_new ();
203                 gtk_widget_show_all (win);
204         }
205         g_list_free (file_list);
206
207         
208         /* Begin main loop */
209         bonobo_main();
210                 
211         return 0;
212 }
213
214 /*---------------------------------------------------------------------------*/
215 /* PRIVATE.  "Save session" callback.                                        */
216 /*---------------------------------------------------------------------------*/
217 gint save_session_cb (GnomeClient        *client,
218                       gint                phase,
219                       GnomeRestartStyle   save_style,
220                       gint                shutdown,
221                       GnomeInteractStyle  interact_style,
222                       gint                fast,
223                       gpointer            client_data)
224 {
225         gchar       *argv[128];
226         gint         argc;
227         const GList *window_list;
228         GList       *p;
229         glWindow    *window;
230         glLabel     *label;
231
232         argv[0] = (gchar *)client_data;
233         argc = 1;
234
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);
241                 }
242         }
243         gnome_client_set_clone_command(client, argc, argv);
244         gnome_client_set_restart_command(client, argc, argv);
245         
246         return TRUE;
247 }
248
249 /*---------------------------------------------------------------------------*/
250 /* PRIVATE.  "Die" callback.                                                 */
251 /*---------------------------------------------------------------------------*/
252 void client_die_cb (GnomeClient *client,
253                     gpointer     client_data)
254 {
255         gl_file_exit ();
256 }
257
258