[gnote] Port inserttimestamp addint to new Preferences



commit 23ea54da4a1cc97b6918ca9cd3abd8150327cc4a
Author: Aurimas Äernius <aurisc4 gmail com>
Date:   Mon Jun 27 11:45:19 2011 +0300

    Port inserttimestamp addint to new Preferences
    
    Use new Preferences API with Gio::Settings.

 .../inserttimestamp/inserttimestampnoteaddin.cpp   |   26 +++++++------------
 .../inserttimestamp/inserttimestampnoteaddin.hpp   |    3 +-
 .../inserttimestamp/inserttimestamppreferences.cpp |   16 +++++++----
 .../inserttimestamp/inserttimestamppreferences.hpp |    3 ++
 4 files changed, 24 insertions(+), 24 deletions(-)
---
diff --git a/src/addins/inserttimestamp/inserttimestampnoteaddin.cpp b/src/addins/inserttimestamp/inserttimestampnoteaddin.cpp
index 7e4f624..cfc3422 100644
--- a/src/addins/inserttimestamp/inserttimestampnoteaddin.cpp
+++ b/src/addins/inserttimestamp/inserttimestampnoteaddin.cpp
@@ -23,12 +23,10 @@
 #include <glibmm/i18n.h>
 
 #include "sharp/datetime.hpp"
+#include "inserttimestamppreferences.hpp"
 #include "inserttimestamppreferencesfactory.hpp"
 #include "inserttimestampnoteaddin.hpp"
 #include "notewindow.hpp"
-#include "preferences.hpp"
-
-using gnote::Preferences;
 
 namespace inserttimestamp {
 
@@ -86,12 +84,11 @@ namespace inserttimestamp {
     m_item->show ();
     add_plugin_menu_item (m_item);
 
-    // Get the format from GConf and subscribe to changes
-    m_date_format = Preferences::obj().get<std::string>(
-      Preferences::INSERT_TIMESTAMP_FORMAT);
-    Preferences::obj().signal_setting_changed().connect(
-      sigc::mem_fun(
-        *this, &InsertTimestampNoteAddin::on_format_setting_changed));
+    Glib::RefPtr<Gio::Settings> settings = gnote::Preferences::obj()
+      .get_or_load_schema_settings(SCHEMA_INSERT_TIMESTAMP);
+    m_date_format = settings->get_string(INSERT_TIMESTAMP_FORMAT);
+    settings->signal_changed().connect(
+      sigc::mem_fun(*this, &InsertTimestampNoteAddin::on_format_setting_changed));
   }
 
 
@@ -105,14 +102,11 @@ namespace inserttimestamp {
   }
 
 
-  void InsertTimestampNoteAddin::on_format_setting_changed(gnote::Preferences*, 
-                                                           GConfEntry* entry)
+  void InsertTimestampNoteAddin::on_format_setting_changed(const Glib::ustring & key)
   {
-    const gchar *key = gconf_entry_get_key(entry);
-    if(strcmp(key, Preferences::INSERT_TIMESTAMP_FORMAT) == 0) {
-      GConfValue * conf_value = gconf_entry_get_value(entry);
-      const gchar *value = gconf_value_get_string(conf_value);
-      m_date_format = value ? value : "";
+    if(key == INSERT_TIMESTAMP_FORMAT) {
+      m_date_format = gnote::Preferences::obj().get_or_load_schema_settings(
+          SCHEMA_INSERT_TIMESTAMP)->get_string(INSERT_TIMESTAMP_FORMAT);
     }
   }
 
diff --git a/src/addins/inserttimestamp/inserttimestampnoteaddin.hpp b/src/addins/inserttimestamp/inserttimestampnoteaddin.hpp
index 122bcdb..9461154 100644
--- a/src/addins/inserttimestamp/inserttimestampnoteaddin.hpp
+++ b/src/addins/inserttimestamp/inserttimestampnoteaddin.hpp
@@ -29,7 +29,6 @@
 
 #include "sharp/dynamicmodule.hpp"
 #include "noteaddin.hpp"
-#include "preferences.hpp"
 
 namespace inserttimestamp {
 
@@ -63,7 +62,7 @@ public:
   virtual void on_note_opened();
 private:
   void on_menu_item_activated();
-  void on_format_setting_changed(gnote::Preferences*, GConfEntry*);
+  void on_format_setting_changed(const Glib::ustring & key);
 
   std::string    m_date_format;
   Gtk::MenuItem *m_item;
diff --git a/src/addins/inserttimestamp/inserttimestamppreferences.cpp b/src/addins/inserttimestamp/inserttimestamppreferences.cpp
index 3e4d380..d6ae551 100644
--- a/src/addins/inserttimestamp/inserttimestamppreferences.cpp
+++ b/src/addins/inserttimestamp/inserttimestamppreferences.cpp
@@ -32,6 +32,9 @@ using gnote::Preferences;
 
 namespace inserttimestamp {
 
+  const char * SCHEMA_INSERT_TIMESTAMP = "org.gnome.gnote.insert-timestamp";
+  const char * INSERT_TIMESTAMP_FORMAT = "format";
+
   bool InsertTimestampPreferences::s_static_inited = false;
   std::vector<std::string> InsertTimestampPreferences::s_formats;
 
@@ -54,8 +57,9 @@ namespace inserttimestamp {
   {
     _init_static();
     // Get current values
-    std::string dateFormat = Preferences::obj().get<std::string> (
-      Preferences::INSERT_TIMESTAMP_FORMAT);
+    Glib::RefPtr<Gio::Settings> settings = Preferences::obj().get_or_load_schema_settings(
+        SCHEMA_INSERT_TIMESTAMP);
+    std::string dateFormat = settings->get_string(INSERT_TIMESTAMP_FORMAT);
 
     sharp::DateTime now = sharp::DateTime::now();
 
@@ -104,7 +108,7 @@ namespace inserttimestamp {
     customBox->pack_start (*custom_entry);
 
     sharp::PropertyEditor *  entryEditor = new sharp::PropertyEditor(
-      Preferences::INSERT_TIMESTAMP_FORMAT, *custom_entry);
+      settings, INSERT_TIMESTAMP_FORMAT, *custom_entry);
     entryEditor->setup ();
 
     // Activate/deactivate widgets
@@ -119,7 +123,7 @@ namespace inserttimestamp {
         // Found format in list
         useCustom = false;
         break;
-      }	
+      }
     }
 
     if (useCustom) {
@@ -176,8 +180,8 @@ namespace inserttimestamp {
     if (iter) {
       std::string format;
       iter->get_value(1, format);
-      Preferences::obj().set<std::string>(Preferences::INSERT_TIMESTAMP_FORMAT,
-                                          format);
+      Preferences::obj().get_or_load_schema_settings(SCHEMA_INSERT_TIMESTAMP)->set_string(
+          INSERT_TIMESTAMP_FORMAT, format);
     }
   }
 
diff --git a/src/addins/inserttimestamp/inserttimestamppreferences.hpp b/src/addins/inserttimestamp/inserttimestamppreferences.hpp
index 215f13c..c80f68d 100644
--- a/src/addins/inserttimestamp/inserttimestamppreferences.hpp
+++ b/src/addins/inserttimestamp/inserttimestamppreferences.hpp
@@ -32,6 +32,9 @@
 
 namespace inserttimestamp {
 
+extern const char * SCHEMA_INSERT_TIMESTAMP;
+extern const char * INSERT_TIMESTAMP_FORMAT;
+
 class InsertTimestampPreferences
   : public Gtk::VBox
 {



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