diff options
| author | Martin Owens <doctormo@gmail.com> | 2017-06-28 07:04:16 +0000 |
|---|---|---|
| committer | Martin Owens <doctormo@gmail.com> | 2017-06-28 07:04:16 +0000 |
| commit | cf457eea72b81850da5503d0091952871135c1fd (patch) | |
| tree | 3709bcf46a0152434a89ed68bbb343a8d45408dd | |
| parent | Update dxf_input.py for LP Bug #1700582 (diff) | |
| download | inkscape-cf457eea72b81850da5503d0091952871135c1fd.tar.gz inkscape-cf457eea72b81850da5503d0091952871135c1fd.zip | |
Refactor profile directory use and promote IO::Resource get_path and get_filename methods
| -rw-r--r-- | src/extension/error-file.cpp | 3 | ||||
| -rw-r--r-- | src/extension/extension.cpp | 3 | ||||
| -rw-r--r-- | src/extension/init.cpp | 28 | ||||
| -rw-r--r-- | src/extension/internal/filter/filter-file.cpp | 21 | ||||
| -rw-r--r-- | src/extension/internal/filter/filter.h | 1 | ||||
| -rw-r--r-- | src/file.cpp | 45 | ||||
| -rw-r--r-- | src/inkscape.cpp | 209 | ||||
| -rw-r--r-- | src/inkscape.h | 3 | ||||
| -rw-r--r-- | src/io/resource.cpp | 185 | ||||
| -rw-r--r-- | src/io/resource.h | 21 | ||||
| -rw-r--r-- | src/preferences.cpp | 28 | ||||
| -rw-r--r-- | src/preferences.h | 2 | ||||
| -rw-r--r-- | src/selection-chemistry.cpp | 3 | ||||
| -rw-r--r-- | src/shortcuts.cpp | 22 | ||||
| -rw-r--r-- | src/ui/dialog/export.cpp | 3 | ||||
| -rw-r--r-- | src/ui/dialog/filedialogimpl-gtkmm.cpp | 6 | ||||
| -rw-r--r-- | src/ui/dialog/inkscape-preferences.cpp | 2 | ||||
| -rw-r--r-- | src/ui/dialog/swatches.cpp | 7 | ||||
| -rw-r--r-- | src/ui/dialog/symbols.cpp | 17 | ||||
| -rw-r--r-- | src/ui/dialog/template-load-tab.cpp | 17 | ||||
| -rw-r--r-- | src/ui/dialog/template-load-tab.h | 4 | ||||
| -rw-r--r-- | src/widgets/icon.cpp | 10 | ||||
| -rw-r--r-- | src/widgets/toolbox.cpp | 14 |
23 files changed, 302 insertions, 352 deletions
diff --git a/src/extension/error-file.cpp b/src/extension/error-file.cpp index 342511ec9..063e43f42 100644 --- a/src/extension/error-file.cpp +++ b/src/extension/error-file.cpp @@ -18,6 +18,7 @@ #include "inkscape.h" #include "preferences.h" #include "extension/extension.h" +#include "io/resource.h" #include "error-file.h" @@ -51,7 +52,7 @@ ErrorFileNotice::ErrorFileNotice (void) : // \FIXME change this /* This is some filler text, needs to change before relase */ Glib::ustring dialog_text(_("<span weight=\"bold\" size=\"larger\">One or more extensions failed to load</span>\n\nThe failed extensions have been skipped. Inkscape will continue to run normally but those extensions will be unavailable. For details to troubleshoot this problem, please refer to the error log located at: ")); - gchar * ext_error_file = Inkscape::Application::profile_path(EXTENSION_ERROR_LOG_FILENAME); + gchar * ext_error_file = Inkscape::IO::Resource::log_path(EXTENSION_ERROR_LOG_FILENAME); dialog_text += ext_error_file; g_free(ext_error_file); set_message(dialog_text, true); diff --git a/src/extension/extension.cpp b/src/extension/extension.cpp index 497f98431..9c0221521 100644 --- a/src/extension/extension.cpp +++ b/src/extension/extension.cpp @@ -33,6 +33,7 @@ #include "dependency.h" #include "timer.h" #include "param/parameter.h" +#include "io/resource.h" namespace Inkscape { namespace Extension { @@ -658,7 +659,7 @@ Extension::set_param_color (const gchar * name, guint32 color, SPDocument * doc, void Extension::error_file_open (void) { - gchar * ext_error_file = Inkscape::Application::profile_path(EXTENSION_ERROR_LOG_FILENAME); + gchar * ext_error_file = Inkscape::IO::Resource::log_path(EXTENSION_ERROR_LOG_FILENAME); gchar * filename = g_filename_from_utf8( ext_error_file, -1, NULL, NULL, NULL ); error_file.open(filename); if (!error_file.is_open()) { diff --git a/src/extension/init.cpp b/src/extension/init.cpp index af7af2cb1..f2e74377d 100644 --- a/src/extension/init.cpp +++ b/src/extension/init.cpp @@ -60,6 +60,7 @@ #endif #include "preferences.h" #include "io/sys.h" +#include "io/resource.h" #ifdef WITH_DBUS #include "dbus/dbus-init.h" #endif @@ -106,6 +107,8 @@ #include "init.h" +using namespace Inkscape::IO::Resource; + namespace Inkscape { namespace Extension { @@ -113,7 +116,7 @@ namespace Extension { the extension directory and parsed */ #define SP_MODULE_EXTENSION "inx" -static void build_module_from_dir(gchar const *dirname); +static void build_module_from_domain(Domain domain); static void check_extensions(); /** @@ -150,7 +153,7 @@ update_pref(Glib::ustring const &pref_path, * Invokes the init routines for internal modules. * * This should be a list of all the internal modules that need to initialized. This is just a - * convinent place to put them. Also, this function calls build_module_from_dir to parse the + * convinent place to put them. Also, this function calls build_module_from_domain to parse the * Inkscape extensions directory. */ void @@ -240,18 +243,8 @@ init() Internal::Filter::Filter::filters_all(); - /* Load search path for extensions */ - if (Inkscape::Extension::Extension::search_path.size() == 0) - { - Inkscape::Extension::Extension::search_path.push_back(Inkscape::Application::profile_path("extensions")); - - Inkscape::Extension::Extension::search_path.push_back(g_strdup(INKSCAPE_EXTENSIONDIR)); - - } - - for (unsigned int i=0; i<Inkscape::Extension::Extension::search_path.size(); i++) { - build_module_from_dir(Inkscape::Extension::Extension::search_path[i]); - } + build_module_from_domain(USER); + build_module_from_domain(SYSTEM); /* this is at the very end because it has several catch-alls * that are possibly over-ridden by other extensions (such as @@ -282,8 +275,10 @@ init() * with their filenames. */ static void -build_module_from_dir(gchar const *dirname) +build_module_from_domain(Domain domain) { + char const *dirname = get_path(domain, EXTENSIONS); + if (!dirname) { g_warning("%s", _("Null external module directory name. Modules will not be loaded.")); return; @@ -293,7 +288,8 @@ build_module_from_dir(gchar const *dirname) return; } - //# Hopefully doing this the Glib way is portable + // TODO: We may have to get to why this is needed, since it seems redundent. + Inkscape::Extension::Extension::search_path.push_back(dirname); GError *err; GDir *directory = g_dir_open(dirname, 0, &err); diff --git a/src/extension/internal/filter/filter-file.cpp b/src/extension/internal/filter/filter-file.cpp index b1993057d..dfe889ddf 100644 --- a/src/extension/internal/filter/filter-file.cpp +++ b/src/extension/internal/filter/filter-file.cpp @@ -8,6 +8,7 @@ #include "filter.h" #include "io/sys.h" +#include "io/resource.h" #include "io/inkscapestream.h" /* Directory includes */ @@ -22,27 +23,27 @@ #include <glibmm/i18n.h> #include <glibmm/fileutils.h> +using namespace Inkscape::IO::Resource; + namespace Inkscape { namespace Extension { namespace Internal { namespace Filter { +void filters_load_domain(Domain domain, gchar *menuname); + void Filter::filters_all_files(void) { - gchar *filtersProfilePath = Inkscape::Application::profile_path("filters"); - - filters_load_dir(INKSCAPE_FILTERDIR, _("Bundled")); - filters_load_dir(filtersProfilePath, _("Personal")); - - g_free(filtersProfilePath); - filtersProfilePath = 0; + filters_load_domain(SYSTEM, _("Bundled")); + filters_load_domain(USER, _("Personal")); } #define INKSCAPE_FILTER_FILE ".svg" -void -Filter::filters_load_dir (gchar const * dirname, gchar * menuname) +void filters_load_domain(Domain domain, gchar *menuname) { + char const *dirname = get_path(domain, FILTERS); + if (!dirname) { g_warning("%s", _("Null external module directory name. Filters will not be loaded.")); return; @@ -72,7 +73,7 @@ Filter::filters_load_dir (gchar const * dirname, gchar * menuname) } gchar *pathname = g_build_filename(dirname, filename, NULL); - filters_load_file(pathname, menuname); + Filter::filters_load_file(pathname, menuname); g_free(pathname); } diff --git a/src/extension/internal/filter/filter.h b/src/extension/internal/filter/filter.h index 9aaa84aec..d4728b69c 100644 --- a/src/extension/internal/filter/filter.h +++ b/src/extension/internal/filter/filter.h @@ -53,7 +53,6 @@ public: /* File loader related */ static void filters_all_files(void); - static void filters_load_dir(gchar const * filename, gchar * menuname); static void filters_load_file(gchar * filename, gchar * menuname); static void filters_load_node(Inkscape::XML::Node * node, gchar * menuname); diff --git a/src/file.cpp b/src/file.cpp index 43a9c6f5b..b9d896de0 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -50,6 +50,7 @@ #include "inkscape-version.h" #include "ui/interface.h" #include "io/sys.h" +#include "io/resource.h" #include "message-stack.h" #include "path-prefix.h" #include "print.h" @@ -67,6 +68,7 @@ using Inkscape::DocumentUndo; +using Inkscape::IO::Resource::TEMPLATES; #ifdef WITH_GNOME_VFS # include <libgnomevfs/gnome-vfs.h> @@ -159,48 +161,7 @@ SPDesktop *sp_file_new(const std::string &templ) Glib::ustring sp_file_default_template_uri() { - std::list<gchar *> sources; - sources.push_back( Inkscape::Application::profile_path("templates") ); // first try user's local dir - sources.push_back( g_strdup(INKSCAPE_TEMPLATESDIR) ); // then the system templates dir - std::list<gchar const*> baseNames; - gchar const* localized = _("default.svg"); - if (strcmp("default.svg", localized) != 0) { - baseNames.push_back(localized); - } - baseNames.push_back("default.svg"); - gchar *foundTemplate = 0; - - for (std::list<gchar *>::iterator it = sources.begin(); (it != sources.end()) && !foundTemplate; ++it) { - for (std::list<gchar const*>::iterator nameIt = baseNames.begin(); (nameIt != baseNames.end()) && !foundTemplate; ++nameIt) { - gchar *dirname = *it; - if ( Inkscape::IO::file_test( dirname, (GFileTest)(G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR) ) ) { - - // TRANSLATORS: default.svg is localizable - this is the name of the default document - // template. This way you can localize the default pagesize, translate the name of - // the default layer, etc. If you wish to localize this file, please create a - // localized share/templates/default.xx.svg file, where xx is your language code. - char *tmp = g_build_filename(dirname, *nameIt, NULL); - if (Inkscape::IO::file_test(tmp, G_FILE_TEST_IS_REGULAR)) { - foundTemplate = tmp; - } else { - g_free(tmp); - } - } - } - } - - for (std::list<gchar *>::iterator it = sources.begin(); it != sources.end(); ++it) { - g_free(*it); - } - - Glib::ustring templateUri = foundTemplate ? foundTemplate : ""; - - if (foundTemplate) { - g_free(foundTemplate); - foundTemplate = 0; - } - - return templateUri; + return Inkscape::IO::Resource::get_filename(TEMPLATES, "default.svg", _("default.svg")); } SPDesktop* sp_file_new_default() diff --git a/src/inkscape.cpp b/src/inkscape.cpp index bf694ada7..b0d2a7f6b 100644 --- a/src/inkscape.cpp +++ b/src/inkscape.cpp @@ -60,6 +60,7 @@ #include "helper/action-context.h" #include "inkscape.h" #include "io/sys.h" +#include "io/resource.h" #include "message-stack.h" #include "path-prefix.h" #include "resource-manager.h" @@ -83,9 +84,6 @@ static void (* ill_handler) (int) = SIG_DFL; static void (* bus_handler) (int) = SIG_DFL; #endif -#define INKSCAPE_PROFILE_DIR "inkscape" -#define INKSCAPE_PROFILE_DIR_047DEV "Inkscape" -#define INKSCAPE_LEGACY_PROFILE_DIR ".inkscape" #define MENUS_FILE "menus.xml" #define SP_INDENT 8 @@ -390,31 +388,17 @@ void Application::argv0(char const* argv) void Application::add_icon_theme() { + using namespace Inkscape::IO::Resource; // Get list of the possible folders containing the theme - auto dataDirs = Glib::get_system_data_dirs(); - dataDirs.insert(dataDirs.begin(), Glib::get_user_data_dir()); - auto icon_theme = Gtk::IconTheme::get_default(); - - for (auto it : dataDirs) - { - std::vector<Glib::ustring> listing; - listing.push_back(it); - listing.push_back("inkscape"); - listing.push_back("icons"); - auto dir = Glib::build_filename(listing); - icon_theme->append_search_path(dir); - } - - // Add our icon directory to the search path for icon theme lookups. - auto const usericondir = Inkscape::Application::profile_path("icons"); - icon_theme->append_search_path(usericondir); - icon_theme->append_search_path(INKSCAPE_PIXMAPDIR); + // We used to add get_system_data_dirs and get_user_data_dir, but these + // folders didn't seem to make much sense for Linux. More testing needed. + icon_theme->append_search_path(get_path_ustring(SYSTEM, ICONS)); + icon_theme->append_search_path(get_path_ustring(USER, ICONS)); #ifdef INKSCAPE_THEMEDIR - icon_theme->append_search_path(INKSCAPE_THEMEDIR); - icon_theme->rescan_if_needed(); + icon_theme->append_search_path(get_path_ustring(SYSTEM, THEMES)); + icon_theme->append_search_path(get_path_ustring(USER, THEMES)); #endif - g_free(usericondir); } /** @@ -423,63 +407,33 @@ Application::add_icon_theme() void Application::add_style_sheet() { + using namespace Inkscape::IO::Resource; // Add style sheet (GTK3) auto const screen = Gdk::Screen::get_default(); - Glib::ustring inkscape_style = INKSCAPE_UIDIR; - inkscape_style += "/style.css"; - // std::cout << "CSS Stylesheet Inkscape: " << inkscape_style << std::endl; - - if (Glib::file_test(inkscape_style, Glib::FILE_TEST_EXISTS)) { + // Calling get_filename always returns a real filename OR + // if no file exists, then it will have warned already and returns empty. + Glib::ustring style = get_filename(UIS, "style.css"); + if (!style.empty()) { auto provider = Gtk::CssProvider::create(); // From 3.16, throws an error which we must catch. try { - provider->load_from_path (inkscape_style); + provider->load_from_path (style); } #if GTK_CHECK_VERSION(3,16,0) // Gtk::CssProviderError not defined until 3.16. catch (const Gtk::CssProviderError& ex) { - std::cerr << "CSSProviderError::load_from_path(): failed to load: " << inkscape_style - << "\n (" << ex.what() << ")" << std::endl; + g_error("CSSProviderError::load_from_path(): %s\n(%s)", + style.c_str(), ex.what().c_str()); } #else catch (...) {} #endif - Gtk::StyleContext::add_provider_for_screen (screen, provider, GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); - } else { - std::cerr << "sp_main_gui: Cannot find default style file:\n (" << inkscape_style - << ")" << std::endl; - } - - Glib::ustring user_style = Inkscape::Application::profile_path("ui/style.css"); - // std::cout << "CSS Stylesheet User: " << user_style << std::endl; - - if (Glib::file_test(user_style, Glib::FILE_TEST_EXISTS)) { - auto provider2 = Gtk::CssProvider::create(); - - // From 3.16, throws an error which we must catch. - try { - provider2->load_from_path (user_style); - } -#if GTK_CHECK_VERSION(3,16,0) - // Gtk::CssProviderError not defined until 3.16. - catch (const Gtk::CssProviderError& ex) - { - std::cerr << "CSSProviderError::load_from_path(): failed to load: " << user_style - << "\n (" << ex.what() << ")" << std::endl; - } -#else - catch (...) - {} -#endif - - Gtk::StyleContext::add_provider_for_screen (screen, provider2, GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); } - } /* \brief Constructor for the application. * Creates a new Inkscape::Application. @@ -813,7 +767,7 @@ Application::crash_handler (int /*signum*/) */ bool Application::load_menus() { - gchar *fn = profile_path(MENUS_FILE); + gchar *fn = Inkscape::IO::Resource::profile_path(MENUS_FILE); gchar *menus_xml = 0; gsize len = 0; @@ -1302,137 +1256,8 @@ Application::exit () gtk_main_quit (); } -char * -Application::homedir_path(const char *filename) -{ - static const gchar *homedir = NULL; - if (!homedir) { - homedir = g_get_home_dir(); - } - if (!homedir) { - if (Application::exists()) { - homedir = g_path_get_dirname(Application::instance()._argv0); - } - } - return g_build_filename(homedir, filename, NULL); -} - - -/** - * Get, or guess, or decide the location where the preferences.xml - * file should be located. - */ -gchar * -Application::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); - } - // Then check for a custom user environment variable - gchar const *userenv = g_getenv("INKSCAPE_PROFILE_DIR"); - if (userenv) { - prefdir = g_strdup(userenv); - } - -#ifdef HAS_SHGetSpecialFolderLocation - // prefer c:\Documents and Settings\UserName\Application Data\ to - // c:\Documents and Settings\userName\; - if (!prefdir) { - ITEMIDLIST *pidl = 0; - if ( SHGetSpecialFolderLocation( NULL, CSIDL_APPDATA, &pidl ) == NOERROR ) { - gchar * utf8Path = NULL; - - { - wchar_t pathBuf[MAX_PATH+1]; - g_assert(sizeof(wchar_t) == sizeof(gunichar2)); - - if ( SHGetPathFromIDListW( pidl, pathBuf ) ) { - utf8Path = g_utf16_to_utf8( (gunichar2*)(&pathBuf[0]), -1, NULL, NULL, NULL ); - } - } - - if ( utf8Path ) { - if (!g_utf8_validate(utf8Path, -1, NULL)) { - g_warning( "SHGetPathFromIDListW() resulted in invalid UTF-8"); - g_free( utf8Path ); - utf8Path = 0; - } else { - prefdir = utf8Path; - } - } - - - /* not compiling yet... - - // Remember to free the list pointer - IMalloc * imalloc = 0; - if ( SHGetMalloc(&imalloc) == NOERROR) { - imalloc->lpVtbl->Free( imalloc, pidl ); - imalloc->lpVtbl->Release( imalloc ); - } - */ - } - if (prefdir) { - const char *prefdir_profile = g_build_filename(prefdir, INKSCAPE_PROFILE_DIR, NULL); - g_free((void *)prefdir); - prefdir = prefdir_profile; - } - } -#endif - 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); - - 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); - Inkscape::Preferences::migrate( legacyDir, prefdir ); - } - - 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); - } else { - gchar const *userDirs[] = {"keys", "templates", "icons", "extensions", "palettes", NULL}; - for (gchar const** name = userDirs; *name; ++name) { - gchar *dir = g_build_filename(prefdir, *name, NULL); - g_mkdir_with_parents(dir, mode); - g_free(dir); - } - } - } - } - return g_build_filename(prefdir, filename, NULL); -} Inkscape::XML::Node * Application::get_menus() diff --git a/src/inkscape.h b/src/inkscape.h index 3f4416f2f..e66201b25 100644 --- a/src/inkscape.h +++ b/src/inkscape.h @@ -147,9 +147,6 @@ public: void add_document (SPDocument *document); bool remove_document (SPDocument *document); - static char *homedir_path(const char *filename); - static char *profile_path(const char *filename); - // fixme: This has to be rethought void refresh_display (); diff --git a/src/io/resource.cpp b/src/io/resource.cpp index 52ac884b1..84be1586e 100644 --- a/src/io/resource.cpp +++ b/src/io/resource.cpp @@ -1,7 +1,11 @@ /* * Inkscape::IO::Resource - simple resource API * - * Copyright 2006 MenTaLguY <mental@rydia.net> + * Authors: + * MenTaLguY <mental@rydia.net> + * Martin Owens <doctormo@gmail.com> + * + * Copyright (C) 2006-2017 Authors * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -18,7 +22,6 @@ #include <glib.h> // g_assert() #include "path-prefix.h" -#include "inkscape.h" #include "io/sys.h" #include "io/resource.h" @@ -30,6 +33,8 @@ namespace IO { namespace Resource { +#define INKSCAPE_PROFILE_DIR "inkscape" + gchar *_get_path(Domain domain, Type type, char const *filename) { gchar *path=NULL; @@ -39,6 +44,7 @@ gchar *_get_path(Domain domain, Type type, char const *filename) switch (type) { case APPICONS: temp = INKSCAPE_APPICONDIR; break; case EXTENSIONS: temp = INKSCAPE_EXTENSIONDIR; break; + case FILTERS: temp = INKSCAPE_FILTERDIR; break; case GRADIENTS: temp = INKSCAPE_GRADIENTSDIR; break; case ICONS: temp = INKSCAPE_PIXMAPDIR; break; case KEYS: temp = INKSCAPE_KEYSDIR; break; @@ -46,9 +52,11 @@ gchar *_get_path(Domain domain, Type type, char const *filename) case PALETTES: temp = INKSCAPE_PALETTESDIR; break; case PATTERNS: temp = INKSCAPE_PATTERNSDIR; break; case SCREENS: temp = INKSCAPE_SCREENSDIR; break; + case SYMBOLS: temp = INKSCAPE_SYMBOLSDIR; break; case TEMPLATES: temp = INKSCAPE_TEMPLATESDIR; break; + case THEMES: temp = INKSCAPE_THEMEDIR; break; case TUTORIALS: temp = INKSCAPE_TUTORIALSDIR; break; - case UI: temp = INKSCAPE_UIDIR; break; + case UIS: temp = INKSCAPE_UIDIR; break; default: g_assert_not_reached(); } path = g_strdup(temp); @@ -67,17 +75,20 @@ gchar *_get_path(Domain domain, Type type, char const *filename) char const *name=NULL; switch (type) { case EXTENSIONS: name = "extensions"; break; + case FILTERS: name = "filters"; break; case GRADIENTS: name = "gradients"; break; case ICONS: name = "icons"; break; case KEYS: name = "keys"; break; case MARKERS: name = "markers"; break; case PALETTES: name = "palettes"; break; case PATTERNS: name = "patterns"; break; + case SYMBOLS: name = "symbols"; break; case TEMPLATES: name = "templates"; break; - case UI: name = "ui"; break; + case THEMES: name = "icons"; break; + case UIS: name = "ui"; break; default: return _get_path(SYSTEM, type, filename); } - path = Inkscape::Application::profile_path(name); + path = profile_path(name); } break; } @@ -97,29 +108,185 @@ Util::ptr_shared<char> get_path(Domain domain, Type type, char const *filename) g_free(path); return result; } +Glib::ustring get_path_ustring(Domain domain, Type type, char const *filename) +{ + Glib::ustring result; + char *path = _get_path(domain, type, filename); + if(path) { + result = Glib::ustring(path); + g_free(path); + } + return result; +} /* * Same as get_path, but checks for file's existance and falls back * from USER to SYSTEM modes. + * + * type - The type of file to get, such as extension, template, ui etc + * filename - The filename to get, i.e. preferences.xml + * locale - The local language version of the file (if needed) */ -Util::ptr_shared<char> get_filename(Type type, char const *filename) +Glib::ustring get_filename(Type type, char const *filename, char const *locale) { - Util::ptr_shared<char> result; + Glib::ustring result; + + if(locale != NULL) { + char *user_locale = _get_path(USER, type, filename); + char *sys_locale = _get_path(SYSTEM, type, filename); + + if (file_test(user_locale, G_FILE_TEST_EXISTS)) { + result = Glib::ustring(user_locale); + } else if(file_test(sys_locale, G_FILE_TEST_EXISTS)) { + result = Glib::ustring(sys_locale); + } + g_free(user_locale); + g_free(sys_locale); + + if(!result.empty()) { + g_info("Using translated resource file: %s", result.c_str()); + return result; + } + } + char *user_filename = _get_path(USER, type, filename); char *sys_filename = _get_path(SYSTEM, type, filename); if (file_test(user_filename, G_FILE_TEST_EXISTS)) { - result = Util::share_string(user_filename); + result = Glib::ustring(user_filename); } else if(file_test(sys_filename, G_FILE_TEST_EXISTS)) { - result = Util::share_string(sys_filename); + result = Glib::ustring(sys_filename); } else { g_warning("Failed to load resource: %s", filename); } + + if(!result.empty()) { + g_info("Using resource file: %s", result.c_str()); + } + g_free(user_filename); g_free(sys_filename); return result; } +/** + * Get, or guess, or decide the location where the preferences.xml + * file should be located. This also indicates where all other inkscape + * shared files may optionally exist. + */ +char *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); + } + // Then check for a custom user environment variable + gchar const *userenv = g_getenv("INKSCAPE_PROFILE_DIR"); + if (userenv) { + prefdir = g_strdup(userenv); + } + +#ifdef HAS_SHGetSpecialFolderLocation + // prefer c:\Documents and Settings\UserName\Application Data\ to + // c:\Documents and Settings\userName\; + if (!prefdir) { + ITEMIDLIST *pidl = 0; + if ( SHGetSpecialFolderLocation( NULL, CSIDL_APPDATA, &pidl ) == NOERROR ) { + gchar * utf8Path = NULL; + + { + wchar_t pathBuf[MAX_PATH+1]; + g_assert(sizeof(wchar_t) == sizeof(gunichar2)); + + if ( SHGetPathFromIDListW( pidl, pathBuf ) ) { + utf8Path = g_utf16_to_utf8( (gunichar2*)(&pathBuf[0]), -1, NULL, NULL, NULL ); + } + } + + if ( utf8Path ) { + if (!g_utf8_validate(utf8Path, -1, NULL)) { + g_warning( "SHGetPathFromIDListW() resulted in invalid UTF-8"); + g_free( utf8Path ); + utf8Path = 0; + } else { + prefdir = utf8Path; + } + } + + + /* not compiling yet... + + // Remember to free the list pointer + IMalloc * imalloc = 0; + if ( SHGetMalloc(&imalloc) == NOERROR) { + imalloc->lpVtbl->Free( imalloc, pidl ); + imalloc->lpVtbl->Release( imalloc ); + } + */ + } + + if (prefdir) { + const char *prefdir_profile = g_build_filename(prefdir, INKSCAPE_PROFILE_DIR, NULL); + g_free((void *)prefdir); + prefdir = prefdir_profile; + } + } +#endif + if (!prefdir) { + prefdir = g_build_filename(g_get_user_config_dir(), INKSCAPE_PROFILE_DIR, NULL); + // 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); + } else { + gchar const *userDirs[] = {"keys", "templates", "icons", "extensions", "palettes", NULL}; + for (gchar const** name = userDirs; *name; ++name) { + gchar *dir = g_build_filename(prefdir, *name, NULL); + g_mkdir_with_parents(dir, mode); + g_free(dir); + } + } + } + } + return g_build_filename(prefdir, filename, NULL); +} + +/* + * We return the profile_path because that is where most documentation + * days log files will be generated in inkscape 0.92 + */ +char *log_path(const char *filename) +{ + return profile_path(filename); +} + +char *homedir_path(const char *filename) +{ + static const gchar *homedir = NULL; + homedir = g_get_home_dir(); + + // I suspect this is for handling inkscape app packages + /*if (!homedir && Application::exists()) { + homedir = g_path_get_dirname(Application::instance()._argv0); + }*/ + return g_build_filename(homedir, filename, NULL); +} + } } diff --git a/src/io/resource.h b/src/io/resource.h index fbf2111f4..8b60775b5 100644 --- a/src/io/resource.h +++ b/src/io/resource.h @@ -1,5 +1,9 @@ /* - * Copyright 2006 MenTaLguY <mental@rydia.net> + * Authors: + * MenTaLguY <mental@rydia.net> + * Martin Owens <doctormo@gmail.com> + * + * Copyright (C) 2006-2017 Authors * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -36,7 +40,10 @@ enum Type { SCREENS, TEMPLATES, TUTORIALS, - UI + SYMBOLS, + FILTERS, + THEMES, + UIS }; enum Domain { @@ -48,7 +55,15 @@ enum Domain { Util::ptr_shared<char> get_path(Domain domain, Type type, char const *filename=NULL); -Util::ptr_shared<char> get_filename(Type type, char const *filename=NULL); +Glib::ustring get_path_ustring(Domain domain, Type type, + char const *filename=NULL); + +Glib::ustring get_filename(Type type, char const *filename, + char const *locale=NULL); + +char *profile_path(const char *filename); +char *homedir_path(const char *filename); +char *log_path(const char *filename); } diff --git a/src/preferences.cpp b/src/preferences.cpp index 2849fe068..4d14afa93 100644 --- a/src/preferences.cpp +++ b/src/preferences.cpp @@ -25,6 +25,7 @@ #include "xml/attribute-record.h" #include "util/units.h" #include "attribute-rel-util.h" +#include "io/resource.h" #define PREFERENCES_FILE_NAME "preferences.xml" @@ -82,22 +83,13 @@ private: }; Preferences::Preferences() : - _prefs_basename(PREFERENCES_FILE_NAME), - _prefs_dir(""), _prefs_filename(""), _prefs_doc(0), _errorHandler(0), _writable(false), _hasError(false) { - // profile_path essentailly returns the argument prefixed by the profile directory. - // \TODO this is kinda hackish, but the alternative (strrchr) is worse - - gchar *path = Inkscape::Application::profile_path(NULL); - _prefs_dir = path; - g_free(path); - - path = Inkscape::Application::profile_path(_prefs_basename.c_str()); + char *path = Inkscape::IO::Resource::profile_path(PREFERENCES_FILE_NAME); _prefs_filename = path; g_free(path); @@ -140,16 +132,16 @@ void Preferences::_load() // 1. Does the file exist? if (!g_file_test(_prefs_filename.c_str(), G_FILE_TEST_EXISTS)) { + char *_prefs_dir = Inkscape::IO::Resource::profile_path(NULL); // No - we need to create one. // Does the profile directory exist? - if (!g_file_test(_prefs_dir.c_str(), G_FILE_TEST_EXISTS)) { + if (!g_file_test(_prefs_dir, G_FILE_TEST_EXISTS)) { // No - create the profile directory - if (g_mkdir(_prefs_dir.c_str(), 0755)) { + if (g_mkdir(_prefs_dir, 0755)) { // the creation failed //_reportError(Glib::ustring::compose(_("Cannot create profile directory %1."), // Glib::filename_to_utf8(_prefs_dir)), not_saved); - gchar *msg = g_strdup_printf(_("Cannot create profile directory %s."), - Glib::filename_to_utf8(_prefs_dir).c_str()); + gchar *msg = g_strdup_printf(_("Cannot create profile directory %s."), _prefs_dir); _reportError(msg, not_saved); g_free(msg); return; @@ -157,17 +149,17 @@ void Preferences::_load() // create some subdirectories for user stuff char const *user_dirs[] = {"keys", "templates", "icons", "extensions", "palettes", NULL}; for (int i=0; user_dirs[i]; ++i) { - char *dir = Inkscape::Application::profile_path(user_dirs[i]); + // XXX Why are we doing this here? shouldn't this be an IO load item? + char *dir = Inkscape::IO::Resource::profile_path(user_dirs[i]); g_mkdir(dir, 0755); g_free(dir); } - } else if (!g_file_test(_prefs_dir.c_str(), G_FILE_TEST_IS_DIR)) { + } else if (!g_file_test(_prefs_dir, G_FILE_TEST_IS_DIR)) { // The profile dir is not actually a directory //_reportError(Glib::ustring::compose(_("%1 is not a valid directory."), // Glib::filename_to_utf8(_prefs_dir)), not_saved); - gchar *msg = g_strdup_printf(_("%s is not a valid directory."), - Glib::filename_to_utf8(_prefs_dir).c_str()); + gchar *msg = g_strdup_printf(_("%s is not a valid directory."), _prefs_dir); _reportError(msg, not_saved); g_free(msg); return; diff --git a/src/preferences.h b/src/preferences.h index d5ae40e56..2a9818c63 100644 --- a/src/preferences.h +++ b/src/preferences.h @@ -544,8 +544,6 @@ private: Preferences(Preferences const &); Preferences operator=(Preferences const &); - std::string _prefs_basename; ///< Basename of the prefs file - std::string _prefs_dir; ///< Directory in which to look for the prefs file std::string _prefs_filename; ///< Full filename (with directory) of the prefs file Glib::ustring _lastErrPrimary; ///< Last primary error message, if any. Glib::ustring _lastErrSecondary; ///< Last secondary error message, if any. diff --git a/src/selection-chemistry.cpp b/src/selection-chemistry.cpp index b3d910700..bac924980 100644 --- a/src/selection-chemistry.cpp +++ b/src/selection-chemistry.cpp @@ -39,6 +39,7 @@ SPCycleType SP_CYCLING = SP_CYCLE_FOCUS; #include "layer-model.h" #include "selection.h" #include "ui/tools-switch.h" +#include "io/resource.h" #include "message-stack.h" #include "sp-item-transform.h" @@ -3628,7 +3629,7 @@ void ObjectSet::createBitmapCopy() directory = g_path_get_dirname( doc->getURI() ); } if (directory == NULL) { - directory = INKSCAPE.homedir_path(NULL); + directory = Inkscape::IO::Resource::homedir_path(NULL); } gchar *filepath = g_build_filename(directory, basename, NULL); g_free(directory); diff --git a/src/shortcuts.cpp b/src/shortcuts.cpp index e74d60abc..f8a647040 100644 --- a/src/shortcuts.cpp +++ b/src/shortcuts.cpp @@ -48,11 +48,7 @@ #include "ui/dialog/filedialog.h" using namespace Inkscape; - -using Inkscape::IO::Resource::get_path; -using Inkscape::IO::Resource::SYSTEM; -using Inkscape::IO::Resource::USER; -using Inkscape::IO::Resource::KEYS; +using namespace Inkscape::IO::Resource; static void try_shortcuts_file(char const *filename); static void read_shortcuts_file(char const *filename, bool const is_user_set=false); @@ -208,9 +204,11 @@ Inkscape::XML::Document *sp_shortcut_create_template_file(char const *filename) */ void sp_shortcut_get_file_names(std::vector<Glib::ustring> *names, std::vector<Glib::ustring> *paths) { - std::list<gchar *> sources; - sources.push_back( Inkscape::Application::profile_path("keys") ); - sources.push_back( g_strdup(INKSCAPE_KEYSDIR) ); + using namespace Inkscape::IO::Resource; + std::list<char *> sources; + + sources.push_back(g_strdup(get_path(USER, KEYS))); + sources.push_back(g_strdup(get_path(SYSTEM, KEYS))); // loop through possible keyboard shortcut file locations. while (!sources.empty()) { @@ -227,14 +225,12 @@ void sp_shortcut_get_file_names(std::vector<Glib::ustring> *names, std::vector<G gchar *filename = 0; while ((filename = (gchar *) g_dir_read_name(directory)) != NULL) { gchar* lower = g_ascii_strdown(filename, -1); - if (!strcmp(dirname, Inkscape::Application::profile_path("keys")) && - !strcmp(lower, "default.xml")) { + if (!strcmp(lower, "default.xml")) { // Dont add the users custom keys file continue; } - if (!strcmp(dirname, INKSCAPE_KEYSDIR) && - !strcmp(lower, "inkscape.xml")) { - // Dont add system inkscape.xml (since its a duplicate? of dfefault.xml) + if (!strcmp(lower, "inkscape.xml")) { + // Dont add system inkscape.xml (since its a duplicate? of default.xml) continue; } if (g_str_has_suffix(lower, ".xml")) { diff --git a/src/ui/dialog/export.cpp b/src/ui/dialog/export.cpp index 1bb952de4..b1b1cc291 100644 --- a/src/ui/dialog/export.cpp +++ b/src/ui/dialog/export.cpp @@ -54,6 +54,7 @@ #include "extension/db.h" #include "io/sys.h" +#include "io/resource.h" #include "helper/png-write.h" @@ -564,7 +565,7 @@ Glib::ustring Export::create_filepath_from_id (Glib::ustring id, const Glib::ust } if (directory.empty()) { - directory = INKSCAPE.homedir_path(NULL); + directory = Inkscape::IO::Resource::homedir_path(NULL); } Glib::ustring filename = Glib::build_filename(directory, id+".png"); diff --git a/src/ui/dialog/filedialogimpl-gtkmm.cpp b/src/ui/dialog/filedialogimpl-gtkmm.cpp index 92e9ce834..b69e9ce97 100644 --- a/src/ui/dialog/filedialogimpl-gtkmm.cpp +++ b/src/ui/dialog/filedialogimpl-gtkmm.cpp @@ -27,6 +27,7 @@ #include "ui/dialog-events.h" #include "ui/interface.h" #include "io/sys.h" +#include "io/resource.h" #include "path-prefix.h" #include "preferences.h" @@ -1038,13 +1039,12 @@ FileSaveDialogImplGtk::FileSaveDialogImplGtk(Gtk::Window &parentWindow, const Gl } // allow easy access to the user's own templates folder - gchar *templates = Inkscape::Application::profile_path("templates"); + using namespace Inkscape::IO::Resource; + char const *templates = Inkscape::IO::Resource::get_path(USER, TEMPLATES); if (Inkscape::IO::file_test(templates, G_FILE_TEST_EXISTS) && Inkscape::IO::file_test(templates, G_FILE_TEST_IS_DIR) && g_path_is_absolute(templates)) { add_shortcut_folder(templates); } - g_free(templates); - // if (extension == NULL) // checkbox.set_sensitive(FALSE); diff --git a/src/ui/dialog/inkscape-preferences.cpp b/src/ui/dialog/inkscape-preferences.cpp index 646439613..1ad44941f 100644 --- a/src/ui/dialog/inkscape-preferences.cpp +++ b/src/ui/dialog/inkscape-preferences.cpp @@ -1947,7 +1947,7 @@ void InkscapePreferences::initPageSystem() _page_system.add_group_header( _("System info")); - _sys_user_config.set_text((char const *)Inkscape::Application::profile_path("")); + _sys_user_config.set_text((char const *)Inkscape::IO::Resource::profile_path("")); _sys_user_config.set_editable(false); _page_system.add_line(true, _("User config: "), _sys_user_config, "", _("Location of users configuration"), true); diff --git a/src/ui/dialog/swatches.cpp b/src/ui/dialog/swatches.cpp index 87bfa9252..82b099bd1 100644 --- a/src/ui/dialog/swatches.cpp +++ b/src/ui/dialog/swatches.cpp @@ -512,15 +512,16 @@ compare_swatch_names(SwatchPage const *a, SwatchPage const *b) { static void loadEmUp() { + using namespace Inkscape::IO::Resource; static bool beenHere = false; gboolean userPalette = true; if ( !beenHere ) { beenHere = true; std::list<gchar *> sources; - sources.push_back( Inkscape::Application::profile_path("palettes") ); - sources.push_back( g_strdup(INKSCAPE_PALETTESDIR) ); - sources.push_back( g_strdup(CREATE_PALETTESDIR) ); + sources.push_back(g_strdup(get_path(USER, PALETTES))); + sources.push_back(g_strdup(get_path(SYSTEM, PALETTES))); + sources.push_back(g_strdup(get_path(CREATE, PALETTES))); // Use this loop to iterate through a list of possible document locations. while (!sources.empty()) { diff --git a/src/ui/dialog/symbols.cpp b/src/ui/dialog/symbols.cpp index e9a13620b..b7a43a1ca 100644 --- a/src/ui/dialog/symbols.cpp +++ b/src/ui/dialog/symbols.cpp @@ -31,6 +31,7 @@ #include <glibmm/i18n.h> #include "path-prefix.h" #include "io/sys.h" +#include "io/resource.h" #include "ui/cache/svg_preview_cache.h" #include "ui/clipboard.h" @@ -577,19 +578,15 @@ void SymbolsDialog::get_symbols() { std::list<Glib::ustring> directories; -// \TODO optimize this - - if( Inkscape::IO::file_test( INKSCAPE_SYMBOLSDIR, G_FILE_TEST_EXISTS ) && - Inkscape::IO::file_test( INKSCAPE_SYMBOLSDIR, G_FILE_TEST_IS_DIR ) ) { - directories.push_back( INKSCAPE_SYMBOLSDIR ); - } - if( Inkscape::IO::file_test( Inkscape::Application::profile_path("symbols"), G_FILE_TEST_EXISTS ) && - Inkscape::IO::file_test( Inkscape::Application::profile_path("symbols"), G_FILE_TEST_IS_DIR ) ) { - directories.push_back( Inkscape::Application::profile_path("symbols") ); - } + using namespace Inkscape::IO::Resource; + directories.push_back(get_path_ustring(USER, SYMBOLS)); + directories.push_back(get_path_ustring(SYSTEM, SYMBOLS)); std::list<Glib::ustring>::iterator it; for( it = directories.begin(); it != directories.end(); ++it ) { + if(!Inkscape::IO::file_test((*it).c_str(), G_FILE_TEST_IS_DIR)) { + continue; + } GError *err = 0; GDir *dir = g_dir_open( (*it).c_str(), 0, &err ); diff --git a/src/ui/dialog/template-load-tab.cpp b/src/ui/dialog/template-load-tab.cpp index 7b96c2b97..10b4716ff 100644 --- a/src/ui/dialog/template-load-tab.cpp +++ b/src/ui/dialog/template-load-tab.cpp @@ -24,6 +24,8 @@ #include "file.h" #include "path-prefix.h" +using namespace Inkscape::IO::Resource; + namespace Inkscape { namespace UI { @@ -57,7 +59,6 @@ TemplateLoadTab::TemplateLoadTab(NewFromTemplate* parent) sigc::mem_fun(*this, &TemplateLoadTab::_keywordSelected)); this->show_all(); - _loading_path = ""; _loadTemplates(); _initLists(); } @@ -207,11 +208,8 @@ void TemplateLoadTab::_refreshTemplatesList() void TemplateLoadTab::_loadTemplates() { - // user's local dir - _getTemplatesFromDir(Inkscape::Application::profile_path("templates") + _loading_path); - - // system templates dir - _getTemplatesFromDir(INKSCAPE_TEMPLATESDIR + _loading_path); + _getTemplatesFromDomain(USER); + _getTemplatesFromDomain(SYSTEM); // procedural templates _getProceduralTemplates(); @@ -252,11 +250,12 @@ TemplateLoadTab::TemplateData TemplateLoadTab::_processTemplateFile(const std::s } -void TemplateLoadTab::_getTemplatesFromDir(const std::string &path) +void TemplateLoadTab::_getTemplatesFromDomain(Domain domain) { - if ( !Glib::file_test(path, Glib::FILE_TEST_EXISTS) || - !Glib::file_test(path, Glib::FILE_TEST_IS_DIR)) + Glib::ustring path = get_path_ustring(domain, TEMPLATES); + if (!Glib::file_test(path, Glib::FILE_TEST_IS_DIR)) { return; + } Glib::Dir dir(path); diff --git a/src/ui/dialog/template-load-tab.h b/src/ui/dialog/template-load-tab.h index d11c4c77f..0a5521d93 100644 --- a/src/ui/dialog/template-load-tab.h +++ b/src/ui/dialog/template-load-tab.h @@ -21,6 +21,7 @@ #include <string> #include "xml/node.h" +#include "io/resource.h" #include "extension/effect.h" @@ -66,7 +67,6 @@ protected: Glib::ustring _current_keyword; Glib::ustring _current_template; - std::string _loading_path; std::map<Glib::ustring, TemplateData> _tdata; std::set<Glib::ustring> _keywords; @@ -100,7 +100,7 @@ private: void _getDataFromNode(Inkscape::XML::Node *, TemplateData &); void _getProceduralTemplates(); - void _getTemplatesFromDir(const std::string &); + void _getTemplatesFromDomain(Inkscape::IO::Resource::Domain domain); void _keywordSelected(); TemplateData _processTemplateFile(const std::string &); diff --git a/src/widgets/icon.cpp b/src/widgets/icon.cpp index 885deaab7..730fe3e31 100644 --- a/src/widgets/icon.cpp +++ b/src/widgets/icon.cpp @@ -34,6 +34,7 @@ #include "display/drawing-item.h" #include "display/drawing.h" #include "io/sys.h" +#include "io/resource.h" #include "sp-root.h" #include "sp-namedview.h" #include "util/units.h" @@ -1237,14 +1238,15 @@ GdkPixbuf *get_cached_pixbuf(Glib::ustring const &key) { std::list<gchar*> &IconImpl::icons_svg_paths() { + using namespace Inkscape::IO::Resource; static std::list<gchar *> sources; static bool initialized = false; if (!initialized) { // Fall back from user prefs dir into system locations. - gchar *userdir = Inkscape::Application::profile_path("icons"); - sources.push_back(g_build_filename(userdir,"icons.svg", NULL)); - sources.push_back(g_build_filename(INKSCAPE_PIXMAPDIR, "icons.svg", NULL)); - g_free(userdir); + // doctormo 2017 hackfest - I've left this modification very light + // because there is a refactoring of the icons underway. + sources.push_back(g_strdup(get_path(USER, ICONS, "icons.svg"))); + sources.push_back(g_strdup(get_path(SYSTEM, ICONS, "icons.svg"))); initialized = true; } return sources; diff --git a/src/widgets/toolbox.cpp b/src/widgets/toolbox.cpp index 65c54f0ce..672cb708b 100644 --- a/src/widgets/toolbox.cpp +++ b/src/widgets/toolbox.cpp @@ -102,7 +102,7 @@ using Inkscape::UI::ToolboxFactory; using Inkscape::UI::Tools::ToolBase; using Inkscape::IO::Resource::get_filename; -using Inkscape::IO::Resource::UI; +using Inkscape::IO::Resource::UIS; typedef void (*SetupFunction)(GtkWidget *toolbox, SPDesktop *desktop); typedef void (*UpdateFunction)(SPDesktop *desktop, ToolBase *eventcontext, GtkWidget *toolbox); @@ -840,10 +840,10 @@ static void setupToolboxCommon( GtkWidget *toolbox, gtk_ui_manager_insert_action_group( mgr, mainActions->gobj(), 0 ); - char const *filename = get_filename(UI, ui_file); - gtk_ui_manager_add_ui_from_file( mgr, filename, &err ); + Glib::ustring filename = get_filename(UIS, ui_file); + gtk_ui_manager_add_ui_from_file( mgr, filename.c_str(), &err ); if(err) { - g_warning("Failed to load %s: %s", filename, err->message); + g_warning("Failed to load %s: %s", filename.c_str(), err->message); g_error_free(err); return; } @@ -984,10 +984,10 @@ void setup_aux_toolbox(GtkWidget *toolbox, SPDesktop *desktop) GError *err = 0; gtk_ui_manager_insert_action_group( mgr, mainActions->gobj(), 0 ); - char const *filename = get_filename(UI, "select-toolbar.ui"); - guint ret = gtk_ui_manager_add_ui_from_file(mgr, filename, &err); + Glib::ustring filename = get_filename(UIS, "select-toolbar.ui"); + guint ret = gtk_ui_manager_add_ui_from_file(mgr, filename.c_str(), &err); if(err) { - g_warning("Failed to load aux toolbar %s: %s", filename, err->message); + g_warning("Failed to load aux toolbar %s: %s", filename.c_str(), err->message); g_error_free(err); return; } |
