Merge lp:~rodrigo-moya/ubuntuone-client/re-add-places into lp:ubuntuone-client

Proposed by Rodrigo Moya
Status: Merged
Approved by: John Lenton
Approved revision: 731
Merged at revision: 728
Proposed branch: lp:~rodrigo-moya/ubuntuone-client/re-add-places
Merge into: lp:ubuntuone-client
Diff against target: 178 lines (+112/-3)
3 files modified
configure.ac (+1/-0)
gsd-plugin/gsd-ubuntuone.c (+110/-1)
gsd-plugin/gsd-ubuntuone.h (+1/-2)
To merge this branch: bzr merge lp:~rodrigo-moya/ubuntuone-client/re-add-places
Reviewer Review Type Date Requested Status
John Lenton (community) Approve
dobey (community) Approve
Review via email: mp+36985@code.launchpad.net

Commit message

Add Ubuntu One root dir to Nautilus places

Description of the change

Add Ubuntu One root dir to Nautilus places

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

I really don't like the way this is working. We should use the API that is in gtkfilesystem.h to do this, rather than editing the file directly.

And if we should edit it directly, we should use the GKeyFile API to do so, I think.

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

As discussed on IRC, gtkfilesystem is a private API, and indeed goes away from $includedir in GTK3, so we shouldn't be using that. This code is what Nautilus uses, and what gtkfilesystem.c internally uses also

Revision history for this message
dobey (dobey) wrote :

But we shouldn't have to duplicate code that is already in a library we're using. But since upstream is brilliant fail in that regard, I'll let it slide.

This however, does introduce a regression. We must only add the bookmark once, when the first successful token retrieval and association is completed, and store a boolean somewhere to remind ourselves that we've done so, to avoid adding the bookmark at every log-in, if the user has decided to remove it, because they don't actually want the bookmark.

review: Needs Fixing
729. By Rodrigo Moya

Only add the U1 folder to Places when we have credentials, and only do it once

Revision history for this message
dobey (dobey) wrote :

In check_bookmark_file() I think you also need to check that the key actually exists. If the key doesn't exist, you will still see a 'FALSE' value for the gboolean, since the _get_bool() can only return either TRUE or FALSE. If the key doesn't exist, and check_bookmark_file() gets called, it could still create the bookmark, even if it shouldn't.

I also wish the added code to use libsyncdaemon, was done with async code, rather than the synchronous calls being made.

review: Needs Fixing
730. By Rodrigo Moya

Check for errors and for U1 folder existence

731. By Rodrigo Moya

Fixed

Revision history for this message
dobey (dobey) :
review: Approve
Revision history for this message
John Lenton (chipaca) :
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-09-23 13:57:58 +0000
3+++ configure.ac 2010-09-30 14:24:46 +0000
4@@ -176,6 +176,7 @@
5 PKG_CHECK_MODULES(SETTINGS_PLUGIN,
6 gtk+-2.0
7 gnome-settings-daemon
8+ gconf-2.0
9 )
10
11 AC_SUBST(SETTINGS_PLUGIN_CFLAGS)
12
13=== modified file 'gsd-plugin/gsd-ubuntuone.c'
14--- gsd-plugin/gsd-ubuntuone.c 2010-07-29 14:41:36 +0000
15+++ gsd-plugin/gsd-ubuntuone.c 2010-09-30 14:24:46 +0000
16@@ -23,6 +23,7 @@
17
18 #include <glib/gi18n-lib.h>
19 #include <gmodule.h>
20+#include <gconf/gconf-client.h>
21 #include <gtk/gtk.h>
22
23 #include "gnome-settings-daemon/gnome-settings-plugin.h"
24@@ -39,6 +40,7 @@
25 #define NO_SPACE_TITLE _("Out of space")
26 #define UPGRADE_SUBSCRIPTION_TEXT _("Upgrade Subscription")
27 #define UPGRADE_SUBSCRIPTION_URI "http://one.ubuntu.com/plans/"
28+#define CHECKED_BOOKMARK_FILE_KEY "/apps/gnome_settings_daemon/plugins/ubuntuone/checked_bookmark_file"
29
30 static void
31 dialog_closed_callback (GtkDialog *dialog,
32@@ -117,10 +119,108 @@
33 }
34 }
35
36+static void
37+bookmark_file_loaded (GObject *source, GAsyncResult *res, gpointer user_data)
38+{
39+ gchar *contents = NULL;
40+ GError *error = NULL;
41+
42+ g_file_load_contents_finish (G_FILE (source), res, &contents, NULL, NULL, &error);
43+ if (error == NULL) {
44+ gchar **lines, *u1_location;
45+ gint i;
46+ gboolean add_it = TRUE;
47+
48+ u1_location = g_build_filename ("file://", g_get_home_dir (), "Ubuntu%20One", NULL);
49+
50+ lines = g_strsplit (contents, "\n", -1);
51+ for (i = 0; lines[i] != NULL; i++) {
52+ /* Ignore empty lines */
53+ if (lines[i][0] != '\0' && lines[i][0] != ' ') {
54+ if (g_str_has_prefix (lines[i], u1_location)) {
55+ add_it = FALSE;
56+ break;
57+ }
58+ }
59+ }
60+
61+ if (add_it) {
62+ gchar *new_contents = g_strdup_printf ("%s\n%s Ubuntu One\n", contents, u1_location);
63+
64+ if (g_file_replace_contents (G_FILE (source),
65+ (const gchar *) new_contents,
66+ strlen (new_contents),
67+ NULL,
68+ FALSE,
69+ 0, NULL, NULL, &error)) {
70+ GConfClient *conf_client;
71+
72+ conf_client = gconf_client_get_default ();
73+ gconf_client_set_bool (conf_client, CHECKED_BOOKMARK_FILE_KEY, TRUE, NULL);
74+ } else {
75+ g_warning ("Could not save bookmarks file: %s\n", error->message);
76+ g_error_free (error);
77+ }
78+ }
79+
80+ g_free (contents);
81+ g_free (u1_location);
82+ g_strfreev (lines);
83+ } else {
84+ g_warning ("Could not load bookmark file: %s\n", error->message);
85+ g_error_free (error);
86+ }
87+}
88+
89+static void
90+check_bookmark_file (void)
91+{
92+ gchar *filename;
93+ GConfClient *conf_client;
94+ GError *error = NULL;
95+
96+ /* We only check the bookmark file if we haven't already done so */
97+ conf_client = gconf_client_get_default ();
98+ if (!gconf_client_get_bool (conf_client, CHECKED_BOOKMARK_FILE_KEY, &error)) {
99+ if (error == NULL) {
100+ gchar *u1_folder;
101+
102+ u1_folder = g_build_filename (g_get_home_dir (), "Ubuntu One", NULL);
103+ if (g_file_test ((const gchar *) u1_folder, G_FILE_TEST_IS_DIR)) {
104+ /* Load the bookmark file */
105+ filename = g_build_filename (g_get_home_dir (), ".gtk-bookmarks", NULL);
106+ if (filename != NULL) {
107+ GFile *file;
108+
109+ file = g_file_new_for_path (filename);
110+ g_file_load_contents_async (file, NULL, bookmark_file_loaded, NULL);
111+
112+ g_object_unref (G_OBJECT (file));
113+ g_free (filename);
114+ }
115+ }
116+
117+ g_free (u1_folder);
118+ } else {
119+ g_warning ("Error getting settings: %s\n", error->message);
120+ g_error_free (error);
121+ }
122+ }
123+
124+ g_object_unref (conf_client);
125+}
126+
127+static void
128+credentials_found_cb (SyncdaemonAuthentication *auth, SyncdaemonCredentials *credentials, gpointer user_data)
129+{
130+ check_bookmark_file ();
131+}
132+
133 static gboolean
134 delayed_syncdaemon_start (gpointer data)
135 {
136 GsdUbuntuOne *plugin;
137+ SyncdaemonAuthentication *auth;
138
139 plugin = GSD_UBUNTUONE (data);
140 g_debug ("Performing delayed syncdaemon init");
141@@ -129,6 +229,15 @@
142 plugin->out_of_space_dialog = NULL;
143 g_signal_connect (G_OBJECT (plugin->syncdaemon), "quota_exceeded",
144 G_CALLBACK (quota_exceeded_callback), plugin);
145+
146+ /* Check for authentication */
147+ auth = syncdaemon_daemon_get_authentication (plugin->syncdaemon);
148+ if (syncdaemon_authentication_has_credentials (auth))
149+ check_bookmark_file ();
150+ else
151+ g_signal_connect (auth, "credentials_found",
152+ G_CALLBACK (credentials_found_cb), NULL);
153+
154 return FALSE;
155 }
156
157@@ -152,7 +261,7 @@
158 GsdUbuntuOneClass *klass = GSD_UBUNTUONE_GET_CLASS (object);
159 GObjectClass *parent_class = G_OBJECT_CLASS (klass);
160
161- if (plugin->syncdaemon)
162+ if (plugin->syncdaemon != NULL)
163 g_object_unref (plugin->syncdaemon);
164
165 parent_class->dispose (object);
166
167=== modified file 'gsd-plugin/gsd-ubuntuone.h'
168--- gsd-plugin/gsd-ubuntuone.h 2010-07-14 19:51:54 +0000
169+++ gsd-plugin/gsd-ubuntuone.h 2010-09-30 14:24:46 +0000
170@@ -27,8 +27,7 @@
171 #include <gmodule.h>
172
173 #include "gnome-settings-daemon/gnome-settings-plugin.h"
174-
175-#include <libsyncdaemon/syncdaemon-publicfiles-interface.h>
176+#include <libsyncdaemon/libsyncdaemon.h>
177
178 G_BEGIN_DECLS
179

Subscribers

People subscribed via source and target branches