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