Merge lp:~rodrigo-moya/ubuntuone-client/nautilus-refactor-1 into lp:ubuntuone-client

Proposed by Rodrigo Moya
Status: Merged
Approved by: Rodrigo Moya
Approved revision: 737
Merged at revision: 732
Proposed branch: lp:~rodrigo-moya/ubuntuone-client/nautilus-refactor-1
Merge into: lp:ubuntuone-client
Diff against target: 1904 lines (+818/-815)
11 files modified
libsyncdaemon/syncdaemon-daemon.c (+76/-11)
libsyncdaemon/syncdaemon-daemon.h (+8/-0)
nautilus/Makefile.am (+2/-0)
nautilus/context-menu.c (+3/-3)
nautilus/file-watcher.c (+358/-0)
nautilus/file-watcher.h (+54/-0)
nautilus/location-widget.c (+3/-3)
nautilus/ubuntuone-nautilus.c (+303/-760)
nautilus/ubuntuone-nautilus.h (+6/-18)
nautilus/utils.c (+4/-20)
po/POTFILES.in (+1/-0)
To merge this branch: bzr merge lp:~rodrigo-moya/ubuntuone-client/nautilus-refactor-1
Reviewer Review Type Date Requested Status
dobey (community) Needs Fixing
Alejandro J. Cura (community) Approve
Natalia Bidart (community) Approve
Review via email: mp+37120@code.launchpad.net

Commit message

Refactor Nautilus plugin to not store status in hash tables, but rather keep a more clever track of status in signals

Description of the change

Refactor Nautilus plugin to not store status in hash tables, but rather keep a more clever track of status in signals.

This is part I of the refactoring, so there are a few issues still, which will be fixed in upcoming branches. Just didn't want to delay this branch any more and make it bigger than what it already is

To post a comment you must log in.
Revision history for this message
dobey (dobey) wrote :

> Refactor Nautilus plugin to not store status in hash tables, but rather keep a more clever track of status in signals.

I'm a bit confused about what this means exactly. Can you explain? It looks like rather than caching, you're making synchronous calls to syncdaemon over dbus whenever a file is queried?

review: Needs Information
Revision history for this message
Rodrigo Moya (rodrigo-moya) wrote :

> > Refactor Nautilus plugin to not store status in hash tables, but rather keep
> a more clever track of status in signals.
>
> I'm a bit confused about what this means exactly. Can you explain? It looks
> like rather than caching, you're making synchronous calls to syncdaemon over
> dbus whenever a file is queried?

the cache is in libsyncdaemon already (except for metadata, which will come in part II)

Revision history for this message
Natalia Bidart (nataliabidart) wrote :

There is some conflict when merging trunk:

Text conflict in libsyncdaemon/syncdaemon-daemon.c
Text conflict in nautilus/ubuntuone-nautilus.c
2 conflicts encountered.

review: Needs Fixing
Revision history for this message
Natalia Bidart (nataliabidart) wrote :

I ran the test though the Python suite won't cover changes in this branch. I performed some manual testing (start synching a folder, stop synching, publish file). No crashes!
The overview of the code looks fine, though I didn't follow it on detail. I still insist we need an automated test suite for all the C code.

review: Approve
Revision history for this message
Alejandro J. Cura (alecu) wrote :

Huge diff! Looks good.

review: Approve
Revision history for this message
dobey (dobey) :
review: Abstain
Revision history for this message
dobey (dobey) wrote :

Just setting to needs fixing since there seems to be a branch rescan issue on lp.

review: Needs Fixing
Revision history for this message
dobey (dobey) :
review: Abstain
Revision history for this message
dobey (dobey) wrote :

Test command "./autogen.sh --enable-debug --with-protocol=/var/cache/tarmac/ubuntuone-storage-protocol/trunk --with-sso=/var/cache/tarmac/ubuntu-sso-client/trunk && make dist && make check" failed.

Revision history for this message
dobey (dobey) wrote :

cc1: warnings being treated as errors
file-watcher.c: In function ‘udf_created_cb’:
file-watcher.c:142: error: unused variable ‘file’
file-watcher.c:141: error: unused variable ‘key’
file-watcher.c:140: error: unused variable ‘iter’
file-watcher.c: In function ‘got_public_files_cb’:
file-watcher.c:218: error: unused variable ‘i’
make[1]: *** [libnautilus_ubuntuone_la-file-watcher.lo] Error 1
make: *** [check-recursive] Error 1

review: Needs Fixing
735. By Rodrigo Moya

Remove unused variables

736. By Rodrigo Moya

Merge from trunk

737. By Rodrigo Moya

Fix after compiling with -Werror

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'libsyncdaemon/syncdaemon-daemon.c'
2--- libsyncdaemon/syncdaemon-daemon.c 2010-10-04 18:47:52 +0000
3+++ libsyncdaemon/syncdaemon-daemon.c 2010-10-08 07:48:50 +0000
4@@ -43,11 +43,11 @@
5
6 struct _SyncdaemonDaemonPrivate {
7 #ifdef HAVE_GDBUS
8- GDBusConnection *bus;
9- GDbusProxy *dbus_proxy;
10+ GDBusConnection *bus;
11+ GDbusProxy *dbus_proxy;
12 #else
13- DBusGConnection *bus;
14- DBusGProxy *dbus_proxy;
15+ DBusGConnection *bus;
16+ DBusGProxy *dbus_proxy;
17 #endif
18
19 /* Interfaces */
20@@ -661,6 +661,71 @@
21 return daemon->priv->auth;
22 }
23
24+/**
25+ * syncdaemon_daemon_is_folder_enabled:
26+ * @daemon: A #SyncdaemonDaemon object
27+ * @path: The folder path to check
28+ * @is_root: Placeholder for returning whether the given path is a U1 root folder
29+ *
30+ * Check whether a given path is a folder enabled for synchronization to U1.
31+ *
32+ * Return value: TRUE if the folder is enabled, FALSE otherwise.
33+ */
34+gboolean
35+syncdaemon_daemon_is_folder_enabled (SyncdaemonDaemon *daemon, const gchar *path, gboolean *is_root)
36+{
37+ const gchar *root;
38+ gboolean managed = FALSE;
39+ gchar *dirpath;
40+ SyncdaemonInterface *interface;
41+
42+ g_return_val_if_fail (SYNCDAEMON_IS_DAEMON (daemon), FALSE);
43+ g_return_val_if_fail (path != NULL, FALSE);
44+
45+ *is_root = FALSE;
46+
47+ /* First check the root folder */
48+ root = syncdaemon_daemon_get_root_dir (daemon);
49+ if (g_strcmp0 (path, root) == 0) {
50+ *is_root = TRUE;
51+ return TRUE;
52+ } else if (g_str_has_prefix (path, root))
53+ return TRUE;
54+
55+ /* Now check the 'Shared With Me' directory */
56+ dirpath = g_build_filename (root, "Shared With Me", NULL);
57+ if (g_strcmp0 (path, dirpath) == 0) {
58+ g_free (dirpath);
59+ return FALSE;
60+ }
61+
62+ /* And finally check UDFs */
63+ interface = syncdaemon_daemon_get_folders_interface (daemon);
64+ if (SYNCDAEMON_IS_FOLDERS_INTERFACE (interface)) {
65+ GSList *udfs, *l;
66+
67+ udfs = syncdaemon_folders_interface_get_folders (SYNCDAEMON_FOLDERS_INTERFACE (interface));
68+ for (l = udfs; l != NULL; l = l->next) {
69+ const gchar *tmp_path;
70+ SyncdaemonFolderInfo *finfo = SYNCDAEMON_FOLDER_INFO (l->data);
71+
72+ tmp_path = syncdaemon_folder_info_get_path (finfo);
73+ if (g_strcmp0 (path, tmp_path) == 0) {
74+ managed = TRUE;
75+ *is_root = TRUE;
76+ break;
77+ } else if (g_str_has_prefix (path, tmp_path)) {
78+ managed = TRUE;
79+ break;
80+ }
81+ }
82+
83+ g_slist_free (udfs);
84+ }
85+
86+ return managed;
87+}
88+
89 typedef SyncdaemonInterface * (* SDINewFunc) (SyncdaemonDaemon * daemon);
90
91 static SyncdaemonInterface *
92@@ -687,7 +752,7 @@
93 g_return_val_if_fail (SYNCDAEMON_IS_DAEMON (daemon), NULL);
94
95 return get_interface (daemon, "/config",
96- (SDINewFunc) syncdaemon_config_interface_new);
97+ (SDINewFunc) syncdaemon_config_interface_new);
98 }
99
100 /**
101@@ -699,7 +764,7 @@
102 g_return_val_if_fail (SYNCDAEMON_IS_DAEMON (daemon), NULL);
103
104 return get_interface (daemon, "/events",
105- (SDINewFunc) syncdaemon_events_interface_new);
106+ (SDINewFunc) syncdaemon_events_interface_new);
107 }
108
109 /**
110@@ -711,7 +776,7 @@
111 g_return_val_if_fail (SYNCDAEMON_IS_DAEMON (daemon), NULL);
112
113 return get_interface (daemon, "/filesystem",
114- (SDINewFunc) syncdaemon_filesystem_interface_new);
115+ (SDINewFunc) syncdaemon_filesystem_interface_new);
116 }
117
118 /**
119@@ -723,7 +788,7 @@
120 g_return_val_if_fail (SYNCDAEMON_IS_DAEMON (daemon), NULL);
121
122 return get_interface (daemon, "/folders",
123- (SDINewFunc) syncdaemon_folders_interface_new);
124+ (SDINewFunc) syncdaemon_folders_interface_new);
125 }
126
127 /**
128@@ -735,7 +800,7 @@
129 g_return_val_if_fail (SYNCDAEMON_IS_DAEMON (daemon), NULL);
130
131 return get_interface (daemon, "/publicfiles",
132- (SDINewFunc) syncdaemon_publicfiles_interface_new);
133+ (SDINewFunc) syncdaemon_publicfiles_interface_new);
134 }
135
136 /**
137@@ -747,7 +812,7 @@
138 g_return_val_if_fail (SYNCDAEMON_IS_DAEMON (daemon), NULL);
139
140 return get_interface (daemon, "/shares",
141- (SDINewFunc) syncdaemon_shares_interface_new);
142+ (SDINewFunc) syncdaemon_shares_interface_new);
143 }
144
145 /**
146@@ -759,5 +824,5 @@
147 g_return_val_if_fail (SYNCDAEMON_IS_DAEMON (daemon), NULL);
148
149 return get_interface (daemon, "/status",
150- (SDINewFunc) syncdaemon_status_interface_new);
151+ (SDINewFunc) syncdaemon_status_interface_new);
152 }
153
154=== modified file 'libsyncdaemon/syncdaemon-daemon.h'
155--- libsyncdaemon/syncdaemon-daemon.h 2010-08-24 22:27:04 +0000
156+++ libsyncdaemon/syncdaemon-daemon.h 2010-10-08 07:48:50 +0000
157@@ -95,6 +95,14 @@
158 gboolean syncdaemon_daemon_has_network (SyncdaemonDaemon *daemon);
159 SyncdaemonAuthentication *syncdaemon_daemon_get_authentication (SyncdaemonDaemon *daemon);
160
161+/* Folders operations */
162+gboolean syncdaemon_daemon_is_folder_enabled (SyncdaemonDaemon *daemon,
163+ const gchar *path,
164+ gboolean *is_root);
165+
166+/*
167+ * Low level DBus interface access
168+ */
169 SyncdaemonInterface *syncdaemon_daemon_get_config_interface (SyncdaemonDaemon *daemon);
170 SyncdaemonInterface *syncdaemon_daemon_get_events_interface (SyncdaemonDaemon *daemon);
171 SyncdaemonInterface *syncdaemon_daemon_get_filesystem_interface (SyncdaemonDaemon *daemon);
172
173=== modified file 'nautilus/Makefile.am'
174--- nautilus/Makefile.am 2010-09-22 10:58:17 +0000
175+++ nautilus/Makefile.am 2010-10-08 07:48:50 +0000
176@@ -27,6 +27,8 @@
177 context-menu.c \
178 context-menu.h \
179 error-dialog.c \
180+ file-watcher.c \
181+ file-watcher.h \
182 location-widget.c \
183 location-widget.h \
184 highlight.c \
185
186=== modified file 'nautilus/context-menu.c'
187--- nautilus/context-menu.c 2010-10-04 18:47:52 +0000
188+++ nautilus/context-menu.c 2010-10-08 07:48:50 +0000
189@@ -87,7 +87,7 @@
190 folder_info = syncdaemon_folders_interface_get_info (SYNCDAEMON_FOLDERS_INTERFACE (interface),
191 data->path);
192 if (folder_info != NULL) {
193- if (ubuntuone_nautilus_check_shares_and_public_files (data->uon, folder_info, data->parent)) {
194+ if (ubuntuone_check_shares_and_public_files (data->uon, folder_info, data->parent)) {
195 syncdaemon_folders_interface_delete (SYNCDAEMON_FOLDERS_INTERFACE (interface),
196 syncdaemon_folder_info_get_volume_id (folder_info));
197 }
198@@ -139,7 +139,7 @@
199 }
200
201 g_hash_table_replace (data->uon->public, g_strdup (data->path), UPDATE_PENDING);
202- ubuntuone_nautilus_reset_emblem (data->uon, data->path);
203+ file_watcher_update_path (data->uon->file_watcher, data->path);
204 }
205
206 static void
207@@ -200,7 +200,7 @@
208 if (path == NULL)
209 return NULL;
210
211- if (ubuntuone_is_storagefs (uon, path, &is_root))
212+ if (syncdaemon_daemon_is_folder_enabled (uon->syncdaemon, path, &is_root))
213 is_managed = TRUE;
214
215 homedir_path = g_strdup_printf ("%s/", g_get_home_dir());
216
217=== added file 'nautilus/file-watcher.c'
218--- nautilus/file-watcher.c 1970-01-01 00:00:00 +0000
219+++ nautilus/file-watcher.c 2010-10-08 07:48:50 +0000
220@@ -0,0 +1,358 @@
221+/*
222+ * UbuntuOne Nautilus plugin
223+ *
224+ * Authors: Rodrigo Moya <rodrigo.moya@canonical.com>
225+ *
226+ * Copyright 2009-2010 Canonical Ltd.
227+ *
228+ * This program is free software: you can redistribute it and/or modify it
229+ * under the terms of the GNU General Public License version 3, as published
230+ * by the Free Software Foundation.
231+ *
232+ * This program is distributed in the hope that it will be useful, but
233+ * WITHOUT ANY WARRANTY; without even the implied warranties of
234+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
235+ * PURPOSE. See the GNU General Public License for more details.
236+ *
237+ * You should have received a copy of the GNU General Public License along
238+ * with this program. If not, see <http://www.gnu.org/licenses/>.
239+ *
240+ */
241+
242+#ifdef HAVE_CONFIG_H
243+#include <config.h>
244+#endif
245+
246+#include <glib/gi18n-lib.h>
247+#include <libsyncdaemon/libsyncdaemon.h>
248+#include "ubuntuone-nautilus.h"
249+
250+G_DEFINE_TYPE(FileWatcher, file_watcher, G_TYPE_OBJECT)
251+
252+static void
253+file_watcher_finalize (GObject *object)
254+{
255+ FileWatcher *watcher = FILE_WATCHER (object);
256+
257+ if (watcher->files != NULL)
258+ g_hash_table_destroy (watcher->files);
259+
260+ G_OBJECT_CLASS (file_watcher_parent_class)->finalize (object);
261+}
262+
263+static void
264+file_watcher_class_init (FileWatcherClass *klass)
265+{
266+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
267+
268+ object_class->finalize = file_watcher_finalize;
269+}
270+
271+static void
272+file_watcher_init (FileWatcher *watcher)
273+{
274+ watcher->uon = NULL;
275+ watcher->files = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
276+}
277+
278+static void
279+transfer_started_cb (SyncdaemonDaemon *daemon,
280+ gchar *path,
281+ gpointer user_data)
282+{
283+ FileWatcher *watcher = FILE_WATCHER (user_data);
284+
285+ file_watcher_update_path (watcher, path);
286+}
287+
288+static void
289+transfer_finished_cb (SyncdaemonDaemon *daemon,
290+ gchar *path,
291+ SyncdaemonTransferInfo * info,
292+ gpointer user_data)
293+{
294+ FileWatcher *watcher = FILE_WATCHER (user_data);
295+
296+ file_watcher_update_path (watcher, path);
297+}
298+
299+static void
300+share_created_cb (SyncdaemonDaemon *daemon,
301+ gboolean success,
302+ SyncdaemonShareInfo *share_info,
303+ gpointer user_data)
304+{
305+ FileWatcher *watcher = FILE_WATCHER (user_data);
306+ const gchar * path;
307+
308+ path = syncdaemon_share_info_get_path (share_info);
309+ if (success) {
310+ const gchar * id;
311+
312+ id = syncdaemon_share_info_get_volume_id (share_info);
313+ if (!g_hash_table_lookup (watcher->uon->shares, path)) {
314+ g_hash_table_insert (watcher->uon->shares, g_strdup (path), g_strdup (id));
315+ file_watcher_update_path (watcher, path);
316+ }
317+ } else {
318+ ubuntuone_show_error_dialog (watcher->uon, _("Error creating share."),
319+ _("There was an error sharing the folder '%s'"),
320+ path);
321+ }
322+}
323+
324+static void
325+share_deleted_cb (SyncdaemonDaemon *daemon,
326+ gboolean success,
327+ SyncdaemonShareInfo *share_info,
328+ gpointer user_data)
329+{
330+ FileWatcher *watcher = FILE_WATCHER (user_data);
331+ const gchar *path;
332+
333+ path = syncdaemon_share_info_get_path (share_info);
334+ if (success) {
335+ g_hash_table_remove (watcher->uon->shares, path);
336+ file_watcher_update_path (watcher, path);
337+ } else {
338+ ubuntuone_show_error_dialog (watcher->uon, _("Error deleting share."),
339+ _("There was an error deleting the share for folder '%s'"),
340+ path);
341+ }
342+}
343+
344+static void
345+udf_created_cb (SyncdaemonDaemon *daemon,
346+ gboolean success,
347+ SyncdaemonFolderInfo *folder_info,
348+ gpointer user_data)
349+{
350+ FileWatcher *watcher = FILE_WATCHER (user_data);
351+ const gchar *path, *id;
352+ gboolean subscribed;
353+
354+ path = syncdaemon_folder_info_get_path (folder_info);
355+ id = syncdaemon_folder_info_get_volume_id (folder_info);
356+ subscribed = syncdaemon_folder_info_get_subscribed (folder_info);
357+ if (success) {
358+ if (!g_hash_table_lookup (watcher->uon->udfs, path)) {
359+ if (subscribed) {
360+ g_hash_table_insert (watcher->uon->udfs, g_strdup (path), g_strdup (id));
361+
362+ /* Update the emblems of the files on this new UDF */
363+ file_watcher_update_path (watcher, path);
364+ }
365+ }
366+ }
367+}
368+
369+static void
370+udf_deleted_cb (SyncdaemonDaemon *daemon,
371+ gboolean success,
372+ SyncdaemonFolderInfo *folder_info,
373+ gpointer user_data)
374+{
375+ FileWatcher *watcher = FILE_WATCHER (user_data);
376+ const gchar * path;
377+
378+ path = syncdaemon_folder_info_get_path (folder_info);
379+ if (path != NULL && success) {
380+ /* Remove the files from the status hash table */
381+ g_hash_table_remove (watcher->uon->udfs, path);
382+
383+ file_watcher_update_path (watcher, path);
384+ }
385+}
386+
387+static void
388+file_published_cb (SyncdaemonDaemon *daemon,
389+ gboolean success,
390+ SyncdaemonFileInfo *finfo,
391+ gpointer user_data)
392+{
393+ FileWatcher *watcher = FILE_WATCHER (user_data);
394+ const gchar * path, * url;
395+ gboolean is_public;
396+
397+ path = syncdaemon_file_info_get_path (finfo);
398+ if (success) {
399+ url = syncdaemon_file_info_get_public_url (finfo);
400+ is_public = syncdaemon_file_info_get_is_public (finfo);
401+
402+ if (!is_public && g_hash_table_lookup (watcher->uon->public, path))
403+ g_hash_table_remove (watcher->uon->public, path);
404+
405+ if (is_public)
406+ g_hash_table_replace (watcher->uon->public, g_strdup (path), g_strdup (url));
407+
408+ file_watcher_update_path (watcher, path);
409+ watcher->uon->gotpubs = TRUE;
410+ } else {
411+ ubuntuone_show_error_dialog (watcher->uon, _("Error publishing file."),
412+ _("There was an error publishing file '%s'"),
413+ path);
414+ }
415+}
416+
417+static void
418+got_public_files_cb (SyncdaemonDaemon *daemon,
419+ gboolean success,
420+ GSList *files,
421+ gpointer user_data)
422+{
423+ FileWatcher *watcher = FILE_WATCHER (user_data);
424+
425+ if (success) {
426+ GSList *l;
427+
428+ g_hash_table_remove_all (watcher->uon->public);
429+ for (l = files; l != NULL; l = l->next) {
430+ const gchar *path;
431+ SyncdaemonFileInfo *finfo = SYNCDAEMON_FILE_INFO (l->data);
432+
433+ path = syncdaemon_file_info_get_path (finfo);
434+ g_hash_table_insert (watcher->uon->public,
435+ g_strdup (path),
436+ g_strdup (syncdaemon_file_info_get_public_url (finfo)));
437+
438+ file_watcher_update_path (watcher, path);
439+ }
440+ } else {
441+ ubuntuone_show_error_dialog (watcher->uon, _("Error getting public files"),
442+ _("There was an error getting the list of public files"));
443+ }
444+}
445+
446+FileWatcher *
447+file_watcher_new (UbuntuOneNautilus *uon)
448+{
449+ FileWatcher *watcher;
450+
451+ watcher = g_object_new (TYPE_FILE_WATCHER, NULL);
452+ watcher->uon = uon;
453+
454+ /* Connect to transfers-related signals */
455+ g_signal_connect (G_OBJECT (uon->syncdaemon), "upload_started",
456+ G_CALLBACK (transfer_started_cb), watcher);
457+ g_signal_connect (G_OBJECT (uon->syncdaemon), "upload_finished",
458+ G_CALLBACK (transfer_finished_cb), watcher);
459+ g_signal_connect (G_OBJECT (uon->syncdaemon), "download_started",
460+ G_CALLBACK (transfer_started_cb), watcher);
461+ g_signal_connect (G_OBJECT (uon->syncdaemon), "download_finished",
462+ G_CALLBACK (transfer_finished_cb), watcher);
463+
464+ /* Connect to shares-related signals */
465+ g_signal_connect (G_OBJECT (uon->syncdaemon), "share_created",
466+ G_CALLBACK (share_created_cb), watcher);
467+ g_signal_connect (G_OBJECT (uon->syncdaemon), "share_deleted",
468+ G_CALLBACK (share_deleted_cb), watcher);
469+
470+ /* Connect to folder-related signals */
471+ g_signal_connect (G_OBJECT (uon->syncdaemon), "folder_created",
472+ G_CALLBACK (udf_created_cb), watcher);
473+ g_signal_connect (G_OBJECT (uon->syncdaemon), "folder_subscribed",
474+ G_CALLBACK (udf_created_cb), watcher);
475+ g_signal_connect (G_OBJECT (uon->syncdaemon), "folder_deleted",
476+ G_CALLBACK (udf_deleted_cb), watcher);
477+ g_signal_connect (G_OBJECT (uon->syncdaemon), "folder_unsubscribed",
478+ G_CALLBACK (udf_deleted_cb), watcher);
479+
480+ /* Connect to public files-related signals */
481+ g_signal_connect (G_OBJECT (uon->syncdaemon), "file_published",
482+ G_CALLBACK (file_published_cb), watcher);
483+ g_signal_connect (G_OBJECT (uon->syncdaemon), "got_published_files",
484+ G_CALLBACK (got_public_files_cb), watcher);
485+
486+ return watcher;
487+}
488+
489+static gboolean
490+check_for_shared_folder (const gchar *path, GSList *list_of_shares)
491+{
492+ GSList *l;
493+ gboolean is_shared = FALSE;
494+
495+ for (l = list_of_shares; l != NULL; l = l->next) {
496+ SyncdaemonShareInfo *share_info = SYNCDAEMON_SHARE_INFO (l->data);
497+
498+ if (g_strcmp0 (syncdaemon_share_info_get_path (share_info), path) == 0) {
499+ is_shared = TRUE;
500+ break;
501+ }
502+ }
503+
504+ g_slist_free (list_of_shares);
505+
506+ return is_shared;
507+}
508+
509+void
510+file_watcher_add_file (FileWatcher *watcher, NautilusFileInfo *file)
511+{
512+ gboolean is_root;
513+ gchar *path = NULL;
514+
515+ g_return_if_fail (IS_FILE_WATCHER (watcher));
516+
517+ path = g_filename_from_uri (nautilus_file_info_get_uri (file), NULL, NULL);
518+ if (path == NULL)
519+ return;
520+
521+ /* Always add it to the observed hash table, so that we can update emblems */
522+ g_hash_table_insert (watcher->files, path, g_object_ref (file));
523+
524+ /* Retrieve metadata */
525+ if (syncdaemon_daemon_is_folder_enabled (watcher->uon->syncdaemon, path, &is_root)) {
526+ SyncdaemonInterface *interface;
527+
528+ interface = syncdaemon_daemon_get_filesystem_interface (watcher->uon->syncdaemon);
529+ if (interface != NULL) {
530+ SyncdaemonMetadata *metadata;
531+ gboolean is_dir = nautilus_file_info_is_directory (file);
532+
533+ metadata = syncdaemon_filesystem_interface_get_metadata (
534+ SYNCDAEMON_FILESYSTEM_INTERFACE (interface), path, is_dir);
535+
536+ if (syncdaemon_metadata_get_is_synced (metadata))
537+ nautilus_file_info_add_emblem (file, "ubuntuone-synchronized");
538+ else
539+ nautilus_file_info_add_emblem (file, "ubuntuone-updating");
540+
541+ if (is_dir) {
542+ /* If it's a directory, check shares */
543+ interface = syncdaemon_daemon_get_shares_interface (watcher->uon->syncdaemon);
544+ if (check_for_shared_folder ((const gchar *) path,
545+ syncdaemon_shares_interface_get_shared (SYNCDAEMON_SHARES_INTERFACE (interface))) ||
546+ check_for_shared_folder ((const gchar *) path,
547+ syncdaemon_shares_interface_get_shares (SYNCDAEMON_SHARES_INTERFACE (interface)))) {
548+ nautilus_file_info_add_emblem (file, "shared");
549+ }
550+ } else {
551+ /* If it's a file, check for public files */
552+ }
553+
554+ /* Free memory */
555+ g_object_unref (G_OBJECT (metadata));
556+ }
557+ }
558+
559+ /* if (g_hash_table_lookup (watcher->uon->public, path)) */
560+ /* nautilus_file_info_add_emblem (file, "ubuntuone-public"); */
561+}
562+
563+void
564+file_watcher_update_path (FileWatcher *watcher, const gchar *path)
565+{
566+ GHashTableIter iter;
567+ gchar *key;
568+ NautilusFileInfo *file;
569+
570+ g_return_if_fail (IS_FILE_WATCHER (watcher));
571+
572+ /* Remove emblems from all files in the specified path */
573+ g_hash_table_iter_init (&iter, watcher->files);
574+ while (g_hash_table_iter_next (&iter, (gpointer *) &key, (gpointer *) &file)) {
575+ if (g_str_has_prefix (key, path) || g_strcmp0 (key, path) == 0)
576+ nautilus_file_info_invalidate_extension_info (file);
577+ }
578+}
579
580=== added file 'nautilus/file-watcher.h'
581--- nautilus/file-watcher.h 1970-01-01 00:00:00 +0000
582+++ nautilus/file-watcher.h 2010-10-08 07:48:50 +0000
583@@ -0,0 +1,54 @@
584+/*
585+ * UbuntuOne Nautilus plugin
586+ *
587+ * Authors: Rodrigo Moya <rodrigo.moya@canonical.com>
588+ *
589+ * Copyright 2009-2010 Canonical Ltd.
590+ *
591+ * This program is free software: you can redistribute it and/or modify it
592+ * under the terms of the GNU General Public License version 3, as published
593+ * by the Free Software Foundation.
594+ *
595+ * This program is distributed in the hope that it will be useful, but
596+ * WITHOUT ANY WARRANTY; without even the implied warranties of
597+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
598+ * PURPOSE. See the GNU General Public License for more details.
599+ *
600+ * You should have received a copy of the GNU General Public License along
601+ * with this program. If not, see <http://www.gnu.org/licenses/>.
602+ *
603+ */
604+
605+#ifndef __FILE_WATCHER_H__
606+#define __FILE_WATCHER_H__
607+
608+#include <libnautilus-extension/nautilus-file-info.h>
609+
610+#define TYPE_FILE_WATCHER (file_watcher_get_type ())
611+#define FILE_WATCHER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_FILE_WATCHER, FileWatcher))
612+#define IS_FILE_WATCHER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_FILE_WATCHER))
613+#define FILE_WATCHER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_FILE_WATCHER, FileWatcherClass))
614+#define IS_FILE_WATCHER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_FILE_WATCHER))
615+#define FILE_WATCHER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_FILE_WATCHER, FileWatcherClass))
616+
617+typedef struct _UbuntuOneNautilus UbuntuOneNautilus;
618+
619+typedef struct {
620+ GObject parent;
621+
622+ /* Private data */
623+ UbuntuOneNautilus *uon;
624+ GHashTable *files;
625+} FileWatcher;
626+
627+typedef struct {
628+ GObjectClass parent_class;
629+} FileWatcherClass;
630+
631+GType file_watcher_get_type (void);
632+
633+FileWatcher *file_watcher_new (UbuntuOneNautilus *uon);
634+void file_watcher_add_file (FileWatcher *watcher, NautilusFileInfo *file);
635+void file_watcher_update_path (FileWatcher *watcher, const gchar *path);
636+
637+#endif
638
639=== modified file 'nautilus/location-widget.c'
640--- nautilus/location-widget.c 2010-10-04 18:47:52 +0000
641+++ nautilus/location-widget.c 2010-10-08 07:48:50 +0000
642@@ -137,7 +137,7 @@
643 SYNCDAEMON_FOLDERS_INTERFACE (interface),
644 location->path);
645 if (folder_info != NULL) {
646- if (ubuntuone_nautilus_check_shares_and_public_files (location->uon, folder_info, GTK_WIDGET (location))) {
647+ if (ubuntuone_check_shares_and_public_files (location->uon, folder_info, GTK_WIDGET (location))) {
648 start_spinner (location);
649
650 syncdaemon_folders_interface_delete (
651@@ -365,7 +365,7 @@
652 }
653 if (!is_xdg) {
654 /* last chance */
655- ubuntuone_is_storagefs (uon, path, &is_root);
656+ syncdaemon_daemon_is_folder_enabled (uon->syncdaemon, path, &is_root);
657 if (!is_root || is_special_udf (uon, path))
658 return NULL;
659 }
660@@ -380,7 +380,7 @@
661 g_signal_connect (G_OBJECT (uon->syncdaemon), "folder_deleted",
662 G_CALLBACK (folder_deleted_cb), location);
663
664- if (ubuntuone_is_storagefs (uon, path, &is_root)) {
665+ if (syncdaemon_daemon_is_folder_enabled (uon->syncdaemon, path, &is_root)) {
666 /* Create label and disable button */
667 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (location->toggle_button), TRUE);
668 if (!is_root || is_special_udf (uon, path))
669
670=== modified file 'nautilus/ubuntuone-nautilus.c'
671--- nautilus/ubuntuone-nautilus.c 2010-10-04 18:47:52 +0000
672+++ nautilus/ubuntuone-nautilus.c 2010-10-08 07:48:50 +0000
673@@ -49,283 +49,74 @@
674 /* The header is generated from ubuntuone-marshallers.list */
675 #include "ubuntuone-marshallers.h"
676
677-static void ubuntuone_nautilus_finalize(GObject * object);
678-
679-static void ubuntuone_nautilus_register_type (GTypeModule * module);
680-
681-/* Utility functions */
682-static void ubuntuone_nautilus_observed_file_unref (gpointer user_data,
683- GObject *where_the_object_was);
684-
685-static void ubuntuone_nautilus_observed_file_foreach_unref (gpointer key,
686- gpointer value,
687- gpointer user_data);
688+static void ubuntuone_nautilus_finalize (GObject *object);
689+
690+static void ubuntuone_nautilus_register_type (GTypeModule *module);
691
692 /* DBus signal and async method call handlers */
693-static void ubuntuone_nautilus_update_meta (SyncdaemonFilesystemInterface *interface,
694- gboolean success,
695- SyncdaemonMetadata *metadata,
696- gpointer user_data);
697 static void ubuntuone_nautilus_daemon_ready (SyncdaemonDaemon *daemon, gpointer user_data);
698-static void ubuntuone_nautilus_upload_started (SyncdaemonDaemon *daemon,
699- gchar * path,
700- gpointer user_data);
701-static void ubuntuone_nautilus_upload_finished (SyncdaemonDaemon *daemon,
702- gchar * path,
703- SyncdaemonTransferInfo * info,
704- gpointer user_data);
705-static void ubuntuone_nautilus_download_started (SyncdaemonDaemon *daemon,
706- gchar * path,
707- gpointer user_data);
708-static void ubuntuone_nautilus_download_finished (SyncdaemonDaemon *daemon,
709- gchar * path,
710- SyncdaemonTransferInfo * info,
711- gpointer user_data);
712-static void ubuntuone_nautilus_udf_created (SyncdaemonDaemon *daemon,
713- gboolean success,
714- SyncdaemonFolderInfo *folder_info,
715- gpointer user_data);
716-static void ubuntuone_nautilus_udf_deleted (SyncdaemonDaemon *daemon,
717- gboolean success,
718- SyncdaemonFolderInfo *folder_info,
719- gpointer user_data);
720-static void ubuntuone_nautilus_file_published (SyncdaemonDaemon *daemon,
721- gboolean success,
722- SyncdaemonFileInfo *finfo,
723- gpointer user_data);
724-static void ubuntuone_nautilus_got_public_files (SyncdaemonDaemon *daemon,
725- gboolean success,
726- GSList *files,
727- gpointer user_data);
728-static void ubuntuone_nautilus_share_created (SyncdaemonDaemon *daemon,
729- gboolean success,
730- SyncdaemonShareInfo *share_info,
731- gpointer user_data);
732-static void ubuntuone_nautilus_share_deleted (SyncdaemonDaemon *daemon,
733- gboolean success,
734- SyncdaemonShareInfo *share_info,
735- gpointer user_data);
736-
737-
738-static GObjectClass * parent_class = NULL;
739-
740-/* Called when NautilusFileInfo is unreferenced */
741-static void ubuntuone_nautilus_observed_file_unref (gpointer user_data,
742- GObject *where_the_object_was) {
743- UbuntuOneNautilus * uon;
744- NautilusFileInfo * file;
745- gchar * path = NULL;
746-
747- uon = UBUNTUONE_NAUTILUS(user_data);
748- file = NAUTILUS_FILE_INFO(where_the_object_was);
749- path = g_filename_from_uri (nautilus_file_info_get_uri (file), NULL, NULL);
750-
751- if (g_hash_table_lookup (uon->observed, path ))
752- g_hash_table_remove (uon->observed, path);
753-
754-}
755-
756-/* Cleanup routine for weak reference callbacks */
757-static void ubuntuone_nautilus_observed_file_foreach_unref (gpointer key,
758- gpointer value,
759- gpointer user_data) {
760- UbuntuOneNautilus * uon;
761- NautilusFileInfo * file;
762-
763- uon = UBUNTUONE_NAUTILUS(user_data);
764- file = NAUTILUS_FILE_INFO(value);
765-
766- g_object_weak_unref (G_OBJECT (file),
767- (GWeakNotify) ubuntuone_nautilus_observed_file_unref,
768- uon);
769-
770-}
771-
772-/* Are we in an Ubuntu One managed (root or udf) directory */
773-gboolean ubuntuone_is_storagefs (UbuntuOneNautilus * uon,
774- const char * path,
775- gboolean * is_root) {
776- gboolean managed = FALSE;
777- gchar * dirpath;
778- gchar * shared;
779- GSList * udfs, * l;
780- SyncdaemonFoldersInterface *interface;
781-
782- *is_root = FALSE;
783-
784- if (!uon->managed)
785- return FALSE;
786-
787- if (!path)
788- return FALSE;
789-
790- /* Check the Ubuntu One directory */
791- if (strcmp (path, uon->managed) == 0) {
792- *is_root = TRUE;
793- return TRUE;
794- }
795-
796- shared = g_build_filename (uon->managed, "Shared With Me", NULL);
797- if (strncmp (path, shared, strlen (shared)) == 0) {
798- managed = FALSE;
799- goto fsdone;
800- }
801-
802- dirpath = g_strdup_printf ("%s/", uon->managed);
803- if (strncmp (path, dirpath, strlen (dirpath)) == 0) {
804- managed = TRUE;
805- goto fsdone;
806- }
807-
808- g_free (dirpath);
809-
810- /* Check for UDFs */
811- interface = SYNCDAEMON_FOLDERS_INTERFACE (syncdaemon_daemon_get_folders_interface (uon->syncdaemon));
812- if (interface != NULL) {
813- udfs = syncdaemon_folders_interface_get_folders (SYNCDAEMON_FOLDERS_INTERFACE (interface));
814- for (l = udfs; l != NULL && l->data != NULL; l = l->next) {
815- const char *tmp_path;
816-
817- tmp_path = syncdaemon_folder_info_get_path (SYNCDAEMON_FOLDER_INFO (l->data));
818- if (!tmp_path)
819- continue;
820-
821- if (strcmp (path, tmp_path) == 0) {
822- managed = TRUE;
823- *is_root = TRUE;
824- break;
825- }
826-
827- dirpath = g_strdup_printf ("%s/", (char *) tmp_path);
828- if (strncmp (path, dirpath, strlen (dirpath)) == 0) {
829- managed = TRUE;
830- g_free (dirpath);
831- break;
832- }
833-
834- g_free (dirpath);
835- }
836- g_slist_free (udfs);
837- }
838-
839- fsdone:
840- g_free (shared);
841- return managed;
842-}
843-
844-static void
845-ubuntuone_nautilus_add_observed (UbuntuOneNautilus * uon,
846- gchar * path,
847- NautilusFileInfo * file)
848-{
849- g_object_weak_ref (G_OBJECT(file),
850- (GWeakNotify) ubuntuone_nautilus_observed_file_unref,
851- uon);
852- g_hash_table_insert (uon->observed, g_strdup (path), file);
853-}
854+
855+static GObjectClass *parent_class = NULL;
856
857 /* Update file info provider */
858 static NautilusOperationResult
859-ubuntuone_nautilus_update_file_info (NautilusInfoProvider * provider,
860- NautilusFileInfo * file,
861- GClosure * update_complete,
862- NautilusOperationHandle ** handle)
863+ubuntuone_nautilus_update_file_info (NautilusInfoProvider *provider,
864+ NautilusFileInfo *file,
865+ GClosure *update_complete,
866+ NautilusOperationHandle **handle)
867 {
868- UbuntuOneNautilus * uon;
869- gboolean is_root;
870- char * path = NULL;
871-
872- uon = UBUNTUONE_NAUTILUS(provider);
873-
874- /* If syncdaemon is not ready, do nothing */
875- if (!syncdaemon_daemon_is_ready (uon->syncdaemon))
876- return NAUTILUS_OPERATION_COMPLETE;
877-
878- path = g_filename_from_uri (nautilus_file_info_get_uri (file), NULL, NULL);
879- if (path == NULL)
880- return NAUTILUS_OPERATION_COMPLETE;
881-
882- /* Always add it to the observed hash table, so that we can update emblems */
883- ubuntuone_nautilus_add_observed (uon, path, file);
884-
885- if (!g_hash_table_lookup (uon->updated, path) &&
886- !g_hash_table_lookup (uon->needsupdating, path) &&
887- ubuntuone_is_storagefs (uon, path, &is_root)) {
888- SyncdaemonFilesystemInterface *interface;
889-
890- /* Add the unsynchronized emblem anyway, and update later */
891- nautilus_file_info_add_emblem (file, "ubuntuone-updating");
892-
893- interface = (SyncdaemonFilesystemInterface *) syncdaemon_daemon_get_filesystem_interface (uon->syncdaemon);
894- if (interface != NULL) {
895- syncdaemon_filesystem_interface_get_metadata_async (interface,
896- path,
897- nautilus_file_info_is_directory (file),
898- (SyncdaemonGotMetadataFunc) ubuntuone_nautilus_update_meta,
899- uon);
900- goto updating_meta;
901- }
902- }
903-
904- if (g_hash_table_lookup (uon->uploads, path) ||
905- g_hash_table_lookup (uon->downloads, path))
906- nautilus_file_info_add_emblem (file, "ubuntuone-updating");
907- else if (g_hash_table_lookup (uon->updated, path))
908- nautilus_file_info_add_emblem (file, "ubuntuone-synchronized");
909- else if (g_hash_table_lookup (uon->needsupdating, path))
910- nautilus_file_info_add_emblem (file, "ubuntuone-updating");
911-
912- if (g_hash_table_lookup (uon->udfs, path))
913- nautilus_file_info_add_emblem (file, "ubuntuone-enabled");
914-
915- if (g_hash_table_lookup (uon->public, path))
916- nautilus_file_info_add_emblem (file, "ubuntuone-public");
917-
918- if (g_hash_table_lookup (uon->shares, path))
919- nautilus_file_info_add_emblem (file, "shared");
920-
921- updating_meta:
922- g_free (path);
923-
924- return NAUTILUS_OPERATION_COMPLETE;
925+ UbuntuOneNautilus *uon = UBUNTUONE_NAUTILUS (provider);
926+
927+ /* If syncdaemon is not ready, do nothing */
928+ if (!syncdaemon_daemon_is_ready (uon->syncdaemon))
929+ return NAUTILUS_OPERATION_COMPLETE;
930+
931+ file_watcher_add_file (uon->file_watcher, file);
932+
933+ return NAUTILUS_OPERATION_COMPLETE;
934 }
935
936-static void ubuntuone_nautilus_info_provider_iface_init (NautilusInfoProviderIface * iface) {
937- iface->update_file_info = ubuntuone_nautilus_update_file_info;
938+static void
939+ubuntuone_nautilus_info_provider_iface_init (NautilusInfoProviderIface * iface)
940+{
941+ iface->update_file_info = ubuntuone_nautilus_update_file_info;
942 }
943
944 /* LocationWidget provider */
945-static GtkWidget * ubuntuone_nautilus_get_location_widget (NautilusLocationWidgetProvider * provider,
946- const char * uri,
947- GtkWidget * parent) {
948- UbuntuOneNautilus * uon;
949- gchar *path;
950- GtkWidget *location;
951-
952- /* if the bar is disabled, do nothing */
953- if (!ubuntuone_is_location_bar_enabled ())
954- return NULL;
955-
956- uon = UBUNTUONE_NAUTILUS (provider);
957-
958- /* If syncdaemon is not ready, do nothing */
959- if (!syncdaemon_daemon_is_ready (uon->syncdaemon))
960- return NULL;
961-
962- path = g_filename_from_uri (uri, NULL, NULL);
963-
964- if (!path)
965- return NULL;
966-
967- location = location_widget_new (uon, path);
968-
969- g_free (path);
970-
971- return location;
972+static GtkWidget *
973+ubuntuone_nautilus_get_location_widget (NautilusLocationWidgetProvider * provider,
974+ const char * uri,
975+ GtkWidget * parent)
976+{
977+ UbuntuOneNautilus * uon;
978+ gchar *path;
979+ GtkWidget *location;
980+
981+ /* if the bar is disabled, do nothing */
982+ if (!ubuntuone_is_location_bar_enabled ())
983+ return NULL;
984+
985+ uon = UBUNTUONE_NAUTILUS (provider);
986+
987+ /* If syncdaemon is not ready, do nothing */
988+ if (!syncdaemon_daemon_is_ready (uon->syncdaemon))
989+ return NULL;
990+
991+ path = g_filename_from_uri (uri, NULL, NULL);
992+ if (!path)
993+ return NULL;
994+
995+ location = location_widget_new (uon, path);
996+
997+ g_free (path);
998+
999+ return location;
1000 }
1001
1002-static void ubuntuone_nautilus_bar_provider_iface_init (NautilusLocationWidgetProviderIface * iface) {
1003- iface->get_widget = ubuntuone_nautilus_get_location_widget;
1004+static void
1005+ubuntuone_nautilus_bar_provider_iface_init (NautilusLocationWidgetProviderIface * iface)
1006+{
1007+ iface->get_widget = ubuntuone_nautilus_get_location_widget;
1008 }
1009
1010 /* Menu provider */
1011@@ -334,522 +125,274 @@
1012 GtkWidget * window,
1013 GList * files)
1014 {
1015- UbuntuOneNautilus * uon;
1016- GList *items = NULL;
1017- NautilusMenuItem *root_item;
1018-
1019- uon = UBUNTUONE_NAUTILUS (provider);
1020-
1021- /* If syncdaemon is not ready, do nothing */
1022- if (!syncdaemon_daemon_is_ready (uon->syncdaemon))
1023- return NULL;
1024-
1025- root_item = context_menu_new (uon, window, files);
1026- if (root_item != NULL)
1027- items = g_list_append (items, root_item);
1028-
1029- return items;
1030-}
1031-
1032-static GList * ubuntuone_nautilus_get_bg_menu_items (NautilusMenuProvider * provider,
1033- GtkWidget * window,
1034- NautilusFileInfo * folder) {
1035- GList * files = NULL;
1036- GList * items = NULL;
1037-
1038- files = g_list_prepend (files, folder);
1039- items = ubuntuone_nautilus_get_menu_items (provider, window, files);
1040- files = g_list_remove (files, folder);
1041- g_list_free (files);
1042-
1043- return items;
1044-}
1045-
1046-static void ubuntuone_nautilus_menu_provider_iface_init (NautilusMenuProviderIface * iface) {
1047- iface->get_file_items = ubuntuone_nautilus_get_menu_items;
1048- iface->get_background_items = ubuntuone_nautilus_get_bg_menu_items;
1049+ UbuntuOneNautilus * uon;
1050+ GList *items = NULL;
1051+ NautilusMenuItem *root_item;
1052+
1053+ uon = UBUNTUONE_NAUTILUS (provider);
1054+
1055+ /* If syncdaemon is not ready, do nothing */
1056+ if (!syncdaemon_daemon_is_ready (uon->syncdaemon))
1057+ return NULL;
1058+
1059+ root_item = context_menu_new (uon, window, files);
1060+ if (root_item != NULL)
1061+ items = g_list_append (items, root_item);
1062+
1063+ return items;
1064+}
1065+
1066+static GList *
1067+ubuntuone_nautilus_get_bg_menu_items (NautilusMenuProvider * provider,
1068+ GtkWidget * window,
1069+ NautilusFileInfo * folder)
1070+{
1071+ GList * files = NULL;
1072+ GList * items = NULL;
1073+
1074+ files = g_list_prepend (files, folder);
1075+ items = ubuntuone_nautilus_get_menu_items (provider, window, files);
1076+ files = g_list_remove (files, folder);
1077+ g_list_free (files);
1078+
1079+ return items;
1080+}
1081+
1082+static void
1083+ubuntuone_nautilus_menu_provider_iface_init (NautilusMenuProviderIface * iface)
1084+{
1085+ iface->get_file_items = ubuntuone_nautilus_get_menu_items;
1086+ iface->get_background_items = ubuntuone_nautilus_get_bg_menu_items;
1087 }
1088
1089 /* GType and nautilus module stuff */
1090 static GType un_type = 0;
1091
1092-static void ubuntuone_nautilus_instance_init (UbuntuOneNautilus * uon) {
1093- uon->connected = FALSE;
1094- uon->uploads = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
1095- uon->downloads = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
1096- uon->shares = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
1097- uon->updated = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
1098- uon->needsupdating = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
1099- uon->observed = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
1100- uon->udfs = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
1101- uon->public = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
1102-
1103- uon->syncdaemon = syncdaemon_daemon_new ();
1104- g_signal_connect (G_OBJECT (uon->syncdaemon), "ready",
1105- G_CALLBACK (ubuntuone_nautilus_daemon_ready), uon);
1106-
1107- /* Default to ~/Ubuntu One for now, as it's all we really support */
1108- uon->managed = g_build_filename (g_get_home_dir (), "Ubuntu One", NULL);
1109- uon->gotroot = FALSE;
1110- uon->gotudfs = FALSE;
1111- uon->gotpubs = FALSE;
1112-
1113- /* Connec to status-related signals */
1114- g_signal_connect (G_OBJECT (uon->syncdaemon), "upload_started",
1115- G_CALLBACK (ubuntuone_nautilus_upload_started), uon);
1116- g_signal_connect (G_OBJECT (uon->syncdaemon), "upload_finished",
1117- G_CALLBACK (ubuntuone_nautilus_upload_finished), uon);
1118- g_signal_connect (G_OBJECT (uon->syncdaemon), "download_started",
1119- G_CALLBACK (ubuntuone_nautilus_download_started), uon);
1120- g_signal_connect (G_OBJECT (uon->syncdaemon), "download_finished",
1121- G_CALLBACK (ubuntuone_nautilus_download_finished), uon);
1122-
1123- /* Connect to shares-related signals */
1124- g_signal_connect (G_OBJECT (uon->syncdaemon), "share_created",
1125- G_CALLBACK (ubuntuone_nautilus_share_created), uon);
1126- g_signal_connect (G_OBJECT (uon->syncdaemon), "share_deleted",
1127- G_CALLBACK (ubuntuone_nautilus_share_deleted), uon);
1128-
1129- /* Connect to folder-related signals */
1130- g_signal_connect (G_OBJECT (uon->syncdaemon), "folder_created",
1131- G_CALLBACK (ubuntuone_nautilus_udf_created), uon);
1132- g_signal_connect (G_OBJECT (uon->syncdaemon), "folder_subscribed",
1133- G_CALLBACK (ubuntuone_nautilus_udf_created), uon);
1134- g_signal_connect (G_OBJECT (uon->syncdaemon), "folder_deleted",
1135- G_CALLBACK (ubuntuone_nautilus_udf_deleted), uon);
1136- g_signal_connect (G_OBJECT (uon->syncdaemon), "folder_unsubscribed",
1137- G_CALLBACK (ubuntuone_nautilus_udf_deleted), uon);
1138-
1139- /* Connect to public files-related signals */
1140- g_signal_connect (G_OBJECT (uon->syncdaemon), "file_published",
1141- G_CALLBACK (ubuntuone_nautilus_file_published), uon);
1142- g_signal_connect (G_OBJECT (uon->syncdaemon), "got_published_files",
1143- G_CALLBACK (ubuntuone_nautilus_got_public_files), uon);
1144-
1145-}
1146-
1147-static void ubuntuone_nautilus_class_init (UbuntuOneNautilusClass * klass) {
1148- parent_class = g_type_class_peek_parent (klass);
1149-
1150- G_OBJECT_CLASS(klass)->finalize = ubuntuone_nautilus_finalize;
1151-}
1152-
1153-static void ubuntuone_nautilus_finalize(GObject * object) {
1154- UbuntuOneNautilus * uon = UBUNTUONE_NAUTILUS(object);
1155-
1156- if (uon->syncdaemon)
1157- g_object_unref (uon->syncdaemon);
1158-
1159- g_hash_table_destroy (uon->uploads);
1160- uon->uploads = NULL;
1161-
1162- g_hash_table_destroy (uon->downloads);
1163- uon->downloads = NULL;
1164-
1165- g_hash_table_destroy (uon->shares);
1166- uon->shares = NULL;
1167-
1168- g_hash_table_destroy (uon->udfs);
1169- uon->udfs = NULL;
1170-
1171- g_hash_table_destroy (uon->public);
1172- uon->public = NULL;
1173-
1174- g_hash_table_destroy (uon->updated);
1175- uon->updated = NULL;
1176-
1177- g_hash_table_destroy (uon->needsupdating);
1178- uon->needsupdating = NULL;
1179-
1180- /* We need to remove all weak reference callbacks */
1181- g_hash_table_foreach (uon->observed,
1182- (GHFunc)ubuntuone_nautilus_observed_file_foreach_unref,
1183- uon);
1184-
1185- g_hash_table_destroy (uon->observed);
1186- uon->observed = NULL;
1187-}
1188-
1189-GType ubuntuone_nautilus_get_type (void) {
1190- return un_type;
1191-}
1192-
1193-static void ubuntuone_nautilus_register_type (GTypeModule * module) {
1194- static const GTypeInfo info = {
1195- sizeof (UbuntuOneNautilusClass),
1196- (GBaseInitFunc) NULL,
1197- (GBaseFinalizeFunc) NULL,
1198- (GClassInitFunc) ubuntuone_nautilus_class_init,
1199- NULL,
1200- NULL,
1201- sizeof (UbuntuOneNautilus),
1202- 0,
1203- (GInstanceInitFunc) ubuntuone_nautilus_instance_init,
1204- };
1205-
1206- static const GInterfaceInfo info_provider_iface_info = {
1207- (GInterfaceInitFunc) ubuntuone_nautilus_info_provider_iface_init,
1208- NULL,
1209- NULL
1210- };
1211-
1212- static const GInterfaceInfo bar_provider_iface_info = {
1213- (GInterfaceInitFunc) ubuntuone_nautilus_bar_provider_iface_init,
1214- NULL,
1215- NULL
1216- };
1217-
1218- static const GInterfaceInfo menu_provider_iface_info = {
1219- (GInterfaceInitFunc) ubuntuone_nautilus_menu_provider_iface_init,
1220- NULL,
1221- NULL
1222- };
1223-
1224- un_type = g_type_module_register_type (module,
1225- G_TYPE_OBJECT,
1226- "UbuntuOneNautilus",
1227- &info, 0);
1228+static void
1229+ubuntuone_nautilus_instance_init (UbuntuOneNautilus * uon)
1230+{
1231+ uon->connected = FALSE;
1232+ uon->shares = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
1233+ uon->udfs = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
1234+ uon->public = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
1235+
1236+ uon->syncdaemon = syncdaemon_daemon_new ();
1237+ g_signal_connect (G_OBJECT (uon->syncdaemon), "ready",
1238+ G_CALLBACK (ubuntuone_nautilus_daemon_ready), uon);
1239+
1240+ /* Create a FileWatcher object to watch files we know about from Nautilus */
1241+ uon->file_watcher = file_watcher_new (uon);
1242+
1243+ /* Default to ~/Ubuntu One for now, as it's all we really support */
1244+ uon->managed = g_build_filename (g_get_home_dir (), "Ubuntu One", NULL);
1245+ uon->gotroot = FALSE;
1246+ uon->gotudfs = FALSE;
1247+ uon->gotpubs = FALSE;
1248+}
1249+
1250+static void
1251+ubuntuone_nautilus_class_init (UbuntuOneNautilusClass * klass)
1252+{
1253+ parent_class = g_type_class_peek_parent (klass);
1254+
1255+ G_OBJECT_CLASS(klass)->finalize = ubuntuone_nautilus_finalize;
1256+}
1257+
1258+static void
1259+ubuntuone_nautilus_finalize (GObject *object)
1260+{
1261+ UbuntuOneNautilus * uon = UBUNTUONE_NAUTILUS(object);
1262+
1263+ if (uon->file_watcher != NULL)
1264+ g_object_unref (G_OBJECT (uon->file_watcher));
1265+
1266+ if (uon->syncdaemon)
1267+ g_object_unref (uon->syncdaemon);
1268+
1269+ g_hash_table_destroy (uon->shares);
1270+ uon->shares = NULL;
1271+
1272+ g_hash_table_destroy (uon->udfs);
1273+ uon->udfs = NULL;
1274+
1275+ g_hash_table_destroy (uon->public);
1276+ uon->public = NULL;
1277+}
1278+
1279+GType
1280+ubuntuone_nautilus_get_type (void)
1281+{
1282+ return un_type;
1283+}
1284+
1285+static void
1286+ubuntuone_nautilus_register_type (GTypeModule * module)
1287+{
1288+ static const GTypeInfo info = {
1289+ sizeof (UbuntuOneNautilusClass),
1290+ (GBaseInitFunc) NULL,
1291+ (GBaseFinalizeFunc) NULL,
1292+ (GClassInitFunc) ubuntuone_nautilus_class_init,
1293+ NULL,
1294+ NULL,
1295+ sizeof (UbuntuOneNautilus),
1296+ 0,
1297+ (GInstanceInitFunc) ubuntuone_nautilus_instance_init,
1298+ };
1299+
1300+ static const GInterfaceInfo info_provider_iface_info = {
1301+ (GInterfaceInitFunc) ubuntuone_nautilus_info_provider_iface_init,
1302+ NULL,
1303+ NULL
1304+ };
1305+
1306+ static const GInterfaceInfo bar_provider_iface_info = {
1307+ (GInterfaceInitFunc) ubuntuone_nautilus_bar_provider_iface_init,
1308+ NULL,
1309+ NULL
1310+ };
1311+
1312+ static const GInterfaceInfo menu_provider_iface_info = {
1313+ (GInterfaceInitFunc) ubuntuone_nautilus_menu_provider_iface_init,
1314+ NULL,
1315+ NULL
1316+ };
1317+
1318+ un_type = g_type_module_register_type (module,
1319+ G_TYPE_OBJECT,
1320+ "UbuntuOneNautilus",
1321+ &info, 0);
1322
1323- g_type_module_add_interface (module,
1324- un_type,
1325- NAUTILUS_TYPE_INFO_PROVIDER,
1326- &info_provider_iface_info);
1327-
1328- g_type_module_add_interface (module,
1329- un_type,
1330- NAUTILUS_TYPE_LOCATION_WIDGET_PROVIDER,
1331- &bar_provider_iface_info);
1332-
1333- /* XXX Need to sign a request via DBus */
1334- g_type_module_add_interface (module,
1335- un_type,
1336- NAUTILUS_TYPE_MENU_PROVIDER,
1337- &menu_provider_iface_info);
1338+ g_type_module_add_interface (module,
1339+ un_type,
1340+ NAUTILUS_TYPE_INFO_PROVIDER,
1341+ &info_provider_iface_info);
1342+
1343+ g_type_module_add_interface (module,
1344+ un_type,
1345+ NAUTILUS_TYPE_LOCATION_WIDGET_PROVIDER,
1346+ &bar_provider_iface_info);
1347+
1348+ /* XXX Need to sign a request via DBus */
1349+ g_type_module_add_interface (module,
1350+ un_type,
1351+ NAUTILUS_TYPE_MENU_PROVIDER,
1352+ &menu_provider_iface_info);
1353 }
1354
1355
1356 /* DBus signal handlers and async method call handlers */
1357-static void ubuntuone_nautilus_update_meta (SyncdaemonFilesystemInterface *interface,
1358- gboolean success,
1359- SyncdaemonMetadata *metadata,
1360- gpointer user_data) {
1361- UbuntuOneNautilus * uon;
1362- gchar * path;
1363- gboolean is_root;
1364-
1365- if (!success) {
1366- g_warning ("ERROR: Could not retrieve metadata");
1367- return;
1368- }
1369-
1370- uon = UBUNTUONE_NAUTILUS (user_data);
1371- path = g_strdup (syncdaemon_metadata_get_path (metadata));
1372-
1373- if (ubuntuone_is_storagefs (uon, path, &is_root)) {
1374- if (syncdaemon_metadata_get_is_synced (metadata)) {
1375- g_hash_table_replace (uon->updated, path, path);
1376- ubuntuone_nautilus_reset_emblem (uon, path);
1377- } else
1378- g_hash_table_replace (uon->needsupdating, path, path);
1379- } else {
1380- g_hash_table_remove (uon->updated, path);
1381- g_hash_table_remove (uon->needsupdating, path);
1382- ubuntuone_nautilus_reset_emblem (uon, path);
1383-
1384- g_free (path);
1385- }
1386-}
1387-
1388 static void
1389 ubuntuone_nautilus_daemon_ready (SyncdaemonDaemon *daemon, gpointer user_data)
1390 {
1391- UbuntuOneNautilus * uon = UBUNTUONE_NAUTILUS (user_data);
1392- gboolean is_online = FALSE;
1393- SyncdaemonInterface *interface;
1394-
1395- interface = syncdaemon_daemon_get_status_interface (daemon);
1396- if (interface != NULL) {
1397- SyncdaemonStatusInfo *status_info;
1398-
1399- status_info = syncdaemon_status_interface_get_current_status (SYNCDAEMON_STATUS_INTERFACE (interface));
1400- is_online = syncdaemon_status_info_get_online (status_info);
1401- }
1402-
1403- /* Get the root when we get a status change signal, if we haven't yet */
1404- if (!uon->gotroot) {
1405- uon->managed = g_strdup (syncdaemon_daemon_get_root_dir (uon->syncdaemon));
1406- if (uon->managed != NULL)
1407- uon->gotroot = TRUE;
1408- }
1409-
1410- /* Get the list of UDFs if we haven't already */
1411- if (!uon->gotudfs) {
1412- SyncdaemonInterface *interface;
1413-
1414- interface = syncdaemon_daemon_get_folders_interface (uon->syncdaemon);
1415- if (interface != NULL) {
1416- GSList *folders, *l;
1417-
1418- folders = syncdaemon_folders_interface_get_folders (SYNCDAEMON_FOLDERS_INTERFACE (interface));
1419- for (l = folders; l != NULL; l = l->next) {
1420- SyncdaemonFolderInfo *folder_info = SYNCDAEMON_FOLDER_INFO (l->data);
1421-
1422- ubuntuone_nautilus_udf_created (uon->syncdaemon, TRUE, folder_info, uon);
1423- uon->gotudfs = TRUE;
1424- }
1425-
1426- g_slist_free (folders);
1427- }
1428- }
1429-
1430- /* Get the list of shared folders */
1431- interface = syncdaemon_daemon_get_shares_interface (uon->syncdaemon);
1432- if (SYNCDAEMON_IS_SHARES_INTERFACE (interface)) {
1433- GSList *shares;
1434-
1435- shares = syncdaemon_shares_interface_get_shared (SYNCDAEMON_SHARES_INTERFACE (interface));
1436- while (shares != NULL) {
1437- ubuntuone_nautilus_share_created (uon->syncdaemon, TRUE, SYNCDAEMON_SHARE_INFO (shares->data), uon);
1438- shares = g_slist_remove (shares, shares->data);
1439- }
1440- }
1441-
1442- /* Get the list of public files if we haven't already */
1443- if (is_online && !uon->gotpubs) {
1444- SyncdaemonInterface *public;
1445-
1446- public = syncdaemon_daemon_get_publicfiles_interface (uon->syncdaemon);
1447- if (public != NULL) {
1448- syncdaemon_publicfiles_interface_get_public_files (SYNCDAEMON_PUBLICFILES_INTERFACE (public));
1449- uon->gotpubs = TRUE;
1450- }
1451- }
1452-}
1453-
1454-static void ubuntuone_nautilus_upload_started (SyncdaemonDaemon *daemon,
1455- gchar * path,
1456- gpointer user_data) {
1457- UbuntuOneNautilus * uon = UBUNTUONE_NAUTILUS (user_data);
1458-
1459- if (!g_hash_table_lookup (uon->uploads, path)) {
1460- gchar *new_path = g_strdup (path);
1461- g_hash_table_insert (uon->uploads, new_path, new_path);
1462- ubuntuone_nautilus_reset_emblem (uon, path);
1463- }
1464-}
1465-
1466-static void ubuntuone_nautilus_upload_finished (SyncdaemonDaemon *daemon,
1467- gchar * path,
1468- SyncdaemonTransferInfo * info,
1469- gpointer user_data) {
1470- UbuntuOneNautilus * uon = UBUNTUONE_NAUTILUS (user_data);
1471- gchar * new_path;
1472-
1473- g_hash_table_remove (uon->uploads, path);
1474- g_hash_table_remove (uon->needsupdating, path);
1475-
1476- new_path = g_strdup (path);
1477- g_hash_table_replace (uon->updated, new_path, new_path);
1478-
1479- ubuntuone_nautilus_reset_emblem (uon, path);
1480-}
1481-
1482-static void ubuntuone_nautilus_download_started (SyncdaemonDaemon *daemon,
1483- gchar * path,
1484- gpointer user_data) {
1485- UbuntuOneNautilus * uon = UBUNTUONE_NAUTILUS (user_data);
1486-
1487- if (!g_hash_table_lookup (uon->downloads, path)) {
1488- gchar *new_path = g_strdup (path);
1489- g_hash_table_insert (uon->downloads, new_path, new_path);
1490- ubuntuone_nautilus_reset_emblem (uon, path);
1491- }
1492-}
1493-
1494-static void ubuntuone_nautilus_download_finished (SyncdaemonDaemon *daemon,
1495- gchar * path,
1496- SyncdaemonTransferInfo * info,
1497- gpointer user_data) {
1498- UbuntuOneNautilus * uon = UBUNTUONE_NAUTILUS (user_data);
1499- gchar * new_path;
1500-
1501- g_hash_table_remove (uon->downloads, path);
1502- g_hash_table_remove (uon->needsupdating, path);
1503-
1504- new_path = g_strdup (path);
1505- g_hash_table_replace (uon->updated, new_path, new_path);
1506-
1507- ubuntuone_nautilus_reset_emblem (uon, path);
1508-}
1509-
1510-static void ubuntuone_nautilus_udf_created (SyncdaemonDaemon *daemon,
1511- gboolean success,
1512- SyncdaemonFolderInfo *folder_info,
1513- gpointer user_data) {
1514- UbuntuOneNautilus * uon = UBUNTUONE_NAUTILUS (user_data);
1515- const gchar * path, * id;
1516- gboolean subscribed;
1517-
1518- path = syncdaemon_folder_info_get_path (folder_info);
1519- id = syncdaemon_folder_info_get_volume_id (folder_info);
1520- subscribed = syncdaemon_folder_info_get_subscribed (folder_info);
1521- if (success) {
1522- if (!g_hash_table_lookup (uon->udfs, path)) {
1523- if (subscribed) {
1524- GHashTableIter iter;
1525- gchar *key;
1526- NautilusFileInfo *file;
1527-
1528- g_hash_table_insert (uon->udfs, g_strdup (path), g_strdup (id));
1529-
1530- /* Update the emblems of the files on this new UDF */
1531- g_hash_table_iter_init (&iter, uon->observed);
1532- while (g_hash_table_iter_next (&iter, (gpointer *) &key, (gpointer *) &file)) {
1533- if (g_str_has_prefix (key, path))
1534- nautilus_file_info_add_emblem (file, "ubuntuone-updating");
1535- }
1536- }
1537- }
1538- }
1539-}
1540-
1541-static gboolean
1542-remove_by_path_in_hash (gpointer key, gpointer value, gpointer user_data)
1543-{
1544- if (g_str_has_prefix ((const gchar *) key, (const gchar *) user_data) ||
1545- g_strcmp0 ((const gchar *) key, (const gchar *) user_data) == 0)
1546- return TRUE;
1547-
1548- return FALSE;
1549-}
1550-
1551-static void
1552-ubuntuone_nautilus_udf_deleted (SyncdaemonDaemon *daemon,
1553- gboolean success,
1554- SyncdaemonFolderInfo *folder_info,
1555- gpointer user_data)
1556-{
1557- UbuntuOneNautilus * uon = UBUNTUONE_NAUTILUS (user_data);
1558- const gchar * path;
1559-
1560- path = syncdaemon_folder_info_get_path (folder_info);
1561- if (path != NULL && success) {
1562- g_hash_table_remove (uon->udfs, path);
1563- ubuntuone_nautilus_reset_emblem (uon, path);
1564-
1565- /* Now remove the files from the status hash tables */
1566- g_hash_table_foreach_remove (uon->updated, (GHRFunc) remove_by_path_in_hash, (gpointer) path);
1567- g_hash_table_foreach_remove (uon->needsupdating, (GHRFunc) remove_by_path_in_hash, (gpointer) path);
1568- }
1569-}
1570-
1571-static void ubuntuone_nautilus_file_published (SyncdaemonDaemon *daemon,
1572- gboolean success,
1573- SyncdaemonFileInfo *finfo,
1574- gpointer user_data) {
1575- UbuntuOneNautilus * uon = UBUNTUONE_NAUTILUS (user_data);
1576- const gchar * path, * url;
1577- gboolean is_public;
1578-
1579- if (!success)
1580- return;
1581-
1582- path = syncdaemon_file_info_get_path (finfo);
1583- url = syncdaemon_file_info_get_public_url (finfo);
1584- is_public = syncdaemon_file_info_get_is_public (finfo);
1585-
1586- if (!is_public && g_hash_table_lookup (uon->public, path))
1587- g_hash_table_remove (uon->public, path);
1588-
1589- if (is_public)
1590- g_hash_table_replace (uon->public, g_strdup (path), g_strdup (url));
1591-
1592- ubuntuone_nautilus_reset_emblem (uon, path);
1593- uon->gotpubs = TRUE;
1594-}
1595-
1596-static void ubuntuone_nautilus_got_public_files (SyncdaemonDaemon *daemon,
1597- gboolean success,
1598- GSList *files,
1599- gpointer user_data) {
1600- UbuntuOneNautilus * uon = UBUNTUONE_NAUTILUS (user_data);
1601-
1602- if (success) {
1603- GSList *l;
1604-
1605- g_hash_table_remove_all (uon->public);
1606- for (l = files; l != NULL; l = l->next) {
1607- SyncdaemonFileInfo *finfo = SYNCDAEMON_FILE_INFO (l->data);
1608-
1609- g_hash_table_insert (uon->public,
1610- g_strdup (syncdaemon_file_info_get_path (finfo)),
1611- g_strdup (syncdaemon_file_info_get_public_url (finfo)));
1612- }
1613- }
1614-}
1615-
1616-static void
1617-ubuntuone_nautilus_share_created (SyncdaemonDaemon *daemon,
1618- gboolean success,
1619- SyncdaemonShareInfo *share_info,
1620- gpointer user_data)
1621-{
1622- UbuntuOneNautilus * uon = UBUNTUONE_NAUTILUS (user_data);
1623- const gchar * path;
1624-
1625- path = syncdaemon_share_info_get_path (share_info);
1626- if (success) {
1627- const gchar * id;
1628-
1629- id = syncdaemon_share_info_get_volume_id (share_info);
1630- if (!g_hash_table_lookup (uon->shares, path)) {
1631- g_hash_table_insert (uon->shares, g_strdup (path), g_strdup (id));
1632- ubuntuone_nautilus_reset_emblem (uon, path);
1633- }
1634- } else {
1635- ubuntuone_show_error_dialog (uon, _("Error creating share."),
1636- _("There was an error sharing the folder '%s'"),
1637- path);
1638- }
1639-}
1640-
1641-static void
1642-ubuntuone_nautilus_share_deleted (SyncdaemonDaemon *daemon,
1643- gboolean success,
1644- SyncdaemonShareInfo *share_info,
1645- gpointer user_data)
1646-{
1647- UbuntuOneNautilus * uon = UBUNTUONE_NAUTILUS (user_data);
1648- const gchar * path;
1649-
1650- path = syncdaemon_share_info_get_path (share_info);
1651- if (success) {
1652- g_hash_table_remove (uon->shares, path);
1653- ubuntuone_nautilus_reset_emblem (uon, path);
1654- }
1655+ UbuntuOneNautilus * uon = UBUNTUONE_NAUTILUS (user_data);
1656+ gboolean is_online = FALSE;
1657+ SyncdaemonInterface *interface;
1658+
1659+ interface = syncdaemon_daemon_get_status_interface (daemon);
1660+ if (interface != NULL) {
1661+ SyncdaemonStatusInfo *status_info;
1662+
1663+ status_info = syncdaemon_status_interface_get_current_status (SYNCDAEMON_STATUS_INTERFACE (interface));
1664+ is_online = syncdaemon_status_info_get_online (status_info);
1665+ }
1666+
1667+ /* Get the root when we get a status change signal, if we haven't yet */
1668+ if (!uon->gotroot) {
1669+ uon->managed = g_strdup (syncdaemon_daemon_get_root_dir (uon->syncdaemon));
1670+ if (uon->managed != NULL)
1671+ uon->gotroot = TRUE;
1672+ }
1673+
1674+ /* Get the list of UDFs if we haven't already */
1675+ if (!uon->gotudfs) {
1676+ SyncdaemonInterface *interface;
1677+
1678+ interface = syncdaemon_daemon_get_folders_interface (uon->syncdaemon);
1679+ if (interface != NULL) {
1680+ GSList *folders, *l;
1681+
1682+ folders = syncdaemon_folders_interface_get_folders (SYNCDAEMON_FOLDERS_INTERFACE (interface));
1683+ for (l = folders; l != NULL; l = l->next) {
1684+ const gchar *path, *id;
1685+ gboolean subscribed;
1686+ SyncdaemonFolderInfo *folder_info = SYNCDAEMON_FOLDER_INFO (l->data);
1687+
1688+ path = syncdaemon_folder_info_get_path (folder_info);
1689+ id = syncdaemon_folder_info_get_volume_id (folder_info);
1690+ subscribed = syncdaemon_folder_info_get_subscribed (folder_info);
1691+ if (subscribed) {
1692+ g_hash_table_insert (uon->udfs, g_strdup (path), g_strdup (id));
1693+ uon->gotudfs = TRUE;
1694+
1695+ file_watcher_update_path (uon->file_watcher, path);
1696+ }
1697+ }
1698+
1699+ g_slist_free (folders);
1700+ }
1701+ }
1702+
1703+ /* Get the list of shared folders */
1704+ interface = syncdaemon_daemon_get_shares_interface (uon->syncdaemon);
1705+ if (SYNCDAEMON_IS_SHARES_INTERFACE (interface)) {
1706+ GSList *shares;
1707+
1708+ shares = syncdaemon_shares_interface_get_shared (SYNCDAEMON_SHARES_INTERFACE (interface));
1709+ while (shares != NULL) {
1710+ const gchar *id, *path;
1711+ SyncdaemonShareInfo *share_info = SYNCDAEMON_SHARE_INFO (shares->data);
1712+
1713+ /* This code is duplicated in file-watcher.c */
1714+ path = syncdaemon_share_info_get_path (share_info);
1715+ id = syncdaemon_share_info_get_volume_id (share_info);
1716+ if (!g_hash_table_lookup (uon->shares, path)) {
1717+ g_hash_table_insert (uon->shares, g_strdup (path), g_strdup (id));
1718+ file_watcher_update_path (uon->file_watcher, path);
1719+ }
1720+
1721+ shares = g_slist_remove (shares, shares->data);
1722+ }
1723+ }
1724+
1725+ /* Get the list of public files if we haven't already */
1726+ if (is_online && !uon->gotpubs) {
1727+ SyncdaemonInterface *public;
1728+
1729+ public = syncdaemon_daemon_get_publicfiles_interface (uon->syncdaemon);
1730+ if (public != NULL) {
1731+ syncdaemon_publicfiles_interface_get_public_files (SYNCDAEMON_PUBLICFILES_INTERFACE (public));
1732+ uon->gotpubs = TRUE;
1733+ }
1734+ }
1735 }
1736
1737 /* Required Nautilus module handling methods */
1738-void nautilus_module_initialize (GTypeModule * module) {
1739+void
1740+nautilus_module_initialize (GTypeModule *module)
1741+{
1742 #ifdef ENABLE_NLS
1743- bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
1744- bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
1745- textdomain (GETTEXT_PACKAGE);
1746+ bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
1747+ bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
1748+ textdomain (GETTEXT_PACKAGE);
1749 #endif
1750
1751- ubuntuone_nautilus_register_type (module);
1752-}
1753-
1754-void nautilus_module_shutdown (void) {
1755-}
1756-
1757-
1758-void nautilus_module_list_types (const GType ** types,
1759- int * num_types) {
1760- static GType type_list[1];
1761+ ubuntuone_nautilus_register_type (module);
1762+}
1763+
1764+void
1765+nautilus_module_shutdown (void)
1766+{
1767+}
1768+
1769+void
1770+nautilus_module_list_types (const GType **types,
1771+ int *num_types)
1772+{
1773+ static GType type_list[1];
1774
1775- type_list[0] = UBUNTUONE_TYPE_NAUTILUS;
1776+ type_list[0] = UBUNTUONE_TYPE_NAUTILUS;
1777
1778- *types = type_list;
1779- *num_types = 1;
1780+ *types = type_list;
1781+ *num_types = 1;
1782 }
1783
1784=== modified file 'nautilus/ubuntuone-nautilus.h'
1785--- nautilus/ubuntuone-nautilus.h 2010-09-22 11:12:43 +0000
1786+++ nautilus/ubuntuone-nautilus.h 2010-10-08 07:48:50 +0000
1787@@ -27,6 +27,7 @@
1788 #include <dbus/dbus-glib.h>
1789 #include <libsyncdaemon/syncdaemon-daemon.h>
1790 #include <gtk/gtk.h>
1791+#include "file-watcher.h"
1792
1793 #define UBUNTUONE_TYPE_NAUTILUS (ubuntuone_nautilus_get_type ())
1794 #define UBUNTUONE_NAUTILUS(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), UBUNTUONE_TYPE_NAUTILUS, UbuntuOneNautilus))
1795@@ -34,10 +35,11 @@
1796 /* This is used when a change is pending */
1797 #define UPDATE_PENDING "pending"
1798
1799-typedef struct {
1800+struct _UbuntuOneNautilus {
1801 GObject parent_slot;
1802
1803- SyncdaemonDaemon * syncdaemon;
1804+ SyncdaemonDaemon *syncdaemon;
1805+ FileWatcher *file_watcher;
1806
1807 /* Are we connected? */
1808 gboolean connected;
1809@@ -51,21 +53,12 @@
1810 gboolean gotpubs;
1811
1812 /* Lists of ul/dl/shares for setting emblems */
1813- GHashTable * uploads;
1814- GHashTable * downloads;
1815 GHashTable * shares;
1816
1817 /* Lists of public files and user defined folders */
1818 GHashTable * public;
1819 GHashTable * udfs;
1820-
1821- /* Lists of sync/unsync'd files */
1822- GHashTable * updated;
1823- GHashTable * needsupdating;
1824-
1825- /* List of files that are observed for changes */
1826- GHashTable * observed;
1827-} UbuntuOneNautilus;
1828+};
1829
1830 typedef struct {
1831 GObjectClass parent_slot;
1832@@ -74,16 +67,11 @@
1833 GType ubuntuone_nautilus_get_type (void);
1834
1835 /* Utility functions */
1836-gboolean ubuntuone_is_storagefs (UbuntuOneNautilus * uon,
1837- const char * path,
1838- gboolean * is_root);
1839 gboolean ubuntuone_is_location_bar_enabled (void);
1840
1841-gboolean ubuntuone_nautilus_check_shares_and_public_files (UbuntuOneNautilus *uon,
1842+gboolean ubuntuone_check_shares_and_public_files (UbuntuOneNautilus *uon,
1843 SyncdaemonFolderInfo *folder_info,
1844 GtkWidget *widget);
1845-void ubuntuone_nautilus_reset_emblem (UbuntuOneNautilus * uon, const char * path);
1846-
1847 void ubuntuone_show_error_dialog (UbuntuOneNautilus *uon, const gchar *title, const gchar *error_message, ...);
1848
1849 #endif
1850
1851=== modified file 'nautilus/utils.c'
1852--- nautilus/utils.c 2010-09-22 11:12:43 +0000
1853+++ nautilus/utils.c 2010-10-08 07:48:50 +0000
1854@@ -21,15 +21,14 @@
1855
1856 #include <glib/gi18n.h>
1857 #include <libnautilus-extension/nautilus-file-info.h>
1858-#include <libsyncdaemon/syncdaemon-shares-interface.h>
1859+#include <libsyncdaemon/libsyncdaemon.h>
1860 #include "ubuntuone-nautilus.h"
1861 #include "location-widget.h"
1862
1863-/* this is the wrong place for this, but it'll have to do for now */
1864 gboolean
1865-ubuntuone_nautilus_check_shares_and_public_files (UbuntuOneNautilus *uon,
1866- SyncdaemonFolderInfo *folder_info,
1867- GtkWidget *widget)
1868+ubuntuone_check_shares_and_public_files (UbuntuOneNautilus *uon,
1869+ SyncdaemonFolderInfo *folder_info,
1870+ GtkWidget *widget)
1871 {
1872 SyncdaemonInterface *interface;
1873 gboolean result = TRUE, has_shares = FALSE, has_published = FALSE;
1874@@ -122,18 +121,3 @@
1875 return show_location;
1876 }
1877
1878-void
1879-ubuntuone_nautilus_reset_emblem (UbuntuOneNautilus *uon, const char *path)
1880-{
1881- GHashTableIter iter;
1882- gchar *key;
1883- NautilusFileInfo *file;
1884-
1885- /* Remove emblems from all files in the specified path */
1886- g_hash_table_iter_init (&iter, uon->observed);
1887- while (g_hash_table_iter_next (&iter, (gpointer *) &key, (gpointer *) &file)) {
1888- if (g_str_has_prefix (key, path) || g_strcmp0 (key, path) == 0) {
1889- nautilus_file_info_invalidate_extension_info (file);
1890- }
1891- }
1892-}
1893
1894=== modified file 'po/POTFILES.in'
1895--- po/POTFILES.in 2010-10-05 14:06:15 +0000
1896+++ po/POTFILES.in 2010-10-08 07:48:50 +0000
1897@@ -9,6 +9,7 @@
1898 nautilus/ubuntuone-nautilus.c
1899 nautilus/contacts-view.c
1900 nautilus/context-menu.c
1901+nautilus/file-watcher.c
1902 nautilus/u1-contacts-picker.c
1903 nautilus/location-widget.c
1904 nautilus/share-dialog.c

Subscribers

People subscribed via source and target branches