summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon McVittie <simon.mcvittie@collabora.co.uk>2012-09-10 18:31:43 +0100
committerSimon McVittie <simon.mcvittie@collabora.co.uk>2012-09-12 14:22:50 +0100
commit3975989913b12fa1488d00085d8cdb84e5b3f46d (patch)
treeca59dc6de3d70ce180daf61b63ed63e928e4c950
parent7cf22355325f32bcf9898cfeb253390ed6624923 (diff)
mcp_account_storage_owns: addtyped-settings-54872
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@collabora.co.uk>
-rw-r--r--mission-control-plugins/account-storage.c47
-rw-r--r--mission-control-plugins/account-storage.h8
-rw-r--r--src/mcd-storage.c2
3 files changed, 56 insertions, 1 deletions
diff --git a/mission-control-plugins/account-storage.c b/mission-control-plugins/account-storage.c
index beecf75e..59871d5b 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 a5b5db50..ef19fd62 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 693d358d..0117f6e2 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;
}