aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCosimo Cecchi <cosimoc@gnome.org>2009-02-18 03:07:06 +0800
committerCosimo Cecchi <cosimoc@gnome.org>2009-06-01 23:46:05 +0800
commite5ac1f797a0e2f24f9a2412abf833dcdddf6998d (patch)
treed9a795af966434d25f677e55221296916d998a72
parenta5440333ee18a3174acc2437e2ba1e30365b1bca (diff)
downloadgsoc2013-empathy-e5ac1f797a0e2f24f9a2412abf833dcdddf6998d.tar
gsoc2013-empathy-e5ac1f797a0e2f24f9a2412abf833dcdddf6998d.tar.gz
gsoc2013-empathy-e5ac1f797a0e2f24f9a2412abf833dcdddf6998d.tar.bz2
gsoc2013-empathy-e5ac1f797a0e2f24f9a2412abf833dcdddf6998d.tar.lz
gsoc2013-empathy-e5ac1f797a0e2f24f9a2412abf833dcdddf6998d.tar.xz
gsoc2013-empathy-e5ac1f797a0e2f24f9a2412abf833dcdddf6998d.tar.zst
gsoc2013-empathy-e5ac1f797a0e2f24f9a2412abf833dcdddf6998d.zip
Make libempathy compile with the new changes.
-rw-r--r--libempathy/empathy-ft-factory.c24
-rw-r--r--libempathy/empathy-ft-handler.c3
-rw-r--r--libempathy/empathy-tp-file.c169
-rw-r--r--libempathy/empathy-tp-file.h3
4 files changed, 100 insertions, 99 deletions
diff --git a/libempathy/empathy-ft-factory.c b/libempathy/empathy-ft-factory.c
index 5f62f99e7..407434d68 100644
--- a/libempathy/empathy-ft-factory.c
+++ b/libempathy/empathy-ft-factory.c
@@ -114,6 +114,22 @@ empathy_ft_factory_init (EmpathyFTFactory *self)
}
static void
+ft_handler_outgoing_ready_cb (EmpathyFTHandler *handler,
+ GError *error,
+ gpointer user_data)
+{
+ EmpathyFTFactory *factory = user_data;
+
+ if (error != NULL)
+ {
+ /* TODO: error handling */
+ return;
+ }
+
+ g_signal_emit (factory, signals[NEW_FT_HANDLER], 0, handler, TRUE);
+}
+
+static void
ft_handler_incoming_ready_cb (EmpathyFTHandler *handler,
GError *error,
gpointer user_data)
@@ -142,16 +158,12 @@ empathy_ft_factory_new_transfer (EmpathyFTFactory *factory,
EmpathyContact *contact,
GFile *source)
{
- EmpathyFTHandler *handler;
-
g_return_if_fail (EMPATHY_IS_FT_FACTORY (factory));
g_return_if_fail (EMPATHY_IS_CONTACT (contact));
g_return_if_fail (G_IS_FILE (source));
- handler = empathy_ft_handler_new_outgoing (contact, source);
- g_signal_emit (factory, signals[NEW_FT_HANDLER], 0, handler, TRUE);
-
- g_object_unref (handler);
+ empathy_ft_handler_new_outgoing (contact, source,
+ ft_handler_outgoing_ready_cb, factory);
}
void
diff --git a/libempathy/empathy-ft-handler.c b/libempathy/empathy-ft-handler.c
index 85d70dbd2..ca054aa35 100644
--- a/libempathy/empathy-ft-handler.c
+++ b/libempathy/empathy-ft-handler.c
@@ -334,7 +334,6 @@ ft_transfer_operation_callback (EmpathyTpFile *tp_file,
static void
ft_transfer_progress_callback (EmpathyTpFile *tp_file,
guint64 transferred_bytes,
- guint64 total_bytes,
gpointer user_data)
{
EmpathyFTHandler *handler = user_data;
@@ -344,7 +343,7 @@ ft_transfer_progress_callback (EmpathyTpFile *tp_file,
{
priv->transferred_bytes = transferred_bytes;
g_signal_emit (handler, signals[TRANSFER_PROGRESS], 0,
- transferred_bytes, total_bytes);
+ transferred_bytes, priv->total_bytes);
}
}
diff --git a/libempathy/empathy-tp-file.c b/libempathy/empathy-tp-file.c
index 6f794b287..cbaff763e 100644
--- a/libempathy/empathy-tp-file.c
+++ b/libempathy/empathy-tp-file.c
@@ -25,6 +25,7 @@
#include <string.h>
#include <unistd.h>
+#include <errno.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
@@ -90,6 +91,7 @@ struct _EmpathyTpFilePriv {
gboolean incoming;
time_t start_time;
gchar *unix_socket_path;
+ guint64 offset;
/* GCancellable we're passed when offering/accepting the transfer */
GCancellable *cancellable;
@@ -97,7 +99,7 @@ struct _EmpathyTpFilePriv {
/* callbacks for the operation */
EmpathyTpFileProgressCallback progress_callback;
gpointer progress_user_data;
- EmpathyTpFileOperationCallback op_callback,
+ EmpathyTpFileOperationCallback op_callback;
gpointer op_user_data;
};
@@ -107,6 +109,11 @@ enum {
PROP_STATE
};
+static void tp_file_state_changed_cb (TpProxy *proxy, guint state,
+ guint reason, gpointer user_data, GObject *weak_object);
+static void tp_file_transferred_bytes_changed_cb (TpProxy *proxy, guint64 count,
+ gpointer user_data, GObject *weak_object);
+
#define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyTpFile)
G_DEFINE_TYPE (EmpathyTpFile, empathy_tp_file, G_TYPE_OBJECT);
@@ -162,11 +169,7 @@ tp_file_finalize (GObject *object)
g_object_unref (priv->factory);
}
- g_free (priv->filename);
g_free (priv->unix_socket_path);
- g_free (priv->description);
- g_free (priv->content_hash);
- g_free (priv->content_type);
if (priv->in_stream)
g_object_unref (priv->in_stream);
@@ -202,7 +205,7 @@ tp_file_get_property (GObject *object,
GValue *value,
GParamSpec *pspec)
{
- EmpathyTpFilePriv = GET_PRIV (object);
+ EmpathyTpFilePriv *priv = GET_PRIV (object);
switch (param_id)
{
@@ -266,9 +269,6 @@ tp_file_constructor (GType type,
GObject *file_obj;
EmpathyTpFile *tp_file;
EmpathyTpFilePriv *priv;
- TpHandle handle;
- GHashTable *properties;
- McAccount *account;
file_obj = G_OBJECT_CLASS (empathy_tp_file_parent_class)->constructor (type,
n_props, props);
@@ -276,8 +276,6 @@ tp_file_constructor (GType type,
tp_file = EMPATHY_TP_FILE (file_obj);
priv = GET_PRIV (tp_file);
- priv->factory = empathy_contact_factory_dup_singleton ();
-
g_signal_connect (priv->channel, "invalidated",
G_CALLBACK (tp_file_invalidated_cb), tp_file);
@@ -289,12 +287,6 @@ tp_file_constructor (GType type,
TP_PROXY (priv->channel), tp_file_transferred_bytes_changed_cb,
NULL, NULL, G_OBJECT (tp_file), NULL);
- account = empathy_channel_get_account (priv->channel);
-
- handle = tp_channel_get_handle (priv->channel, NULL);
- priv->contact = empathy_contact_factory_get_from_handle (
- priv->factory, account, (guint) handle);
-
tp_cli_dbus_properties_call_get (priv->channel,
-1, EMP_IFACE_CHANNEL_TYPE_FILE_TRANSFER, "State", tp_file_get_state_cb,
NULL, NULL, file_obj);
@@ -302,8 +294,6 @@ tp_file_constructor (GType type,
priv->state_change_reason =
EMP_FILE_TRANSFER_STATE_CHANGE_REASON_NONE;
- g_object_unref (account);
-
return file_obj;
}
@@ -361,59 +351,6 @@ ft_operation_close_with_error (EmpathyTpFile *tp_file,
}
static void
-tp_file_state_changed_cb (TpProxy *proxy,
- guint state,
- guint reason,
- gpointer user_data,
- GObject *weak_object)
-{
- EmpathyTpFilePriv *priv = GET_PRIV (weak_object);
-
- if (state == priv->state)
- return;
-
- DEBUG ("File transfer state changed:\n"
- "\tfilename = %s, old state = %u, state = %u, reason = %u\n"
- "\tincoming = %s, in_stream = %s, out_stream = %s",
- priv->filename, priv->state, state, reason,
- priv->incoming ? "yes" : "no",
- priv->in_stream ? "present" : "not present",
- priv->out_stream ? "present" : "not present");
-
- /* If the channel is open AND we have the socket path, we can start the
- * transfer. The socket path could be NULL if we are not doing the actual
- * data transfer but are just an observer for the channel.
- */
- if (state == EMP_FILE_TRANSFER_STATE_OPEN &&
- priv->unix_socket_path != NULL)
- tp_file_start_transfer (tp_file);
-
- priv->state = state;
- priv->state_change_reason = reason;
-
- g_object_notify (G_OBJECT (tp_file), "state");
-}
-
-static void
-tp_file_transferred_bytes_changed_cb (TpProxy *proxy,
- guint64 count,
- gpointer user_data,
- GObject *weak_object)
-{
- EmpathyTpFilePriv *priv = GET_PRIV (weak_object);
-
- if (priv->transferred_bytes == count)
- return;
-
- priv->transferred_bytes = count;
-
- /* notify clients */
- if (priv->progress_callback)
- priv->progress_callback (EMPATHY_TP_FILE (weak_object),
- priv->transferred_bytes, priv->size, priv->progress_user_data);
-}
-
-static void
splice_stream_ready_cb (GObject *source,
GAsyncResult *res,
gpointer user_data)
@@ -487,8 +424,7 @@ tp_file_start_transfer (EmpathyTpFile *tp_file)
/* notify we're starting a transfer */
if (priv->progress_callback)
- priv->progress_callback (tp_file, 0, priv->size,
- priv->progress_callback_user_data);
+ priv->progress_callback (tp_file, 0, priv->progress_user_data);
if (priv->incoming)
{
@@ -521,6 +457,54 @@ tp_file_start_transfer (EmpathyTpFile *tp_file)
}
static void
+tp_file_state_changed_cb (TpProxy *proxy,
+ guint state,
+ guint reason,
+ gpointer user_data,
+ GObject *weak_object)
+{
+ EmpathyTpFilePriv *priv = GET_PRIV (weak_object);
+
+ if (state == priv->state)
+ return;
+
+ DEBUG ("File transfer state changed:\n"
+ "old state = %u, state = %u, reason = %u\n"
+ "\tincoming = %s, in_stream = %s, out_stream = %s",
+ priv->state, state, reason,
+ priv->incoming ? "yes" : "no",
+ priv->in_stream ? "present" : "not present",
+ priv->out_stream ? "present" : "not present");
+
+ /* If the channel is open AND we have the socket path, we can start the
+ * transfer. The socket path could be NULL if we are not doing the actual
+ * data transfer but are just an observer for the channel.
+ */
+ if (state == EMP_FILE_TRANSFER_STATE_OPEN &&
+ priv->unix_socket_path != NULL)
+ tp_file_start_transfer (EMPATHY_TP_FILE (weak_object));
+
+ priv->state = state;
+ priv->state_change_reason = reason;
+
+ g_object_notify (weak_object, "state");
+}
+
+static void
+tp_file_transferred_bytes_changed_cb (TpProxy *proxy,
+ guint64 count,
+ gpointer user_data,
+ GObject *weak_object)
+{
+ EmpathyTpFilePriv *priv = GET_PRIV (weak_object);
+
+ /* notify clients */
+ if (priv->progress_callback)
+ priv->progress_callback (EMPATHY_TP_FILE (weak_object),
+ count, priv->progress_user_data);
+}
+
+static void
ft_operation_provide_or_accept_file_cb (TpProxy *proxy,
const GValue *address,
const GError *error,
@@ -589,7 +573,7 @@ file_read_async_cb (GObject *source,
g_value_set_static_string (&nothing, "");
emp_cli_channel_type_file_transfer_call_provide_file (
- TP_PROXY (tp_file->priv->channel), -1,
+ TP_PROXY (priv->channel), -1,
TP_SOCKET_ADDRESS_TYPE_UNIX, TP_SOCKET_ACCESS_CONTROL_LOCALHOST,
&nothing, ft_operation_provide_or_accept_file_cb, NULL, NULL, G_OBJECT (tp_file));
}
@@ -617,20 +601,15 @@ file_replace_async_cb (GObject *source,
return;
}
- priv->out_stream = out_stream;
-
- priv->filename = g_file_get_basename (gfile);
- g_object_notify (G_OBJECT (tp_file), "filename");
-
- DEBUG ("Accepting file: filename=%s", tp_file->priv->filename);
+ priv->out_stream = G_OUTPUT_STREAM (out_stream);
g_value_init (&nothing, G_TYPE_STRING);
g_value_set_static_string (&nothing, "");
emp_cli_channel_type_file_transfer_call_accept_file (TP_PROXY (priv->channel),
-1, TP_SOCKET_ADDRESS_TYPE_UNIX, TP_SOCKET_ACCESS_CONTROL_LOCALHOST,
- &nothing, offset, ft_operation_provide_or_accept_file_cb, NULL, NULL,
- G_OBJECT (tp_file));
+ &nothing, priv->offset,
+ ft_operation_provide_or_accept_file_cb, NULL, NULL, G_OBJECT (tp_file));
}
@@ -682,9 +661,10 @@ empathy_tp_file_accept (EmpathyTpFile *tp_file,
priv->op_callback = op_callback;
priv->op_user_data = op_user_data;
priv->incoming = TRUE;
+ priv->offset = offset;
- g_file_replace_async (file, G_PRIORITY_DEFAULT, cancellable,
- file_replace_async_cb, tp_file);
+ g_file_replace_async (gfile, NULL, FALSE, G_FILE_CREATE_NONE,
+ G_PRIORITY_DEFAULT, cancellable, file_replace_async_cb, tp_file);
}
void
@@ -709,7 +689,7 @@ empathy_tp_file_offer (EmpathyTpFile *tp_file,
priv->op_user_data = op_user_data;
priv->incoming = FALSE;
- g_file_read_async (file, G_PRIORITY_DEFAULT, cancellable,
+ g_file_read_async (gfile, G_PRIORITY_DEFAULT, cancellable,
file_read_async_cb, tp_file);
}
@@ -724,8 +704,13 @@ empathy_tp_file_offer (EmpathyTpFile *tp_file,
gboolean
empathy_tp_file_is_incoming (EmpathyTpFile *tp_file)
{
+ EmpathyTpFilePriv *priv;
+
g_return_val_if_fail (EMPATHY_IS_TP_FILE (tp_file), FALSE);
- return tp_file->priv->incoming;
+
+ priv = GET_PRIV (tp_file);
+
+ return priv->incoming;
}
/**
@@ -762,14 +747,18 @@ empathy_tp_file_get_state (EmpathyTpFile *tp_file,
void
empathy_tp_file_cancel (EmpathyTpFile *tp_file)
{
+ EmpathyTpFilePriv *priv;
+
g_return_if_fail (EMPATHY_IS_TP_FILE (tp_file));
+
+ priv = GET_PRIV (tp_file);
DEBUG ("Closing channel..");
- tp_cli_channel_call_close (tp_file->priv->channel, -1,
+ tp_cli_channel_call_close (priv->channel, -1,
NULL, NULL, NULL, NULL);
- if (tp_file->priv->cancellable != NULL)
- g_cancellable_cancel (tp_file->priv->cancellable);
+ if (priv->cancellable != NULL)
+ g_cancellable_cancel (priv->cancellable);
}
/**
diff --git a/libempathy/empathy-tp-file.h b/libempathy/empathy-tp-file.h
index a1447f382..b6fb7ff3a 100644
--- a/libempathy/empathy-tp-file.h
+++ b/libempathy/empathy-tp-file.h
@@ -62,7 +62,6 @@ struct _EmpathyTpFileClass
typedef void (* EmpathyTpFileProgressCallback)
(EmpathyTpFile *tp_file,
guint64 current_bytes,
- guint64 total_bytes,
gpointer user_data);
typedef void (* EmpathyTpFileOperationCallback)
@@ -96,6 +95,8 @@ void empathy_tp_file_offer (EmpathyTpFile *tp_file,
void empathy_tp_file_cancel (EmpathyTpFile *tp_file);
void empathy_tp_file_close (EmpathyTpFile *tp_file);
+gboolean empathy_tp_file_is_incoming (EmpathyTpFile *tp_file);
+
guint empathy_tp_file_get_state (EmpathyTpFile *tp_file, guint *reason);
G_END_DECLS