2
* ubuntuone-nautilus.c - Nautilus extensions for Ubuntu One
4
* Authors: Tim Cole <tim.cole@canonical.com>
5
* Rodney Dawes <rodney.dawes@canonical.com>
7
* Copyright 2009 Canonical Ltd.
9
* This program is free software: you can redistribute it and/or modify it
10
* under the terms of the GNU General Public License version 3, as published
11
* by the Free Software Foundation.
13
* This program is distributed in the hope that it will be useful, but
14
* WITHOUT ANY WARRANTY; without even the implied warranties of
15
* MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
16
* PURPOSE. See the GNU General Public License for more details.
18
* You should have received a copy of the GNU General Public License along
19
* with this program. If not, see <http://www.gnu.org/licenses/>.
27
#include <glib/gi18n-lib.h>
29
#include <dbus/dbus-glib.h>
31
#include <libnautilus-extension/nautilus-extension-types.h>
32
#include <libnautilus-extension/nautilus-file-info.h>
33
#include <libnautilus-extension/nautilus-info-provider.h>
34
#include <libnautilus-extension/nautilus-menu-provider.h>
35
#include <libnautilus-extension/nautilus-location-widget-provider.h>
40
#include <sys/types.h>
42
#define UBUNTUONE_TYPE_NAUTILUS (ubuntuone_nautilus_get_type ())
43
#define UBUNTUONE_NAUTILUS(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), UBUNTUONE_TYPE_NAUTILUS, UbuntuOneNautilus))
48
DBusGConnection * bus;
49
DBusGProxy * u1_proxy;
50
DBusGProxy * u1_status;
51
DBusGProxy * u1_shares;
54
/* Are we connected? */
57
/* The managed directory root */
60
/* Buttons, because we need a different one for each view */
63
/* Lists of ul/dl/shares for setting emblems */
65
GHashTable * downloads;
70
GObjectClass parent_slot;
71
} UbuntuOneNautilusClass;
73
static void ubuntuone_nautilus_finalize(GObject * object);
75
static GType ubuntuone_nautilus_get_type (void);
76
static void ubuntuone_nautilus_register_type (GTypeModule * module);
78
/* DBus signal and async method call handlers */
79
static void ubuntuone_nautilus_share_metadata (DBusGProxy * proxy,
80
DBusGProxyCall * call_id,
82
static void ubuntuone_nautilus_state_toggled (DBusGProxy * proxy,
83
DBusGProxyCall * call_id,
85
static void ubuntuone_nautilus_got_root (DBusGProxy * proxy,
86
DBusGProxyCall * call_id,
88
static void ubuntuone_nautilus_got_shared (DBusGProxy * proxy,
89
DBusGProxyCall * call_id,
91
static void ubuntuone_nautilus_status_changed (DBusGProxy * proxy,
94
static void ubuntuone_nautilus_upload_started (DBusGProxy * proxy,
97
static void ubuntuone_nautilus_upload_finished (DBusGProxy * proxy,
100
static void ubuntuone_nautilus_download_started (DBusGProxy * proxy,
103
static void ubuntuone_nautilus_download_finished (DBusGProxy * proxy,
106
static void ubuntuone_nautilus_share_created (DBusGProxy * proxy,
110
static GObjectClass * parent_class = NULL;
112
/* Are we in an Ubuntu One managed directory */
113
static gboolean ubuntuone_is_storagefs (UbuntuOneNautilus * uon,
115
gboolean managed = FALSE;
124
if (strcmp (path, uon->managed) == 0)
127
dirpath = g_strdup_printf ("%s/", uon->managed);
128
if (strncmp (path, dirpath, strlen (dirpath)) == 0)
136
/* Update file info provider */
137
static NautilusOperationResult ubuntuone_nautilus_update_file_info (NautilusInfoProvider * provider,
138
NautilusFileInfo * file,
139
GClosure * update_complete,
140
NautilusOperationHandle ** handle) {
141
UbuntuOneNautilus * uon;
142
gchar * share_status = NULL;
144
int size = 0, ret = 0;
146
uon = UBUNTUONE_NAUTILUS(provider);
148
path = g_filename_from_uri (nautilus_file_info_get_uri (file), NULL, NULL);
150
if (g_hash_table_lookup (uon->uploads, path))
151
nautilus_file_info_add_emblem (file, "ubuntuone-uploading");
153
if (g_hash_table_lookup (uon->downloads, path))
154
nautilus_file_info_add_emblem (file, "ubuntuone-downloading");
156
if (g_hash_table_lookup (uon->shares, path))
157
nautilus_file_info_add_emblem (file, "shared");
159
return NAUTILUS_OPERATION_COMPLETE;
162
static void ubuntuone_nautilus_info_provider_iface_init (NautilusInfoProviderIface * iface) {
163
iface->update_file_info = ubuntuone_nautilus_update_file_info;
166
/* LocationWidget callbacks */
167
static void ubuntuone_nautilus_button_clicked (GtkButton * button,
168
gpointer user_data) {
169
UbuntuOneNautilus * uon = UBUNTUONE_NAUTILUS (user_data);
172
dbus_g_proxy_begin_call (uon->u1_proxy, "disconnect",
173
ubuntuone_nautilus_state_toggled, NULL,
174
NULL, G_TYPE_INVALID);
176
dbus_g_proxy_begin_call (uon->u1_proxy, "connect",
177
ubuntuone_nautilus_state_toggled, NULL,
178
NULL, G_TYPE_INVALID);
181
static void ubuntuone_nautilus_button_destroyed (GtkObject * button,
182
gpointer user_data) {
183
UbuntuOneNautilus * uon = UBUNTUONE_NAUTILUS (user_data);
186
/* Magic bag of holding +10:
187
* Get the path so we can remove the button from the hash table
189
path = g_object_steal_data (G_OBJECT (button), "uon-path");
190
g_hash_table_remove (uon->buttons, path);
195
/* LocationWidget provider */
196
static GtkWidget * ubuntuone_nautilus_get_location_widget(NautilusLocationWidgetProvider * provider,
198
GtkWidget * parent) {
199
UbuntuOneNautilus * uon;
201
GtkWidget * hbox = NULL;
202
GtkWidget * label, * button;
205
uon = UBUNTUONE_NAUTILUS (provider);
207
path = g_filename_from_uri (uri, NULL, NULL);
209
if (!ubuntuone_is_storagefs (uon, path))
212
hbox = gtk_hbox_new (FALSE, 6);
213
labeltext = g_strdup_printf ("<b>Ubuntu One</b> %s", _("File Sharing"));
214
label = gtk_label_new (labeltext);
215
gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
216
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
217
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
218
gtk_widget_show (label);
220
/* Create a button and stick it in the hash, if we don't have one already */
221
button = g_hash_table_lookup (uon->buttons, path);
223
button = gtk_button_new_with_label (_("Connect"));
224
/* Magic bag of holding +10:
225
* We have to set the path as data on the object, to remove the button
226
* from the hash table when it is destroyed (window close, etc...)
228
g_object_set_data_full (G_OBJECT (button), "uon-path",
229
g_strdup (path), g_free);
230
g_hash_table_replace (uon->buttons, g_strdup (path), button);
232
g_signal_connect (button, "destroy",
233
G_CALLBACK (ubuntuone_nautilus_button_destroyed), uon);
234
g_signal_connect (button, "clicked",
235
G_CALLBACK (ubuntuone_nautilus_button_clicked), uon);
236
gtk_box_pack_end (GTK_BOX (hbox), button, FALSE, FALSE, 0);
238
gtk_widget_show (button);
240
gtk_widget_show (hbox);
248
static void ubuntuone_nautilus_bar_provider_iface_init (NautilusLocationWidgetProviderIface * iface) {
249
iface->get_widget = ubuntuone_nautilus_get_location_widget;
252
/* Magical struct for passing data in sharing callbacks */
253
struct _ShareCBData {
254
UbuntuOneNautilus * uon;
258
/* Share dialog widgets */
259
GtkWidget * user_entry;
260
GtkWidget * name_entry;
261
GtkWidget * allow_mods;
264
static void __share_cb_data_free (struct _ShareCBData * data) {
276
/* Share on Ubuntu One dialog constructor */
277
static GtkWidget * ubuntuone_nautilus_share_dialog_construct (struct _ShareCBData * data) {
279
GtkWidget * area, * table, * label;
281
dialog = gtk_dialog_new ();
282
gtk_window_set_title (GTK_WINDOW (dialog), _("Share on Ubuntu One"));
283
gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (data->parent));
284
gtk_window_set_destroy_with_parent (GTK_WINDOW (dialog), TRUE);
285
gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE);
286
gtk_dialog_add_buttons (GTK_DIALOG (dialog),
287
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
288
("Share"), GTK_RESPONSE_ACCEPT,
290
gtk_dialog_set_default_response (GTK_DIALOG (dialog),
291
GTK_RESPONSE_ACCEPT);
292
gtk_window_set_icon_name (GTK_WINDOW (dialog), "ubuntuone-client");
294
area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
296
table = gtk_table_new (3, 2, FALSE);
297
gtk_table_set_row_spacings (GTK_TABLE (table), 12);
298
gtk_table_set_col_spacings (GTK_TABLE (table), 6);
299
gtk_container_set_border_width (GTK_CONTAINER (table), 7);
300
gtk_widget_show (table);
301
gtk_container_add (GTK_CONTAINER (area), table);
303
label = gtk_label_new (_("Share _with (e-mail):"));
304
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
305
gtk_label_set_use_underline (GTK_LABEL (label), TRUE);
306
gtk_table_attach_defaults (GTK_TABLE (table), label, 0, 1, 0, 1);
307
gtk_widget_show (label);
309
data->user_entry = gtk_entry_new ();
310
gtk_label_set_mnemonic_widget (GTK_LABEL (label), data->user_entry);
311
gtk_table_attach_defaults (GTK_TABLE (table), data->user_entry, 1, 2, 0, 1);
312
gtk_widget_show (data->user_entry);
314
label = gtk_label_new (_("Share _Name:"));
315
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
316
gtk_label_set_use_underline (GTK_LABEL (label), TRUE);
317
gtk_table_attach_defaults (GTK_TABLE (table), label, 0, 1, 1, 2);
318
gtk_widget_show (label);
320
data->name_entry = gtk_entry_new ();
321
gtk_label_set_mnemonic_widget (GTK_LABEL (label), data->name_entry);
322
gtk_table_attach_defaults (GTK_TABLE (table), data->name_entry, 1, 2, 1, 2);
323
gtk_widget_show (data->name_entry);
325
data->allow_mods = gtk_check_button_new_with_mnemonic (_("_Allow Modification"));
326
gtk_table_attach_defaults (GTK_TABLE (table), data->allow_mods, 0, 2, 2, 3);
327
gtk_widget_show (data->allow_mods);
332
/* Struct for post data for creating a share */
333
struct _SharePostData {
339
static void __share_post_data_free (struct _SharePostData * data) {
340
g_free (data->email);
351
static void ubuntuone_nautilus_share_dialog_response (GtkDialog * dialog,
353
gpointer user_data) {
354
struct _ShareCBData * data = (struct _ShareCBData *) user_data;
357
case GTK_RESPONSE_ACCEPT: {
358
struct _SharePostData * pdata = g_new0 (struct _SharePostData, 1);
360
pdata->email = g_strdup (gtk_entry_get_text (GTK_ENTRY (data->user_entry)));
361
pdata->name = g_strdup (gtk_entry_get_text (GTK_ENTRY (data->name_entry)));
362
pdata->modify = gtk_check_box_get_active (GTK_CHECK_BOX (data->allow_mods));
364
dbus_g_proxy_begin_call (data->uon->u1_fs, "get_metadata",
365
ubuntuone_nautilus_share_metadata, pdata,
367
G_TYPE_STRING, data->path,
371
gtk_widget_destroy (GTK_WIDGET (dialog));
374
__share_cb_data_free (data);
377
static void ubuntuone_nautilus_share_dialog_closed (GtkDialog * dialog,
378
gpointer user_data) {
379
ubuntuone_nautilus_share_dialog_response (dialog, GTK_RESPONSE_CANCEL,
383
static void ubuntuone_nautilus_share_folder (NautilusMenuItem * item,
384
gpointer * user_data) {
385
struct _ShareCBData * data = (struct _ShareCBData *) user_data;
388
dialog = ubuntuone_nautilus_share_dialog_construct (data);
389
g_signal_connect (dialog, "close",
390
G_CALLBACK (ubuntuone_nautilus_share_dialog_closed), data);
391
g_signal_connect (dialog, "response",
392
G_CALLBACK (ubuntuone_nautilus_share_dialog_response), data);
394
gtk_widget_show (dialog);
399
static GList * ubuntuone_nautilus_get_menu_items (NautilusMenuProvider * provider,
402
UbuntuOneNautilus * uon;
403
NautilusFileInfo * file;
404
GList * items = NULL;
408
struct _ShareCBData * share_cb_data;
410
if (g_list_length (files) != 1)
413
uon = UBUNTUONE_NAUTILUS (provider);
415
file = g_list_nth_data (files, 0);
416
path = g_filename_from_uri (nautilus_file_info_get_uri (file), NULL, NULL);
418
shared = g_build_filename (uon->managed, "Shared with Me", NULL);
419
myfiles = g_build_filename (uon->managed, "My Files", NULL);
421
if (!ubuntuone_is_storagefs (uon, path))
424
if (strncmp (path, shared, strlen (shared)) == 0)
427
if (strncmp (path, myfiles, strlen (myfiles)) != 0)
430
share_cb_data = g_new0 (struct _ShareCBData, 1);
431
share_cb_data->uon = uon;
432
share_cb_data->parent = window;
433
share_cb_data->path = g_strdup (path);
435
if (nautilus_file_info_is_directory (file)) {
436
NautilusMenuItem * item;
438
item = nautilus_menu_item_new ("ubuntuone-share",
439
_("Share on Ubuntu One"),
440
_("Share this folder on Ubuntu One"),
442
g_signal_connect (item, "activate",
443
G_CALLBACK (ubuntuone_nautilus_share_folder),
445
items = g_list_prepend (items, item);
455
static GList * ubuntuone_nautilus_get_bg_menu_items (NautilusMenuProvider * provider,
457
NautilusFileInfo * folder) {
458
GList * files = NULL;
459
GList * items = NULL;
461
files = g_list_prepend (files, folder);
462
items = ubuntuone_nautilus_get_menu_items (provider, window, files);
463
files = g_list_remove (files, folder);
469
static void ubuntuone_nautilus_menu_provider_iface_init (NautilusMenuProviderIface * iface) {
470
iface->get_file_items = ubuntuone_nautilus_get_menu_items;
471
iface->get_background_items = ubuntuone_nautilus_get_bg_menu_items;
474
/* GType and nautilus module stuff */
475
static GType un_type = 0;
477
static void ubuntuone_nautilus_instance_init (UbuntuOneNautilus * uon) {
478
uon->connected = FALSE;
479
uon->uploads = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
480
uon->downloads = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
481
uon->shares = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
483
/* Magic bag of holding +10:
484
* We store some button widgets in a hash table here, so that we can
485
* update the button's label if there are multiple windows open
486
* This is particularly an issue with spatial mode Nautilus
488
uon->buttons = g_hash_table_new_full (g_str_hash, g_str_equal,
491
uon->bus = dbus_g_bus_get (DBUS_BUS_SESSION, NULL);
493
g_warning ("Failed to get session bus.");
497
uon->u1_proxy = dbus_g_proxy_new_for_name (uon->bus,
498
"com.ubuntuone.SyncDaemon",
500
"com.ubuntuone.SyncDaemon.SyncDaemon");
501
uon->u1_status = dbus_g_proxy_new_for_name (uon->bus,
502
"com.ubuntuone.SyncDaemon",
504
"com.ubuntuone.SyncDaemon.Status");
505
uon->u1_shares = dbus_g_proxy_new_for_name (uon->bus,
506
"com.ubuntuone.SyncDaemon",
508
"com.ubuntuone.SyncDaemon.Shares");
510
dbus_g_proxy_begin_call (uon->u1_proxy, "get_rootdir",
511
ubuntuone_nautilus_got_root, uon,
512
NULL, G_TYPE_INVALID);
513
dbus_g_proxy_begin_call (uon->u1_shares, "get_shared",
514
ubuntuone_nautilus_got_shared, uon,
515
NULL, G_TYPE_INVALID);
517
dbus_g_proxy_add_signal (uon->u1_status, "StatusChanged",
518
dbus_g_type_get_map ("GHashTable",
522
dbus_g_proxy_connect_signal (uon->u1_status, "StatusChanged",
523
G_CALLBACK(ubuntuone_nautilus_status_changed),
526
dbus_g_proxy_add_signal (uon->u1_status, "UploadStarted",
529
dbus_g_proxy_connect_signal (uon->u1_status, "UploadStarted",
530
G_CALLBACK (ubuntuone_nautilus_upload_started),
532
dbus_g_proxy_add_signal (uon->u1_status, "UploadFinished",
535
dbus_g_proxy_connect_signal (uon->u1_status, "UploadFinished",
536
G_CALLBACK (ubuntuone_nautilus_upload_finished),
538
dbus_g_proxy_add_signal (uon->u1_status, "DownloadStarted",
541
dbus_g_proxy_connect_signal (uon->u1_status, "DownloadStarted",
542
G_CALLBACK (ubuntuone_nautilus_download_started),
544
dbus_g_proxy_add_signal (uon->u1_status, "DownloadFinished",
547
dbus_g_proxy_connect_signal (uon->u1_status, "DownloadFinished",
548
G_CALLBACK (ubuntuone_nautilus_download_finished),
550
dbus_g_proxy_add_signal (uon->u1_shares, "ShareCreated",
551
dbus_g_type_get_map ("GHashTable",
555
dbus_g_proxy_connect_signal (uon->u1_shares, "ShareCreated",
556
G_CALLBACK (ubuntuone_nautilus_share_created),
560
static void ubuntuone_nautilus_class_init (UbuntuOneNautilusClass * klass) {
561
parent_class = g_type_class_peek_parent (klass);
563
G_OBJECT_CLASS(klass)->finalize = ubuntuone_nautilus_finalize;
566
static void ubuntuone_nautilus_finalize(GObject * object) {
567
UbuntuOneNautilus * uon = UBUNTUONE_NAUTILUS(object);
570
g_object_unref (uon->u1_proxy);
571
g_object_unref (uon->u1_status);
572
g_object_unref (uon->bus);
574
g_hash_table_destroy (uon->uploads);
577
g_hash_table_destroy (uon->downloads);
578
uon->downloads = NULL;
580
g_hash_table_destroy (uon->shares);
583
g_hash_table_destroy (uon->buttons);
587
static GType ubuntuone_nautilus_get_type (void) {
591
static void ubuntuone_nautilus_register_type (GTypeModule * module) {
592
static const GTypeInfo info = {
593
sizeof (UbuntuOneNautilusClass),
594
(GBaseInitFunc) NULL,
595
(GBaseFinalizeFunc) NULL,
596
(GClassInitFunc) ubuntuone_nautilus_class_init,
599
sizeof (UbuntuOneNautilus),
601
(GInstanceInitFunc) ubuntuone_nautilus_instance_init,
604
static const GInterfaceInfo info_provider_iface_info = {
605
(GInterfaceInitFunc) ubuntuone_nautilus_info_provider_iface_init,
610
static const GInterfaceInfo bar_provider_iface_info = {
611
(GInterfaceInitFunc) ubuntuone_nautilus_bar_provider_iface_init,
616
static const GInterfaceInfo menu_provider_iface_info = {
617
(GInterfaceInitFunc) ubuntuone_nautilus_menu_provider_iface_init,
622
un_type = g_type_module_register_type (module,
627
g_type_module_add_interface (module,
629
NAUTILUS_TYPE_INFO_PROVIDER,
630
&info_provider_iface_info);
632
g_type_module_add_interface (module,
634
NAUTILUS_TYPE_LOCATION_WIDGET_PROVIDER,
635
&bar_provider_iface_info);
637
/* XXX Need to sign a request via DBus */
639
g_type_module_add_interface (module,
641
NAUTILUS_TYPE_MENU_PROVIDER,
642
&menu_provider_iface_info);
647
/* DBus signal handlers and async method call handlers */
648
static void ubuntuone_nautilus_share_metadata (DBusGProxy * proxy,
649
DBusGProxyCall * call_id,
650
gpointer user_data) {
651
struct _SharePostData * data = (struct _SharePostData *) user_data;
653
GError * error = NULL;
657
if (!dbus_g_proxy_end_call (proxy, call_id, &error,
658
dbus_g_type_get_map ("GHashTable",
660
G_TYPE_STRING), &hash,
662
g_warning ("ERROR: %s", error->message);
665
node = g_hash_table_lookup (hash, "node_id");
667
/* Need to call a to-be-implemented DBus method on syncdaemon here */
670
__share_post_data_free (data);
673
static void ubuntuone_nautilus_state_toggled (DBusGProxy * proxy,
674
DBusGProxyCall * call_id,
675
gpointer user_data) {
676
dbus_g_proxy_end_call (proxy, call_id, NULL, G_TYPE_INVALID);
679
static void ubuntuone_nautilus_got_root (DBusGProxy * proxy,
680
DBusGProxyCall * call_id,
681
gpointer user_data) {
682
UbuntuOneNautilus * uon;
684
GError * error = NULL;
686
if (!dbus_g_proxy_end_call (proxy, call_id, &error,
687
G_TYPE_STRING, &managed,
689
g_warning ("ERROR: %s", error->message);
693
uon = UBUNTUONE_NAUTILUS (user_data);
695
uon->managed = g_strdup (managed);
699
static void ubuntuone_nautilus_got_shared (DBusGProxy * proxy,
700
DBusGProxyCall * call_id,
701
gpointer user_data) {
702
UbuntuOneNautilus * uon;
704
GError * error = NULL;
706
if (!dbus_g_proxy_end_call (proxy, call_id, &error,
707
dbus_g_type_get_collection ("GSList",
714
g_warning ("ERROR: %s", error->message);
718
uon = UBUNTUONE_NAUTILUS (user_data);
719
for (l = data; l != NULL && l->data != NULL; l = l->next) {
720
GHashTable * hash = l->data;
721
ubuntuone_nautilus_share_created (proxy, hash, user_data);
722
data = g_slist_remove (data, hash);
727
static void ubuntuone_nautilus_button_foreach (gpointer key,
729
gpointer user_data) {
730
const char * label = (const char *) user_data;
731
GtkButton * button = GTK_BUTTON (value);
733
gtk_button_set_label (button, label);
736
static void ubuntuone_nautilus_status_changed (DBusGProxy * proxy,
738
gpointer user_data) {
739
UbuntuOneNautilus * uon = UBUNTUONE_NAUTILUS (user_data);
742
gchar * is_connected;
744
is_online = g_hash_table_lookup (hash, "is_online");
745
is_connected = g_hash_table_lookup (hash, "is_connected");
746
status = g_hash_table_lookup (hash, "name");
748
if (is_online[0] == '\0' || is_connected[0] == '\0' ||
749
strncmp (status, "INIT", 4) == 0||
750
strncmp (status, "READY", 5) == 0) {
751
uon->connected = FALSE;
752
g_hash_table_foreach (uon->buttons,
753
(GHFunc) ubuntuone_nautilus_button_foreach,
756
uon->connected = TRUE;
757
g_hash_table_foreach (uon->buttons,
758
(GHFunc) ubuntuone_nautilus_button_foreach,
763
static void ubuntuone_nautilus_upload_started (DBusGProxy * proxy,
765
gpointer user_data) {
766
UbuntuOneNautilus * uon = UBUNTUONE_NAUTILUS (user_data);
768
if (!g_hash_table_lookup (uon->uploads, path)) {
769
gchar *new_path = g_strdup (path);
770
g_hash_table_insert (uon->uploads, new_path, new_path);
775
static void ubuntuone_nautilus_upload_finished (DBusGProxy * proxy,
777
gpointer user_data) {
778
UbuntuOneNautilus * uon = UBUNTUONE_NAUTILUS (user_data);
780
g_hash_table_remove (uon->uploads, path);
784
static void ubuntuone_nautilus_download_started (DBusGProxy * proxy,
786
gpointer user_data) {
787
UbuntuOneNautilus * uon = UBUNTUONE_NAUTILUS (user_data);
789
const gchar * usepath;
792
partial = g_strconcat (path, ".partial", NULL);
793
if (g_file_test (path, G_FILE_TEST_IS_DIR))
798
if (!g_hash_table_lookup (uon->uploads, usepath)) {
799
gchar *new_path = g_strdup (usepath);
800
g_hash_table_insert (uon->downloads, new_path, new_path);
801
if (!g_file_test (usepath, G_FILE_TEST_EXISTS)) {
802
fd = open (usepath, O_WRONLY | O_CREAT | O_NONBLOCK | O_NOCTTY,
803
S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
806
utime (usepath, NULL);
811
static void ubuntuone_nautilus_download_finished (DBusGProxy * proxy,
813
gpointer user_data) {
814
UbuntuOneNautilus * uon = UBUNTUONE_NAUTILUS (user_data);
816
const gchar * usepath;
818
partial = g_strconcat (path, ".partial", NULL);
819
if (g_file_test (path, G_FILE_TEST_IS_DIR))
824
g_hash_table_remove (uon->downloads, usepath);
825
utime (usepath, NULL);
830
static void ubuntuone_nautilus_share_created (DBusGProxy * proxy,
832
gpointer user_data) {
833
UbuntuOneNautilus * uon = UBUNTUONE_NAUTILUS (user_data);
836
path = g_hash_table_lookup (hash, "path");
837
if (!g_hash_table_lookup (uon->shares, path)) {
838
gchar *new_share = g_strdup (path);
839
g_hash_table_insert (uon->shares, new_share, new_share);
843
/* Required Nautilus module handling methods */
844
void nautilus_module_initialize (GTypeModule * module) {
846
bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
847
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
848
textdomain (GETTEXT_PACKAGE);
851
ubuntuone_nautilus_register_type (module);
854
void nautilus_module_shutdown (void) {
858
void nautilus_module_list_types (const GType ** types,
860
static GType type_list[1];
862
type_list[0] = UBUNTUONE_TYPE_NAUTILUS;