diff options
| author | Marc Jeanmougin <marc@jeanmougin.fr> | 2019-01-11 08:35:13 +0000 |
|---|---|---|
| committer | Marc Jeanmougin <marc@jeanmougin.fr> | 2019-01-11 08:35:13 +0000 |
| commit | 513b467b11116b80e576e273285cc7f5356e6adf (patch) | |
| tree | f098fc4ec7a6e395ca61957f8d0717d6e008880f /src/preferences.cpp | |
| parent | Prevent window from stealing key presses. (diff) | |
| download | inkscape-513b467b11116b80e576e273285cc7f5356e6adf.tar.gz inkscape-513b467b11116b80e576e273285cc7f5356e6adf.zip | |
Add button to delete prefs
Diffstat (limited to 'src/preferences.cpp')
| -rw-r--r-- | src/preferences.cpp | 39 |
1 files changed, 30 insertions, 9 deletions
diff --git a/src/preferences.cpp b/src/preferences.cpp index 51c363fce..4321b9e0d 100644 --- a/src/preferences.cpp +++ b/src/preferences.cpp @@ -160,15 +160,6 @@ void Preferences::_load() g_free(msg); return; } - // create some subdirectories for user stuff - char const *user_dirs[] = {"extensions", "fonts", "icons", "keys", "palettes", "templates", nullptr}; - for (int i=0; user_dirs[i]; ++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, G_FILE_TEST_IS_DIR)) { // The profile dir is not actually a directory //_reportError(Glib::ustring::compose(_("%1 is not a valid directory."), @@ -178,6 +169,15 @@ void Preferences::_load() g_free(msg); return; } + // create some subdirectories for user stuff + char const *user_dirs[] = {"extensions", "fonts", "icons", "keys", "palettes", "templates", nullptr}; + for (int i=0; user_dirs[i]; ++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]); + if (!g_file_test(dir, G_FILE_TEST_EXISTS)) + g_mkdir(dir, 0755); + g_free(dir); + } // The profile dir exists and is valid. if (!g_file_set_contents(_prefs_filename.c_str(), preferences_skeleton, PREFERENCES_SKELETON_SIZE, nullptr)) { // The write failed. @@ -292,6 +292,27 @@ void Preferences::save() } } +/** + * Deletes the preferences.xml file + */ +void Preferences::reset() +{ + if (g_file_test(_prefs_filename.c_str(), G_FILE_TEST_EXISTS)) { + int retcode = g_unlink (_prefs_filename.c_str()); + if (retcode == 0) g_strdup_printf(_("Preferences file was deleted.")); + else g_warning(_("There was an error trying to delete the preferences file.")); + } + for (_ObsMap::iterator i = _observer_map.begin(); i != _observer_map.end(); ) { + delete (*i++).second; // avoids reference to a deleted key + } + _observer_map.clear(); + Inkscape::GC::release(_prefs_doc); + _prefs_doc = nullptr; + _loadDefaults(); + _load(); + save(); +} + bool Preferences::getLastError( Glib::ustring& primary, Glib::ustring& secondary ) { bool result = _hasError; |
