1 /* Dia -- an diagram creation/manipulation program
2 * Copyright (C) 1998 Alexander Larsson
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 #include <sys/types.h>
39 #if (defined (HAVE_LIBPOPT) && defined (HAVE_POPT_H)) || defined (GNOME)
55 #define mkdir(s,a) _mkdir(s)
59 #include "app_procs.h"
63 #include "modify_tool.h"
64 #include "interface.h"
68 #include "layer_dialog.h"
69 #include "load_save.h"
70 #include "preferences.h"
72 #include "render_eps.h"
75 #include "recent_files.h"
77 #if defined(HAVE_LIBPNG) && defined(HAVE_LIBART)
78 extern DiaExportFilter png_export_filter
;
81 static void create_user_dirs(void);
82 static PluginInitResult
internal_plugin_init(PluginInfo
*info
);
87 session_die (gpointer client_data
)
93 save_state (GnomeClient
*client
,
95 GnomeRestartStyle save_style
,
97 GnomeInteractStyle interact_style
,
108 for(l
= open_diagrams
; l
!= NULL
; l
= g_list_next(l
)) {
109 dia
= (Diagram
*)l
->data
;
111 argv
[i
++] = dia
->filename
;
115 gnome_client_set_restart_command (client
, i
, argv
);
116 gnome_client_set_clone_command (client
, i
, argv
);
125 /* Break here. All symbols are loaded. */
129 app_init (int argc
, char **argv
)
131 Diagram
*diagram
= NULL
;
132 DDisplay
*ddisp
= NULL
;
133 gboolean nosplash
= FALSE
;
137 char *in_file_name
= NULL
;
138 char *export_file_name
= NULL
;
143 poptContext poptCtx
= NULL
;
144 struct poptOption options
[] =
146 {"export", 'e', POPT_ARG_STRING
, &export_file_name
, 0,
147 N_("Export loaded file and exit"), N_("OUTPUT")},
148 {"nosplash", 0, POPT_ARG_NONE
, &nosplash
, 0,
149 N_("Don't show the splash screen"), NULL
},
151 {"help", 'h', POPT_ARG_NONE
, 0, 1, N_("Show this help message") },
153 {(char *) NULL
, '\0', 0, NULL
, 0}
158 setlocale(LC_NUMERIC
, "C");
160 bindtextdomain(PACKAGE
, LOCALEDIR
);
165 gnome_init_with_popt_table(PACKAGE
, VERSION
, argc
, argv
, options
,
168 client
= gnome_master_client();
170 g_warning(_("Can't connect to session manager!\n"));
173 gtk_signal_connect(GTK_OBJECT (client
), "save_yourself",
174 GTK_SIGNAL_FUNC (save_state
), NULL
);
175 gtk_signal_connect(GTK_OBJECT (client
), "die",
176 GTK_SIGNAL_FUNC (session_die
), NULL
);
180 poptCtx
= poptGetContext(PACKAGE
, argc
, (const char **)argv
, options
, 0);
181 poptSetOtherOptionHelp(poptCtx
, _("[OPTION...] [FILE...]"));
182 if((rc
= poptGetNextOpt(poptCtx
)) < -1) {
184 _("Error on option %s: %s.\nRun '%s --help' to see a full list of available command line options.\n"),
185 poptBadOption(poptCtx
, 0),
191 poptPrintHelp(poptCtx
, stderr
, 0);
195 gtk_init (&argc
, &argv
);
199 #if defined(LIBXML_VERSION) && LIBXML_VERSION >= 20000
200 xmlKeepBlanksDefault(0);
207 gtk_rc_parse ("diagtkrc");
211 /* enable_core_dumps(); */
220 default_cursor
= gdk_cursor_new(GDK_LEFT_PTR
);
221 ddisplay_set_all_cursor(default_cursor
);
223 object_registry_init();
225 dia_register_plugins();
226 dia_register_builtin_plugin(internal_plugin_init
);
228 load_all_sheets(); /* new mechanism */
232 if (object_get_type("Standard - Box") == NULL
) {
233 message_error(_("Couldn't find standard objects when looking for "
234 "object-libs, exiting...\n"));
235 fprintf(stderr
, _("Couldn't find standard objects when looking for "
236 "object-libs, exiting...\n"));
242 create_layer_dialog();
244 /* further initialization *before* reading files */
245 active_tool
= create_modify_tool();
249 /*fill recent file menu */
250 recent_file_history_init();
254 while (poptPeekArg(poptCtx
)) {
255 in_file_name
= (char *)poptGetArg(poptCtx
);
256 diagram
= diagram_load (in_file_name
, NULL
);
257 if (export_file_name
) {
260 fprintf (stderr
, _("Need valid input file\n"));
263 ef
= filter_guess_export_filter(export_file_name
);
265 ef
= &eps_export_filter
;
266 ef
->export(diagram
->data
, export_file_name
, in_file_name
, ef
->user_data
);
269 if (diagram
!= NULL
) {
270 diagram_update_extents(diagram
);
271 ddisp
= new_display(diagram
);
274 poptFreeContext(poptCtx
);
277 for (i
=1; i
<argc
; i
++) {
281 diagram
= diagram_load(argv
[i
], NULL
);
283 if (diagram
!= NULL
) {
284 diagram_update_extents(diagram
);
285 layer_dialog_set_diagram(diagram
);
287 ddisp
= new_display(diagram
);
289 /* Error messages are done in diagram_load() */
296 set_true_callback(GtkWidget
*w
, int *data
)
308 if (diagram_modified_exists()) {
318 dialog
= gnome_dialog_new(_("Quit, are you sure?"), NULL
);
319 vbox
= GNOME_DIALOG(dialog
)->vbox
;
320 gnome_dialog_set_close(GNOME_DIALOG(dialog
), TRUE
);
322 dialog
= gtk_dialog_new();
323 vbox
= GTK_DIALOG(dialog
)->vbox
;
324 gtk_window_set_title (GTK_WINDOW (dialog
), _("Quit, are you sure?"));
325 gtk_container_set_border_width (GTK_CONTAINER (dialog
), 0);
328 gtk_signal_connect (GTK_OBJECT (dialog
), "destroy",
329 GTK_SIGNAL_FUNC(gtk_main_quit
), NULL
);
331 label
= gtk_label_new (_("Modified diagrams exists.\n"
332 "Are you sure you want to quit?"));
334 gtk_misc_set_padding (GTK_MISC (label
), 10, 10);
335 gtk_box_pack_start (GTK_BOX (vbox
), label
, TRUE
, TRUE
, 0);
337 gtk_widget_show (label
);
340 gnome_dialog_append_button_with_pixmap(GNOME_DIALOG(dialog
),
341 _("Quit"), GNOME_STOCK_PIXMAP_QUIT
);
342 gnome_dialog_append_button(GNOME_DIALOG(dialog
),GNOME_STOCK_BUTTON_CANCEL
);
344 result
= (gnome_dialog_run(GNOME_DIALOG(dialog
)) == 0);
346 button
= gtk_button_new_with_label (_("Quit"));
347 GTK_WIDGET_SET_FLAGS (button
, GTK_CAN_DEFAULT
);
348 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog
)->action_area
),
349 button
, TRUE
, TRUE
, 0);
350 gtk_signal_connect (GTK_OBJECT (button
), "clicked",
351 GTK_SIGNAL_FUNC(set_true_callback
),
353 gtk_signal_connect_object (GTK_OBJECT (button
), "clicked",
354 GTK_SIGNAL_FUNC (gtk_widget_destroy
),
355 GTK_OBJECT (dialog
));
356 gtk_widget_show (button
);
358 button
= gtk_button_new_with_label (_("Cancel"));
359 GTK_WIDGET_SET_FLAGS (button
, GTK_CAN_DEFAULT
);
360 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog
)->action_area
),
361 button
, TRUE
, TRUE
, 0);
362 gtk_widget_grab_default (button
);
363 gtk_signal_connect_object (GTK_OBJECT (button
), "clicked",
364 GTK_SIGNAL_FUNC (gtk_widget_destroy
),
365 GTK_OBJECT (dialog
));
367 gtk_widget_show (button
);
369 gtk_widget_show (dialog
);
371 /* Make dialog modal: */
372 gtk_widget_grab_focus(dialog
);
373 gtk_grab_add(dialog
);
382 /* Save menu accelerators */
383 filename
= dia_config_filename("menus" G_DIR_SEPARATOR_S
"toolbox");
384 if (filename
!=NULL
) {
385 GtkPatternSpec pattern
;
387 gtk_pattern_spec_init(&pattern
, "*<Toolbox>*");
389 gtk_item_factory_dump_rc (filename
, &pattern
, TRUE
);
391 gtk_pattern_spec_free_segs(&pattern
);
394 /* Free loads of stuff (toolbox) */
396 list
= open_diagrams
;
398 Diagram
*dia
= (Diagram
*)list
->data
;
399 list
= g_list_next(list
);
401 slist
= dia
->displays
;
402 while (slist
!=NULL
) {
403 DDisplay
*ddisp
= (DDisplay
*)slist
->data
;
404 slist
= g_slist_next(slist
);
406 gtk_widget_destroy(ddisp
->shell
);
409 /* The diagram is freed when the last display is destroyed */
414 dia_pluginrc_write();
416 /* save recent file history */
417 recent_file_history_write();
422 static void create_user_dirs(void)
427 /* not necessary to quit the program with g_error, everywhere else
428 * dia_config_filename appears to be used. Spit out a warning ...
430 if (!g_get_home_dir())
432 g_warning(_("Could not create per-user Dia config directory"));
433 return; /* ... and return. Probably removes my one and only FAQ. --HB */
436 dir
= g_strconcat(g_get_home_dir(), G_DIR_SEPARATOR_S
".dia", NULL
);
437 if (mkdir(dir
, 0755) && errno
!= EEXIST
)
438 g_error(_("Could not create per-user Dia config directory"));
440 /* it is no big deal if these directories can't be created */
441 subdir
= g_strconcat(dir
, G_DIR_SEPARATOR_S
"objects", NULL
);
444 subdir
= g_strconcat(dir
, G_DIR_SEPARATOR_S
"shapes", NULL
);
447 subdir
= g_strconcat(dir
, G_DIR_SEPARATOR_S
"sheets", NULL
);
454 static PluginInitResult
455 internal_plugin_init(PluginInfo
*info
)
457 if (!dia_plugin_info_init(info
, "Internal",
458 _("Objects and filters internal to dia"),
460 return DIA_PLUGIN_INIT_ERROR
;
462 /* register the group object type */
463 object_register_type(&group_type
);
465 /* register import filters */
466 filter_register_import(&dia_import_filter
);
468 /* register export filters */
469 filter_register_export(&dia_export_filter
);
470 filter_register_export(&eps_export_filter
);
471 #if defined(HAVE_LIBPNG) && defined(HAVE_LIBART)
472 filter_register_export(&png_export_filter
);
475 return DIA_PLUGIN_INIT_OK
;