From: joncruz Date: Tue, 10 Nov 2009 02:29:49 +0000 (+0000) Subject: Fixed copying of old settings, along with some data() vs. c_str() cleanup. Fixes... X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=9fae10676238f30f8405c5239208bcd403833702;p=inkscape.git Fixed copying of old settings, along with some data() vs. c_str() cleanup. Fixes bug #437929. --- diff --git a/src/preferences.cpp b/src/preferences.cpp index d4d67837b..39a9e4d69 100644 --- a/src/preferences.cpp +++ b/src/preferences.cpp @@ -90,7 +90,7 @@ Preferences::Preferences() : _prefs_dir = path; g_free(path); - path = profile_path(_prefs_basename.data()); + path = profile_path(_prefs_basename.c_str()); _prefs_filename = path; g_free(path); @@ -132,17 +132,17 @@ void Preferences::_load() // NOTE: After we upgrade to Glib 2.16, use Glib::ustring::compose // 1. Does the file exist? - if (!g_file_test(_prefs_filename.data(), G_FILE_TEST_EXISTS)) { + if (!g_file_test(_prefs_filename.c_str(), G_FILE_TEST_EXISTS)) { // No - we need to create one. // Does the profile directory exist? - if (!g_file_test(_prefs_dir.data(), G_FILE_TEST_EXISTS)) { + if (!g_file_test(_prefs_dir.c_str(), G_FILE_TEST_EXISTS)) { // No - create the profile directory - if (g_mkdir(_prefs_dir.data(), 0755)) { + if (g_mkdir(_prefs_dir.c_str(), 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).data()); + Glib::filename_to_utf8(_prefs_dir).c_str()); _reportError(msg, not_saved); g_free(msg); return; @@ -155,28 +155,32 @@ void Preferences::_load() g_free(dir); } - } else if (!g_file_test(_prefs_dir.data(), G_FILE_TEST_IS_DIR)) { + } else if (!g_file_test(_prefs_dir.c_str(), 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).data()); + Glib::filename_to_utf8(_prefs_dir).c_str()); _reportError(msg, not_saved); g_free(msg); return; } // The profile dir exists and is valid. - if (!g_file_set_contents(_prefs_filename.data(), preferences_skeleton, PREFERENCES_SKELETON_SIZE, NULL)) { + if (!g_file_set_contents(_prefs_filename.c_str(), preferences_skeleton, PREFERENCES_SKELETON_SIZE, NULL)) { // The write failed. //_reportError(Glib::ustring::compose(_("Failed to create the preferences file %1."), // Glib::filename_to_utf8(_prefs_filename)), not_saved); gchar *msg = g_strdup_printf(_("Failed to create the preferences file %s."), - Glib::filename_to_utf8(_prefs_filename).data()); + Glib::filename_to_utf8(_prefs_filename).c_str()); _reportError(msg, not_saved); g_free(msg); return; } + if ( migrateFromDoc ) { + migrateDetails( migrateFromDoc, _prefs_doc ); + } + // The prefs file was just created. // We can return now and skip the rest of the load process. _writable = true; @@ -188,9 +192,6 @@ void Preferences::_load() Inkscape::XML::Document *prefs_read = loadImpl( _prefs_filename, errMsg ); if ( prefs_read ) { - if ( migrateFromDoc ) { - migrateDetails( migrateFromDoc, _prefs_doc ); - } // Merge the loaded prefs with defaults. _prefs_doc->root()->mergeFrom(prefs_read->root(), "id"); Inkscape::GC::release(prefs_read); @@ -204,9 +205,9 @@ void Preferences::_load() static Inkscape::XML::Document *loadImpl( std::string const& prefsFilename, Glib::ustring & errMsg ) { // 2. Is it a regular file? - if (!g_file_test(prefsFilename.data(), G_FILE_TEST_IS_REGULAR)) { + if (!g_file_test(prefsFilename.c_str(), G_FILE_TEST_IS_REGULAR)) { gchar *msg = g_strdup_printf(_("The preferences file %s is not a regular file."), - Glib::filename_to_utf8(prefsFilename).data()); + Glib::filename_to_utf8(prefsFilename).c_str()); errMsg = msg; g_free(msg); return 0; @@ -214,9 +215,9 @@ static Inkscape::XML::Document *loadImpl( std::string const& prefsFilename, Glib // 3. Is the file readable? gchar *prefs_xml = NULL; gsize len = 0; - if (!g_file_get_contents(prefsFilename.data(), &prefs_xml, &len, NULL)) { + if (!g_file_get_contents(prefsFilename.c_str(), &prefs_xml, &len, NULL)) { gchar *msg = g_strdup_printf(_("The preferences file %s could not be read."), - Glib::filename_to_utf8(prefsFilename).data()); + Glib::filename_to_utf8(prefsFilename).c_str()); errMsg = msg; g_free(msg); return 0; @@ -227,7 +228,7 @@ static Inkscape::XML::Document *loadImpl( std::string const& prefsFilename, Glib g_free(prefs_xml); if (!prefs_read) { gchar *msg = g_strdup_printf(_("The preferences file %s is not a valid XML document."), - Glib::filename_to_utf8(prefsFilename).data()); + Glib::filename_to_utf8(prefsFilename).c_str()); errMsg = msg; g_free(msg); return 0; @@ -236,7 +237,7 @@ static Inkscape::XML::Document *loadImpl( std::string const& prefsFilename, Glib // 5. Basic sanity check: does the root element have a correct name? if (strcmp(prefs_read->root()->name(), "inkscape")) { gchar *msg = g_strdup_printf(_("The file %s is not a valid Inkscape preferences file."), - Glib::filename_to_utf8(prefsFilename).data()); + Glib::filename_to_utf8(prefsFilename).c_str()); errMsg = msg; g_free(msg); Inkscape::GC::release(prefs_read); @@ -273,7 +274,7 @@ void Preferences::save() // There are many other factors, so ask if you would like to learn them. - JAC Glib::ustring utf8name = Glib::filename_to_utf8(_prefs_filename); if (!utf8name.empty()) { - sp_repr_save_file(_prefs_doc, utf8name.data()); + sp_repr_save_file(_prefs_doc, utf8name.c_str()); } } } @@ -306,11 +307,11 @@ void Preferences::migrate( std::string const& legacyDir, std::string const& pref #ifdef S_IXOTH mode |= S_IXOTH; #endif - if ( g_mkdir_with_parents(prefdir.data(), mode) == -1 ) { + if ( g_mkdir_with_parents(prefdir.c_str(), mode) == -1 ) { } else { } - gchar * oldPrefFile = g_build_filename(legacyDir.data(), PREFERENCES_FILE_NAME, NULL); + gchar * oldPrefFile = g_build_filename(legacyDir.c_str(), PREFERENCES_FILE_NAME, NULL); if (oldPrefFile) { if (g_file_test(oldPrefFile, G_FILE_TEST_EXISTS)) { Glib::ustring errMsg; @@ -319,11 +320,16 @@ void Preferences::migrate( std::string const& legacyDir, std::string const& pref Glib::ustring docId("documents"); Glib::ustring recentId("recent"); Inkscape::XML::Node *node = oldPrefs->root(); - Inkscape::XML::Node *child = NULL; + Inkscape::XML::Node *child = 0; + Inkscape::XML::Node *recentNode = 0; + if (node->attribute("version")) { + node->setAttribute("version", "1"); + } for (child = node->firstChild(); child; child = child->next()) { if (docId == child->attribute("id")) { for (child = child->firstChild(); child; child = child->next()) { if (recentId == child->attribute("id")) { + recentNode = child; for (child = child->firstChild(); child; child = child->next()) { gchar const* uri = child->attribute("uri"); if (uri) { @@ -337,6 +343,11 @@ void Preferences::migrate( std::string const& legacyDir, std::string const& pref } } + if (recentNode) { + while (recentNode->firstChild()) { + recentNode->removeChild(recentNode->firstChild()); + } + } migrateFromDoc = oldPrefs; //Inkscape::GC::release(oldPrefs); oldPrefs = 0; @@ -442,7 +453,7 @@ void Preferences::setDouble(Glib::ustring const &pref_path, double value) */ void Preferences::setString(Glib::ustring const &pref_path, Glib::ustring const &value) { - _setRawValue(pref_path, value.data()); + _setRawValue(pref_path, value.c_str()); } void Preferences::setStyle(Glib::ustring const &pref_path, SPCSSAttr *style) @@ -612,7 +623,7 @@ Inkscape::XML::Node *Preferences::_getNode(Glib::ustring const &pref_key, bool c Inkscape::XML::Node *node = _prefs_doc->root(); Inkscape::XML::Node *child = NULL; - gchar **splits = g_strsplit(pref_key.data(), "/", 0); + gchar **splits = g_strsplit(pref_key.c_str(), "/", 0); if ( splits ) { for (int part_i = 0; splits[part_i]; ++part_i) { @@ -665,7 +676,7 @@ void Preferences::_getRawValue(Glib::ustring const &path, gchar const *&result) if ( node == NULL ) { result = NULL; } else { - gchar const *attr = node->attribute(attr_key.data()); + gchar const *attr = node->attribute(attr_key.c_str()); if ( attr == NULL ) { result = NULL; } else { @@ -682,7 +693,7 @@ void Preferences::_setRawValue(Glib::ustring const &path, gchar const *value) // set the attribute Inkscape::XML::Node *node = _getNode(node_key, true); - node->setAttribute(attr_key.data(), value); + node->setAttribute(attr_key.c_str(), value); } // The _extract* methods are where the actual wrok is done - they define how preferences are stored @@ -737,7 +748,7 @@ SPCSSAttr *Preferences::_extractInheritedStyle(Entry const &v) _keySplit(v._pref_path, node_key, attr_key); Inkscape::XML::Node *node = _getNode(node_key, false); - return sp_repr_css_attr_inherited(node, attr_key.data()); + return sp_repr_css_attr_inherited(node, attr_key.c_str()); } // XML backend helper: Split the path into a node key and an attribute key.