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 "debug/simple-event.h"
22 #include "debug/event-tracker.h"
24 #ifndef WIN32
25 # define HAS_PROC_SELF_EXE //to get path of executable
26 #else
28 // For now to get at is_os_wide().
29 # include "extension/internal/win32.h"
30 using Inkscape::Extension::Internal::PrintWin32;
32 #define _WIN32_IE 0x0400
33 //#define HAS_SHGetSpecialFolderPath
34 #define HAS_SHGetSpecialFolderLocation
35 #define HAS_GetModuleFileName
36 # include <shlobj.h>
37 #endif
39 #include <signal.h>
41 #include <gtk/gtkmain.h>
42 #include <gtk/gtkmessagedialog.h>
44 #include <glibmm/i18n.h>
45 #include "helper/sp-marshal.h"
46 #include "dialogs/debugdialog.h"
47 #include "application/application.h"
48 #include "application/editor.h"
49 #include "preferences.h"
52 #include "document.h"
53 #include "desktop.h"
54 #include "desktop-handles.h"
55 #include "selection.h"
56 #include "event-context.h"
57 #include "inkscape-private.h"
58 #include "prefs-utils.h"
59 #include "xml/repr.h"
60 #include "io/sys.h"
62 #include "extension/init.h"
64 static Inkscape::Application *inkscape = NULL;
66 /* Backbones of configuration xml data */
67 #include "menus-skeleton.h"
69 enum {
70 MODIFY_SELECTION, // global: one of selections modified
71 CHANGE_SELECTION, // global: one of selections changed
72 CHANGE_SUBSELECTION, // global: one of subselections (text selection, gradient handle, etc) changed
73 SET_SELECTION, // global: one of selections set
74 SET_EVENTCONTEXT, // tool switched
75 ACTIVATE_DESKTOP, // some desktop got focus
76 DEACTIVATE_DESKTOP, // some desktop lost focus
77 SHUTDOWN_SIGNAL, // inkscape is quitting
78 DIALOGS_HIDE, // user pressed F12
79 DIALOGS_UNHIDE, // user pressed F12
80 EXTERNAL_CHANGE, // a document was changed by some external means (undo or XML editor); this
81 // may not be reflected by a selection change and thus needs a separate signal
82 LAST_SIGNAL
83 };
85 #define DESKTOP_IS_ACTIVE(d) ((d) == inkscape->desktops->data)
88 /*################################
89 # FORWARD DECLARATIONS
90 ################################*/
92 gboolean inkscape_app_use_gui( Inkscape::Application const * app );
94 static void inkscape_class_init (Inkscape::ApplicationClass *klass);
95 static void inkscape_init (SPObject *object);
96 static void inkscape_dispose (GObject *object);
98 static void inkscape_activate_desktop_private (Inkscape::Application *inkscape, SPDesktop *desktop);
99 static void inkscape_deactivate_desktop_private (Inkscape::Application *inkscape, SPDesktop *desktop);
101 static bool inkscape_init_config (Inkscape::XML::Document *doc, const gchar *config_name, const gchar *skeleton,
102 unsigned int skel_size,
103 const gchar *e_mkdir,
104 const gchar *e_notdir,
105 const gchar *e_ccf,
106 const gchar *e_cwf,
107 const gchar *warn);
109 struct Inkscape::Application {
110 GObject object;
111 Inkscape::XML::Document *menus;
112 GSList *documents;
113 GSList *desktops;
114 gchar *argv0;
115 gboolean dialogs_toggle;
116 gboolean use_gui; // may want to consider a virtual function
117 // for overriding things like the warning dlg's
118 };
120 struct Inkscape::ApplicationClass {
121 GObjectClass object_class;
123 /* Signals */
124 void (* change_selection) (Inkscape::Application * inkscape, Inkscape::Selection * selection);
125 void (* change_subselection) (Inkscape::Application * inkscape, SPDesktop *desktop);
126 void (* modify_selection) (Inkscape::Application * inkscape, Inkscape::Selection * selection, guint flags);
127 void (* set_selection) (Inkscape::Application * inkscape, Inkscape::Selection * selection);
128 void (* set_eventcontext) (Inkscape::Application * inkscape, SPEventContext * eventcontext);
129 void (* activate_desktop) (Inkscape::Application * inkscape, SPDesktop * desktop);
130 void (* deactivate_desktop) (Inkscape::Application * inkscape, SPDesktop * desktop);
131 void (* destroy_document) (Inkscape::Application *inkscape, SPDocument *doc);
132 void (* color_set) (Inkscape::Application *inkscape, SPColor *color, double opacity);
133 void (* shut_down) (Inkscape::Application *inkscape);
134 void (* dialogs_hide) (Inkscape::Application *inkscape);
135 void (* dialogs_unhide) (Inkscape::Application *inkscape);
136 void (* external_change) (Inkscape::Application *inkscape);
137 };
139 static GObjectClass * parent_class;
140 static guint inkscape_signals[LAST_SIGNAL] = {0};
142 static void (* segv_handler) (int) = NULL;
144 #ifdef WIN32
145 #define INKSCAPE_PROFILE_DIR "Inkscape"
146 #else
147 #define INKSCAPE_PROFILE_DIR ".inkscape"
148 #endif
150 #define MENUS_FILE "menus.xml"
153 /**
154 * Retrieves the GType for the Inkscape Application object.
155 */
156 GType
157 inkscape_get_type (void)
158 {
159 static GType type = 0;
160 if (!type) {
161 GTypeInfo info = {
162 sizeof (Inkscape::ApplicationClass),
163 NULL, NULL,
164 (GClassInitFunc) inkscape_class_init,
165 NULL, NULL,
166 sizeof (Inkscape::Application),
167 4,
168 (GInstanceInitFunc) inkscape_init,
169 NULL
170 };
171 type = g_type_register_static (G_TYPE_OBJECT, "Inkscape_Application", &info, (GTypeFlags)0);
172 }
173 return type;
174 }
177 /**
178 * Initializes the inkscape class, registering all of its signal handlers
179 * and virtual functions
180 */
181 static void
182 inkscape_class_init (Inkscape::ApplicationClass * klass)
183 {
184 GObjectClass * object_class;
186 object_class = (GObjectClass *) klass;
188 parent_class = (GObjectClass *)g_type_class_peek_parent (klass);
190 inkscape_signals[MODIFY_SELECTION] = g_signal_new ("modify_selection",
191 G_TYPE_FROM_CLASS (klass),
192 G_SIGNAL_RUN_FIRST,
193 G_STRUCT_OFFSET (Inkscape::ApplicationClass, modify_selection),
194 NULL, NULL,
195 sp_marshal_NONE__POINTER_UINT,
196 G_TYPE_NONE, 2,
197 G_TYPE_POINTER, G_TYPE_UINT);
198 inkscape_signals[CHANGE_SELECTION] = g_signal_new ("change_selection",
199 G_TYPE_FROM_CLASS (klass),
200 G_SIGNAL_RUN_FIRST,
201 G_STRUCT_OFFSET (Inkscape::ApplicationClass, change_selection),
202 NULL, NULL,
203 sp_marshal_NONE__POINTER,
204 G_TYPE_NONE, 1,
205 G_TYPE_POINTER);
206 inkscape_signals[CHANGE_SUBSELECTION] = g_signal_new ("change_subselection",
207 G_TYPE_FROM_CLASS (klass),
208 G_SIGNAL_RUN_FIRST,
209 G_STRUCT_OFFSET (Inkscape::ApplicationClass, change_subselection),
210 NULL, NULL,
211 sp_marshal_NONE__POINTER,
212 G_TYPE_NONE, 1,
213 G_TYPE_POINTER);
214 inkscape_signals[SET_SELECTION] = g_signal_new ("set_selection",
215 G_TYPE_FROM_CLASS (klass),
216 G_SIGNAL_RUN_FIRST,
217 G_STRUCT_OFFSET (Inkscape::ApplicationClass, set_selection),
218 NULL, NULL,
219 sp_marshal_NONE__POINTER,
220 G_TYPE_NONE, 1,
221 G_TYPE_POINTER);
222 inkscape_signals[SET_EVENTCONTEXT] = g_signal_new ("set_eventcontext",
223 G_TYPE_FROM_CLASS (klass),
224 G_SIGNAL_RUN_FIRST,
225 G_STRUCT_OFFSET (Inkscape::ApplicationClass, set_eventcontext),
226 NULL, NULL,
227 sp_marshal_NONE__POINTER,
228 G_TYPE_NONE, 1,
229 G_TYPE_POINTER);
230 inkscape_signals[ACTIVATE_DESKTOP] = g_signal_new ("activate_desktop",
231 G_TYPE_FROM_CLASS (klass),
232 G_SIGNAL_RUN_FIRST,
233 G_STRUCT_OFFSET (Inkscape::ApplicationClass, activate_desktop),
234 NULL, NULL,
235 sp_marshal_NONE__POINTER,
236 G_TYPE_NONE, 1,
237 G_TYPE_POINTER);
238 inkscape_signals[DEACTIVATE_DESKTOP] = g_signal_new ("deactivate_desktop",
239 G_TYPE_FROM_CLASS (klass),
240 G_SIGNAL_RUN_FIRST,
241 G_STRUCT_OFFSET (Inkscape::ApplicationClass, deactivate_desktop),
242 NULL, NULL,
243 sp_marshal_NONE__POINTER,
244 G_TYPE_NONE, 1,
245 G_TYPE_POINTER);
246 inkscape_signals[SHUTDOWN_SIGNAL] = g_signal_new ("shut_down",
247 G_TYPE_FROM_CLASS (klass),
248 G_SIGNAL_RUN_FIRST,
249 G_STRUCT_OFFSET (Inkscape::ApplicationClass, shut_down),
250 NULL, NULL,
251 g_cclosure_marshal_VOID__VOID,
252 G_TYPE_NONE, 0);
253 inkscape_signals[DIALOGS_HIDE] = g_signal_new ("dialogs_hide",
254 G_TYPE_FROM_CLASS (klass),
255 G_SIGNAL_RUN_FIRST,
256 G_STRUCT_OFFSET (Inkscape::ApplicationClass, dialogs_hide),
257 NULL, NULL,
258 g_cclosure_marshal_VOID__VOID,
259 G_TYPE_NONE, 0);
260 inkscape_signals[DIALOGS_UNHIDE] = g_signal_new ("dialogs_unhide",
261 G_TYPE_FROM_CLASS (klass),
262 G_SIGNAL_RUN_FIRST,
263 G_STRUCT_OFFSET (Inkscape::ApplicationClass, dialogs_unhide),
264 NULL, NULL,
265 g_cclosure_marshal_VOID__VOID,
266 G_TYPE_NONE, 0);
267 inkscape_signals[EXTERNAL_CHANGE] = g_signal_new ("external_change",
268 G_TYPE_FROM_CLASS (klass),
269 G_SIGNAL_RUN_FIRST,
270 G_STRUCT_OFFSET (Inkscape::ApplicationClass, external_change),
271 NULL, NULL,
272 g_cclosure_marshal_VOID__VOID,
273 G_TYPE_NONE, 0);
275 object_class->dispose = inkscape_dispose;
277 klass->activate_desktop = inkscape_activate_desktop_private;
278 klass->deactivate_desktop = inkscape_deactivate_desktop_private;
279 }
282 static void
283 inkscape_init (SPObject * object)
284 {
285 if (!inkscape) {
286 inkscape = (Inkscape::Application *) object;
287 } else {
288 g_assert_not_reached ();
289 }
291 inkscape->menus = sp_repr_read_mem (_(menus_skeleton), MENUS_SKELETON_SIZE, NULL);
293 inkscape->documents = NULL;
294 inkscape->desktops = NULL;
296 inkscape->dialogs_toggle = TRUE;
297 }
300 static void
301 inkscape_dispose (GObject *object)
302 {
303 Inkscape::Application *inkscape = (Inkscape::Application *) object;
305 while (inkscape->documents) {
306 // we don't otherwise unref, so why here?
307 sp_document_unref((SPDocument *)inkscape->documents->data);
308 }
310 g_assert (!inkscape->desktops);
312 Inkscape::Preferences::save();
314 if (inkscape->menus) {
315 /* fixme: This is not the best place */
316 Inkscape::GC::release(inkscape->menus);
317 inkscape->menus = NULL;
318 }
320 G_OBJECT_CLASS (parent_class)->dispose (object);
322 gtk_main_quit ();
323 }
326 void
327 inkscape_ref (void)
328 {
329 if (inkscape)
330 g_object_ref (G_OBJECT (inkscape));
331 }
334 void
335 inkscape_unref (void)
336 {
337 if (inkscape)
338 g_object_unref (G_OBJECT (inkscape));
339 }
342 static void
343 inkscape_activate_desktop_private (Inkscape::Application *inkscape, SPDesktop *desktop)
344 {
345 desktop->set_active (true);
346 }
349 static void
350 inkscape_deactivate_desktop_private (Inkscape::Application *inkscape, SPDesktop *desktop)
351 {
352 desktop->set_active (false);
353 }
356 /* fixme: This is EVIL, and belongs to main after all */
358 #define SP_INDENT 8
361 static void
362 inkscape_segv_handler (int signum)
363 {
364 using Inkscape::Debug::SimpleEvent;
365 using Inkscape::Debug::EventTracker;
366 using Inkscape::Debug::Logger;
368 static gint recursion = FALSE;
370 /* let any SIGABRTs seen from within this handler dump core */
371 signal(SIGABRT, SIG_DFL);
373 /* Kill loops */
374 if (recursion) {
375 abort ();
376 }
377 recursion = TRUE;
379 EventTracker<SimpleEvent<Inkscape::Debug::Event::CORE> > tracker("crash");
380 tracker.set<SimpleEvent<> >("emergency-save");
382 fprintf(stderr, "\nEmergency save activated!\n");
384 time_t sptime = time (NULL);
385 struct tm *sptm = localtime (&sptime);
386 gchar sptstr[256];
387 strftime (sptstr, 256, "%Y_%m_%d_%H_%M_%S", sptm);
389 gint count = 0;
390 GSList *savednames = NULL;
391 GSList *failednames = NULL;
392 for (GSList *l = inkscape->documents; l != NULL; l = l->next) {
393 SPDocument *doc;
394 Inkscape::XML::Node *repr;
395 doc = (SPDocument *) l->data;
396 repr = sp_document_repr_root (doc);
397 if (repr->attribute("sodipodi:modified")) {
398 const gchar *docname, *d0, *d;
399 gchar n[64], c[1024];
400 FILE *file;
402 /* originally, the document name was retrieved from
403 * the sodipod:docname attribute */
404 docname = doc->name;
405 if (docname) {
406 /* fixme: Quick hack to remove emergency file suffix */
407 d0 = strrchr ((char*)docname, '.');
408 if (d0 && (d0 > docname)) {
409 d0 = strrchr ((char*)(d0 - 1), '.');
410 if (d0 && (d0 > docname)) {
411 d = d0;
412 while (isdigit (*d) || (*d == '.') || (*d == '_')) d += 1;
413 if (*d) {
414 memcpy (n, docname, MIN (d0 - docname - 1, 64));
415 n[63] = '\0';
416 docname = n;
417 }
418 }
419 }
420 }
422 if (!docname || !*docname) docname = "emergency";
423 // try saving to the profile location
424 g_snprintf (c, 1024, "%.256s.%s.%d", docname, sptstr, count);
425 gchar * location = homedir_path(c);
426 Inkscape::IO::dump_fopen_call(location, "E");
427 file = Inkscape::IO::fopen_utf8name(location, "w");
428 g_free(location);
429 if (!file) {
430 // try saving to /tmp
431 g_snprintf (c, 1024, "/tmp/inkscape-%.256s.%s.%d", docname, sptstr, count);
432 Inkscape::IO::dump_fopen_call(c, "G");
433 file = Inkscape::IO::fopen_utf8name(c, "w");
434 }
435 if (!file) {
436 // try saving to the current directory
437 g_snprintf (c, 1024, "inkscape-%.256s.%s.%d", docname, sptstr, count);
438 Inkscape::IO::dump_fopen_call(c, "F");
439 file = Inkscape::IO::fopen_utf8name(c, "w");
440 }
441 if (file) {
442 sp_repr_save_stream (sp_repr_document (repr), file, SP_SVG_NS_URI);
443 savednames = g_slist_prepend (savednames, g_strdup (c));
444 fclose (file);
445 } else {
446 docname = repr->attribute("sodipodi:docname");
447 failednames = g_slist_prepend (failednames, (docname) ? g_strdup (docname) : g_strdup (_("Untitled document")));
448 }
449 count++;
450 }
451 }
453 savednames = g_slist_reverse (savednames);
454 failednames = g_slist_reverse (failednames);
455 if (savednames) {
456 fprintf (stderr, "\nEmergency save document locations:\n");
457 for (GSList *l = savednames; l != NULL; l = l->next) {
458 fprintf (stderr, " %s\n", (gchar *) l->data);
459 }
460 }
461 if (failednames) {
462 fprintf (stderr, "\nFailed to do emergency save for documents:\n");
463 for (GSList *l = failednames; l != NULL; l = l->next) {
464 fprintf (stderr, " %s\n", (gchar *) l->data);
465 }
466 }
468 Inkscape::Preferences::save();
470 fprintf (stderr, "Emergency save completed. Inkscape will close now.\n");
471 fprintf (stderr, "If you can reproduce this crash, please file a bug at www.inkscape.org\n");
472 fprintf (stderr, "with a detailed description of the steps leading to the crash, so we can fix it.\n");
474 /* Show nice dialog box */
476 char const *istr = _("Inkscape encountered an internal error and will close now.\n");
477 char const *sstr = _("Automatic backups of unsaved documents were done to the following locations:\n");
478 char const *fstr = _("Automatic backup of the following documents failed:\n");
479 gint nllen = strlen ("\n");
480 gint len = strlen (istr) + strlen (sstr) + strlen (fstr);
481 for (GSList *l = savednames; l != NULL; l = l->next) {
482 len = len + SP_INDENT + strlen ((gchar *) l->data) + nllen;
483 }
484 for (GSList *l = failednames; l != NULL; l = l->next) {
485 len = len + SP_INDENT + strlen ((gchar *) l->data) + nllen;
486 }
487 len += 1;
488 gchar *b = g_new (gchar, len);
489 gint pos = 0;
490 len = strlen (istr);
491 memcpy (b + pos, istr, len);
492 pos += len;
493 if (savednames) {
494 len = strlen (sstr);
495 memcpy (b + pos, sstr, len);
496 pos += len;
497 for (GSList *l = savednames; l != NULL; l = l->next) {
498 memset (b + pos, ' ', SP_INDENT);
499 pos += SP_INDENT;
500 len = strlen ((gchar *) l->data);
501 memcpy (b + pos, l->data, len);
502 pos += len;
503 memcpy (b + pos, "\n", nllen);
504 pos += nllen;
505 }
506 }
507 if (failednames) {
508 len = strlen (fstr);
509 memcpy (b + pos, fstr, len);
510 pos += len;
511 for (GSList *l = failednames; l != NULL; l = l->next) {
512 memset (b + pos, ' ', SP_INDENT);
513 pos += SP_INDENT;
514 len = strlen ((gchar *) l->data);
515 memcpy (b + pos, l->data, len);
516 pos += len;
517 memcpy (b + pos, "\n", nllen);
518 pos += nllen;
519 }
520 }
521 *(b + pos) = '\0';
523 if ( inkscape_get_instance() && inkscape_app_use_gui( inkscape_get_instance() ) ) {
524 GtkWidget *msgbox = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, "%s", b);
525 gtk_dialog_run (GTK_DIALOG (msgbox));
526 gtk_widget_destroy (msgbox);
527 }
528 else
529 {
530 g_message( "Error: %s", b );
531 }
532 g_free (b);
534 tracker.clear();
535 Logger::shutdown();
537 (* segv_handler) (signum);
538 }
542 void
543 inkscape_application_init (const gchar *argv0, gboolean use_gui)
544 {
545 inkscape = (Inkscape::Application *)g_object_new (SP_TYPE_INKSCAPE, NULL);
546 /* fixme: load application defaults */
548 segv_handler = signal (SIGSEGV, inkscape_segv_handler);
549 signal (SIGFPE, inkscape_segv_handler);
550 signal (SIGILL, inkscape_segv_handler);
551 #ifndef WIN32
552 signal (SIGBUS, inkscape_segv_handler);
553 #endif
554 signal (SIGABRT, inkscape_segv_handler);
556 inkscape->use_gui = use_gui;
557 inkscape->argv0 = g_strdup(argv0);
559 /* Attempt to load the preferences, and set the save_preferences flag to TRUE
560 if we could, or FALSE if we couldn't */
561 Inkscape::Preferences::load();
562 inkscape_load_menus(inkscape);
564 /* DebugDialog redirection. On Linux, default to OFF, on Win32, default to ON.
565 * Use only if use_gui is enabled
566 */
567 #ifdef WIN32
568 #define DEFAULT_LOG_REDIRECT true
569 #else
570 #define DEFAULT_LOG_REDIRECT false
571 #endif
573 if (use_gui == TRUE && prefs_get_int_attribute("dialogs.debug", "redirect", DEFAULT_LOG_REDIRECT))
574 {
575 Inkscape::UI::Dialogs::DebugDialog::getInstance()->captureLogMessages();
576 }
578 /* Initialize the extensions */
579 Inkscape::Extension::init();
581 return;
582 }
584 /**
585 * Returns the current Inkscape::Application global object
586 */
587 Inkscape::Application *
588 inkscape_get_instance()
589 {
590 return inkscape;
591 }
593 gboolean inkscape_app_use_gui( Inkscape::Application const * app )
594 {
595 return app->use_gui;
596 }
598 /**
599 * Preference management
600 * We use '.' as separator
601 *
602 * Returns TRUE if the config file was successfully loaded, FALSE if not.
603 */
604 bool
605 inkscape_load_config (const gchar *filename, Inkscape::XML::Document *config, const gchar *skeleton,
606 unsigned int skel_size, const gchar *e_notreg, const gchar *e_notxml,
607 const gchar *e_notsp, const gchar *warn)
608 {
609 gchar *fn = profile_path(filename);
610 if (!Inkscape::IO::file_test(fn, G_FILE_TEST_EXISTS)) {
611 bool result;
612 /* No such file */
613 result = inkscape_init_config (config, filename, skeleton,
614 skel_size,
615 _("Cannot create directory %s.\n%s"),
616 _("%s is not a valid directory.\n%s"),
617 _("Cannot create file %s.\n%s"),
618 _("Cannot write file %s.\n%s"),
619 _("Although Inkscape will run, it will use default settings,\n"
620 "and any changes made in preferences will not be saved."));
621 g_free (fn);
622 return result;
623 }
625 if (!Inkscape::IO::file_test(fn, G_FILE_TEST_IS_REGULAR)) {
626 /* Not a regular file */
627 gchar *safeFn = Inkscape::IO::sanitizeString(fn);
628 GtkWidget *w = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, e_notreg, safeFn, warn);
629 gtk_dialog_run (GTK_DIALOG (w));
630 gtk_widget_destroy (w);
631 g_free(safeFn);
632 g_free (fn);
633 return false;
634 }
636 Inkscape::XML::Document *doc = sp_repr_read_file (fn, NULL);
637 if (doc == NULL) {
638 /* Not an valid xml file */
639 gchar *safeFn = Inkscape::IO::sanitizeString(fn);
640 GtkWidget *w = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, e_notxml, safeFn, warn);
641 gtk_dialog_run (GTK_DIALOG (w));
642 gtk_widget_destroy (w);
643 g_free(safeFn);
644 g_free (fn);
645 return false;
646 }
648 Inkscape::XML::Node *root = sp_repr_document_root (doc);
649 if (strcmp (root->name(), "inkscape")) {
650 gchar *safeFn = Inkscape::IO::sanitizeString(fn);
651 GtkWidget *w = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, e_notsp, safeFn, warn);
652 gtk_dialog_run (GTK_DIALOG (w));
653 gtk_widget_destroy (w);
654 Inkscape::GC::release(doc);
655 g_free(safeFn);
656 g_free (fn);
657 return false;
658 }
660 /** \todo this is a hack, need to figure out how to get
661 * a reasonable merge working with the menus.xml file */
662 if (skel_size == MENUS_SKELETON_SIZE) {
663 if (INKSCAPE)
664 INKSCAPE->menus = doc;
665 doc = config;
666 } else {
667 config->root()->mergeFrom(doc->root(), "id");
668 }
670 Inkscape::GC::release(doc);
671 g_free (fn);
672 return true;
673 }
675 /**
676 * Menus management
677 *
678 */
679 bool
680 inkscape_load_menus (Inkscape::Application *inkscape)
681 {
682 gchar *fn = profile_path(MENUS_FILE);
683 bool retval = false;
684 if (Inkscape::IO::file_test(fn, G_FILE_TEST_EXISTS)) {
685 retval = inkscape_load_config (MENUS_FILE,
686 inkscape->menus,
687 menus_skeleton,
688 MENUS_SKELETON_SIZE,
689 _("%s is not a regular file.\n%s"),
690 _("%s not a valid XML file, or\n"
691 "you don't have read permissions on it.\n%s"),
692 _("%s is not a valid menus file.\n%s"),
693 _("Inkscape will run with default menus.\n"
694 "New menus will not be saved."));
695 } else {
696 INKSCAPE->menus = sp_repr_read_mem(menus_skeleton, MENUS_SKELETON_SIZE, NULL);
697 if (INKSCAPE->menus != NULL)
698 retval = true;
699 }
700 g_free(fn);
701 return retval;
702 }
704 /**
705 * We use '.' as separator
706 * \param inkscape Unused
707 */
708 Inkscape::XML::Node *
709 inkscape_get_repr (Inkscape::Application *inkscape, const gchar *key)
710 {
711 if (key == NULL) {
712 return NULL;
713 }
715 Inkscape::XML::Node *repr = sp_repr_document_root (Inkscape::Preferences::get());
716 g_assert (!(strcmp (repr->name(), "inkscape")));
718 gchar const *s = key;
719 while ((s) && (*s)) {
721 /* Find next name */
722 gchar const *e = strchr (s, '.');
723 guint len;
724 if (e) {
725 len = e++ - s;
726 } else {
727 len = strlen (s);
728 }
730 Inkscape::XML::Node* child;
731 for (child = repr->firstChild(); child != NULL; child = child->next()) {
732 gchar const *id = child->attribute("id");
733 if ((id) && (strlen (id) == len) && (!strncmp (id, s, len)))
734 {
735 break;
736 }
737 }
738 if (child == NULL) {
739 return NULL;
740 }
742 repr = child;
743 s = e;
744 }
745 return repr;
746 }
750 void
751 inkscape_selection_modified (Inkscape::Selection *selection, guint flags)
752 {
753 if (Inkscape::NSApplication::Application::getNewGui()) {
754 Inkscape::NSApplication::Editor::selectionModified (selection, flags);
755 return;
756 }
757 g_return_if_fail (selection != NULL);
759 if (DESKTOP_IS_ACTIVE (selection->desktop())) {
760 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[MODIFY_SELECTION], 0, selection, flags);
761 }
762 }
765 void
766 inkscape_selection_changed (Inkscape::Selection * selection)
767 {
768 if (Inkscape::NSApplication::Application::getNewGui()) {
769 Inkscape::NSApplication::Editor::selectionChanged (selection);
770 return;
771 }
772 g_return_if_fail (selection != NULL);
774 if (DESKTOP_IS_ACTIVE (selection->desktop())) {
775 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[CHANGE_SELECTION], 0, selection);
776 }
777 }
779 void
780 inkscape_subselection_changed (SPDesktop *desktop)
781 {
782 if (Inkscape::NSApplication::Application::getNewGui()) {
783 Inkscape::NSApplication::Editor::subSelectionChanged (desktop);
784 return;
785 }
786 g_return_if_fail (desktop != NULL);
788 if (DESKTOP_IS_ACTIVE (desktop)) {
789 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[CHANGE_SUBSELECTION], 0, desktop);
790 }
791 }
794 void
795 inkscape_selection_set (Inkscape::Selection * selection)
796 {
797 if (Inkscape::NSApplication::Application::getNewGui()) {
798 Inkscape::NSApplication::Editor::selectionSet (selection);
799 return;
800 }
801 g_return_if_fail (selection != NULL);
803 if (DESKTOP_IS_ACTIVE (selection->desktop())) {
804 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[SET_SELECTION], 0, selection);
805 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[CHANGE_SELECTION], 0, selection);
806 }
807 }
810 void
811 inkscape_eventcontext_set (SPEventContext * eventcontext)
812 {
813 if (Inkscape::NSApplication::Application::getNewGui()) {
814 Inkscape::NSApplication::Editor::eventContextSet (eventcontext);
815 return;
816 }
817 g_return_if_fail (eventcontext != NULL);
818 g_return_if_fail (SP_IS_EVENT_CONTEXT (eventcontext));
820 if (DESKTOP_IS_ACTIVE (eventcontext->desktop)) {
821 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[SET_EVENTCONTEXT], 0, eventcontext);
822 }
823 }
826 void
827 inkscape_add_desktop (SPDesktop * desktop)
828 {
829 g_return_if_fail (desktop != NULL);
831 if (Inkscape::NSApplication::Application::getNewGui())
832 {
833 Inkscape::NSApplication::Editor::addDesktop (desktop);
834 return;
835 }
836 g_return_if_fail (inkscape != NULL);
838 g_assert (!g_slist_find (inkscape->desktops, desktop));
840 inkscape->desktops = g_slist_append (inkscape->desktops, desktop);
842 if (DESKTOP_IS_ACTIVE (desktop)) {
843 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[ACTIVATE_DESKTOP], 0, desktop);
844 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[SET_EVENTCONTEXT], 0, sp_desktop_event_context (desktop));
845 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[SET_SELECTION], 0, sp_desktop_selection (desktop));
846 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[CHANGE_SELECTION], 0, sp_desktop_selection (desktop));
847 }
848 }
852 void
853 inkscape_remove_desktop (SPDesktop * desktop)
854 {
855 g_return_if_fail (desktop != NULL);
856 if (Inkscape::NSApplication::Application::getNewGui())
857 {
858 Inkscape::NSApplication::Editor::removeDesktop (desktop);
859 return;
860 }
861 g_return_if_fail (inkscape != NULL);
863 g_assert (g_slist_find (inkscape->desktops, desktop));
865 if (DESKTOP_IS_ACTIVE (desktop)) {
866 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[DEACTIVATE_DESKTOP], 0, desktop);
867 if (inkscape->desktops->next != NULL) {
868 SPDesktop * new_desktop = (SPDesktop *) inkscape->desktops->next->data;
869 inkscape->desktops = g_slist_remove (inkscape->desktops, new_desktop);
870 inkscape->desktops = g_slist_prepend (inkscape->desktops, new_desktop);
871 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[ACTIVATE_DESKTOP], 0, new_desktop);
872 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[SET_EVENTCONTEXT], 0, sp_desktop_event_context (new_desktop));
873 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[SET_SELECTION], 0, sp_desktop_selection (new_desktop));
874 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[CHANGE_SELECTION], 0, sp_desktop_selection (new_desktop));
875 } else {
876 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[SET_EVENTCONTEXT], 0, NULL);
877 if (sp_desktop_selection(desktop))
878 sp_desktop_selection(desktop)->clear();
879 }
880 }
882 inkscape->desktops = g_slist_remove (inkscape->desktops, desktop);
884 // if this was the last desktop, shut down the program
885 if (inkscape->desktops == NULL) {
886 inkscape_exit (inkscape);
887 }
888 }
892 void
893 inkscape_activate_desktop (SPDesktop * desktop)
894 {
895 g_return_if_fail (desktop != NULL);
896 if (Inkscape::NSApplication::Application::getNewGui())
897 {
898 Inkscape::NSApplication::Editor::activateDesktop (desktop);
899 return;
900 }
901 g_return_if_fail (inkscape != NULL);
903 if (DESKTOP_IS_ACTIVE (desktop)) {
904 return;
905 }
907 g_assert (g_slist_find (inkscape->desktops, desktop));
909 SPDesktop *current = (SPDesktop *) inkscape->desktops->data;
911 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[DEACTIVATE_DESKTOP], 0, current);
913 inkscape->desktops = g_slist_remove (inkscape->desktops, desktop);
914 inkscape->desktops = g_slist_prepend (inkscape->desktops, desktop);
916 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[ACTIVATE_DESKTOP], 0, desktop);
917 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[SET_EVENTCONTEXT], 0, sp_desktop_event_context (desktop));
918 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[SET_SELECTION], 0, sp_desktop_selection (desktop));
919 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[CHANGE_SELECTION], 0, sp_desktop_selection (desktop));
920 }
923 /**
924 * Resends ACTIVATE_DESKTOP for current desktop; needed when a new desktop has got its window that dialogs will transientize to
925 */
926 void
927 inkscape_reactivate_desktop (SPDesktop * desktop)
928 {
929 g_return_if_fail (desktop != NULL);
930 if (Inkscape::NSApplication::Application::getNewGui())
931 {
932 Inkscape::NSApplication::Editor::reactivateDesktop (desktop);
933 return;
934 }
935 g_return_if_fail (inkscape != NULL);
937 if (DESKTOP_IS_ACTIVE (desktop))
938 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[ACTIVATE_DESKTOP], 0, desktop);
939 }
943 SPDesktop *
944 inkscape_find_desktop_by_dkey (unsigned int dkey)
945 {
946 for (GSList *r = inkscape->desktops; r; r = r->next) {
947 if (((SPDesktop *) r->data)->dkey == dkey)
948 return ((SPDesktop *) r->data);
949 }
950 return NULL;
951 }
956 unsigned int
957 inkscape_maximum_dkey()
958 {
959 unsigned int dkey = 0;
961 for (GSList *r = inkscape->desktops; r; r = r->next) {
962 if (((SPDesktop *) r->data)->dkey > dkey)
963 dkey = ((SPDesktop *) r->data)->dkey;
964 }
966 return dkey;
967 }
971 SPDesktop *
972 inkscape_next_desktop ()
973 {
974 SPDesktop *d = NULL;
975 unsigned int dkey_current = ((SPDesktop *) inkscape->desktops->data)->dkey;
977 if (dkey_current < inkscape_maximum_dkey()) {
978 // find next existing
979 for (unsigned int i = dkey_current + 1; i <= inkscape_maximum_dkey(); i++) {
980 d = inkscape_find_desktop_by_dkey (i);
981 if (d) {
982 break;
983 }
984 }
985 } else {
986 // find first existing
987 for (unsigned int i = 0; i <= inkscape_maximum_dkey(); i++) {
988 d = inkscape_find_desktop_by_dkey (i);
989 if (d) {
990 break;
991 }
992 }
993 }
995 g_assert (d);
997 return d;
998 }
1002 SPDesktop *
1003 inkscape_prev_desktop ()
1004 {
1005 SPDesktop *d = NULL;
1006 unsigned int dkey_current = ((SPDesktop *) inkscape->desktops->data)->dkey;
1008 if (dkey_current > 0) {
1009 // find prev existing
1010 for (signed int i = dkey_current - 1; i >= 0; i--) {
1011 d = inkscape_find_desktop_by_dkey (i);
1012 if (d) {
1013 break;
1014 }
1015 }
1016 }
1017 if (!d) {
1018 // find last existing
1019 d = inkscape_find_desktop_by_dkey (inkscape_maximum_dkey());
1020 }
1022 g_assert (d);
1024 return d;
1025 }
1029 void
1030 inkscape_switch_desktops_next ()
1031 {
1032 inkscape_next_desktop()->presentWindow();
1033 }
1037 void
1038 inkscape_switch_desktops_prev ()
1039 {
1040 inkscape_prev_desktop()->presentWindow();
1041 }
1045 void
1046 inkscape_dialogs_hide ()
1047 {
1048 if (Inkscape::NSApplication::Application::getNewGui())
1049 Inkscape::NSApplication::Editor::hideDialogs();
1050 else
1051 {
1052 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[DIALOGS_HIDE], 0);
1053 inkscape->dialogs_toggle = FALSE;
1054 }
1055 }
1059 void
1060 inkscape_dialogs_unhide ()
1061 {
1062 if (Inkscape::NSApplication::Application::getNewGui())
1063 Inkscape::NSApplication::Editor::unhideDialogs();
1064 else
1065 {
1066 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[DIALOGS_UNHIDE], 0);
1067 inkscape->dialogs_toggle = TRUE;
1068 }
1069 }
1073 void
1074 inkscape_dialogs_toggle ()
1075 {
1076 if (inkscape->dialogs_toggle) {
1077 inkscape_dialogs_hide ();
1078 } else {
1079 inkscape_dialogs_unhide ();
1080 }
1081 }
1083 void
1084 inkscape_external_change ()
1085 {
1086 g_return_if_fail (inkscape != NULL);
1088 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[EXTERNAL_CHANGE], 0);
1089 }
1091 /**
1092 * fixme: These need probably signals too
1093 */
1094 void
1095 inkscape_add_document (SPDocument *document)
1096 {
1097 g_return_if_fail (document != NULL);
1099 if (!Inkscape::NSApplication::Application::getNewGui())
1100 {
1101 g_assert (!g_slist_find (inkscape->documents, document));
1102 inkscape->documents = g_slist_append (inkscape->documents, document);
1103 }
1104 else
1105 {
1106 Inkscape::NSApplication::Editor::addDocument (document);
1107 }
1108 }
1112 void
1113 inkscape_remove_document (SPDocument *document)
1114 {
1115 g_return_if_fail (document != NULL);
1117 if (!Inkscape::NSApplication::Application::getNewGui())
1118 {
1119 g_assert (g_slist_find (inkscape->documents, document));
1120 inkscape->documents = g_slist_remove (inkscape->documents, document);
1121 }
1122 else
1123 {
1124 Inkscape::NSApplication::Editor::removeDocument (document);
1125 }
1127 return;
1128 }
1130 SPDesktop *
1131 inkscape_active_desktop (void)
1132 {
1133 if (Inkscape::NSApplication::Application::getNewGui())
1134 return Inkscape::NSApplication::Editor::getActiveDesktop();
1136 if (inkscape->desktops == NULL) {
1137 return NULL;
1138 }
1140 return (SPDesktop *) inkscape->desktops->data;
1141 }
1143 SPDocument *
1144 inkscape_active_document (void)
1145 {
1146 if (Inkscape::NSApplication::Application::getNewGui())
1147 return Inkscape::NSApplication::Editor::getActiveDocument();
1149 if (SP_ACTIVE_DESKTOP) {
1150 return sp_desktop_document (SP_ACTIVE_DESKTOP);
1151 }
1153 return NULL;
1154 }
1156 bool inkscape_is_sole_desktop_for_document(SPDesktop const &desktop) {
1157 SPDocument const* document = desktop.doc();
1158 if (!document) {
1159 return false;
1160 }
1161 for ( GSList *iter = inkscape->desktops ; iter ; iter = iter->next ) {
1162 SPDesktop *other_desktop=(SPDesktop *)iter->data;
1163 SPDocument *other_document=other_desktop->doc();
1164 if ( other_document == document && other_desktop != &desktop ) {
1165 return false;
1166 }
1167 }
1168 return true;
1169 }
1171 SPEventContext *
1172 inkscape_active_event_context (void)
1173 {
1174 if (SP_ACTIVE_DESKTOP) {
1175 return sp_desktop_event_context (SP_ACTIVE_DESKTOP);
1176 }
1178 return NULL;
1179 }
1183 /*#####################
1184 # HELPERS
1185 #####################*/
1187 static bool
1188 inkscape_init_config (Inkscape::XML::Document *doc, const gchar *config_name, const gchar *skeleton,
1189 unsigned int skel_size,
1190 const gchar *e_mkdir,
1191 const gchar *e_notdir,
1192 const gchar *e_ccf,
1193 const gchar *e_cwf,
1194 const gchar *warn)
1195 {
1196 gchar *dn = profile_path(NULL);
1197 bool use_gui = (Inkscape::NSApplication::Application::getNewGui())? Inkscape::NSApplication::Application::getUseGui() : inkscape->use_gui;
1198 if (!Inkscape::IO::file_test(dn, G_FILE_TEST_EXISTS)) {
1199 if (Inkscape::IO::mkdir_utf8name(dn))
1200 {
1201 if (use_gui) {
1202 // Cannot create directory
1203 gchar *safeDn = Inkscape::IO::sanitizeString(dn);
1204 GtkWidget *w = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, e_mkdir, safeDn, warn);
1205 gtk_dialog_run (GTK_DIALOG (w));
1206 gtk_widget_destroy (w);
1207 g_free(safeDn);
1208 g_free (dn);
1209 return false;
1210 } else {
1211 g_warning(e_mkdir, dn, warn);
1212 g_free (dn);
1213 return false;
1214 }
1215 }
1216 } else if (!Inkscape::IO::file_test(dn, G_FILE_TEST_IS_DIR)) {
1217 if (use_gui) {
1218 // Not a directory
1219 gchar *safeDn = Inkscape::IO::sanitizeString(dn);
1220 GtkWidget *w = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, e_notdir, safeDn, warn);
1221 gtk_dialog_run (GTK_DIALOG (w));
1222 gtk_widget_destroy (w);
1223 g_free( safeDn );
1224 g_free (dn);
1225 return false;
1226 } else {
1227 g_warning(e_notdir, dn, warn);
1228 g_free(dn);
1229 return false;
1230 }
1231 }
1232 g_free (dn);
1234 gchar *fn = profile_path(config_name);
1236 Inkscape::IO::dump_fopen_call(fn, "H");
1237 FILE *fh = Inkscape::IO::fopen_utf8name(fn, "w");
1238 if (!fh) {
1239 if (use_gui) {
1240 /* Cannot create file */
1241 gchar *safeFn = Inkscape::IO::sanitizeString(fn);
1242 GtkWidget *w = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, e_ccf, safeFn, warn);
1243 gtk_dialog_run (GTK_DIALOG (w));
1244 gtk_widget_destroy (w);
1245 g_free(safeFn);
1246 g_free (fn);
1247 return false;
1248 } else {
1249 g_warning(e_ccf, fn, warn);
1250 g_free(fn);
1251 return false;
1252 }
1253 }
1254 if ( fwrite(skeleton, 1, skel_size, fh) != skel_size ) {
1255 if (use_gui) {
1256 /* Cannot create file */
1257 gchar *safeFn = Inkscape::IO::sanitizeString(fn);
1258 GtkWidget *w = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, e_cwf, safeFn, warn);
1259 gtk_dialog_run (GTK_DIALOG (w));
1260 gtk_widget_destroy (w);
1261 g_free(safeFn);
1262 g_free (fn);
1263 fclose(fh);
1264 return false;
1265 } else {
1266 g_warning(e_cwf, fn, warn);
1267 g_free(fn);
1268 fclose(fh);
1269 return false;
1270 }
1271 }
1273 g_free(fn);
1274 fclose(fh);
1275 return true;
1276 }
1278 void
1279 inkscape_refresh_display (Inkscape::Application *inkscape)
1280 {
1281 for (GSList *l = inkscape->desktops; l != NULL; l = l->next) {
1282 (static_cast<Inkscape::UI::View::View*>(l->data))->requestRedraw();
1283 }
1284 }
1287 /**
1288 * Handler for Inkscape's Exit verb. This emits the shutdown signal,
1289 * saves the preferences if appropriate, and quits.
1290 */
1291 void
1292 inkscape_exit (Inkscape::Application *inkscape)
1293 {
1294 g_assert (INKSCAPE);
1296 //emit shutdown signal so that dialogs could remember layout
1297 g_signal_emit (G_OBJECT (INKSCAPE), inkscape_signals[SHUTDOWN_SIGNAL], 0);
1299 Inkscape::Preferences::save();
1300 gtk_main_quit ();
1301 }
1303 gchar *
1304 homedir_path(const char *filename)
1305 {
1306 static const gchar *homedir = NULL;
1307 if (!homedir) {
1308 homedir = g_get_home_dir();
1309 gchar* utf8Path = g_filename_to_utf8( homedir, -1, NULL, NULL, NULL );
1310 if ( utf8Path )
1311 {
1312 homedir = utf8Path;
1313 if (!g_utf8_validate(homedir, -1, NULL)) {
1314 g_warning( "g_get_home_dir() post A IS NOT UTF-8" );
1315 }
1316 }
1317 }
1318 if (!homedir) {
1319 gchar * path = g_path_get_dirname(INKSCAPE->argv0);
1320 gchar* utf8Path = g_filename_to_utf8( path, -1, NULL, NULL, NULL );
1321 g_free(path);
1322 if ( utf8Path )
1323 {
1324 homedir = utf8Path;
1325 if (!g_utf8_validate(homedir, -1, NULL)) {
1326 g_warning( "g_get_home_dir() post B IS NOT UTF-8" );
1327 }
1328 }
1329 }
1330 return g_build_filename(homedir, filename, NULL);
1331 }
1334 /**
1335 * Get, or guess, or decide the location where the preferences.xml
1336 * file should be located.
1337 */
1338 gchar *
1339 profile_path(const char *filename)
1340 {
1341 static const gchar *prefdir = NULL;
1342 if (!prefdir) {
1343 #ifdef HAS_SHGetSpecialFolderLocation
1344 // prefer c:\Documents and Settings\UserName\Application Data\ to
1345 // c:\Documents and Settings\userName\;
1346 if (!prefdir) {
1347 ITEMIDLIST *pidl = 0;
1348 if ( SHGetSpecialFolderLocation( NULL, CSIDL_APPDATA, &pidl ) == NOERROR ) {
1349 gchar * utf8Path = NULL;
1351 if ( PrintWin32::is_os_wide() ) {
1352 wchar_t pathBuf[MAX_PATH+1];
1353 g_assert(sizeof(wchar_t) == sizeof(gunichar2));
1355 if ( SHGetPathFromIDListW( pidl, pathBuf ) ) {
1356 utf8Path = g_utf16_to_utf8( (gunichar2*)(&pathBuf[0]), -1, NULL, NULL, NULL );
1357 }
1358 } else {
1359 char pathBuf[MAX_PATH+1];
1361 if ( SHGetPathFromIDListA( pidl, pathBuf ) ) {
1362 utf8Path = g_filename_to_utf8( pathBuf, -1, NULL, NULL, NULL );
1363 }
1364 }
1366 if ( utf8Path ) {
1367 if (!g_utf8_validate(utf8Path, -1, NULL)) {
1368 g_warning( "SHGetPathFromIDList%c() resulted in invalid UTF-8", (PrintWin32::is_os_wide() ? 'W' : 'A') );
1369 g_free( utf8Path );
1370 utf8Path = 0;
1371 } else {
1372 prefdir = utf8Path;
1373 }
1374 }
1377 /* not compiling yet...
1379 // Remember to free the list pointer
1380 IMalloc * imalloc = 0;
1381 if ( SHGetMalloc(&imalloc) == NOERROR) {
1382 imalloc->lpVtbl->Free( imalloc, pidl );
1383 imalloc->lpVtbl->Release( imalloc );
1384 }
1385 */
1386 }
1387 }
1388 #endif
1389 if (!prefdir) {
1390 prefdir = homedir_path(NULL);
1391 }
1392 }
1393 return g_build_filename(prefdir, INKSCAPE_PROFILE_DIR, filename, NULL);
1394 }
1396 Inkscape::XML::Node *
1397 inkscape_get_menus (Inkscape::Application * inkscape)
1398 {
1399 Inkscape::XML::Node *repr = sp_repr_document_root (inkscape->menus);
1400 g_assert (!(strcmp (repr->name(), "inkscape")));
1401 return repr->firstChild();
1402 }
1404 void
1405 inkscape_get_all_desktops(std::list< SPDesktop* >& listbuf)
1406 {
1407 for(GSList* l = inkscape->desktops; l != NULL; l = l->next) {
1408 listbuf.push_back(static_cast< SPDesktop* >(l->data));
1409 }
1410 }
1414 /*
1415 Local Variables:
1416 mode:c++
1417 c-file-style:"stroustrup"
1418 c-file-offsets:((innamespace . 0)(inline-open . 0))
1419 indent-tabs-mode:nil
1420 fill-column:99
1421 End:
1422 */
1423 // vim: expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :