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 MENUS_FILE "menus.xml"
154 /**
155 * Retrieves the GType for the Inkscape Application object.
156 */
157 GType
158 inkscape_get_type (void)
159 {
160 static GType type = 0;
161 if (!type) {
162 GTypeInfo info = {
163 sizeof (Inkscape::ApplicationClass),
164 NULL, NULL,
165 (GClassInitFunc) inkscape_class_init,
166 NULL, NULL,
167 sizeof (Inkscape::Application),
168 4,
169 (GInstanceInitFunc) inkscape_init,
170 NULL
171 };
172 type = g_type_register_static (G_TYPE_OBJECT, "Inkscape_Application", &info, (GTypeFlags)0);
173 }
174 return type;
175 }
178 /**
179 * Initializes the inkscape class, registering all of its signal handlers
180 * and virtual functions
181 */
182 static void
183 inkscape_class_init (Inkscape::ApplicationClass * klass)
184 {
185 GObjectClass * object_class;
187 object_class = (GObjectClass *) klass;
189 parent_class = (GObjectClass *)g_type_class_peek_parent (klass);
191 inkscape_signals[MODIFY_SELECTION] = g_signal_new ("modify_selection",
192 G_TYPE_FROM_CLASS (klass),
193 G_SIGNAL_RUN_FIRST,
194 G_STRUCT_OFFSET (Inkscape::ApplicationClass, modify_selection),
195 NULL, NULL,
196 sp_marshal_NONE__POINTER_UINT,
197 G_TYPE_NONE, 2,
198 G_TYPE_POINTER, G_TYPE_UINT);
199 inkscape_signals[CHANGE_SELECTION] = g_signal_new ("change_selection",
200 G_TYPE_FROM_CLASS (klass),
201 G_SIGNAL_RUN_FIRST,
202 G_STRUCT_OFFSET (Inkscape::ApplicationClass, change_selection),
203 NULL, NULL,
204 sp_marshal_NONE__POINTER,
205 G_TYPE_NONE, 1,
206 G_TYPE_POINTER);
207 inkscape_signals[CHANGE_SUBSELECTION] = g_signal_new ("change_subselection",
208 G_TYPE_FROM_CLASS (klass),
209 G_SIGNAL_RUN_FIRST,
210 G_STRUCT_OFFSET (Inkscape::ApplicationClass, change_subselection),
211 NULL, NULL,
212 sp_marshal_NONE__POINTER,
213 G_TYPE_NONE, 1,
214 G_TYPE_POINTER);
215 inkscape_signals[SET_SELECTION] = g_signal_new ("set_selection",
216 G_TYPE_FROM_CLASS (klass),
217 G_SIGNAL_RUN_FIRST,
218 G_STRUCT_OFFSET (Inkscape::ApplicationClass, set_selection),
219 NULL, NULL,
220 sp_marshal_NONE__POINTER,
221 G_TYPE_NONE, 1,
222 G_TYPE_POINTER);
223 inkscape_signals[SET_EVENTCONTEXT] = g_signal_new ("set_eventcontext",
224 G_TYPE_FROM_CLASS (klass),
225 G_SIGNAL_RUN_FIRST,
226 G_STRUCT_OFFSET (Inkscape::ApplicationClass, set_eventcontext),
227 NULL, NULL,
228 sp_marshal_NONE__POINTER,
229 G_TYPE_NONE, 1,
230 G_TYPE_POINTER);
231 inkscape_signals[ACTIVATE_DESKTOP] = g_signal_new ("activate_desktop",
232 G_TYPE_FROM_CLASS (klass),
233 G_SIGNAL_RUN_FIRST,
234 G_STRUCT_OFFSET (Inkscape::ApplicationClass, activate_desktop),
235 NULL, NULL,
236 sp_marshal_NONE__POINTER,
237 G_TYPE_NONE, 1,
238 G_TYPE_POINTER);
239 inkscape_signals[DEACTIVATE_DESKTOP] = g_signal_new ("deactivate_desktop",
240 G_TYPE_FROM_CLASS (klass),
241 G_SIGNAL_RUN_FIRST,
242 G_STRUCT_OFFSET (Inkscape::ApplicationClass, deactivate_desktop),
243 NULL, NULL,
244 sp_marshal_NONE__POINTER,
245 G_TYPE_NONE, 1,
246 G_TYPE_POINTER);
247 inkscape_signals[SHUTDOWN_SIGNAL] = g_signal_new ("shut_down",
248 G_TYPE_FROM_CLASS (klass),
249 G_SIGNAL_RUN_FIRST,
250 G_STRUCT_OFFSET (Inkscape::ApplicationClass, shut_down),
251 NULL, NULL,
252 g_cclosure_marshal_VOID__VOID,
253 G_TYPE_NONE, 0);
254 inkscape_signals[DIALOGS_HIDE] = g_signal_new ("dialogs_hide",
255 G_TYPE_FROM_CLASS (klass),
256 G_SIGNAL_RUN_FIRST,
257 G_STRUCT_OFFSET (Inkscape::ApplicationClass, dialogs_hide),
258 NULL, NULL,
259 g_cclosure_marshal_VOID__VOID,
260 G_TYPE_NONE, 0);
261 inkscape_signals[DIALOGS_UNHIDE] = g_signal_new ("dialogs_unhide",
262 G_TYPE_FROM_CLASS (klass),
263 G_SIGNAL_RUN_FIRST,
264 G_STRUCT_OFFSET (Inkscape::ApplicationClass, dialogs_unhide),
265 NULL, NULL,
266 g_cclosure_marshal_VOID__VOID,
267 G_TYPE_NONE, 0);
268 inkscape_signals[EXTERNAL_CHANGE] = g_signal_new ("external_change",
269 G_TYPE_FROM_CLASS (klass),
270 G_SIGNAL_RUN_FIRST,
271 G_STRUCT_OFFSET (Inkscape::ApplicationClass, external_change),
272 NULL, NULL,
273 g_cclosure_marshal_VOID__VOID,
274 G_TYPE_NONE, 0);
276 object_class->dispose = inkscape_dispose;
278 klass->activate_desktop = inkscape_activate_desktop_private;
279 klass->deactivate_desktop = inkscape_deactivate_desktop_private;
280 }
282 #ifdef WIN32
283 typedef int uid_t;
284 #define getuid() 0
285 #endif
287 /**
288 * static gint inkscape_autosave(gpointer);
289 *
290 * Callback passed to g_timeout_add_seconds()
291 * Responsible for autosaving all open documents
292 */
293 static gint inkscape_autosave(gpointer)
294 {
295 if (inkscape->document_set.empty()) { // nothing to autosave
296 return TRUE;
297 }
298 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
300 // Use UID for separating autosave-documents between users if directory is multiuser
301 uid_t uid = getuid();
303 Glib::ustring autosave_dir;
304 {
305 Glib::ustring tmp = prefs->getString("options.autosave", "path");
306 if (!tmp.empty()) {
307 autosave_dir = tmp;
308 } else {
309 autosave_dir = Glib::get_tmp_dir();
310 }
311 }
313 GDir *autosave_dir_ptr = g_dir_open(autosave_dir.c_str(), 0, NULL);
314 if( !autosave_dir_ptr ){
315 g_warning("Cannot open autosave directory!");
316 return TRUE;
317 }
319 time_t sptime = time(NULL);
320 struct tm *sptm = localtime(&sptime);
321 gchar sptstr[256];
322 strftime(sptstr, 256, "%Y_%m_%d_%H_%M_%S", sptm);
324 gint autosave_max = prefs->getInt("options.autosave", "max", 10);
326 gint docnum = 0;
328 SP_ACTIVE_DESKTOP->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Autosaving documents..."));
329 for (std::map<SPDocument*,int>::iterator iter = inkscape->document_set.begin();
330 iter != inkscape->document_set.end();
331 ++iter) {
333 SPDocument *doc = iter->first;
335 ++docnum;
337 Inkscape::XML::Node *repr = sp_document_repr_root(doc);
338 // g_debug("Document %d: \"%s\" %s", docnum, doc ? doc->name : "(null)", doc ? (doc->isModifiedSinceSave() ? "(dirty)" : "(clean)") : "(null)");
340 if (doc->isModifiedSinceSave()) {
341 gchar *oldest_autosave = 0;
342 const gchar *filename = 0;
343 struct stat sb;
344 time_t min_time = 0;
345 gint count = 0;
347 // Look for previous autosaves
348 gchar* baseName = g_strdup_printf( "inkscape-autosave-%d", uid );
349 g_dir_rewind(autosave_dir_ptr);
350 while( (filename = g_dir_read_name(autosave_dir_ptr)) != NULL ){
351 if ( strncmp(filename, baseName, strlen(baseName)) == 0 ){
352 gchar* full_path = g_build_filename( autosave_dir.c_str(), filename, NULL );
353 if ( g_stat(full_path, &sb) != -1 ) {
354 if ( difftime(sb.st_ctime, min_time) < 0 || min_time == 0 ){
355 min_time = sb.st_ctime;
356 if ( oldest_autosave ) {
357 g_free(oldest_autosave);
358 }
359 oldest_autosave = g_strdup(full_path);
360 }
361 count ++;
362 }
363 g_free(full_path);
364 }
365 }
367 // g_debug("%d previous autosaves exists. Max = %d", count, autosave_max);
369 // Have we reached the limit for number of autosaves?
370 if ( count >= autosave_max ){
371 // Remove the oldest file
372 if ( oldest_autosave ) {
373 unlink(oldest_autosave);
374 }
375 }
377 if ( oldest_autosave ) {
378 g_free(oldest_autosave);
379 oldest_autosave = 0;
380 }
383 // Set the filename we will actually save to
384 g_free(baseName);
385 baseName = g_strdup_printf("inkscape-autosave-%d-%s-%03d.svg", uid, sptstr, docnum);
386 gchar* full_path = g_build_filename(autosave_dir.c_str(), baseName, NULL);
387 g_free(baseName);
388 baseName = 0;
390 // g_debug("Filename: %s", full_path);
392 // Try to save the file
393 FILE *file = Inkscape::IO::fopen_utf8name(full_path, "w");
394 gchar *errortext = 0;
395 if (file) {
396 try{
397 sp_repr_save_stream(repr->document(), file, SP_SVG_NS_URI);
398 } catch (Inkscape::Extension::Output::no_extension_found &e) {
399 errortext = g_strdup(_("Autosave failed! Could not find inkscape extension to save document."));
400 } catch (Inkscape::Extension::Output::save_failed &e) {
401 gchar *safeUri = Inkscape::IO::sanitizeString(full_path);
402 errortext = g_strdup_printf(_("Autosave failed! File %s could not be saved."), safeUri);
403 g_free(safeUri);
404 }
405 fclose(file);
406 }
407 else {
408 gchar *safeUri = Inkscape::IO::sanitizeString(full_path);
409 errortext = g_strdup_printf(_("Autosave failed! File %s could not be saved."), safeUri);
410 g_free(safeUri);
411 }
413 if (errortext) {
414 SP_ACTIVE_DESKTOP->messageStack()->flash(Inkscape::ERROR_MESSAGE, errortext);
415 g_warning("%s", errortext);
416 g_free(errortext);
417 }
419 g_free(full_path);
420 }
421 }
422 g_dir_close(autosave_dir_ptr);
424 SP_ACTIVE_DESKTOP->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Autosave complete."));
426 return TRUE;
427 }
429 void inkscape_autosave_init()
430 {
431 static guint32 autosave_timeout_id = 0;
432 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
434 // Turn off any previously initiated timeouts
435 if ( autosave_timeout_id ) {
436 g_source_remove(autosave_timeout_id);
437 autosave_timeout_id = 0;
438 }
440 // g_debug("options.autosave.enable = %d", prefs->getBool("options.autosave", "enable", true));
441 // Is autosave enabled?
442 if (!prefs->getBool("options.autosave", "enable", true)){
443 autosave_timeout_id = 0;
444 } else {
445 // Turn on autosave
446 guint32 timeout = prefs->getInt("options.autosave", "interval", 10) * 60;
447 // g_debug("options.autosave.interval = %d", prefs->getInt("options.autosave", "interval", 10));
448 #if GLIB_CHECK_VERSION(2,14,0)
449 autosave_timeout_id = g_timeout_add_seconds(timeout, inkscape_autosave, NULL);
450 #else
451 autosave_timeout_id = g_timeout_add(timeout * 1000, inkscape_autosave, NULL);
452 #endif
453 }
454 }
457 static void
458 inkscape_init (SPObject * object)
459 {
460 if (!inkscape) {
461 inkscape = (Inkscape::Application *) object;
462 } else {
463 g_assert_not_reached ();
464 }
466 new (&inkscape->document_set) std::map<SPDocument *, int>();
468 inkscape->menus = sp_repr_read_mem (_(menus_skeleton), MENUS_SKELETON_SIZE, NULL);
470 inkscape->desktops = NULL;
472 inkscape->dialogs_toggle = TRUE;
474 inkscape->mapalt=GDK_MOD1_MASK;
475 }
477 static void
478 inkscape_dispose (GObject *object)
479 {
480 Inkscape::Application *inkscape = (Inkscape::Application *) object;
482 g_assert (!inkscape->desktops);
484 Inkscape::Preferences::unload();
486 if (inkscape->menus) {
487 /* fixme: This is not the best place */
488 Inkscape::GC::release(inkscape->menus);
489 inkscape->menus = NULL;
490 }
492 inkscape->document_set.~map();
494 G_OBJECT_CLASS (parent_class)->dispose (object);
496 gtk_main_quit ();
497 }
500 void
501 inkscape_ref (void)
502 {
503 if (inkscape)
504 g_object_ref (G_OBJECT (inkscape));
505 }
508 void
509 inkscape_unref (void)
510 {
511 if (inkscape)
512 g_object_unref (G_OBJECT (inkscape));
513 }
515 /* returns the mask of the keyboard modifier to map to Alt, zero if no mapping */
516 /* Needs to be a guint because gdktypes.h does not define a 'no-modifier' value */
517 guint
518 inkscape_mapalt() {
519 return inkscape->mapalt;
520 }
522 /* Sets the keyboard modifer to map to Alt. Zero switches off mapping, as does '1', which is the default */
523 void inkscape_mapalt(guint maskvalue)
524 {
525 if(maskvalue<2 || maskvalue> 5 ){ /* MOD5 is the highest defined in gdktypes.h */
526 inkscape->mapalt=0;
527 }else{
528 inkscape->mapalt=(GDK_MOD1_MASK << (maskvalue-1));
529 }
530 }
532 static void
533 inkscape_activate_desktop_private (Inkscape::Application */*inkscape*/, SPDesktop *desktop)
534 {
535 desktop->set_active (true);
536 }
539 static void
540 inkscape_deactivate_desktop_private (Inkscape::Application */*inkscape*/, SPDesktop *desktop)
541 {
542 desktop->set_active (false);
543 }
546 /* fixme: This is EVIL, and belongs to main after all */
548 #define SP_INDENT 8
551 static void
552 inkscape_crash_handler (int /*signum*/)
553 {
554 using Inkscape::Debug::SimpleEvent;
555 using Inkscape::Debug::EventTracker;
556 using Inkscape::Debug::Logger;
558 static gint recursion = FALSE;
560 /*
561 * reset all signal handlers: any further crashes should just be allowed
562 * to crash normally.
563 * */
564 signal (SIGSEGV, segv_handler );
565 signal (SIGABRT, abrt_handler );
566 signal (SIGFPE, fpe_handler );
567 signal (SIGILL, ill_handler );
568 #ifndef WIN32
569 signal (SIGBUS, bus_handler );
570 #endif
572 /* Stop bizarre loops */
573 if (recursion) {
574 abort ();
575 }
576 recursion = TRUE;
578 EventTracker<SimpleEvent<Inkscape::Debug::Event::CORE> > tracker("crash");
579 tracker.set<SimpleEvent<> >("emergency-save");
581 fprintf(stderr, "\nEmergency save activated!\n");
583 time_t sptime = time (NULL);
584 struct tm *sptm = localtime (&sptime);
585 gchar sptstr[256];
586 strftime (sptstr, 256, "%Y_%m_%d_%H_%M_%S", sptm);
588 gint count = 0;
589 GSList *savednames = NULL;
590 GSList *failednames = NULL;
591 for (std::map<SPDocument*,int>::iterator iter = inkscape->document_set.begin();
592 iter != inkscape->document_set.end();
593 ++iter) {
594 SPDocument *doc = iter->first;
595 Inkscape::XML::Node *repr;
596 repr = sp_document_repr_root (doc);
597 if (doc->isModifiedSinceSave()) {
598 const gchar *docname, *d0, *d;
599 gchar n[64], c[1024];
600 FILE *file;
602 /* originally, the document name was retrieved from
603 * the sodipod:docname attribute */
604 docname = doc->name;
605 if (docname) {
606 /* fixme: Quick hack to remove emergency file suffix */
607 d0 = strrchr ((char*)docname, '.');
608 if (d0 && (d0 > docname)) {
609 d0 = strrchr ((char*)(d0 - 1), '.');
610 if (d0 && (d0 > docname)) {
611 d = d0;
612 while (isdigit (*d) || (*d == '.') || (*d == '_')) d += 1;
613 if (*d) {
614 memcpy (n, docname, MIN (d0 - docname - 1, 64));
615 n[63] = '\0';
616 docname = n;
617 }
618 }
619 }
620 }
622 if (!docname || !*docname) docname = "emergency";
623 // try saving to the profile location
624 g_snprintf (c, 1024, "%.256s.%s.%d.svg", docname, sptstr, count);
625 gchar * location = homedir_path(c);
626 Inkscape::IO::dump_fopen_call(location, "E");
627 file = Inkscape::IO::fopen_utf8name(location, "w");
628 g_free(location);
629 if (!file) {
630 // try saving to /tmp
631 g_snprintf (c, 1024, "/tmp/inkscape-%.256s.%s.%d.svg", docname, sptstr, count);
632 Inkscape::IO::dump_fopen_call(c, "G");
633 file = Inkscape::IO::fopen_utf8name(c, "w");
634 }
635 if (!file) {
636 // try saving to the current directory
637 g_snprintf (c, 1024, "inkscape-%.256s.%s.%d.svg", docname, sptstr, count);
638 Inkscape::IO::dump_fopen_call(c, "F");
639 file = Inkscape::IO::fopen_utf8name(c, "w");
640 }
641 if (file) {
642 sp_repr_save_stream (repr->document(), file, SP_SVG_NS_URI);
643 savednames = g_slist_prepend (savednames, g_strdup (c));
644 fclose (file);
645 } else {
646 failednames = g_slist_prepend (failednames, (doc->name) ? g_strdup (doc->name) : g_strdup (_("Untitled document")));
647 }
648 count++;
649 }
650 }
652 savednames = g_slist_reverse (savednames);
653 failednames = g_slist_reverse (failednames);
654 if (savednames) {
655 fprintf (stderr, "\nEmergency save document locations:\n");
656 for (GSList *l = savednames; l != NULL; l = l->next) {
657 fprintf (stderr, " %s\n", (gchar *) l->data);
658 }
659 }
660 if (failednames) {
661 fprintf (stderr, "\nFailed to do emergency save for documents:\n");
662 for (GSList *l = failednames; l != NULL; l = l->next) {
663 fprintf (stderr, " %s\n", (gchar *) l->data);
664 }
665 }
667 Inkscape::Preferences::unload();
669 fprintf (stderr, "Emergency save completed. Inkscape will close now.\n");
670 fprintf (stderr, "If you can reproduce this crash, please file a bug at www.inkscape.org\n");
671 fprintf (stderr, "with a detailed description of the steps leading to the crash, so we can fix it.\n");
673 /* Show nice dialog box */
675 char const *istr = _("Inkscape encountered an internal error and will close now.\n");
676 char const *sstr = _("Automatic backups of unsaved documents were done to the following locations:\n");
677 char const *fstr = _("Automatic backup of the following documents failed:\n");
678 gint nllen = strlen ("\n");
679 gint len = strlen (istr) + strlen (sstr) + strlen (fstr);
680 for (GSList *l = savednames; l != NULL; l = l->next) {
681 len = len + SP_INDENT + strlen ((gchar *) l->data) + nllen;
682 }
683 for (GSList *l = failednames; l != NULL; l = l->next) {
684 len = len + SP_INDENT + strlen ((gchar *) l->data) + nllen;
685 }
686 len += 1;
687 gchar *b = g_new (gchar, len);
688 gint pos = 0;
689 len = strlen (istr);
690 memcpy (b + pos, istr, len);
691 pos += len;
692 if (savednames) {
693 len = strlen (sstr);
694 memcpy (b + pos, sstr, len);
695 pos += len;
696 for (GSList *l = savednames; l != NULL; l = l->next) {
697 memset (b + pos, ' ', SP_INDENT);
698 pos += SP_INDENT;
699 len = strlen ((gchar *) l->data);
700 memcpy (b + pos, l->data, len);
701 pos += len;
702 memcpy (b + pos, "\n", nllen);
703 pos += nllen;
704 }
705 }
706 if (failednames) {
707 len = strlen (fstr);
708 memcpy (b + pos, fstr, len);
709 pos += len;
710 for (GSList *l = failednames; l != NULL; l = l->next) {
711 memset (b + pos, ' ', SP_INDENT);
712 pos += SP_INDENT;
713 len = strlen ((gchar *) l->data);
714 memcpy (b + pos, l->data, len);
715 pos += len;
716 memcpy (b + pos, "\n", nllen);
717 pos += nllen;
718 }
719 }
720 *(b + pos) = '\0';
722 if ( inkscape_get_instance() && inkscape_app_use_gui( inkscape_get_instance() ) ) {
723 GtkWidget *msgbox = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, "%s", b);
724 gtk_dialog_run (GTK_DIALOG (msgbox));
725 gtk_widget_destroy (msgbox);
726 }
727 else
728 {
729 g_message( "Error: %s", b );
730 }
731 g_free (b);
733 tracker.clear();
734 Logger::shutdown();
736 /* on exit, allow restored signal handler to take over and crash us */
737 }
741 void
742 inkscape_application_init (const gchar *argv0, gboolean use_gui)
743 {
744 inkscape = (Inkscape::Application *)g_object_new (SP_TYPE_INKSCAPE, NULL);
745 /* fixme: load application defaults */
747 segv_handler = signal (SIGSEGV, inkscape_crash_handler);
748 abrt_handler = signal (SIGABRT, inkscape_crash_handler);
749 fpe_handler = signal (SIGFPE, inkscape_crash_handler);
750 ill_handler = signal (SIGILL, inkscape_crash_handler);
751 #ifndef WIN32
752 bus_handler = signal (SIGBUS, inkscape_crash_handler);
753 #endif
755 inkscape->use_gui = use_gui;
756 inkscape->argv0 = g_strdup(argv0);
758 /* Load the preferences and menus; Later menu layout should be merged into prefs */
759 Inkscape::Preferences::use_gui = use_gui;
760 Inkscape::Preferences::load();
761 Inkscape::Preferences *prefs = Inkscape::Preferences::get();
762 inkscape_load_menus(inkscape);
763 sp_input_load_from_preferences();
765 /* DebugDialog redirection. On Linux, default to OFF, on Win32, default to ON.
766 * Use only if use_gui is enabled
767 */
768 #ifdef WIN32
769 #define DEFAULT_LOG_REDIRECT true
770 #else
771 #define DEFAULT_LOG_REDIRECT false
772 #endif
774 if (use_gui == TRUE && prefs->getBool("dialogs.debug", "redirect", DEFAULT_LOG_REDIRECT))
775 {
776 Inkscape::UI::Dialogs::DebugDialog::getInstance()->captureLogMessages();
777 }
779 /* Check for global remapping of Alt key */
780 if(use_gui)
781 {
782 inkscape_mapalt(guint(prefs->getInt("options.mapalt", "value", 0)));
783 }
785 /* Initialize the extensions */
786 Inkscape::Extension::init();
788 inkscape_autosave_init();
790 return;
791 }
793 /**
794 * Returns the current Inkscape::Application global object
795 */
796 Inkscape::Application *
797 inkscape_get_instance()
798 {
799 return inkscape;
800 }
802 gboolean inkscape_app_use_gui( Inkscape::Application const * app )
803 {
804 return app->use_gui;
805 }
807 /**
808 * Menus management
809 *
810 */
811 bool inkscape_load_menus (Inkscape::Application */*inkscape*/)
812 {
813 gchar *fn = profile_path(MENUS_FILE);
814 gchar *menus_xml = NULL; gsize len = 0;
816 if (g_file_get_contents(fn, &menus_xml, &len, NULL)) {
817 // load the menus_xml file
818 INKSCAPE->menus = sp_repr_read_mem(menus_xml, len, NULL);
819 g_free(menus_xml);
820 if (INKSCAPE->menus) return true;
821 }
822 INKSCAPE->menus = sp_repr_read_mem(menus_skeleton, MENUS_SKELETON_SIZE, NULL);
823 if (INKSCAPE->menus) return true;
824 return false;
825 }
827 /**
828 * @deprecated Use the Preferences class instead, and try not to use _getNode
829 */
830 Inkscape::XML::Node *inkscape_get_repr(Inkscape::Application */*inkscape*/, const gchar *key)
831 {
832 Inkscape::Preferences *ps = Inkscape::Preferences::get();
833 return ps->_getNode(key);
834 }
837 void
838 inkscape_selection_modified (Inkscape::Selection *selection, guint flags)
839 {
840 if (Inkscape::NSApplication::Application::getNewGui()) {
841 Inkscape::NSApplication::Editor::selectionModified (selection, flags);
842 return;
843 }
844 g_return_if_fail (selection != NULL);
846 if (DESKTOP_IS_ACTIVE (selection->desktop())) {
847 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[MODIFY_SELECTION], 0, selection, flags);
848 }
849 }
852 void
853 inkscape_selection_changed (Inkscape::Selection * selection)
854 {
855 if (Inkscape::NSApplication::Application::getNewGui()) {
856 Inkscape::NSApplication::Editor::selectionChanged (selection);
857 return;
858 }
859 g_return_if_fail (selection != NULL);
861 if (DESKTOP_IS_ACTIVE (selection->desktop())) {
862 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[CHANGE_SELECTION], 0, selection);
863 }
864 }
866 void
867 inkscape_subselection_changed (SPDesktop *desktop)
868 {
869 if (Inkscape::NSApplication::Application::getNewGui()) {
870 Inkscape::NSApplication::Editor::subSelectionChanged (desktop);
871 return;
872 }
873 g_return_if_fail (desktop != NULL);
875 if (DESKTOP_IS_ACTIVE (desktop)) {
876 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[CHANGE_SUBSELECTION], 0, desktop);
877 }
878 }
881 void
882 inkscape_selection_set (Inkscape::Selection * selection)
883 {
884 if (Inkscape::NSApplication::Application::getNewGui()) {
885 Inkscape::NSApplication::Editor::selectionSet (selection);
886 return;
887 }
888 g_return_if_fail (selection != NULL);
890 if (DESKTOP_IS_ACTIVE (selection->desktop())) {
891 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[SET_SELECTION], 0, selection);
892 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[CHANGE_SELECTION], 0, selection);
893 }
894 }
897 void
898 inkscape_eventcontext_set (SPEventContext * eventcontext)
899 {
900 if (Inkscape::NSApplication::Application::getNewGui()) {
901 Inkscape::NSApplication::Editor::eventContextSet (eventcontext);
902 return;
903 }
904 g_return_if_fail (eventcontext != NULL);
905 g_return_if_fail (SP_IS_EVENT_CONTEXT (eventcontext));
907 if (DESKTOP_IS_ACTIVE (eventcontext->desktop)) {
908 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[SET_EVENTCONTEXT], 0, eventcontext);
909 }
910 }
913 void
914 inkscape_add_desktop (SPDesktop * desktop)
915 {
916 g_return_if_fail (desktop != NULL);
918 if (Inkscape::NSApplication::Application::getNewGui())
919 {
920 Inkscape::NSApplication::Editor::addDesktop (desktop);
921 return;
922 }
923 g_return_if_fail (inkscape != NULL);
925 g_assert (!g_slist_find (inkscape->desktops, desktop));
927 inkscape->desktops = g_slist_prepend (inkscape->desktops, desktop);
929 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[ACTIVATE_DESKTOP], 0, desktop);
930 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[SET_EVENTCONTEXT], 0, sp_desktop_event_context (desktop));
931 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[SET_SELECTION], 0, sp_desktop_selection (desktop));
932 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[CHANGE_SELECTION], 0, sp_desktop_selection (desktop));
933 }
937 void
938 inkscape_remove_desktop (SPDesktop * desktop)
939 {
940 g_return_if_fail (desktop != NULL);
941 if (Inkscape::NSApplication::Application::getNewGui())
942 {
943 Inkscape::NSApplication::Editor::removeDesktop (desktop);
944 return;
945 }
946 g_return_if_fail (inkscape != NULL);
948 g_assert (g_slist_find (inkscape->desktops, desktop));
950 if (DESKTOP_IS_ACTIVE (desktop)) {
951 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[DEACTIVATE_DESKTOP], 0, desktop);
952 if (inkscape->desktops->next != NULL) {
953 SPDesktop * new_desktop = (SPDesktop *) inkscape->desktops->next->data;
954 inkscape->desktops = g_slist_remove (inkscape->desktops, new_desktop);
955 inkscape->desktops = g_slist_prepend (inkscape->desktops, new_desktop);
956 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[ACTIVATE_DESKTOP], 0, new_desktop);
957 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[SET_EVENTCONTEXT], 0, sp_desktop_event_context (new_desktop));
958 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[SET_SELECTION], 0, sp_desktop_selection (new_desktop));
959 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[CHANGE_SELECTION], 0, sp_desktop_selection (new_desktop));
960 } else {
961 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[SET_EVENTCONTEXT], 0, NULL);
962 if (sp_desktop_selection(desktop))
963 sp_desktop_selection(desktop)->clear();
964 }
965 }
967 inkscape->desktops = g_slist_remove (inkscape->desktops, desktop);
969 // if this was the last desktop, shut down the program
970 if (inkscape->desktops == NULL) {
971 inkscape_exit (inkscape);
972 }
973 }
977 void
978 inkscape_activate_desktop (SPDesktop * desktop)
979 {
980 g_return_if_fail (desktop != NULL);
981 if (Inkscape::NSApplication::Application::getNewGui())
982 {
983 Inkscape::NSApplication::Editor::activateDesktop (desktop);
984 return;
985 }
986 g_return_if_fail (inkscape != NULL);
988 if (DESKTOP_IS_ACTIVE (desktop)) {
989 return;
990 }
992 g_assert (g_slist_find (inkscape->desktops, desktop));
994 SPDesktop *current = (SPDesktop *) inkscape->desktops->data;
996 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[DEACTIVATE_DESKTOP], 0, current);
998 inkscape->desktops = g_slist_remove (inkscape->desktops, desktop);
999 inkscape->desktops = g_slist_prepend (inkscape->desktops, desktop);
1001 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[ACTIVATE_DESKTOP], 0, desktop);
1002 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[SET_EVENTCONTEXT], 0, sp_desktop_event_context (desktop));
1003 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[SET_SELECTION], 0, sp_desktop_selection (desktop));
1004 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[CHANGE_SELECTION], 0, sp_desktop_selection (desktop));
1005 }
1008 /**
1009 * Resends ACTIVATE_DESKTOP for current desktop; needed when a new desktop has got its window that dialogs will transientize to
1010 */
1011 void
1012 inkscape_reactivate_desktop (SPDesktop * desktop)
1013 {
1014 g_return_if_fail (desktop != NULL);
1015 if (Inkscape::NSApplication::Application::getNewGui())
1016 {
1017 Inkscape::NSApplication::Editor::reactivateDesktop (desktop);
1018 return;
1019 }
1020 g_return_if_fail (inkscape != NULL);
1022 if (DESKTOP_IS_ACTIVE (desktop))
1023 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[ACTIVATE_DESKTOP], 0, desktop);
1024 }
1028 SPDesktop *
1029 inkscape_find_desktop_by_dkey (unsigned int dkey)
1030 {
1031 for (GSList *r = inkscape->desktops; r; r = r->next) {
1032 if (((SPDesktop *) r->data)->dkey == dkey)
1033 return ((SPDesktop *) r->data);
1034 }
1035 return NULL;
1036 }
1041 unsigned int
1042 inkscape_maximum_dkey()
1043 {
1044 unsigned int dkey = 0;
1046 for (GSList *r = inkscape->desktops; r; r = r->next) {
1047 if (((SPDesktop *) r->data)->dkey > dkey)
1048 dkey = ((SPDesktop *) r->data)->dkey;
1049 }
1051 return dkey;
1052 }
1056 SPDesktop *
1057 inkscape_next_desktop ()
1058 {
1059 SPDesktop *d = NULL;
1060 unsigned int dkey_current = ((SPDesktop *) inkscape->desktops->data)->dkey;
1062 if (dkey_current < inkscape_maximum_dkey()) {
1063 // find next existing
1064 for (unsigned int i = dkey_current + 1; i <= inkscape_maximum_dkey(); i++) {
1065 d = inkscape_find_desktop_by_dkey (i);
1066 if (d) {
1067 break;
1068 }
1069 }
1070 } else {
1071 // find first existing
1072 for (unsigned int i = 0; i <= inkscape_maximum_dkey(); i++) {
1073 d = inkscape_find_desktop_by_dkey (i);
1074 if (d) {
1075 break;
1076 }
1077 }
1078 }
1080 g_assert (d);
1082 return d;
1083 }
1087 SPDesktop *
1088 inkscape_prev_desktop ()
1089 {
1090 SPDesktop *d = NULL;
1091 unsigned int dkey_current = ((SPDesktop *) inkscape->desktops->data)->dkey;
1093 if (dkey_current > 0) {
1094 // find prev existing
1095 for (signed int i = dkey_current - 1; i >= 0; i--) {
1096 d = inkscape_find_desktop_by_dkey (i);
1097 if (d) {
1098 break;
1099 }
1100 }
1101 }
1102 if (!d) {
1103 // find last existing
1104 d = inkscape_find_desktop_by_dkey (inkscape_maximum_dkey());
1105 }
1107 g_assert (d);
1109 return d;
1110 }
1114 void
1115 inkscape_switch_desktops_next ()
1116 {
1117 inkscape_next_desktop()->presentWindow();
1118 }
1122 void
1123 inkscape_switch_desktops_prev ()
1124 {
1125 inkscape_prev_desktop()->presentWindow();
1126 }
1130 void
1131 inkscape_dialogs_hide ()
1132 {
1133 if (Inkscape::NSApplication::Application::getNewGui())
1134 Inkscape::NSApplication::Editor::hideDialogs();
1135 else
1136 {
1137 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[DIALOGS_HIDE], 0);
1138 inkscape->dialogs_toggle = FALSE;
1139 }
1140 }
1144 void
1145 inkscape_dialogs_unhide ()
1146 {
1147 if (Inkscape::NSApplication::Application::getNewGui())
1148 Inkscape::NSApplication::Editor::unhideDialogs();
1149 else
1150 {
1151 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[DIALOGS_UNHIDE], 0);
1152 inkscape->dialogs_toggle = TRUE;
1153 }
1154 }
1158 void
1159 inkscape_dialogs_toggle ()
1160 {
1161 if (inkscape->dialogs_toggle) {
1162 inkscape_dialogs_hide ();
1163 } else {
1164 inkscape_dialogs_unhide ();
1165 }
1166 }
1168 void
1169 inkscape_external_change ()
1170 {
1171 g_return_if_fail (inkscape != NULL);
1173 g_signal_emit (G_OBJECT (inkscape), inkscape_signals[EXTERNAL_CHANGE], 0);
1174 }
1176 /**
1177 * fixme: These need probably signals too
1178 */
1179 void
1180 inkscape_add_document (SPDocument *document)
1181 {
1182 g_return_if_fail (document != NULL);
1184 if (!Inkscape::NSApplication::Application::getNewGui())
1185 {
1186 // try to insert the pair into the list
1187 if (!(inkscape->document_set.insert(std::make_pair(document, 1)).second)) {
1188 //insert failed, this key (document) is already in the list
1189 for (std::map<SPDocument*,int>::iterator iter = inkscape->document_set.begin();
1190 iter != inkscape->document_set.end();
1191 ++iter) {
1192 if (iter->first == document) {
1193 // found this document in list, increase its count
1194 iter->second ++;
1195 }
1196 }
1197 }
1198 }
1199 else
1200 {
1201 Inkscape::NSApplication::Editor::addDocument (document);
1202 }
1203 }
1206 // returns true if this was last reference to this document, so you can delete it
1207 bool
1208 inkscape_remove_document (SPDocument *document)
1209 {
1210 g_return_val_if_fail (document != NULL, false);
1212 if (!Inkscape::NSApplication::Application::getNewGui())
1213 {
1214 for (std::map<SPDocument*,int>::iterator iter = inkscape->document_set.begin();
1215 iter != inkscape->document_set.end();
1216 ++iter) {
1217 if (iter->first == document) {
1218 // found this document in list, decrease its count
1219 iter->second --;
1220 if (iter->second < 1) {
1221 // this was the last one, remove the pair from list
1222 inkscape->document_set.erase (iter);
1223 return true;
1224 } else {
1225 return false;
1226 }
1227 }
1228 }
1229 }
1230 else
1231 {
1232 Inkscape::NSApplication::Editor::removeDocument (document);
1233 }
1235 return false;
1236 }
1238 SPDesktop *
1239 inkscape_active_desktop (void)
1240 {
1241 if (Inkscape::NSApplication::Application::getNewGui())
1242 return Inkscape::NSApplication::Editor::getActiveDesktop();
1244 if (inkscape->desktops == NULL) {
1245 return NULL;
1246 }
1248 return (SPDesktop *) inkscape->desktops->data;
1249 }
1251 SPDocument *
1252 inkscape_active_document (void)
1253 {
1254 if (Inkscape::NSApplication::Application::getNewGui())
1255 return Inkscape::NSApplication::Editor::getActiveDocument();
1257 if (SP_ACTIVE_DESKTOP) {
1258 return sp_desktop_document (SP_ACTIVE_DESKTOP);
1259 }
1261 return NULL;
1262 }
1264 bool inkscape_is_sole_desktop_for_document(SPDesktop const &desktop) {
1265 SPDocument const* document = desktop.doc();
1266 if (!document) {
1267 return false;
1268 }
1269 for ( GSList *iter = inkscape->desktops ; iter ; iter = iter->next ) {
1270 SPDesktop *other_desktop=(SPDesktop *)iter->data;
1271 SPDocument *other_document=other_desktop->doc();
1272 if ( other_document == document && other_desktop != &desktop ) {
1273 return false;
1274 }
1275 }
1276 return true;
1277 }
1279 SPEventContext *
1280 inkscape_active_event_context (void)
1281 {
1282 if (SP_ACTIVE_DESKTOP) {
1283 return sp_desktop_event_context (SP_ACTIVE_DESKTOP);
1284 }
1286 return NULL;
1287 }
1291 /*#####################
1292 # HELPERS
1293 #####################*/
1295 void
1296 inkscape_refresh_display (Inkscape::Application *inkscape)
1297 {
1298 for (GSList *l = inkscape->desktops; l != NULL; l = l->next) {
1299 (static_cast<Inkscape::UI::View::View*>(l->data))->requestRedraw();
1300 }
1301 }
1304 /**
1305 * Handler for Inkscape's Exit verb. This emits the shutdown signal,
1306 * saves the preferences if appropriate, and quits.
1307 */
1308 void
1309 inkscape_exit (Inkscape::Application */*inkscape*/)
1310 {
1311 g_assert (INKSCAPE);
1313 //emit shutdown signal so that dialogs could remember layout
1314 g_signal_emit (G_OBJECT (INKSCAPE), inkscape_signals[SHUTDOWN_SIGNAL], 0);
1316 Inkscape::Preferences::unload();
1317 gtk_main_quit ();
1318 }
1320 char *
1321 homedir_path(const char *filename)
1322 {
1323 static const gchar *homedir = NULL;
1324 if (!homedir) {
1325 homedir = g_get_home_dir();
1326 }
1327 if (!homedir) {
1328 homedir = g_path_get_dirname(INKSCAPE->argv0);
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(".config");
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 = inkscape->menus->root();
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 :