]> git.0d.be Git - empathy.git/commitdiff
Use new API to request file transfers
authorSjoerd Simons <sjoerd.simons@collabora.co.uk>
Fri, 9 Jan 2009 16:12:33 +0000 (16:12 +0000)
committerXavier Claessens <xclaesse@src.gnome.org>
Fri, 9 Jan 2009 16:12:33 +0000 (16:12 +0000)
Signed-off-by: Sjoerd Simons <sjoerd.simons@collabora.co.uk>
svn path=/trunk/; revision=2136

libempathy-gtk/empathy-ui-utils.c

index bd85c0522f0ce1b09e1f552c7d2062912c4bdca0..10c32bcb7a30092260835bbdf4e0e32acca8ea17 100644 (file)
@@ -51,6 +51,7 @@
 #include <libempathy/empathy-utils.h>
 #include <libempathy/empathy-dispatcher.h>
 #include <libempathy/empathy-idle.h>
+#include <libempathy/empathy-tp-file.h>
 
 void
 empathy_gtk_init (void)
@@ -1421,6 +1422,31 @@ empathy_toggle_button_set_state_quietly (GtkWidget *widget,
 
 /* Sending files with the file chooser */
 
+static void
+file_manager_send_file_request_cb (EmpathyDispatchOperation *operation,
+  const GError *error, gpointer user_data)
+{
+  GFile *file = (GFile *)user_data;
+  EmpathyTpFile *tp_file;
+
+  if (error != NULL)
+    {
+      DEBUG ("Couldn't request channel: %s", error->message);
+      g_object_unref (file);
+      return;
+    }
+
+  DEBUG ("Starting to send file");
+
+  tp_file = EMPATHY_TP_FILE (
+    empathy_dispatch_operation_get_channel_wrapper (operation));
+
+  empathy_tp_file_offer (tp_file, file, NULL);
+
+  g_object_unref (file);
+  g_object_unref (tp_file);
+}
+
 static void
 file_manager_send_file_response_cb (GtkDialog      *widget,
                                    gint            response_id,
@@ -1437,18 +1463,42 @@ file_manager_send_file_response_cb (GtkDialog      *widget,
                for (l = list; l; l = l->next) {
                        gchar            *uri;
                        GFile            *gfile;
+                       GFileInfo        *info;
                        GtkRecentManager *manager;
+                       gchar *filename;
+                       GTimeVal mtime;
+                       GError *error = NULL;
 
                        uri = l->data;
                        gfile = g_file_new_for_uri (uri);
+                       info = g_file_query_info (gfile,
+                               G_FILE_ATTRIBUTE_STANDARD_SIZE ","
+                               G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE ","
+                               G_FILE_ATTRIBUTE_TIME_MODIFIED,
+                               0, NULL, &error);
+
+                       if (error) {
+                               DEBUG ("Can't get info about the file: %s", error->message);
+                               g_clear_error (&error);
+                               g_object_unref (gfile);
+                               continue;
+                       }
 
                        DEBUG ("\t%s", uri);
-                       empathy_dispatcher_send_file (contact, gfile);
+                       filename = g_file_get_basename (gfile);
+                       g_file_info_get_modification_time (info, &mtime);
+
+                       empathy_dispatcher_send_file_to_contact (contact,
+                               filename, g_file_info_get_size (info), mtime.tv_sec,
+                               g_file_info_get_content_type (info),
+                               file_manager_send_file_request_cb, gfile);
+
+                       g_free (filename);
+                       g_object_unref (info);
 
                        manager = gtk_recent_manager_get_default ();
                        gtk_recent_manager_add_item (manager, uri);
 
-                       g_object_unref (gfile);
                        g_free (uri);
                }
                g_slist_free (list);