]> git.sur5r.net Git - glabels/blob - glabels2/src/glabels.c
Initial revision
[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 /*
24  * This file is based on gedit2.c from gedit2:
25  *
26  * Copyright (C) 1998, 1999 Alex Roberts, Evan Lawrence
27  * Copyright (C) 2000, 2001 Chema Celorio, Paolo Maggi 
28  *
29  */
30 #include <config.h>
31
32 #include <libgnome/libgnome.h>
33 #include <libgnomeui/libgnomeui.h>
34 #include <libgnomeui/gnome-window-icon.h>
35
36 #include "glabels.h"
37 #include "splash.h"
38 #include "stock.h"
39 #include "merge.h"
40 #include "template.h"
41 #include "mdi.h"
42 #include "prefs.h"
43 #include "file.h"
44 #include "debug.h"
45
46 #ifdef PACKAGE_DATA_DIR
47 #define ICON_PIXMAP (PACKAGE_DATA_DIR "/pixmaps/glabels/glabels-icon.png")
48 #else
49 #define ICON_PIXMAP gnome_pixmap_file("glabels/glabels-icon.png")
50 #endif
51
52 glMDI *glabels_mdi = NULL;
53 gboolean glabels_close_x_button_pressed = FALSE;
54 gboolean glabels_exit_button_pressed = FALSE; 
55
56 static const struct poptOption options [] =
57 {
58         { "debug-view", '\0', POPT_ARG_NONE, &gl_debug_view, 0,
59           N_("Show view debugging messages."), NULL },
60
61         { "debug-item", '\0', POPT_ARG_NONE, &gl_debug_item, 0,
62           N_("Show item debugging messages."), NULL },
63
64         { "debug-print", '\0', POPT_ARG_NONE, &gl_debug_print, 0,
65           N_("Show printing debugging messages."), NULL },
66
67         { "debug-prefs", '\0', POPT_ARG_NONE, &gl_debug_prefs, 0,
68           N_("Show prefs debugging messages."), NULL },
69
70         { "debug-file", '\0', POPT_ARG_NONE, &gl_debug_file, 0,
71           N_("Show file debugging messages."), NULL },
72
73         { "debug-label", '\0', POPT_ARG_NONE, &gl_debug_label, 0,
74           N_("Show document debugging messages."), NULL },
75
76         { "debug-template", '\0', POPT_ARG_NONE, &gl_debug_template, 0,
77           N_("Show template debugging messages."), NULL },
78
79         { "debug-xml", '\0', POPT_ARG_NONE, &gl_debug_xml, 0,
80           N_("Show xml debugging messages."), NULL },
81
82         { "debug-merge", '\0', POPT_ARG_NONE, &gl_debug_merge, 0,
83           N_("Show document merge debugging messages."), NULL },
84
85         { "debug-commands", '\0', POPT_ARG_NONE, &gl_debug_commands, 0,
86           N_("Show commands debugging messages."), NULL },
87
88         { "debug-undo", '\0', POPT_ARG_NONE, &gl_debug_undo, 0,
89           N_("Show undo debugging messages."), NULL },
90
91         { "debug-recent", '\0', POPT_ARG_NONE, &gl_debug_recent, 0,
92           N_("Show recent debugging messages."), NULL },
93
94         { "debug-mdi", '\0', POPT_ARG_NONE, &gl_debug_mdi, 0,
95           N_("Show mdi debugging messages."), NULL },
96
97         { "debug-media-select", '\0', POPT_ARG_NONE, &gl_debug_media_select, 0,
98           N_("Show media select widget debugging messages."), NULL },
99
100         { "debug-mini-preview", '\0', POPT_ARG_NONE, &gl_debug_mini_preview, 0,
101           N_("Show mini preview widget debugging messages."), NULL },
102
103         { "debug-wdgt", '\0', POPT_ARG_NONE, &gl_debug_wdgt, 0,
104           N_("Show widget debugging messages."), NULL },
105
106         { "debug", '\0', POPT_ARG_NONE, &gl_debug_all, 0,
107           N_("Turn on all debugging messages."), NULL },
108
109         {NULL, '\0', 0, NULL, 0}
110 };
111
112
113 int
114 main (int argc, char **argv)
115 {
116         GValue value = { 0, };
117         GnomeProgram *program;
118         poptContext ctx;
119         char **args;
120         GList *file_list = NULL, *p;
121         gint i;
122
123         bindtextdomain (GETTEXT_PACKAGE, GLABELS_LOCALEDIR);
124         bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
125         textdomain (GETTEXT_PACKAGE);
126
127         /* Initialize gnome program */
128         program = gnome_program_init ("glabels", VERSION,
129                             LIBGNOMEUI_MODULE, argc, argv,
130                             GNOME_PARAM_POPT_TABLE, options,
131                             NULL);
132
133         /* Splash screen */
134         gl_splash ();
135
136         gl_stock_init();
137
138         /* Set default icon */
139         if (!g_file_test (ICON_PIXMAP, G_FILE_TEST_EXISTS))
140         {
141                 g_warning ("Could not find %s", ICON_PIXMAP);
142         }
143         else
144         {
145                 gnome_window_icon_set_default_from_file (ICON_PIXMAP);
146         }
147         
148         /* Load user preferences */
149         gl_prefs_init ();
150         gl_prefs_load_settings ();
151
152         gl_template_init();
153         gl_merge_init();
154         gl_merge_ui_init();
155         gl_recent_init();
156
157         /* Parse args and build the list of files to be loaded at startup */
158         g_value_init (&value, G_TYPE_POINTER);
159         g_object_get_property (G_OBJECT (program),
160                                GNOME_PARAM_POPT_CONTEXT, &value);
161         ctx = g_value_get_pointer (&value);
162         g_value_unset (&value);
163         args = (char**) poptGetArgs(ctx);
164         for (i = 0; args && args[i]; i++) 
165         {
166                 file_list = g_list_append (file_list, args[i]);
167         }
168
169         /* Create glabels_mdi and open the first top level window */
170         glabels_mdi = gl_mdi_new ();
171         bonobo_mdi_open_toplevel (BONOBO_MDI (glabels_mdi), NULL); 
172
173         for (p = file_list; p; p = p->next) {
174                 gl_file_open_real (p->data,
175                                    GTK_WINDOW(glabels_get_active_window()));
176         }
177         g_list_free (file_list);
178
179         gtk_main();
180                 
181         return 0;
182 }
183
184
185 BonoboWindow*
186 glabels_get_active_window (void)
187 {
188         g_return_val_if_fail (glabels_mdi != NULL, NULL);
189
190         return  bonobo_mdi_get_active_window (BONOBO_MDI (glabels_mdi));
191 }
192
193 glLabel*
194 glabels_get_active_label (void)
195 {
196         BonoboMDIChild *active_child;
197
198         g_return_val_if_fail (glabels_mdi != NULL, NULL);
199
200         active_child = bonobo_mdi_get_active_child (BONOBO_MDI (glabels_mdi));
201
202         if (active_child == NULL)
203                 return NULL;
204
205         return GL_MDI_CHILD (active_child)->label;
206 }
207
208 glView*
209 glabels_get_active_view (void)
210 {
211         GtkWidget *active_view;
212
213         g_return_val_if_fail (glabels_mdi != NULL, NULL);
214
215         active_view = bonobo_mdi_get_active_view (BONOBO_MDI (glabels_mdi));
216         
217         if (active_view == NULL)
218                 return NULL;
219
220         return GL_VIEW (active_view);
221 }
222
223 GList* 
224 glabels_get_top_windows (void)
225 {
226         g_return_val_if_fail (glabels_mdi != NULL, NULL);
227
228         return  bonobo_mdi_get_windows (BONOBO_MDI (glabels_mdi));
229 }
230