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 if (!repr) return NULL;
717 g_assert (!(strcmp (repr->name(), "inkscape")));
719 gchar const *s = key;
720 while ((s) && (*s)) {
722 /* Find next name */
723 gchar const *e = strchr (s, '.');
724 guint len;
725 if (e) {
726 len = e++ - s;
727 } else {
728 len = strlen (s);
729 }
731 Inkscape::XML::Node* child;
732 for (child = repr->firstChild(); child != NULL; child = child->next()) {
733 gchar const *id = child->attribute("id");
734 if ((id) && (strlen (id) == len) && (!strncmp (id, s, len)))
735 {
736 break;
737 }
738 }
739 if (child == NULL) {
740 return NULL;
741 }
743 repr = child;
744 s = e;
745 }
746 return repr;
747 }
751 void
752 inkscape_selection_modified (Inkscape::Selection *selection, guint flags)
753 {
754 if (Inkscape::NSApplication::Application::getNewGui()) {
755 Inkscape::NSApplication::Editor::selectionModified (selection, flags);
756 return;
757 }
758 g_return_if_fail (selection != NULL);
760 if (DESKTOP_IS_ACTIVE (selection->desktop())) {
761 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[MODIFY_SELECTION], 0, selection, flags);
762 }
763 }
766 void
767 inkscape_selection_changed (Inkscape::Selection * selection)
768 {
769 if (Inkscape::NSApplication::Application::getNewGui()) {
770 Inkscape::NSApplication::Editor::selectionChanged (selection);
771 return;
772 }
773 g_return_if_fail (selection != NULL);
775 if (DESKTOP_IS_ACTIVE (selection->desktop())) {
776 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[CHANGE_SELECTION], 0, selection);
777 }
778 }
780 void
781 inkscape_subselection_changed (SPDesktop *desktop)
782 {
783 if (Inkscape::NSApplication::Application::getNewGui()) {
784 Inkscape::NSApplication::Editor::subSelectionChanged (desktop);
785 return;
786 }
787 g_return_if_fail (desktop != NULL);
789 if (DESKTOP_IS_ACTIVE (desktop)) {
790 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[CHANGE_SUBSELECTION], 0, desktop);
791 }
792 }
795 void
796 inkscape_selection_set (Inkscape::Selection * selection)
797 {
798 if (Inkscape::NSApplication::Application::getNewGui()) {
799 Inkscape::NSApplication::Editor::selectionSet (selection);
800 return;
801 }
802 g_return_if_fail (selection != NULL);
804 if (DESKTOP_IS_ACTIVE (selection->desktop())) {
805 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[SET_SELECTION], 0, selection);
806 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[CHANGE_SELECTION], 0, selection);
807 }
808 }
811 void
812 inkscape_eventcontext_set (SPEventContext * eventcontext)
813 {
814 if (Inkscape::NSApplication::Application::getNewGui()) {
815 Inkscape::NSApplication::Editor::eventContextSet (eventcontext);
816 return;
817 }
818 g_return_if_fail (eventcontext != NULL);
819 g_return_if_fail (SP_IS_EVENT_CONTEXT (eventcontext));
821 if (DESKTOP_IS_ACTIVE (eventcontext->desktop)) {
822 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[SET_EVENTCONTEXT], 0, eventcontext);
823 }
824 }
827 void
828 inkscape_add_desktop (SPDesktop * desktop)
829 {
830 g_return_if_fail (desktop != NULL);
832 if (Inkscape::NSApplication::Application::getNewGui())
833 {
834 Inkscape::NSApplication::Editor::addDesktop (desktop);
835 return;
836 }
837 g_return_if_fail (inkscape != NULL);
839 g_assert (!g_slist_find (inkscape->desktops, desktop));
841 inkscape->desktops = g_slist_append (inkscape->desktops, desktop);
843 if (DESKTOP_IS_ACTIVE (desktop)) {
844 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[ACTIVATE_DESKTOP], 0, desktop);
845 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[SET_EVENTCONTEXT], 0, sp_desktop_event_context (desktop));
846 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[SET_SELECTION], 0, sp_desktop_selection (desktop));
847 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[CHANGE_SELECTION], 0, sp_desktop_selection (desktop));
848 }
849 }
853 void
854 inkscape_remove_desktop (SPDesktop * desktop)
855 {
856 g_return_if_fail (desktop != NULL);
857 if (Inkscape::NSApplication::Application::getNewGui())
858 {
859 Inkscape::NSApplication::Editor::removeDesktop (desktop);
860 return;
861 }
862 g_return_if_fail (inkscape != NULL);
864 g_assert (g_slist_find (inkscape->desktops, desktop));
866 if (DESKTOP_IS_ACTIVE (desktop)) {
867 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[DEACTIVATE_DESKTOP], 0, desktop);
868 if (inkscape->desktops->next != NULL) {
869 SPDesktop * new_desktop = (SPDesktop *) inkscape->desktops->next->data;
870 inkscape->desktops = g_slist_remove (inkscape->desktops, new_desktop);
871 inkscape->desktops = g_slist_prepend (inkscape->desktops, new_desktop);
872 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[ACTIVATE_DESKTOP], 0, new_desktop);
873 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[SET_EVENTCONTEXT], 0, sp_desktop_event_context (new_desktop));
874 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[SET_SELECTION], 0, sp_desktop_selection (new_desktop));
875 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[CHANGE_SELECTION], 0, sp_desktop_selection (new_desktop));
876 } else {
877 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[SET_EVENTCONTEXT], 0, NULL);
878 if (sp_desktop_selection(desktop))
879 sp_desktop_selection(desktop)->clear();
880 }
881 }
883 inkscape->desktops = g_slist_remove (inkscape->desktops, desktop);
885 // if this was the last desktop, shut down the program
886 if (inkscape->desktops == NULL) {
887 inkscape_exit (inkscape);
888 }
889 }
893 void
894 inkscape_activate_desktop (SPDesktop * desktop)
895 {
896 g_return_if_fail (desktop != NULL);
897 if (Inkscape::NSApplication::Application::getNewGui())
898 {
899 Inkscape::NSApplication::Editor::activateDesktop (desktop);
900 return;
901 }
902 g_return_if_fail (inkscape != NULL);
904 if (DESKTOP_IS_ACTIVE (desktop)) {
905 return;
906 }
908 g_assert (g_slist_find (inkscape->desktops, desktop));
910 SPDesktop *current = (SPDesktop *) inkscape->desktops->data;
912 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[DEACTIVATE_DESKTOP], 0, current);
914 inkscape->desktops = g_slist_remove (inkscape->desktops, desktop);
915 inkscape->desktops = g_slist_prepend (inkscape->desktops, desktop);
917 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[ACTIVATE_DESKTOP], 0, desktop);
918 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[SET_EVENTCONTEXT], 0, sp_desktop_event_context (desktop));
919 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[SET_SELECTION], 0, sp_desktop_selection (desktop));
920 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[CHANGE_SELECTION], 0, sp_desktop_selection (desktop));
921 }
924 /**
925 * Resends ACTIVATE_DESKTOP for current desktop; needed when a new desktop has got its window that dialogs will transientize to
926 */
927 void
928 inkscape_reactivate_desktop (SPDesktop * desktop)
929 {
930 g_return_if_fail (desktop != NULL);
931 if (Inkscape::NSApplication::Application::getNewGui())
932 {
933 Inkscape::NSApplication::Editor::reactivateDesktop (desktop);
934 return;
935 }
936 g_return_if_fail (inkscape != NULL);
938 if (DESKTOP_IS_ACTIVE (desktop))
939 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[ACTIVATE_DESKTOP], 0, desktop);
940 }
944 SPDesktop *
945 inkscape_find_desktop_by_dkey (unsigned int dkey)
946 {
947 for (GSList *r = inkscape->desktops; r; r = r->next) {
948 if (((SPDesktop *) r->data)->dkey == dkey)
949 return ((SPDesktop *) r->data);
950 }
951 return NULL;
952 }
957 unsigned int
958 inkscape_maximum_dkey()
959 {
960 unsigned int dkey = 0;
962 for (GSList *r = inkscape->desktops; r; r = r->next) {
963 if (((SPDesktop *) r->data)->dkey > dkey)
964 dkey = ((SPDesktop *) r->data)->dkey;
965 }
967 return dkey;
968 }
972 SPDesktop *
973 inkscape_next_desktop ()
974 {
975 SPDesktop *d = NULL;
976 unsigned int dkey_current = ((SPDesktop *) inkscape->desktops->data)->dkey;
978 if (dkey_current < inkscape_maximum_dkey()) {
979 // find next existing
980 for (unsigned int i = dkey_current + 1; i <= inkscape_maximum_dkey(); i++) {
981 d = inkscape_find_desktop_by_dkey (i);
982 if (d) {
983 break;
984 }
985 }
986 } else {
987 // find first existing
988 for (unsigned int i = 0; i <= inkscape_maximum_dkey(); i++) {
989 d = inkscape_find_desktop_by_dkey (i);
990 if (d) {
991 break;
992 }
993 }
994 }
996 g_assert (d);
998 return d;
999 }
1003 SPDesktop *
1004 inkscape_prev_desktop ()
1005 {
1006 SPDesktop *d = NULL;
1007 unsigned int dkey_current = ((SPDesktop *) inkscape->desktops->data)->dkey;
1009 if (dkey_current > 0) {
1010 // find prev existing
1011 for (signed int i = dkey_current - 1; i >= 0; i--) {
1012 d = inkscape_find_desktop_by_dkey (i);
1013 if (d) {
1014 break;
1015 }
1016 }
1017 }
1018 if (!d) {
1019 // find last existing
1020 d = inkscape_find_desktop_by_dkey (inkscape_maximum_dkey());
1021 }
1023 g_assert (d);
1025 return d;
1026 }
1030 void
1031 inkscape_switch_desktops_next ()
1032 {
1033 inkscape_next_desktop()->presentWindow();
1034 }
1038 void
1039 inkscape_switch_desktops_prev ()
1040 {
1041 inkscape_prev_desktop()->presentWindow();
1042 }
1046 void
1047 inkscape_dialogs_hide ()
1048 {
1049 if (Inkscape::NSApplication::Application::getNewGui())
1050 Inkscape::NSApplication::Editor::hideDialogs();
1051 else
1052 {
1053 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[DIALOGS_HIDE], 0);
1054 inkscape->dialogs_toggle = FALSE;
1055 }
1056 }
1060 void
1061 inkscape_dialogs_unhide ()
1062 {
1063 if (Inkscape::NSApplication::Application::getNewGui())
1064 Inkscape::NSApplication::Editor::unhideDialogs();
1065 else
1066 {
1067 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[DIALOGS_UNHIDE], 0);
1068 inkscape->dialogs_toggle = TRUE;
1069 }
1070 }
1074 void
1075 inkscape_dialogs_toggle ()
1076 {
1077 if (inkscape->dialogs_toggle) {
1078 inkscape_dialogs_hide ();
1079 } else {
1080 inkscape_dialogs_unhide ();
1081 }
1082 }
1084 void
1085 inkscape_external_change ()
1086 {
1087 g_return_if_fail (inkscape != NULL);
1089 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[EXTERNAL_CHANGE], 0);
1090 }
1092 /**
1093 * fixme: These need probably signals too
1094 */
1095 void
1096 inkscape_add_document (SPDocument *document)
1097 {
1098 g_return_if_fail (document != NULL);
1100 if (!Inkscape::NSApplication::Application::getNewGui())
1101 {
1102 g_assert (!g_slist_find (inkscape->documents, document));
1103 inkscape->documents = g_slist_append (inkscape->documents, document);
1104 }
1105 else
1106 {
1107 Inkscape::NSApplication::Editor::addDocument (document);
1108 }
1109 }
1113 void
1114 inkscape_remove_document (SPDocument *document)
1115 {
1116 g_return_if_fail (document != NULL);
1118 if (!Inkscape::NSApplication::Application::getNewGui())
1119 {
1120 g_assert (g_slist_find (inkscape->documents, document));
1121 inkscape->documents = g_slist_remove (inkscape->documents, document);
1122 }
1123 else
1124 {
1125 Inkscape::NSApplication::Editor::removeDocument (document);
1126 }
1128 return;
1129 }
1131 SPDesktop *
1132 inkscape_active_desktop (void)
1133 {
1134 if (Inkscape::NSApplication::Application::getNewGui())
1135 return Inkscape::NSApplication::Editor::getActiveDesktop();
1137 if (inkscape->desktops == NULL) {
1138 return NULL;
1139 }
1141 return (SPDesktop *) inkscape->desktops->data;
1142 }
1144 SPDocument *
1145 inkscape_active_document (void)
1146 {
1147 if (Inkscape::NSApplication::Application::getNewGui())
1148 return Inkscape::NSApplication::Editor::getActiveDocument();
1150 if (SP_ACTIVE_DESKTOP) {
1151 return sp_desktop_document (SP_ACTIVE_DESKTOP);
1152 }
1154 return NULL;
1155 }
1157 bool inkscape_is_sole_desktop_for_document(SPDesktop const &desktop) {
1158 SPDocument const* document = desktop.doc();
1159 if (!document) {
1160 return false;
1161 }
1162 for ( GSList *iter = inkscape->desktops ; iter ; iter = iter->next ) {
1163 SPDesktop *other_desktop=(SPDesktop *)iter->data;
1164 SPDocument *other_document=other_desktop->doc();
1165 if ( other_document == document && other_desktop != &desktop ) {
1166 return false;
1167 }
1168 }
1169 return true;
1170 }
1172 SPEventContext *
1173 inkscape_active_event_context (void)
1174 {
1175 if (SP_ACTIVE_DESKTOP) {
1176 return sp_desktop_event_context (SP_ACTIVE_DESKTOP);
1177 }
1179 return NULL;
1180 }
1184 /*#####################
1185 # HELPERS
1186 #####################*/
1188 static bool
1189 inkscape_init_config (Inkscape::XML::Document *doc, const gchar *config_name, const gchar *skeleton,
1190 unsigned int skel_size,
1191 const gchar *e_mkdir,
1192 const gchar *e_notdir,
1193 const gchar *e_ccf,
1194 const gchar *e_cwf,
1195 const gchar *warn)
1196 {
1197 gchar *dn = profile_path(NULL);
1198 bool use_gui = (Inkscape::NSApplication::Application::getNewGui())? Inkscape::NSApplication::Application::getUseGui() : inkscape->use_gui;
1199 if (!Inkscape::IO::file_test(dn, G_FILE_TEST_EXISTS)) {
1200 if (Inkscape::IO::mkdir_utf8name(dn))
1201 {
1202 if (use_gui) {
1203 // Cannot create directory
1204 gchar *safeDn = Inkscape::IO::sanitizeString(dn);
1205 GtkWidget *w = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, e_mkdir, safeDn, warn);
1206 gtk_dialog_run (GTK_DIALOG (w));
1207 gtk_widget_destroy (w);
1208 g_free(safeDn);
1209 g_free (dn);
1210 return false;
1211 } else {
1212 g_warning(e_mkdir, dn, warn);
1213 g_free (dn);
1214 return false;
1215 }
1216 }
1217 } else if (!Inkscape::IO::file_test(dn, G_FILE_TEST_IS_DIR)) {
1218 if (use_gui) {
1219 // Not a directory
1220 gchar *safeDn = Inkscape::IO::sanitizeString(dn);
1221 GtkWidget *w = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, e_notdir, safeDn, warn);
1222 gtk_dialog_run (GTK_DIALOG (w));
1223 gtk_widget_destroy (w);
1224 g_free( safeDn );
1225 g_free (dn);
1226 return false;
1227 } else {
1228 g_warning(e_notdir, dn, warn);
1229 g_free(dn);
1230 return false;
1231 }
1232 }
1233 g_free (dn);
1235 gchar *fn = profile_path(config_name);
1237 Inkscape::IO::dump_fopen_call(fn, "H");
1238 FILE *fh = Inkscape::IO::fopen_utf8name(fn, "w");
1239 if (!fh) {
1240 if (use_gui) {
1241 /* Cannot create file */
1242 gchar *safeFn = Inkscape::IO::sanitizeString(fn);
1243 GtkWidget *w = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, e_ccf, safeFn, warn);
1244 gtk_dialog_run (GTK_DIALOG (w));
1245 gtk_widget_destroy (w);
1246 g_free(safeFn);
1247 g_free (fn);
1248 return false;
1249 } else {
1250 g_warning(e_ccf, fn, warn);
1251 g_free(fn);
1252 return false;
1253 }
1254 }
1255 if ( fwrite(skeleton, 1, skel_size, fh) != skel_size ) {
1256 if (use_gui) {
1257 /* Cannot create file */
1258 gchar *safeFn = Inkscape::IO::sanitizeString(fn);
1259 GtkWidget *w = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, e_cwf, safeFn, warn);
1260 gtk_dialog_run (GTK_DIALOG (w));
1261 gtk_widget_destroy (w);
1262 g_free(safeFn);
1263 g_free (fn);
1264 fclose(fh);
1265 return false;
1266 } else {
1267 g_warning(e_cwf, fn, warn);
1268 g_free(fn);
1269 fclose(fh);
1270 return false;
1271 }
1272 }
1274 g_free(fn);
1275 fclose(fh);
1276 return true;
1277 }
1279 void
1280 inkscape_refresh_display (Inkscape::Application *inkscape)
1281 {
1282 for (GSList *l = inkscape->desktops; l != NULL; l = l->next) {
1283 (static_cast<Inkscape::UI::View::View*>(l->data))->requestRedraw();
1284 }
1285 }
1288 /**
1289 * Handler for Inkscape's Exit verb. This emits the shutdown signal,
1290 * saves the preferences if appropriate, and quits.
1291 */
1292 void
1293 inkscape_exit (Inkscape::Application *inkscape)
1294 {
1295 g_assert (INKSCAPE);
1297 //emit shutdown signal so that dialogs could remember layout
1298 g_signal_emit (G_OBJECT (INKSCAPE), inkscape_signals[SHUTDOWN_SIGNAL], 0);
1300 Inkscape::Preferences::save();
1301 gtk_main_quit ();
1302 }
1304 gchar *
1305 homedir_path(const char *filename)
1306 {
1307 static const gchar *homedir = NULL;
1308 if (!homedir) {
1309 homedir = g_get_home_dir();
1310 gchar* utf8Path = g_filename_to_utf8( homedir, -1, NULL, NULL, NULL );
1311 if ( utf8Path )
1312 {
1313 homedir = utf8Path;
1314 if (!g_utf8_validate(homedir, -1, NULL)) {
1315 g_warning( "g_get_home_dir() post A IS NOT UTF-8" );
1316 }
1317 }
1318 }
1319 if (!homedir) {
1320 gchar * path = g_path_get_dirname(INKSCAPE->argv0);
1321 gchar* utf8Path = g_filename_to_utf8( path, -1, NULL, NULL, NULL );
1322 g_free(path);
1323 if ( utf8Path )
1324 {
1325 homedir = utf8Path;
1326 if (!g_utf8_validate(homedir, -1, NULL)) {
1327 g_warning( "g_get_home_dir() post B IS NOT UTF-8" );
1328 }
1329 }
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 }
1388 }
1389 #endif
1390 if (!prefdir) {
1391 prefdir = homedir_path(NULL);
1392 }
1393 }
1394 return g_build_filename(prefdir, INKSCAPE_PROFILE_DIR, filename, NULL);
1395 }
1397 Inkscape::XML::Node *
1398 inkscape_get_menus (Inkscape::Application * inkscape)
1399 {
1400 Inkscape::XML::Node *repr = sp_repr_document_root (inkscape->menus);
1401 g_assert (!(strcmp (repr->name(), "inkscape")));
1402 return repr->firstChild();
1403 }
1405 void
1406 inkscape_get_all_desktops(std::list< SPDesktop* >& listbuf)
1407 {
1408 for(GSList* l = inkscape->desktops; l != NULL; l = l->next) {
1409 listbuf.push_back(static_cast< SPDesktop* >(l->data));
1410 }
1411 }
1415 /*
1416 Local Variables:
1417 mode:c++
1418 c-file-style:"stroustrup"
1419 c-file-offsets:((innamespace . 0)(inline-open . 0))
1420 indent-tabs-mode:nil
1421 fill-column:99
1422 End:
1423 */
1424 // vim: expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :