/srv/mercurial-server/detachablepurple: 24fd5a518156: Added a ge...
Gilles Bedel
gillux at cpw.pidgin.im
Fri Jun 15 22:01:32 EDT 2012
Changeset: 24fd5a5181569f9ec5b4c39bb87605f029cdac4d
Author: Gilles Bedel <gillux at cpw.pidgin.im>
Date: 2012-05-12 17:51 +0000
Branch: cpw.gillux.detachablepurple
URL: http://hg.pidgin.im/srv/mercurial-server/detachablepurple/rev/24fd5a518156
Description:
Added a generic D-Bus property setter function.
Also made PurpleAccount to use it.
diffstat:
libpurple/account.c | 36 ++++++++++++++++++------------------
libpurple/pobject.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
libpurple/pobject.h | 14 ++++++++++++++
3 files changed, 76 insertions(+), 18 deletions(-)
diffs (180 lines):
diff --git a/libpurple/account.c b/libpurple/account.c
--- a/libpurple/account.c
+++ b/libpurple/account.c
@@ -1382,8 +1382,8 @@
g_return_if_fail(PURPLE_IS_ACCOUNT(account));
g_return_if_fail(username != NULL);
- PURPLE_DBUS_REMOTELY_SET_PROP(account, g_value_set_string, G_TYPE_STRING,
- PROP_USERNAME_S, username);
+ purple_object_set_prop_on_dbus(PURPLE_OBJECT(account),
+ PROP_USERNAME_S, &username);
priv = PURPLE_ACCOUNT_GET_PRIVATE(account);
if (purple_util_strings_equal(priv->username, username))
@@ -1407,8 +1407,8 @@
g_return_if_fail(PURPLE_IS_ACCOUNT(account));
- PURPLE_DBUS_REMOTELY_SET_PROP(account, g_value_set_string, G_TYPE_STRING,
- PROP_PASSWORD_S, password);
+ purple_object_set_prop_on_dbus(PURPLE_OBJECT(account),
+ PROP_PASSWORD_S, password);
priv = PURPLE_ACCOUNT_GET_PRIVATE(account);
if (purple_util_strings_equal(priv->password, password))
@@ -1426,8 +1426,8 @@
g_return_if_fail(PURPLE_IS_ACCOUNT(account));
- PURPLE_DBUS_REMOTELY_SET_PROP(account, g_value_set_string, G_TYPE_STRING,
- PROP_PRIVATE_ALIAS_S, alias);
+ purple_object_set_prop_on_dbus(PURPLE_OBJECT(account),
+ PROP_PRIVATE_ALIAS_S, alias);
priv = PURPLE_ACCOUNT_GET_PRIVATE(account);
if (purple_util_strings_equal(priv->alias, alias))
@@ -1453,8 +1453,8 @@
g_return_if_fail(PURPLE_IS_ACCOUNT(account));
- PURPLE_DBUS_REMOTELY_SET_PROP(account, g_value_set_string, G_TYPE_STRING,
- PROP_USER_INFO_S, user_info);
+ purple_object_set_prop_on_dbus(PURPLE_OBJECT(account),
+ PROP_USER_INFO_S, user_info);
priv = PURPLE_ACCOUNT_GET_PRIVATE(account);
@@ -1472,8 +1472,8 @@
g_return_if_fail(PURPLE_IS_ACCOUNT(account));
- PURPLE_DBUS_REMOTELY_SET_PROP(account, g_value_set_string, G_TYPE_STRING,
- PROP_BUDDY_ICON_PATH_S, path);
+ purple_object_set_prop_on_dbus(PURPLE_OBJECT(account),
+ PROP_BUDDY_ICON_PATH_S, path);
priv = PURPLE_ACCOUNT_GET_PRIVATE(account);
@@ -1514,8 +1514,8 @@
g_return_if_fail(PURPLE_IS_ACCOUNT(account));
- PURPLE_DBUS_REMOTELY_SET_PROP(account, g_value_set_boolean, G_TYPE_BOOLEAN,
- PROP_REMEMBER_PASSWORD_S, value);
+ purple_object_set_prop_on_dbus(PURPLE_OBJECT(account),
+ PROP_REMEMBER_PASSWORD_S, value);
priv = PURPLE_ACCOUNT_GET_PRIVATE(account);
if (priv->remember_pass == value)
@@ -1531,8 +1531,8 @@
g_return_if_fail(PURPLE_IS_ACCOUNT(account));
- PURPLE_DBUS_REMOTELY_SET_PROP(account, g_value_set_boolean, G_TYPE_BOOLEAN,
- PROP_CHECK_MAIL_S, value);
+ purple_object_set_prop_on_dbus(PURPLE_OBJECT(account),
+ PROP_CHECK_MAIL_S, value);
priv = PURPLE_ACCOUNT_GET_PRIVATE(account);
if (priv->check_mail == value)
@@ -1550,8 +1550,8 @@
g_return_if_fail(PURPLE_IS_ACCOUNT(account));
- PURPLE_DBUS_REMOTELY_SET_PROP(account, g_value_set_boolean, G_TYPE_BOOLEAN,
- PROP_ENABLED_S, value);
+ purple_object_set_prop_on_dbus(PURPLE_OBJECT(account),
+ PROP_ENABLED_S, value);
was_enabled = purple_account_get_enabled(account);
if (was_enabled == value)
@@ -1710,8 +1710,8 @@
g_return_if_fail(purple_account_is_connected(account));
/* TODO: also handle the callbacks, probably with dbus signals */
- PURPLE_DBUS_REMOTELY_SET_PROP(account, g_value_set_string, G_TYPE_STRING,
- PROP_PUBLIC_ALIAS_S, alias);
+ purple_object_set_prop_on_dbus(PURPLE_OBJECT(account),
+ PROP_PUBLIC_ALIAS_S, alias);
gc = purple_account_get_connection(account);
prpl = purple_connection_get_prpl(gc);
diff --git a/libpurple/pobject.c b/libpurple/pobject.c
--- a/libpurple/pobject.c
+++ b/libpurple/pobject.c
@@ -947,6 +947,50 @@
return out_args;
}
+static void
+set_prop_on_dbus_done(GObject *object, GAsyncResult *res, gpointer user_data)
+{
+ /* Maybe do something here. */
+}
+
+void
+purple_object_set_prop_on_dbus(PurpleObject *pobj, gchar *prop_name, ...)
+{
+ GDBusConnection *connection;
+ GVariant *params, *prop_value;
+ GDBusInterfaceInfo *iface;
+ GDBusPropertyInfo *prop_info;
+ va_list ap;
+
+ if (!purple_object_get_synchronized(pobj) || !purple_core_is_remote_mode())
+ return;
+
+ connection = purple_gdbus_get_connection();
+ if (!connection) /* TODO: handle this properly. */
+ return;
+
+ /* Prepare the parameters. */
+ iface = PURPLE_OBJECT_GET_CLASS(pobj)->dbus_ifaceinfo;
+ prop_info = g_dbus_interface_info_lookup_property(iface, prop_name);
+ va_start(ap, prop_name);
+ prop_value = g_variant_new_va(prop_info->signature, NULL, &ap);
+ va_end(ap);
+ params = g_variant_new("(ssv)", iface->name, prop_name, prop_value),
+
+ /* This does not block, it is an asynchronous D-Bus call. */
+ g_dbus_connection_call(connection,
+ DBUS_PURPLE_SERVICE,
+ purple_object_get_dbus_path(pobj),
+ "org.freedesktop.DBus.Properties", "Set",
+ params,
+ NULL,
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ set_prop_on_dbus_done,
+ NULL);
+}
+
static GQuark
purple_object_type_dbus_metadata_quark(void)
{
diff --git a/libpurple/pobject.h b/libpurple/pobject.h
--- a/libpurple/pobject.h
+++ b/libpurple/pobject.h
@@ -375,6 +375,20 @@
void purple_object_dbus_connect(gpointer object, GDBusConnection *dbus_conn);
/**
+ * Calls the org.freedesktop.DBus.Properties.Set D-Bus method on the daemon
+ * to set the given property. This function will do nothing unless you are
+ * in remote mode and the PurpleObject is marked as synchronized (with
+ * purple_object_set_synchronized()).
+ *
+ * @param pobj The PurpleObject proxing the PurpleObject
+ * you want to set a property on.
+ * @param prop_name The name of the property
+ * @param ... The property value. The type of this parameter must match the
+ * property signature on D-Bus.
+ */
+void purple_object_set_prop_on_dbus(PurpleObject *pobj, gchar *prop_name, ...);
+
+/**
* Remotely calls method_name on pobj over D-Bus. Actually, it's not called
* on this pojb object but on the remote associated one. The input parameters
* are all the variable parameters, and must follow the method input parameters
More information about the Commits
mailing list