]> git.sur5r.net Git - glabels/blob - src/glabels.c
Make libglabels parallel installable with other versions
[glabels] / 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.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 "font-history.h"
34 #include "template-history.h"
35 #include "debug.h"
36 #include "window.h"
37 #include "file.h"
38
39
40 /*========================================================*/
41 /* Private macros and constants.                          */
42 /*========================================================*/
43
44
45 /*========================================================*/
46 /* Private globals                                        */
47 /*========================================================*/
48
49
50 /*========================================================*/
51 /* Local function prototypes                              */
52 /*========================================================*/
53
54
55 /****************************************************************************/
56 /* main program                                                             */
57 /****************************************************************************/
58 int
59 main (int argc, char **argv)
60 {
61         gchar **remaining_args = NULL;
62         GOptionEntry option_entries[] = {
63                 { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY,
64                   &remaining_args, NULL, N_("[FILE...]") },
65                 { NULL }
66         };
67
68         GOptionContext *option_context;
69         gchar          *icon_file;
70         GList          *file_list = NULL, *p;
71         GtkWidget      *win;
72         gchar          *utf8_filename;
73         GError         *error = NULL;
74
75         bindtextdomain (GETTEXT_PACKAGE, GLABELS_LOCALEDIR);
76         bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
77         textdomain (GETTEXT_PACKAGE);
78
79         option_context = g_option_context_new (NULL);
80         g_option_context_set_summary (option_context,
81                                       _("Launch gLabels label and business card designer."));
82         g_option_context_add_main_entries (option_context, option_entries, GETTEXT_PACKAGE);
83
84
85         /* Initialize program */
86         gtk_init( &argc, &argv );
87         if (!g_option_context_parse (option_context, &argc, &argv, &error))
88         {
89                 g_print(_("%s\nRun '%s --help' to see a full list of available command line options.\n"),
90                         error->message, argv[0]);
91                 g_error_free (error);
92                 return 1;
93         }
94
95
96         /* Install GUI handlers for critical error and warning messages */
97         gl_critical_error_handler_init();
98         gl_warning_handler_init();
99
100         /* Set default icon */
101         icon_file = GLABELS_ICON_DIR "glabels.png";
102         if (!g_file_test (icon_file, G_FILE_TEST_EXISTS))
103         {
104                 g_message ("Could not find %s", icon_file);
105         }
106         else
107         {
108                 gtk_window_set_default_icon_from_file (icon_file, NULL);
109         }
110
111         
112         /* Initialize subsystems */
113         gl_debug_init ();
114         gl_stock_init ();
115         lgl_db_init ();
116         gl_prefs_init ();
117         gl_mini_preview_pixbuf_cache_init ();
118         gl_merge_init ();
119         gl_recent_init ();
120         gl_template_history_init ();
121         gl_font_history_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
158
159
160 /*
161  * Local Variables:       -- emacs
162  * mode: C                -- emacs
163  * c-basic-offset: 8      -- emacs
164  * tab-width: 8           -- emacs
165  * indent-tabs-mode: nil  -- emacs
166  * End:                   -- emacs
167  */