X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Finkscape.cpp;h=60ab895ede7789bf05f082b957aaf1f017375f40;hb=bd2dcf193883cbaf5c165835f9bac5c22b24cd71;hp=2a7f31c3e92647b7c42e042fcd64ca60635ad2be;hpb=a4ceb4c68d07fabde1ec5eed287f66b1c848f0e3;p=inkscape.git diff --git a/src/inkscape.cpp b/src/inkscape.cpp index 2a7f31c3e..60ab895ed 100644 --- a/src/inkscape.cpp +++ b/src/inkscape.cpp @@ -15,6 +15,7 @@ # include "config.h" #endif +#include #include #include "debug/simple-event.h" @@ -41,6 +42,7 @@ using Inkscape::Extension::Internal::PrintWin32; #include #include #include +#include #include #include #include "application/application.h" @@ -110,6 +112,7 @@ struct Inkscape::Application { gboolean use_gui; // may want to consider a virtual function // for overriding things like the warning dlg's guint mapalt; + guint trackalt; }; struct Inkscape::ApplicationClass { @@ -138,9 +141,12 @@ static void (* segv_handler) (int) = SIG_DFL; static void (* abrt_handler) (int) = SIG_DFL; static void (* fpe_handler) (int) = SIG_DFL; static void (* ill_handler) (int) = SIG_DFL; +#ifndef WIN32 static void (* bus_handler) (int) = SIG_DFL; +#endif -#define INKSCAPE_PROFILE_DIR "Inkscape" +#define INKSCAPE_PROFILE_DIR "inkscape" +#define INKSCAPE_PROFILE_DIR_047DEV "Inkscape" #define INKSCAPE_LEGACY_PROFILE_DIR ".inkscape" #define MENUS_FILE "menus.xml" @@ -460,12 +466,10 @@ inkscape_init (SPObject * object) new (&inkscape->document_set) std::map(); inkscape->menus = sp_repr_read_mem (_(menus_skeleton), MENUS_SKELETON_SIZE, NULL); - inkscape->desktops = NULL; - inkscape->dialogs_toggle = TRUE; - - inkscape->mapalt=GDK_MOD1_MASK; + inkscape->mapalt = GDK_MOD1_MASK; + inkscape->trackalt = FALSE; } static void @@ -523,6 +527,17 @@ void inkscape_mapalt(guint maskvalue) } } +guint +inkscape_trackalt() { + return inkscape->trackalt; +} + +void inkscape_trackalt(guint trackvalue) +{ + inkscape->trackalt = trackvalue; +} + + static void inkscape_activate_desktop_private (Inkscape::Application */*inkscape*/, SPDesktop *desktop) { @@ -658,7 +673,8 @@ inkscape_crash_handler (int /*signum*/) } } - Inkscape::Preferences::unload(); + // do not save the preferences since they can be in a corrupted state + Inkscape::Preferences::unload(false); fprintf (stderr, "Emergency save completed. Inkscape will close now.\n"); fprintf (stderr, "If you can reproduce this crash, please file a bug at www.inkscape.org\n"); @@ -731,6 +747,28 @@ inkscape_crash_handler (int /*signum*/) } +class InkErrorHandler : public Inkscape::ErrorReporter { +public: + InkErrorHandler(bool useGui) : Inkscape::ErrorReporter(), + _useGui(useGui) + {} + virtual ~InkErrorHandler() {} + + virtual void handleError( Glib::ustring const& primary, Glib::ustring const& secondary ) const + { + if (_useGui) { + Gtk::MessageDialog err(primary, false, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_OK, true); + err.set_secondary_text(secondary); + err.run(); + } else { + g_message("%s", primary.data()); + g_message("%s", secondary.data()); + } + } + +private: + bool _useGui; +}; void inkscape_application_init (const gchar *argv0, gboolean use_gui) @@ -749,12 +787,28 @@ inkscape_application_init (const gchar *argv0, gboolean use_gui) inkscape->use_gui = use_gui; inkscape->argv0 = g_strdup(argv0); - /* Load the preferences and menus; Later menu layout should be merged into prefs */ + /* Load the preferences and menus */ Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - prefs->load(use_gui, false); + InkErrorHandler* handler = new InkErrorHandler(use_gui); + prefs->setErrorHandler(handler); + { + Glib::ustring msg; + Glib::ustring secondary; + if (prefs->getLastError( msg, secondary )) { + handler->handleError(msg, secondary); + } + } + inkscape_load_menus(inkscape); sp_input_load_from_preferences(); + /* set language for user interface according setting in preferences */ + Glib::ustring ui_language = prefs->getString("/ui/language"); + if(!ui_language.empty()) + { + setenv("LANGUAGE", ui_language, 1); + } + /* DebugDialog redirection. On Linux, default to OFF, on Win32, default to ON. * Use only if use_gui is enabled */ @@ -770,9 +824,10 @@ inkscape_application_init (const gchar *argv0, gboolean use_gui) } /* Check for global remapping of Alt key */ - if(use_gui) + if (use_gui) { inkscape_mapalt(guint(prefs->getInt("/options/mapalt/value", 0))); + inkscape_trackalt(guint(prefs->getInt("/options/trackalt/value", 0))); } /* Initialize the extensions */ @@ -803,18 +858,21 @@ gboolean inkscape_app_use_gui( Inkscape::Application const * app ) */ bool inkscape_load_menus (Inkscape::Application */*inkscape*/) { + // TODO fix that fn is being leaked gchar *fn = profile_path(MENUS_FILE); - gchar *menus_xml = NULL; gsize len = 0; + gchar *menus_xml = NULL; + gsize len = 0; if (g_file_get_contents(fn, &menus_xml, &len, NULL)) { // load the menus_xml file INKSCAPE->menus = sp_repr_read_mem(menus_xml, len, NULL); g_free(menus_xml); - if (INKSCAPE->menus) return true; + if (INKSCAPE->menus) { + return true; + } } INKSCAPE->menus = sp_repr_read_mem(menus_skeleton, MENUS_SKELETON_SIZE, NULL); - if (INKSCAPE->menus) return true; - return false; + return (INKSCAPE->menus != 0); } @@ -1323,7 +1381,15 @@ gchar * profile_path(const char *filename) { static const gchar *prefdir = NULL; + + if (!prefdir) { + // First check for a custom environment variable for a "portable app" + gchar const *val = g_getenv("INKSCAPE_PORTABLE_PROFILE_DIR"); + if (val) { + prefdir = g_strdup(val); + } + #ifdef HAS_SHGetSpecialFolderLocation // prefer c:\Documents and Settings\UserName\Application Data\ to // c:\Documents and Settings\userName\; @@ -1377,14 +1443,37 @@ profile_path(const char *filename) if (!prefdir) { prefdir = g_build_filename(g_get_user_config_dir(), INKSCAPE_PROFILE_DIR, NULL); gchar * legacyDir = homedir_path(INKSCAPE_LEGACY_PROFILE_DIR); + gchar * dev47Dir = g_build_filename(g_get_user_config_dir(), INKSCAPE_PROFILE_DIR_047DEV, NULL); - // TODO here is a point to hook in preference migration + bool needsMigration = ( !Inkscape::IO::file_test( prefdir, G_FILE_TEST_EXISTS ) && Inkscape::IO::file_test( legacyDir, G_FILE_TEST_EXISTS ) ); + if (needsMigration) { + // TODO here is a point to hook in preference migration + g_warning("Preferences need to be migrated from 0.46 or older %s to %s", legacyDir, prefdir); + } - if ( !Inkscape::IO::file_test( prefdir, G_FILE_TEST_EXISTS ) && Inkscape::IO::file_test( legacyDir, G_FILE_TEST_EXISTS ) ) { - prefdir = legacyDir; - } else { - g_free(legacyDir); - legacyDir = 0; + bool needsRenameWarning = ( !Inkscape::IO::file_test( prefdir, G_FILE_TEST_EXISTS ) && Inkscape::IO::file_test( dev47Dir, G_FILE_TEST_EXISTS ) ); + if (needsRenameWarning) { + g_warning("Preferences need to be copied from %s to %s", legacyDir, prefdir); + } + + g_free(legacyDir); + legacyDir = 0; + g_free(dev47Dir); + dev47Dir = 0; + // In case the XDG user config dir of the moment does not yet exist... + int mode = S_IRWXU; +#ifdef S_IRGRP + mode |= S_IRGRP; +#endif +#ifdef S_IXGRP + mode |= S_IXGRP; +#endif +#ifdef S_IXOTH + mode |= S_IXOTH; +#endif + if ( g_mkdir_with_parents(prefdir, mode) == -1 ) { + int problem = errno; + g_warning("Unable to create profile directory (%s) (%d)", g_strerror(problem), problem); } } } @@ -1407,8 +1496,6 @@ inkscape_get_all_desktops(std::list< SPDesktop* >& listbuf) } } - - /* Local Variables: mode:c++