2 * Copyright (C) 2008, 2009 Collabora Ltd.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more av.
14 * You should have received a copy of the GNU General Public
15 * License along with this program; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301 USA.
19 * Authors: Jonny Lamb <jonny.lamb@collabora.co.uk>
20 * Cosimo Cecchi <cosimo.cecchi@collabora.co.uk>
26 #include <glib/gi18n-lib.h>
30 #include <telepathy-glib/enums.h>
32 #include <libempathy/empathy-contact.h>
33 #include <libempathy/empathy-debug.h>
34 #include <libempathy/empathy-ft-factory.h>
35 #include <libempathy/empathy-ft-handler.h>
37 #include <libempathy-gtk/empathy-contact-chooser.h>
38 #include <libempathy-gtk/empathy-ui-utils.h>
40 #include "nautilus-sendto-plugin.h"
42 static EmpathyFTFactory *factory = NULL;
43 static guint transfers = 0;
45 static gboolean destroy (NstPlugin *plugin);
48 init (NstPlugin *plugin)
50 g_print ("Init %s plugin\n", plugin->info->id);
57 static EmpathyContact *
58 dup_contact_from_individual (FolksIndividual *individual)
60 EmpathyContact *contact;
61 gboolean can_do_action;
63 if (individual == NULL)
66 contact = empathy_contact_dup_best_for_action (individual,
67 EMPATHY_ACTION_SEND_FILE);
71 can_do_action = empathy_contact_can_do_action (contact,
72 EMPATHY_ACTION_SEND_FILE);
76 /* If contact can't do FT we don't care about him */
77 g_object_unref (contact);
85 filter_individual (EmpathyContactChooser *chooser,
86 FolksIndividual *individual,
91 EmpathyContact *contact;
96 contact = dup_contact_from_individual (individual);
100 g_object_unref (contact);
105 get_contacts_widget (NstPlugin *plugin)
109 chooser = empathy_contact_chooser_new ();
110 empathy_contact_chooser_set_filter_func (EMPATHY_CONTACT_CHOOSER (chooser),
111 filter_individual, plugin);
113 empathy_contact_chooser_show_search_entry (EMPATHY_CONTACT_CHOOSER (chooser),
116 /* Make sure to display some contacts */
117 gtk_widget_set_size_request (chooser, -1, 300);
121 static EmpathyContact *
122 get_selected_contact (GtkWidget *widget)
124 FolksIndividual *individual;
125 EmpathyContact *contact;
127 individual = empathy_contact_chooser_dup_selected (
128 EMPATHY_CONTACT_CHOOSER (widget));
129 if (individual == NULL)
132 contact = dup_contact_from_individual (individual);
134 g_object_unref (individual);
139 validate_destination (NstPlugin *plugin,
140 GtkWidget *contact_widget,
143 EmpathyContact *contact = NULL;
146 contact = get_selected_contact (contact_widget);
151 g_object_unref (contact);
167 transfer_done_cb (EmpathyFTHandler *handler,
168 TpFileTransferChannel *channel,
175 transfer_error_cb (EmpathyFTHandler *handler,
183 error_dialog_cb (GtkDialog *dialog,
187 gtk_widget_destroy (GTK_WIDGET (dialog));
192 handler_ready_cb (EmpathyFTFactory *fact,
193 EmpathyFTHandler *handler,
200 dialog = gtk_message_dialog_new (NULL, 0, GTK_MESSAGE_ERROR,
201 GTK_BUTTONS_CLOSE, "%s",
202 error->message ? error->message : _("No error message"));
204 g_signal_connect (dialog, "response", G_CALLBACK (error_dialog_cb), NULL);
205 gtk_widget_show (dialog);
209 g_signal_connect (handler, "transfer-done",
210 G_CALLBACK (transfer_done_cb), plugin);
211 g_signal_connect (handler, "transfer-error",
212 G_CALLBACK (transfer_error_cb), plugin);
214 empathy_ft_handler_start_transfer (handler);
219 send_files (NstPlugin *plugin,
220 GtkWidget *contact_widget,
223 EmpathyContact *contact;
226 contact = get_selected_contact (contact_widget);
231 factory = empathy_ft_factory_dup_singleton ();
233 g_signal_connect (factory, "new-ft-handler",
234 G_CALLBACK (handler_ready_cb), plugin);
236 for (l = file_list; l; l = l->next)
238 gchar *path = l->data;
241 file = g_file_new_for_uri (path);
245 empathy_ft_factory_new_transfer_outgoing (factory,
246 contact, file, empathy_get_current_action_time ());
248 g_object_unref (file);
251 g_object_unref (contact);
263 destroy (NstPlugin *plugin)
266 g_object_unref (factory);
272 NstPluginInfo plugin_info = {
275 N_("Instant Message (Empathy)"),
280 validate_destination,
285 NST_INIT_PLUGIN (plugin_info)