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
=== modified file 'libsyncdaemon/syncdaemon-daemon.c'
--- libsyncdaemon/syncdaemon-daemon.c 2010-10-04 18:47:52 +0000
+++ libsyncdaemon/syncdaemon-daemon.c 2010-10-08 07:48:50 +0000
@@ -43,11 +43,11 @@
4343
44struct _SyncdaemonDaemonPrivate {44struct _SyncdaemonDaemonPrivate {
45#ifdef HAVE_GDBUS45#ifdef HAVE_GDBUS
46 GDBusConnection *bus;46 GDBusConnection *bus;
47 GDbusProxy *dbus_proxy;47 GDbusProxy *dbus_proxy;
48#else48#else
49 DBusGConnection *bus;49 DBusGConnection *bus;
50 DBusGProxy *dbus_proxy;50 DBusGProxy *dbus_proxy;
51#endif51#endif
5252
53 /* Interfaces */53 /* Interfaces */
@@ -661,6 +661,71 @@
661 return daemon->priv->auth;661 return daemon->priv->auth;
662}662}
663663
664/**
665 * syncdaemon_daemon_is_folder_enabled:
666 * @daemon: A #SyncdaemonDaemon object
667 * @path: The folder path to check
668 * @is_root: Placeholder for returning whether the given path is a U1 root folder
669 *
670 * Check whether a given path is a folder enabled for synchronization to U1.
671 *
672 * Return value: TRUE if the folder is enabled, FALSE otherwise.
673 */
674gboolean
675syncdaemon_daemon_is_folder_enabled (SyncdaemonDaemon *daemon, const gchar *path, gboolean *is_root)
676{
677 const gchar *root;
678 gboolean managed = FALSE;
679 gchar *dirpath;
680 SyncdaemonInterface *interface;
681
682 g_return_val_if_fail (SYNCDAEMON_IS_DAEMON (daemon), FALSE);
683 g_return_val_if_fail (path != NULL, FALSE);
684
685 *is_root = FALSE;
686
687 /* First check the root folder */
688 root = syncdaemon_daemon_get_root_dir (daemon);
689 if (g_strcmp0 (path, root) == 0) {
690 *is_root = TRUE;
691 return TRUE;
692 } else if (g_str_has_prefix (path, root))
693 return TRUE;
694
695 /* Now check the 'Shared With Me' directory */
696 dirpath = g_build_filename (root, "Shared With Me", NULL);
697 if (g_strcmp0 (path, dirpath) == 0) {
698 g_free (dirpath);
699 return FALSE;
700 }
701
702 /* And finally check UDFs */
703 interface = syncdaemon_daemon_get_folders_interface (daemon);
704 if (SYNCDAEMON_IS_FOLDERS_INTERFACE (interface)) {
705 GSList *udfs, *l;
706
707 udfs = syncdaemon_folders_interface_get_folders (SYNCDAEMON_FOLDERS_INTERFACE (interface));
708 for (l = udfs; l != NULL; l = l->next) {
709 const gchar *tmp_path;
710 SyncdaemonFolderInfo *finfo = SYNCDAEMON_FOLDER_INFO (l->data);
711
712 tmp_path = syncdaemon_folder_info_get_path (finfo);
713 if (g_strcmp0 (path, tmp_path) == 0) {
714 managed = TRUE;
715 *is_root = TRUE;
716 break;
717 } else if (g_str_has_prefix (path, tmp_path)) {
718 managed = TRUE;
719 break;
720 }
721 }
722
723 g_slist_free (udfs);
724 }
725
726 return managed;
727}
728
664typedef SyncdaemonInterface * (* SDINewFunc) (SyncdaemonDaemon * daemon);729typedef SyncdaemonInterface * (* SDINewFunc) (SyncdaemonDaemon * daemon);
665730
666static SyncdaemonInterface *731static SyncdaemonInterface *
@@ -687,7 +752,7 @@
687 g_return_val_if_fail (SYNCDAEMON_IS_DAEMON (daemon), NULL);752 g_return_val_if_fail (SYNCDAEMON_IS_DAEMON (daemon), NULL);
688753
689 return get_interface (daemon, "/config",754 return get_interface (daemon, "/config",
690 (SDINewFunc) syncdaemon_config_interface_new);755 (SDINewFunc) syncdaemon_config_interface_new);
691}756}
692757
693/**758/**
@@ -699,7 +764,7 @@
699 g_return_val_if_fail (SYNCDAEMON_IS_DAEMON (daemon), NULL);764 g_return_val_if_fail (SYNCDAEMON_IS_DAEMON (daemon), NULL);
700765
701 return get_interface (daemon, "/events",766 return get_interface (daemon, "/events",
702 (SDINewFunc) syncdaemon_events_interface_new);767 (SDINewFunc) syncdaemon_events_interface_new);
703}768}
704769
705/**770/**
@@ -711,7 +776,7 @@
711 g_return_val_if_fail (SYNCDAEMON_IS_DAEMON (daemon), NULL);776 g_return_val_if_fail (SYNCDAEMON_IS_DAEMON (daemon), NULL);
712777
713 return get_interface (daemon, "/filesystem",778 return get_interface (daemon, "/filesystem",
714 (SDINewFunc) syncdaemon_filesystem_interface_new);779 (SDINewFunc) syncdaemon_filesystem_interface_new);
715}780}
716781
717/**782/**
@@ -723,7 +788,7 @@
723 g_return_val_if_fail (SYNCDAEMON_IS_DAEMON (daemon), NULL);788 g_return_val_if_fail (SYNCDAEMON_IS_DAEMON (daemon), NULL);
724789
725 return get_interface (daemon, "/folders",790 return get_interface (daemon, "/folders",
726 (SDINewFunc) syncdaemon_folders_interface_new);791 (SDINewFunc) syncdaemon_folders_interface_new);
727}792}
728793
729/**794/**
@@ -735,7 +800,7 @@
735 g_return_val_if_fail (SYNCDAEMON_IS_DAEMON (daemon), NULL);800 g_return_val_if_fail (SYNCDAEMON_IS_DAEMON (daemon), NULL);
736801
737 return get_interface (daemon, "/publicfiles",802 return get_interface (daemon, "/publicfiles",
738 (SDINewFunc) syncdaemon_publicfiles_interface_new);803 (SDINewFunc) syncdaemon_publicfiles_interface_new);
739}804}
740805
741/**806/**
@@ -747,7 +812,7 @@
747 g_return_val_if_fail (SYNCDAEMON_IS_DAEMON (daemon), NULL);812 g_return_val_if_fail (SYNCDAEMON_IS_DAEMON (daemon), NULL);
748813
749 return get_interface (daemon, "/shares",814 return get_interface (daemon, "/shares",
750 (SDINewFunc) syncdaemon_shares_interface_new);815 (SDINewFunc) syncdaemon_shares_interface_new);
751}816}
752817
753/**818/**
@@ -759,5 +824,5 @@
759 g_return_val_if_fail (SYNCDAEMON_IS_DAEMON (daemon), NULL);824 g_return_val_if_fail (SYNCDAEMON_IS_DAEMON (daemon), NULL);
760825
761 return get_interface (daemon, "/status",826 return get_interface (daemon, "/status",
762 (SDINewFunc) syncdaemon_status_interface_new);827 (SDINewFunc) syncdaemon_status_interface_new);
763}828}
764829
=== modified file 'libsyncdaemon/syncdaemon-daemon.h'
--- libsyncdaemon/syncdaemon-daemon.h 2010-08-24 22:27:04 +0000
+++ libsyncdaemon/syncdaemon-daemon.h 2010-10-08 07:48:50 +0000
@@ -95,6 +95,14 @@
95gboolean syncdaemon_daemon_has_network (SyncdaemonDaemon *daemon);95gboolean syncdaemon_daemon_has_network (SyncdaemonDaemon *daemon);
96SyncdaemonAuthentication *syncdaemon_daemon_get_authentication (SyncdaemonDaemon *daemon);96SyncdaemonAuthentication *syncdaemon_daemon_get_authentication (SyncdaemonDaemon *daemon);
9797
98/* Folders operations */
99gboolean syncdaemon_daemon_is_folder_enabled (SyncdaemonDaemon *daemon,
100 const gchar *path,
101 gboolean *is_root);
102
103/*
104 * Low level DBus interface access
105 */
98SyncdaemonInterface *syncdaemon_daemon_get_config_interface (SyncdaemonDaemon *daemon);106SyncdaemonInterface *syncdaemon_daemon_get_config_interface (SyncdaemonDaemon *daemon);
99SyncdaemonInterface *syncdaemon_daemon_get_events_interface (SyncdaemonDaemon *daemon);107SyncdaemonInterface *syncdaemon_daemon_get_events_interface (SyncdaemonDaemon *daemon);
100SyncdaemonInterface *syncdaemon_daemon_get_filesystem_interface (SyncdaemonDaemon *daemon);108SyncdaemonInterface *syncdaemon_daemon_get_filesystem_interface (SyncdaemonDaemon *daemon);
101109
=== modified file 'nautilus/Makefile.am'
--- nautilus/Makefile.am 2010-09-22 10:58:17 +0000
+++ nautilus/Makefile.am 2010-10-08 07:48:50 +0000
@@ -27,6 +27,8 @@
27 context-menu.c \27 context-menu.c \
28 context-menu.h \28 context-menu.h \
29 error-dialog.c \29 error-dialog.c \
30 file-watcher.c \
31 file-watcher.h \
30 location-widget.c \32 location-widget.c \
31 location-widget.h \33 location-widget.h \
32 highlight.c \34 highlight.c \
3335
=== modified file 'nautilus/context-menu.c'
--- nautilus/context-menu.c 2010-10-04 18:47:52 +0000
+++ nautilus/context-menu.c 2010-10-08 07:48:50 +0000
@@ -87,7 +87,7 @@
87 folder_info = syncdaemon_folders_interface_get_info (SYNCDAEMON_FOLDERS_INTERFACE (interface),87 folder_info = syncdaemon_folders_interface_get_info (SYNCDAEMON_FOLDERS_INTERFACE (interface),
88 data->path);88 data->path);
89 if (folder_info != NULL) {89 if (folder_info != NULL) {
90 if (ubuntuone_nautilus_check_shares_and_public_files (data->uon, folder_info, data->parent)) {90 if (ubuntuone_check_shares_and_public_files (data->uon, folder_info, data->parent)) {
91 syncdaemon_folders_interface_delete (SYNCDAEMON_FOLDERS_INTERFACE (interface),91 syncdaemon_folders_interface_delete (SYNCDAEMON_FOLDERS_INTERFACE (interface),
92 syncdaemon_folder_info_get_volume_id (folder_info));92 syncdaemon_folder_info_get_volume_id (folder_info));
93 }93 }
@@ -139,7 +139,7 @@
139 }139 }
140140
141 g_hash_table_replace (data->uon->public, g_strdup (data->path), UPDATE_PENDING);141 g_hash_table_replace (data->uon->public, g_strdup (data->path), UPDATE_PENDING);
142 ubuntuone_nautilus_reset_emblem (data->uon, data->path);142 file_watcher_update_path (data->uon->file_watcher, data->path);
143}143}
144144
145static void145static void
@@ -200,7 +200,7 @@
200 if (path == NULL)200 if (path == NULL)
201 return NULL;201 return NULL;
202202
203 if (ubuntuone_is_storagefs (uon, path, &is_root))203 if (syncdaemon_daemon_is_folder_enabled (uon->syncdaemon, path, &is_root))
204 is_managed = TRUE;204 is_managed = TRUE;
205205
206 homedir_path = g_strdup_printf ("%s/", g_get_home_dir());206 homedir_path = g_strdup_printf ("%s/", g_get_home_dir());
207207
=== added file 'nautilus/file-watcher.c'
--- nautilus/file-watcher.c 1970-01-01 00:00:00 +0000
+++ nautilus/file-watcher.c 2010-10-08 07:48:50 +0000
@@ -0,0 +1,358 @@
1/*
2 * UbuntuOne Nautilus plugin
3 *
4 * Authors: Rodrigo Moya <rodrigo.moya@canonical.com>
5 *
6 * Copyright 2009-2010 Canonical Ltd.
7 *
8 * This program is free software: you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License version 3, as published
10 * by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranties of
14 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 */
21
22#ifdef HAVE_CONFIG_H
23#include <config.h>
24#endif
25
26#include <glib/gi18n-lib.h>
27#include <libsyncdaemon/libsyncdaemon.h>
28#include "ubuntuone-nautilus.h"
29
30G_DEFINE_TYPE(FileWatcher, file_watcher, G_TYPE_OBJECT)
31
32static void
33file_watcher_finalize (GObject *object)
34{
35 FileWatcher *watcher = FILE_WATCHER (object);
36
37 if (watcher->files != NULL)
38 g_hash_table_destroy (watcher->files);
39
40 G_OBJECT_CLASS (file_watcher_parent_class)->finalize (object);
41}
42
43static void
44file_watcher_class_init (FileWatcherClass *klass)
45{
46 GObjectClass *object_class = G_OBJECT_CLASS (klass);
47
48 object_class->finalize = file_watcher_finalize;
49}
50
51static void
52file_watcher_init (FileWatcher *watcher)
53{
54 watcher->uon = NULL;
55 watcher->files = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
56}
57
58static void
59transfer_started_cb (SyncdaemonDaemon *daemon,
60 gchar *path,
61 gpointer user_data)
62{
63 FileWatcher *watcher = FILE_WATCHER (user_data);
64
65 file_watcher_update_path (watcher, path);
66}
67
68static void
69transfer_finished_cb (SyncdaemonDaemon *daemon,
70 gchar *path,
71 SyncdaemonTransferInfo * info,
72 gpointer user_data)
73{
74 FileWatcher *watcher = FILE_WATCHER (user_data);
75
76 file_watcher_update_path (watcher, path);
77}
78
79static void
80share_created_cb (SyncdaemonDaemon *daemon,
81 gboolean success,
82 SyncdaemonShareInfo *share_info,
83 gpointer user_data)
84{
85 FileWatcher *watcher = FILE_WATCHER (user_data);
86 const gchar * path;
87
88 path = syncdaemon_share_info_get_path (share_info);
89 if (success) {
90 const gchar * id;
91
92 id = syncdaemon_share_info_get_volume_id (share_info);
93 if (!g_hash_table_lookup (watcher->uon->shares, path)) {
94 g_hash_table_insert (watcher->uon->shares, g_strdup (path), g_strdup (id));
95 file_watcher_update_path (watcher, path);
96 }
97 } else {
98 ubuntuone_show_error_dialog (watcher->uon, _("Error creating share."),
99 _("There was an error sharing the folder '%s'"),
100 path);
101 }
102}
103
104static void
105share_deleted_cb (SyncdaemonDaemon *daemon,
106 gboolean success,
107 SyncdaemonShareInfo *share_info,
108 gpointer user_data)
109{
110 FileWatcher *watcher = FILE_WATCHER (user_data);
111 const gchar *path;
112
113 path = syncdaemon_share_info_get_path (share_info);
114 if (success) {
115 g_hash_table_remove (watcher->uon->shares, path);
116 file_watcher_update_path (watcher, path);
117 } else {
118 ubuntuone_show_error_dialog (watcher->uon, _("Error deleting share."),
119 _("There was an error deleting the share for folder '%s'"),
120 path);
121 }
122}
123
124static void
125udf_created_cb (SyncdaemonDaemon *daemon,
126 gboolean success,
127 SyncdaemonFolderInfo *folder_info,
128 gpointer user_data)
129{
130 FileWatcher *watcher = FILE_WATCHER (user_data);
131 const gchar *path, *id;
132 gboolean subscribed;
133
134 path = syncdaemon_folder_info_get_path (folder_info);
135 id = syncdaemon_folder_info_get_volume_id (folder_info);
136 subscribed = syncdaemon_folder_info_get_subscribed (folder_info);
137 if (success) {
138 if (!g_hash_table_lookup (watcher->uon->udfs, path)) {
139 if (subscribed) {
140 g_hash_table_insert (watcher->uon->udfs, g_strdup (path), g_strdup (id));
141
142 /* Update the emblems of the files on this new UDF */
143 file_watcher_update_path (watcher, path);
144 }
145 }
146 }
147}
148
149static void
150udf_deleted_cb (SyncdaemonDaemon *daemon,
151 gboolean success,
152 SyncdaemonFolderInfo *folder_info,
153 gpointer user_data)
154{
155 FileWatcher *watcher = FILE_WATCHER (user_data);
156 const gchar * path;
157
158 path = syncdaemon_folder_info_get_path (folder_info);
159 if (path != NULL && success) {
160 /* Remove the files from the status hash table */
161 g_hash_table_remove (watcher->uon->udfs, path);
162
163 file_watcher_update_path (watcher, path);
164 }
165}
166
167static void
168file_published_cb (SyncdaemonDaemon *daemon,
169 gboolean success,
170 SyncdaemonFileInfo *finfo,
171 gpointer user_data)
172{
173 FileWatcher *watcher = FILE_WATCHER (user_data);
174 const gchar * path, * url;
175 gboolean is_public;
176
177 path = syncdaemon_file_info_get_path (finfo);
178 if (success) {
179 url = syncdaemon_file_info_get_public_url (finfo);
180 is_public = syncdaemon_file_info_get_is_public (finfo);
181
182 if (!is_public && g_hash_table_lookup (watcher->uon->public, path))
183 g_hash_table_remove (watcher->uon->public, path);
184
185 if (is_public)
186 g_hash_table_replace (watcher->uon->public, g_strdup (path), g_strdup (url));
187
188 file_watcher_update_path (watcher, path);
189 watcher->uon->gotpubs = TRUE;
190 } else {
191 ubuntuone_show_error_dialog (watcher->uon, _("Error publishing file."),
192 _("There was an error publishing file '%s'"),
193 path);
194 }
195}
196
197static void
198got_public_files_cb (SyncdaemonDaemon *daemon,
199 gboolean success,
200 GSList *files,
201 gpointer user_data)
202{
203 FileWatcher *watcher = FILE_WATCHER (user_data);
204
205 if (success) {
206 GSList *l;
207
208 g_hash_table_remove_all (watcher->uon->public);
209 for (l = files; l != NULL; l = l->next) {
210 const gchar *path;
211 SyncdaemonFileInfo *finfo = SYNCDAEMON_FILE_INFO (l->data);
212
213 path = syncdaemon_file_info_get_path (finfo);
214 g_hash_table_insert (watcher->uon->public,
215 g_strdup (path),
216 g_strdup (syncdaemon_file_info_get_public_url (finfo)));
217
218 file_watcher_update_path (watcher, path);
219 }
220 } else {
221 ubuntuone_show_error_dialog (watcher->uon, _("Error getting public files"),
222 _("There was an error getting the list of public files"));
223 }
224}
225
226FileWatcher *
227file_watcher_new (UbuntuOneNautilus *uon)
228{
229 FileWatcher *watcher;
230
231 watcher = g_object_new (TYPE_FILE_WATCHER, NULL);
232 watcher->uon = uon;
233
234 /* Connect to transfers-related signals */
235 g_signal_connect (G_OBJECT (uon->syncdaemon), "upload_started",
236 G_CALLBACK (transfer_started_cb), watcher);
237 g_signal_connect (G_OBJECT (uon->syncdaemon), "upload_finished",
238 G_CALLBACK (transfer_finished_cb), watcher);
239 g_signal_connect (G_OBJECT (uon->syncdaemon), "download_started",
240 G_CALLBACK (transfer_started_cb), watcher);
241 g_signal_connect (G_OBJECT (uon->syncdaemon), "download_finished",
242 G_CALLBACK (transfer_finished_cb), watcher);
243
244 /* Connect to shares-related signals */
245 g_signal_connect (G_OBJECT (uon->syncdaemon), "share_created",
246 G_CALLBACK (share_created_cb), watcher);
247 g_signal_connect (G_OBJECT (uon->syncdaemon), "share_deleted",
248 G_CALLBACK (share_deleted_cb), watcher);
249
250 /* Connect to folder-related signals */
251 g_signal_connect (G_OBJECT (uon->syncdaemon), "folder_created",
252 G_CALLBACK (udf_created_cb), watcher);
253 g_signal_connect (G_OBJECT (uon->syncdaemon), "folder_subscribed",
254 G_CALLBACK (udf_created_cb), watcher);
255 g_signal_connect (G_OBJECT (uon->syncdaemon), "folder_deleted",
256 G_CALLBACK (udf_deleted_cb), watcher);
257 g_signal_connect (G_OBJECT (uon->syncdaemon), "folder_unsubscribed",
258 G_CALLBACK (udf_deleted_cb), watcher);
259
260 /* Connect to public files-related signals */
261 g_signal_connect (G_OBJECT (uon->syncdaemon), "file_published",
262 G_CALLBACK (file_published_cb), watcher);
263 g_signal_connect (G_OBJECT (uon->syncdaemon), "got_published_files",
264 G_CALLBACK (got_public_files_cb), watcher);
265
266 return watcher;
267}
268
269static gboolean
270check_for_shared_folder (const gchar *path, GSList *list_of_shares)
271{
272 GSList *l;
273 gboolean is_shared = FALSE;
274
275 for (l = list_of_shares; l != NULL; l = l->next) {
276 SyncdaemonShareInfo *share_info = SYNCDAEMON_SHARE_INFO (l->data);
277
278 if (g_strcmp0 (syncdaemon_share_info_get_path (share_info), path) == 0) {
279 is_shared = TRUE;
280 break;
281 }
282 }
283
284 g_slist_free (list_of_shares);
285
286 return is_shared;
287}
288
289void
290file_watcher_add_file (FileWatcher *watcher, NautilusFileInfo *file)
291{
292 gboolean is_root;
293 gchar *path = NULL;
294
295 g_return_if_fail (IS_FILE_WATCHER (watcher));
296
297 path = g_filename_from_uri (nautilus_file_info_get_uri (file), NULL, NULL);
298 if (path == NULL)
299 return;
300
301 /* Always add it to the observed hash table, so that we can update emblems */
302 g_hash_table_insert (watcher->files, path, g_object_ref (file));
303
304 /* Retrieve metadata */
305 if (syncdaemon_daemon_is_folder_enabled (watcher->uon->syncdaemon, path, &is_root)) {
306 SyncdaemonInterface *interface;
307
308 interface = syncdaemon_daemon_get_filesystem_interface (watcher->uon->syncdaemon);
309 if (interface != NULL) {
310 SyncdaemonMetadata *metadata;
311 gboolean is_dir = nautilus_file_info_is_directory (file);
312
313 metadata = syncdaemon_filesystem_interface_get_metadata (
314 SYNCDAEMON_FILESYSTEM_INTERFACE (interface), path, is_dir);
315
316 if (syncdaemon_metadata_get_is_synced (metadata))
317 nautilus_file_info_add_emblem (file, "ubuntuone-synchronized");
318 else
319 nautilus_file_info_add_emblem (file, "ubuntuone-updating");
320
321 if (is_dir) {
322 /* If it's a directory, check shares */
323 interface = syncdaemon_daemon_get_shares_interface (watcher->uon->syncdaemon);
324 if (check_for_shared_folder ((const gchar *) path,
325 syncdaemon_shares_interface_get_shared (SYNCDAEMON_SHARES_INTERFACE (interface))) ||
326 check_for_shared_folder ((const gchar *) path,
327 syncdaemon_shares_interface_get_shares (SYNCDAEMON_SHARES_INTERFACE (interface)))) {
328 nautilus_file_info_add_emblem (file, "shared");
329 }
330 } else {
331 /* If it's a file, check for public files */
332 }
333
334 /* Free memory */
335 g_object_unref (G_OBJECT (metadata));
336 }
337 }
338
339 /* if (g_hash_table_lookup (watcher->uon->public, path)) */
340 /* nautilus_file_info_add_emblem (file, "ubuntuone-public"); */
341}
342
343void
344file_watcher_update_path (FileWatcher *watcher, const gchar *path)
345{
346 GHashTableIter iter;
347 gchar *key;
348 NautilusFileInfo *file;
349
350 g_return_if_fail (IS_FILE_WATCHER (watcher));
351
352 /* Remove emblems from all files in the specified path */
353 g_hash_table_iter_init (&iter, watcher->files);
354 while (g_hash_table_iter_next (&iter, (gpointer *) &key, (gpointer *) &file)) {
355 if (g_str_has_prefix (key, path) || g_strcmp0 (key, path) == 0)
356 nautilus_file_info_invalidate_extension_info (file);
357 }
358}
0359
=== added file 'nautilus/file-watcher.h'
--- nautilus/file-watcher.h 1970-01-01 00:00:00 +0000
+++ nautilus/file-watcher.h 2010-10-08 07:48:50 +0000
@@ -0,0 +1,54 @@
1/*
2 * UbuntuOne Nautilus plugin
3 *
4 * Authors: Rodrigo Moya <rodrigo.moya@canonical.com>
5 *
6 * Copyright 2009-2010 Canonical Ltd.
7 *
8 * This program is free software: you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License version 3, as published
10 * by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranties of
14 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 */
21
22#ifndef __FILE_WATCHER_H__
23#define __FILE_WATCHER_H__
24
25#include <libnautilus-extension/nautilus-file-info.h>
26
27#define TYPE_FILE_WATCHER (file_watcher_get_type ())
28#define FILE_WATCHER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_FILE_WATCHER, FileWatcher))
29#define IS_FILE_WATCHER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_FILE_WATCHER))
30#define FILE_WATCHER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_FILE_WATCHER, FileWatcherClass))
31#define IS_FILE_WATCHER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_FILE_WATCHER))
32#define FILE_WATCHER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_FILE_WATCHER, FileWatcherClass))
33
34typedef struct _UbuntuOneNautilus UbuntuOneNautilus;
35
36typedef struct {
37 GObject parent;
38
39 /* Private data */
40 UbuntuOneNautilus *uon;
41 GHashTable *files;
42} FileWatcher;
43
44typedef struct {
45 GObjectClass parent_class;
46} FileWatcherClass;
47
48GType file_watcher_get_type (void);
49
50FileWatcher *file_watcher_new (UbuntuOneNautilus *uon);
51void file_watcher_add_file (FileWatcher *watcher, NautilusFileInfo *file);
52void file_watcher_update_path (FileWatcher *watcher, const gchar *path);
53
54#endif
055
=== modified file 'nautilus/location-widget.c'
--- nautilus/location-widget.c 2010-10-04 18:47:52 +0000
+++ nautilus/location-widget.c 2010-10-08 07:48:50 +0000
@@ -137,7 +137,7 @@
137 SYNCDAEMON_FOLDERS_INTERFACE (interface),137 SYNCDAEMON_FOLDERS_INTERFACE (interface),
138 location->path);138 location->path);
139 if (folder_info != NULL) {139 if (folder_info != NULL) {
140 if (ubuntuone_nautilus_check_shares_and_public_files (location->uon, folder_info, GTK_WIDGET (location))) {140 if (ubuntuone_check_shares_and_public_files (location->uon, folder_info, GTK_WIDGET (location))) {
141 start_spinner (location);141 start_spinner (location);
142142
143 syncdaemon_folders_interface_delete (143 syncdaemon_folders_interface_delete (
@@ -365,7 +365,7 @@
365 }365 }
366 if (!is_xdg) {366 if (!is_xdg) {
367 /* last chance */367 /* last chance */
368 ubuntuone_is_storagefs (uon, path, &is_root);368 syncdaemon_daemon_is_folder_enabled (uon->syncdaemon, path, &is_root);
369 if (!is_root || is_special_udf (uon, path))369 if (!is_root || is_special_udf (uon, path))
370 return NULL;370 return NULL;
371 }371 }
@@ -380,7 +380,7 @@
380 g_signal_connect (G_OBJECT (uon->syncdaemon), "folder_deleted",380 g_signal_connect (G_OBJECT (uon->syncdaemon), "folder_deleted",
381 G_CALLBACK (folder_deleted_cb), location);381 G_CALLBACK (folder_deleted_cb), location);
382382
383 if (ubuntuone_is_storagefs (uon, path, &is_root)) {383 if (syncdaemon_daemon_is_folder_enabled (uon->syncdaemon, path, &is_root)) {
384 /* Create label and disable button */384 /* Create label and disable button */
385 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (location->toggle_button), TRUE);385 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (location->toggle_button), TRUE);
386 if (!is_root || is_special_udf (uon, path))386 if (!is_root || is_special_udf (uon, path))
387387
=== modified file 'nautilus/ubuntuone-nautilus.c'
--- nautilus/ubuntuone-nautilus.c 2010-10-04 18:47:52 +0000
+++ nautilus/ubuntuone-nautilus.c 2010-10-08 07:48:50 +0000
@@ -49,283 +49,74 @@
49/* The header is generated from ubuntuone-marshallers.list */49/* The header is generated from ubuntuone-marshallers.list */
50#include "ubuntuone-marshallers.h"50#include "ubuntuone-marshallers.h"
5151
52static void ubuntuone_nautilus_finalize(GObject * object);52static void ubuntuone_nautilus_finalize (GObject *object);
5353
54static void ubuntuone_nautilus_register_type (GTypeModule * module);54static void ubuntuone_nautilus_register_type (GTypeModule *module);
55
56/* Utility functions */
57static void ubuntuone_nautilus_observed_file_unref (gpointer user_data,
58 GObject *where_the_object_was);
59
60static void ubuntuone_nautilus_observed_file_foreach_unref (gpointer key,
61 gpointer value,
62 gpointer user_data);
6355
64/* DBus signal and async method call handlers */56/* DBus signal and async method call handlers */
65static void ubuntuone_nautilus_update_meta (SyncdaemonFilesystemInterface *interface,
66 gboolean success,
67 SyncdaemonMetadata *metadata,
68 gpointer user_data);
69static void ubuntuone_nautilus_daemon_ready (SyncdaemonDaemon *daemon, gpointer user_data);57static void ubuntuone_nautilus_daemon_ready (SyncdaemonDaemon *daemon, gpointer user_data);
70static void ubuntuone_nautilus_upload_started (SyncdaemonDaemon *daemon,58
71 gchar * path,59static GObjectClass *parent_class = NULL;
72 gpointer user_data);
73static void ubuntuone_nautilus_upload_finished (SyncdaemonDaemon *daemon,
74 gchar * path,
75 SyncdaemonTransferInfo * info,
76 gpointer user_data);
77static void ubuntuone_nautilus_download_started (SyncdaemonDaemon *daemon,
78 gchar * path,
79 gpointer user_data);
80static void ubuntuone_nautilus_download_finished (SyncdaemonDaemon *daemon,
81 gchar * path,
82 SyncdaemonTransferInfo * info,
83 gpointer user_data);
84static void ubuntuone_nautilus_udf_created (SyncdaemonDaemon *daemon,
85 gboolean success,
86 SyncdaemonFolderInfo *folder_info,
87 gpointer user_data);
88static void ubuntuone_nautilus_udf_deleted (SyncdaemonDaemon *daemon,
89 gboolean success,
90 SyncdaemonFolderInfo *folder_info,
91 gpointer user_data);
92static void ubuntuone_nautilus_file_published (SyncdaemonDaemon *daemon,
93 gboolean success,
94 SyncdaemonFileInfo *finfo,
95 gpointer user_data);
96static void ubuntuone_nautilus_got_public_files (SyncdaemonDaemon *daemon,
97 gboolean success,
98 GSList *files,
99 gpointer user_data);
100static void ubuntuone_nautilus_share_created (SyncdaemonDaemon *daemon,
101 gboolean success,
102 SyncdaemonShareInfo *share_info,
103 gpointer user_data);
104static void ubuntuone_nautilus_share_deleted (SyncdaemonDaemon *daemon,
105 gboolean success,
106 SyncdaemonShareInfo *share_info,
107 gpointer user_data);
108
109
110static GObjectClass * parent_class = NULL;
111
112/* Called when NautilusFileInfo is unreferenced */
113static void ubuntuone_nautilus_observed_file_unref (gpointer user_data,
114 GObject *where_the_object_was) {
115 UbuntuOneNautilus * uon;
116 NautilusFileInfo * file;
117 gchar * path = NULL;
118
119 uon = UBUNTUONE_NAUTILUS(user_data);
120 file = NAUTILUS_FILE_INFO(where_the_object_was);
121 path = g_filename_from_uri (nautilus_file_info_get_uri (file), NULL, NULL);
122
123 if (g_hash_table_lookup (uon->observed, path ))
124 g_hash_table_remove (uon->observed, path);
125
126}
127
128/* Cleanup routine for weak reference callbacks */
129static void ubuntuone_nautilus_observed_file_foreach_unref (gpointer key,
130 gpointer value,
131 gpointer user_data) {
132 UbuntuOneNautilus * uon;
133 NautilusFileInfo * file;
134
135 uon = UBUNTUONE_NAUTILUS(user_data);
136 file = NAUTILUS_FILE_INFO(value);
137
138 g_object_weak_unref (G_OBJECT (file),
139 (GWeakNotify) ubuntuone_nautilus_observed_file_unref,
140 uon);
141
142}
143
144/* Are we in an Ubuntu One managed (root or udf) directory */
145gboolean ubuntuone_is_storagefs (UbuntuOneNautilus * uon,
146 const char * path,
147 gboolean * is_root) {
148 gboolean managed = FALSE;
149 gchar * dirpath;
150 gchar * shared;
151 GSList * udfs, * l;
152 SyncdaemonFoldersInterface *interface;
153
154 *is_root = FALSE;
155
156 if (!uon->managed)
157 return FALSE;
158
159 if (!path)
160 return FALSE;
161
162 /* Check the Ubuntu One directory */
163 if (strcmp (path, uon->managed) == 0) {
164 *is_root = TRUE;
165 return TRUE;
166 }
167
168 shared = g_build_filename (uon->managed, "Shared With Me", NULL);
169 if (strncmp (path, shared, strlen (shared)) == 0) {
170 managed = FALSE;
171 goto fsdone;
172 }
173
174 dirpath = g_strdup_printf ("%s/", uon->managed);
175 if (strncmp (path, dirpath, strlen (dirpath)) == 0) {
176 managed = TRUE;
177 goto fsdone;
178 }
179
180 g_free (dirpath);
181
182 /* Check for UDFs */
183 interface = SYNCDAEMON_FOLDERS_INTERFACE (syncdaemon_daemon_get_folders_interface (uon->syncdaemon));
184 if (interface != NULL) {
185 udfs = syncdaemon_folders_interface_get_folders (SYNCDAEMON_FOLDERS_INTERFACE (interface));
186 for (l = udfs; l != NULL && l->data != NULL; l = l->next) {
187 const char *tmp_path;
188
189 tmp_path = syncdaemon_folder_info_get_path (SYNCDAEMON_FOLDER_INFO (l->data));
190 if (!tmp_path)
191 continue;
192
193 if (strcmp (path, tmp_path) == 0) {
194 managed = TRUE;
195 *is_root = TRUE;
196 break;
197 }
198
199 dirpath = g_strdup_printf ("%s/", (char *) tmp_path);
200 if (strncmp (path, dirpath, strlen (dirpath)) == 0) {
201 managed = TRUE;
202 g_free (dirpath);
203 break;
204 }
205
206 g_free (dirpath);
207 }
208 g_slist_free (udfs);
209 }
210
211 fsdone:
212 g_free (shared);
213 return managed;
214}
215
216static void
217ubuntuone_nautilus_add_observed (UbuntuOneNautilus * uon,
218 gchar * path,
219 NautilusFileInfo * file)
220{
221 g_object_weak_ref (G_OBJECT(file),
222 (GWeakNotify) ubuntuone_nautilus_observed_file_unref,
223 uon);
224 g_hash_table_insert (uon->observed, g_strdup (path), file);
225}
22660
227/* Update file info provider */61/* Update file info provider */
228static NautilusOperationResult62static NautilusOperationResult
229ubuntuone_nautilus_update_file_info (NautilusInfoProvider * provider,63ubuntuone_nautilus_update_file_info (NautilusInfoProvider *provider,
230 NautilusFileInfo * file,64 NautilusFileInfo *file,
231 GClosure * update_complete,65 GClosure *update_complete,
232 NautilusOperationHandle ** handle)66 NautilusOperationHandle **handle)
233{67{
234 UbuntuOneNautilus * uon;68 UbuntuOneNautilus *uon = UBUNTUONE_NAUTILUS (provider);
235 gboolean is_root;69
236 char * path = NULL;70 /* If syncdaemon is not ready, do nothing */
23771 if (!syncdaemon_daemon_is_ready (uon->syncdaemon))
238 uon = UBUNTUONE_NAUTILUS(provider);72 return NAUTILUS_OPERATION_COMPLETE;
23973
240 /* If syncdaemon is not ready, do nothing */74 file_watcher_add_file (uon->file_watcher, file);
241 if (!syncdaemon_daemon_is_ready (uon->syncdaemon))75
242 return NAUTILUS_OPERATION_COMPLETE;76 return NAUTILUS_OPERATION_COMPLETE;
243
244 path = g_filename_from_uri (nautilus_file_info_get_uri (file), NULL, NULL);
245 if (path == NULL)
246 return NAUTILUS_OPERATION_COMPLETE;
247
248 /* Always add it to the observed hash table, so that we can update emblems */
249 ubuntuone_nautilus_add_observed (uon, path, file);
250
251 if (!g_hash_table_lookup (uon->updated, path) &&
252 !g_hash_table_lookup (uon->needsupdating, path) &&
253 ubuntuone_is_storagefs (uon, path, &is_root)) {
254 SyncdaemonFilesystemInterface *interface;
255
256 /* Add the unsynchronized emblem anyway, and update later */
257 nautilus_file_info_add_emblem (file, "ubuntuone-updating");
258
259 interface = (SyncdaemonFilesystemInterface *) syncdaemon_daemon_get_filesystem_interface (uon->syncdaemon);
260 if (interface != NULL) {
261 syncdaemon_filesystem_interface_get_metadata_async (interface,
262 path,
263 nautilus_file_info_is_directory (file),
264 (SyncdaemonGotMetadataFunc) ubuntuone_nautilus_update_meta,
265 uon);
266 goto updating_meta;
267 }
268 }
269
270 if (g_hash_table_lookup (uon->uploads, path) ||
271 g_hash_table_lookup (uon->downloads, path))
272 nautilus_file_info_add_emblem (file, "ubuntuone-updating");
273 else if (g_hash_table_lookup (uon->updated, path))
274 nautilus_file_info_add_emblem (file, "ubuntuone-synchronized");
275 else if (g_hash_table_lookup (uon->needsupdating, path))
276 nautilus_file_info_add_emblem (file, "ubuntuone-updating");
277
278 if (g_hash_table_lookup (uon->udfs, path))
279 nautilus_file_info_add_emblem (file, "ubuntuone-enabled");
280
281 if (g_hash_table_lookup (uon->public, path))
282 nautilus_file_info_add_emblem (file, "ubuntuone-public");
283
284 if (g_hash_table_lookup (uon->shares, path))
285 nautilus_file_info_add_emblem (file, "shared");
286
287 updating_meta:
288 g_free (path);
289
290 return NAUTILUS_OPERATION_COMPLETE;
291}77}
29278
293static void ubuntuone_nautilus_info_provider_iface_init (NautilusInfoProviderIface * iface) {79static void
294 iface->update_file_info = ubuntuone_nautilus_update_file_info;80ubuntuone_nautilus_info_provider_iface_init (NautilusInfoProviderIface * iface)
81{
82 iface->update_file_info = ubuntuone_nautilus_update_file_info;
295}83}
29684
297/* LocationWidget provider */85/* LocationWidget provider */
298static GtkWidget * ubuntuone_nautilus_get_location_widget (NautilusLocationWidgetProvider * provider,86static GtkWidget *
299 const char * uri,87ubuntuone_nautilus_get_location_widget (NautilusLocationWidgetProvider * provider,
300 GtkWidget * parent) {88 const char * uri,
301 UbuntuOneNautilus * uon;89 GtkWidget * parent)
302 gchar *path;90{
303 GtkWidget *location;91 UbuntuOneNautilus * uon;
30492 gchar *path;
305 /* if the bar is disabled, do nothing */93 GtkWidget *location;
306 if (!ubuntuone_is_location_bar_enabled ())94
307 return NULL;95 /* if the bar is disabled, do nothing */
30896 if (!ubuntuone_is_location_bar_enabled ())
309 uon = UBUNTUONE_NAUTILUS (provider);97 return NULL;
31098
311 /* If syncdaemon is not ready, do nothing */99 uon = UBUNTUONE_NAUTILUS (provider);
312 if (!syncdaemon_daemon_is_ready (uon->syncdaemon))100
313 return NULL;101 /* If syncdaemon is not ready, do nothing */
314102 if (!syncdaemon_daemon_is_ready (uon->syncdaemon))
315 path = g_filename_from_uri (uri, NULL, NULL);103 return NULL;
316104
317 if (!path)105 path = g_filename_from_uri (uri, NULL, NULL);
318 return NULL;106 if (!path)
319107 return NULL;
320 location = location_widget_new (uon, path);108
321109 location = location_widget_new (uon, path);
322 g_free (path);110
323111 g_free (path);
324 return location;112
113 return location;
325}114}
326115
327static void ubuntuone_nautilus_bar_provider_iface_init (NautilusLocationWidgetProviderIface * iface) {116static void
328 iface->get_widget = ubuntuone_nautilus_get_location_widget;117ubuntuone_nautilus_bar_provider_iface_init (NautilusLocationWidgetProviderIface * iface)
118{
119 iface->get_widget = ubuntuone_nautilus_get_location_widget;
329}120}
330121
331/* Menu provider */122/* Menu provider */
@@ -334,522 +125,274 @@
334 GtkWidget * window,125 GtkWidget * window,
335 GList * files)126 GList * files)
336{127{
337 UbuntuOneNautilus * uon;128 UbuntuOneNautilus * uon;
338 GList *items = NULL;129 GList *items = NULL;
339 NautilusMenuItem *root_item;130 NautilusMenuItem *root_item;
340131
341 uon = UBUNTUONE_NAUTILUS (provider);132 uon = UBUNTUONE_NAUTILUS (provider);
342133
343 /* If syncdaemon is not ready, do nothing */134 /* If syncdaemon is not ready, do nothing */
344 if (!syncdaemon_daemon_is_ready (uon->syncdaemon))135 if (!syncdaemon_daemon_is_ready (uon->syncdaemon))
345 return NULL;136 return NULL;
346137
347 root_item = context_menu_new (uon, window, files);138 root_item = context_menu_new (uon, window, files);
348 if (root_item != NULL)139 if (root_item != NULL)
349 items = g_list_append (items, root_item);140 items = g_list_append (items, root_item);
350141
351 return items;142 return items;
352}143}
353144
354static GList * ubuntuone_nautilus_get_bg_menu_items (NautilusMenuProvider * provider,145static GList *
355 GtkWidget * window,146ubuntuone_nautilus_get_bg_menu_items (NautilusMenuProvider * provider,
356 NautilusFileInfo * folder) {147 GtkWidget * window,
357 GList * files = NULL;148 NautilusFileInfo * folder)
358 GList * items = NULL;149{
359150 GList * files = NULL;
360 files = g_list_prepend (files, folder);151 GList * items = NULL;
361 items = ubuntuone_nautilus_get_menu_items (provider, window, files);152
362 files = g_list_remove (files, folder);153 files = g_list_prepend (files, folder);
363 g_list_free (files);154 items = ubuntuone_nautilus_get_menu_items (provider, window, files);
364155 files = g_list_remove (files, folder);
365 return items;156 g_list_free (files);
366}157
367158 return items;
368static void ubuntuone_nautilus_menu_provider_iface_init (NautilusMenuProviderIface * iface) {159}
369 iface->get_file_items = ubuntuone_nautilus_get_menu_items;160
370 iface->get_background_items = ubuntuone_nautilus_get_bg_menu_items;161static void
162ubuntuone_nautilus_menu_provider_iface_init (NautilusMenuProviderIface * iface)
163{
164 iface->get_file_items = ubuntuone_nautilus_get_menu_items;
165 iface->get_background_items = ubuntuone_nautilus_get_bg_menu_items;
371}166}
372167
373/* GType and nautilus module stuff */168/* GType and nautilus module stuff */
374static GType un_type = 0;169static GType un_type = 0;
375170
376static void ubuntuone_nautilus_instance_init (UbuntuOneNautilus * uon) {171static void
377 uon->connected = FALSE;172ubuntuone_nautilus_instance_init (UbuntuOneNautilus * uon)
378 uon->uploads = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);173{
379 uon->downloads = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);174 uon->connected = FALSE;
380 uon->shares = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);175 uon->shares = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
381 uon->updated = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);176 uon->udfs = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
382 uon->needsupdating = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);177 uon->public = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
383 uon->observed = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);178
384 uon->udfs = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);179 uon->syncdaemon = syncdaemon_daemon_new ();
385 uon->public = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);180 g_signal_connect (G_OBJECT (uon->syncdaemon), "ready",
386181 G_CALLBACK (ubuntuone_nautilus_daemon_ready), uon);
387 uon->syncdaemon = syncdaemon_daemon_new ();182
388 g_signal_connect (G_OBJECT (uon->syncdaemon), "ready",183 /* Create a FileWatcher object to watch files we know about from Nautilus */
389 G_CALLBACK (ubuntuone_nautilus_daemon_ready), uon);184 uon->file_watcher = file_watcher_new (uon);
390185
391 /* Default to ~/Ubuntu One for now, as it's all we really support */186 /* Default to ~/Ubuntu One for now, as it's all we really support */
392 uon->managed = g_build_filename (g_get_home_dir (), "Ubuntu One", NULL);187 uon->managed = g_build_filename (g_get_home_dir (), "Ubuntu One", NULL);
393 uon->gotroot = FALSE;188 uon->gotroot = FALSE;
394 uon->gotudfs = FALSE;189 uon->gotudfs = FALSE;
395 uon->gotpubs = FALSE;190 uon->gotpubs = FALSE;
396191}
397 /* Connec to status-related signals */192
398 g_signal_connect (G_OBJECT (uon->syncdaemon), "upload_started",193static void
399 G_CALLBACK (ubuntuone_nautilus_upload_started), uon);194ubuntuone_nautilus_class_init (UbuntuOneNautilusClass * klass)
400 g_signal_connect (G_OBJECT (uon->syncdaemon), "upload_finished",195{
401 G_CALLBACK (ubuntuone_nautilus_upload_finished), uon);196 parent_class = g_type_class_peek_parent (klass);
402 g_signal_connect (G_OBJECT (uon->syncdaemon), "download_started",197
403 G_CALLBACK (ubuntuone_nautilus_download_started), uon);198 G_OBJECT_CLASS(klass)->finalize = ubuntuone_nautilus_finalize;
404 g_signal_connect (G_OBJECT (uon->syncdaemon), "download_finished",199}
405 G_CALLBACK (ubuntuone_nautilus_download_finished), uon);200
406201static void
407 /* Connect to shares-related signals */202ubuntuone_nautilus_finalize (GObject *object)
408 g_signal_connect (G_OBJECT (uon->syncdaemon), "share_created",203{
409 G_CALLBACK (ubuntuone_nautilus_share_created), uon);204 UbuntuOneNautilus * uon = UBUNTUONE_NAUTILUS(object);
410 g_signal_connect (G_OBJECT (uon->syncdaemon), "share_deleted",205
411 G_CALLBACK (ubuntuone_nautilus_share_deleted), uon);206 if (uon->file_watcher != NULL)
412207 g_object_unref (G_OBJECT (uon->file_watcher));
413 /* Connect to folder-related signals */208
414 g_signal_connect (G_OBJECT (uon->syncdaemon), "folder_created",209 if (uon->syncdaemon)
415 G_CALLBACK (ubuntuone_nautilus_udf_created), uon);210 g_object_unref (uon->syncdaemon);
416 g_signal_connect (G_OBJECT (uon->syncdaemon), "folder_subscribed",211
417 G_CALLBACK (ubuntuone_nautilus_udf_created), uon);212 g_hash_table_destroy (uon->shares);
418 g_signal_connect (G_OBJECT (uon->syncdaemon), "folder_deleted",213 uon->shares = NULL;
419 G_CALLBACK (ubuntuone_nautilus_udf_deleted), uon);214
420 g_signal_connect (G_OBJECT (uon->syncdaemon), "folder_unsubscribed",215 g_hash_table_destroy (uon->udfs);
421 G_CALLBACK (ubuntuone_nautilus_udf_deleted), uon);216 uon->udfs = NULL;
422217
423 /* Connect to public files-related signals */218 g_hash_table_destroy (uon->public);
424 g_signal_connect (G_OBJECT (uon->syncdaemon), "file_published",219 uon->public = NULL;
425 G_CALLBACK (ubuntuone_nautilus_file_published), uon);220}
426 g_signal_connect (G_OBJECT (uon->syncdaemon), "got_published_files",221
427 G_CALLBACK (ubuntuone_nautilus_got_public_files), uon);222GType
428223ubuntuone_nautilus_get_type (void)
429}224{
430225 return un_type;
431static void ubuntuone_nautilus_class_init (UbuntuOneNautilusClass * klass) {226}
432 parent_class = g_type_class_peek_parent (klass);227
433228static void
434 G_OBJECT_CLASS(klass)->finalize = ubuntuone_nautilus_finalize;229ubuntuone_nautilus_register_type (GTypeModule * module)
435}230{
436231 static const GTypeInfo info = {
437static void ubuntuone_nautilus_finalize(GObject * object) {232 sizeof (UbuntuOneNautilusClass),
438 UbuntuOneNautilus * uon = UBUNTUONE_NAUTILUS(object);233 (GBaseInitFunc) NULL,
439234 (GBaseFinalizeFunc) NULL,
440 if (uon->syncdaemon)235 (GClassInitFunc) ubuntuone_nautilus_class_init,
441 g_object_unref (uon->syncdaemon);236 NULL,
442237 NULL,
443 g_hash_table_destroy (uon->uploads);238 sizeof (UbuntuOneNautilus),
444 uon->uploads = NULL;239 0,
445240 (GInstanceInitFunc) ubuntuone_nautilus_instance_init,
446 g_hash_table_destroy (uon->downloads);241 };
447 uon->downloads = NULL;242
448243 static const GInterfaceInfo info_provider_iface_info = {
449 g_hash_table_destroy (uon->shares);244 (GInterfaceInitFunc) ubuntuone_nautilus_info_provider_iface_init,
450 uon->shares = NULL;245 NULL,
451246 NULL
452 g_hash_table_destroy (uon->udfs);247 };
453 uon->udfs = NULL;248
454249 static const GInterfaceInfo bar_provider_iface_info = {
455 g_hash_table_destroy (uon->public);250 (GInterfaceInitFunc) ubuntuone_nautilus_bar_provider_iface_init,
456 uon->public = NULL;251 NULL,
457252 NULL
458 g_hash_table_destroy (uon->updated);253 };
459 uon->updated = NULL;254
460255 static const GInterfaceInfo menu_provider_iface_info = {
461 g_hash_table_destroy (uon->needsupdating);256 (GInterfaceInitFunc) ubuntuone_nautilus_menu_provider_iface_init,
462 uon->needsupdating = NULL;257 NULL,
463258 NULL
464 /* We need to remove all weak reference callbacks */259 };
465 g_hash_table_foreach (uon->observed, 260
466 (GHFunc)ubuntuone_nautilus_observed_file_foreach_unref,261 un_type = g_type_module_register_type (module,
467 uon);262 G_TYPE_OBJECT,
468263 "UbuntuOneNautilus",
469 g_hash_table_destroy (uon->observed);264 &info, 0);
470 uon->observed = NULL;
471}
472
473GType ubuntuone_nautilus_get_type (void) {
474 return un_type;
475}
476
477static void ubuntuone_nautilus_register_type (GTypeModule * module) {
478 static const GTypeInfo info = {
479 sizeof (UbuntuOneNautilusClass),
480 (GBaseInitFunc) NULL,
481 (GBaseFinalizeFunc) NULL,
482 (GClassInitFunc) ubuntuone_nautilus_class_init,
483 NULL,
484 NULL,
485 sizeof (UbuntuOneNautilus),
486 0,
487 (GInstanceInitFunc) ubuntuone_nautilus_instance_init,
488 };
489
490 static const GInterfaceInfo info_provider_iface_info = {
491 (GInterfaceInitFunc) ubuntuone_nautilus_info_provider_iface_init,
492 NULL,
493 NULL
494 };
495
496 static const GInterfaceInfo bar_provider_iface_info = {
497 (GInterfaceInitFunc) ubuntuone_nautilus_bar_provider_iface_init,
498 NULL,
499 NULL
500 };
501
502 static const GInterfaceInfo menu_provider_iface_info = {
503 (GInterfaceInitFunc) ubuntuone_nautilus_menu_provider_iface_init,
504 NULL,
505 NULL
506 };
507
508 un_type = g_type_module_register_type (module,
509 G_TYPE_OBJECT,
510 "UbuntuOneNautilus",
511 &info, 0);
512 265
513 g_type_module_add_interface (module,266 g_type_module_add_interface (module,
514 un_type,267 un_type,
515 NAUTILUS_TYPE_INFO_PROVIDER,268 NAUTILUS_TYPE_INFO_PROVIDER,
516 &info_provider_iface_info);269 &info_provider_iface_info);
517270
518 g_type_module_add_interface (module,271 g_type_module_add_interface (module,
519 un_type,272 un_type,
520 NAUTILUS_TYPE_LOCATION_WIDGET_PROVIDER,273 NAUTILUS_TYPE_LOCATION_WIDGET_PROVIDER,
521 &bar_provider_iface_info);274 &bar_provider_iface_info);
522275
523 /* XXX Need to sign a request via DBus */276 /* XXX Need to sign a request via DBus */
524 g_type_module_add_interface (module,277 g_type_module_add_interface (module,
525 un_type,278 un_type,
526 NAUTILUS_TYPE_MENU_PROVIDER,279 NAUTILUS_TYPE_MENU_PROVIDER,
527 &menu_provider_iface_info);280 &menu_provider_iface_info);
528}281}
529282
530283
531/* DBus signal handlers and async method call handlers */284/* DBus signal handlers and async method call handlers */
532static void ubuntuone_nautilus_update_meta (SyncdaemonFilesystemInterface *interface,
533 gboolean success,
534 SyncdaemonMetadata *metadata,
535 gpointer user_data) {
536 UbuntuOneNautilus * uon;
537 gchar * path;
538 gboolean is_root;
539
540 if (!success) {
541 g_warning ("ERROR: Could not retrieve metadata");
542 return;
543 }
544
545 uon = UBUNTUONE_NAUTILUS (user_data);
546 path = g_strdup (syncdaemon_metadata_get_path (metadata));
547
548 if (ubuntuone_is_storagefs (uon, path, &is_root)) {
549 if (syncdaemon_metadata_get_is_synced (metadata)) {
550 g_hash_table_replace (uon->updated, path, path);
551 ubuntuone_nautilus_reset_emblem (uon, path);
552 } else
553 g_hash_table_replace (uon->needsupdating, path, path);
554 } else {
555 g_hash_table_remove (uon->updated, path);
556 g_hash_table_remove (uon->needsupdating, path);
557 ubuntuone_nautilus_reset_emblem (uon, path);
558
559 g_free (path);
560 }
561}
562
563static void285static void
564ubuntuone_nautilus_daemon_ready (SyncdaemonDaemon *daemon, gpointer user_data)286ubuntuone_nautilus_daemon_ready (SyncdaemonDaemon *daemon, gpointer user_data)
565{287{
566 UbuntuOneNautilus * uon = UBUNTUONE_NAUTILUS (user_data);288 UbuntuOneNautilus * uon = UBUNTUONE_NAUTILUS (user_data);
567 gboolean is_online = FALSE;289 gboolean is_online = FALSE;
568 SyncdaemonInterface *interface;290 SyncdaemonInterface *interface;
569291
570 interface = syncdaemon_daemon_get_status_interface (daemon);292 interface = syncdaemon_daemon_get_status_interface (daemon);
571 if (interface != NULL) {293 if (interface != NULL) {
572 SyncdaemonStatusInfo *status_info;294 SyncdaemonStatusInfo *status_info;
573295
574 status_info = syncdaemon_status_interface_get_current_status (SYNCDAEMON_STATUS_INTERFACE (interface));296 status_info = syncdaemon_status_interface_get_current_status (SYNCDAEMON_STATUS_INTERFACE (interface));
575 is_online = syncdaemon_status_info_get_online (status_info);297 is_online = syncdaemon_status_info_get_online (status_info);
576 }298 }
577299
578 /* Get the root when we get a status change signal, if we haven't yet */300 /* Get the root when we get a status change signal, if we haven't yet */
579 if (!uon->gotroot) {301 if (!uon->gotroot) {
580 uon->managed = g_strdup (syncdaemon_daemon_get_root_dir (uon->syncdaemon));302 uon->managed = g_strdup (syncdaemon_daemon_get_root_dir (uon->syncdaemon));
581 if (uon->managed != NULL)303 if (uon->managed != NULL)
582 uon->gotroot = TRUE;304 uon->gotroot = TRUE;
583 }305 }
584306
585 /* Get the list of UDFs if we haven't already */307 /* Get the list of UDFs if we haven't already */
586 if (!uon->gotudfs) {308 if (!uon->gotudfs) {
587 SyncdaemonInterface *interface;309 SyncdaemonInterface *interface;
588310
589 interface = syncdaemon_daemon_get_folders_interface (uon->syncdaemon);311 interface = syncdaemon_daemon_get_folders_interface (uon->syncdaemon);
590 if (interface != NULL) {312 if (interface != NULL) {
591 GSList *folders, *l;313 GSList *folders, *l;
592314
593 folders = syncdaemon_folders_interface_get_folders (SYNCDAEMON_FOLDERS_INTERFACE (interface));315 folders = syncdaemon_folders_interface_get_folders (SYNCDAEMON_FOLDERS_INTERFACE (interface));
594 for (l = folders; l != NULL; l = l->next) {316 for (l = folders; l != NULL; l = l->next) {
595 SyncdaemonFolderInfo *folder_info = SYNCDAEMON_FOLDER_INFO (l->data);317 const gchar *path, *id;
596318 gboolean subscribed;
597 ubuntuone_nautilus_udf_created (uon->syncdaemon, TRUE, folder_info, uon);319 SyncdaemonFolderInfo *folder_info = SYNCDAEMON_FOLDER_INFO (l->data);
598 uon->gotudfs = TRUE;320
599 }321 path = syncdaemon_folder_info_get_path (folder_info);
600322 id = syncdaemon_folder_info_get_volume_id (folder_info);
601 g_slist_free (folders);323 subscribed = syncdaemon_folder_info_get_subscribed (folder_info);
602 }324 if (subscribed) {
603 }325 g_hash_table_insert (uon->udfs, g_strdup (path), g_strdup (id));
604326 uon->gotudfs = TRUE;
605 /* Get the list of shared folders */327
606 interface = syncdaemon_daemon_get_shares_interface (uon->syncdaemon);328 file_watcher_update_path (uon->file_watcher, path);
607 if (SYNCDAEMON_IS_SHARES_INTERFACE (interface)) {329 }
608 GSList *shares;330 }
609331
610 shares = syncdaemon_shares_interface_get_shared (SYNCDAEMON_SHARES_INTERFACE (interface));332 g_slist_free (folders);
611 while (shares != NULL) {333 }
612 ubuntuone_nautilus_share_created (uon->syncdaemon, TRUE, SYNCDAEMON_SHARE_INFO (shares->data), uon);334 }
613 shares = g_slist_remove (shares, shares->data);335
614 }336 /* Get the list of shared folders */
615 }337 interface = syncdaemon_daemon_get_shares_interface (uon->syncdaemon);
616338 if (SYNCDAEMON_IS_SHARES_INTERFACE (interface)) {
617 /* Get the list of public files if we haven't already */339 GSList *shares;
618 if (is_online && !uon->gotpubs) {340
619 SyncdaemonInterface *public;341 shares = syncdaemon_shares_interface_get_shared (SYNCDAEMON_SHARES_INTERFACE (interface));
620342 while (shares != NULL) {
621 public = syncdaemon_daemon_get_publicfiles_interface (uon->syncdaemon);343 const gchar *id, *path;
622 if (public != NULL) {344 SyncdaemonShareInfo *share_info = SYNCDAEMON_SHARE_INFO (shares->data);
623 syncdaemon_publicfiles_interface_get_public_files (SYNCDAEMON_PUBLICFILES_INTERFACE (public));345
624 uon->gotpubs = TRUE;346 /* This code is duplicated in file-watcher.c */
625 }347 path = syncdaemon_share_info_get_path (share_info);
626 }348 id = syncdaemon_share_info_get_volume_id (share_info);
627}349 if (!g_hash_table_lookup (uon->shares, path)) {
628350 g_hash_table_insert (uon->shares, g_strdup (path), g_strdup (id));
629static void ubuntuone_nautilus_upload_started (SyncdaemonDaemon *daemon,351 file_watcher_update_path (uon->file_watcher, path);
630 gchar * path,352 }
631 gpointer user_data) {353
632 UbuntuOneNautilus * uon = UBUNTUONE_NAUTILUS (user_data);354 shares = g_slist_remove (shares, shares->data);
633355 }
634 if (!g_hash_table_lookup (uon->uploads, path)) {356 }
635 gchar *new_path = g_strdup (path);357
636 g_hash_table_insert (uon->uploads, new_path, new_path);358 /* Get the list of public files if we haven't already */
637 ubuntuone_nautilus_reset_emblem (uon, path);359 if (is_online && !uon->gotpubs) {
638 }360 SyncdaemonInterface *public;
639}361
640362 public = syncdaemon_daemon_get_publicfiles_interface (uon->syncdaemon);
641static void ubuntuone_nautilus_upload_finished (SyncdaemonDaemon *daemon,363 if (public != NULL) {
642 gchar * path,364 syncdaemon_publicfiles_interface_get_public_files (SYNCDAEMON_PUBLICFILES_INTERFACE (public));
643 SyncdaemonTransferInfo * info,365 uon->gotpubs = TRUE;
644 gpointer user_data) {366 }
645 UbuntuOneNautilus * uon = UBUNTUONE_NAUTILUS (user_data);367 }
646 gchar * new_path;
647
648 g_hash_table_remove (uon->uploads, path);
649 g_hash_table_remove (uon->needsupdating, path);
650
651 new_path = g_strdup (path);
652 g_hash_table_replace (uon->updated, new_path, new_path);
653
654 ubuntuone_nautilus_reset_emblem (uon, path);
655}
656
657static void ubuntuone_nautilus_download_started (SyncdaemonDaemon *daemon,
658 gchar * path,
659 gpointer user_data) {
660 UbuntuOneNautilus * uon = UBUNTUONE_NAUTILUS (user_data);
661
662 if (!g_hash_table_lookup (uon->downloads, path)) {
663 gchar *new_path = g_strdup (path);
664 g_hash_table_insert (uon->downloads, new_path, new_path);
665 ubuntuone_nautilus_reset_emblem (uon, path);
666 }
667}
668
669static void ubuntuone_nautilus_download_finished (SyncdaemonDaemon *daemon,
670 gchar * path,
671 SyncdaemonTransferInfo * info,
672 gpointer user_data) {
673 UbuntuOneNautilus * uon = UBUNTUONE_NAUTILUS (user_data);
674 gchar * new_path;
675
676 g_hash_table_remove (uon->downloads, path);
677 g_hash_table_remove (uon->needsupdating, path);
678
679 new_path = g_strdup (path);
680 g_hash_table_replace (uon->updated, new_path, new_path);
681
682 ubuntuone_nautilus_reset_emblem (uon, path);
683}
684
685static void ubuntuone_nautilus_udf_created (SyncdaemonDaemon *daemon,
686 gboolean success,
687 SyncdaemonFolderInfo *folder_info,
688 gpointer user_data) {
689 UbuntuOneNautilus * uon = UBUNTUONE_NAUTILUS (user_data);
690 const gchar * path, * id;
691 gboolean subscribed;
692
693 path = syncdaemon_folder_info_get_path (folder_info);
694 id = syncdaemon_folder_info_get_volume_id (folder_info);
695 subscribed = syncdaemon_folder_info_get_subscribed (folder_info);
696 if (success) {
697 if (!g_hash_table_lookup (uon->udfs, path)) {
698 if (subscribed) {
699 GHashTableIter iter;
700 gchar *key;
701 NautilusFileInfo *file;
702
703 g_hash_table_insert (uon->udfs, g_strdup (path), g_strdup (id));
704
705 /* Update the emblems of the files on this new UDF */
706 g_hash_table_iter_init (&iter, uon->observed);
707 while (g_hash_table_iter_next (&iter, (gpointer *) &key, (gpointer *) &file)) {
708 if (g_str_has_prefix (key, path))
709 nautilus_file_info_add_emblem (file, "ubuntuone-updating");
710 }
711 }
712 }
713 }
714}
715
716static gboolean
717remove_by_path_in_hash (gpointer key, gpointer value, gpointer user_data)
718{
719 if (g_str_has_prefix ((const gchar *) key, (const gchar *) user_data) ||
720 g_strcmp0 ((const gchar *) key, (const gchar *) user_data) == 0)
721 return TRUE;
722
723 return FALSE;
724}
725
726static void
727ubuntuone_nautilus_udf_deleted (SyncdaemonDaemon *daemon,
728 gboolean success,
729 SyncdaemonFolderInfo *folder_info,
730 gpointer user_data)
731{
732 UbuntuOneNautilus * uon = UBUNTUONE_NAUTILUS (user_data);
733 const gchar * path;
734
735 path = syncdaemon_folder_info_get_path (folder_info);
736 if (path != NULL && success) {
737 g_hash_table_remove (uon->udfs, path);
738 ubuntuone_nautilus_reset_emblem (uon, path);
739
740 /* Now remove the files from the status hash tables */
741 g_hash_table_foreach_remove (uon->updated, (GHRFunc) remove_by_path_in_hash, (gpointer) path);
742 g_hash_table_foreach_remove (uon->needsupdating, (GHRFunc) remove_by_path_in_hash, (gpointer) path);
743 }
744}
745
746static void ubuntuone_nautilus_file_published (SyncdaemonDaemon *daemon,
747 gboolean success,
748 SyncdaemonFileInfo *finfo,
749 gpointer user_data) {
750 UbuntuOneNautilus * uon = UBUNTUONE_NAUTILUS (user_data);
751 const gchar * path, * url;
752 gboolean is_public;
753
754 if (!success)
755 return;
756
757 path = syncdaemon_file_info_get_path (finfo);
758 url = syncdaemon_file_info_get_public_url (finfo);
759 is_public = syncdaemon_file_info_get_is_public (finfo);
760
761 if (!is_public && g_hash_table_lookup (uon->public, path))
762 g_hash_table_remove (uon->public, path);
763
764 if (is_public)
765 g_hash_table_replace (uon->public, g_strdup (path), g_strdup (url));
766
767 ubuntuone_nautilus_reset_emblem (uon, path);
768 uon->gotpubs = TRUE;
769}
770
771static void ubuntuone_nautilus_got_public_files (SyncdaemonDaemon *daemon,
772 gboolean success,
773 GSList *files,
774 gpointer user_data) {
775 UbuntuOneNautilus * uon = UBUNTUONE_NAUTILUS (user_data);
776
777 if (success) {
778 GSList *l;
779
780 g_hash_table_remove_all (uon->public);
781 for (l = files; l != NULL; l = l->next) {
782 SyncdaemonFileInfo *finfo = SYNCDAEMON_FILE_INFO (l->data);
783
784 g_hash_table_insert (uon->public,
785 g_strdup (syncdaemon_file_info_get_path (finfo)),
786 g_strdup (syncdaemon_file_info_get_public_url (finfo)));
787 }
788 }
789}
790
791static void
792ubuntuone_nautilus_share_created (SyncdaemonDaemon *daemon,
793 gboolean success,
794 SyncdaemonShareInfo *share_info,
795 gpointer user_data)
796{
797 UbuntuOneNautilus * uon = UBUNTUONE_NAUTILUS (user_data);
798 const gchar * path;
799
800 path = syncdaemon_share_info_get_path (share_info);
801 if (success) {
802 const gchar * id;
803
804 id = syncdaemon_share_info_get_volume_id (share_info);
805 if (!g_hash_table_lookup (uon->shares, path)) {
806 g_hash_table_insert (uon->shares, g_strdup (path), g_strdup (id));
807 ubuntuone_nautilus_reset_emblem (uon, path);
808 }
809 } else {
810 ubuntuone_show_error_dialog (uon, _("Error creating share."),
811 _("There was an error sharing the folder '%s'"),
812 path);
813 }
814}
815
816static void
817ubuntuone_nautilus_share_deleted (SyncdaemonDaemon *daemon,
818 gboolean success,
819 SyncdaemonShareInfo *share_info,
820 gpointer user_data)
821{
822 UbuntuOneNautilus * uon = UBUNTUONE_NAUTILUS (user_data);
823 const gchar * path;
824
825 path = syncdaemon_share_info_get_path (share_info);
826 if (success) {
827 g_hash_table_remove (uon->shares, path);
828 ubuntuone_nautilus_reset_emblem (uon, path);
829 }
830}368}
831369
832/* Required Nautilus module handling methods */370/* Required Nautilus module handling methods */
833void nautilus_module_initialize (GTypeModule * module) {371void
372nautilus_module_initialize (GTypeModule *module)
373{
834#ifdef ENABLE_NLS374#ifdef ENABLE_NLS
835 bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);375 bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
836 bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");376 bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
837 textdomain (GETTEXT_PACKAGE);377 textdomain (GETTEXT_PACKAGE);
838#endif378#endif
839379
840 ubuntuone_nautilus_register_type (module);380 ubuntuone_nautilus_register_type (module);
841}381}
842382
843void nautilus_module_shutdown (void) {383void
844}384nautilus_module_shutdown (void)
845385{
846386}
847void nautilus_module_list_types (const GType ** types,387
848 int * num_types) {388void
849 static GType type_list[1];389nautilus_module_list_types (const GType **types,
390 int *num_types)
391{
392 static GType type_list[1];
850 393
851 type_list[0] = UBUNTUONE_TYPE_NAUTILUS;394 type_list[0] = UBUNTUONE_TYPE_NAUTILUS;
852395
853 *types = type_list;396 *types = type_list;
854 *num_types = 1;397 *num_types = 1;
855}398}
856399
=== modified file 'nautilus/ubuntuone-nautilus.h'
--- nautilus/ubuntuone-nautilus.h 2010-09-22 11:12:43 +0000
+++ nautilus/ubuntuone-nautilus.h 2010-10-08 07:48:50 +0000
@@ -27,6 +27,7 @@
27#include <dbus/dbus-glib.h>27#include <dbus/dbus-glib.h>
28#include <libsyncdaemon/syncdaemon-daemon.h>28#include <libsyncdaemon/syncdaemon-daemon.h>
29#include <gtk/gtk.h>29#include <gtk/gtk.h>
30#include "file-watcher.h"
3031
31#define UBUNTUONE_TYPE_NAUTILUS (ubuntuone_nautilus_get_type ())32#define UBUNTUONE_TYPE_NAUTILUS (ubuntuone_nautilus_get_type ())
32#define UBUNTUONE_NAUTILUS(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), UBUNTUONE_TYPE_NAUTILUS, UbuntuOneNautilus))33#define UBUNTUONE_NAUTILUS(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), UBUNTUONE_TYPE_NAUTILUS, UbuntuOneNautilus))
@@ -34,10 +35,11 @@
34/* This is used when a change is pending */35/* This is used when a change is pending */
35#define UPDATE_PENDING "pending"36#define UPDATE_PENDING "pending"
3637
37typedef struct {38struct _UbuntuOneNautilus {
38 GObject parent_slot;39 GObject parent_slot;
3940
40 SyncdaemonDaemon * syncdaemon;41 SyncdaemonDaemon *syncdaemon;
42 FileWatcher *file_watcher;
4143
42 /* Are we connected? */44 /* Are we connected? */
43 gboolean connected;45 gboolean connected;
@@ -51,21 +53,12 @@
51 gboolean gotpubs;53 gboolean gotpubs;
5254
53 /* Lists of ul/dl/shares for setting emblems */55 /* Lists of ul/dl/shares for setting emblems */
54 GHashTable * uploads;
55 GHashTable * downloads;
56 GHashTable * shares;56 GHashTable * shares;
5757
58 /* Lists of public files and user defined folders */58 /* Lists of public files and user defined folders */
59 GHashTable * public;59 GHashTable * public;
60 GHashTable * udfs;60 GHashTable * udfs;
61 61};
62 /* Lists of sync/unsync'd files */
63 GHashTable * updated;
64 GHashTable * needsupdating;
65
66 /* List of files that are observed for changes */
67 GHashTable * observed;
68} UbuntuOneNautilus;
6962
70typedef struct {63typedef struct {
71 GObjectClass parent_slot;64 GObjectClass parent_slot;
@@ -74,16 +67,11 @@
74GType ubuntuone_nautilus_get_type (void);67GType ubuntuone_nautilus_get_type (void);
7568
76/* Utility functions */69/* Utility functions */
77gboolean ubuntuone_is_storagefs (UbuntuOneNautilus * uon,
78 const char * path,
79 gboolean * is_root);
80gboolean ubuntuone_is_location_bar_enabled (void);70gboolean ubuntuone_is_location_bar_enabled (void);
8171
82gboolean ubuntuone_nautilus_check_shares_and_public_files (UbuntuOneNautilus *uon,72gboolean ubuntuone_check_shares_and_public_files (UbuntuOneNautilus *uon,
83 SyncdaemonFolderInfo *folder_info,73 SyncdaemonFolderInfo *folder_info,
84 GtkWidget *widget);74 GtkWidget *widget);
85void ubuntuone_nautilus_reset_emblem (UbuntuOneNautilus * uon, const char * path);
86
87void ubuntuone_show_error_dialog (UbuntuOneNautilus *uon, const gchar *title, const gchar *error_message, ...);75void ubuntuone_show_error_dialog (UbuntuOneNautilus *uon, const gchar *title, const gchar *error_message, ...);
8876
89#endif77#endif
9078
=== modified file 'nautilus/utils.c'
--- nautilus/utils.c 2010-09-22 11:12:43 +0000
+++ nautilus/utils.c 2010-10-08 07:48:50 +0000
@@ -21,15 +21,14 @@
2121
22#include <glib/gi18n.h>22#include <glib/gi18n.h>
23#include <libnautilus-extension/nautilus-file-info.h>23#include <libnautilus-extension/nautilus-file-info.h>
24#include <libsyncdaemon/syncdaemon-shares-interface.h>24#include <libsyncdaemon/libsyncdaemon.h>
25#include "ubuntuone-nautilus.h"25#include "ubuntuone-nautilus.h"
26#include "location-widget.h"26#include "location-widget.h"
2727
28/* this is the wrong place for this, but it'll have to do for now */
29gboolean28gboolean
30ubuntuone_nautilus_check_shares_and_public_files (UbuntuOneNautilus *uon,29ubuntuone_check_shares_and_public_files (UbuntuOneNautilus *uon,
31 SyncdaemonFolderInfo *folder_info,30 SyncdaemonFolderInfo *folder_info,
32 GtkWidget *widget)31 GtkWidget *widget)
33{32{
34 SyncdaemonInterface *interface;33 SyncdaemonInterface *interface;
35 gboolean result = TRUE, has_shares = FALSE, has_published = FALSE;34 gboolean result = TRUE, has_shares = FALSE, has_published = FALSE;
@@ -122,18 +121,3 @@
122 return show_location;121 return show_location;
123}122}
124123
125void
126ubuntuone_nautilus_reset_emblem (UbuntuOneNautilus *uon, const char *path)
127{
128 GHashTableIter iter;
129 gchar *key;
130 NautilusFileInfo *file;
131
132 /* Remove emblems from all files in the specified path */
133 g_hash_table_iter_init (&iter, uon->observed);
134 while (g_hash_table_iter_next (&iter, (gpointer *) &key, (gpointer *) &file)) {
135 if (g_str_has_prefix (key, path) || g_strcmp0 (key, path) == 0) {
136 nautilus_file_info_invalidate_extension_info (file);
137 }
138 }
139}
140124
=== modified file 'po/POTFILES.in'
--- po/POTFILES.in 2010-10-05 14:06:15 +0000
+++ po/POTFILES.in 2010-10-08 07:48:50 +0000
@@ -9,6 +9,7 @@
9nautilus/ubuntuone-nautilus.c9nautilus/ubuntuone-nautilus.c
10nautilus/contacts-view.c10nautilus/contacts-view.c
11nautilus/context-menu.c11nautilus/context-menu.c
12nautilus/file-watcher.c
12nautilus/u1-contacts-picker.c13nautilus/u1-contacts-picker.c
13nautilus/location-widget.c14nautilus/location-widget.c
14nautilus/share-dialog.c15nautilus/share-dialog.c

Subscribers

People subscribed via source and target branches