summaryrefslogtreecommitdiffstats
path: root/src/file.cpp
diff options
context:
space:
mode:
authorJon A. Cruz <jon@joncruz.org>2009-09-29 03:07:09 +0000
committerjoncruz <joncruz@users.sourceforge.net>2009-09-29 03:07:09 +0000
commit6793d0aeee098a4141883649c044df7bdc8614ae (patch)
tree4e975bea4c33f6e13b7e5c1ac4be7988901ff373 /src/file.cpp
parentRemove unused files: ftos.cpp and ftos.h (diff)
downloadinkscape-6793d0aeee098a4141883649c044df7bdc8614ae.tar.gz
inkscape-6793d0aeee098a4141883649c044df7bdc8614ae.zip
Fixed leaking memory and added proper name fallback. Applies modified patch and addresses bug #436151.
(bzr r8672)
Diffstat (limited to 'src/file.cpp')
-rw-r--r--src/file.cpp51
1 files changed, 34 insertions, 17 deletions
diff --git a/src/file.cpp b/src/file.cpp
index ef9706c33..4964d30d5 100644
--- a/src/file.cpp
+++ b/src/file.cpp
@@ -138,31 +138,48 @@ sp_file_new(const Glib::ustring &templ)
return dt;
}
-SPDesktop*
-sp_file_new_default()
+SPDesktop* sp_file_new_default()
{
std::list<gchar *> sources;
sources.push_back( profile_path("templates") ); // first try user's local dir
sources.push_back( g_strdup(INKSCAPE_TEMPLATESDIR) ); // then the system templates dir
-
- while (!sources.empty()) {
- gchar *dirname = sources.front();
- 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 *default_template = g_build_filename(dirname, _("default.svg"), NULL);
- if (Inkscape::IO::file_test(default_template, G_FILE_TEST_IS_REGULAR)) {
- return sp_file_new(default_template);
+ 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 const*>::iterator nameIt = baseNames.begin(); (nameIt != baseNames.end()) && !foundTemplate; ++nameIt) {
+ for (std::list<gchar *>::iterator it = sources.begin(); (it != sources.end()) && !foundTemplate; ++it) {
+ 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);
+ }
}
}
- g_free(dirname);
- sources.pop_front();
}
- return sp_file_new("");
+ for (std::list<gchar *>::iterator it = sources.begin(); it != sources.end(); ++it) {
+ g_free(*it);
+ }
+
+ SPDesktop* desk = sp_file_new(foundTemplate ? foundTemplate : "");
+ if (foundTemplate) {
+ g_free(foundTemplate);
+ foundTemplate = 0;
+ }
+ return desk;
}