[gnote] Rewrite preferences for Gio::Settings
- From: Aurimas Äernius <aurimasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnote] Rewrite preferences for Gio::Settings
- Date: Mon, 27 Jun 2011 09:19:43 +0000 (UTC)
commit 8db4e50fed41fb7bf3de6e4cde211f2bb64719a2
Author: Aurimas Äernius <aurisc4 gmail com>
Date: Tue Jun 21 23:00:55 2011 +0300
Rewrite preferences for Gio::Settings
Remove usage of GConf.
Change API for Gio::Settings.
src/preferences.cpp | 172 ++++++++++++++++-----------------------------------
src/preferences.hpp | 85 +++++++-------------------
2 files changed, 75 insertions(+), 182 deletions(-)
---
diff --git a/src/preferences.cpp b/src/preferences.cpp
index d956097..4487396 100644
--- a/src/preferences.cpp
+++ b/src/preferences.cpp
@@ -1,6 +1,7 @@
/*
* gnote
*
+ * Copyright (C) 2011 Aurimas Cernius
* Copyright (C) 2009 Hubert Figuiere
*
* This program is free software: you can redistribute it and/or modify
@@ -26,144 +27,77 @@
namespace gnote {
- const char * Preferences::ENABLE_SPELLCHECKING = "/apps/gnote/enable_spellchecking";
- const char * Preferences::ENABLE_WIKIWORDS = "/apps/gnote/enable_wikiwords";
- const char * Preferences::ENABLE_CUSTOM_FONT = "/apps/gnote/enable_custom_font";
- const char * Preferences::ENABLE_KEYBINDINGS = "/apps/gnote/enable_keybindings";
- const char * Preferences::ENABLE_STARTUP_NOTES = "/apps/gnote/enable_startup_notes";
- const char * Preferences::ENABLE_AUTO_BULLETED_LISTS = "/apps/gnote/enable_bulleted_lists";
- const char * Preferences::ENABLE_ICON_PASTE = "/apps/gnote/enable_icon_paste";
- const char * Preferences::ENABLE_CLOSE_NOTE_ON_ESCAPE = "/apps/gnote/enable_close_note_on_escape";
+ const char * Preferences::SCHEMA_GNOTE = "org.gnome.gnote";
+ const char * Preferences::SCHEMA_KEYBINDINGS = "org.gnome.gnote.global-keybindings";
+ const char * Preferences::SCHEMA_SYNC = "org.gnome.gnote.sync";
+ const char * Preferences::SCHEMA_DESKTOP_GNOME_INTERFACE = "org.gnome.desktop.interface";
- const char * Preferences::START_NOTE_URI = "/apps/gnote/start_note";
- const char * Preferences::CUSTOM_FONT_FACE = "/apps/gnote/custom_font_face";
- const char * Preferences::MENU_NOTE_COUNT = "/apps/gnote/menu_note_count";
- const char * Preferences::MENU_PINNED_NOTES = "/apps/gnote/menu_pinned_notes";
+ const char * Preferences::ENABLE_SPELLCHECKING = "enable-spellchecking";
+ const char * Preferences::ENABLE_WIKIWORDS = "enable-wikiwords";
+ const char * Preferences::ENABLE_CUSTOM_FONT = "enable-custom-font";
+ const char * Preferences::ENABLE_KEYBINDINGS = "enable-keybindings";
+ const char * Preferences::ENABLE_STARTUP_NOTES = "enable-startup-notes";
+ const char * Preferences::ENABLE_AUTO_BULLETED_LISTS = "enable-bulleted-lists";
+ const char * Preferences::ENABLE_ICON_PASTE = "enable-icon-paste";
+ const char * Preferences::ENABLE_CLOSE_NOTE_ON_ESCAPE = "enable-close-note-on-escape";
- const char * Preferences::KEYBINDING_SHOW_NOTE_MENU = "/apps/gnote/global_keybindings/show_note_menu";
- const char * Preferences::KEYBINDING_OPEN_START_HERE = "/apps/gnote/global_keybindings/open_start_here";
- const char * Preferences::KEYBINDING_CREATE_NEW_NOTE = "/apps/gnote/global_keybindings/create_new_note";
- const char * Preferences::KEYBINDING_OPEN_SEARCH = "/apps/gnote/global_keybindings/open_search";
- const char * Preferences::KEYBINDING_OPEN_RECENT_CHANGES = "/apps/gnote/global_keybindings/open_recent_changes";
+ const char * Preferences::START_NOTE_URI = "start-note";
+ const char * Preferences::CUSTOM_FONT_FACE = "custom-font-face";
+ const char * Preferences::MENU_NOTE_COUNT = "menu-note-count";
+ const char * Preferences::MENU_PINNED_NOTES = "menu-pinned-notes";
- const char * Preferences::EXPORTHTML_LAST_DIRECTORY = "/apps/gnote/export_html/last_directory";
- const char * Preferences::EXPORTHTML_EXPORT_LINKED = "/apps/gnote/export_html/export_linked";
- const char * Preferences::EXPORTHTML_EXPORT_LINKED_ALL = "/apps/gnote/export_html/export_linked_all";
+ const char * Preferences::KEYBINDING_SHOW_NOTE_MENU = "show-note-menu";
+ const char * Preferences::KEYBINDING_OPEN_START_HERE = "open-start-here";
+ const char * Preferences::KEYBINDING_CREATE_NEW_NOTE = "create-new-note";
+ const char * Preferences::KEYBINDING_OPEN_SEARCH = "open-search";
+ const char * Preferences::KEYBINDING_OPEN_RECENT_CHANGES = "open-recent-changes";
- const char * Preferences::SYNC_CLIENT_ID = "/apps/gnote/sync/sync_guid";
- const char * Preferences::SYNC_LOCAL_PATH = "/apps/gnote/sync/sync_local_path";
- const char * Preferences::SYNC_SELECTED_SERVICE_ADDIN = "/apps/gnote/sync/sync_selected_service_addin";
- const char * Preferences::SYNC_CONFIGURED_CONFLICT_BEHAVIOR = "/apps/gnote/sync/sync_conflict_behavior";
+ const char * Preferences::SYNC_CLIENT_ID = "sync-guid";
+ const char * Preferences::SYNC_LOCAL_PATH = "sync-local-path";
+ const char * Preferences::SYNC_SELECTED_SERVICE_ADDIN = "sync-selected-service-addin";
+ const char * Preferences::SYNC_CONFIGURED_CONFLICT_BEHAVIOR = "sync-conflict-behavior";
- const char * Preferences::NOTE_RENAME_BEHAVIOR = "/apps/gnote/note_rename_behavior";
+ const char * Preferences::NOTE_RENAME_BEHAVIOR = "note-rename-behavior";
- const char * Preferences::INSERT_TIMESTAMP_FORMAT = "/apps/gnote/insert_timestamp/format";
-
- const char * Preferences::SEARCH_WINDOW_X_POS = "/apps/gnote/search_window_x_pos";
- const char * Preferences::SEARCH_WINDOW_Y_POS = "/apps/gnote/search_window_y_pos";
- const char * Preferences::SEARCH_WINDOW_WIDTH = "/apps/gnote/search_window_width";
- const char * Preferences::SEARCH_WINDOW_HEIGHT = "/apps/gnote/search_window_height";
- const char * Preferences::SEARCH_WINDOW_SPLITTER_POS = "/apps/gnote/search_window_splitter_pos";
+ const char * Preferences::SEARCH_WINDOW_X_POS = "search-window-x-pos";
+ const char * Preferences::SEARCH_WINDOW_Y_POS = "search-window-y-pos";
+ const char * Preferences::SEARCH_WINDOW_WIDTH = "search-window-width";
+ const char * Preferences::SEARCH_WINDOW_HEIGHT = "search-window-height";
+ const char * Preferences::SEARCH_WINDOW_SPLITTER_POS = "search-window-splitter-pos";
+
+ const char * Preferences::DESKTOP_GNOME_FONT = "document-font-name";
+ const char * Preferences::DESKTOP_GNOME_KEY_THEME = "gtk-key-theme";
Preferences::Preferences()
- : m_client(gconf_client_get_default())
{
- gconf_client_add_dir(m_client, "/apps/gnote", GCONF_CLIENT_PRELOAD_NONE, NULL);
- m_cnx = gconf_client_notify_add(m_client, "/apps/gnote" ,
- GConfClientNotifyFunc(&Preferences::gconf_notify_glue),
- this, NULL, NULL);
+ m_schemas[SCHEMA_GNOTE] = Gio::Settings::create(SCHEMA_GNOTE);
+ m_schemas[SCHEMA_KEYBINDINGS] = Gio::Settings::create(SCHEMA_KEYBINDINGS);
}
- Preferences::~Preferences()
+ Glib::RefPtr<Gio::Settings> Preferences::get_schema_settings(const std::string & schema)
{
- gconf_client_remove_dir(m_client, "/apps/gnote", NULL);
- gconf_client_notify_remove(m_client, m_cnx);
- }
+ std::map<std::string, Glib::RefPtr<Gio::Settings> >::iterator iter = m_schemas.find(schema);
+ if(iter != m_schemas.end()) {
+ return iter->second;
+ }
- void Preferences::gconf_notify_glue(GConfClient */*client*/, guint /*cid*/, GConfEntry *entry,
- Preferences * self)
- {
- self->m_signal_setting_changed(self, entry);
+ return Glib::RefPtr<Gio::Settings>();
}
- template<>
- void Preferences::set<bool>(const char *p, const bool & v)
+ Glib::RefPtr<Gio::Settings> Preferences::get_or_load_schema_settings(const std::string & schema)
{
- gconf_client_set_bool(m_client, p, v, NULL);
- }
+ std::map<std::string, Glib::RefPtr<Gio::Settings> >::iterator iter = m_schemas.find(schema);
+ if(iter != m_schemas.end()) {
+ return iter->second;
+ }
- template<>
- void Preferences::set<std::string>(const char *p, const std::string & v)
- {
- gconf_client_set_string(m_client, p, v.c_str(), NULL);
- }
-
- template<>
- void Preferences::set<int>(const char *p, const int & v)
- {
- gconf_client_set_int(m_client, p, v, NULL);
- }
+ Glib::RefPtr<Gio::Settings> settings = Gio::Settings::create(schema);
+ if(settings) {
+ m_schemas[schema] = settings;
+ }
- template<>
- bool Preferences::get<bool>(const char *p)
- {
- return gconf_client_get_bool(m_client, p, NULL);
- }
-
- template<>
- std::string Preferences::get<std::string>(const char *p)
- {
- gchar * s = gconf_client_get_string(m_client, p, NULL);
- std::string s2 = (s ? s : "");
- g_free(s);
- return s2;
- }
-
- template<>
- int Preferences::get<int>(const char *p)
- {
- return gconf_client_get_int(m_client, p, NULL);
- }
-
- template<>
- bool Preferences::get_default<bool>(const char *p)
- {
- GConfValue * v = gconf_client_get_default_from_schema(m_client, p, NULL);
- bool b = gconf_value_get_bool(v);
- gconf_value_free(v);
- return b;
- }
-
- template<>
- std::string Preferences::get_default<std::string>(const char *p)
- {
- GConfValue * v = gconf_client_get_default_from_schema(m_client, p, NULL);
- const gchar* s = gconf_value_get_string(v);
- std::string s2 = (s ? s : "");
- gconf_value_free(v);
- return s2;
- }
-
- template<>
- int Preferences::get_default<int>(const char *p)
- {
- GConfValue * v = gconf_client_get_default_from_schema(m_client, p, NULL);
- int i = gconf_value_get_int(v);
- gconf_value_free(v);
- return i;
- }
-
-
- guint Preferences::add_notify(const char *ns, GConfClientNotifyFunc func, gpointer data)
- {
- return gconf_client_notify_add(m_client, ns, func, data, NULL, NULL);
- }
-
-
- void Preferences::remove_notify(guint cnxid)
- {
- gconf_client_notify_remove(m_client, cnxid);
+ return settings;
}
}
diff --git a/src/preferences.hpp b/src/preferences.hpp
index 7522a06..24cf86f 100644
--- a/src/preferences.hpp
+++ b/src/preferences.hpp
@@ -1,6 +1,7 @@
/*
* gnote
*
+ * Copyright (C) 2011 Aurimas Cernius
* Copyright (C) 2009 Hubert Figuiere
*
* This program is free software: you can redistribute it and/or modify
@@ -23,9 +24,10 @@
#ifndef __PREFERENCES_HPP_
#define __PREFERENCES_HPP_
+#include <map>
#include <string>
-#include <gconf/gconf-client.h>
#include <sigc++/signal.h>
+#include <giomm/settings.h>
#include "base/singleton.hpp"
@@ -35,7 +37,11 @@ namespace gnote {
: public base::Singleton<Preferences>
{
public:
- typedef sigc::signal<void, Preferences*, GConfEntry*> NotifyChangeSignal;
+ static const char *SCHEMA_GNOTE;
+ static const char *SCHEMA_KEYBINDINGS;
+ static const char *SCHEMA_SYNC;
+ static const char *SCHEMA_DESKTOP_GNOME_INTERFACE;
+
static const char *ENABLE_SPELLCHECKING;
static const char *ENABLE_WIKIWORDS;
static const char *ENABLE_CUSTOM_FONT;
@@ -50,82 +56,35 @@ namespace gnote {
static const char *MENU_NOTE_COUNT;
static const char *MENU_PINNED_NOTES;
+ static const char *NOTE_RENAME_BEHAVIOR;
+
+ static const char *SEARCH_WINDOW_X_POS;
+ static const char *SEARCH_WINDOW_Y_POS;
+ static const char *SEARCH_WINDOW_WIDTH;
+ static const char *SEARCH_WINDOW_HEIGHT;
+ static const char *SEARCH_WINDOW_SPLITTER_POS;
+
static const char *KEYBINDING_SHOW_NOTE_MENU;
static const char *KEYBINDING_OPEN_START_HERE;
static const char *KEYBINDING_CREATE_NEW_NOTE;
static const char *KEYBINDING_OPEN_SEARCH;
static const char *KEYBINDING_OPEN_RECENT_CHANGES;
- static const char *EXPORTHTML_LAST_DIRECTORY;
- static const char *EXPORTHTML_EXPORT_LINKED;
- static const char *EXPORTHTML_EXPORT_LINKED_ALL;
-
static const char *SYNC_CLIENT_ID;
static const char *SYNC_LOCAL_PATH;
static const char *SYNC_SELECTED_SERVICE_ADDIN;
static const char *SYNC_CONFIGURED_CONFLICT_BEHAVIOR;
- static const char *NOTE_RENAME_BEHAVIOR;
-
- static const char *INSERT_TIMESTAMP_FORMAT;
-
- static const char *SEARCH_WINDOW_X_POS;
- static const char *SEARCH_WINDOW_Y_POS;
- static const char *SEARCH_WINDOW_WIDTH;
- static const char *SEARCH_WINDOW_HEIGHT;
- static const char *SEARCH_WINDOW_SPLITTER_POS;
+ static const char *DESKTOP_GNOME_FONT;
+ static const char *DESKTOP_GNOME_KEY_THEME;
Preferences();
- ~Preferences();
-
- template<typename T>
- void set(const char * p, const T&);
-
- template<typename T>
- void set(const std::string & p, const T&v)
- {
- set<T>(p.c_str(),v);
- }
-
-
- template<typename T>
- T get(const char * p);
-
- template<typename T>
- T get(const std::string & p)
- {
- return get<T>(p.c_str());
- }
-
- template<typename T>
- T get_default(const char * p);
-
- template<typename T>
- T get_default(const std::string & p)
- {
- return get_default<T>(p.c_str());
- }
-
- sigc::signal<void, Preferences*, GConfEntry*> & signal_setting_changed()
- {
- return m_signal_setting_changed;
- }
-
- // this is very hackish. maybe I should just use gconfmm
- guint add_notify(const char *ns, GConfClientNotifyFunc func, gpointer data);
- void remove_notify(guint);
- GConfClient * get_client() const
- {
- return m_client;
- }
+
+ Glib::RefPtr<Gio::Settings> get_schema_settings(const std::string & schema);
+ Glib::RefPtr<Gio::Settings> get_or_load_schema_settings(const std::string & schema);
private:
Preferences(const Preferences &); // non implemented
- GConfClient *m_client;
- guint m_cnx;
-
- static void gconf_notify_glue(GConfClient *client, guint cid, GConfEntry *entry,
- Preferences * self);
- NotifyChangeSignal m_signal_setting_changed;
+ std::map<std::string, Glib::RefPtr<Gio::Settings> > m_schemas;
};
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]