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 (GtkWidget *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 egg_list_box_set_filter_func (EGG_LIST_BOX (roster_view), filter_individual,
126 egg_list_box_add_to_scrolled (EGG_LIST_BOX (roster_view),
127 GTK_SCROLLED_WINDOW (scrolled));
129 gtk_box_pack_start (GTK_BOX (box), scrolled, TRUE, TRUE, 0);
131 gtk_widget_set_size_request (box, -1, 300);
132 gtk_widget_show (roster_view);
133 gtk_widget_show (scrolled);
134 gtk_widget_show (box);
136 g_object_set_data (G_OBJECT (box), BOX_DATA_KEY, roster_view);
141 static EmpathyContact *
142 get_selected_contact (GtkWidget *widget)
144 EmpathyRosterView *roster_view;
145 FolksIndividual *individual;
146 EmpathyContact *contact;
148 roster_view = g_object_get_data (G_OBJECT (widget), BOX_DATA_KEY);
149 individual = empathy_roster_view_get_selected_individual (roster_view);
151 if (individual == NULL)
154 contact = dup_contact_from_individual (individual);
156 g_object_unref (individual);
161 validate_destination (NstPlugin *plugin,
162 GtkWidget *contact_widget,
165 EmpathyContact *contact = NULL;
167 contact = get_selected_contact (contact_widget);
172 g_object_unref (contact);
188 transfer_done_cb (EmpathyFTHandler *handler,
189 TpFileTransferChannel *channel,
196 transfer_error_cb (EmpathyFTHandler *handler,
204 error_dialog_cb (GtkDialog *dialog,
208 gtk_widget_destroy (GTK_WIDGET (dialog));
213 handler_ready_cb (EmpathyFTFactory *fact,
214 EmpathyFTHandler *handler,
221 dialog = gtk_message_dialog_new (NULL, 0, GTK_MESSAGE_ERROR,
222 GTK_BUTTONS_CLOSE, "%s",
223 error->message ? error->message : _("No error message"));
225 g_signal_connect (dialog, "response", G_CALLBACK (error_dialog_cb), NULL);
226 gtk_widget_show (dialog);
230 g_signal_connect (handler, "transfer-done",
231 G_CALLBACK (transfer_done_cb), plugin);
232 g_signal_connect (handler, "transfer-error",
233 G_CALLBACK (transfer_error_cb), plugin);
235 empathy_ft_handler_start_transfer (handler);
240 send_files (NstPlugin *plugin,
241 GtkWidget *contact_widget,
244 EmpathyContact *contact;
247 contact = get_selected_contact (contact_widget);
252 factory = empathy_ft_factory_dup_singleton ();
254 g_signal_connect (factory, "new-ft-handler",
255 G_CALLBACK (handler_ready_cb), plugin);
257 for (l = file_list; l; l = l->next)
259 gchar *path = l->data;
262 file = g_file_new_for_uri (path);
266 empathy_ft_factory_new_transfer_outgoing (factory,
267 contact, file, empathy_get_current_action_time ());
269 g_object_unref (file);
272 g_object_unref (contact);
284 destroy (NstPlugin *plugin)
287 g_object_unref (factory);
293 NstPluginInfo plugin_info = {
296 N_("Instant Message (Empathy)"),
301 validate_destination,
306 NST_INIT_PLUGIN (plugin_info)