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 }
828 /**
829 * @deprecated Use the Preferences class instead, and try not to use _getNode
830 */
831 Inkscape::XML::Node *inkscape_get_repr(Inkscape::Application */*inkscape*/, const gchar *key)
832 {
833 Inkscape::Preferences *ps = Inkscape::Preferences::get();
834 return ps->_getNode(key);
835 }
838 void
839 inkscape_selection_modified (Inkscape::Selection *selection, guint flags)
840 {
841 if (Inkscape::NSApplication::Application::getNewGui()) {
842 Inkscape::NSApplication::Editor::selectionModified (selection, flags);
843 return;
844 }
845 g_return_if_fail (selection != NULL);
847 if (DESKTOP_IS_ACTIVE (selection->desktop())) {
848 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[MODIFY_SELECTION], 0, selection, flags);
849 }
850 }
853 void
854 inkscape_selection_changed (Inkscape::Selection * selection)
855 {
856 if (Inkscape::NSApplication::Application::getNewGui()) {
857 Inkscape::NSApplication::Editor::selectionChanged (selection);
858 return;
859 }
860 g_return_if_fail (selection != NULL);
862 if (DESKTOP_IS_ACTIVE (selection->desktop())) {
863 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[CHANGE_SELECTION], 0, selection);
864 }
865 }
867 void
868 inkscape_subselection_changed (SPDesktop *desktop)
869 {
870 if (Inkscape::NSApplication::Application::getNewGui()) {
871 Inkscape::NSApplication::Editor::subSelectionChanged (desktop);
872 return;
873 }
874 g_return_if_fail (desktop != NULL);
876 if (DESKTOP_IS_ACTIVE (desktop)) {
877 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[CHANGE_SUBSELECTION], 0, desktop);
878 }
879 }
882 void
883 inkscape_selection_set (Inkscape::Selection * selection)
884 {
885 if (Inkscape::NSApplication::Application::getNewGui()) {
886 Inkscape::NSApplication::Editor::selectionSet (selection);
887 return;
888 }
889 g_return_if_fail (selection != NULL);
891 if (DESKTOP_IS_ACTIVE (selection->desktop())) {
892 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[SET_SELECTION], 0, selection);
893 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[CHANGE_SELECTION], 0, selection);
894 }
895 }
898 void
899 inkscape_eventcontext_set (SPEventContext * eventcontext)
900 {
901 if (Inkscape::NSApplication::Application::getNewGui()) {
902 Inkscape::NSApplication::Editor::eventContextSet (eventcontext);
903 return;
904 }
905 g_return_if_fail (eventcontext != NULL);
906 g_return_if_fail (SP_IS_EVENT_CONTEXT (eventcontext));
908 if (DESKTOP_IS_ACTIVE (eventcontext->desktop)) {
909 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[SET_EVENTCONTEXT], 0, eventcontext);
910 }
911 }
914 void
915 inkscape_add_desktop (SPDesktop * desktop)
916 {
917 g_return_if_fail (desktop != NULL);
919 if (Inkscape::NSApplication::Application::getNewGui())
920 {
921 Inkscape::NSApplication::Editor::addDesktop (desktop);
922 return;
923 }
924 g_return_if_fail (inkscape != NULL);
926 g_assert (!g_slist_find (inkscape->desktops, desktop));
928 inkscape->desktops = g_slist_prepend (inkscape->desktops, desktop);
930 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[ACTIVATE_DESKTOP], 0, desktop);
931 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[SET_EVENTCONTEXT], 0, sp_desktop_event_context (desktop));
932 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[SET_SELECTION], 0, sp_desktop_selection (desktop));
933 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[CHANGE_SELECTION], 0, sp_desktop_selection (desktop));
934 }
938 void
939 inkscape_remove_desktop (SPDesktop * desktop)
940 {
941 g_return_if_fail (desktop != NULL);
942 if (Inkscape::NSApplication::Application::getNewGui())
943 {
944 Inkscape::NSApplication::Editor::removeDesktop (desktop);
945 return;
946 }
947 g_return_if_fail (inkscape != NULL);
949 g_assert (g_slist_find (inkscape->desktops, desktop));
951 if (DESKTOP_IS_ACTIVE (desktop)) {
952 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[DEACTIVATE_DESKTOP], 0, desktop);
953 if (inkscape->desktops->next != NULL) {
954 SPDesktop * new_desktop = (SPDesktop *) inkscape->desktops->next->data;
955 inkscape->desktops = g_slist_remove (inkscape->desktops, new_desktop);
956 inkscape->desktops = g_slist_prepend (inkscape->desktops, new_desktop);
957 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[ACTIVATE_DESKTOP], 0, new_desktop);
958 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[SET_EVENTCONTEXT], 0, sp_desktop_event_context (new_desktop));
959 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[SET_SELECTION], 0, sp_desktop_selection (new_desktop));
960 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[CHANGE_SELECTION], 0, sp_desktop_selection (new_desktop));
961 } else {
962 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[SET_EVENTCONTEXT], 0, NULL);
963 if (sp_desktop_selection(desktop))
964 sp_desktop_selection(desktop)->clear();
965 }
966 }
968 inkscape->desktops = g_slist_remove (inkscape->desktops, desktop);
970 // if this was the last desktop, shut down the program
971 if (inkscape->desktops == NULL) {
972 inkscape_exit (inkscape);
973 }
974 }
978 void
979 inkscape_activate_desktop (SPDesktop * desktop)
980 {
981 g_return_if_fail (desktop != NULL);
982 if (Inkscape::NSApplication::Application::getNewGui())
983 {
984 Inkscape::NSApplication::Editor::activateDesktop (desktop);
985 return;
986 }
987 g_return_if_fail (inkscape != NULL);
989 if (DESKTOP_IS_ACTIVE (desktop)) {
990 return;
991 }
993 g_assert (g_slist_find (inkscape->desktops, desktop));
995 SPDesktop *current = (SPDesktop *) inkscape->desktops->data;
997 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[DEACTIVATE_DESKTOP], 0, current);
999 inkscape->desktops = g_slist_remove (inkscape->desktops, desktop);
1000 inkscape->desktops = g_slist_prepend (inkscape->desktops, desktop);
1002 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[ACTIVATE_DESKTOP], 0, desktop);
1003 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[SET_EVENTCONTEXT], 0, sp_desktop_event_context (desktop));
1004 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[SET_SELECTION], 0, sp_desktop_selection (desktop));
1005 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[CHANGE_SELECTION], 0, sp_desktop_selection (desktop));
1006 }
1009 /**
1010 * Resends ACTIVATE_DESKTOP for current desktop; needed when a new desktop has got its window that dialogs will transientize to
1011 */
1012 void
1013 inkscape_reactivate_desktop (SPDesktop * desktop)
1014 {
1015 g_return_if_fail (desktop != NULL);
1016 if (Inkscape::NSApplication::Application::getNewGui())
1017 {
1018 Inkscape::NSApplication::Editor::reactivateDesktop (desktop);
1019 return;
1020 }
1021 g_return_if_fail (inkscape != NULL);
1023 if (DESKTOP_IS_ACTIVE (desktop))
1024 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[ACTIVATE_DESKTOP], 0, desktop);
1025 }
1029 SPDesktop *
1030 inkscape_find_desktop_by_dkey (unsigned int dkey)
1031 {
1032 for (GSList *r = inkscape->desktops; r; r = r->next) {
1033 if (((SPDesktop *) r->data)->dkey == dkey)
1034 return ((SPDesktop *) r->data);
1035 }
1036 return NULL;
1037 }
1042 unsigned int
1043 inkscape_maximum_dkey()
1044 {
1045 unsigned int dkey = 0;
1047 for (GSList *r = inkscape->desktops; r; r = r->next) {
1048 if (((SPDesktop *) r->data)->dkey > dkey)
1049 dkey = ((SPDesktop *) r->data)->dkey;
1050 }
1052 return dkey;
1053 }
1057 SPDesktop *
1058 inkscape_next_desktop ()
1059 {
1060 SPDesktop *d = NULL;
1061 unsigned int dkey_current = ((SPDesktop *) inkscape->desktops->data)->dkey;
1063 if (dkey_current < inkscape_maximum_dkey()) {
1064 // find next existing
1065 for (unsigned int i = dkey_current + 1; i <= inkscape_maximum_dkey(); i++) {
1066 d = inkscape_find_desktop_by_dkey (i);
1067 if (d) {
1068 break;
1069 }
1070 }
1071 } else {
1072 // find first existing
1073 for (unsigned int i = 0; i <= inkscape_maximum_dkey(); i++) {
1074 d = inkscape_find_desktop_by_dkey (i);
1075 if (d) {
1076 break;
1077 }
1078 }
1079 }
1081 g_assert (d);
1083 return d;
1084 }
1088 SPDesktop *
1089 inkscape_prev_desktop ()
1090 {
1091 SPDesktop *d = NULL;
1092 unsigned int dkey_current = ((SPDesktop *) inkscape->desktops->data)->dkey;
1094 if (dkey_current > 0) {
1095 // find prev existing
1096 for (signed int i = dkey_current - 1; i >= 0; i--) {
1097 d = inkscape_find_desktop_by_dkey (i);
1098 if (d) {
1099 break;
1100 }
1101 }
1102 }
1103 if (!d) {
1104 // find last existing
1105 d = inkscape_find_desktop_by_dkey (inkscape_maximum_dkey());
1106 }
1108 g_assert (d);
1110 return d;
1111 }
1115 void
1116 inkscape_switch_desktops_next ()
1117 {
1118 inkscape_next_desktop()->presentWindow();
1119 }
1123 void
1124 inkscape_switch_desktops_prev ()
1125 {
1126 inkscape_prev_desktop()->presentWindow();
1127 }
1131 void
1132 inkscape_dialogs_hide ()
1133 {
1134 if (Inkscape::NSApplication::Application::getNewGui())
1135 Inkscape::NSApplication::Editor::hideDialogs();
1136 else
1137 {
1138 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[DIALOGS_HIDE], 0);
1139 inkscape->dialogs_toggle = FALSE;
1140 }
1141 }
1145 void
1146 inkscape_dialogs_unhide ()
1147 {
1148 if (Inkscape::NSApplication::Application::getNewGui())
1149 Inkscape::NSApplication::Editor::unhideDialogs();
1150 else
1151 {
1152 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[DIALOGS_UNHIDE], 0);
1153 inkscape->dialogs_toggle = TRUE;
1154 }
1155 }
1159 void
1160 inkscape_dialogs_toggle ()
1161 {
1162 if (inkscape->dialogs_toggle) {
1163 inkscape_dialogs_hide ();
1164 } else {
1165 inkscape_dialogs_unhide ();
1166 }
1167 }
1169 void
1170 inkscape_external_change ()
1171 {
1172 g_return_if_fail (inkscape != NULL);
1174 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[EXTERNAL_CHANGE], 0);
1175 }
1177 /**
1178 * fixme: These need probably signals too
1179 */
1180 void
1181 inkscape_add_document (SPDocument *document)
1182 {
1183 g_return_if_fail (document != NULL);
1185 if (!Inkscape::NSApplication::Application::getNewGui())
1186 {
1187 // try to insert the pair into the list
1188 if (!(inkscape->document_set.insert(std::make_pair(document, 1)).second)) {
1189 //insert failed, this key (document) is already in the list
1190 for (std::map<SPDocument*,int>::iterator iter = inkscape->document_set.begin();
1191 iter != inkscape->document_set.end();
1192 ++iter) {
1193 if (iter->first == document) {
1194 // found this document in list, increase its count
1195 iter->second ++;
1196 }
1197 }
1198 }
1199 }
1200 else
1201 {
1202 Inkscape::NSApplication::Editor::addDocument (document);
1203 }
1204 }
1207 // returns true if this was last reference to this document, so you can delete it
1208 bool
1209 inkscape_remove_document (SPDocument *document)
1210 {
1211 g_return_val_if_fail (document != NULL, false);
1213 if (!Inkscape::NSApplication::Application::getNewGui())
1214 {
1215 for (std::map<SPDocument*,int>::iterator iter = inkscape->document_set.begin();
1216 iter != inkscape->document_set.end();
1217 ++iter) {
1218 if (iter->first == document) {
1219 // found this document in list, decrease its count
1220 iter->second --;
1221 if (iter->second < 1) {
1222 // this was the last one, remove the pair from list
1223 inkscape->document_set.erase (iter);
1224 return true;
1225 } else {
1226 return false;
1227 }
1228 }
1229 }
1230 }
1231 else
1232 {
1233 Inkscape::NSApplication::Editor::removeDocument (document);
1234 }
1236 return false;
1237 }
1239 SPDesktop *
1240 inkscape_active_desktop (void)
1241 {
1242 if (Inkscape::NSApplication::Application::getNewGui())
1243 return Inkscape::NSApplication::Editor::getActiveDesktop();
1245 if (inkscape->desktops == NULL) {
1246 return NULL;
1247 }
1249 return (SPDesktop *) inkscape->desktops->data;
1250 }
1252 SPDocument *
1253 inkscape_active_document (void)
1254 {
1255 if (Inkscape::NSApplication::Application::getNewGui())
1256 return Inkscape::NSApplication::Editor::getActiveDocument();
1258 if (SP_ACTIVE_DESKTOP) {
1259 return sp_desktop_document (SP_ACTIVE_DESKTOP);
1260 }
1262 return NULL;
1263 }
1265 bool inkscape_is_sole_desktop_for_document(SPDesktop const &desktop) {
1266 SPDocument const* document = desktop.doc();
1267 if (!document) {
1268 return false;
1269 }
1270 for ( GSList *iter = inkscape->desktops ; iter ; iter = iter->next ) {
1271 SPDesktop *other_desktop=(SPDesktop *)iter->data;
1272 SPDocument *other_document=other_desktop->doc();
1273 if ( other_document == document && other_desktop != &desktop ) {
1274 return false;
1275 }
1276 }
1277 return true;
1278 }
1280 SPEventContext *
1281 inkscape_active_event_context (void)
1282 {
1283 if (SP_ACTIVE_DESKTOP) {
1284 return sp_desktop_event_context (SP_ACTIVE_DESKTOP);
1285 }
1287 return NULL;
1288 }
1292 /*#####################
1293 # HELPERS
1294 #####################*/
1296 void
1297 inkscape_refresh_display (Inkscape::Application *inkscape)
1298 {
1299 for (GSList *l = inkscape->desktops; l != NULL; l = l->next) {
1300 (static_cast<Inkscape::UI::View::View*>(l->data))->requestRedraw();
1301 }
1302 }
1305 /**
1306 * Handler for Inkscape's Exit verb. This emits the shutdown signal,
1307 * saves the preferences if appropriate, and quits.
1308 */
1309 void
1310 inkscape_exit (Inkscape::Application */*inkscape*/)
1311 {
1312 g_assert (INKSCAPE);
1314 //emit shutdown signal so that dialogs could remember layout
1315 g_signal_emit (G_OBJECT (INKSCAPE), inkscape_signals[SHUTDOWN_SIGNAL], 0);
1317 Inkscape::Preferences::unload();
1318 gtk_main_quit ();
1319 }
1321 char *
1322 homedir_path(const char *filename)
1323 {
1324 static const gchar *homedir = NULL;
1325 if (!homedir) {
1326 homedir = g_get_home_dir();
1327 }
1328 if (!homedir) {
1329 homedir = g_path_get_dirname(INKSCAPE->argv0);
1330 }
1331 return g_build_filename(homedir, filename, NULL);
1332 }
1335 /**
1336 * Get, or guess, or decide the location where the preferences.xml
1337 * file should be located.
1338 */
1339 gchar *
1340 profile_path(const char *filename)
1341 {
1342 static const gchar *prefdir = NULL;
1343 if (!prefdir) {
1344 #ifdef HAS_SHGetSpecialFolderLocation
1345 // prefer c:\Documents and Settings\UserName\Application Data\ to
1346 // c:\Documents and Settings\userName\;
1347 if (!prefdir) {
1348 ITEMIDLIST *pidl = 0;
1349 if ( SHGetSpecialFolderLocation( NULL, CSIDL_APPDATA, &pidl ) == NOERROR ) {
1350 gchar * utf8Path = NULL;
1352 if ( PrintWin32::is_os_wide() ) {
1353 wchar_t pathBuf[MAX_PATH+1];
1354 g_assert(sizeof(wchar_t) == sizeof(gunichar2));
1356 if ( SHGetPathFromIDListW( pidl, pathBuf ) ) {
1357 utf8Path = g_utf16_to_utf8( (gunichar2*)(&pathBuf[0]), -1, NULL, NULL, NULL );
1358 }
1359 } else {
1360 char pathBuf[MAX_PATH+1];
1362 if ( SHGetPathFromIDListA( pidl, pathBuf ) ) {
1363 utf8Path = g_filename_to_utf8( pathBuf, -1, NULL, NULL, NULL );
1364 }
1365 }
1367 if ( utf8Path ) {
1368 if (!g_utf8_validate(utf8Path, -1, NULL)) {
1369 g_warning( "SHGetPathFromIDList%c() resulted in invalid UTF-8", (PrintWin32::is_os_wide() ? 'W' : 'A') );
1370 g_free( utf8Path );
1371 utf8Path = 0;
1372 } else {
1373 prefdir = utf8Path;
1374 }
1375 }
1378 /* not compiling yet...
1380 // Remember to free the list pointer
1381 IMalloc * imalloc = 0;
1382 if ( SHGetMalloc(&imalloc) == NOERROR) {
1383 imalloc->lpVtbl->Free( imalloc, pidl );
1384 imalloc->lpVtbl->Release( imalloc );
1385 }
1386 */
1387 }
1389 if (prefdir) {
1390 prefdir = g_build_filename(prefdir, INKSCAPE_PROFILE_DIR, NULL);
1391 }
1392 }
1393 #endif
1394 if (!prefdir) {
1395 prefdir = g_build_filename(g_get_user_config_dir(), INKSCAPE_PROFILE_DIR, NULL);
1396 gchar * legacyDir = homedir_path(INKSCAPE_LEGACY_PROFILE_DIR);
1398 // TODO here is a point to hook in preference migration
1400 if ( !Inkscape::IO::file_test( prefdir, G_FILE_TEST_EXISTS ) && Inkscape::IO::file_test( legacyDir, G_FILE_TEST_EXISTS ) ) {
1401 prefdir = legacyDir;
1402 } else {
1403 g_free(legacyDir);
1404 legacyDir = 0;
1405 }
1406 }
1407 }
1408 return g_build_filename(prefdir, filename, NULL);
1409 }
1411 Inkscape::XML::Node *
1412 inkscape_get_menus (Inkscape::Application * inkscape)
1413 {
1414 Inkscape::XML::Node *repr = inkscape->menus->root();
1415 g_assert (!(strcmp (repr->name(), "inkscape")));
1416 return repr->firstChild();
1417 }
1419 void
1420 inkscape_get_all_desktops(std::list< SPDesktop* >& listbuf)
1421 {
1422 for(GSList* l = inkscape->desktops; l != NULL; l = l->next) {
1423 listbuf.push_back(static_cast< SPDesktop* >(l->data));
1424 }
1425 }
1429 /*
1430 Local Variables:
1431 mode:c++
1432 c-file-style:"stroustrup"
1433 c-file-offsets:((innamespace . 0)(inline-open . 0))
1434 indent-tabs-mode:nil
1435 fill-column:99
1436 End:
1437 */
1438 // vim: expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :