cpw.gillux.detachablepurple: 88769daa: Added generic functions to load any Purp...
gillux at soc.pidgin.im
gillux at soc.pidgin.im
Mon May 14 23:27:01 EDT 2012
----------------------------------------------------------------------
Revision: 88769daaa0620a7450b76b7e27dadc5cb085cff4
Parent: ff0ccd9620c3cf25b6005e2c641c87215c0ca64e
Author: gillux at soc.pidgin.im
Date: 05/14/12 21:53:34
Branch: im.pidgin.cpw.gillux.detachablepurple
URL: http://d.pidgin.im/viewmtn/revision/info/88769daaa0620a7450b76b7e27dadc5cb085cff4
Changelog:
Added generic functions to load any PurpleObject or array of PurpleObjects.
Also updated the accounts loading function to take advantage of this.
Renamed the pack_account() function to pack_pobject(), as this one was
actually already generic.
Changes against parent ff0ccd9620c3cf25b6005e2c641c87215c0ca64e
patched libpurple/dbus/constructor.c
-------------- next part --------------
============================================================
--- libpurple/dbus/constructor.c b5ca796bbdb46066414c869804d23212f10310c4
+++ libpurple/dbus/constructor.c 494adff3f813b0b9009436838743d74f186f67cf
@@ -262,35 +262,52 @@ static GVariant*
}
static GVariant*
-pack_account(PurpleAccount *account)
+pack_pobject(gpointer obj)
{
- PurpleObject *pobj = PURPLE_OBJECT(account);
+ PurpleObject *pobj = PURPLE_OBJECT(obj);
return g_variant_new("(o at a(sv))",
purple_object_get_dbus_path(pobj),
pack_pobject_properties(pobj));
}
-/* Unpacks a GVariant-packed account and creates local PurpleAccounts
- * that will act as proxy objects. */
-static void
-load_account(GVariant *account)
+static gpointer
+load_pobject(GVariant *vpobject, const char *type_name)
{
- PurpleAccount *paccount;
+ PurpleObject *pobject;
+ gpointer *obj;
GVariant *props;
- gchar *dbus_path;
+ const gchar *dbus_path;
- g_variant_get(account, "(o at a(sv))", &dbus_path, &props);
+ g_variant_get(vpobject, "(o at a(sv))", &dbus_path, &props);
- paccount = purple_constructor_new_proxy_object("PurpleAccount", props);
+ obj = purple_constructor_new_proxy_object(type_name, props);
+
+ pobject = PURPLE_OBJECT(obj);
+ purple_object_set_dbus_path(pobject, dbus_path);
+ purple_object_dbus_init(obj);
+
g_variant_unref(props);
+ g_free((gchar*)dbus_path);
- purple_object_set_dbus_path(PURPLE_OBJECT(paccount), dbus_path);
- g_free(dbus_path);
+ return obj;
+}
- purple_account_dbus_init(paccount);
- /* This signal will add our new account in the account list. */
- g_signal_emit_by_name(G_OBJECT(paccount), "new");
- purple_object_set_synchronized(PURPLE_OBJECT(paccount), TRUE);
+static void
+load_pobjects(GVariant *box, const char *type_name)
+{
+ GVariantIter iter;
+ GVariant *array, *pobject;
+ gpointer obj;
+
+ g_variant_get(box, "(@a(oa(sv)))", &array);
+
+ g_variant_iter_init(&iter, array);
+ while ((pobject = g_variant_iter_next_value(&iter)) != NULL) {
+ obj = load_pobject(pobject, type_name);
+ purple_object_set_synchronized(PURPLE_OBJECT(obj), TRUE);
+ g_variant_unref(pobject);
+ }
+ g_variant_unref(array);
}
/**
@@ -308,34 +325,27 @@ purple_constructor_get_all_accounts(void
g_variant_builder_init(&builder, G_VARIANT_TYPE_ARRAY);
while (all) {
PurpleAccount *account = all->data;
- g_variant_builder_add_value(&builder, pack_account(account));
+ g_variant_builder_add_value(&builder, pack_pobject(account));
all = all->next;
}
return g_variant_new("(@a(oa(sv)))", g_variant_builder_end(&builder));
}
-/**
- * This is what a client calls when it wants to call the dbus method
- * GetAllAccounts. It unpacks the gdbus formatted data and creates proxy
- * PurpleAccounts.
- */
-void
-purple_accounts_get_all_RPC(void)
+static void
+purple_constructor_load_all_pobj(const char *method, const char *type)
{
PurpleConstructor* con = purple_constructor_get_instance();
- GVariant *ret, *accounts, *account;
- GVariantIter iter;
+ GVariant *ret;
- /* Download all the accounts. */
- ret = purple_object_dbus_call(PURPLE_OBJECT(con), "GetAllAccounts");
- g_variant_get(ret, "(@a(oa(sv)))", &accounts);
+ ret = purple_object_dbus_call(PURPLE_OBJECT(con), method);
+ if (ret) {
+ load_pobjects(ret, type);
+ g_variant_unref(ret);
+ }
+}
- /* Unpack all this data. */
- g_variant_iter_init(&iter, accounts);
- while ((account = g_variant_iter_next_value(&iter)) != NULL) {
- load_account(account);
- g_variant_unref(account);
- }
- purple_debug_info("dbus", "Loaded %d accounts.\n", g_variant_n_children(accounts));
- g_variant_unref(accounts);
+void
+purple_accounts_get_all_RPC(void)
+{
+ purple_constructor_load_all_pobj("GetAllAccounts", "PurpleAccount");
}
More information about the Commits
mailing list