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