Merge lp:~rodrigo-moya/ubuntuone-client/no-shared-callback-data into lp:ubuntuone-client

Proposed by Rodrigo Moya
Status: Merged
Approved by: Rodrigo Moya
Approved revision: 719
Merged at revision: 719
Proposed branch: lp:~rodrigo-moya/ubuntuone-client/no-shared-callback-data
Merge into: lp:ubuntuone-client
Diff against target: 1172 lines (+523/-474)
9 files modified
nautilus/Makefile.am (+2/-0)
nautilus/context-menu.c (+426/-0)
nautilus/context-menu.h (+32/-0)
nautilus/error-dialog.c (+1/-1)
nautilus/location-widget.h (+0/-3)
nautilus/ubuntuone-nautilus.c (+17/-456)
nautilus/ubuntuone-nautilus.h (+5/-14)
nautilus/utils.c (+39/-0)
po/POTFILES.in (+1/-0)
To merge this branch: bzr merge lp:~rodrigo-moya/ubuntuone-client/no-shared-callback-data
Reviewer Review Type Date Requested Status
Natalia Bidart (community) Approve
Roman Yepishev (community) fieldtest Approve
Review via email: mp+36281@code.launchpad.net

Commit message

Don't use shared callback data anymore, each menu should have its own

Description of the change

Don't use shared callback data anymore, each menu should have its own

To post a comment you must log in.
Revision history for this message
Roman Yepishev (rye) :
review: Approve (fieldtest)
Revision history for this message
Natalia Bidart (nataliabidart) :
review: Approve
Revision history for this message
dobey (dobey) wrote :

Attempt to merge into lp:ubuntuone-client failed due to conflicts:

text conflict in nautilus/ubuntuone-nautilus.c

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'nautilus/Makefile.am'
2--- nautilus/Makefile.am 2010-08-25 14:00:10 +0000
3+++ nautilus/Makefile.am 2010-09-22 11:18:40 +0000
4@@ -24,6 +24,8 @@
5 add-contact-dialog.h \
6 contacts-view.c \
7 contacts-view.h \
8+ context-menu.c \
9+ context-menu.h \
10 error-dialog.c \
11 location-widget.c \
12 location-widget.h \
13
14=== added file 'nautilus/context-menu.c'
15--- nautilus/context-menu.c 1970-01-01 00:00:00 +0000
16+++ nautilus/context-menu.c 2010-09-22 11:18:40 +0000
17@@ -0,0 +1,426 @@
18+/*
19+ * UbuntuOne Nautilus plugin
20+ *
21+ * Authors: Rodrigo Moya <rodrigo.moya@canonical.com>
22+ *
23+ * Copyright 2009-2010 Canonical Ltd.
24+ *
25+ * This program is free software: you can redistribute it and/or modify it
26+ * under the terms of the GNU General Public License version 3, as published
27+ * by the Free Software Foundation.
28+ *
29+ * This program is distributed in the hope that it will be useful, but
30+ * WITHOUT ANY WARRANTY; without even the implied warranties of
31+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
32+ * PURPOSE. See the GNU General Public License for more details.
33+ *
34+ * You should have received a copy of the GNU General Public License along
35+ * with this program. If not, see <http://www.gnu.org/licenses/>.
36+ *
37+ */
38+
39+#ifdef HAVE_CONFIG_H
40+#include <config.h>
41+#endif
42+
43+#include <glib/gi18n-lib.h>
44+#include <libsyncdaemon/libsyncdaemon.h>
45+#include "context-menu.h"
46+#include "location-widget.h"
47+#include "share-dialog.h"
48+
49+typedef struct {
50+ UbuntuOneNautilus *uon;
51+ gchar *path;
52+ GtkWidget *parent;
53+
54+ /* Whether to make a file public or private */
55+ gboolean make_public;
56+} MenuCallbackData;
57+
58+static void
59+free_menu_cb_data (gpointer data, GObject *where_the_object_was)
60+{
61+ MenuCallbackData *cb_data = (MenuCallbackData *) data;
62+
63+ g_free (cb_data->path);
64+ g_free (cb_data);
65+}
66+
67+/* Menu callbacks */
68+static void
69+got_public_meta (SyncdaemonFilesystemInterface *interface,
70+ gboolean success,
71+ SyncdaemonMetadata *metadata,
72+ gpointer user_data)
73+{
74+ MenuCallbackData *data = (MenuCallbackData *) user_data;
75+ GError * error = NULL;
76+ const gchar * share_id, * node_id;
77+ SyncdaemonInterface *public;
78+
79+ if (!success) {
80+ g_warning ("ERROR: getting metadata for public file");
81+ return;
82+ }
83+
84+ share_id = syncdaemon_metadata_get_share_id (metadata);
85+ node_id = syncdaemon_metadata_get_node_id (metadata);
86+
87+ public = syncdaemon_daemon_get_publicfiles_interface (data->uon->syncdaemon);
88+ if (public != NULL) {
89+ syncdaemon_publicfiles_interface_change_public_access (SYNCDAEMON_PUBLICFILES_INTERFACE (public),
90+ share_id, node_id, data->make_public);
91+ }
92+}
93+
94+static void
95+unsubscribe_folder_cb (NautilusMenuItem *item, gpointer user_data)
96+{
97+ SyncdaemonInterface *interface;
98+ MenuCallbackData * data = (MenuCallbackData *) user_data;
99+
100+ /* Perform the removal of this folder */
101+ interface = syncdaemon_daemon_get_folders_interface (data->uon->syncdaemon);
102+ if (interface != NULL) {
103+ SyncdaemonFolderInfo *folder_info;
104+
105+ folder_info = syncdaemon_folders_interface_get_info (SYNCDAEMON_FOLDERS_INTERFACE (interface),
106+ data->path);
107+ if (folder_info != NULL) {
108+ if (ubuntuone_nautilus_check_shares_and_public_files (data->uon, folder_info, data->parent)) {
109+ syncdaemon_folders_interface_delete (SYNCDAEMON_FOLDERS_INTERFACE (interface),
110+ syncdaemon_folder_info_get_volume_id (folder_info));
111+ }
112+ g_object_unref (G_OBJECT (folder_info));
113+ }
114+ }
115+}
116+
117+static void
118+subscribe_folder_cb (NautilusMenuItem *item, gpointer user_data)
119+{
120+ SyncdaemonInterface *interface;
121+ MenuCallbackData * data = (MenuCallbackData *) user_data;
122+
123+ /* Perform the addition of this folder */
124+ interface = syncdaemon_daemon_get_folders_interface (data->uon->syncdaemon);
125+ if (interface != NULL) {
126+ /* If there is no user authenticated, make Syncdaemon do so */
127+ if (!syncdaemon_authentication_has_credentials (syncdaemon_daemon_get_authentication (data->uon->syncdaemon)))
128+ syncdaemon_daemon_connect (data->uon->syncdaemon);
129+ syncdaemon_folders_interface_create (SYNCDAEMON_FOLDERS_INTERFACE (interface),
130+ data->path);
131+ }
132+}
133+
134+static void
135+copy_public_url_cb (NautilusMenuItem *item, gpointer user_data)
136+{
137+ MenuCallbackData * data = (MenuCallbackData *) user_data;
138+ gchar * url;
139+
140+ url = g_hash_table_lookup (data->uon->public, data->path);
141+ gtk_clipboard_set_text (gtk_clipboard_get(GDK_SELECTION_CLIPBOARD),
142+ url, strlen (url));
143+ gtk_clipboard_store (gtk_clipboard_get(GDK_SELECTION_CLIPBOARD));
144+}
145+
146+static void
147+toggle_publicity_cb (NautilusMenuItem * item, gpointer user_data)
148+{
149+ SyncdaemonFilesystemInterface *interface;
150+ MenuCallbackData * data = (MenuCallbackData *) user_data;
151+
152+ interface = (SyncdaemonFilesystemInterface *) syncdaemon_daemon_get_filesystem_interface (data->uon->syncdaemon);
153+ if (interface != NULL) {
154+ /* we know this will not be a directory (so no need for _and_quick_tree_synced) */
155+ syncdaemon_filesystem_interface_get_metadata_async (interface, data->path, FALSE,
156+ (SyncdaemonGotMetadataFunc) got_public_meta, data);
157+ }
158+
159+ g_hash_table_replace (data->uon->public, g_strdup (data->path), UPDATE_PENDING);
160+ ubuntuone_nautilus_reset_emblem (data->uon, data->path);
161+}
162+
163+static void
164+share_folder_cb (NautilusMenuItem *item, gpointer user_data)
165+{
166+ MenuCallbackData * data = (MenuCallbackData *) user_data;
167+ GtkWidget * dialog;
168+
169+ dialog = share_dialog_new (data->parent, data->uon, data->path);
170+ gtk_widget_show (dialog);
171+}
172+
173+static void
174+unshare_folder_cb (NautilusMenuItem *item, gpointer user_data)
175+{
176+ MenuCallbackData * data = (MenuCallbackData *) user_data;
177+ gchar * share_id;
178+ SyncdaemonSharesInterface *interface;
179+
180+ interface = (SyncdaemonSharesInterface *) syncdaemon_daemon_get_shares_interface (data->uon->syncdaemon);
181+ if (interface != NULL) {
182+ share_id = g_hash_table_lookup (data->uon->shares, data->path);
183+ syncdaemon_shares_interface_delete (interface, share_id);
184+ }
185+}
186+
187+static void
188+toggle_location_cb (NautilusMenuItem *item, gpointer user_data)
189+{
190+ GConfClient *conf_client;
191+
192+ conf_client = gconf_client_get_default ();
193+ gconf_client_set_bool (conf_client, EXPANDER_SHOWN_KEY, !ubuntuone_is_location_bar_enabled (), NULL);
194+}
195+
196+NautilusMenuItem *
197+context_menu_new (UbuntuOneNautilus *uon,
198+ GtkWidget *window,
199+ GList *files)
200+{
201+ NautilusFileInfo *file;
202+ NautilusMenu *submenu;
203+ NautilusMenuItem *root_item, *menu_item, *urlitem;
204+ gchar *path, *item, *homedir_path;
205+ gboolean is_managed, is_root, is_udf, is_public, is_shared, is_pending;
206+ gboolean is_inhome, is_dir, is_regular;
207+ MenuCallbackData *cb_data;
208+
209+ is_managed = is_root = is_udf = is_public = is_shared = is_pending = FALSE;
210+ is_inhome = is_dir = is_regular = FALSE;
211+
212+ if (g_list_length (files) != 1)
213+ return NULL;
214+
215+ file = NAUTILUS_FILE_INFO (g_list_nth_data (files, 0));
216+ path = g_filename_from_uri (nautilus_file_info_get_uri (file), NULL, NULL);
217+
218+ if (path == NULL)
219+ return NULL;
220+
221+ if (ubuntuone_is_storagefs (uon, path, &is_root))
222+ is_managed = TRUE;
223+
224+ homedir_path = g_strdup_printf ("%s/", g_get_home_dir());
225+ if (strncmp (path, homedir_path, strlen (homedir_path)) == 0)
226+ is_inhome = TRUE;
227+ g_free (homedir_path);
228+
229+ if ((item = g_hash_table_lookup (uon->udfs, path)) != NULL) {
230+ is_udf = TRUE;
231+ if (strcmp (item, UPDATE_PENDING) == 0)
232+ is_pending = TRUE;
233+ } else if ((item = g_hash_table_lookup (uon->public, path)) != NULL) {
234+ is_public = TRUE;
235+ if (strcmp (item, UPDATE_PENDING) == 0)
236+ is_pending = TRUE;
237+ }
238+ if (g_hash_table_lookup (uon->shares, path) != NULL)
239+ is_shared = TRUE;
240+
241+ is_dir = nautilus_file_info_is_directory (file);
242+ is_regular = nautilus_file_info_get_file_type (file) == G_FILE_TYPE_REGULAR;
243+
244+ cb_data = g_new0 (MenuCallbackData, 1);
245+ cb_data->uon = uon;
246+ cb_data->parent = window;
247+ cb_data->path = g_strdup (path);
248+
249+ /* Create the root item */
250+ root_item = nautilus_menu_item_new ("ubuntuone",
251+ _("_Ubuntu One"),
252+ _("Ubuntu One options"),
253+ "ubuntuone");
254+ submenu = nautilus_menu_new ();
255+ nautilus_menu_item_set_submenu (root_item, submenu);
256+
257+ g_object_weak_ref (G_OBJECT (root_item), (GWeakNotify) free_menu_cb_data, cb_data);
258+
259+ /* Share/unshare */
260+ if ((is_managed || is_udf) && !is_root && is_dir) {
261+
262+ menu_item = nautilus_menu_item_new ("ubuntuone-share",
263+ _("_Share..."),
264+ _("Share this folder on Ubuntu One"),
265+ "ubuntuone");
266+ if (is_pending)
267+ g_object_set (menu_item, "sensitive", FALSE, NULL);
268+
269+ g_signal_connect (menu_item, "activate",
270+ G_CALLBACK (share_folder_cb), cb_data);
271+ } else {
272+ /* the different tooltips will probably do us no good */
273+ if (is_root) {
274+ menu_item = nautilus_menu_item_new ("ubuntuone-noshare-root",
275+ _("_Share..."),
276+ _("Sorry, you can't share the root of a Ubuntu One volume"),
277+ "ubuntuone");
278+ } else if (!(is_managed || is_udf)) {
279+ menu_item = nautilus_menu_item_new ("ubuntuone-noshare-unmanaged",
280+ _("_Share..."),
281+ _("Sorry, you can't share folders not managed by Ubuntu One"),
282+ "ubuntuone");
283+ } else {
284+ menu_item = nautilus_menu_item_new ("ubuntuone-noshare-unmanaged",
285+ _("_Share..."),
286+ _("Sorry, you can only share folders"),
287+ "ubuntuone");
288+ }
289+ g_object_set (menu_item, "sensitive", FALSE, NULL);
290+ }
291+
292+ nautilus_menu_append_item (submenu, menu_item);
293+
294+ if ((is_managed && is_shared) && !is_root && is_dir) {
295+ menu_item = nautilus_menu_item_new ("ubuntuone-unshare",
296+ _("Stop _Sharing"),
297+ _("Stop sharing this folder on Ubuntu One"),
298+ "ubuntuone");
299+ if (is_pending)
300+ g_object_set (menu_item, "sensitive", FALSE, NULL);
301+
302+ g_signal_connect (menu_item, "activate",
303+ G_CALLBACK (unshare_folder_cb), cb_data);
304+ nautilus_menu_append_item (submenu, menu_item);
305+ }
306+
307+ /* UDF logic
308+ *
309+ * XXX: clean this up and separate the logic out and reuse this
310+ * and locationbar somewhere (libsd?)
311+ */
312+ menu_item = NULL;
313+
314+ if (is_dir && is_inhome) {
315+ /* UDFs could be happening */
316+ if (is_managed) {
317+ if (strcmp (path, uon->managed) == 0) {
318+ /* the Ubuntu One directory, no UDFs */
319+ menu_item = nautilus_menu_item_new ("ubuntuone-no-disable-u1",
320+ _("Stop Synchronizing This _Folder"),
321+ _("Sorry, you can't stop synchronizing ~/Ubuntu One"),
322+ "ubuntuone");
323+ g_object_set (menu_item, "sensitive", FALSE, NULL);
324+ } else if (is_root) {
325+ /* the root of a UDF: disabling possible */
326+
327+ menu_item = nautilus_menu_item_new ("ubuntuone-disable-udf",
328+ _("Stop Synchronizing This _Folder"),
329+ _("Stop synchronizing this folder with Ubuntu One"),
330+ "ubuntuone");
331+
332+ g_signal_connect (menu_item, "activate",
333+ G_CALLBACK (unsubscribe_folder_cb), cb_data);
334+ }
335+ } else {
336+ /* unmanaged */
337+ menu_item = nautilus_menu_item_new ("ubuntuone-enable-udf",
338+ _("Synchronize This _Folder"),
339+ _("Start synchronizing this folder with Ubuntu One"),
340+ "ubuntuone");
341+
342+ g_signal_connect (menu_item, "activate",
343+ G_CALLBACK (subscribe_folder_cb), cb_data);
344+ }
345+ } else {
346+ if (is_dir) {
347+ menu_item = nautilus_menu_item_new ("ubuntuone-no-disable-u1",
348+ _("Synchronize This _Folder"),
349+ _("Sorry, you can only synchronize folders within your home folder"),
350+ "ubuntuone");
351+ } else {
352+ menu_item = nautilus_menu_item_new ("ubuntuone-no-disable-u1",
353+ _("Synchronize This _Folder"),
354+ _("Sorry, you can only synchronize folders"),
355+ "ubuntuone");
356+ }
357+
358+ g_object_set (menu_item, "sensitive", FALSE, NULL);
359+ }
360+
361+ if (!menu_item) {
362+ menu_item = nautilus_menu_item_new ("ubuntuone-no-udf-operation-possible",
363+ _("Synchronize This _Folder"),
364+ _("Synchronization not possible for this folder"),
365+ "ubuntuone");
366+ g_object_set (menu_item, "sensitive", FALSE, NULL);
367+ }
368+
369+ nautilus_menu_append_item (submenu, menu_item);
370+
371+ /* public files */
372+ menu_item = urlitem = NULL;
373+
374+ if (is_managed && is_regular) {
375+ if (is_public) {
376+ urlitem = nautilus_menu_item_new ("ubuntuone-geturl",
377+ _("Copy Web _Link"),
378+ _("Copy the Ubuntu One public URL for this file to the clipboard."),
379+ "ubuntuone");
380+ if (is_pending)
381+ g_object_set (urlitem, "sensitive", FALSE, NULL);
382+ g_signal_connect (urlitem, "activate",
383+ G_CALLBACK (copy_public_url_cb), cb_data);
384+
385+ menu_item = nautilus_menu_item_new ("ubuntuone-unpublish",
386+ _("Stop _Publishing"),
387+ _("No longer share this file with everyone via Ubuntu One."),
388+ "ubuntuone");
389+ if (is_pending)
390+ g_object_set (menu_item, "sensitive", FALSE, NULL);
391+
392+ cb_data->make_public = FALSE;
393+ } else {
394+ menu_item = nautilus_menu_item_new ("ubuntuone-publish",
395+ _("_Publish"),
396+ _("Make this file available to anyone via Ubuntu One."),
397+ "ubuntuone");
398+ cb_data->make_public = TRUE;
399+ }
400+ g_signal_connect (menu_item, "activate",
401+ G_CALLBACK (toggle_publicity_cb), cb_data);
402+ }
403+
404+ if (!urlitem) {
405+ urlitem = nautilus_menu_item_new ("ubuntuone-geturl",
406+ _("Copy Web _Link"),
407+ _("Sorry, no public URL for this file via Ubuntu One."),
408+ "ubuntuone");
409+ g_object_set (urlitem, "sensitive", FALSE, NULL);
410+ }
411+
412+ if (!menu_item) {
413+ menu_item = nautilus_menu_item_new ("ubuntuone-publish",
414+ _("_Publish"),
415+ _("Sorry, unable to publish via Ubuntu One."),
416+ "ubuntuone");
417+ g_object_set (menu_item, "sensitive", FALSE, NULL);
418+ }
419+
420+ nautilus_menu_append_item (submenu, menu_item);
421+ nautilus_menu_append_item (submenu, urlitem);
422+
423+ /* location bar enable/disable */
424+ if (ubuntuone_is_location_bar_enabled ()) {
425+ menu_item = nautilus_menu_item_new ("ubuntuone-location-hide",
426+ _("Hide _Ribbon"),
427+ _("Do not show the Ubuntu One ribbon"
428+ " in selected folders"),
429+ "ubuntuone");
430+ } else {
431+ menu_item = nautilus_menu_item_new ("ubuntuone-location-show",
432+ _("Show _Ribbon in Some Folders"),
433+ _("Show the Ubuntu One ribbon"
434+ " in selected folders"),
435+ "ubuntuone");
436+ }
437+
438+ g_signal_connect (menu_item, "activate",
439+ G_CALLBACK (toggle_location_cb), cb_data);
440+ nautilus_menu_append_item (submenu, menu_item);
441+
442+ return root_item;
443+}
444
445=== added file 'nautilus/context-menu.h'
446--- nautilus/context-menu.h 1970-01-01 00:00:00 +0000
447+++ nautilus/context-menu.h 2010-09-22 11:18:40 +0000
448@@ -0,0 +1,32 @@
449+/*
450+ * UbuntuOne Nautilus plugin
451+ *
452+ * Authors: Rodrigo Moya <rodrigo.moya@canonical.com>
453+ *
454+ * Copyright 2009-2010 Canonical Ltd.
455+ *
456+ * This program is free software: you can redistribute it and/or modify it
457+ * under the terms of the GNU General Public License version 3, as published
458+ * by the Free Software Foundation.
459+ *
460+ * This program is distributed in the hope that it will be useful, but
461+ * WITHOUT ANY WARRANTY; without even the implied warranties of
462+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
463+ * PURPOSE. See the GNU General Public License for more details.
464+ *
465+ * You should have received a copy of the GNU General Public License along
466+ * with this program. If not, see <http://www.gnu.org/licenses/>.
467+ *
468+ */
469+
470+#ifndef __CONTEXT_MENU_H__
471+#define __CONTEXT_MENU_H__
472+
473+#include <libnautilus-extension/nautilus-menu-provider.h>
474+#include "ubuntuone-nautilus.h"
475+
476+NautilusMenuItem *context_menu_new (UbuntuOneNautilus *uon,
477+ GtkWidget *window,
478+ GList *files);
479+
480+#endif
481
482=== modified file 'nautilus/error-dialog.c'
483--- nautilus/error-dialog.c 2010-08-02 10:40:26 +0000
484+++ nautilus/error-dialog.c 2010-09-22 11:18:40 +0000
485@@ -37,7 +37,7 @@
486 va_end (args);
487
488 /* Show the dialog */
489- dialog = gtk_message_dialog_new (GTK_WINDOW (uon->cb_data->parent),
490+ dialog = gtk_message_dialog_new (NULL,
491 GTK_DIALOG_DESTROY_WITH_PARENT,
492 GTK_MESSAGE_ERROR,
493 GTK_BUTTONS_CLOSE,
494
495=== modified file 'nautilus/location-widget.h'
496--- nautilus/location-widget.h 2010-08-11 22:38:44 +0000
497+++ nautilus/location-widget.h 2010-09-22 11:18:40 +0000
498@@ -61,7 +61,4 @@
499 GType location_widget_get_type (void);
500 GtkWidget *location_widget_new (UbuntuOneNautilus *uon, const gchar *path);
501
502-/* this is the wrong place for this, but it'll have to do for now */
503-gboolean location_widget_check_shared_for_folder (SyncdaemonDaemon *daemon, SyncdaemonFolderInfo *folder_info, GtkWidget *widget);
504-
505 #endif
506
507=== modified file 'nautilus/ubuntuone-nautilus.c'
508--- nautilus/ubuntuone-nautilus.c 2010-09-14 14:20:39 +0000
509+++ nautilus/ubuntuone-nautilus.c 2010-09-22 11:18:40 +0000
510@@ -33,8 +33,8 @@
511 #include <libnautilus-extension/nautilus-location-widget-provider.h>
512 #include <libsyncdaemon/libsyncdaemon.h>
513 #include "ubuntuone-nautilus.h"
514+#include "context-menu.h"
515 #include "location-widget.h"
516-#include "share-dialog.h"
517
518 /* We need to do this explicitly because older versions of nautilus
519 * don't seem to do it for us
520@@ -49,17 +49,11 @@
521 /* The header is generated from ubuntuone-marshallers.list */
522 #include "ubuntuone-marshallers.h"
523
524-/* This is used when a change is pending */
525-#define UPDATE_PENDING "pending"
526-
527 static void ubuntuone_nautilus_finalize(GObject * object);
528
529 static void ubuntuone_nautilus_register_type (GTypeModule * module);
530
531 /* Utility functions */
532-static void ubuntuone_nautilus_reset_emblem (UbuntuOneNautilus * uon,
533- const char * path);
534-
535 static void ubuntuone_nautilus_observed_file_unref (gpointer user_data,
536 GObject *where_the_object_was);
537
538@@ -115,22 +109,6 @@
539
540 static GObjectClass * parent_class = NULL;
541
542-static void ubuntuone_nautilus_reset_emblem (UbuntuOneNautilus * uon,
543- const char * path) {
544-
545- GHashTableIter iter;
546- gchar *key;
547- NautilusFileInfo *file;
548-
549- /* Remove emblems from all files in the specified path */
550- g_hash_table_iter_init (&iter, uon->observed);
551- while (g_hash_table_iter_next (&iter, (gpointer *) &key, (gpointer *) &file)) {
552- if (g_str_has_prefix (key, path) || g_strcmp0 (key, path) == 0) {
553- nautilus_file_info_invalidate_extension_info (file);
554- }
555- }
556-}
557-
558 /* Called when NautilusFileInfo is unreferenced */
559 static void ubuntuone_nautilus_observed_file_unref (gpointer user_data,
560 GObject *where_the_object_was) {
561@@ -157,8 +135,8 @@
562 uon = UBUNTUONE_NAUTILUS(user_data);
563 file = NAUTILUS_FILE_INFO(value);
564
565- g_object_weak_unref (G_OBJECT(file),
566- (GWeakNotify)ubuntuone_nautilus_observed_file_unref,
567+ g_object_weak_unref (G_OBJECT (file),
568+ (GWeakNotify) ubuntuone_nautilus_observed_file_unref,
569 uon);
570
571 }
572@@ -316,44 +294,16 @@
573 iface->update_file_info = ubuntuone_nautilus_update_file_info;
574 }
575
576-static gboolean
577-show_location (void)
578-{
579- GConfClient *conf_client;
580- GConfValue * show_location_value;
581- gboolean show_location;
582-
583- conf_client = gconf_client_get_default ();
584- show_location_value = gconf_client_get (conf_client, EXPANDER_SHOWN_KEY, NULL);
585- g_object_unref (conf_client);
586-
587- if (show_location_value == NULL) {
588- show_location = TRUE;
589- } else {
590- show_location = gconf_value_get_bool (show_location_value);
591- }
592- gconf_value_free (show_location_value);
593-
594- return show_location;
595-}
596-
597-static void toggle_location() {
598- GConfClient *conf_client;
599-
600- conf_client = gconf_client_get_default ();
601- gconf_client_set_bool (conf_client, EXPANDER_SHOWN_KEY, !show_location(), NULL);
602-}
603-
604 /* LocationWidget provider */
605-static GtkWidget * ubuntuone_nautilus_get_location_widget(NautilusLocationWidgetProvider * provider,
606- const char * uri,
607- GtkWidget * parent) {
608+static GtkWidget * ubuntuone_nautilus_get_location_widget (NautilusLocationWidgetProvider * provider,
609+ const char * uri,
610+ GtkWidget * parent) {
611 UbuntuOneNautilus * uon;
612 gchar *path;
613 GtkWidget *location;
614
615 /* if the bar is disabled, do nothing */
616- if (!show_location())
617+ if (!ubuntuone_is_location_bar_enabled ())
618 return NULL;
619
620 uon = UBUNTUONE_NAUTILUS (provider);
621@@ -378,151 +328,15 @@
622 iface->get_widget = ubuntuone_nautilus_get_location_widget;
623 }
624
625-static void __cb_data_free (struct _CBData * data) {
626- if (!data)
627- return;
628-
629- data->uon = NULL;
630- data->parent = NULL;
631-
632- if (data->path) {
633- g_free (data->path);
634- data->path = NULL;
635- }
636-
637- g_free (data);
638-
639- data = NULL;
640-}
641-
642-/* Menu callbacks */
643-static void ubuntuone_nautilus_public_meta (SyncdaemonFilesystemInterface *interface,
644- gboolean success,
645- SyncdaemonMetadata *metadata,
646- gpointer user_data) {
647- struct _CBData * data = (struct _CBData *) user_data;
648- GError * error = NULL;
649- const gchar * share_id, * node_id;
650- SyncdaemonInterface *public;
651-
652- if (!success) {
653- g_warning ("ERROR: getting metadata for public file");
654- return;
655- }
656-
657- share_id = syncdaemon_metadata_get_share_id (metadata);
658- node_id = syncdaemon_metadata_get_node_id (metadata);
659-
660- public = syncdaemon_daemon_get_publicfiles_interface (data->uon->syncdaemon);
661- if (public != NULL) {
662- syncdaemon_publicfiles_interface_change_public_access (SYNCDAEMON_PUBLICFILES_INTERFACE (public),
663- share_id, node_id, data->make_public);
664- }
665-}
666-
667-static void ubuntuone_nautilus_unsubscribe_folder (NautilusMenuItem *item,
668- gpointer user_data) {
669- SyncdaemonInterface *interface;
670- struct _CBData * data = (struct _CBData *) user_data;
671-
672- /* Perform the removal of this folder */
673- interface = syncdaemon_daemon_get_folders_interface (data->uon->syncdaemon);
674- if (interface != NULL) {
675- SyncdaemonFolderInfo *folder_info;
676-
677- folder_info = syncdaemon_folders_interface_get_info (SYNCDAEMON_FOLDERS_INTERFACE (interface),
678- data->path);
679- if (folder_info != NULL) {
680- if (ubuntuone_nautilus_check_shares_and_public_files (data->uon, folder_info, data->parent)) {
681- syncdaemon_folders_interface_delete (SYNCDAEMON_FOLDERS_INTERFACE (interface),
682- syncdaemon_folder_info_get_volume_id (folder_info));
683- }
684- g_object_unref (G_OBJECT (folder_info));
685- }
686- }
687-}
688-
689-static void ubuntuone_nautilus_subscribe_folder (NautilusMenuItem *item,
690- gpointer user_data) {
691- SyncdaemonInterface *interface;
692- struct _CBData * data = (struct _CBData *) user_data;
693-
694- /* Perform the addition of this folder */
695- interface = syncdaemon_daemon_get_folders_interface (data->uon->syncdaemon);
696- if (interface != NULL) {
697- /* If there is no user authenticated, make Syncdaemon do so */
698- if (!syncdaemon_authentication_has_credentials (syncdaemon_daemon_get_authentication (data->uon->syncdaemon)))
699- syncdaemon_daemon_connect (data->uon->syncdaemon);
700- syncdaemon_folders_interface_create (SYNCDAEMON_FOLDERS_INTERFACE (interface),
701- data->path);
702- }
703-}
704-
705-static void ubuntuone_nautilus_copy_public_url (NautilusMenuItem * item,
706- gpointer user_data) {
707- struct _CBData * data = (struct _CBData *) user_data;
708- gchar * url;
709-
710- url = g_hash_table_lookup (data->uon->public, data->path);
711- gtk_clipboard_set_text (gtk_clipboard_get(GDK_SELECTION_CLIPBOARD),
712- url, strlen (url));
713- gtk_clipboard_store (gtk_clipboard_get(GDK_SELECTION_CLIPBOARD));
714-}
715-
716-static void ubuntuone_nautilus_toggle_publicity (NautilusMenuItem * item,
717- gpointer user_data) {
718- SyncdaemonFilesystemInterface *interface;
719- struct _CBData * data = (struct _CBData *) user_data;
720-
721- interface = (SyncdaemonFilesystemInterface *) syncdaemon_daemon_get_filesystem_interface (data->uon->syncdaemon);
722- if (interface != NULL) {
723- /* we know this will not be a directory (so no need for _and_quick_tree_synced) */
724- syncdaemon_filesystem_interface_get_metadata_async (interface, data->path, FALSE,
725- (SyncdaemonGotMetadataFunc) ubuntuone_nautilus_public_meta,
726- data);
727- }
728-
729- g_hash_table_replace (data->uon->public, g_strdup (data->path), UPDATE_PENDING);
730- ubuntuone_nautilus_reset_emblem (data->uon, data->path);
731-}
732-
733-static void ubuntuone_nautilus_share_folder (NautilusMenuItem * item,
734- gpointer * user_data) {
735- struct _CBData * data = (struct _CBData *) user_data;
736- GtkWidget * dialog;
737-
738- dialog = share_dialog_new (data->parent, data->uon, data->path);
739- gtk_widget_show (dialog);
740-}
741-
742-static void ubuntuone_nautilus_unshare_folder (NautilusMenuItem * item,
743- gpointer * user_data) {
744- struct _CBData * data = (struct _CBData *) user_data;
745- gchar * share_id;
746- SyncdaemonSharesInterface *interface;
747-
748- interface = (SyncdaemonSharesInterface *) syncdaemon_daemon_get_shares_interface (data->uon->syncdaemon);
749- if (interface != NULL) {
750- share_id = g_hash_table_lookup (data->uon->shares, data->path);
751- syncdaemon_shares_interface_delete (interface, share_id);
752- }
753-}
754-
755 /* Menu provider */
756-static GList * ubuntuone_nautilus_get_menu_items (NautilusMenuProvider * provider,
757- GtkWidget * window,
758- GList * files) {
759+static GList *
760+ubuntuone_nautilus_get_menu_items (NautilusMenuProvider * provider,
761+ GtkWidget * window,
762+ GList * files)
763+{
764 UbuntuOneNautilus * uon;
765- NautilusFileInfo * file;
766- NautilusMenu * submenu;
767- NautilusMenuItem * root_item;
768- GList * items = NULL;
769- gchar * path;
770- gchar * item;
771- gchar * homedir_path;
772- gboolean is_managed, is_root, is_udf, is_public, is_shared, is_pending;
773- gboolean is_inhome, is_dir, is_regular;
774- struct _CBData * cb_data;
775+ GList *items = NULL;
776+ NautilusMenuItem *root_item;
777
778 uon = UBUNTUONE_NAUTILUS (provider);
779
780@@ -530,260 +344,9 @@
781 if (!syncdaemon_daemon_is_ready (uon->syncdaemon))
782 return NULL;
783
784- is_managed = is_root = is_udf = is_public = is_shared = is_pending = FALSE;
785- is_inhome = is_dir = is_regular = FALSE;
786-
787- if (g_list_length (files) != 1)
788- return NULL;
789-
790- file = g_list_nth_data (files, 0);
791- path = g_filename_from_uri (nautilus_file_info_get_uri (file), NULL, NULL);
792-
793- if (path == NULL)
794- goto done;
795-
796- if (ubuntuone_is_storagefs (uon, path, &is_root))
797- is_managed = TRUE;
798-
799- homedir_path = g_strdup_printf ("%s/", g_get_home_dir());
800- if (strncmp (path, homedir_path, strlen (homedir_path)) == 0)
801- is_inhome = TRUE;
802- g_free (homedir_path);
803-
804- if ((item = g_hash_table_lookup (uon->udfs, path)) != NULL) {
805- is_udf = TRUE;
806- if (strcmp (item, UPDATE_PENDING) == 0)
807- is_pending = TRUE;
808- } else if ((item = g_hash_table_lookup (uon->public, path)) != NULL) {
809- is_public = TRUE;
810- if (strcmp (item, UPDATE_PENDING) == 0)
811- is_pending = TRUE;
812- }
813- if (g_hash_table_lookup (uon->shares, path) != NULL)
814- is_shared = TRUE;
815-
816- is_dir = nautilus_file_info_is_directory (file);
817- is_regular = nautilus_file_info_get_file_type (file) == G_FILE_TYPE_REGULAR;
818-
819- if (uon->cb_data)
820- __cb_data_free (uon->cb_data);
821-
822- cb_data = g_new0 (struct _CBData, 1);
823- cb_data->uon = uon;
824- cb_data->parent = window;
825- cb_data->path = g_strdup (path);
826-
827- uon->cb_data = cb_data;
828-
829- root_item = nautilus_menu_item_new ("ubuntuone",
830- _("_Ubuntu One"),
831- _("Ubuntu One options"),
832- "ubuntuone");
833- submenu = nautilus_menu_new ();
834- nautilus_menu_item_set_submenu (root_item, submenu);
835-
836- items = g_list_append (items, root_item);
837-
838- /* Share/unshare */
839- {
840- NautilusMenuItem * item;
841-
842- if ((is_managed || is_udf) && !is_root && is_dir) {
843-
844- item = nautilus_menu_item_new ("ubuntuone-share",
845- _("_Share..."),
846- _("Share this folder on Ubuntu One"),
847- "ubuntuone");
848- if (is_pending)
849- g_object_set (item, "sensitive", FALSE, NULL);
850-
851- g_signal_connect (item, "activate",
852- G_CALLBACK (ubuntuone_nautilus_share_folder),
853- cb_data);
854- } else {
855- /* the different tooltips will probably do us no good */
856- if (is_root) {
857- item = nautilus_menu_item_new ("ubuntuone-noshare-root",
858- _("_Share..."),
859- _("Sorry, you can't share the root of a Ubuntu One volume"),
860- "ubuntuone");
861- } else if (!(is_managed || is_udf)) {
862- item = nautilus_menu_item_new ("ubuntuone-noshare-unmanaged",
863- _("_Share..."),
864- _("Sorry, you can't share folders not managed by Ubuntu One"),
865- "ubuntuone");
866- } else {
867- item = nautilus_menu_item_new ("ubuntuone-noshare-unmanaged",
868- _("_Share..."),
869- _("Sorry, you can only share folders"),
870- "ubuntuone");
871- }
872- g_object_set (item, "sensitive", FALSE, NULL);
873- }
874-
875- nautilus_menu_append_item (submenu, item);
876- }
877-
878- if ((is_managed && is_shared) && !is_root && is_dir) {
879- NautilusMenuItem * item;
880-
881- item = nautilus_menu_item_new ("ubuntuone-unshare",
882- _("Stop _Sharing"),
883- _("Stop sharing this folder on Ubuntu One"),
884- "ubuntuone");
885- if (is_pending)
886- g_object_set (item, "sensitive", FALSE, NULL);
887-
888- g_signal_connect (item, "activate",
889- G_CALLBACK (ubuntuone_nautilus_unshare_folder),
890- cb_data);
891- nautilus_menu_append_item (submenu, item);
892- }
893-
894- {
895- /* UDF logic
896- *
897- * XXX: clean this up and separate the logic out and reuse this
898- * and locationbar somewhere (libsd?)
899- */
900- NautilusMenuItem * item = NULL;
901- if (is_dir && is_inhome) {
902- /* UDFs could be happening */
903- if (is_managed) {
904- if (strcmp (path, uon->managed) == 0) {
905- /* the Ubuntu One directory, no UDFs */
906- item = nautilus_menu_item_new ("ubuntuone-no-disable-u1",
907- _("Stop Synchronizing This _Folder"),
908- _("Sorry, you can't stop synchronizing ~/Ubuntu One"),
909- "ubuntuone");
910- g_object_set (item, "sensitive", FALSE, NULL);
911- } else if (is_root) {
912- /* the root of a UDF: disabling possible */
913-
914- item = nautilus_menu_item_new ("ubuntuone-disable-udf",
915- _("Stop Synchronizing This _Folder"),
916- _("Stop synchronizing this folder with Ubuntu One"),
917- "ubuntuone");
918-
919- g_signal_connect (item, "activate",
920- G_CALLBACK (ubuntuone_nautilus_unsubscribe_folder),
921- cb_data);
922- }
923- } else {
924- /* unmanaged */
925-
926- item = nautilus_menu_item_new ("ubuntuone-enable-udf",
927- _("Synchronize This _Folder"),
928- _("Start synchronizing this folder with Ubuntu One"),
929- "ubuntuone");
930-
931- g_signal_connect (item, "activate",
932- G_CALLBACK (ubuntuone_nautilus_subscribe_folder),
933- cb_data);
934- }
935- } else {
936- if (is_dir) {
937- item = nautilus_menu_item_new ("ubuntuone-no-disable-u1",
938- _("Synchronize This _Folder"),
939- _("Sorry, you can only synchronize folders within your home folder"),
940- "ubuntuone");
941- } else {
942- item = nautilus_menu_item_new ("ubuntuone-no-disable-u1",
943- _("Synchronize This _Folder"),
944- _("Sorry, you can only synchronize folders"),
945- "ubuntuone");
946- }
947- g_object_set (item, "sensitive", FALSE, NULL);
948- }
949- if (!item) {
950- item = nautilus_menu_item_new ("ubuntuone-no-udf-operation-possible",
951- _("Synchronize This _Folder"),
952- _("Synchronization not possible for this folder"),
953- "ubuntuone");
954- g_object_set (item, "sensitive", FALSE, NULL);
955- }
956- nautilus_menu_append_item (submenu, item);
957- }
958-
959- /* public files */
960- {
961- NautilusMenuItem * item = NULL, * urlitem = NULL;
962-
963- if (is_managed && is_regular) {
964-
965- if (is_public) {
966- urlitem = nautilus_menu_item_new ("ubuntuone-geturl",
967- _("Copy Web _Link"),
968- _("Copy the Ubuntu One public URL for this file to the clipboard."),
969- "ubuntuone");
970- if (is_pending)
971- g_object_set (urlitem, "sensitive", FALSE, NULL);
972-
973- g_signal_connect (urlitem, "activate",
974- G_CALLBACK (ubuntuone_nautilus_copy_public_url),
975- cb_data);
976- item = nautilus_menu_item_new ("ubuntuone-unpublish",
977- _("Stop _Publishing"),
978- _("No longer share this file with everyone via Ubuntu One."),
979- "ubuntuone");
980- if (is_pending)
981- g_object_set (item, "sensitive", FALSE, NULL);
982-
983- cb_data->make_public = FALSE;
984- } else {
985- item = nautilus_menu_item_new ("ubuntuone-publish",
986- _("_Publish"),
987- _("Make this file available to anyone via Ubuntu One."),
988- "ubuntuone");
989- cb_data->make_public = TRUE;
990- }
991- g_signal_connect (item, "activate",
992- G_CALLBACK (ubuntuone_nautilus_toggle_publicity),
993- cb_data);
994- }
995- if (!urlitem) {
996- urlitem = nautilus_menu_item_new ("ubuntuone-geturl",
997- _("Copy Web _Link"),
998- _("Sorry, no public URL for this file via Ubuntu One."),
999- "ubuntuone");
1000- g_object_set (urlitem, "sensitive", FALSE, NULL);
1001- }
1002- if (!item) {
1003- item = nautilus_menu_item_new ("ubuntuone-publish",
1004- _("_Publish"),
1005- _("Sorry, unable to publish via Ubuntu One."),
1006- "ubuntuone");
1007- g_object_set (item, "sensitive", FALSE, NULL);
1008- }
1009-
1010- nautilus_menu_append_item (submenu, item);
1011- nautilus_menu_append_item (submenu, urlitem);
1012- }
1013-
1014- /* location bar enable/disable */
1015- {
1016- NautilusMenuItem * item;
1017- if (show_location()) {
1018- item = nautilus_menu_item_new ("ubuntuone-location-hide",
1019- _("Hide _Ribbon"),
1020- _("Do not show the Ubuntu One ribbon"
1021- " in selected folders"),
1022- "ubuntuone");
1023- } else {
1024- item = nautilus_menu_item_new ("ubuntuone-location-show",
1025- _("Show _Ribbon in Some Folders"),
1026- _("Show the Ubuntu One ribbon"
1027- " in selected folders"),
1028- "ubuntuone");
1029- }
1030- g_signal_connect (item, "activate",
1031- G_CALLBACK (toggle_location),
1032- cb_data);
1033- nautilus_menu_append_item (submenu, item);
1034- }
1035-
1036- done:
1037- g_free (path);
1038+ root_item = context_menu_new (uon, window, files);
1039+ if (root_item != NULL)
1040+ items = g_list_append (items, root_item);
1041
1042 return items;
1043 }
1044@@ -876,8 +439,6 @@
1045 static void ubuntuone_nautilus_finalize(GObject * object) {
1046 UbuntuOneNautilus * uon = UBUNTUONE_NAUTILUS(object);
1047
1048- __cb_data_free (uon->cb_data);
1049-
1050 if (uon->syncdaemon)
1051 g_object_unref (uon->syncdaemon);
1052
1053
1054=== modified file 'nautilus/ubuntuone-nautilus.h'
1055--- nautilus/ubuntuone-nautilus.h 2010-08-25 14:00:10 +0000
1056+++ nautilus/ubuntuone-nautilus.h 2010-09-22 11:18:40 +0000
1057@@ -31,8 +31,8 @@
1058 #define UBUNTUONE_TYPE_NAUTILUS (ubuntuone_nautilus_get_type ())
1059 #define UBUNTUONE_NAUTILUS(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), UBUNTUONE_TYPE_NAUTILUS, UbuntuOneNautilus))
1060
1061-/* Magical struct for passing data in callbacks */
1062-typedef struct _CBData CBData;
1063+/* This is used when a change is pending */
1064+#define UPDATE_PENDING "pending"
1065
1066 typedef struct {
1067 GObject parent_slot;
1068@@ -65,33 +65,24 @@
1069
1070 /* List of files that are observed for changes */
1071 GHashTable * observed;
1072-
1073- /* Extra data we need to free on finalization */
1074- CBData * cb_data;
1075 } UbuntuOneNautilus;
1076
1077 typedef struct {
1078 GObjectClass parent_slot;
1079 } UbuntuOneNautilusClass;
1080
1081-struct _CBData {
1082- UbuntuOneNautilus * uon;
1083- gchar * path;
1084- GtkWidget * parent;
1085-
1086- /* Whether to make a file public or private */
1087- gboolean make_public;
1088-};
1089-
1090 GType ubuntuone_nautilus_get_type (void);
1091
1092 /* Utility functions */
1093 gboolean ubuntuone_is_storagefs (UbuntuOneNautilus * uon,
1094 const char * path,
1095 gboolean * is_root);
1096+gboolean ubuntuone_is_location_bar_enabled (void);
1097+
1098 gboolean ubuntuone_nautilus_check_shares_and_public_files (UbuntuOneNautilus *uon,
1099 SyncdaemonFolderInfo *folder_info,
1100 GtkWidget *widget);
1101+void ubuntuone_nautilus_reset_emblem (UbuntuOneNautilus * uon, const char * path);
1102
1103 void ubuntuone_show_error_dialog (UbuntuOneNautilus *uon, const gchar *title, const gchar *error_message, ...);
1104
1105
1106=== modified file 'nautilus/utils.c'
1107--- nautilus/utils.c 2010-09-01 17:50:47 +0000
1108+++ nautilus/utils.c 2010-09-22 11:18:40 +0000
1109@@ -20,8 +20,10 @@
1110 */
1111
1112 #include <glib/gi18n.h>
1113+#include <libnautilus-extension/nautilus-file-info.h>
1114 #include <libsyncdaemon/syncdaemon-shares-interface.h>
1115 #include "ubuntuone-nautilus.h"
1116+#include "location-widget.h"
1117
1118 /* this is the wrong place for this, but it'll have to do for now */
1119 gboolean
1120@@ -98,3 +100,40 @@
1121
1122 return result;
1123 }
1124+
1125+gboolean
1126+ubuntuone_is_location_bar_enabled (void)
1127+{
1128+ GConfClient *conf_client;
1129+ GConfValue * show_location_value;
1130+ gboolean show_location;
1131+
1132+ conf_client = gconf_client_get_default ();
1133+ show_location_value = gconf_client_get (conf_client, EXPANDER_SHOWN_KEY, NULL);
1134+ g_object_unref (conf_client);
1135+
1136+ if (show_location_value == NULL)
1137+ show_location = TRUE;
1138+ else
1139+ show_location = gconf_value_get_bool (show_location_value);
1140+
1141+ gconf_value_free (show_location_value);
1142+
1143+ return show_location;
1144+}
1145+
1146+void
1147+ubuntuone_nautilus_reset_emblem (UbuntuOneNautilus *uon, const char *path)
1148+{
1149+ GHashTableIter iter;
1150+ gchar *key;
1151+ NautilusFileInfo *file;
1152+
1153+ /* Remove emblems from all files in the specified path */
1154+ g_hash_table_iter_init (&iter, uon->observed);
1155+ while (g_hash_table_iter_next (&iter, (gpointer *) &key, (gpointer *) &file)) {
1156+ if (g_str_has_prefix (key, path) || g_strcmp0 (key, path) == 0) {
1157+ nautilus_file_info_invalidate_extension_info (file);
1158+ }
1159+ }
1160+}
1161
1162=== modified file 'po/POTFILES.in'
1163--- po/POTFILES.in 2010-08-25 20:00:32 +0000
1164+++ po/POTFILES.in 2010-09-22 11:18:40 +0000
1165@@ -7,6 +7,7 @@
1166 nautilus/add-contact-dialog.c
1167 nautilus/ubuntuone-nautilus.c
1168 nautilus/contacts-view.c
1169+nautilus/context-menu.c
1170 nautilus/u1-contacts-picker.c
1171 nautilus/location-widget.c
1172 nautilus/share-dialog.c

Subscribers

People subscribed via source and target branches