telepathy-mission-control: mcp_account_storage_owns: add

Simon McVittie smcv at kemper.freedesktop.org
Wed Feb 13 06:18:21 PST 2013


Module: telepathy-mission-control
Branch: master
Commit: 3975989913b12fa1488d00085d8cdb84e5b3f46d
URL:    http://cgit.freedesktop.org/telepathy/telepathy-mission-control/commit/?id=3975989913b12fa1488d00085d8cdb84e5b3f46d

Author: Simon McVittie <simon.mcvittie at collabora.co.uk>
Date:   Mon Sep 10 18:31:43 2012 +0100

mcp_account_storage_owns: add

At the moment we use get() to see whether a plugin thinks it "owns" a
particular account, but it seems clearer and more self-documenting
to have a dedicated virtual method for this.

Signed-off-by: Simon McVittie <simon.mcvittie at collabora.co.uk>

---

 mission-control-plugins/account-storage.c |   47 +++++++++++++++++++++++++++++
 mission-control-plugins/account-storage.h |    8 +++++
 src/mcd-storage.c                         |    2 +-
 3 files changed, 56 insertions(+), 1 deletions(-)

diff --git a/mission-control-plugins/account-storage.c b/mission-control-plugins/account-storage.c
index beecf75..59871d5 100644
--- a/mission-control-plugins/account-storage.c
+++ b/mission-control-plugins/account-storage.c
@@ -67,6 +67,7 @@
  *   iface->get_additional_info = foo_plugin_get_additional_info;
  *   iface->get_restrictions = foo_plugin_get_restrictions;
  *   iface->create = foo_plugin_create;
+ *   iface->owns = foo_plugin_owns;
  * }
  * </programlisting></example>
  *
@@ -110,11 +111,27 @@ enum
 
 static guint signals[NO_SIGNAL] = { 0 };
 
+static gboolean
+default_owns (McpAccountStorage *storage,
+    McpAccountManager *am,
+    const gchar *account)
+{
+  /* This has the side-effect of pushing the "manager" key back into @am,
+   * but that should be a no-op in practice: we always call this
+   * method in priority order and stop at the first one that says "yes",
+   * and @am's idea of what "manager" is should have come from that same
+   * plugin anyway. */
+  return mcp_account_storage_get (storage, am, account, "manager");
+}
+
 static void
 class_init (gpointer klass,
     gpointer data)
 {
   GType type = G_TYPE_FROM_CLASS (klass);
+  McpAccountStorageIface *iface = klass;
+
+  iface->owns = default_owns;
 
   if (signals[CREATED] != 0)
     {
@@ -1096,3 +1113,33 @@ mcp_account_storage_emit_reconnect (McpAccountStorage *storage,
 {
   g_signal_emit (storage, signals[RECONNECT], 0, account);
 }
+
+/**
+ * mcp_account_storage_owns:
+ * @storage: an #McpAccountStorage instance
+ * @am: an #McpAccountManager instance
+ * @account: the unique name (object-path tail) of an account
+ *
+ * Check whether @account is stored in @storage. The highest-priority
+ * plugin for which this function returns %TRUE is considered to be
+ * responsible for @account.
+ *
+ * There is a default implementation, which calls mcp_account_storage_get()
+ * for the well-known key "manager".
+ *
+ * Returns: %TRUE if @account is stored in @storage
+ *
+ * Since: 5.13.UNRELEASED
+ */
+gboolean
+mcp_account_storage_owns (McpAccountStorage *storage,
+    McpAccountManager *am,
+    const gchar *account)
+{
+  McpAccountStorageIface *iface = MCP_ACCOUNT_STORAGE_GET_IFACE (storage);
+
+  g_return_val_if_fail (iface != NULL, FALSE);
+  g_return_val_if_fail (iface->owns != NULL, FALSE);
+
+  return iface->owns (storage, am, account);
+}
diff --git a/mission-control-plugins/account-storage.h b/mission-control-plugins/account-storage.h
index a5b5db5..ef19fd6 100644
--- a/mission-control-plugins/account-storage.h
+++ b/mission-control-plugins/account-storage.h
@@ -127,6 +127,11 @@ struct _McpAccountStorageIface
   McpAccountStorageGetAdditionalInfoFunc get_additional_info;
   McpAccountStorageGetRestrictionsFunc get_restrictions;
   McpAccountStorageCreate create;
+
+  /* Since 5.13.UNRELEASED */
+  gboolean (*owns) (McpAccountStorage *storage,
+      McpAccountManager *am,
+      const gchar *account);
 };
 
 #ifndef __GTK_DOC_IGNORE__
@@ -248,6 +253,9 @@ const gchar *mcp_account_storage_name (const McpAccountStorage *storage);
 const gchar *mcp_account_storage_description (const McpAccountStorage *storage);
 const gchar *mcp_account_storage_provider (const McpAccountStorage *storage);
 
+gboolean mcp_account_storage_owns (McpAccountStorage *storage,
+    McpAccountManager *am,
+    const gchar *account);
 void mcp_account_storage_emit_created (McpAccountStorage *storage,
     const gchar *account);
 G_DEPRECATED_FOR (something that is actually implemented)
diff --git a/src/mcd-storage.c b/src/mcd-storage.c
index 693d358..0117f6e 100644
--- a/src/mcd-storage.c
+++ b/src/mcd-storage.c
@@ -788,7 +788,7 @@ mcd_storage_get_plugin (McdStorage *self,
     {
       McpAccountStorage *plugin = store->data;
 
-      if (mcp_account_storage_get (plugin, ma, account, "manager"))
+      if (mcp_account_storage_owns (plugin, ma, account))
         owner = plugin;
     }
 



More information about the telepathy-commits mailing list