1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
4 * (GLABELS) Label and Business Card Creation program for GNOME
6 * glabels.c: GLabels main module
8 * Copyright (C) 2001-2002 Jim Evins <evins@snaught.com>.
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.
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.
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
27 #include <glib/gi18n.h>
28 #include <libgnome/libgnome.h>
29 #include <libgnomeui/libgnomeui.h>
30 #include <libgnomeui/gnome-window-icon.h>
32 #include "warning-handler.h"
33 #include "critical-error-handler.h"
35 #include "merge-init.h"
37 #include <libglabels/db.h>
38 #include "mini-preview-pixbuf-cache.h"
44 /*========================================================*/
45 /* Private macros and constants. */
46 /*========================================================*/
48 /*========================================================*/
50 /*========================================================*/
52 /*========================================================*/
53 /* Local function prototypes */
54 /*========================================================*/
55 gboolean save_session_cb (GnomeClient *client,
57 GnomeRestartStyle save_style,
59 GnomeInteractStyle interact_style,
61 gpointer client_data);
63 void client_die_cb (GnomeClient *client,
64 gpointer client_data);
66 /****************************************************************************/
68 /****************************************************************************/
70 main (int argc, char **argv)
72 gchar **remaining_args = NULL;
73 GOptionEntry option_entries[] = {
74 { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY,
75 &remaining_args, NULL, N_("[FILE...]") },
79 GOptionContext *option_context;
80 GnomeProgram *program;
83 GList *file_list = NULL, *p;
87 bindtextdomain (GETTEXT_PACKAGE, GLABELS_LOCALEDIR);
88 bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
89 textdomain (GETTEXT_PACKAGE);
91 option_context = g_option_context_new (_("- gLabels label designer"));
92 g_option_context_add_main_entries (option_context, option_entries, GETTEXT_PACKAGE);
95 /* Initialize gnome program */
96 program = gnome_program_init ("glabels", VERSION,
97 LIBGNOMEUI_MODULE, argc, argv,
98 GNOME_PARAM_GOPTION_CONTEXT, option_context,
99 GNOME_PROGRAM_STANDARD_PROPERTIES,
102 /* Install GUI handlers for critical error and warning messages */
103 gl_critical_error_handler_init();
104 gl_warning_handler_init();
106 /* Set default icon */
107 icon_file = GLABELS_ICON_DIR "glabels.png";
108 if (!g_file_test (icon_file, G_FILE_TEST_EXISTS))
110 g_message ("Could not find %s", icon_file);
114 gnome_window_icon_set_default_from_file (icon_file);
118 /* Initialize subsystems */
123 gl_mini_preview_pixbuf_cache_init ();
128 client = gnome_master_client();
130 g_signal_connect (G_OBJECT (client), "save_yourself",
131 G_CALLBACK (save_session_cb),
134 g_signal_connect (G_OBJECT (client), "die",
135 G_CALLBACK (client_die_cb), NULL);
138 /* Parse args and build the list of files to be loaded at startup */
139 if (remaining_args != NULL) {
142 num_args = g_strv_length (remaining_args);
143 for (i = 0; i < num_args; ++i) {
144 utf8_filename = g_filename_to_utf8 (remaining_args[i], -1, NULL, NULL, NULL);
146 file_list = g_list_append (file_list, utf8_filename);
148 g_strfreev (remaining_args);
149 remaining_args = NULL;
153 /* Open files or create empty top-level window. */
154 for (p = file_list; p; p = p->next) {
155 win = gl_window_new_from_file (p->data);
156 gtk_widget_show_all (win);
159 if ( gl_window_get_window_list() == NULL ) {
160 win = gl_window_new ();
161 gtk_widget_show_all (win);
163 g_list_free (file_list);
166 /* Begin main loop */
169 g_object_unref (G_OBJECT (program));
174 /*---------------------------------------------------------------------------*/
175 /* PRIVATE. "Save session" callback. */
176 /*---------------------------------------------------------------------------*/
177 gboolean save_session_cb (GnomeClient *client,
179 GnomeRestartStyle save_style,
181 GnomeInteractStyle interact_style,
183 gpointer client_data)
187 const GList *window_list;
192 argv[0] = (gchar *)client_data;
195 window_list = gl_window_get_window_list();
196 for ( p=(GList *)window_list; p != NULL; p=p->next ) {
197 window = GL_WINDOW(p->data);
198 if ( !gl_window_is_empty (window) ) {
199 label = GL_VIEW(window->view)->label;
200 argv[argc++] = gl_label_get_filename (label);
203 gnome_client_set_clone_command(client, argc, argv);
204 gnome_client_set_restart_command(client, argc, argv);
209 /*---------------------------------------------------------------------------*/
210 /* PRIVATE. "Die" callback. */
211 /*---------------------------------------------------------------------------*/
212 void client_die_cb (GnomeClient *client,
213 gpointer client_data)