Merge lp:~rodrigo-moya/ubuntuone-client/check-network-connectivity into lp:ubuntuone-client

Proposed by Rodrigo Moya
Status: Merged
Approved by: Guillermo Gonzalez
Approved revision: 614
Merged at revision: 617
Proposed branch: lp:~rodrigo-moya/ubuntuone-client/check-network-connectivity
Merge into: lp:ubuntuone-client
Diff against target: 464 lines (+269/-4)
11 files modified
configure.ac (+1/-1)
libsyncdaemon/Makefile.am (+2/-0)
libsyncdaemon/libsyncdaemon.h (+1/-0)
libsyncdaemon/syncdaemon-authentication.c (+88/-0)
libsyncdaemon/syncdaemon-authentication.h (+53/-0)
libsyncdaemon/syncdaemon-daemon.c (+42/-1)
libsyncdaemon/syncdaemon-daemon.h (+4/-0)
libsyncdaemon/syncdaemon-status-info.c (+36/-0)
libsyncdaemon/syncdaemon-status-info.h (+2/-0)
libsyncdaemon/test-libsyncdaemon.c (+6/-0)
nautilus/location-widget.c (+34/-2)
To merge this branch: bzr merge lp:~rodrigo-moya/ubuntuone-client/check-network-connectivity
Reviewer Review Type Date Requested Status
Manuel de la Peña (community) Approve
Guillermo Gonzalez Approve
Review via email: mp+31643@code.launchpad.net

Commit message

Deal correctly with no network/no U1 tokens cases when creating UDFs from the Nautilus plugin

Description of the change

Deal correctly with no network/no U1 tokens cases when creating UDFs from the Nautilus plugin

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

Hi,

The "With User" in the status doesn't mean that we have a valid token, just that the user wants to be connected.

see ubuntuone/syncdaemon/states.py @ lines 35-43

review: Needs Fixing
Revision history for this message
Manuel de la Peña (mandel) wrote :

rodrigos code looks good, but I've taken at look at the python and With User seems not to be the correct things, nevertheless, I'm not a big fun of using strings for this type of things, specially WitT diFFerent casing, is error prone ;)

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

As a temporary solution (since I'm going to make use of ubuntu-sso's new DBus interface in the next branch), I've added code to check if the tokens are in the keyring, which is what this branch needs. So, Guillermo, Manuel, can you please review it again?

Revision history for this message
Guillermo Gonzalez (verterok) wrote :

+1 on ubuntu-sso!

review: Approve
Revision history for this message
Manuel de la Peña (mandel) wrote :

+1 looks good to me :D

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'configure.ac'
2--- configure.ac 2010-08-04 08:02:09 +0000
3+++ configure.ac 2010-08-05 09:18:43 +0000
4@@ -112,7 +112,7 @@
5 AC_SUBST(NAUTILUS_CFLAGS)
6 AC_SUBST(NAUTILUS_LIBS)
7
8-PKG_CHECK_MODULES(DBUS, [dbus-glib-1 >= 0.70])
9+PKG_CHECK_MODULES(DBUS, [dbus-glib-1 >= 0.70 gnome-keyring-1])
10 AC_SUBST(DBUS_CFLAGS)
11 AC_SUBST(DBUS_LIBS)
12
13
14=== modified file 'libsyncdaemon/Makefile.am'
15--- libsyncdaemon/Makefile.am 2010-07-20 12:38:17 +0000
16+++ libsyncdaemon/Makefile.am 2010-08-05 09:18:43 +0000
17@@ -21,6 +21,7 @@
18 syncdaemonincludedir = $(includedir)/libsyncdaemon-1.0/libsyncdaemon
19 syncdaemoninclude_HEADERS = \
20 libsyncdaemon.h \
21+ syncdaemon-authentication.h \
22 syncdaemon-daemon.h \
23 syncdaemon-config-interface.h \
24 syncdaemon-events-interface.h \
25@@ -39,6 +40,7 @@
26 libsyncdaemon_1_0_la_SOURCES = \
27 $(MARSHAL_GENERATED) \
28 $(syncdaemoninclude_HEADERS) \
29+ syncdaemon-authentication.c \
30 syncdaemon-daemon.c \
31 syncdaemon-config-interface.c \
32 syncdaemon-events-interface.c \
33
34=== modified file 'libsyncdaemon/libsyncdaemon.h'
35--- libsyncdaemon/libsyncdaemon.h 2010-07-20 12:38:17 +0000
36+++ libsyncdaemon/libsyncdaemon.h 2010-08-05 09:18:43 +0000
37@@ -19,6 +19,7 @@
38 *
39 */
40
41+#include <libsyncdaemon/syncdaemon-authentication.h>
42 #include <libsyncdaemon/syncdaemon-config-interface.h>
43 #include <libsyncdaemon/syncdaemon-daemon.h>
44 #include <libsyncdaemon/syncdaemon-events-interface.h>
45
46=== added file 'libsyncdaemon/syncdaemon-authentication.c'
47--- libsyncdaemon/syncdaemon-authentication.c 1970-01-01 00:00:00 +0000
48+++ libsyncdaemon/syncdaemon-authentication.c 2010-08-05 09:18:43 +0000
49@@ -0,0 +1,88 @@
50+/*
51+ * Syncdaemon API
52+ *
53+ * Authors: Rodrigo Moya <rodrigo.moya@canonical.com>
54+ *
55+ * Copyright 2010 Canonical Ltd.
56+ *
57+ * This program is free software: you can redistribute it and/or modify it
58+ * under the terms of the GNU General Public License version 3, as published
59+ * by the Free Software Foundation.
60+ *
61+ * This program is distributed in the hope that it will be useful, but
62+ * WITHOUT ANY WARRANTY; without even the implied warranties of
63+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
64+ * PURPOSE. See the GNU General Public License for more details.
65+ *
66+ * You should have received a copy of the GNU General Public License along
67+ * with this program. If not, see <http://www.gnu.org/licenses/>.
68+ *
69+ */
70+
71+#include <gnome-keyring.h>
72+#include "syncdaemon-authentication.h"
73+
74+G_DEFINE_TYPE(SyncdaemonAuthentication, syncdaemon_authentication, G_TYPE_OBJECT)
75+
76+struct _SyncdaemonAuthenticationPrivate {
77+ gboolean has_credentials;
78+};
79+
80+static void
81+syncdaemon_authentication_finalize (GObject *object)
82+{
83+ SyncdaemonAuthentication *auth = SYNCDAEMON_AUTHENTICATION (object);
84+
85+ if (auth->priv != NULL) {
86+ g_free (auth->priv);
87+ }
88+
89+ G_OBJECT_CLASS (syncdaemon_authentication_parent_class)->finalize (object);
90+}
91+
92+static void
93+syncdaemon_authentication_class_init (SyncdaemonAuthenticationClass *klass)
94+{
95+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
96+
97+ object_class->finalize = syncdaemon_authentication_finalize;
98+}
99+
100+static void
101+syncdaemon_authentication_init (SyncdaemonAuthentication *auth)
102+{
103+ auth->priv = g_new0 (SyncdaemonAuthenticationPrivate, 1);
104+ auth->priv->has_credentials = FALSE;
105+}
106+
107+/**
108+ * syncdaemon_authentication_has_credentials:
109+ */
110+gboolean
111+syncdaemon_authentication_has_credentials (SyncdaemonAuthentication *auth)
112+{
113+ GnomeKeyringAttributeList *attrs;
114+ GnomeKeyringResult result;
115+ GList *items_found;
116+
117+ g_return_val_if_fail (SYNCDAEMON_IS_AUTHENTICATION (auth), FALSE);
118+
119+ if (auth->priv->has_credentials)
120+ return TRUE;
121+
122+ /* FIXME: use ubuntu-sso's DBus interface when available */
123+ attrs = gnome_keyring_attribute_list_new ();
124+ gnome_keyring_attribute_list_append_string (attrs, "ubuntuone-realm", "https://ubuntuone.com");
125+ gnome_keyring_attribute_list_append_string (attrs, "oauth-consumer-key", "ubuntuone");
126+
127+ result = gnome_keyring_find_items_sync (GNOME_KEYRING_ITEM_GENERIC_SECRET,
128+ attrs, &items_found);
129+ if (result == GNOME_KEYRING_RESULT_OK && items_found != NULL) {
130+ gnome_keyring_found_list_free (items_found);
131+ auth->priv->has_credentials = TRUE;
132+
133+ return TRUE;
134+ }
135+
136+ return FALSE;
137+}
138
139=== added file 'libsyncdaemon/syncdaemon-authentication.h'
140--- libsyncdaemon/syncdaemon-authentication.h 1970-01-01 00:00:00 +0000
141+++ libsyncdaemon/syncdaemon-authentication.h 2010-08-05 09:18:43 +0000
142@@ -0,0 +1,53 @@
143+/*
144+ * Syncdaemon API
145+ *
146+ * Authors: Rodrigo Moya <rodrigo.moya@canonical.com>
147+ *
148+ * Copyright 2010 Canonical Ltd.
149+ *
150+ * This program is free software: you can redistribute it and/or modify it
151+ * under the terms of the GNU General Public License version 3, as published
152+ * by the Free Software Foundation.
153+ *
154+ * This program is distributed in the hope that it will be useful, but
155+ * WITHOUT ANY WARRANTY; without even the implied warranties of
156+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
157+ * PURPOSE. See the GNU General Public License for more details.
158+ *
159+ * You should have received a copy of the GNU General Public License along
160+ * with this program. If not, see <http://www.gnu.org/licenses/>.
161+ *
162+ */
163+
164+#ifndef __SYNCDAEMON_AUTHENTICATION_H__
165+#define __SYNCDAEMON_AUTHENTICATION_H__
166+
167+#include <glib-object.h>
168+
169+G_BEGIN_DECLS
170+
171+#define SYNCDAEMON_TYPE_AUTHENTICATION (syncdaemon_authentication_get_type ())
172+#define SYNCDAEMON_AUTHENTICATION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SYNCDAEMON_TYPE_AUTHENTICATION, SyncdaemonAuthentication))
173+#define SYNCDAEMON_IS_AUTHENTICATION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SYNCDAEMON_TYPE_AUTHENTICATION))
174+#define SYNCDAEMON_AUTHENTICATION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SYNCDAEMON_TYPE_AUTHENTICATION, SyncdaemonAuthenticationClass))
175+#define SYNCDAEMON_IS_AUTHENTICATION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SYNCDAEMON_TYPE_AUTHENTICATION))
176+#define SYNCDAEMON_AUTHENTICATION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SYNCDAEMON_TYPE_AUTHENTICATION, SyncdaemonAuthenticationClass))
177+
178+typedef struct _SyncdaemonAuthenticationPrivate SyncdaemonAuthenticationPrivate;
179+
180+typedef struct {
181+ GObject parent;
182+ SyncdaemonAuthenticationPrivate *priv;
183+} SyncdaemonAuthentication;
184+
185+typedef struct {
186+ GObjectClass parent_class;
187+} SyncdaemonAuthenticationClass;
188+
189+GType syncdaemon_authentication_get_type (void);
190+
191+gboolean syncdaemon_authentication_has_credentials (SyncdaemonAuthentication *auth);
192+
193+G_END_DECLS
194+
195+#endif
196
197=== modified file 'libsyncdaemon/syncdaemon-daemon.c'
198--- libsyncdaemon/syncdaemon-daemon.c 2010-07-26 16:18:00 +0000
199+++ libsyncdaemon/syncdaemon-daemon.c 2010-08-05 09:18:43 +0000
200@@ -54,6 +54,7 @@
201 gboolean ready;
202 gboolean connected;
203 gchar *root_dir;
204+ SyncdaemonAuthentication *auth;
205 };
206
207 /* Signals */
208@@ -105,7 +106,10 @@
209
210 if (daemon->priv->root_dir != NULL)
211 g_free (daemon->priv->root_dir);
212-
213+
214+ if (daemon->priv->auth != NULL)
215+ g_object_unref (G_OBJECT (daemon->priv->auth));
216+
217 g_free (daemon->priv);
218 }
219
220@@ -390,6 +394,7 @@
221 daemon->priv->connected = FALSE;
222 daemon->priv->subinterfaces = g_hash_table_new_full (g_str_hash, g_str_equal,
223 g_free, g_object_unref);
224+ daemon->priv->auth = g_object_new (SYNCDAEMON_TYPE_AUTHENTICATION, NULL);
225
226 /* Initialize DBus */
227 #ifdef HAVE_GDBUS
228@@ -602,6 +607,42 @@
229 return NULL;
230 }
231
232+/**
233+ * syncdaemon_daemon_has_network:
234+ */
235+gboolean
236+syncdaemon_daemon_has_network (SyncdaemonDaemon *daemon)
237+{
238+ SyncdaemonInterface *interface;
239+ gboolean result = FALSE;
240+
241+ g_return_val_if_fail (SYNCDAEMON_IS_DAEMON (daemon), FALSE);
242+
243+ interface = syncdaemon_daemon_get_status_interface (daemon);
244+ if (SYNCDAEMON_IS_STATUS_INTERFACE (interface)) {
245+ SyncdaemonStatusInfo *status_info;
246+
247+ status_info = syncdaemon_status_interface_get_current_status (SYNCDAEMON_STATUS_INTERFACE (interface));
248+ if (g_strrstr (syncdaemon_status_info_get_connection (status_info), "With Network") != NULL)
249+ result = TRUE;
250+
251+ g_object_unref (G_OBJECT (status_info));
252+ }
253+
254+ return result;
255+}
256+
257+/**
258+ * syncdaemon_daemon_get_authentication:
259+ */
260+SyncdaemonAuthentication *
261+syncdaemon_daemon_get_authentication (SyncdaemonDaemon *daemon)
262+{
263+ g_return_val_if_fail (SYNCDAEMON_IS_DAEMON (daemon), NULL);
264+
265+ return daemon->priv->auth;
266+}
267+
268 static SyncdaemonInterface *
269 get_interface (SyncdaemonDaemon *daemon, const gchar *path, SyncdaemonInterface * (* new_func) (SyncdaemonDaemon *daemon))
270 {
271
272=== modified file 'libsyncdaemon/syncdaemon-daemon.h'
273--- libsyncdaemon/syncdaemon-daemon.h 2010-07-20 15:17:43 +0000
274+++ libsyncdaemon/syncdaemon-daemon.h 2010-08-05 09:18:43 +0000
275@@ -23,6 +23,7 @@
276 #define __SYNCDAEMON_DAEMON_H__
277
278 #include <glib-object.h>
279+#include "syncdaemon-authentication.h"
280 #include "syncdaemon-folder-info.h"
281 #include "syncdaemon-interface.h"
282 #include "syncdaemon-share-info.h"
283@@ -90,6 +91,9 @@
284 gboolean syncdaemon_daemon_quit (SyncdaemonDaemon *daemon);
285 const gchar *syncdaemon_daemon_get_root_dir (SyncdaemonDaemon *daemon);
286
287+gboolean syncdaemon_daemon_has_network (SyncdaemonDaemon *daemon);
288+SyncdaemonAuthentication *syncdaemon_daemon_get_authentication (SyncdaemonDaemon *daemon);
289+
290 SyncdaemonInterface *syncdaemon_daemon_get_config_interface (SyncdaemonDaemon *daemon);
291 SyncdaemonInterface *syncdaemon_daemon_get_events_interface (SyncdaemonDaemon *daemon);
292 SyncdaemonInterface *syncdaemon_daemon_get_filesystem_interface (SyncdaemonDaemon *daemon);
293
294=== modified file 'libsyncdaemon/syncdaemon-status-info.c'
295--- libsyncdaemon/syncdaemon-status-info.c 2010-06-24 10:25:12 +0000
296+++ libsyncdaemon/syncdaemon-status-info.c 2010-08-05 09:18:43 +0000
297@@ -24,6 +24,7 @@
298 G_DEFINE_TYPE(SyncdaemonStatusInfo, syncdaemon_status_info, G_TYPE_OBJECT)
299
300 struct _SyncdaemonStatusInfoPrivate {
301+ gchar *connection;
302 gchar *description;
303 gboolean is_connected;
304 gboolean is_online;
305@@ -37,6 +38,15 @@
306 SyncdaemonStatusInfo *sinfo = SYNCDAEMON_STATUS_INFO (object);
307
308 if (sinfo->priv != NULL) {
309+ if (sinfo->priv->connection != NULL)
310+ g_free (sinfo->priv->connection);
311+ if (sinfo->priv->description != NULL)
312+ g_free (sinfo->priv->description);
313+ if (sinfo->priv->name != NULL)
314+ g_free (sinfo->priv->name);
315+ if (sinfo->priv->queues != NULL)
316+ g_free (sinfo->priv->queues);
317+
318 g_free (sinfo->priv);
319 }
320
321@@ -76,6 +86,7 @@
322
323 sinfo = g_object_new (SYNCDAEMON_TYPE_STATUS_INFO, NULL);
324 if (hash != NULL) {
325+ syncdaemon_status_info_set_connection (sinfo, g_hash_table_lookup (hash, "connection"));
326 syncdaemon_status_info_set_description (sinfo, g_hash_table_lookup (hash, "description"));
327 syncdaemon_status_info_set_connected (
328 sinfo,
329@@ -91,6 +102,31 @@
330 }
331
332 /**
333+ * syncdaemon_status_info_get_connection:
334+ */
335+const gchar *
336+syncdaemon_status_info_get_connection (SyncdaemonStatusInfo *sinfo)
337+{
338+ g_return_val_if_fail (SYNCDAEMON_IS_STATUS_INFO (sinfo), NULL);
339+
340+ return (const gchar *) sinfo->priv->connection;
341+}
342+
343+/**
344+ * syncdaemon_status_info_set_connection:
345+ */
346+void
347+syncdaemon_status_info_set_connection (SyncdaemonStatusInfo *sinfo, const gchar *connection)
348+{
349+ g_return_if_fail (SYNCDAEMON_IS_STATUS_INFO (sinfo));
350+
351+ if (sinfo->priv->connection != NULL)
352+ g_free (sinfo->priv->connection);
353+
354+ sinfo->priv->connection = g_strdup (connection);
355+}
356+
357+/**
358 * syncdaemon_status_info_get_connected:
359 */
360 gboolean
361
362=== modified file 'libsyncdaemon/syncdaemon-status-info.h'
363--- libsyncdaemon/syncdaemon-status-info.h 2010-06-24 10:25:12 +0000
364+++ libsyncdaemon/syncdaemon-status-info.h 2010-08-05 09:18:43 +0000
365@@ -49,6 +49,8 @@
366 SyncdaemonStatusInfo *syncdaemon_status_info_new (void);
367 SyncdaemonStatusInfo *syncdaemon_status_info_new_from_hash_table (GHashTable *hash);
368
369+const gchar *syncdaemon_status_info_get_connection (SyncdaemonStatusInfo *sinfo);
370+void syncdaemon_status_info_set_connection (SyncdaemonStatusInfo *sinfo, const gchar *connection);
371 gboolean syncdaemon_status_info_get_connected (SyncdaemonStatusInfo *sinfo);
372 void syncdaemon_status_info_set_connected (SyncdaemonStatusInfo *sinfo, gboolean connected);
373 const gchar *syncdaemon_status_info_get_description (SyncdaemonStatusInfo *sinfo);
374
375=== modified file 'libsyncdaemon/test-libsyncdaemon.c'
376--- libsyncdaemon/test-libsyncdaemon.c 2010-07-23 10:29:23 +0000
377+++ libsyncdaemon/test-libsyncdaemon.c 2010-08-05 09:18:43 +0000
378@@ -51,6 +51,10 @@
379
380 str = syncdaemon_daemon_get_root_dir (the_daemon);
381 g_assert (str != NULL);
382+
383+ syncdaemon_daemon_has_network (the_daemon);
384+ syncdaemon_authentication_has_credentials (
385+ syncdaemon_daemon_get_authentication (the_daemon));
386 }
387
388 static void
389@@ -332,6 +336,7 @@
390
391 /* Test creating a SyncdaemonStatusInfo from a hash table */
392 hash = g_hash_table_new (g_str_hash, g_str_equal);
393+ g_hash_table_insert (hash, "connection", TEST_DESCRIPTION);
394 g_hash_table_insert (hash, "description", TEST_DESCRIPTION);
395 g_hash_table_insert (hash, "is_connected", "True");
396 g_hash_table_insert (hash, "is_online", "False");
397@@ -339,6 +344,7 @@
398 g_hash_table_insert (hash, "queues", TEST_STATUS);
399
400 sinfo = syncdaemon_status_info_new_from_hash_table (hash);
401+ g_assert (g_strcmp0 (syncdaemon_status_info_get_connection (sinfo), TEST_DESCRIPTION) == 0);
402 g_assert (g_strcmp0 (syncdaemon_status_info_get_description (sinfo), TEST_DESCRIPTION) == 0);
403 g_assert (syncdaemon_status_info_get_connected (sinfo));
404 g_assert (syncdaemon_status_info_get_online (sinfo) == FALSE);
405
406=== modified file 'nautilus/location-widget.c'
407--- nautilus/location-widget.c 2010-07-27 11:27:54 +0000
408+++ nautilus/location-widget.c 2010-08-05 09:18:43 +0000
409@@ -266,6 +266,20 @@
410 }
411 }
412
413+static void enable_u1 (LocationWidget *location);
414+
415+static void
416+daemon_connected_cb (SyncdaemonDaemon *daemon, gpointer user_data)
417+{
418+ LocationWidget *location = LOCATION_WIDGET (user_data);
419+
420+ if (syncdaemon_daemon_has_network (daemon) &&
421+ syncdaemon_authentication_has_credentials (
422+ syncdaemon_daemon_get_authentication (daemon))) {
423+ enable_u1 (location);
424+ }
425+}
426+
427 static void
428 enable_u1 (LocationWidget *location)
429 {
430@@ -284,8 +298,16 @@
431 start_spinner (location);
432 gtk_widget_set_sensitive (location->toggle_button, FALSE);
433
434- syncdaemon_folders_interface_create (SYNCDAEMON_FOLDERS_INTERFACE (interface),
435- location->path);
436+ /* If there is no user authenticated, make Syncdaemon do so */
437+ if (syncdaemon_authentication_has_credentials (
438+ syncdaemon_daemon_get_authentication (location->uon->syncdaemon))) {
439+ syncdaemon_folders_interface_create (SYNCDAEMON_FOLDERS_INTERFACE (interface),
440+ location->path);
441+ } else {
442+ g_signal_connect (G_OBJECT (location->uon->syncdaemon), "connected",
443+ G_CALLBACK (daemon_connected_cb), location);
444+ syncdaemon_daemon_connect (location->uon->syncdaemon);
445+ }
446 }
447 }
448
449@@ -506,6 +528,16 @@
450 }
451 }
452
453+ /* Check for connectivity */
454+ if (!syncdaemon_daemon_has_network (location->uon->syncdaemon)) {
455+ gtk_widget_set_sensitive (location->toggle_button, FALSE);
456+ gtk_label_set_text (GTK_LABEL (location->help_label),
457+ _("Operations on this folder are disabled because there is no network "
458+ "connection"));
459+ if (location->expander_status == GTK_ARROW_DOWN)
460+ gtk_widget_show (location->help_label);
461+ }
462+
463 g_signal_connect (G_OBJECT (location->toggle_button), "toggled",
464 G_CALLBACK (sync_toggled_cb), location);
465

Subscribers

People subscribed via source and target branches