49b92394e48cb83ce6d0b1e06f1fb893c3b9cb79
1 /** @file
2 * @brief Legacy interface to main application
3 */
4 /* Authors:
5 * Lauris Kaplinski <lauris@kaplinski.com>
6 * bulia byak <buliabyak@users.sf.net>
7 *
8 * Copyright (C) 1999-2005 authors
9 * g++ port Copyright (C) 2003 Nathan Hurst
10 *
11 * Released under GNU GPL, read the file 'COPYING' for more information
12 */
14 #ifdef HAVE_CONFIG_H
15 # include "config.h"
16 #endif
19 #include <map>
20 #include "debug/simple-event.h"
21 #include "debug/event-tracker.h"
23 #ifndef WIN32
24 # define HAS_PROC_SELF_EXE //to get path of executable
25 #else
27 // For now to get at is_os_wide().
28 # include "extension/internal/win32.h"
29 using Inkscape::Extension::Internal::PrintWin32;
31 #define _WIN32_IE 0x0400
32 //#define HAS_SHGetSpecialFolderPath
33 #define HAS_SHGetSpecialFolderLocation
34 #define HAS_GetModuleFileName
35 # include <shlobj.h>
36 #endif
38 #include <cstring>
39 #include <glib/gstdio.h>
40 #include <glib.h>
41 #include <glibmm/i18n.h>
42 #include <gtk/gtkmain.h>
43 #include <gtk/gtkmessagedialog.h>
44 #include <signal.h>
45 #include <string>
46 #include "application/application.h"
47 #include "application/editor.h"
48 #include "desktop.h"
49 #include "desktop-handles.h"
50 #include "dialogs/input.h"
51 #include "document.h"
52 #include "event-context.h"
53 #include "extension/db.h"
54 #include "extension/init.h"
55 #include "extension/output.h"
56 #include "extension/system.h"
57 #include "helper/sp-marshal.h"
58 #include "inkscape-private.h"
59 #include "io/sys.h"
60 #include "message-stack.h"
61 #include "preferences.h"
62 #include "selection.h"
63 #include "ui/dialog/debug.h"
64 #include "xml/repr.h"
66 static Inkscape::Application *inkscape = NULL;
68 /* Backbones of configuration xml data */
69 #include "menus-skeleton.h"
71 enum {
72 MODIFY_SELECTION, // global: one of selections modified
73 CHANGE_SELECTION, // global: one of selections changed
74 CHANGE_SUBSELECTION, // global: one of subselections (text selection, gradient handle, etc) changed
75 SET_SELECTION, // global: one of selections set
76 SET_EVENTCONTEXT, // tool switched
77 ACTIVATE_DESKTOP, // some desktop got focus
78 DEACTIVATE_DESKTOP, // some desktop lost focus
79 SHUTDOWN_SIGNAL, // inkscape is quitting
80 DIALOGS_HIDE, // user pressed F12
81 DIALOGS_UNHIDE, // user pressed F12
82 EXTERNAL_CHANGE, // a document was changed by some external means (undo or XML editor); this
83 // may not be reflected by a selection change and thus needs a separate signal
84 LAST_SIGNAL
85 };
87 #define DESKTOP_IS_ACTIVE(d) ((d) == inkscape->desktops->data)
90 /*################################
91 # FORWARD DECLARATIONS
92 ################################*/
94 gboolean inkscape_app_use_gui( Inkscape::Application const * app );
96 static void inkscape_class_init (Inkscape::ApplicationClass *klass);
97 static void inkscape_init (SPObject *object);
98 static void inkscape_dispose (GObject *object);
100 static void inkscape_activate_desktop_private (Inkscape::Application *inkscape, SPDesktop *desktop);
101 static void inkscape_deactivate_desktop_private (Inkscape::Application *inkscape, SPDesktop *desktop);
103 struct Inkscape::Application {
104 GObject object;
105 Inkscape::XML::Document *menus;
106 std::map<SPDocument *, int> document_set;
107 GSList *desktops;
108 gchar *argv0;
109 gboolean dialogs_toggle;
110 gboolean use_gui; // may want to consider a virtual function
111 // for overriding things like the warning dlg's
112 guint mapalt;
113 };
115 struct Inkscape::ApplicationClass {
116 GObjectClass object_class;
118 /* Signals */
119 void (* change_selection) (Inkscape::Application * inkscape, Inkscape::Selection * selection);
120 void (* change_subselection) (Inkscape::Application * inkscape, SPDesktop *desktop);
121 void (* modify_selection) (Inkscape::Application * inkscape, Inkscape::Selection * selection, guint flags);
122 void (* set_selection) (Inkscape::Application * inkscape, Inkscape::Selection * selection);
123 void (* set_eventcontext) (Inkscape::Application * inkscape, SPEventContext * eventcontext);
124 void (* activate_desktop) (Inkscape::Application * inkscape, SPDesktop * desktop);
125 void (* deactivate_desktop) (Inkscape::Application * inkscape, SPDesktop * desktop);
126 void (* destroy_document) (Inkscape::Application *inkscape, SPDocument *doc);
127 void (* color_set) (Inkscape::Application *inkscape, SPColor *color, double opacity);
128 void (* shut_down) (Inkscape::Application *inkscape);
129 void (* dialogs_hide) (Inkscape::Application *inkscape);
130 void (* dialogs_unhide) (Inkscape::Application *inkscape);
131 void (* external_change) (Inkscape::Application *inkscape);
132 };
134 static GObjectClass * parent_class;
135 static guint inkscape_signals[LAST_SIGNAL] = {0};
137 static void (* segv_handler) (int) = SIG_DFL;
138 static void (* abrt_handler) (int) = SIG_DFL;
139 static void (* fpe_handler) (int) = SIG_DFL;
140 static void (* ill_handler) (int) = SIG_DFL;
141 static void (* bus_handler) (int) = SIG_DFL;
143 #define INKSCAPE_PROFILE_DIR "Inkscape"
144 #define INKSCAPE_LEGACY_PROFILE_DIR ".inkscape"
145 #define MENUS_FILE "menus.xml"
148 /**
149 * Retrieves the GType for the Inkscape Application object.
150 */
151 GType
152 inkscape_get_type (void)
153 {
154 static GType type = 0;
155 if (!type) {
156 GTypeInfo info = {
157 sizeof (Inkscape::ApplicationClass),
158 NULL, NULL,
159 (GClassInitFunc) inkscape_class_init,
160 NULL, NULL,
161 sizeof (Inkscape::Application),
162 4,
163 (GInstanceInitFunc) inkscape_init,
164 NULL
165 };
166 type = g_type_register_static (G_TYPE_OBJECT, "Inkscape_Application", &info, (GTypeFlags)0);
167 }
168 return type;
169 }
172 /**
173 * Initializes the inkscape class, registering all of its signal handlers
174 * and virtual functions
175 */
176 static void
177 inkscape_class_init (Inkscape::ApplicationClass * klass)
178 {
179 GObjectClass * object_class;
181 object_class = (GObjectClass *) klass;
183 parent_class = (GObjectClass *)g_type_class_peek_parent (klass);
185 inkscape_signals[MODIFY_SELECTION] = g_signal_new ("modify_selection",
186 G_TYPE_FROM_CLASS (klass),
187 G_SIGNAL_RUN_FIRST,
188 G_STRUCT_OFFSET (Inkscape::ApplicationClass, modify_selection),
189 NULL, NULL,
190 sp_marshal_NONE__POINTER_UINT,
191 G_TYPE_NONE, 2,
192 G_TYPE_POINTER, G_TYPE_UINT);
193 inkscape_signals[CHANGE_SELECTION] = g_signal_new ("change_selection",
194 G_TYPE_FROM_CLASS (klass),
195 G_SIGNAL_RUN_FIRST,
196 G_STRUCT_OFFSET (Inkscape::ApplicationClass, change_selection),
197 NULL, NULL,
198 sp_marshal_NONE__POINTER,
199 G_TYPE_NONE, 1,
200 G_TYPE_POINTER);
201 inkscape_signals[CHANGE_SUBSELECTION] = g_signal_new ("change_subselection",
202 G_TYPE_FROM_CLASS (klass),
203 G_SIGNAL_RUN_FIRST,
204 G_STRUCT_OFFSET (Inkscape::ApplicationClass, change_subselection),
205 NULL, NULL,
206 sp_marshal_NONE__POINTER,
207 G_TYPE_NONE, 1,
208 G_TYPE_POINTER);
209 inkscape_signals[SET_SELECTION] = g_signal_new ("set_selection",
210 G_TYPE_FROM_CLASS (klass),
211 G_SIGNAL_RUN_FIRST,
212 G_STRUCT_OFFSET (Inkscape::ApplicationClass, set_selection),
213 NULL, NULL,
214 sp_marshal_NONE__POINTER,
215 G_TYPE_NONE, 1,
216 G_TYPE_POINTER);
217 inkscape_signals[SET_EVENTCONTEXT] = g_signal_new ("set_eventcontext",
218 G_TYPE_FROM_CLASS (klass),
219 G_SIGNAL_RUN_FIRST,
220 G_STRUCT_OFFSET (Inkscape::ApplicationClass, set_eventcontext),
221 NULL, NULL,
222 sp_marshal_NONE__POINTER,
223 G_TYPE_NONE, 1,
224 G_TYPE_POINTER);
225 inkscape_signals[ACTIVATE_DESKTOP] = g_signal_new ("activate_desktop",
226 G_TYPE_FROM_CLASS (klass),
227 G_SIGNAL_RUN_FIRST,
228 G_STRUCT_OFFSET (Inkscape::ApplicationClass, activate_desktop),
229 NULL, NULL,
230 sp_marshal_NONE__POINTER,
231 G_TYPE_NONE, 1,
232 G_TYPE_POINTER);
233 inkscape_signals[DEACTIVATE_DESKTOP] = g_signal_new ("deactivate_desktop",
234 G_TYPE_FROM_CLASS (klass),
235 G_SIGNAL_RUN_FIRST,
236 G_STRUCT_OFFSET (Inkscape::ApplicationClass, deactivate_desktop),
237 NULL, NULL,
238 sp_marshal_NONE__POINTER,
239 G_TYPE_NONE, 1,
240 G_TYPE_POINTER);
241 inkscape_signals[SHUTDOWN_SIGNAL] = g_signal_new ("shut_down",
242 G_TYPE_FROM_CLASS (klass),
243 G_SIGNAL_RUN_FIRST,
244 G_STRUCT_OFFSET (Inkscape::ApplicationClass, shut_down),
245 NULL, NULL,
246 g_cclosure_marshal_VOID__VOID,
247 G_TYPE_NONE, 0);
248 inkscape_signals[DIALOGS_HIDE] = g_signal_new ("dialogs_hide",
249 G_TYPE_FROM_CLASS (klass),
250 G_SIGNAL_RUN_FIRST,
251 G_STRUCT_OFFSET (Inkscape::ApplicationClass, dialogs_hide),
252 NULL, NULL,
253 g_cclosure_marshal_VOID__VOID,
254 G_TYPE_NONE, 0);
255 inkscape_signals[DIALOGS_UNHIDE] = g_signal_new ("dialogs_unhide",
256 G_TYPE_FROM_CLASS (klass),
257 G_SIGNAL_RUN_FIRST,
258 G_STRUCT_OFFSET (Inkscape::ApplicationClass, dialogs_unhide),
259 NULL, NULL,
260 g_cclosure_marshal_VOID__VOID,
261 G_TYPE_NONE, 0);
262 inkscape_signals[EXTERNAL_CHANGE] = g_signal_new ("external_change",
263 G_TYPE_FROM_CLASS (klass),
264 G_SIGNAL_RUN_FIRST,
265 G_STRUCT_OFFSET (Inkscape::ApplicationClass, external_change),
266 NULL, NULL,
267 g_cclosure_marshal_VOID__VOID,
268 G_TYPE_NONE, 0);
270 object_class->dispose = inkscape_dispose;
272 klass->activate_desktop = inkscape_activate_desktop_private;
273 klass->deactivate_desktop = inkscape_deactivate_desktop_private;
274 }
276 #ifdef WIN32
277 typedef int uid_t;
278 #define getuid() 0
279 #endif
281 /**
282 * static gint inkscape_autosave(gpointer);
283 *
284 * Callback passed to g_timeout_add_seconds()
285 * Responsible for autosaving all open documents
286 */
287 static gint inkscape_autosave(gpointer)
288 {
289 if (inkscape->document_set.empty()) { // nothing to autosave
290 return TRUE;
291 }
292 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
294 // Use UID for separating autosave-documents between users if directory is multiuser
295 uid_t uid = getuid();
297 Glib::ustring autosave_dir;
298 {
299 Glib::ustring tmp = prefs->getString("/options/autosave/path");
300 if (!tmp.empty()) {
301 autosave_dir = tmp;
302 } else {
303 autosave_dir = Glib::get_tmp_dir();
304 }
305 }
307 GDir *autosave_dir_ptr = g_dir_open(autosave_dir.c_str(), 0, NULL);
308 if( !autosave_dir_ptr ){
309 g_warning("Cannot open autosave directory!");
310 return TRUE;
311 }
313 time_t sptime = time(NULL);
314 struct tm *sptm = localtime(&sptime);
315 gchar sptstr[256];
316 strftime(sptstr, 256, "%Y_%m_%d_%H_%M_%S", sptm);
318 gint autosave_max = prefs->getInt("/options/autosave/max", 10);
320 gint docnum = 0;
322 SP_ACTIVE_DESKTOP->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Autosaving documents..."));
323 for (std::map<SPDocument*,int>::iterator iter = inkscape->document_set.begin();
324 iter != inkscape->document_set.end();
325 ++iter) {
327 SPDocument *doc = iter->first;
329 ++docnum;
331 Inkscape::XML::Node *repr = sp_document_repr_root(doc);
332 // g_debug("Document %d: \"%s\" %s", docnum, doc ? doc->name : "(null)", doc ? (doc->isModifiedSinceSave() ? "(dirty)" : "(clean)") : "(null)");
334 if (doc->isModifiedSinceSave()) {
335 gchar *oldest_autosave = 0;
336 const gchar *filename = 0;
337 struct stat sb;
338 time_t min_time = 0;
339 gint count = 0;
341 // Look for previous autosaves
342 gchar* baseName = g_strdup_printf( "inkscape-autosave-%d", uid );
343 g_dir_rewind(autosave_dir_ptr);
344 while( (filename = g_dir_read_name(autosave_dir_ptr)) != NULL ){
345 if ( strncmp(filename, baseName, strlen(baseName)) == 0 ){
346 gchar* full_path = g_build_filename( autosave_dir.c_str(), filename, NULL );
347 if ( g_stat(full_path, &sb) != -1 ) {
348 if ( difftime(sb.st_ctime, min_time) < 0 || min_time == 0 ){
349 min_time = sb.st_ctime;
350 if ( oldest_autosave ) {
351 g_free(oldest_autosave);
352 }
353 oldest_autosave = g_strdup(full_path);
354 }
355 count ++;
356 }
357 g_free(full_path);
358 }
359 }
361 // g_debug("%d previous autosaves exists. Max = %d", count, autosave_max);
363 // Have we reached the limit for number of autosaves?
364 if ( count >= autosave_max ){
365 // Remove the oldest file
366 if ( oldest_autosave ) {
367 unlink(oldest_autosave);
368 }
369 }
371 if ( oldest_autosave ) {
372 g_free(oldest_autosave);
373 oldest_autosave = 0;
374 }
377 // Set the filename we will actually save to
378 g_free(baseName);
379 baseName = g_strdup_printf("inkscape-autosave-%d-%s-%03d.svg", uid, sptstr, docnum);
380 gchar* full_path = g_build_filename(autosave_dir.c_str(), baseName, NULL);
381 g_free(baseName);
382 baseName = 0;
384 // g_debug("Filename: %s", full_path);
386 // Try to save the file
387 FILE *file = Inkscape::IO::fopen_utf8name(full_path, "w");
388 gchar *errortext = 0;
389 if (file) {
390 try{
391 sp_repr_save_stream(repr->document(), file, SP_SVG_NS_URI);
392 } catch (Inkscape::Extension::Output::no_extension_found &e) {
393 errortext = g_strdup(_("Autosave failed! Could not find inkscape extension to save document."));
394 } catch (Inkscape::Extension::Output::save_failed &e) {
395 gchar *safeUri = Inkscape::IO::sanitizeString(full_path);
396 errortext = g_strdup_printf(_("Autosave failed! File %s could not be saved."), safeUri);
397 g_free(safeUri);
398 }
399 fclose(file);
400 }
401 else {
402 gchar *safeUri = Inkscape::IO::sanitizeString(full_path);
403 errortext = g_strdup_printf(_("Autosave failed! File %s could not be saved."), safeUri);
404 g_free(safeUri);
405 }
407 if (errortext) {
408 SP_ACTIVE_DESKTOP->messageStack()->flash(Inkscape::ERROR_MESSAGE, errortext);
409 g_warning("%s", errortext);
410 g_free(errortext);
411 }
413 g_free(full_path);
414 }
415 }
416 g_dir_close(autosave_dir_ptr);
418 SP_ACTIVE_DESKTOP->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Autosave complete."));
420 return TRUE;
421 }
423 void inkscape_autosave_init()
424 {
425 static guint32 autosave_timeout_id = 0;
426 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
428 // Turn off any previously initiated timeouts
429 if ( autosave_timeout_id ) {
430 g_source_remove(autosave_timeout_id);
431 autosave_timeout_id = 0;
432 }
434 // g_debug("options.autosave.enable = %d", prefs->getBool("/options/autosave/enable", true));
435 // Is autosave enabled?
436 if (!prefs->getBool("/options/autosave/enable", true)){
437 autosave_timeout_id = 0;
438 } else {
439 // Turn on autosave
440 guint32 timeout = prefs->getInt("/options/autosave/interval", 10) * 60;
441 // g_debug("options.autosave.interval = %d", prefs->getInt("/options/autosave/interval", 10));
442 #if GLIB_CHECK_VERSION(2,14,0)
443 autosave_timeout_id = g_timeout_add_seconds(timeout, inkscape_autosave, NULL);
444 #else
445 autosave_timeout_id = g_timeout_add(timeout * 1000, inkscape_autosave, NULL);
446 #endif
447 }
448 }
451 static void
452 inkscape_init (SPObject * object)
453 {
454 if (!inkscape) {
455 inkscape = (Inkscape::Application *) object;
456 } else {
457 g_assert_not_reached ();
458 }
460 new (&inkscape->document_set) std::map<SPDocument *, int>();
462 inkscape->menus = sp_repr_read_mem (_(menus_skeleton), MENUS_SKELETON_SIZE, NULL);
464 inkscape->desktops = NULL;
466 inkscape->dialogs_toggle = TRUE;
468 inkscape->mapalt=GDK_MOD1_MASK;
469 }
471 static void
472 inkscape_dispose (GObject *object)
473 {
474 Inkscape::Application *inkscape = (Inkscape::Application *) object;
476 g_assert (!inkscape->desktops);
478 Inkscape::Preferences::unload();
480 if (inkscape->menus) {
481 /* fixme: This is not the best place */
482 Inkscape::GC::release(inkscape->menus);
483 inkscape->menus = NULL;
484 }
486 inkscape->document_set.~map();
488 G_OBJECT_CLASS (parent_class)->dispose (object);
490 gtk_main_quit ();
491 }
494 void
495 inkscape_ref (void)
496 {
497 if (inkscape)
498 g_object_ref (G_OBJECT (inkscape));
499 }
502 void
503 inkscape_unref (void)
504 {
505 if (inkscape)
506 g_object_unref (G_OBJECT (inkscape));
507 }
509 /* returns the mask of the keyboard modifier to map to Alt, zero if no mapping */
510 /* Needs to be a guint because gdktypes.h does not define a 'no-modifier' value */
511 guint
512 inkscape_mapalt() {
513 return inkscape->mapalt;
514 }
516 /* Sets the keyboard modifer to map to Alt. Zero switches off mapping, as does '1', which is the default */
517 void inkscape_mapalt(guint maskvalue)
518 {
519 if(maskvalue<2 || maskvalue> 5 ){ /* MOD5 is the highest defined in gdktypes.h */
520 inkscape->mapalt=0;
521 }else{
522 inkscape->mapalt=(GDK_MOD1_MASK << (maskvalue-1));
523 }
524 }
526 static void
527 inkscape_activate_desktop_private (Inkscape::Application */*inkscape*/, SPDesktop *desktop)
528 {
529 desktop->set_active (true);
530 }
533 static void
534 inkscape_deactivate_desktop_private (Inkscape::Application */*inkscape*/, SPDesktop *desktop)
535 {
536 desktop->set_active (false);
537 }
540 /* fixme: This is EVIL, and belongs to main after all */
542 #define SP_INDENT 8
545 static void
546 inkscape_crash_handler (int /*signum*/)
547 {
548 using Inkscape::Debug::SimpleEvent;
549 using Inkscape::Debug::EventTracker;
550 using Inkscape::Debug::Logger;
552 static gint recursion = FALSE;
554 /*
555 * reset all signal handlers: any further crashes should just be allowed
556 * to crash normally.
557 * */
558 signal (SIGSEGV, segv_handler );
559 signal (SIGABRT, abrt_handler );
560 signal (SIGFPE, fpe_handler );
561 signal (SIGILL, ill_handler );
562 #ifndef WIN32
563 signal (SIGBUS, bus_handler );
564 #endif
566 /* Stop bizarre loops */
567 if (recursion) {
568 abort ();
569 }
570 recursion = TRUE;
572 EventTracker<SimpleEvent<Inkscape::Debug::Event::CORE> > tracker("crash");
573 tracker.set<SimpleEvent<> >("emergency-save");
575 fprintf(stderr, "\nEmergency save activated!\n");
577 time_t sptime = time (NULL);
578 struct tm *sptm = localtime (&sptime);
579 gchar sptstr[256];
580 strftime (sptstr, 256, "%Y_%m_%d_%H_%M_%S", sptm);
582 gint count = 0;
583 GSList *savednames = NULL;
584 GSList *failednames = NULL;
585 for (std::map<SPDocument*,int>::iterator iter = inkscape->document_set.begin();
586 iter != inkscape->document_set.end();
587 ++iter) {
588 SPDocument *doc = iter->first;
589 Inkscape::XML::Node *repr;
590 repr = sp_document_repr_root (doc);
591 if (doc->isModifiedSinceSave()) {
592 const gchar *docname, *d0, *d;
593 gchar n[64], c[1024];
594 FILE *file;
596 /* originally, the document name was retrieved from
597 * the sodipod:docname attribute */
598 docname = doc->name;
599 if (docname) {
600 /* fixme: Quick hack to remove emergency file suffix */
601 d0 = strrchr ((char*)docname, '.');
602 if (d0 && (d0 > docname)) {
603 d0 = strrchr ((char*)(d0 - 1), '.');
604 if (d0 && (d0 > docname)) {
605 d = d0;
606 while (isdigit (*d) || (*d == '.') || (*d == '_')) d += 1;
607 if (*d) {
608 memcpy (n, docname, MIN (d0 - docname - 1, 64));
609 n[63] = '\0';
610 docname = n;
611 }
612 }
613 }
614 }
616 if (!docname || !*docname) docname = "emergency";
617 // try saving to the profile location
618 g_snprintf (c, 1024, "%.256s.%s.%d.svg", docname, sptstr, count);
619 gchar * location = homedir_path(c);
620 Inkscape::IO::dump_fopen_call(location, "E");
621 file = Inkscape::IO::fopen_utf8name(location, "w");
622 g_free(location);
623 if (!file) {
624 // try saving to /tmp
625 g_snprintf (c, 1024, "/tmp/inkscape-%.256s.%s.%d.svg", docname, sptstr, count);
626 Inkscape::IO::dump_fopen_call(c, "G");
627 file = Inkscape::IO::fopen_utf8name(c, "w");
628 }
629 if (!file) {
630 // try saving to the current directory
631 g_snprintf (c, 1024, "inkscape-%.256s.%s.%d.svg", docname, sptstr, count);
632 Inkscape::IO::dump_fopen_call(c, "F");
633 file = Inkscape::IO::fopen_utf8name(c, "w");
634 }
635 if (file) {
636 sp_repr_save_stream (repr->document(), file, SP_SVG_NS_URI);
637 savednames = g_slist_prepend (savednames, g_strdup (c));
638 fclose (file);
639 } else {
640 failednames = g_slist_prepend (failednames, (doc->name) ? g_strdup (doc->name) : g_strdup (_("Untitled document")));
641 }
642 count++;
643 }
644 }
646 savednames = g_slist_reverse (savednames);
647 failednames = g_slist_reverse (failednames);
648 if (savednames) {
649 fprintf (stderr, "\nEmergency save document locations:\n");
650 for (GSList *l = savednames; l != NULL; l = l->next) {
651 fprintf (stderr, " %s\n", (gchar *) l->data);
652 }
653 }
654 if (failednames) {
655 fprintf (stderr, "\nFailed to do emergency save for documents:\n");
656 for (GSList *l = failednames; l != NULL; l = l->next) {
657 fprintf (stderr, " %s\n", (gchar *) l->data);
658 }
659 }
661 Inkscape::Preferences::unload();
663 fprintf (stderr, "Emergency save completed. Inkscape will close now.\n");
664 fprintf (stderr, "If you can reproduce this crash, please file a bug at www.inkscape.org\n");
665 fprintf (stderr, "with a detailed description of the steps leading to the crash, so we can fix it.\n");
667 /* Show nice dialog box */
669 char const *istr = _("Inkscape encountered an internal error and will close now.\n");
670 char const *sstr = _("Automatic backups of unsaved documents were done to the following locations:\n");
671 char const *fstr = _("Automatic backup of the following documents failed:\n");
672 gint nllen = strlen ("\n");
673 gint len = strlen (istr) + strlen (sstr) + strlen (fstr);
674 for (GSList *l = savednames; l != NULL; l = l->next) {
675 len = len + SP_INDENT + strlen ((gchar *) l->data) + nllen;
676 }
677 for (GSList *l = failednames; l != NULL; l = l->next) {
678 len = len + SP_INDENT + strlen ((gchar *) l->data) + nllen;
679 }
680 len += 1;
681 gchar *b = g_new (gchar, len);
682 gint pos = 0;
683 len = strlen (istr);
684 memcpy (b + pos, istr, len);
685 pos += len;
686 if (savednames) {
687 len = strlen (sstr);
688 memcpy (b + pos, sstr, len);
689 pos += len;
690 for (GSList *l = savednames; l != NULL; l = l->next) {
691 memset (b + pos, ' ', SP_INDENT);
692 pos += SP_INDENT;
693 len = strlen ((gchar *) l->data);
694 memcpy (b + pos, l->data, len);
695 pos += len;
696 memcpy (b + pos, "\n", nllen);
697 pos += nllen;
698 }
699 }
700 if (failednames) {
701 len = strlen (fstr);
702 memcpy (b + pos, fstr, len);
703 pos += len;
704 for (GSList *l = failednames; l != NULL; l = l->next) {
705 memset (b + pos, ' ', SP_INDENT);
706 pos += SP_INDENT;
707 len = strlen ((gchar *) l->data);
708 memcpy (b + pos, l->data, len);
709 pos += len;
710 memcpy (b + pos, "\n", nllen);
711 pos += nllen;
712 }
713 }
714 *(b + pos) = '\0';
716 if ( inkscape_get_instance() && inkscape_app_use_gui( inkscape_get_instance() ) ) {
717 GtkWidget *msgbox = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, "%s", b);
718 gtk_dialog_run (GTK_DIALOG (msgbox));
719 gtk_widget_destroy (msgbox);
720 }
721 else
722 {
723 g_message( "Error: %s", b );
724 }
725 g_free (b);
727 tracker.clear();
728 Logger::shutdown();
730 /* on exit, allow restored signal handler to take over and crash us */
731 }
735 void
736 inkscape_application_init (const gchar *argv0, gboolean use_gui)
737 {
738 inkscape = (Inkscape::Application *)g_object_new (SP_TYPE_INKSCAPE, NULL);
739 /* fixme: load application defaults */
741 segv_handler = signal (SIGSEGV, inkscape_crash_handler);
742 abrt_handler = signal (SIGABRT, inkscape_crash_handler);
743 fpe_handler = signal (SIGFPE, inkscape_crash_handler);
744 ill_handler = signal (SIGILL, inkscape_crash_handler);
745 #ifndef WIN32
746 bus_handler = signal (SIGBUS, inkscape_crash_handler);
747 #endif
749 inkscape->use_gui = use_gui;
750 inkscape->argv0 = g_strdup(argv0);
752 /* Load the preferences and menus; Later menu layout should be merged into prefs */
753 Inkscape::Preferences::use_gui = use_gui;
754 Inkscape::Preferences::load();
755 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
756 inkscape_load_menus(inkscape);
757 sp_input_load_from_preferences();
759 /* DebugDialog redirection. On Linux, default to OFF, on Win32, default to ON.
760 * Use only if use_gui is enabled
761 */
762 #ifdef WIN32
763 #define DEFAULT_LOG_REDIRECT true
764 #else
765 #define DEFAULT_LOG_REDIRECT false
766 #endif
768 if (use_gui == TRUE && prefs->getBool("/dialogs/debug/redirect", DEFAULT_LOG_REDIRECT))
769 {
770 Inkscape::UI::Dialog::DebugDialog::getInstance()->captureLogMessages();
771 }
773 /* Check for global remapping of Alt key */
774 if(use_gui)
775 {
776 inkscape_mapalt(guint(prefs->getInt("/options/mapalt/value", 0)));
777 }
779 /* Initialize the extensions */
780 Inkscape::Extension::init();
782 inkscape_autosave_init();
784 return;
785 }
787 /**
788 * Returns the current Inkscape::Application global object
789 */
790 Inkscape::Application *
791 inkscape_get_instance()
792 {
793 return inkscape;
794 }
796 gboolean inkscape_app_use_gui( Inkscape::Application const * app )
797 {
798 return app->use_gui;
799 }
801 /**
802 * Menus management
803 *
804 */
805 bool inkscape_load_menus (Inkscape::Application */*inkscape*/)
806 {
807 gchar *fn = profile_path(MENUS_FILE);
808 gchar *menus_xml = NULL; gsize len = 0;
810 if (g_file_get_contents(fn, &menus_xml, &len, NULL)) {
811 // load the menus_xml file
812 INKSCAPE->menus = sp_repr_read_mem(menus_xml, len, NULL);
813 g_free(menus_xml);
814 if (INKSCAPE->menus) return true;
815 }
816 INKSCAPE->menus = sp_repr_read_mem(menus_skeleton, MENUS_SKELETON_SIZE, NULL);
817 if (INKSCAPE->menus) return true;
818 return false;
819 }
822 void
823 inkscape_selection_modified (Inkscape::Selection *selection, guint flags)
824 {
825 if (Inkscape::NSApplication::Application::getNewGui()) {
826 Inkscape::NSApplication::Editor::selectionModified (selection, flags);
827 return;
828 }
829 g_return_if_fail (selection != NULL);
831 if (DESKTOP_IS_ACTIVE (selection->desktop())) {
832 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[MODIFY_SELECTION], 0, selection, flags);
833 }
834 }
837 void
838 inkscape_selection_changed (Inkscape::Selection * selection)
839 {
840 if (Inkscape::NSApplication::Application::getNewGui()) {
841 Inkscape::NSApplication::Editor::selectionChanged (selection);
842 return;
843 }
844 g_return_if_fail (selection != NULL);
846 if (DESKTOP_IS_ACTIVE (selection->desktop())) {
847 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[CHANGE_SELECTION], 0, selection);
848 }
849 }
851 void
852 inkscape_subselection_changed (SPDesktop *desktop)
853 {
854 if (Inkscape::NSApplication::Application::getNewGui()) {
855 Inkscape::NSApplication::Editor::subSelectionChanged (desktop);
856 return;
857 }
858 g_return_if_fail (desktop != NULL);
860 if (DESKTOP_IS_ACTIVE (desktop)) {
861 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[CHANGE_SUBSELECTION], 0, desktop);
862 }
863 }
866 void
867 inkscape_selection_set (Inkscape::Selection * selection)
868 {
869 if (Inkscape::NSApplication::Application::getNewGui()) {
870 Inkscape::NSApplication::Editor::selectionSet (selection);
871 return;
872 }
873 g_return_if_fail (selection != NULL);
875 if (DESKTOP_IS_ACTIVE (selection->desktop())) {
876 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[SET_SELECTION], 0, selection);
877 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[CHANGE_SELECTION], 0, selection);
878 }
879 }
882 void
883 inkscape_eventcontext_set (SPEventContext * eventcontext)
884 {
885 if (Inkscape::NSApplication::Application::getNewGui()) {
886 Inkscape::NSApplication::Editor::eventContextSet (eventcontext);
887 return;
888 }
889 g_return_if_fail (eventcontext != NULL);
890 g_return_if_fail (SP_IS_EVENT_CONTEXT (eventcontext));
892 if (DESKTOP_IS_ACTIVE (eventcontext->desktop)) {
893 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[SET_EVENTCONTEXT], 0, eventcontext);
894 }
895 }
898 void
899 inkscape_add_desktop (SPDesktop * desktop)
900 {
901 g_return_if_fail (desktop != NULL);
903 if (Inkscape::NSApplication::Application::getNewGui())
904 {
905 Inkscape::NSApplication::Editor::addDesktop (desktop);
906 return;
907 }
908 g_return_if_fail (inkscape != NULL);
910 g_assert (!g_slist_find (inkscape->desktops, desktop));
912 inkscape->desktops = g_slist_prepend (inkscape->desktops, desktop);
914 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[ACTIVATE_DESKTOP], 0, desktop);
915 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[SET_EVENTCONTEXT], 0, sp_desktop_event_context (desktop));
916 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[SET_SELECTION], 0, sp_desktop_selection (desktop));
917 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[CHANGE_SELECTION], 0, sp_desktop_selection (desktop));
918 }
922 void
923 inkscape_remove_desktop (SPDesktop * desktop)
924 {
925 g_return_if_fail (desktop != NULL);
926 if (Inkscape::NSApplication::Application::getNewGui())
927 {
928 Inkscape::NSApplication::Editor::removeDesktop (desktop);
929 return;
930 }
931 g_return_if_fail (inkscape != NULL);
933 g_assert (g_slist_find (inkscape->desktops, desktop));
935 if (DESKTOP_IS_ACTIVE (desktop)) {
936 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[DEACTIVATE_DESKTOP], 0, desktop);
937 if (inkscape->desktops->next != NULL) {
938 SPDesktop * new_desktop = (SPDesktop *) inkscape->desktops->next->data;
939 inkscape->desktops = g_slist_remove (inkscape->desktops, new_desktop);
940 inkscape->desktops = g_slist_prepend (inkscape->desktops, new_desktop);
941 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[ACTIVATE_DESKTOP], 0, new_desktop);
942 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[SET_EVENTCONTEXT], 0, sp_desktop_event_context (new_desktop));
943 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[SET_SELECTION], 0, sp_desktop_selection (new_desktop));
944 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[CHANGE_SELECTION], 0, sp_desktop_selection (new_desktop));
945 } else {
946 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[SET_EVENTCONTEXT], 0, NULL);
947 if (sp_desktop_selection(desktop))
948 sp_desktop_selection(desktop)->clear();
949 }
950 }
952 inkscape->desktops = g_slist_remove (inkscape->desktops, desktop);
954 // if this was the last desktop, shut down the program
955 if (inkscape->desktops == NULL) {
956 inkscape_exit (inkscape);
957 }
958 }
962 void
963 inkscape_activate_desktop (SPDesktop * desktop)
964 {
965 g_return_if_fail (desktop != NULL);
966 if (Inkscape::NSApplication::Application::getNewGui())
967 {
968 Inkscape::NSApplication::Editor::activateDesktop (desktop);
969 return;
970 }
971 g_return_if_fail (inkscape != NULL);
973 if (DESKTOP_IS_ACTIVE (desktop)) {
974 return;
975 }
977 g_assert (g_slist_find (inkscape->desktops, desktop));
979 SPDesktop *current = (SPDesktop *) inkscape->desktops->data;
981 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[DEACTIVATE_DESKTOP], 0, current);
983 inkscape->desktops = g_slist_remove (inkscape->desktops, desktop);
984 inkscape->desktops = g_slist_prepend (inkscape->desktops, desktop);
986 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[ACTIVATE_DESKTOP], 0, desktop);
987 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[SET_EVENTCONTEXT], 0, sp_desktop_event_context (desktop));
988 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[SET_SELECTION], 0, sp_desktop_selection (desktop));
989 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[CHANGE_SELECTION], 0, sp_desktop_selection (desktop));
990 }
993 /**
994 * Resends ACTIVATE_DESKTOP for current desktop; needed when a new desktop has got its window that dialogs will transientize to
995 */
996 void
997 inkscape_reactivate_desktop (SPDesktop * desktop)
998 {
999 g_return_if_fail (desktop != NULL);
1000 if (Inkscape::NSApplication::Application::getNewGui())
1001 {
1002 Inkscape::NSApplication::Editor::reactivateDesktop (desktop);
1003 return;
1004 }
1005 g_return_if_fail (inkscape != NULL);
1007 if (DESKTOP_IS_ACTIVE (desktop))
1008 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[ACTIVATE_DESKTOP], 0, desktop);
1009 }
1013 SPDesktop *
1014 inkscape_find_desktop_by_dkey (unsigned int dkey)
1015 {
1016 for (GSList *r = inkscape->desktops; r; r = r->next) {
1017 if (((SPDesktop *) r->data)->dkey == dkey)
1018 return ((SPDesktop *) r->data);
1019 }
1020 return NULL;
1021 }
1026 unsigned int
1027 inkscape_maximum_dkey()
1028 {
1029 unsigned int dkey = 0;
1031 for (GSList *r = inkscape->desktops; r; r = r->next) {
1032 if (((SPDesktop *) r->data)->dkey > dkey)
1033 dkey = ((SPDesktop *) r->data)->dkey;
1034 }
1036 return dkey;
1037 }
1041 SPDesktop *
1042 inkscape_next_desktop ()
1043 {
1044 SPDesktop *d = NULL;
1045 unsigned int dkey_current = ((SPDesktop *) inkscape->desktops->data)->dkey;
1047 if (dkey_current < inkscape_maximum_dkey()) {
1048 // find next existing
1049 for (unsigned int i = dkey_current + 1; i <= inkscape_maximum_dkey(); i++) {
1050 d = inkscape_find_desktop_by_dkey (i);
1051 if (d) {
1052 break;
1053 }
1054 }
1055 } else {
1056 // find first existing
1057 for (unsigned int i = 0; i <= inkscape_maximum_dkey(); i++) {
1058 d = inkscape_find_desktop_by_dkey (i);
1059 if (d) {
1060 break;
1061 }
1062 }
1063 }
1065 g_assert (d);
1067 return d;
1068 }
1072 SPDesktop *
1073 inkscape_prev_desktop ()
1074 {
1075 SPDesktop *d = NULL;
1076 unsigned int dkey_current = ((SPDesktop *) inkscape->desktops->data)->dkey;
1078 if (dkey_current > 0) {
1079 // find prev existing
1080 for (signed int i = dkey_current - 1; i >= 0; i--) {
1081 d = inkscape_find_desktop_by_dkey (i);
1082 if (d) {
1083 break;
1084 }
1085 }
1086 }
1087 if (!d) {
1088 // find last existing
1089 d = inkscape_find_desktop_by_dkey (inkscape_maximum_dkey());
1090 }
1092 g_assert (d);
1094 return d;
1095 }
1099 void
1100 inkscape_switch_desktops_next ()
1101 {
1102 inkscape_next_desktop()->presentWindow();
1103 }
1107 void
1108 inkscape_switch_desktops_prev ()
1109 {
1110 inkscape_prev_desktop()->presentWindow();
1111 }
1115 void
1116 inkscape_dialogs_hide ()
1117 {
1118 if (Inkscape::NSApplication::Application::getNewGui())
1119 Inkscape::NSApplication::Editor::hideDialogs();
1120 else
1121 {
1122 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[DIALOGS_HIDE], 0);
1123 inkscape->dialogs_toggle = FALSE;
1124 }
1125 }
1129 void
1130 inkscape_dialogs_unhide ()
1131 {
1132 if (Inkscape::NSApplication::Application::getNewGui())
1133 Inkscape::NSApplication::Editor::unhideDialogs();
1134 else
1135 {
1136 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[DIALOGS_UNHIDE], 0);
1137 inkscape->dialogs_toggle = TRUE;
1138 }
1139 }
1143 void
1144 inkscape_dialogs_toggle ()
1145 {
1146 if (inkscape->dialogs_toggle) {
1147 inkscape_dialogs_hide ();
1148 } else {
1149 inkscape_dialogs_unhide ();
1150 }
1151 }
1153 void
1154 inkscape_external_change ()
1155 {
1156 g_return_if_fail (inkscape != NULL);
1158 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[EXTERNAL_CHANGE], 0);
1159 }
1161 /**
1162 * fixme: These need probably signals too
1163 */
1164 void
1165 inkscape_add_document (SPDocument *document)
1166 {
1167 g_return_if_fail (document != NULL);
1169 if (!Inkscape::NSApplication::Application::getNewGui())
1170 {
1171 // try to insert the pair into the list
1172 if (!(inkscape->document_set.insert(std::make_pair(document, 1)).second)) {
1173 //insert failed, this key (document) is already in the list
1174 for (std::map<SPDocument*,int>::iterator iter = inkscape->document_set.begin();
1175 iter != inkscape->document_set.end();
1176 ++iter) {
1177 if (iter->first == document) {
1178 // found this document in list, increase its count
1179 iter->second ++;
1180 }
1181 }
1182 }
1183 }
1184 else
1185 {
1186 Inkscape::NSApplication::Editor::addDocument (document);
1187 }
1188 }
1191 // returns true if this was last reference to this document, so you can delete it
1192 bool
1193 inkscape_remove_document (SPDocument *document)
1194 {
1195 g_return_val_if_fail (document != NULL, false);
1197 if (!Inkscape::NSApplication::Application::getNewGui())
1198 {
1199 for (std::map<SPDocument*,int>::iterator iter = inkscape->document_set.begin();
1200 iter != inkscape->document_set.end();
1201 ++iter) {
1202 if (iter->first == document) {
1203 // found this document in list, decrease its count
1204 iter->second --;
1205 if (iter->second < 1) {
1206 // this was the last one, remove the pair from list
1207 inkscape->document_set.erase (iter);
1208 return true;
1209 } else {
1210 return false;
1211 }
1212 }
1213 }
1214 }
1215 else
1216 {
1217 Inkscape::NSApplication::Editor::removeDocument (document);
1218 }
1220 return false;
1221 }
1223 SPDesktop *
1224 inkscape_active_desktop (void)
1225 {
1226 if (Inkscape::NSApplication::Application::getNewGui())
1227 return Inkscape::NSApplication::Editor::getActiveDesktop();
1229 if (inkscape->desktops == NULL) {
1230 return NULL;
1231 }
1233 return (SPDesktop *) inkscape->desktops->data;
1234 }
1236 SPDocument *
1237 inkscape_active_document (void)
1238 {
1239 if (Inkscape::NSApplication::Application::getNewGui())
1240 return Inkscape::NSApplication::Editor::getActiveDocument();
1242 if (SP_ACTIVE_DESKTOP) {
1243 return sp_desktop_document (SP_ACTIVE_DESKTOP);
1244 }
1246 return NULL;
1247 }
1249 bool inkscape_is_sole_desktop_for_document(SPDesktop const &desktop) {
1250 SPDocument const* document = desktop.doc();
1251 if (!document) {
1252 return false;
1253 }
1254 for ( GSList *iter = inkscape->desktops ; iter ; iter = iter->next ) {
1255 SPDesktop *other_desktop=(SPDesktop *)iter->data;
1256 SPDocument *other_document=other_desktop->doc();
1257 if ( other_document == document && other_desktop != &desktop ) {
1258 return false;
1259 }
1260 }
1261 return true;
1262 }
1264 SPEventContext *
1265 inkscape_active_event_context (void)
1266 {
1267 if (SP_ACTIVE_DESKTOP) {
1268 return sp_desktop_event_context (SP_ACTIVE_DESKTOP);
1269 }
1271 return NULL;
1272 }
1276 /*#####################
1277 # HELPERS
1278 #####################*/
1280 void
1281 inkscape_refresh_display (Inkscape::Application *inkscape)
1282 {
1283 for (GSList *l = inkscape->desktops; l != NULL; l = l->next) {
1284 (static_cast<Inkscape::UI::View::View*>(l->data))->requestRedraw();
1285 }
1286 }
1289 /**
1290 * Handler for Inkscape's Exit verb. This emits the shutdown signal,
1291 * saves the preferences if appropriate, and quits.
1292 */
1293 void
1294 inkscape_exit (Inkscape::Application */*inkscape*/)
1295 {
1296 g_assert (INKSCAPE);
1298 //emit shutdown signal so that dialogs could remember layout
1299 g_signal_emit (G_OBJECT (INKSCAPE), inkscape_signals[SHUTDOWN_SIGNAL], 0);
1301 Inkscape::Preferences::unload();
1302 gtk_main_quit ();
1303 }
1305 char *
1306 homedir_path(const char *filename)
1307 {
1308 static const gchar *homedir = NULL;
1309 if (!homedir) {
1310 homedir = g_get_home_dir();
1311 }
1312 if (!homedir) {
1313 homedir = g_path_get_dirname(INKSCAPE->argv0);
1314 }
1315 return g_build_filename(homedir, filename, NULL);
1316 }
1319 /**
1320 * Get, or guess, or decide the location where the preferences.xml
1321 * file should be located.
1322 */
1323 gchar *
1324 profile_path(const char *filename)
1325 {
1326 static const gchar *prefdir = NULL;
1327 if (!prefdir) {
1328 #ifdef HAS_SHGetSpecialFolderLocation
1329 // prefer c:\Documents and Settings\UserName\Application Data\ to
1330 // c:\Documents and Settings\userName\;
1331 if (!prefdir) {
1332 ITEMIDLIST *pidl = 0;
1333 if ( SHGetSpecialFolderLocation( NULL, CSIDL_APPDATA, &pidl ) == NOERROR ) {
1334 gchar * utf8Path = NULL;
1336 if ( PrintWin32::is_os_wide() ) {
1337 wchar_t pathBuf[MAX_PATH+1];
1338 g_assert(sizeof(wchar_t) == sizeof(gunichar2));
1340 if ( SHGetPathFromIDListW( pidl, pathBuf ) ) {
1341 utf8Path = g_utf16_to_utf8( (gunichar2*)(&pathBuf[0]), -1, NULL, NULL, NULL );
1342 }
1343 } else {
1344 char pathBuf[MAX_PATH+1];
1346 if ( SHGetPathFromIDListA( pidl, pathBuf ) ) {
1347 utf8Path = g_filename_to_utf8( pathBuf, -1, NULL, NULL, NULL );
1348 }
1349 }
1351 if ( utf8Path ) {
1352 if (!g_utf8_validate(utf8Path, -1, NULL)) {
1353 g_warning( "SHGetPathFromIDList%c() resulted in invalid UTF-8", (PrintWin32::is_os_wide() ? 'W' : 'A') );
1354 g_free( utf8Path );
1355 utf8Path = 0;
1356 } else {
1357 prefdir = utf8Path;
1358 }
1359 }
1362 /* not compiling yet...
1364 // Remember to free the list pointer
1365 IMalloc * imalloc = 0;
1366 if ( SHGetMalloc(&imalloc) == NOERROR) {
1367 imalloc->lpVtbl->Free( imalloc, pidl );
1368 imalloc->lpVtbl->Release( imalloc );
1369 }
1370 */
1371 }
1373 if (prefdir) {
1374 prefdir = g_build_filename(prefdir, INKSCAPE_PROFILE_DIR, NULL);
1375 }
1376 }
1377 #endif
1378 if (!prefdir) {
1379 prefdir = g_build_filename(g_get_user_config_dir(), INKSCAPE_PROFILE_DIR, NULL);
1380 gchar * legacyDir = homedir_path(INKSCAPE_LEGACY_PROFILE_DIR);
1382 // TODO here is a point to hook in preference migration
1384 if ( !Inkscape::IO::file_test( prefdir, G_FILE_TEST_EXISTS ) && Inkscape::IO::file_test( legacyDir, G_FILE_TEST_EXISTS ) ) {
1385 prefdir = legacyDir;
1386 } else {
1387 g_free(legacyDir);
1388 legacyDir = 0;
1389 }
1390 }
1391 }
1392 return g_build_filename(prefdir, filename, NULL);
1393 }
1395 Inkscape::XML::Node *
1396 inkscape_get_menus (Inkscape::Application * inkscape)
1397 {
1398 Inkscape::XML::Node *repr = inkscape->menus->root();
1399 g_assert (!(strcmp (repr->name(), "inkscape")));
1400 return repr->firstChild();
1401 }
1403 void
1404 inkscape_get_all_desktops(std::list< SPDesktop* >& listbuf)
1405 {
1406 for(GSList* l = inkscape->desktops; l != NULL; l = l->next) {
1407 listbuf.push_back(static_cast< SPDesktop* >(l->data));
1408 }
1409 }
1413 /*
1414 Local Variables:
1415 mode:c++
1416 c-file-style:"stroustrup"
1417 c-file-offsets:((innamespace . 0)(inline-open . 0))
1418 indent-tabs-mode:nil
1419 fill-column:99
1420 End:
1421 */
1422 // vim: expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :