2
* Copyright (C) 2008 Collabora Ltd.
2
* Copyright (C) 2008, 2009 Collabora Ltd.
4
4
* This program is free software; you can redistribute it and/or
5
5
* modify it under the terms of the GNU General Public License as
16
16
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17
17
* Boston, MA 02110-1301 USA.
19
* Author: Jonny Lamb <jonny.lamb@collabora.co.uk>
19
* Authors: Jonny Lamb <jonny.lamb@collabora.co.uk>
20
* Cosimo Cecchi <cosimo.cecchi@collabora.co.uk>
22
23
#include "config.h"
26
27
#include <gtk/gtk.h>
27
28
#include <gio/gio.h>
30
#include <telepathy-glib/enums.h>
32
#include <libempathy/empathy-contact.h>
29
33
#include <libempathy/empathy-debug.h>
30
34
#include <libempathy/empathy-contact-manager.h>
31
#include <libempathy/empathy-dispatcher.h>
35
#include <libempathy/empathy-ft-factory.h>
36
#include <libempathy/empathy-ft-handler.h>
37
#include <libempathy/empathy-tp-file.h>
32
38
#include <libempathy/empathy-utils.h>
34
#include <libempathy-gtk/empathy-contact-list-store.h>
40
#include <libempathy-gtk/empathy-contact-selector.h>
41
#include <libempathy-gtk/empathy-ui-utils.h>
36
43
#include "nautilus-sendto-plugin.h"
38
static EmpathyContactManager *manager = NULL;
39
45
static MissionControl *mc = NULL;
46
static EmpathyFTFactory *factory = NULL;
47
static guint transfers = 0;
41
49
static gboolean destroy (NstPlugin *plugin);
49
57
g_print ("Init %s plugin\n", plugin->info->id);
51
empathy_debug_set_flags (g_getenv ("EMPATHY_DEBUG"));
53
mc = empathy_mission_control_new ();
59
bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
60
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
64
mc = empathy_mission_control_dup_singleton ();
54
65
accounts = mission_control_get_online_connections (mc, FALSE);
56
67
if (g_slist_length (accounts) == 0)
71
82
get_contacts_widget (NstPlugin *plugin)
73
EmpathyContactListStore *store;
75
GtkCellRenderer *renderer;
77
/* TODO: Replace all this with EmpathyContactSelector once it's fixed up and
78
* merged into libempathy-gtk. */
79
manager = empathy_contact_manager_new ();
80
store = empathy_contact_list_store_new (EMPATHY_CONTACT_LIST (manager));
82
empathy_contact_list_store_set_is_compact (store, TRUE);
83
empathy_contact_list_store_set_show_groups (store, FALSE);
85
combo = gtk_combo_box_new_with_model (GTK_TREE_MODEL (store));
87
renderer = gtk_cell_renderer_text_new ();
89
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo), renderer, TRUE);
90
gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (combo),
91
renderer, "text", EMPATHY_CONTACT_LIST_STORE_COL_NAME);
84
EmpathyContactManager *manager;
87
manager = empathy_contact_manager_dup_singleton ();
88
selector = empathy_contact_selector_new (EMPATHY_CONTACT_LIST (manager));
90
empathy_contact_selector_set_visible (EMPATHY_CONTACT_SELECTOR (selector),
91
(EmpathyContactSelectorFilterFunc) empathy_contact_can_send_files, NULL);
93
g_object_unref (manager);
97
get_selected_contact (GtkWidget *contact_widget,
98
EmpathyContact **contact)
98
static EmpathyContact *
99
get_selected_contact (GtkWidget *contact_widget)
101
EmpathyContact *contact;
100
102
GtkTreeModel *model;
101
103
GtkTreeIter iter;
103
105
if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (contact_widget), &iter))
106
108
model = gtk_combo_box_get_model (GTK_COMBO_BOX (contact_widget));
107
109
gtk_tree_model_get (model, &iter,
108
EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, contact, -1);
110
if (*contact == NULL)
110
EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, &contact, -1);
121
120
EmpathyContact *contact = NULL;
123
if (!get_selected_contact (contact_widget, &contact))
123
contact = get_selected_contact (contact_widget);
126
128
if (!empathy_contact_can_send_files (contact))
128
130
*error = g_strdup (_("The contact selected cannot receive files."));
132
if (!empathy_contact_is_online (contact))
134
if (ret && !empathy_contact_is_online (contact))
134
136
*error = g_strdup (_("The contact selected is offline."));
138
140
g_object_unref (contact);
156
transfer_done_cb (EmpathyFTHandler *handler,
157
EmpathyTpFile *tp_file,
164
transfer_error_cb (EmpathyFTHandler *handler,
172
error_dialog_cb (GtkDialog *dialog,
176
gtk_widget_destroy (GTK_WIDGET (dialog));
181
handler_ready_cb (EmpathyFTFactory *factory,
182
EmpathyFTHandler *handler,
186
g_print ("handler ready!, error %p", error);
191
dialog = gtk_message_dialog_new (NULL, 0, GTK_MESSAGE_ERROR,
192
GTK_BUTTONS_CLOSE, "%s",
193
error->message ? error->message : _("No error message"));
195
g_signal_connect (dialog, "response", G_CALLBACK (error_dialog_cb), NULL);
196
gtk_widget_show (dialog);
200
g_signal_connect (handler, "transfer-done",
201
G_CALLBACK (transfer_done_cb), plugin);
202
g_signal_connect (handler, "transfer-error",
203
G_CALLBACK (transfer_error_cb), plugin);
205
empathy_ft_handler_start_transfer (handler);
145
211
GtkWidget *contact_widget,
146
212
GList *file_list)
148
EmpathyContact *contact = NULL;
214
EmpathyContact *contact;
151
if (!get_selected_contact (contact_widget, &contact))
217
contact = get_selected_contact (contact_widget);
222
factory = empathy_ft_factory_dup_singleton ();
224
g_signal_connect (factory, "new-ft-handler",
225
G_CALLBACK (handler_ready_cb), plugin);
154
227
for (l = file_list; l; l = l->next)
156
229
gchar *path = l->data;
159
232
file = g_file_new_for_uri (path);
160
empathy_dispatcher_send_file (contact, file);
236
empathy_ft_factory_new_transfer_outgoing (factory,
162
239
g_object_unref (file);
166
242
g_object_unref (contact);
172
254
destroy (NstPlugin *plugin)
175
g_object_unref (manager);
178
257
g_object_unref (mc);
260
g_object_unref (factory);