/* empathy-ft-handler.c */
-#include <glib.h>
-#include <glib/gi18n.h>
-#include <telepathy-glib/account-channel-request.h>
-#include <telepathy-glib/util.h>
-#include <telepathy-glib/dbus.h>
-#include <telepathy-glib/interfaces.h>
-
+#include "config.h"
#include "empathy-ft-handler.h"
-#include "empathy-tp-contact-factory.h"
-#include "empathy-time.h"
+
+#include <glib/gi18n-lib.h>
+#include <tp-account-widgets/tpaw-time.h>
+#include <tp-account-widgets/tpaw-utils.h>
+#include <telepathy-glib/telepathy-glib-dbus.h>
+
#include "empathy-utils.h"
#define DEBUG_FLAG EMPATHY_DEBUG_FT
gboolean use_hash;
/* request for the new transfer */
- GHashTable *request;
+ TpAccountChannelRequest *request;
/* transfer properties */
EmpathyContact *contact;
priv->cancellable = NULL;
}
- if (priv->request != NULL)
- {
- g_hash_table_unref (priv->request);
- priv->request = NULL;
- }
+ g_clear_object (&priv->request);
G_OBJECT_CLASS (empathy_ft_handler_parent_class)->dispose (object);
}
HashingData *hash_data;
EmpathyFTHandlerPriv *priv = GET_PRIV (handler);
- if (!EMP_STR_EMPTY (priv->content_hash))
+ if (!TPAW_STR_EMPTY (priv->content_hash))
{
hash_data = g_slice_new0 (HashingData);
hash_data->total_bytes = priv->total_bytes;
last_transferred_bytes = priv->transferred_bytes;
priv->transferred_bytes = transferred_bytes;
- current_time = empathy_time_get_current ();
+ current_time = tpaw_time_get_current ();
elapsed_time = current_time - priv->last_update_time;
if (elapsed_time >= 1)
if (priv->transferred_bytes == 0)
{
- priv->last_update_time = empathy_time_get_current ();
+ priv->last_update_time = tpaw_time_get_current ();
g_signal_emit (handler, signals[TRANSFER_STARTED], 0, channel);
}
static void
ft_handler_push_to_dispatcher (EmpathyFTHandler *handler)
{
- TpAccount *account;
EmpathyFTHandlerPriv *priv = GET_PRIV (handler);
- TpAccountChannelRequest *req;
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);
-
- tp_account_channel_request_create_and_handle_channel_async (req, NULL,
- ft_handler_create_channel_cb, handler);
-
- g_object_unref (req);
+ tp_account_channel_request_create_and_handle_channel_async (priv->request,
+ NULL, ft_handler_create_channel_cb, handler);
}
static void
ft_handler_populate_outgoing_request (EmpathyFTHandler *handler)
{
- guint contact_handle;
EmpathyFTHandlerPriv *priv = GET_PRIV (handler);
gchar *uri;
+ TpAccount *account;
- contact_handle = empathy_contact_get_handle (priv->contact);
uri = g_file_get_uri (priv->gfile);
+ account = empathy_contact_get_account (priv->contact);
- priv->request = tp_asv_new (
- TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING,
- TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER,
- TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, G_TYPE_UINT,
- TP_HANDLE_TYPE_CONTACT,
- TP_PROP_CHANNEL_TARGET_HANDLE, G_TYPE_UINT,
- contact_handle,
- TP_PROP_CHANNEL_TYPE_FILE_TRANSFER_CONTENT_TYPE, G_TYPE_STRING,
- priv->content_type,
- TP_PROP_CHANNEL_TYPE_FILE_TRANSFER_FILENAME, G_TYPE_STRING,
- priv->filename,
- TP_PROP_CHANNEL_TYPE_FILE_TRANSFER_SIZE, G_TYPE_UINT64,
- priv->total_bytes,
- TP_PROP_CHANNEL_TYPE_FILE_TRANSFER_DATE, G_TYPE_UINT64,
- priv->mtime,
- TP_PROP_CHANNEL_TYPE_FILE_TRANSFER_URI, G_TYPE_STRING, uri,
- NULL);
+ priv->request = tp_account_channel_request_new_file_transfer (account,
+ priv->filename, priv->content_type, priv->total_bytes,
+ priv->user_action_time);
+
+ tp_account_channel_request_set_target_contact (priv->request,
+ empathy_contact_get_tp_contact (priv->contact));
+
+ tp_account_channel_request_set_file_transfer_timestamp (priv->request,
+ priv->mtime);
+ tp_account_channel_request_set_file_transfer_uri (priv->request, uri);
g_free (uri);
}
/* set the checksum in the request...
* org.freedesktop.Telepathy.Channel.Type.FileTransfer.ContentHash
*/
- tp_asv_set_string (priv->request,
- TP_PROP_CHANNEL_TYPE_FILE_TRANSFER_CONTENT_HASH,
- g_checksum_get_string (hash_data->checksum));
+ tp_account_channel_request_set_file_transfer_hash (priv->request,
+ TP_FILE_HASH_TYPE_MD5, g_checksum_get_string (hash_data->checksum));
}
cleanup:
/* 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_TRANSFER_CONTENT_HASH_TYPE,
- TP_FILE_HASH_TYPE_MD5);
-
g_signal_emit (handler, signals[HASHING_STARTED], 0);
g_io_scheduler_push_job (do_hash_job, hash_data, NULL,
}
}
-static void
-contact_factory_contact_cb (TpConnection *connection,
- EmpathyContact *contact,
- const GError *error,
- gpointer user_data,
- GObject *weak_object)
-{
- CallbacksData *cb_data = user_data;
- EmpathyFTHandler *handler = EMPATHY_FT_HANDLER (weak_object);
- EmpathyFTHandlerPriv *priv = GET_PRIV (handler);
-
- if (error != NULL)
- {
- if (!g_cancellable_is_cancelled (priv->cancellable))
- g_cancellable_cancel (priv->cancellable);
-
- cb_data->callback (handler, (GError *) error, cb_data->user_data);
- callbacks_data_free (cb_data);
- return;
- }
-
- priv->contact = g_object_ref (contact);
-
- cb_data->callback (handler, NULL, cb_data->user_data);
-}
-
static void
channel_get_all_properties_cb (TpProxy *proxy,
GHashTable *properties,
CallbacksData *cb_data = user_data;
EmpathyFTHandler *handler = EMPATHY_FT_HANDLER (weak_object);
EmpathyFTHandlerPriv *priv = GET_PRIV (handler);
- TpHandle c_handle;
+ TpContact *contact;
if (error != NULL)
{
priv->content_hash_type = g_value_get_uint (
g_hash_table_lookup (properties, "ContentHashType"));
- c_handle = tp_channel_get_handle (TP_CHANNEL (proxy), NULL);
- empathy_tp_contact_factory_get_from_handle (
- tp_channel_borrow_connection (TP_CHANNEL (proxy)), c_handle,
- contact_factory_contact_cb, cb_data, callbacks_data_free,
- G_OBJECT (handler));
+ contact = tp_channel_get_target_contact (TP_CHANNEL (proxy));
+ priv->contact = empathy_contact_dup_from_tp_contact (contact);
+
+ cb_data->callback (handler, NULL, cb_data->user_data);
}
/* public methods */
/* check if hash is supported. if it isn't, set use_hash to FALSE
* anyway, so that clients won't be expecting us to checksum.
*/
- if (EMP_STR_EMPTY (priv->content_hash) ||
+ if (TPAW_STR_EMPTY (priv->content_hash) ||
priv->content_hash_type == TP_FILE_HASH_TYPE_NONE)
priv->use_hash = FALSE;
else