diff options
| author | Jabiertxo Arraiza Cenoz <jtx@jtx.markerlab.es> | 2018-07-26 16:25:16 +0000 |
|---|---|---|
| committer | Jabiertxo Arraiza Cenoz <jtx@jtx.markerlab.es> | 2018-07-26 16:25:16 +0000 |
| commit | fe80b6735d74710229fadf503e750b615ab531f6 (patch) | |
| tree | 764c721a3bb5bf89cc5eb8b552fd167e2af42b9b /src | |
| parent | Fixing paths to allow themes and icons inside main inkscape instalation not o... (diff) | |
| download | inkscape-fe80b6735d74710229fadf503e750b615ab531f6.tar.gz inkscape-fe80b6735d74710229fadf503e750b615ab531f6.zip | |
Add allow to use system icon sets
Diffstat (limited to 'src')
| -rw-r--r-- | src/path-prefix.h | 4 | ||||
| -rw-r--r-- | src/ui/dialog/color-item.cpp | 8 | ||||
| -rw-r--r-- | src/ui/dialog/inkscape-preferences.cpp | 103 | ||||
| -rw-r--r-- | src/ui/widget/preferences-widget.cpp | 7 |
4 files changed, 81 insertions, 41 deletions
diff --git a/src/path-prefix.h b/src/path-prefix.h index a23ffdb48..5e8eec085 100644 --- a/src/path-prefix.h +++ b/src/path-prefix.h @@ -71,7 +71,7 @@ char *get_extensions_path(); # define INKSCAPE_GRADIENTSDIR append_inkscape_datadir("gradients") # define INKSCAPE_KEYSDIR append_inkscape_datadir("keys") # define INKSCAPE_ICONSDIR append_inkscape_datadir("icons") -# define INKSCAPE_PIXMAPSDIR append_inkscape_datadir("pixmaps") +# define INKSCAPE_PIXMAPSDIR append_inkscape_datadir("pixmaps") # define INKSCAPE_MARKERSDIR append_inkscape_datadir("markers") # define INKSCAPE_PALETTESDIR append_inkscape_datadir("palettes") # define INKSCAPE_PATTERNSDIR append_inkscape_datadir("patterns") @@ -123,7 +123,7 @@ char *get_extensions_path(); # define INKSCAPE_GRADIENTSDIR append_inkscape_datadir("inkscape/gradients") # define INKSCAPE_KEYSDIR append_inkscape_datadir("inkscape/keys") # define INKSCAPE_ICONSDIR append_inkscape_datadir("inkscape/icons") -# define INKSCAPE_PIXMAPSDIR append_inkscape_datadir("inkscape/pixmaps") +# define INKSCAPE_PIXMAPSDIR append_inkscape_datadir("inkscape/pixmaps") # define INKSCAPE_MARKERSDIR append_inkscape_datadir("inkscape/markers") # define INKSCAPE_PALETTESDIR append_inkscape_datadir("inkscape/palettes") # define INKSCAPE_PATTERNSDIR append_inkscape_datadir("inkscape/patterns") diff --git a/src/ui/dialog/color-item.cpp b/src/ui/dialog/color-item.cpp index 53f0d4c34..f90d301d3 100644 --- a/src/ui/dialog/color-item.cpp +++ b/src/ui/dialog/color-item.cpp @@ -194,7 +194,7 @@ static void colorItemDragBegin( GtkWidget */*widget*/, GdkDragContext* dc, gpoin if ( item ) { using Inkscape::IO::Resource::get_path; - using Inkscape::IO::Resource::ICONS; + using Inkscape::IO::Resource::PIXMAPS; using Inkscape::IO::Resource::SYSTEM; int width = 32; int height = 24; @@ -203,7 +203,7 @@ static void colorItemDragBegin( GtkWidget */*widget*/, GdkDragContext* dc, gpoin GError *error = nullptr; gsize bytesRead = 0; gsize bytesWritten = 0; - gchar *localFilename = g_filename_from_utf8( get_path(SYSTEM, ICONS, "remove-color.png"), + gchar *localFilename = g_filename_from_utf8( get_path(SYSTEM, PIXMAPS, "remove-color.png"), -1, &bytesRead, &bytesWritten, @@ -507,12 +507,12 @@ void ColorItem::_regenPreview(EekPreview * preview) { if ( def.getType() != ege::PaintDef::RGB ) { using Inkscape::IO::Resource::get_path; - using Inkscape::IO::Resource::ICONS; + using Inkscape::IO::Resource::PIXMAPS; using Inkscape::IO::Resource::SYSTEM; GError *error = nullptr; gsize bytesRead = 0; gsize bytesWritten = 0; - gchar *localFilename = g_filename_from_utf8( get_path(SYSTEM, ICONS, "remove-color.png"), + gchar *localFilename = g_filename_from_utf8( get_path(SYSTEM, PIXMAPS, "remove-color.png"), -1, &bytesRead, &bytesWritten, diff --git a/src/ui/dialog/inkscape-preferences.cpp b/src/ui/dialog/inkscape-preferences.cpp index 2a012ad98..161bd1173 100644 --- a/src/ui/dialog/inkscape-preferences.cpp +++ b/src/ui/dialog/inkscape-preferences.cpp @@ -581,16 +581,6 @@ void InkscapePreferences::initPageTools() #endif // WITH_LPETOOL } -gchar *_inkscape_get_theme_dir(void) -{ - const gchar *var; - - var = g_getenv("GTK_DATA_PREFIX"); - if (var == NULL) - var = g_getenv("GTK_PATH"); - return g_build_filename(var, "share", "themes", NULL); -} - static void _inkscape_fill_gtk(const gchar *path, GHashTable *t) { const gchar *dir_entry; @@ -611,6 +601,32 @@ static void _inkscape_fill_gtk(const gchar *path, GHashTable *t) g_dir_close(dir); } +static void _inkscape_fill_icons(const gchar *path, GHashTable *t) +{ + const gchar *dir_entry; + GDir *dir; + + dir = g_dir_open (path, 0, NULL); + if (!dir) { + return; + } + while ((dir_entry = g_dir_read_name (dir))) { + gchar *filename = g_build_filename (path, dir_entry, "index.theme", NULL); + gchar *scalable = g_build_filename (path, dir_entry, "scalable", NULL); + if (g_file_test (filename, G_FILE_TEST_IS_REGULAR) && + g_file_test (scalable, G_FILE_TEST_IS_DIR) && + g_strcmp0 (dir_entry, "default") != 0 && + !g_hash_table_contains (t, dir_entry)) + { + g_hash_table_add (t, g_strdup (dir_entry)); + } + g_free (filename); + g_free (scalable); + } + g_dir_close (dir); +} + + void InkscapePreferences::symbolicThemeCheck() { using namespace Inkscape::IO::Resource; @@ -648,6 +664,8 @@ void InkscapePreferences::symbolicThemeCheck() } } } + + void InkscapePreferences::initPageUI() { Gtk::TreeModel::iterator iter_ui = this->AddPage(_page_ui, _("Interface"), PREFS_PAGE_UI); @@ -800,14 +818,6 @@ void InkscapePreferences::initPageUI() } g_strfreev(builtin_themes); - path = g_strdup((char const *)Inkscape::IO::Resource::get_path(USER, DATADIR, "")); - _inkscape_fill_gtk(path, t); - g_free(path); - - path = g_strdup((char const *)Inkscape::IO::Resource::get_path(SYSTEM, DATADIR, "")); - _inkscape_fill_gtk(path, t); - g_free(path); - path = g_build_filename(g_get_user_data_dir(), "themes", NULL); _inkscape_fill_gtk(path, t); g_free(path); @@ -844,27 +854,52 @@ void InkscapePreferences::initPageUI() } { - using namespace Inkscape::IO::Resource; - auto folders = get_foldernames(ICONS, { "application" }); + GHashTable *t; + GHashTableIter iter; + gchar *iconTheme, *path; + gchar **builtin_icons; + GList *list, *l; + guint i; + const gchar *const *dirs; + + t = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL); + + path = g_build_filename(g_get_user_data_dir(), "icons", NULL); + _inkscape_fill_icons (path, t); + g_free(path); + + path = g_build_filename(g_get_home_dir(), ".icons", NULL); + _inkscape_fill_icons (path, t); + g_free(path); + + dirs = g_get_system_data_dirs(); + for (i = 0; dirs[i]; i++) { + path = g_build_filename(dirs[i], "icons", NULL); + _inkscape_fill_icons (path, t); + g_free(path); + } + + list = NULL; + g_hash_table_iter_init (&iter, t); + + while (g_hash_table_iter_next(&iter, (gpointer *)&iconTheme, NULL)){ + list = g_list_insert_sorted(list, iconTheme, (GCompareFunc)strcmp); + } std::vector<Glib::ustring> labels; std::vector<Glib::ustring> values; - for (auto &folder : folders) { - // from https://stackoverflow.com/questions/8520560/get-a-file-name-from-a-path#8520871 - // Maybe we can link boost path utilities - // Remove directory if present. - // Do this before extension removal incase directory has a period character. - const size_t last_slash_idx = folder.find_last_of("\\/"); - if (std::string::npos != last_slash_idx) { - folder.erase(0, last_slash_idx + 1); - } - - labels.push_back(folder); - values.push_back(folder); + for (l = list; l; l = l->next) { + iconTheme = (gchar *)l->data; + labels.push_back(Glib::ustring(iconTheme)); + values.push_back(Glib::ustring(iconTheme)); } - std::sort(labels.begin(), labels.end()); - std::sort(values.begin(), values.end()); +// std::sort(labels.begin(), labels.end()); +// std::sort(values.begin(), values.end()); labels.erase(unique(labels.begin(), labels.end()), labels.end()); values.erase(unique(values.begin(), values.end()), values.end()); + + g_list_free(list); + g_hash_table_destroy(t); + _icon_theme.init("/theme/iconTheme", labels, values, "hicolor"); _page_theme.add_line(false, _("Change icon theme:"), _icon_theme, "", "", false); _icon_theme.signal_changed().connect(sigc::mem_fun(*this, &InkscapePreferences::symbolicThemeCheck)); diff --git a/src/ui/widget/preferences-widget.cpp b/src/ui/widget/preferences-widget.cpp index c2cc34f52..8f293e2f5 100644 --- a/src/ui/widget/preferences-widget.cpp +++ b/src/ui/widget/preferences-widget.cpp @@ -908,8 +908,13 @@ void PrefOpenFolder::onRelatedButtonClickedCallback() #elif defined(__APPLE__) system(("open " + relatedEntry->get_text()).c_str()); #else - system(("xdg-open " + relatedEntry->get_text()).c_str()); + gchar *path = g_filename_to_uri(relatedEntry->get_text().c_str(), NULL, NULL); + Glib::ustring xgd = "xdg-open "; + xgd += path; + system((xgd).c_str()); + g_free(path); #endif + } void PrefFileButton::init(Glib::ustring const &prefs_path) |
