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