[gnote] Remove base::IniFile



commit db445160afc6f64bdd4d32986852478f6803b88f
Author: Aurimas Černius <aurisc4 gmail com>
Date:   Wed Apr 17 22:21:05 2013 +0300

    Remove base::IniFile
    
    Was only used in sticky notes import and is avoidable.

 src/Makefile.am                                    |   1 -
 .../stickynoteimport/stickynoteimportnoteaddin.cpp |  53 +++++++---
 src/base/inifile.cpp                               | 107 ---------------------
 src/base/inifile.hpp                               |  67 -------------
 4 files changed, 40 insertions(+), 188 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index f70f2e7..2408b6e 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -69,7 +69,6 @@ libgnote_la_LIBADD = $(LIBGNOTE_LIBS)
 libgnote_la_SOURCES = \
        base/singleton.hpp \
        base/macros.hpp \
-       base/inifile.hpp base/inifile.cpp \
        gnome_keyring/keyringexception.hpp \
        gnome_keyring/ring.hpp gnome_keyring/ring.cpp \
        sharp/datetime.hpp sharp/datetime.cpp \
diff --git a/src/addins/stickynoteimport/stickynoteimportnoteaddin.cpp 
b/src/addins/stickynoteimport/stickynoteimportnoteaddin.cpp
index 6edfe29..6128bfd 100644
--- a/src/addins/stickynoteimport/stickynoteimportnoteaddin.cpp
+++ b/src/addins/stickynoteimport/stickynoteimportnoteaddin.cpp
@@ -18,6 +18,7 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+#include <fstream>
 #include <string.h>
 
 #include <boost/format.hpp>
@@ -27,7 +28,6 @@
 #include <gtkmm/image.h>
 #include <gtkmm/stock.h>
 
-#include "base/inifile.hpp"
 #include "stickynoteimportnoteaddin.hpp"
 #include "sharp/files.hpp"
 #include "sharp/string.hpp"
@@ -112,41 +112,68 @@ bool StickyNoteImportNoteAddin::want_to_run(gnote::NoteManager & manager)
   std::string prefs_file =
     Glib::build_filename(manager.get_addin_manager().get_prefs_dir(),
                          PREFS_FILE);
-  base::IniFile ini_file(prefs_file);
-  ini_file.load();
 
-  if(s_sticky_file_might_exist) {
-    want_run = !ini_file.get_bool("status", "first_run");
+  try {
+    Glib::KeyFile ini_file;
+    ini_file.load_from_file(prefs_file);
+
+    if(s_sticky_file_might_exist) {
+      want_run = !ini_file.get_boolean("status", "first_run");
+    }
+  }
+  catch(Glib::Error & e) {
+    DBG_OUT("Failed to read key file %s: %s", prefs_file.c_str(), e.what().c_str());
+    want_run = true;
   }
+
   return want_run;
 }
 
 
 bool StickyNoteImportNoteAddin::first_run(gnote::NoteManager & manager)
 {
-  base::IniFile ini_file(Glib::build_filename(
+  std::string prefs_file(Glib::build_filename(
                            manager.get_addin_manager().get_prefs_dir(), 
                            PREFS_FILE));
-  
-  ini_file.load();
 
-  bool firstRun = !ini_file.get_bool("status", "first_run");
+  Glib::KeyFile ini_file;
+  try {
+    ini_file.load_from_file(prefs_file);
+  }
+  catch(Glib::Error&) {
+    // ignore
+  }
+
+  bool firstRun = true;
+  try {
+    ini_file.get_boolean("status", "first_run");
+  }
+  catch(Glib::Error&) {
+    // ignore
+  }
 
-  if (firstRun) {
-    ini_file.set_bool("status", "first_run", true);
+  if(firstRun) {
+    ini_file.set_boolean("status", "first_run", true);
 
     DBG_OUT("%s", DEBUG_FIRST_RUN_DETECTED);
 
     xmlDocPtr xml_doc = get_sticky_xml_doc();
-    if (xml_doc) {
+    if(xml_doc) {
       // Don't show dialog when automatically importing
-      import_notes (xml_doc, false, manager);
+      import_notes(xml_doc, false, manager);
       xmlFreeDoc(xml_doc);
     }
     else {
       firstRun = false;
     }
+
+    std::ofstream fout(prefs_file.c_str());
+    if(fout) {
+      fout << ini_file.to_data().c_str();
+      fout.close();
+    }
   }
+
   return firstRun;
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]