[glibmm] Gio::Settings: Add connect_changed().
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glibmm] Gio::Settings: Add connect_changed().
- Date: Wed, 6 May 2015 07:41:50 +0000 (UTC)
commit 46fcd11eeae90247914499cfd58acdf295679849
Author: Murray Cumming <murrayc murrayc com>
Date: Wed May 6 09:40:14 2015 +0200
Gio::Settings: Add connect_changed().
This wraps the strange "somekeyname::changed" signal in GSettings,
so we can get notification when a specific key has changed.
I would welcome any suggestion to improve this API.
gio/src/settings.ccg | 15 +++++++++++++++
gio/src/settings.hg | 13 +++++++++++++
2 files changed, 28 insertions(+), 0 deletions(-)
---
diff --git a/gio/src/settings.ccg b/gio/src/settings.ccg
index d800aa9..8fa0860 100644
--- a/gio/src/settings.ccg
+++ b/gio/src/settings.ccg
@@ -18,6 +18,7 @@
#include <gio/gio.h>
#include <glibmm/exceptionhandler.h>
#include <glibmm/vectorutils.h>
+#include <glibmm/propertyproxy_base.h> //For PropertyProxyConnectionNode
namespace Gio
{
@@ -70,4 +71,18 @@ std::vector<Glib::ustring> Settings::list_schemas()
}
_DEPRECATE_IFDEF_END
+sigc::connection Settings::connect_changed(const Glib::ustring& key, const SlotChanged& slot)
+{
+ // Create a proxy to hold our connection info
+ // This will be deleted by destroy_notify_handler.
+ Glib::PropertyProxyConnectionNode* pConnectionNode = new Glib::PropertyProxyConnectionNode(slot,
G_OBJECT(gobj()));
+
+ const Glib::ustring signal_name = "changed::" + key;
+ g_signal_connect_data(gobj(),
+ signal_name.c_str(), (GCallback)(&Glib::PropertyProxyConnectionNode::callback), pConnectionNode,
+ &Glib::PropertyProxyConnectionNode::destroy_notify_handler,
+ G_CONNECT_AFTER);
+ return sigc::connection(pConnectionNode->slot_);
+}
+
}
diff --git a/gio/src/settings.hg b/gio/src/settings.hg
index 75407d5..abb50e9 100644
--- a/gio/src/settings.hg
+++ b/gio/src/settings.hg
@@ -201,6 +201,19 @@ _DEPRECATE_IFDEF_END
//TODO?: _WRAP_PROPERTY("backend", Glib::RefPtr<SettingsBackend>)
+ /** See connect_changed().
+ * @newin{2,46}
+ */
+ typedef sigc::slot<void> SlotChanged;
+
+ /** Connect a callback @a slot to the "changed" signal for the @a key.
+ * This will be emitted whenever the the value for that key has been changed.
+ * @result A sigc::connection
+ *
+ * @newin{2,46}
+ */
+ sigc::connection connect_changed(const Glib::ustring& key, const SlotChanged& slot);
+
_WRAP_PROPERTY("delay-apply", bool)
_WRAP_PROPERTY("has-unapplied", bool)
_WRAP_PROPERTY("path", std::string)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]