diff options
author | Guillaume Desmottes <guillaume.desmottes@collabora.co.uk> | 2014-02-21 12:11:43 +0100 |
---|---|---|
committer | Guillaume Desmottes <guillaume.desmottes@collabora.co.uk> | 2014-02-27 15:37:58 +0100 |
commit | 19e99ccc8bbf4b1d99849f2f8e8fcb517743050b (patch) | |
tree | 0a623adee98222df6fd90109fedc84fe1c71dd2e /libempathy | |
parent | 996076ea780a05b996e37e46408e3f6f71e0d996 (diff) |
use vardict API to interact and request channels
Diffstat (limited to 'libempathy')
-rw-r--r-- | libempathy/empathy-auth-factory.c | 34 | ||||
-rw-r--r-- | libempathy/empathy-chatroom-manager.c | 10 | ||||
-rw-r--r-- | libempathy/empathy-ft-factory.c | 11 | ||||
-rw-r--r-- | libempathy/empathy-ft-handler.c | 59 | ||||
-rw-r--r-- | libempathy/empathy-request-util.c | 22 | ||||
-rw-r--r-- | libempathy/empathy-tp-chat.c | 30 |
6 files changed, 80 insertions, 86 deletions
diff --git a/libempathy/empathy-auth-factory.c b/libempathy/empathy-auth-factory.c index ecaff1fb..16711cd6 100644 --- a/libempathy/empathy-auth-factory.c +++ b/libempathy/empathy-auth-factory.c @@ -632,22 +632,18 @@ empathy_auth_factory_constructed (GObject *obj) tp_base_client_set_handler_bypass_approval (client, FALSE); /* Handle ServerTLSConnection and ServerAuthentication channels */ - tp_base_client_take_handler_filter (client, tp_asv_new ( - /* ChannelType */ - TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING, + tp_base_client_add_handler_filter (client, g_variant_new_parsed ( + "{ %s: <%s>, %s: <%u> }", + TP_PROP_CHANNEL_CHANNEL_TYPE, TP_IFACE_CHANNEL_TYPE_SERVER_TLS_CONNECTION1, - /* AuthenticationMethod */ - TP_PROP_CHANNEL_TARGET_ENTITY_TYPE, G_TYPE_UINT, - TP_ENTITY_TYPE_NONE, NULL)); + TP_PROP_CHANNEL_TARGET_ENTITY_TYPE, (guint32) TP_ENTITY_TYPE_NONE)); - tp_base_client_take_handler_filter (client, tp_asv_new ( - /* ChannelType */ - TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING, + tp_base_client_add_handler_filter (client, g_variant_new_parsed ( + "{ %s: <%s>, %s: <%s> }", + TP_PROP_CHANNEL_CHANNEL_TYPE, TP_IFACE_CHANNEL_TYPE_SERVER_AUTHENTICATION1, - /* AuthenticationMethod */ - TP_PROP_CHANNEL_TYPE_SERVER_AUTHENTICATION1_AUTHENTICATION_METHOD, - G_TYPE_STRING, TP_IFACE_CHANNEL_INTERFACE_SASL_AUTHENTICATION1, - NULL)); + TP_PROP_CHANNEL_TYPE_SERVER_AUTHENTICATION1_AUTHENTICATION_METHOD, + TP_IFACE_CHANNEL_INTERFACE_SASL_AUTHENTICATION1)); /* We are also an observer so that we can see new auth channels * popping up and if we have the password already saved to one @@ -656,14 +652,12 @@ empathy_auth_factory_constructed (GObject *obj) * sense. */ /* Observe ServerAuthentication channels */ - tp_base_client_take_observer_filter (client, tp_asv_new ( - /* ChannelType */ - TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING, + tp_base_client_add_observer_filter (client, g_variant_new_parsed ( + "{ %s: <%s>, %s: <%s> }", + TP_PROP_CHANNEL_CHANNEL_TYPE, TP_IFACE_CHANNEL_TYPE_SERVER_AUTHENTICATION1, - /* AuthenticationMethod */ - TP_PROP_CHANNEL_TYPE_SERVER_AUTHENTICATION1_AUTHENTICATION_METHOD, - G_TYPE_STRING, TP_IFACE_CHANNEL_INTERFACE_SASL_AUTHENTICATION1, - NULL)); + TP_PROP_CHANNEL_TYPE_SERVER_AUTHENTICATION1_AUTHENTICATION_METHOD, + TP_IFACE_CHANNEL_INTERFACE_SASL_AUTHENTICATION1)); tp_base_client_set_observer_delay_approvers (client, TRUE); } diff --git a/libempathy/empathy-chatroom-manager.c b/libempathy/empathy-chatroom-manager.c index adcaacad..41a8da54 100644 --- a/libempathy/empathy-chatroom-manager.c +++ b/libempathy/empathy-chatroom-manager.c @@ -588,12 +588,10 @@ empathy_chatroom_manager_constructor (GType type, priv->observer = tp_simple_observer_new_with_am (priv->account_manager, TRUE, "Empathy.ChatroomManager", TRUE, observe_channel_cb, self, NULL); - tp_base_client_take_observer_filter (priv->observer, tp_asv_new ( - TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING, - TP_IFACE_CHANNEL_TYPE_TEXT, - TP_PROP_CHANNEL_TARGET_ENTITY_TYPE, G_TYPE_UINT, - TP_ENTITY_TYPE_ROOM, - NULL)); + tp_base_client_add_observer_filter (priv->observer, g_variant_new_parsed ( + "{ %s: <%s>, %s: <%u> }", + TP_PROP_CHANNEL_CHANNEL_TYPE, TP_IFACE_CHANNEL_TYPE_TEXT, + TP_PROP_CHANNEL_TARGET_ENTITY_TYPE, (guint32) TP_ENTITY_TYPE_ROOM)); if (!tp_base_client_register (priv->observer, &error)) { diff --git a/libempathy/empathy-ft-factory.c b/libempathy/empathy-ft-factory.c index 003a50c2..ed5bfd5f 100644 --- a/libempathy/empathy-ft-factory.c +++ b/libempathy/empathy-ft-factory.c @@ -194,14 +194,13 @@ empathy_ft_factory_init (EmpathyFTFactory *self) priv->handler = tp_simple_handler_new_with_am (am, FALSE, FALSE, EMPATHY_FT_TP_BUS_NAME_SUFFIX, FALSE, handle_channel_cb, self, NULL); - tp_base_client_take_handler_filter (priv->handler, tp_asv_new ( - TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING, - TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER1, - TP_PROP_CHANNEL_TARGET_ENTITY_TYPE, G_TYPE_UINT, TP_ENTITY_TYPE_CONTACT, + tp_base_client_add_handler_filter (priv->handler, g_variant_new_parsed ( + "{ %s: <%s>, %s: <%u>, %s: <%b> }", + TP_PROP_CHANNEL_CHANNEL_TYPE, TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER1, + TP_PROP_CHANNEL_TARGET_ENTITY_TYPE, (guint32) TP_ENTITY_TYPE_CONTACT, /* Only handle *incoming* channels as outgoing FT channels has to be * handled by the requester. */ - TP_PROP_CHANNEL_REQUESTED, G_TYPE_BOOLEAN, FALSE, - NULL)); + TP_PROP_CHANNEL_REQUESTED, FALSE)); g_object_unref (am); } diff --git a/libempathy/empathy-ft-handler.c b/libempathy/empathy-ft-handler.c index a64f557c..c24dcb7f 100644 --- a/libempathy/empathy-ft-handler.c +++ b/libempathy/empathy-ft-handler.c @@ -123,7 +123,7 @@ typedef struct { gboolean use_hash; /* request for the new transfer */ - GHashTable *request; + GVariantDict *request; /* transfer properties */ EmpathyContact *contact; @@ -273,11 +273,7 @@ do_dispose (GObject *object) priv->cancellable = NULL; } - if (priv->request != NULL) - { - g_hash_table_unref (priv->request); - priv->request = NULL; - } + g_clear_pointer (&priv->request, g_variant_dict_unref); G_OBJECT_CLASS (empathy_ft_handler_parent_class)->dispose (object); } @@ -836,12 +832,16 @@ ft_handler_push_to_dispatcher (EmpathyFTHandler *handler) EmpathyFTHandlerPriv *priv = GET_PRIV (handler); TpAccountChannelRequest *req; + g_return_if_fail (priv->request != NULL); + DEBUG ("Pushing request to the dispatcher"); account = empathy_contact_get_account (priv->contact); - req = tp_account_channel_request_new (account, priv->request, - priv->user_action_time); + req = tp_account_channel_request_new (account, + g_variant_dict_end (priv->request), priv->user_action_time); + + g_clear_pointer (&priv->request, g_variant_dict_unref); tp_account_channel_request_create_and_handle_channel_async (req, NULL, ft_handler_create_channel_cb, handler); @@ -859,23 +859,24 @@ ft_handler_populate_outgoing_request (EmpathyFTHandler *handler) contact_handle = empathy_contact_get_handle (priv->contact); uri = g_file_get_uri (priv->gfile); - priv->request = tp_asv_new ( - TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING, - TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER1, - TP_PROP_CHANNEL_TARGET_ENTITY_TYPE, G_TYPE_UINT, - TP_ENTITY_TYPE_CONTACT, - TP_PROP_CHANNEL_TARGET_HANDLE, G_TYPE_UINT, - contact_handle, - TP_PROP_CHANNEL_TYPE_FILE_TRANSFER1_CONTENT_TYPE, G_TYPE_STRING, - priv->content_type, - TP_PROP_CHANNEL_TYPE_FILE_TRANSFER1_FILENAME, G_TYPE_STRING, - priv->filename, - TP_PROP_CHANNEL_TYPE_FILE_TRANSFER1_SIZE, G_TYPE_UINT64, - priv->total_bytes, - TP_PROP_CHANNEL_TYPE_FILE_TRANSFER1_DATE, G_TYPE_UINT64, - priv->mtime, - TP_PROP_CHANNEL_TYPE_FILE_TRANSFER1_URI, G_TYPE_STRING, uri, - NULL); + priv->request = g_variant_dict_new (NULL); + g_variant_dict_insert (priv->request, TP_PROP_CHANNEL_CHANNEL_TYPE, + "s", TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER1); + g_variant_dict_insert (priv->request, TP_PROP_CHANNEL_TARGET_ENTITY_TYPE, + "u", TP_ENTITY_TYPE_CONTACT); + g_variant_dict_insert (priv->request, TP_PROP_CHANNEL_TARGET_HANDLE, + "u", contact_handle); + g_variant_dict_insert (priv->request, + TP_PROP_CHANNEL_TYPE_FILE_TRANSFER1_CONTENT_TYPE, + "s", priv->content_type); + g_variant_dict_insert (priv->request, + TP_PROP_CHANNEL_TYPE_FILE_TRANSFER1_FILENAME, "s", priv->filename); + g_variant_dict_insert (priv->request, + TP_PROP_CHANNEL_TYPE_FILE_TRANSFER1_SIZE, "t", priv->total_bytes); + g_variant_dict_insert (priv->request, + TP_PROP_CHANNEL_TYPE_FILE_TRANSFER1_DATE, "t", priv->mtime); + g_variant_dict_insert (priv->request, TP_PROP_CHANNEL_TYPE_FILE_TRANSFER1_URI, + "s", uri); g_free (uri); } @@ -927,8 +928,8 @@ hash_job_done (gpointer user_data) /* set the checksum in the request... * im.telepathy.v1.Channel.Type.FileTransfer.ContentHash */ - tp_asv_set_string (priv->request, - TP_PROP_CHANNEL_TYPE_FILE_TRANSFER1_CONTENT_HASH, + g_variant_dict_insert (priv->request, + TP_PROP_CHANNEL_TYPE_FILE_TRANSFER1_CONTENT_HASH, "s", g_checksum_get_string (hash_data->checksum)); } @@ -1067,8 +1068,8 @@ ft_handler_read_async_cb (GObject *source, /* FIXME: MD5 is the only ContentHashType supported right now */ hash_data->checksum = g_checksum_new (G_CHECKSUM_MD5); - tp_asv_set_uint32 (priv->request, - TP_PROP_CHANNEL_TYPE_FILE_TRANSFER1_CONTENT_HASH_TYPE, + g_variant_dict_insert (priv->request, + TP_PROP_CHANNEL_TYPE_FILE_TRANSFER1_CONTENT_HASH_TYPE, "s", TP_FILE_HASH_TYPE_MD5); g_signal_emit (handler, signals[HASHING_STARTED], 0); diff --git a/libempathy/empathy-request-util.c b/libempathy/empathy-request-util.c index da770106..17cc037c 100644 --- a/libempathy/empathy-request-util.c +++ b/libempathy/empathy-request-util.c @@ -60,28 +60,28 @@ create_text_channel (TpAccount *account, GAsyncReadyCallback callback, gpointer user_data) { - GHashTable *request; + GVariantDict dict; TpAccountChannelRequest *req; - request = tp_asv_new ( - TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING, - TP_IFACE_CHANNEL_TYPE_TEXT, - TP_PROP_CHANNEL_TARGET_ENTITY_TYPE, G_TYPE_UINT, target_entity_type, - TP_PROP_CHANNEL_TARGET_ID, G_TYPE_STRING, target_id, - NULL); + g_variant_dict_init (&dict, NULL); + g_variant_dict_insert (&dict, TP_PROP_CHANNEL_CHANNEL_TYPE, "s", + TP_IFACE_CHANNEL_TYPE_TEXT); + g_variant_dict_insert (&dict, TP_PROP_CHANNEL_TARGET_ENTITY_TYPE, "u", + target_entity_type); + g_variant_dict_insert (&dict, TP_PROP_CHANNEL_TARGET_ID, "s", target_id); if (sms_channel) - tp_asv_set_boolean (request, - TP_PROP_CHANNEL_INTERFACE_SMS1_SMS_CHANNEL, TRUE); + g_variant_dict_insert (&dict, + TP_PROP_CHANNEL_INTERFACE_SMS1_SMS_CHANNEL, "b", TRUE); - req = tp_account_channel_request_new (account, request, timestamp); + req = tp_account_channel_request_new (account, g_variant_dict_end (&dict), + timestamp); tp_account_channel_request_set_delegate_to_preferred_handler (req, TRUE); tp_account_channel_request_ensure_channel_async (req, EMPATHY_CHAT_TP_BUS_NAME, NULL, callback ? callback : ensure_text_channel_cb, user_data); - g_hash_table_unref (request); g_object_unref (req); } diff --git a/libempathy/empathy-tp-chat.c b/libempathy/empathy-tp-chat.c index 70f0925b..b18551cd 100644 --- a/libempathy/empathy-tp-chat.c +++ b/libempathy/empathy-tp-chat.c @@ -196,31 +196,34 @@ empathy_tp_chat_add (EmpathyTpChat *self, else if (self->priv->can_upgrade_to_muc) { TpAccountChannelRequest *req; - GHashTable *props; + GVariantDict props; const char *object_path; - GPtrArray channels = { (gpointer *) &object_path, 1 }; + GVariantBuilder channels; const char *invitees[2] = { NULL, }; TpAccount *account; invitees[0] = empathy_contact_get_id (contact); object_path = tp_proxy_get_object_path (self); - props = tp_asv_new ( - TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING, - TP_IFACE_CHANNEL_TYPE_TEXT, - TP_PROP_CHANNEL_TARGET_ENTITY_TYPE, G_TYPE_UINT, - TP_ENTITY_TYPE_NONE, + g_variant_builder_init (&channels, G_VARIANT_TYPE ("ao")); + g_variant_builder_add (&channels, "o", object_path); + + g_variant_dict_init (&props, NULL); + g_variant_dict_insert (&props, TP_PROP_CHANNEL_CHANNEL_TYPE, "s", + TP_IFACE_CHANNEL_TYPE_TEXT); + g_variant_dict_insert (&props, TP_PROP_CHANNEL_TARGET_ENTITY_TYPE, "u", + TP_ENTITY_TYPE_NONE); + g_variant_dict_insert_value (&props, TP_PROP_CHANNEL_INTERFACE_CONFERENCE1_INITIAL_CHANNELS, - TP_ARRAY_TYPE_OBJECT_PATH_LIST, &channels, + g_variant_builder_end (&channels)); + g_variant_dict_insert_value (&props, TP_PROP_CHANNEL_INTERFACE_CONFERENCE1_INITIAL_INVITEE_IDS, - G_TYPE_STRV, invitees, - /* FIXME: InvitationMessage ? */ - NULL); + g_variant_new_strv (invitees, -1)); account = empathy_tp_chat_get_account (self); - req = tp_account_channel_request_new (account, props, - TP_USER_ACTION_TIME_NOT_USER_ACTION); + req = tp_account_channel_request_new (account, + g_variant_dict_end (&props), TP_USER_ACTION_TIME_NOT_USER_ACTION); /* Although this is a MUC, it's anonymous, so CreateChannel is * valid. */ @@ -228,7 +231,6 @@ empathy_tp_chat_add (EmpathyTpChat *self, EMPATHY_CHAT_TP_BUS_NAME, NULL, create_conference_cb, NULL); g_object_unref (req); - g_hash_table_unref (props); } else { |