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>
25 #include <glib/gi18n-lib.h>
28 #include "empathy-debug.h"
29 #include "empathy-ft-factory.h"
31 #include "empathy-roster-model-manager.h"
32 #include "empathy-ui-utils.h"
33 #include "empathy-roster-view.h"
34 #include "empathy-roster-contact.h"
37 #include "nautilus-sendto-plugin.h"
39 static EmpathyFTFactory *factory = NULL;
40 static guint transfers = 0;
42 #define BOX_DATA_KEY "roster_view"
44 static gboolean destroy (NstPlugin *plugin);
47 init (NstPlugin *plugin)
49 g_print ("Init %s plugin\n", plugin->info->id);
56 static EmpathyContact *
57 dup_contact_from_individual (FolksIndividual *individual)
59 EmpathyContact *contact;
60 gboolean can_do_action;
62 if (individual == NULL)
65 contact = empathy_contact_dup_best_for_action (individual,
66 EMPATHY_ACTION_SEND_FILE);
70 can_do_action = empathy_contact_can_do_action (contact,
71 EMPATHY_ACTION_SEND_FILE);
75 /* If contact can't do FT we don't care about him */
76 g_object_unref (contact);
84 filter_individual (GtkListBoxRow *child,
87 FolksIndividual *individual;
88 EmpathyContact *contact;
90 if (!EMPATHY_IS_ROSTER_CONTACT (child))
93 individual = empathy_roster_contact_get_individual (EMPATHY_ROSTER_CONTACT (child));
95 contact = dup_contact_from_individual (individual);
99 g_object_unref (contact);
104 get_contacts_widget (NstPlugin *plugin)
106 GtkWidget *roster_view, *box, *scrolled;
107 EmpathyIndividualManager *mgr;
108 EmpathyRosterModel *model;
110 box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 8);
112 mgr = empathy_individual_manager_dup_singleton ();
113 model = EMPATHY_ROSTER_MODEL (empathy_roster_model_manager_new (mgr));
114 roster_view = empathy_roster_view_new (model);
116 g_object_unref (model);
118 scrolled = gtk_scrolled_window_new (NULL, NULL);
120 g_object_unref (mgr);
122 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled),
123 GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
124 gtk_list_box_set_filter_func (GTK_LIST_BOX (roster_view), filter_individual,
126 gtk_container_add (GTK_CONTAINER (scrolled), roster_view);
128 gtk_box_pack_start (GTK_BOX (box), scrolled, TRUE, TRUE, 0);
130 gtk_widget_set_size_request (box, -1, 300);
131 gtk_widget_show (roster_view);
132 gtk_widget_show (scrolled);
133 gtk_widget_show (box);
135 g_object_set_data (G_OBJECT (box), BOX_DATA_KEY, roster_view);
140 static EmpathyContact *
141 get_selected_contact (GtkWidget *widget)
143 EmpathyRosterView *roster_view;
144 FolksIndividual *individual;
145 EmpathyContact *contact;
147 roster_view = g_object_get_data (G_OBJECT (widget), BOX_DATA_KEY);
148 individual = empathy_roster_view_get_selected_individual (roster_view);
150 if (individual == NULL)
153 contact = dup_contact_from_individual (individual);
155 g_object_unref (individual);
160 validate_destination (NstPlugin *plugin,
161 GtkWidget *contact_widget,
164 EmpathyContact *contact = NULL;
166 contact = get_selected_contact (contact_widget);
171 g_object_unref (contact);
187 transfer_done_cb (EmpathyFTHandler *handler,
188 TpFileTransferChannel *channel,
195 transfer_error_cb (EmpathyFTHandler *handler,
203 error_dialog_cb (GtkDialog *dialog,
207 gtk_widget_destroy (GTK_WIDGET (dialog));
212 handler_ready_cb (EmpathyFTFactory *fact,
213 EmpathyFTHandler *handler,
220 dialog = gtk_message_dialog_new (NULL, 0, GTK_MESSAGE_ERROR,
221 GTK_BUTTONS_CLOSE, "%s",
222 error->message ? error->message : _("No error message"));
224 g_signal_connect (dialog, "response", G_CALLBACK (error_dialog_cb), NULL);
225 gtk_widget_show (dialog);
229 g_signal_connect (handler, "transfer-done",
230 G_CALLBACK (transfer_done_cb), plugin);
231 g_signal_connect (handler, "transfer-error",
232 G_CALLBACK (transfer_error_cb), plugin);
234 empathy_ft_handler_start_transfer (handler);
239 send_files (NstPlugin *plugin,
240 GtkWidget *contact_widget,
243 EmpathyContact *contact;
246 contact = get_selected_contact (contact_widget);
251 factory = empathy_ft_factory_dup_singleton ();
253 g_signal_connect (factory, "new-ft-handler",
254 G_CALLBACK (handler_ready_cb), plugin);
256 for (l = file_list; l; l = l->next)
258 gchar *path = l->data;
261 file = g_file_new_for_uri (path);
265 empathy_ft_factory_new_transfer_outgoing (factory,
266 contact, file, empathy_get_current_action_time ());
268 g_object_unref (file);
271 g_object_unref (contact);
283 destroy (NstPlugin *plugin)
286 g_object_unref (factory);
292 NstPluginInfo plugin_info = {
295 N_("Instant Message (Empathy)"),
300 validate_destination,
305 NST_INIT_PLUGIN (plugin_info)