summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMartin Owens <doctormo@gmail.com>2017-07-02 14:47:03 +0000
committerMartin Owens <doctormo@gmail.com>2017-07-02 14:47:03 +0000
commit7dc5626af3eb924fa381c46491cd49178a78cd73 (patch)
treee50a3b98ce1393b7a06efbd11425f8c458b0cbbb /src
parentpyc files are generated when testing modules, ignore them (diff)
downloadinkscape-7dc5626af3eb924fa381c46491cd49178a78cd73.tar.gz
inkscape-7dc5626af3eb924fa381c46491cd49178a78cd73.zip
Move directory scanners to new get_filenames(...) calls
Diffstat (limited to 'src')
-rw-r--r--src/extension/dependency.cpp12
-rw-r--r--src/extension/extension.cpp1
-rw-r--r--src/extension/extension.h1
-rw-r--r--src/extension/implementation/script.cpp22
-rw-r--r--src/extension/implementation/xslt.cpp22
-rw-r--r--src/extension/init.cpp66
-rw-r--r--src/io/resource.cpp14
-rw-r--r--src/shortcuts.cpp91
-rw-r--r--src/ui/dialog/swatches.cpp59
-rw-r--r--src/ui/dialog/symbols.cpp97
-rw-r--r--src/ui/dialog/template-load-tab.cpp87
11 files changed, 121 insertions, 351 deletions
diff --git a/src/extension/dependency.cpp b/src/extension/dependency.cpp
index 837520381..827475011 100644
--- a/src/extension/dependency.cpp
+++ b/src/extension/dependency.cpp
@@ -18,6 +18,7 @@
#include "dependency.h"
#include "db.h"
#include "extension.h"
+#include "io/resource.h"
namespace Inkscape {
namespace Extension {
@@ -151,12 +152,11 @@ bool Dependency::check (void) const
Glib::ustring location(_string);
switch (_location) {
case LOCATION_EXTENSIONS: {
- for (unsigned int i=0; i<Inkscape::Extension::Extension::search_path.size(); i++) {
- std::string temploc = Glib::build_filename(Inkscape::Extension::Extension::search_path[i], location);
- if (Glib::file_test(temploc, filetest)) {
- location = temploc;
- break;
- }
+ using namespace Inkscape::IO::Resource;
+ Glib::ustring temploc = get_filename(EXTENSIONS, location.c_str());
+ if(Glib::file_test(temploc, filetest)) {
+ location = temploc;
+ break;
}
} /* PASS THROUGH!!! */
case LOCATION_ABSOLUTE: {
diff --git a/src/extension/extension.cpp b/src/extension/extension.cpp
index 9c0221521..f1b328f05 100644
--- a/src/extension/extension.cpp
+++ b/src/extension/extension.cpp
@@ -40,7 +40,6 @@ namespace Extension {
/* Inkscape::Extension::Extension */
-std::vector<const gchar *> Extension::search_path;
std::ofstream Extension::error_file;
/**
diff --git a/src/extension/extension.h b/src/extension/extension.h
index bbd6d068b..962c3c8a7 100644
--- a/src/extension/extension.h
+++ b/src/extension/extension.h
@@ -95,7 +95,6 @@ public:
STATE_UNLOADED, /**< The extension has not been loaded */
STATE_DEACTIVATED /**< The extension is missing something which makes it unusable */
} state_t;
- static std::vector<const gchar *> search_path; /**< A vector of paths to search for extensions */
private:
gchar *id; /**< The unique identifier for the Extension */
diff --git a/src/extension/implementation/script.cpp b/src/extension/implementation/script.cpp
index b1058d415..8da56fecd 100644
--- a/src/extension/implementation/script.cpp
+++ b/src/extension/implementation/script.cpp
@@ -33,6 +33,7 @@
#include "extension/db.h"
#include "inkscape.h"
#include "io/sys.h"
+#include "io/resource.h"
#include "preferences.h"
#include "script.h"
#include "selection.h"
@@ -184,25 +185,8 @@ std::string Script::solve_reldir(Inkscape::XML::Node *reprin) {
Glib::ustring str = reprin->firstChild()->content();
return str;
}
-
- Glib::ustring reldir = s;
- for (unsigned int i=0;
- i < Inkscape::Extension::Extension::search_path.size();
- i++) {
-
- gchar * fname = g_build_filename(
- Inkscape::Extension::Extension::search_path[i],
- reprin->firstChild()->content(),
- NULL);
- Glib::ustring filename = fname;
- g_free(fname);
- //printf("Filename: %s\n", filename.c_str());
- if ( Inkscape::IO::file_test(filename.c_str(), G_FILE_TEST_EXISTS) ) {
- return Glib::filename_from_utf8(filename);
- }
- }
-
- return "";
+ using namespace Inkscape::IO::Resource;
+ return get_filename(EXTENSIONS, reprin->firstChild()->content());
}
diff --git a/src/extension/implementation/xslt.cpp b/src/extension/implementation/xslt.cpp
index 373378d97..94852a98e 100644
--- a/src/extension/implementation/xslt.cpp
+++ b/src/extension/implementation/xslt.cpp
@@ -23,6 +23,7 @@
#include "extension/input.h"
#include "io/sys.h"
+#include "io/resource.h"
#include <unistd.h>
#include <cstring>
#include "document.h"
@@ -62,30 +63,13 @@ Glib::ustring XSLT::solve_reldir(Inkscape::XML::Node *reprin) {
}
Glib::ustring reldir = s;
-
if (reldir == "extensions") {
-
- for (unsigned int i=0;
- i < Inkscape::Extension::Extension::search_path.size();
- i++) {
-
- gchar * fname = g_build_filename(
- Inkscape::Extension::Extension::search_path[i],
- reprin->firstChild()->content(),
- NULL);
- Glib::ustring filename = fname;
- g_free(fname);
-
- if ( Inkscape::IO::file_test(filename.c_str(), G_FILE_TEST_EXISTS) )
- return filename;
-
- }
+ using namespace Inkscape::IO::Resource;
+ return get_filename(EXTENSIONS, reprin->firstChild()->content());
} else {
Glib::ustring str = reprin->firstChild()->content();
return str;
}
-
- return "";
}
bool XSLT::check(Inkscape::Extension::Extension *module)
diff --git a/src/extension/init.cpp b/src/extension/init.cpp
index a40196a74..9830b0176 100644
--- a/src/extension/init.cpp
+++ b/src/extension/init.cpp
@@ -117,7 +117,6 @@ namespace Extension {
the extension directory and parsed */
#define SP_MODULE_EXTENSION "inx"
-static void build_module_from_domain(Domain domain);
static void check_extensions();
/**
@@ -154,8 +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_domain to parse the
- * Inkscape extensions directory.
+ * convinent place to put them.
*/
void
init()
@@ -246,8 +244,9 @@ init()
Internal::Filter::Filter::filters_all();
- build_module_from_domain(USER);
- build_module_from_domain(SYSTEM);
+ for(auto &filename: get_filenames(EXTENSIONS, {SP_MODULE_EXTENSION})) {
+ build_from_file(filename.c_str());
+ }
/* this is at the very end because it has several catch-alls
* that are possibly over-ridden by other extensions (such as
@@ -267,63 +266,6 @@ init()
);
}
-/**
- * \return none
- * \brief This function parses a directory for files of SP_MODULE_EXTENSION
- * type and loads them.
- * \param dirname The directory that should be searched for modules
- *
- * Here is just a basic function that moves through a directory. It looks at every entry, and
- * compares its filename with SP_MODULE_EXTENSION. Of those that pass, build_from_file is called
- * with their filenames.
- */
-static void
-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;
- }
-
- if (!Glib::file_test(std::string(dirname), Glib::FILE_TEST_EXISTS | Glib::FILE_TEST_IS_DIR)) {
- return;
- }
-
- // 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);
- if (!directory) {
- gchar *safeDir = Inkscape::IO::sanitizeString(dirname);
- g_warning(_("Modules directory (%s) is unavailable. External modules in that directory will not be loaded."), safeDir);
- g_free(safeDir);
- return;
- }
-
- gchar *filename;
- while ((filename = (gchar *)g_dir_read_name(directory)) != NULL) {
- if (strlen(filename) < strlen(SP_MODULE_EXTENSION)) {
- continue;
- }
-
- if (strcmp(SP_MODULE_EXTENSION, filename + (strlen(filename) - strlen(SP_MODULE_EXTENSION)))) {
- continue;
- }
-
- gchar *pathname = g_build_filename(dirname, filename, (char *) NULL);
- build_from_file(pathname);
- g_free(pathname);
- }
-
- g_dir_close(directory);
-
- return;
-}
-
-
static void
check_extensions_internal(Extension *in_plug, gpointer in_data)
{
diff --git a/src/io/resource.cpp b/src/io/resource.cpp
index 6a388c1ac..aa13de683 100644
--- a/src/io/resource.cpp
+++ b/src/io/resource.cpp
@@ -205,7 +205,7 @@ std::vector<Glib::ustring> get_filenames(Domain domain, Type type, std::vector<c
*
* &files - Output list to populate
* path - The directory to parse, will add nothing if directory doesn't exist
- * extensions - Only add files with these extensions.
+ * extensions - Only add files with these extensions, they must be duplicated
* exclusions - Exclude files that exactly match these names.
*/
void get_filenames_from_path(std::vector<Glib::ustring> &files, Glib::ustring path, std::vector<const char *> extensions, std::vector<const char *> exclusions)
@@ -217,15 +217,23 @@ void get_filenames_from_path(std::vector<Glib::ustring> &files, Glib::ustring pa
Glib::Dir dir(path);
std::string file = dir.read_name();
while (!file.empty()){
- bool reject = false;
+ // If not extensions are specified, don't reject ANY files.
+ bool reject = !extensions.empty();
+
+ // Unreject any file which has one of the extensions.
for (auto &ext: extensions) {
- reject |= !Glib::str_has_suffix(file, ext);
+ reject ^= Glib::str_has_suffix(file, ext);
}
+
+ // Reject any file which matches the exclusions.
for (auto &exc: exclusions) {
reject |= Glib::str_has_prefix(file, exc);
}
+
+ // Reject any filename which isn't a regular file
Glib::ustring filename = Glib::build_filename(path, file);
reject |= !Glib::file_test(filename, Glib::FILE_TEST_IS_REGULAR);
+
if(!reject) {
files.push_back(filename);
}
diff --git a/src/shortcuts.cpp b/src/shortcuts.cpp
index 708e58198..e7343c5e4 100644
--- a/src/shortcuts.cpp
+++ b/src/shortcuts.cpp
@@ -215,79 +215,30 @@ Inkscape::XML::Document *sp_shortcut_create_template_file(char const *filename)
* Dont add the users custom keyboards file
*/
void sp_shortcut_get_file_names(std::vector<Glib::ustring> *names, std::vector<Glib::ustring> *paths) {
-
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()) {
- gchar *dirname = sources.front();
- if ( Inkscape::IO::file_test( dirname, G_FILE_TEST_EXISTS )
- && Inkscape::IO::file_test( dirname, G_FILE_TEST_IS_DIR )) {
- GError *err = 0;
- GDir *directory = g_dir_open(dirname, 0, &err);
- if (!directory) {
- gchar *safeDir = Inkscape::IO::sanitizeString(dirname);
- g_warning(_("Keyboard directory (%s) is unavailable."), safeDir);
- g_free(safeDir);
- } else {
- gchar *filename = 0;
- while ((filename = (gchar *) g_dir_read_name(directory)) != NULL) {
- gchar* lower = g_ascii_strdown(filename, -1);
- if (!strcmp(lower, "default.xml")) {
- // Dont add the users custom keys file
- continue;
- }
- 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")) {
- gchar* full = g_build_filename(dirname, filename, NULL);
- if (!Inkscape::IO::file_test(full, G_FILE_TEST_IS_DIR)) {
-
- // Get the "key name" from the root element of each file
- XML::Document *doc=sp_repr_read_file(full, NULL);
- if (!doc) {
- g_warning("Unable to read keyboard shortcut file %s", full);
- continue;
- }
- XML::Node *root=doc->root();
- if (strcmp(root->name(), "keys")) {
- g_warning("Not a shortcut keys file %s", full);
- Inkscape::GC::release(doc);
- continue;
- }
-
- gchar const *name=root->attribute("name");
- Glib::ustring label(filename);
- if (name) {
- label = Glib::ustring(name)+ " (" + filename + ")";
- }
-
- if (!strcmp(filename, "default.xml")) {
- paths->insert(paths->begin(), full);
- names->insert(names->begin(), label.c_str());
- } else {
- paths->push_back(full);
- names->push_back(label.c_str());
- }
-
- Inkscape::GC::release(doc);
- }
- g_free(full);
- }
- g_free(lower);
- }
- g_dir_close(directory);
- }
+
+ for(auto &filename: get_filenames(KEYS, {".xml"}, {"default.xml", "inkscape.xml"})) {
+ Glib::ustring label = Glib::path_get_basename(filename);
+
+ XML::Document *doc = sp_repr_read_file(filename.c_str(), NULL);
+ if (!doc) {
+ g_warning("Unable to read keyboard shortcut file %s", filename.c_str());
+ continue;
}
- g_free(dirname);
- sources.pop_front();
+ // Get the "key name" from the root element of each files
+ XML::Node *root=doc->root();
+ if (!strcmp(root->name(), "keys")) {
+ gchar const *name=root->attribute("name");
+ if (name) {
+ label = Glib::ustring(name) + " (" + label + ")";
+ }
+ paths->push_back(filename.c_str());
+ names->push_back(label.c_str());
+ } else {
+ g_warning("Not a shortcut keys file %s", filename.c_str());
+ }
+ Inkscape::GC::release(doc);
}
}
diff --git a/src/ui/dialog/swatches.cpp b/src/ui/dialog/swatches.cpp
index 82b099bd1..28269c81b 100644
--- a/src/ui/dialog/swatches.cpp
+++ b/src/ui/dialog/swatches.cpp
@@ -24,6 +24,8 @@
#include <glibmm/i18n.h>
#include <glibmm/main.h>
#include <glibmm/timer.h>
+#include <glibmm/fileutils.h>
+#include <glibmm/miscutils.h>
#include "color-item.h"
#include "desktop.h"
@@ -384,10 +386,11 @@ static bool parseNum( char*& str, int& val ) {
}
-void _loadPaletteFile( gchar const *filename, gchar const *path, gboolean user/*=FALSE*/ )
+void _loadPaletteFile(Glib::ustring path, gboolean user/*=FALSE*/)
{
+ Glib::ustring filename = Glib::path_get_basename(path);
char block[1024];
- FILE *f = Inkscape::IO::fopen_utf8name(path, "r" );
+ FILE *f = Inkscape::IO::fopen_utf8name(path.c_str(), "r");
if ( f ) {
char* result = fgets( block, sizeof(block), f );
if ( result ) {
@@ -396,7 +399,7 @@ void _loadPaletteFile( gchar const *filename, gchar const *path, gboolean user/*
bool hasErr = false;
SwatchPage *onceMore = new SwatchPage();
- onceMore->_name = filename;
+ onceMore->_name = filename.c_str();
do {
result = fgets( block, sizeof(block), f );
@@ -518,56 +521,18 @@ static void loadEmUp()
if ( !beenHere ) {
beenHere = true;
- std::list<gchar *> sources;
- 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()) {
- gchar *dirname = sources.front();
- if ( Inkscape::IO::file_test( dirname, G_FILE_TEST_EXISTS )
- && Inkscape::IO::file_test( dirname, G_FILE_TEST_IS_DIR )) {
- GError *err = 0;
- GDir *directory = g_dir_open(dirname, 0, &err);
- if (!directory) {
- gchar *safeDir = Inkscape::IO::sanitizeString(dirname);
- g_warning(_("Palettes directory (%s) is unavailable."), safeDir);
- g_free(safeDir);
- } else {
- gchar *filename = 0;
- while ((filename = (gchar *)g_dir_read_name(directory)) != NULL) {
- gchar* lower = g_ascii_strdown( filename, -1 );
-// if ( g_str_has_suffix(lower, ".gpl") ) {
- if ( !g_str_has_suffix(lower, "~") ) {
- gchar* full = g_build_filename(dirname, filename, NULL);
- if ( !Inkscape::IO::file_test( full, G_FILE_TEST_IS_DIR ) ) {
- _loadPaletteFile(filename, full, userPalette);
- }
- g_free(full);
- }
-// }
- g_free(lower);
- }
- g_dir_close(directory);
- }
- }
-
- // toss the dirname
- g_free(dirname);
- sources.pop_front();
- userPalette = false;
+ for(auto &filename: get_filenames(PALETTES, {".gpl"})) {
+ bool userPalette = Inkscape::IO::file_is_writable(filename.c_str());
+ _loadPaletteFile(filename, userPalette);
}
}
- // Sort the list of swatches by name, grouped by user/system
- userSwatchPages.sort(compare_swatch_names);
- systemSwatchPages.sort(compare_swatch_names);
-
+ // Sort the list of swatches by name, grouped by user/system
+ userSwatchPages.sort(compare_swatch_names);
+ systemSwatchPages.sort(compare_swatch_names);
}
-
SwatchesPanel& SwatchesPanel::getInstance()
{
return *new SwatchesPanel();
diff --git a/src/ui/dialog/symbols.cpp b/src/ui/dialog/symbols.cpp
index aa3d86b00..96ccf416b 100644
--- a/src/ui/dialog/symbols.cpp
+++ b/src/ui/dialog/symbols.cpp
@@ -495,20 +495,19 @@ class REVENGE_API RVNGSVGDrawingGenerator_WithTitle : public RVNGSVGDrawingGener
#endif
// Read Visio stencil files
-SPDocument* read_vss( gchar* fullname, Glib::ustring name ) {
-
+SPDocument* read_vss(Glib::ustring filename, Glib::ustring name ) {
+ gchar *fullname;
#ifdef WIN32
// RVNGFileStream uses fopen() internally which unfortunately only uses ANSI encoding on Windows
// therefore attempt to convert uri to the system codepage
// even if this is not possible the alternate short (8.3) file name will be used if available
- fullname = g_win32_locale_filename_from_utf8(fullname);
+ fullname = g_win32_locale_filename_from_utf8(fullname.c_str());
+ #else
+ filename.copy(fullname, filename.length());
#endif
RVNGFileStream input(fullname);
-
- #ifdef WIN32
- g_free(fullname);
- #endif
+ g_free(fullname);
if (!libvisio::VisioDocument::isSupported(&input)) {
return NULL;
@@ -590,74 +589,32 @@ SPDocument* read_vss( gchar* fullname, Glib::ustring name ) {
/* Hunts preference directories for symbol files */
void SymbolsDialog::get_symbols() {
- std::list<Glib::ustring> directories;
-
- 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 );
- if( dir ) {
-
- gchar *filename = 0;
- while( (filename = (gchar *)g_dir_read_name( dir ) ) != NULL) {
-
- gchar *fullname = g_build_filename((*it).c_str(), filename, NULL);
-
- if ( !Inkscape::IO::file_test( fullname, G_FILE_TEST_IS_DIR )
- && ( Glib::str_has_suffix(fullname, ".svg") || Glib::str_has_suffix(fullname, ".vss") ) ) {
-
- Glib::ustring fn( filename );
- Glib::ustring tag = fn.substr( fn.find_last_of(".") + 1 );
-
- SPDocument* symbol_doc = NULL;
+ using namespace Inkscape::IO::Resource;
+ SPDocument* symbol_doc = NULL;
+ Glib::ustring title;
+
+ for(auto &filename: get_filenames(SYMBOLS, {".svg", ".vss"})) {
+ if(Glib::str_has_suffix(filename, ".svg")) {
+ symbol_doc = SPDocument::createNewDoc(filename.c_str(), FALSE);
+ if(symbol_doc) {
+ title = symbol_doc->getRoot()->title();
+ if(title.empty()) {
+ title = _("Unnamed Symbols");
+ }
+ }
+ }
#ifdef WITH_LIBVISIO
- if( tag.compare( "vss" ) == 0 ) {
- // strip extension from filename and use it as name for the symbol set
- Glib::ustring name = Glib::ustring(filename);
- name = name.erase(name.rfind('.'));
-
- symbol_doc = read_vss( fullname, name );
- if( symbol_doc ) {
- symbolSets[name]= symbol_doc;
- symbolSet->append(name);
- }
- }
+ if(Glib::str_has_suffix(filename, ".vss")) {
+ Glib::ustring title = filename.erase(filename.rfind('.'));
+ symbol_doc = read_vss(filename, title);
+ }
#endif
- // Try to read all remaining files as SVG
- if( !symbol_doc ) {
-
- symbol_doc = SPDocument::createNewDoc( fullname, FALSE );
- if( symbol_doc ) {
-
- const gchar *title = symbol_doc->getRoot()->title();
-
- // A user provided file may not have a title
- if( title != NULL ) {
- title = g_dpgettext2(NULL, "Symbol", title); // Translate
- } else {
- title = _("Unnamed Symbols");
- }
-
- symbolSets[Glib::ustring(title)] = symbol_doc;
- symbolSet->append(title);
- }
- }
-
+ if(symbol_doc) {
+ symbolSets[title]= symbol_doc;
+ symbolSet->append(title);
}
- g_free( fullname );
- }
- g_dir_close( dir );
}
- }
}
GSList* SymbolsDialog::symbols_in_doc_recursive (SPObject *r, GSList *l)
diff --git a/src/ui/dialog/template-load-tab.cpp b/src/ui/dialog/template-load-tab.cpp
index 10b4716ff..7dd889b2f 100644
--- a/src/ui/dialog/template-load-tab.cpp
+++ b/src/ui/dialog/template-load-tab.cpp
@@ -2,7 +2,7 @@
* @brief New From Template abstract tab implementation
*/
/* Authors:
- * Jan Darowski <jan.darowski@gmail.com>, supervised by Krzysztof Kosiński
+ * Jan Darowski <jan.darowski@gmail.com>, supervised by Krzysztof Kosiński
*
* Copyright (C) 2013 Authors
* Released under GNU GPL, read the file 'COPYING' for more information
@@ -38,27 +38,27 @@ TemplateLoadTab::TemplateLoadTab(NewFromTemplate* parent)
set_border_width(10);
_info_widget = Gtk::manage(new TemplateWidget());
-
+
Gtk::Label *title;
title = Gtk::manage(new Gtk::Label(_("Search:")));
_search_box.pack_start(*title, Gtk::PACK_SHRINK);
_search_box.pack_start(_keywords_combo, Gtk::PACK_SHRINK, 5);
-
+
_tlist_box.pack_start(_search_box, Gtk::PACK_SHRINK, 10);
-
+
pack_start(_tlist_box, Gtk::PACK_SHRINK);
pack_start(*_info_widget, Gtk::PACK_EXPAND_WIDGET, 5);
-
+
Gtk::ScrolledWindow *scrolled;
scrolled = Gtk::manage(new Gtk::ScrolledWindow());
scrolled->set_policy(Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
scrolled->add(_tlist_view);
_tlist_box.pack_start(*scrolled, Gtk::PACK_EXPAND_WIDGET, 5);
-
+
_keywords_combo.signal_changed().connect(
sigc::mem_fun(*this, &TemplateLoadTab::_keywordSelected));
this->show_all();
-
+
_loadTemplates();
_initLists();
}
@@ -91,14 +91,14 @@ void TemplateLoadTab::_displayTemplateInfo()
_info_widget->display(_tdata[_current_template]);
_parent_widget->setCreateButtonSensitive(true);
}
-
+
}
void TemplateLoadTab::_initKeywordsList()
{
_keywords_combo.append(_("All"));
-
+
for (std::set<Glib::ustring>::iterator it = _keywords.begin() ; it != _keywords.end() ; ++it){
_keywords_combo.append(*it);
}
@@ -111,15 +111,15 @@ void TemplateLoadTab::_initLists()
_tlist_view.set_model(_tlist_store);
_tlist_view.append_column("", _columns.textValue);
_tlist_view.set_headers_visible(false);
-
+
_initKeywordsList();
_refreshTemplatesList();
-
+
Glib::RefPtr<Gtk::TreeSelection> templateSelectionRef =
- _tlist_view.get_selection();
+ _tlist_view.get_selection();
templateSelectionRef->signal_changed().connect(
sigc::mem_fun(*this, &TemplateLoadTab::_displayTemplateInfo));
-
+
_tlist_view.signal_row_activated().connect(
sigc::mem_fun(*this, &TemplateLoadTab::_onRowActivated));
}
@@ -133,10 +133,10 @@ void TemplateLoadTab::_keywordSelected()
}
else
_current_search_type = LIST_KEYWORD;
-
+
if (_current_keyword == "" || _current_keyword == _("All"))
_current_search_type = ALL;
-
+
_refreshTemplatesList();
}
@@ -203,14 +203,17 @@ void TemplateLoadTab::_refreshTemplatesList()
_info_widget->clear();
_parent_widget->setCreateButtonSensitive(false);
}
-}
+}
void TemplateLoadTab::_loadTemplates()
{
- _getTemplatesFromDomain(USER);
- _getTemplatesFromDomain(SYSTEM);
-
+ for(auto &filename: get_filenames(TEMPLATES, {".svg"}, {"default.", "default_"})) {
+ TemplateData tmp = _processTemplateFile(filename);
+ if (tmp.display_name != "")
+ _tdata[tmp.display_name] = tmp;
+
+ }
// procedural templates
_getProceduralTemplates();
}
@@ -222,73 +225,51 @@ TemplateLoadTab::TemplateData TemplateLoadTab::_processTemplateFile(const std::s
result.path = path;
result.is_procedural = false;
result.preview_name = "";
-
+
// convert path into valid template name
result.display_name = Glib::path_get_basename(path);
gsize n = 0;
while ((n = result.display_name.find_first_of("_", 0)) < Glib::ustring::npos){
result.display_name.replace(n, 1, 1, ' ');
- }
+ }
n = result.display_name.rfind(".svg");
result.display_name.replace(n, 4, 1, ' ');
-
+
Inkscape::XML::Document *rdoc = sp_repr_read_file(path.data(), SP_SVG_NS_URI);
if (rdoc){
Inkscape::XML::Node *myRoot = rdoc->root();
if (strcmp(myRoot->name(), "svg:svg") != 0){ // Wrong file format
return result;
}
-
+
myRoot = sp_repr_lookup_name(myRoot, "inkscape:_templateinfo");
-
+
if (myRoot == NULL) // No template info
return result;
_getDataFromNode(myRoot, result);
}
-
- return result;
-}
-
-void TemplateLoadTab::_getTemplatesFromDomain(Domain domain)
-{
- Glib::ustring path = get_path_ustring(domain, TEMPLATES);
- if (!Glib::file_test(path, Glib::FILE_TEST_IS_DIR)) {
- return;
- }
-
- Glib::Dir dir(path);
-
- std::string file = Glib::build_filename(path, dir.read_name());
- while (file != path){
- if (Glib::str_has_suffix(file, ".svg") && !Glib::str_has_prefix(Glib::path_get_basename(file), "default.")){
- TemplateData tmp = _processTemplateFile(file);
- if (tmp.display_name != "")
- _tdata[tmp.display_name] = tmp;
- }
- file = Glib::build_filename(path, dir.read_name());
- }
+ return result;
}
-
void TemplateLoadTab::_getProceduralTemplates()
{
std::list<Inkscape::Extension::Effect *> effects;
Inkscape::Extension::db.get_effect_list(effects);
-
+
std::list<Inkscape::Extension::Effect *>::iterator it = effects.begin();
while (it != effects.end()){
Inkscape::XML::Node *myRoot;
myRoot = (*it)->get_repr();
myRoot = sp_repr_lookup_name(myRoot, "inkscape:_templateinfo");
-
+
if (myRoot){
TemplateData result;
result.display_name = (*it)->get_name();
result.is_procedural = true;
result.path = "";
result.tpl_effect = *it;
-
+
_getDataFromNode(myRoot, result);
_tdata[result.display_name] = result;
}
@@ -312,18 +293,18 @@ void TemplateLoadTab::_getDataFromNode(Inkscape::XML::Node *dataNode, TemplateDa
data.preview_name = currentData->firstChild()->content();
if ((currentData = sp_repr_lookup_name(dataNode, "inkscape:date")) != NULL)
data.creation_date = currentData->firstChild()->content();
-
+
if ((currentData = sp_repr_lookup_name(dataNode, "inkscape:_keywords")) != NULL){
Glib::ustring tplKeywords = _(currentData->firstChild()->content());
while (!tplKeywords.empty()){
std::size_t pos = tplKeywords.find_first_of(" ");
if (pos == Glib::ustring::npos)
pos = tplKeywords.size();
-
+
Glib::ustring keyword = tplKeywords.substr(0, pos).data();
data.keywords.insert(keyword.lowercase());
_keywords.insert(keyword.lowercase());
-
+
if (pos == tplKeywords.size())
break;
tplKeywords.erase(0, pos+1);