]> git.sur5r.net Git - glabels/blob - glabels2/src/glabels.c
3bac82f758b78ee1236def71e5691269760c43a7
[glabels] / glabels2 / src / glabels.c
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
2
3 /**
4  *  (GLABELS) Label and Business Card Creation program for GNOME
5  *
6  *  glabels.c:  GLabels main module
7  *
8  *  Copyright (C) 2001-2002  Jim Evins <evins@snaught.com>.
9  *
10  *  This program is free software; you can redistribute it and/or modify
11  *  it under the terms of the GNU General Public License as published by
12  *  the Free Software Foundation; either version 2 of the License, or
13  *  (at your option) any later version.
14  *
15  *  This program is distributed in the hope that it will be useful,
16  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  *  GNU General Public License for more details.
19  *
20  *  You should have received a copy of the GNU General Public License
21  *  along with this program; if not, write to the Free Software
22  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
23  */
24
25 #include <config.h>
26
27 #include <glib/gi18n.h>
28
29 #include "warning-handler.h"
30 #include "critical-error-handler.h"
31 #include "stock.h"
32 #include "merge-init.h"
33 #include "recent.h"
34 #include <libglabels/db.h>
35 #include "mini-preview-pixbuf-cache.h"
36 #include "prefs.h"
37 #include "debug.h"
38 #include "window.h"
39 #include "file.h"
40
41
42 /*========================================================*/
43 /* Private macros and constants.                          */
44 /*========================================================*/
45
46
47 /*========================================================*/
48 /* Private globals                                        */
49 /*========================================================*/
50
51
52 /*========================================================*/
53 /* Local function prototypes                              */
54 /*========================================================*/
55
56
57 /****************************************************************************/
58 /* main program                                                             */
59 /****************************************************************************/
60 int
61 main (int argc, char **argv)
62 {
63         gchar **remaining_args = NULL;
64         GOptionEntry option_entries[] = {
65                 { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY,
66                   &remaining_args, NULL, N_("[FILE...]") },
67                 { NULL }
68         };
69
70         GOptionContext *option_context;
71         gchar          *icon_file;
72         GList          *file_list = NULL, *p;
73         GtkWidget      *win;
74         gchar          *utf8_filename;
75         GError         *error = NULL;
76
77         bindtextdomain (GETTEXT_PACKAGE, GLABELS_LOCALEDIR);
78         bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
79         textdomain (GETTEXT_PACKAGE);
80
81         option_context = g_option_context_new (NULL);
82         g_option_context_set_summary (option_context,
83                                       _("Launch gLabels label and business card designer."));
84         g_option_context_add_main_entries (option_context, option_entries, GETTEXT_PACKAGE);
85
86
87         /* Initialize program */
88         gtk_init( &argc, &argv );
89         if (!g_option_context_parse (option_context, &argc, &argv, &error))
90         {
91                 g_print(_("%s\nRun '%s --help' to see a full list of available command line options.\n"),
92                         error->message, argv[0]);
93                 g_error_free (error);
94                 return 1;
95         }
96
97
98         /* Install GUI handlers for critical error and warning messages */
99         gl_critical_error_handler_init();
100         gl_warning_handler_init();
101
102         /* Set default icon */
103         icon_file = GLABELS_ICON_DIR "glabels.png";
104         if (!g_file_test (icon_file, G_FILE_TEST_EXISTS))
105         {
106                 g_message ("Could not find %s", icon_file);
107         }
108         else
109         {
110                 gtk_window_set_default_icon_from_file (icon_file, NULL);
111         }
112
113         
114         /* Initialize subsystems */
115         gl_debug_init ();
116         gl_stock_init ();
117         lgl_db_init ();
118         gl_prefs_init ();
119         gl_mini_preview_pixbuf_cache_init ();
120         gl_merge_init ();
121         gl_recent_init ();
122         
123
124         /* Parse args and build the list of files to be loaded at startup */
125         if (remaining_args != NULL) {
126                 gint i, num_args;
127
128                 num_args = g_strv_length (remaining_args);
129                 for (i = 0; i < num_args; ++i) {
130                         utf8_filename = g_filename_to_utf8 (remaining_args[i], -1, NULL, NULL, NULL);
131                         if (utf8_filename)
132                                 file_list = g_list_append (file_list, utf8_filename);
133                 }
134                 g_strfreev (remaining_args);
135                 remaining_args = NULL;
136         }
137
138
139         /* Open files or create empty top-level window. */
140         for (p = file_list; p; p = p->next) {
141                 win = gl_window_new_from_file (p->data);
142                 gtk_widget_show_all (win);
143                 g_free (p->data);
144         }
145         if ( gl_window_get_window_list() == NULL ) {
146                 win = gl_window_new ();
147                 gtk_widget_show_all (win);
148         }
149         g_list_free (file_list);
150
151         
152         /* Begin main loop */
153         gtk_main();
154
155         return 0;
156 }
157