]> git.sur5r.net Git - glabels/blob - glabels1/src/glabels.c
6e68fb9fc03e093ddaf3dd123888090f5a98f5ed
[glabels] / glabels1 / src / glabels.c
1 /*
2  *  (GLABELS) Label and Business Card Creation program for GNOME
3  *
4  *  glabels.c: main program module
5  *
6  *  Copyright (C) 2001  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 <gnome.h>
26 #include <libgnomeui/gnome-window-icon.h>
27
28 #include "splash.h"
29 #include "stock.h"
30 #include "merge.h"
31 #include "merge_ui.h"
32 #include "mdi.h"
33 #include "template.h"
34 #include "debug.h"
35
36 #ifdef PACKAGE_DATA_DIR
37 #define ICON_PIXMAP (PACKAGE_DATA_DIR "/pixmaps/glabels/glabels-icon.png")
38 #else
39 #define ICON_PIXMAP gnome_pixmap_file("glabels/glabels-icon.png")
40 #endif
41
42 /*============================================*/
43 /* Private globals                            */
44 /*============================================*/
45 static struct poptOption options[] = {
46         {NULL, '\0', 0, NULL, 0, NULL, NULL}
47 };
48
49 /*============================================*/
50 /* Private function prototypes                */
51 /*============================================*/
52 static void session_die (GnomeClient * client,
53                          gpointer client_data);
54 static gint save_session (GnomeClient * client,
55                           gint phase,
56                           GnomeSaveStyle save_style,
57                           gint is_shutdown,
58                           GnomeInteractStyle interact_style,
59                           gint is_fast,
60                           gpointer client_data);
61
62 \f
63 /*****************************************************************************/
64 /* Main                                       */
65 /*****************************************************************************/
66 int
67 main (int argc,
68       char *argv[])
69 {
70         poptContext pctx;
71         gchar **args;
72         GnomeMDI *mdi;
73         GnomeClient *client;
74         GSList *p, *file_list = NULL;
75         gint i, opened;
76
77         bindtextdomain (PACKAGE, PACKAGE_LOCALE_DIR);
78         textdomain (PACKAGE);
79
80         gnome_init_with_popt_table (PACKAGE, VERSION,
81                                     argc, argv, options, 0, &pctx);
82
83         /* Splash screen */
84         gl_splash ();
85
86         if (!g_file_exists (ICON_PIXMAP)) {
87                 WARN ("Could not find %s", ICON_PIXMAP);
88         }
89         gnome_window_icon_set_default_from_file (ICON_PIXMAP);
90
91         /* argument parsing */
92         args = (char **) poptGetArgs (pctx);
93         for (i = 0; args && args[i]; i++) {
94                 file_list = g_slist_append (file_list, args[i]);
95         }
96         poptFreeContext (pctx);
97
98         /* session management */
99         client = gnome_master_client ();
100         gtk_signal_connect (GTK_OBJECT (client), "save_yourself",
101                             GTK_SIGNAL_FUNC (save_session), argv[0]);
102         gtk_signal_connect (GTK_OBJECT (client), "die",
103                             GTK_SIGNAL_FUNC (session_die), NULL);
104
105         gl_stock_init ();
106         gl_merge_init ();
107         gl_merge_ui_init ();
108         gl_template_init ();
109
110         mdi = gl_mdi_init ();
111
112         /* Any files on command line? */
113         opened = 0;
114         for (p = file_list; p; p = p->next) {
115                 if (gl_mdi_new_child_from_xml_file (p->data))
116                         opened++;
117         }
118         g_slist_free (file_list);
119
120         if (!opened) {
121                 gnome_mdi_open_toplevel (mdi);
122         }
123
124         /* Now start main loop */
125         gtk_main ();
126
127         return 0;
128 }
129
130 /*---------------------------------------------------------------------------*/
131 /* PRIVATE.  Save Session signal callback.                                   */
132 /*---------------------------------------------------------------------------*/
133 static gint
134 save_session (GnomeClient * client,
135               gint phase,
136               GnomeSaveStyle save_style,
137               gint is_shutdown,
138               GnomeInteractStyle interact_style,
139               gint is_fast,
140               gpointer client_data)
141 {
142         gchar **argv;
143         guint argc;
144
145         argv = g_malloc0 (4 * sizeof (gchar *));
146         argc = 1;
147
148         argv[0] = client_data;
149
150         gnome_client_set_clone_command (client, argc, argv);
151         gnome_client_set_restart_command (client, argc, argv);
152
153         return TRUE;
154 }
155
156 /*---------------------------------------------------------------------------*/
157 /* PRIVATE.  Session Die signal callback.                                    */
158 /*---------------------------------------------------------------------------*/
159 static void
160 session_die (GnomeClient * client,
161              gpointer client_data)
162 {
163         gtk_main_quit ();
164 }