aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonny Lamb <jonny.lamb@collabora.co.uk>2008-11-22 00:20:00 +0800
committerXavier Claessens <xclaesse@src.gnome.org>2008-11-22 00:20:00 +0800
commitc874dc0493070088fac7b22f35f28107283b33cd (patch)
tree8adebf1dcc59101edab1cf510bb483010aa7f30b
parent1df27a669a4650a50f6b924b47155a512e789ae7 (diff)
downloadgsoc2013-empathy-c874dc0493070088fac7b22f35f28107283b33cd.tar
gsoc2013-empathy-c874dc0493070088fac7b22f35f28107283b33cd.tar.gz
gsoc2013-empathy-c874dc0493070088fac7b22f35f28107283b33cd.tar.bz2
gsoc2013-empathy-c874dc0493070088fac7b22f35f28107283b33cd.tar.lz
gsoc2013-empathy-c874dc0493070088fac7b22f35f28107283b33cd.tar.xz
gsoc2013-empathy-c874dc0493070088fac7b22f35f28107283b33cd.tar.zst
gsoc2013-empathy-c874dc0493070088fac7b22f35f28107283b33cd.zip
Moved empathy_send_file to EmpathyDispatcher and renamed it. (Jonny Lamb)
Signed-off-by: Jonny Lamb <jonny.lamb@collabora.co.uk> svn path=/trunk/; revision=1835
-rw-r--r--libempathy-gtk/empathy-ft-manager.c3
-rw-r--r--libempathy-gtk/empathy-ui-utils.c3
-rw-r--r--libempathy/empathy-dispatcher.c99
-rw-r--r--libempathy/empathy-dispatcher.h3
-rw-r--r--libempathy/empathy-tp-file.c2
-rw-r--r--libempathy/empathy-utils.c100
-rw-r--r--libempathy/empathy-utils.h10
7 files changed, 106 insertions, 114 deletions
diff --git a/libempathy-gtk/empathy-ft-manager.c b/libempathy-gtk/empathy-ft-manager.c
index 3e798c380..5814d14fe 100644
--- a/libempathy-gtk/empathy-ft-manager.c
+++ b/libempathy-gtk/empathy-ft-manager.c
@@ -50,8 +50,7 @@
/**
* SECTION:empathy-ft-manager
* @short_description: File transfer dialog
- * @see_also: #EmpathyTpFile, empathy_send_file(),
- * empathy_send_file_from_stream()
+ * @see_also: #EmpathyTpFile, empathy_dispatcher_send_file()
* @include: libempthy-gtk/empathy-ft-manager.h
*
* The #EmpathyFTManager object represents the file transfer dialog,
diff --git a/libempathy-gtk/empathy-ui-utils.c b/libempathy-gtk/empathy-ui-utils.c
index 388f4c716..20eab6098 100644
--- a/libempathy-gtk/empathy-ui-utils.c
+++ b/libempathy-gtk/empathy-ui-utils.c
@@ -47,6 +47,7 @@
#define DEBUG_FLAG EMPATHY_DEBUG_OTHER
#include <libempathy/empathy-debug.h>
#include <libempathy/empathy-utils.h>
+#include <libempathy/empathy-dispatcher.h>
struct SizeData {
gint width;
@@ -1472,7 +1473,7 @@ file_manager_send_file_response_cb (GtkDialog *widget,
gfile = g_file_new_for_uri (uri);
DEBUG ("\t%s", uri);
- empathy_send_file (contact, gfile);
+ empathy_dispatcher_send_file (contact, gfile);
manager = gtk_recent_manager_get_default ();
gtk_recent_manager_add_item (manager, uri);
diff --git a/libempathy/empathy-dispatcher.c b/libempathy/empathy-dispatcher.c
index 5f26eeeed..a110a2f94 100644
--- a/libempathy/empathy-dispatcher.c
+++ b/libempathy/empathy-dispatcher.c
@@ -927,3 +927,102 @@ empathy_dispatcher_chat_with_contact_id (McAccount *account,
g_object_unref (factory);
}
+EmpathyTpFile *
+empathy_dispatcher_send_file (EmpathyContact *contact,
+ GFile *gfile)
+{
+ GFileInfo *info;
+ guint64 size;
+ GInputStream *in_stream = NULL;
+ MissionControl *mc;
+ McAccount *account;
+ TpConnection *connection;
+ guint handle;
+ gchar *object_path;
+ TpChannel *channel;
+ EmpathyTpFile *tp_file;
+ GError *error = NULL;
+ GValue value = { 0 };
+ gchar *filename;
+
+ g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
+ g_return_val_if_fail (G_IS_FILE (gfile), NULL);
+
+ info = g_file_query_info (gfile,
+ G_FILE_ATTRIBUTE_STANDARD_SIZE ","
+ G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
+ 0, NULL, NULL);
+ size = info ? g_file_info_get_size (info) : EMPATHY_TP_FILE_UNKNOWN_SIZE;
+ filename = g_file_get_basename (gfile);
+ in_stream = G_INPUT_STREAM (g_file_read (gfile, NULL, NULL));
+ mc = empathy_mission_control_new ();
+ account = empathy_contact_get_account (contact);
+ connection = mission_control_get_tpconnection (mc, account, NULL);
+ tp_connection_run_until_ready (connection, FALSE, NULL, NULL);
+ handle = empathy_contact_get_handle (contact);
+
+ DEBUG ("Sending %s from a stream to %s (size %llu, content-type %s)",
+ filename, empathy_contact_get_name (contact), size,
+ g_file_info_get_content_type (info));
+
+ if (!tp_cli_connection_run_request_channel (connection, -1,
+ EMP_IFACE_CHANNEL_TYPE_FILE,
+ TP_HANDLE_TYPE_CONTACT,
+ handle,
+ TRUE,
+ &object_path,
+ &error,
+ NULL)) {
+ DEBUG ("Couldn't request channel: %s",
+ error ? error->message : "No error given");
+ g_clear_error (&error);
+ g_object_unref (mc);
+ g_object_unref (connection);
+ return NULL;
+ }
+
+ channel = tp_channel_new (connection,
+ object_path,
+ EMP_IFACE_CHANNEL_TYPE_FILE,
+ TP_HANDLE_TYPE_CONTACT,
+ handle,
+ NULL);
+
+ /* FIXME: this should go in CreateChannel in the new requests API */
+
+ g_value_init (&value, G_TYPE_STRING);
+ g_value_set_string (&value, g_filename_display_basename (filename));
+ tp_cli_dbus_properties_call_set (TP_PROXY (channel), -1,
+ EMP_IFACE_CHANNEL_TYPE_FILE, "Filename",
+ &value, NULL, NULL, NULL, NULL);
+ g_value_reset (&value);
+
+ g_value_set_string (&value, g_file_info_get_content_type (info));
+ tp_cli_dbus_properties_call_set (TP_PROXY (channel), -1,
+ EMP_IFACE_CHANNEL_TYPE_FILE, "ContentType",
+ &value, NULL, NULL, NULL, NULL);
+
+ g_value_unset (&value);
+
+ g_value_init (&value, G_TYPE_UINT64);
+ g_value_set_uint64 (&value, size);
+ tp_cli_dbus_properties_call_set (TP_PROXY (channel), -1,
+ EMP_IFACE_CHANNEL_TYPE_FILE, "Size",
+ &value, NULL, NULL, NULL, NULL);
+ g_value_unset (&value);
+
+ tp_file = empathy_tp_file_new (channel);
+
+ if (tp_file) {
+ empathy_tp_file_set_input_stream (tp_file, in_stream);
+ }
+
+ empathy_tp_file_offer (tp_file);
+
+ g_object_unref (mc);
+ g_object_unref (connection);
+ g_object_unref (channel);
+ g_free (object_path);
+
+ return tp_file;
+}
diff --git a/libempathy/empathy-dispatcher.h b/libempathy/empathy-dispatcher.h
index b14a460e4..491089d30 100644
--- a/libempathy/empathy-dispatcher.h
+++ b/libempathy/empathy-dispatcher.h
@@ -27,6 +27,7 @@
#include <telepathy-glib/channel.h>
#include "empathy-contact.h"
+#include "empathy-tp-file.h"
G_BEGIN_DECLS
@@ -72,6 +73,8 @@ void empathy_dispatcher_call_with_contact_id (McAccount
void empathy_dispatcher_chat_with_contact_id (McAccount *account,
const gchar *contact_id);
void empathy_dispatcher_chat_with_contact (EmpathyContact *contact);
+EmpathyTpFile * empathy_dispatcher_send_file (EmpathyContact *contact,
+ GFile *gfile);
G_END_DECLS
diff --git a/libempathy/empathy-tp-file.c b/libempathy/empathy-tp-file.c
index a56b8cfe3..bfc5e71a6 100644
--- a/libempathy/empathy-tp-file.c
+++ b/libempathy/empathy-tp-file.c
@@ -49,7 +49,7 @@
/**
* SECTION:empathy-tp-file
* @short_description: File channel
- * @see_also: #EmpathyTpFile, #EmpathyContact, empathy_send_file()
+ * @see_also: #EmpathyTpFile, #EmpathyContact, empathy_dispatcher_send_file()
* @include: libempthy/empathy-tp-file.h
*
* The #EmpathyTpFile object represents a Telepathy file channel.
diff --git a/libempathy/empathy-utils.c b/libempathy/empathy-utils.c
index ecccb04a1..c80b75cce 100644
--- a/libempathy/empathy-utils.c
+++ b/libempathy/empathy-utils.c
@@ -778,103 +778,3 @@ empathy_connection_request_channel (TpConnection *connection,
weak_object);
}
-EmpathyTpFile *
-empathy_send_file (EmpathyContact *contact,
- GFile *gfile)
-{
- GFileInfo *info;
- guint64 size;
- GInputStream *in_stream = NULL;
- MissionControl *mc;
- McAccount *account;
- TpConnection *connection;
- guint handle;
- gchar *object_path;
- TpChannel *channel;
- EmpathyTpFile *tp_file;
- GError *error = NULL;
- GValue value = { 0 };
- gchar *filename;
-
- g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
- g_return_val_if_fail (G_IS_FILE (gfile), NULL);
-
- info = g_file_query_info (gfile,
- G_FILE_ATTRIBUTE_STANDARD_SIZE ","
- G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
- 0, NULL, NULL);
- size = info ? g_file_info_get_size (info) : EMPATHY_TP_FILE_UNKNOWN_SIZE;
- filename = g_file_get_basename (gfile);
- in_stream = G_INPUT_STREAM (g_file_read (gfile, NULL, NULL));
- mc = empathy_mission_control_new ();
- account = empathy_contact_get_account (contact);
- connection = mission_control_get_tpconnection (mc, account, NULL);
- tp_connection_run_until_ready (connection, FALSE, NULL, NULL);
- handle = empathy_contact_get_handle (contact);
-
- DEBUG ("Sending %s from a stream to %s (size %llu, content-type %s)",
- filename, empathy_contact_get_name (contact), size,
- g_file_info_get_content_type (info));
-
- if (!tp_cli_connection_run_request_channel (connection, -1,
- EMP_IFACE_CHANNEL_TYPE_FILE,
- TP_HANDLE_TYPE_CONTACT,
- handle,
- TRUE,
- &object_path,
- &error,
- NULL)) {
- DEBUG ("Couldn't request channel: %s",
- error ? error->message : "No error given");
- g_clear_error (&error);
- g_object_unref (mc);
- g_object_unref (connection);
- return NULL;
- }
-
- channel = tp_channel_new (connection,
- object_path,
- EMP_IFACE_CHANNEL_TYPE_FILE,
- TP_HANDLE_TYPE_CONTACT,
- handle,
- NULL);
-
- /* FIXME: this should go in CreateChannel in the new requests API */
-
- g_value_init (&value, G_TYPE_STRING);
- g_value_set_string (&value, g_filename_display_basename (filename));
- tp_cli_dbus_properties_call_set (TP_PROXY (channel), -1,
- EMP_IFACE_CHANNEL_TYPE_FILE, "Filename",
- &value, NULL, NULL, NULL, NULL);
- g_value_reset (&value);
-
- g_value_set_string (&value, g_file_info_get_content_type (info));
- tp_cli_dbus_properties_call_set (TP_PROXY (channel), -1,
- EMP_IFACE_CHANNEL_TYPE_FILE, "ContentType",
- &value, NULL, NULL, NULL, NULL);
-
- g_value_unset (&value);
-
- g_value_init (&value, G_TYPE_UINT64);
- g_value_set_uint64 (&value, size);
- tp_cli_dbus_properties_call_set (TP_PROXY (channel), -1,
- EMP_IFACE_CHANNEL_TYPE_FILE, "Size",
- &value, NULL, NULL, NULL, NULL);
- g_value_unset (&value);
-
- tp_file = empathy_tp_file_new (channel);
-
- if (tp_file) {
- empathy_tp_file_set_input_stream (tp_file, in_stream);
- }
-
- empathy_tp_file_offer (tp_file);
-
- g_object_unref (mc);
- g_object_unref (connection);
- g_object_unref (channel);
- g_free (object_path);
-
- return tp_file;
-}
-
diff --git a/libempathy/empathy-utils.h b/libempathy/empathy-utils.h
index 9a57679ef..83c19e1c4 100644
--- a/libempathy/empathy-utils.h
+++ b/libempathy/empathy-utils.h
@@ -37,7 +37,6 @@
#include <libmissioncontrol/mission-control.h>
#include "empathy-contact.h"
-#include "empathy-tp-file.h"
G_BEGIN_DECLS
@@ -124,15 +123,6 @@ void empathy_connection_request_channel (TpConnection *proxy,
gpointer user_data,
GDestroyNotify destroy,
GObject *weak_object);
-EmpathyFile * empathy_send_file_from_stream (EmpathyContact *contact,
- GInputStream *in_stream,
- const gchar *filename,
- guint64 size);
-EmpathyFile * empathy_send_file (EmpathyContact *contact,
- GFile *file);
-/* File transfer */
-EmpathyTpFile *empathy_send_file (EmpathyContact *contact,
- GFile *file);
G_END_DECLS