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-contact-manager.h>
35 #include <libempathy/empathy-ft-factory.h>
36 #include <libempathy/empathy-ft-handler.h>
37 #include <libempathy/empathy-tp-file.h>
39 #include <libempathy-gtk/empathy-contact-selector.h>
40 #include <libempathy-gtk/empathy-ui-utils.h>
42 #include "nautilus-sendto-plugin.h"
44 static EmpathyFTFactory *factory = NULL;
45 static guint transfers = 0;
47 static gboolean destroy (NstPlugin *plugin);
50 init (NstPlugin *plugin)
52 g_print ("Init %s plugin\n", plugin->info->id);
60 get_contacts_widget (NstPlugin *plugin)
62 EmpathyContactManager *manager;
65 manager = empathy_contact_manager_dup_singleton ();
66 selector = empathy_contact_selector_new (EMPATHY_CONTACT_LIST (manager));
68 empathy_contact_selector_set_visible (EMPATHY_CONTACT_SELECTOR (selector),
69 (EmpathyContactSelectorFilterFunc) empathy_contact_can_send_files, NULL);
71 g_object_unref (manager);
76 static EmpathyContact *
77 get_selected_contact (GtkWidget *contact_widget)
79 EmpathyContact *contact;
83 if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (contact_widget), &iter))
86 model = gtk_combo_box_get_model (GTK_COMBO_BOX (contact_widget));
87 gtk_tree_model_get (model, &iter,
88 EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, &contact, -1);
94 validate_destination (NstPlugin *plugin,
95 GtkWidget *contact_widget,
98 EmpathyContact *contact = NULL;
101 contact = get_selected_contact (contact_widget);
106 if (!empathy_contact_can_send_files (contact))
108 *error = g_strdup (_("The selected contact cannot receive files."));
112 if (ret && !empathy_contact_is_online (contact))
114 *error = g_strdup (_("The selected contact is offline."));
118 g_object_unref (contact);
134 transfer_done_cb (EmpathyFTHandler *handler,
135 EmpathyTpFile *tp_file,
142 transfer_error_cb (EmpathyFTHandler *handler,
150 error_dialog_cb (GtkDialog *dialog,
154 gtk_widget_destroy (GTK_WIDGET (dialog));
159 handler_ready_cb (EmpathyFTFactory *fact,
160 EmpathyFTHandler *handler,
167 dialog = gtk_message_dialog_new (NULL, 0, GTK_MESSAGE_ERROR,
168 GTK_BUTTONS_CLOSE, "%s",
169 error->message ? error->message : _("No error message"));
171 g_signal_connect (dialog, "response", G_CALLBACK (error_dialog_cb), NULL);
172 gtk_widget_show (dialog);
176 g_signal_connect (handler, "transfer-done",
177 G_CALLBACK (transfer_done_cb), plugin);
178 g_signal_connect (handler, "transfer-error",
179 G_CALLBACK (transfer_error_cb), plugin);
181 empathy_ft_handler_start_transfer (handler);
186 send_files (NstPlugin *plugin,
187 GtkWidget *contact_widget,
190 EmpathyContact *contact;
193 contact = get_selected_contact (contact_widget);
198 factory = empathy_ft_factory_dup_singleton ();
200 g_signal_connect (factory, "new-ft-handler",
201 G_CALLBACK (handler_ready_cb), plugin);
203 for (l = file_list; l; l = l->next)
205 gchar *path = l->data;
208 file = g_file_new_for_uri (path);
212 empathy_ft_factory_new_transfer_outgoing (factory,
215 g_object_unref (file);
218 g_object_unref (contact);
230 destroy (NstPlugin *plugin)
233 g_object_unref (factory);
239 NstPluginInfo plugin_info = {
242 N_("Instant Message (Empathy)"),
247 validate_destination,
252 NST_INIT_PLUGIN (plugin_info)