]> git.sur5r.net Git - glabels/blob - glabels2/src/glabels.c
New document merge API.
[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 "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_recent_init();
169
170         if (bonobo_ui_init ("glabels", VERSION, &argc, argv) == FALSE) {
171                 g_error (_("Could not initialize Bonobo!\n"));
172         }
173
174         client = gnome_master_client();
175
176         g_signal_connect (G_OBJECT (client), "save_yourself",
177                           G_CALLBACK (save_session_cb),
178                           (gpointer)argv[0]);
179
180         g_signal_connect (G_OBJECT (client), "die",
181                           G_CALLBACK (client_die_cb), NULL);
182
183         /* Parse args and build the list of files to be loaded at startup */
184         g_value_init (&value, G_TYPE_POINTER);
185         g_object_get_property (G_OBJECT (program),
186                                GNOME_PARAM_POPT_CONTEXT, &value);
187         ctx = g_value_get_pointer (&value);
188         g_value_unset (&value);
189         args = (char**) poptGetArgs(ctx);
190         for (i = 0; args && args[i]; i++) 
191         {
192                 file_list = g_list_append (file_list, args[i]);
193         }
194
195         /* Open files or create empty top-level window. */
196         for (p = file_list; p; p = p->next) {
197                 win = gl_window_new_from_file (p->data);
198                 gtk_widget_show_all (win);
199         }
200         if ( gl_window_get_window_list() == NULL ) {
201                 win = gl_window_new ();
202                 gtk_widget_show_all (win);
203         }
204         g_list_free (file_list);
205
206         
207         /* Begin main loop */
208         bonobo_main();
209                 
210         return 0;
211 }
212
213 /*---------------------------------------------------------------------------*/
214 /* PRIVATE.  "Save session" callback.                                        */
215 /*---------------------------------------------------------------------------*/
216 gint save_session_cb (GnomeClient        *client,
217                       gint                phase,
218                       GnomeRestartStyle   save_style,
219                       gint                shutdown,
220                       GnomeInteractStyle  interact_style,
221                       gint                fast,
222                       gpointer            client_data)
223 {
224         gchar       *argv[128];
225         gint         argc;
226         const GList *window_list;
227         GList       *p;
228         glWindow    *window;
229         glLabel     *label;
230
231         argv[0] = (gchar *)client_data;
232         argc = 1;
233
234         window_list = gl_window_get_window_list();
235         for ( p=(GList *)window_list; p != NULL; p=p->next ) {
236                 window = GL_WINDOW(p->data);
237                 if ( !gl_window_is_empty (window) ) {
238                         label = GL_VIEW(window->view)->label;
239                         argv[argc++] = gl_label_get_filename (label);
240                 }
241         }
242         gnome_client_set_clone_command(client, argc, argv);
243         gnome_client_set_restart_command(client, argc, argv);
244         
245         return TRUE;
246 }
247
248 /*---------------------------------------------------------------------------*/
249 /* PRIVATE.  "Die" callback.                                                 */
250 /*---------------------------------------------------------------------------*/
251 void client_die_cb (GnomeClient *client,
252                     gpointer     client_data)
253 {
254         gl_file_exit ();
255 }
256
257