cpw.gillux.detachablepurple: 07f0e0ec: Added a generic D-Bus property setter fu...

gillux at soc.pidgin.im gillux at soc.pidgin.im
Sat May 12 16:56:33 EDT 2012


----------------------------------------------------------------------
Revision: 07f0e0ec1ed2da362be7357f264ff57bcd6203f0
Parent:   dc9df5177b2708d8ccc884d5cf2dd51cb70e7e0d
Author:   gillux at soc.pidgin.im
Date:     05/12/12 13:51:52
Branch:   im.pidgin.cpw.gillux.detachablepurple
URL: http://d.pidgin.im/viewmtn/revision/info/07f0e0ec1ed2da362be7357f264ff57bcd6203f0

Changelog: 

Added a generic D-Bus property setter function.
Also made PurpleAccount to use it.

Changes against parent dc9df5177b2708d8ccc884d5cf2dd51cb70e7e0d

  patched  libpurple/account.c
  patched  libpurple/pobject.c
  patched  libpurple/pobject.h

-------------- next part --------------
============================================================
--- libpurple/account.c	a78a975c5c10255e0e1619149c4e3100b0d6c0f6
+++ libpurple/account.c	64c18d526c88bd8fedc2d5b9f076927c0e2dc8a6
@@ -1382,8 +1382,8 @@ purple_account_set_username(PurpleAccoun
 	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 @@ purple_account_set_password(PurpleAccoun
 
 	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 @@ purple_account_set_alias(PurpleAccount *
 
 	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 @@ purple_account_set_user_info(PurpleAccou
 
 	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 @@ void purple_account_set_buddy_icon_path(
 
 	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 @@ purple_account_set_remember_password(Pur
 
 	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 @@ purple_account_set_check_mail(PurpleAcco
 
 	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 @@ purple_account_set_enabled(PurpleAccount
 
 	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 @@ purple_account_set_public_alias(PurpleAc
 	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);
============================================================
--- libpurple/pobject.c	d4564b8ecb4f7399d3e4e2a5f42ff7b8844c12b3
+++ libpurple/pobject.c	ad7cfee7e7f9d42ed8f80d50321cfc1522171afe
@@ -947,6 +947,50 @@ purple_object_dbus_call(PurpleObject *po
 	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)
 {
============================================================
--- libpurple/pobject.h	c1df6822f96a102774f63f4bae4f945cb7f0b6d4
+++ libpurple/pobject.h	5c7421881f7042fdbaca50ff27ccc43642053e9a
@@ -375,6 +375,20 @@ void purple_object_dbus_connect(gpointer
 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