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/paper.h>
38 #include <libglabels/template.h>
39 #include "mini-preview-pixbuf-cache.h"
45 /*========================================================*/
46 /* Private macros and constants. */
47 /*========================================================*/
49 /*========================================================*/
51 /*========================================================*/
53 /*========================================================*/
54 /* Local function prototypes */
55 /*========================================================*/
56 gboolean save_session_cb (GnomeClient *client,
58 GnomeRestartStyle save_style,
60 GnomeInteractStyle interact_style,
62 gpointer client_data);
64 void client_die_cb (GnomeClient *client,
65 gpointer client_data);
67 /****************************************************************************/
69 /****************************************************************************/
71 main (int argc, char **argv)
73 gchar **remaining_args = NULL;
74 GOptionEntry option_entries[] = {
75 { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY,
76 &remaining_args, NULL, N_("[FILE...]") },
80 GOptionContext *option_context;
81 GnomeProgram *program;
84 GList *file_list = NULL, *p;
88 bindtextdomain (GETTEXT_PACKAGE, GLABELS_LOCALEDIR);
89 bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
90 textdomain (GETTEXT_PACKAGE);
92 option_context = g_option_context_new (_("- gLabels label designer"));
93 g_option_context_add_main_entries (option_context, option_entries, GETTEXT_PACKAGE);
96 /* Initialize gnome program */
97 program = gnome_program_init ("glabels", VERSION,
98 LIBGNOMEUI_MODULE, argc, argv,
99 GNOME_PARAM_GOPTION_CONTEXT, option_context,
100 GNOME_PROGRAM_STANDARD_PROPERTIES,
103 /* Install GUI handlers for critical error and warning messages */
104 gl_critical_error_handler_init();
105 gl_warning_handler_init();
107 /* Set default icon */
108 icon_file = GLABELS_ICON_DIR "glabels.png";
109 if (!g_file_test (icon_file, G_FILE_TEST_EXISTS))
111 g_message ("Could not find %s", icon_file);
115 gnome_window_icon_set_default_from_file (icon_file);
119 /* Initialize subsystems */
125 gl_mini_preview_pixbuf_cache_init ();
130 client = gnome_master_client();
132 g_signal_connect (G_OBJECT (client), "save_yourself",
133 G_CALLBACK (save_session_cb),
136 g_signal_connect (G_OBJECT (client), "die",
137 G_CALLBACK (client_die_cb), NULL);
140 /* Parse args and build the list of files to be loaded at startup */
141 if (remaining_args != NULL) {
144 num_args = g_strv_length (remaining_args);
145 for (i = 0; i < num_args; ++i) {
146 utf8_filename = g_filename_to_utf8 (remaining_args[i], -1, NULL, NULL, NULL);
148 file_list = g_list_append (file_list, utf8_filename);
150 g_strfreev (remaining_args);
151 remaining_args = NULL;
155 /* Open files or create empty top-level window. */
156 for (p = file_list; p; p = p->next) {
157 win = gl_window_new_from_file (p->data);
158 gtk_widget_show_all (win);
161 if ( gl_window_get_window_list() == NULL ) {
162 win = gl_window_new ();
163 gtk_widget_show_all (win);
165 g_list_free (file_list);
168 /* Begin main loop */
171 g_object_unref (G_OBJECT (program));
176 /*---------------------------------------------------------------------------*/
177 /* PRIVATE. "Save session" callback. */
178 /*---------------------------------------------------------------------------*/
179 gboolean save_session_cb (GnomeClient *client,
181 GnomeRestartStyle save_style,
183 GnomeInteractStyle interact_style,
185 gpointer client_data)
189 const GList *window_list;
194 argv[0] = (gchar *)client_data;
197 window_list = gl_window_get_window_list();
198 for ( p=(GList *)window_list; p != NULL; p=p->next ) {
199 window = GL_WINDOW(p->data);
200 if ( !gl_window_is_empty (window) ) {
201 label = GL_VIEW(window->view)->label;
202 argv[argc++] = gl_label_get_filename (label);
205 gnome_client_set_clone_command(client, argc, argv);
206 gnome_client_set_restart_command(client, argc, argv);
211 /*---------------------------------------------------------------------------*/
212 /* PRIVATE. "Die" callback. */
213 /*---------------------------------------------------------------------------*/
214 void client_die_cb (GnomeClient *client,
215 gpointer client_data)