Merge lp:~rodrigo-moya/ubuntuone-client/use-a-checkbox-and-an-expander into lp:ubuntuone-client

Proposed by Rodrigo Moya
Status: Merged
Approved by: Natalia Bidart
Approved revision: 605
Merged at revision: 606
Proposed branch: lp:~rodrigo-moya/ubuntuone-client/use-a-checkbox-and-an-expander
Merge into: lp:ubuntuone-client
Diff against target: 352 lines (+132/-54)
2 files modified
nautilus/location-widget.c (+125/-52)
nautilus/location-widget.h (+7/-2)
To merge this branch: bzr merge lp:~rodrigo-moya/ubuntuone-client/use-a-checkbox-and-an-expander
Reviewer Review Type Date Requested Status
Natalia Bidart (community) Approve
Alejandro J. Cura (community) Approve
John Lenton Pending
Review via email: mp+31028@code.launchpad.net

Commit message

Use a expander and a checkbox in the Nautilus location bar

Description of the change

Use a expander and a checkbox in the Nautilus location bar

To post a comment you must log in.
602. By Rodrigo Moya

Store expander status in GConf

603. By Rodrigo Moya

Always show the checkbox

604. By Rodrigo Moya

Always show the checkbox

605. By Rodrigo Moya

Fixed resizing

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

Can you please add some instruction about what to test/see? I'm a bit lost on how to be able to see this in action. What should I do in nautilus?

review: Needs Information
Revision history for this message
John Lenton (chipaca) wrote :

On Wed, Jul 28, 2010 at 05:19:43PM -0000, Naty Bidart wrote:
> Review: Needs Information
> Can you please add some instruction about what to test/see? I'm a bit lost on how to be able to see this in action. What should I do in nautilus?

http://people.gnome.org/~rodrigo/location-bar-with-expander.ogv
:)

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

Looks and works great.

review: Approve
Revision history for this message
Natalia Bidart (nataliabidart) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'nautilus/location-widget.c'
2--- nautilus/location-widget.c 2010-07-21 11:41:51 +0000
3+++ nautilus/location-widget.c 2010-07-27 11:29:41 +0000
4@@ -24,6 +24,9 @@
5 #include <libsyncdaemon/syncdaemon-shares-interface.h>
6 #include "location-widget.h"
7
8+#define EXPANDER_STATUS_SECTION "/apps/ubuntuone/nautilus"
9+#define EXPANDER_STATUS_KEY EXPANDER_STATUS_SECTION "/expand-location"
10+
11 G_DEFINE_TYPE(LocationWidget, location_widget, GTK_TYPE_HBOX)
12
13 static void
14@@ -36,7 +39,8 @@
15 gtk_widget_hide (location->help_label);
16 } else {
17 labeltext = g_strdup_printf ("<b>Ubuntu One</b> - %s", _("folder not synchronized"));
18- gtk_widget_show (location->help_label);
19+ if (location->expander_status == GTK_ARROW_DOWN)
20+ gtk_widget_show (location->help_label);
21 }
22
23 gtk_label_set_markup (GTK_LABEL (location->info_label), labeltext);
24@@ -69,14 +73,11 @@
25 if (g_strcmp0 (path, location->path) == 0) {
26 set_label_text (location, success);
27 if (success) {
28- gtk_widget_hide (location->enable_button);
29- gtk_widget_show (location->disable_button);
30- gtk_widget_set_sensitive (location->disable_button, TRUE);
31+ gtk_widget_hide (location->expander);
32+ gtk_widget_set_sensitive (location->toggle_button, TRUE);
33 gtk_widget_hide (location->help_label);
34 } else {
35- gtk_widget_show (location->enable_button);
36- gtk_widget_set_sensitive (location->enable_button, TRUE);
37- gtk_widget_hide (location->disable_button);
38+ gtk_widget_set_sensitive (location->toggle_button, TRUE);
39 ubuntuone_show_error_dialog (location->uon, _("Error enabling folder"),
40 _("Could not enable folder %s for synchronizing to Ubuntu One"),
41 location->path);
42@@ -95,16 +96,14 @@
43 path = syncdaemon_folder_info_get_path (folder_info);
44 if (g_strcmp0 (path, location->path) == 0) {
45 if (success) {
46+ gtk_widget_show (location->expander);
47 set_label_text (location, FALSE);
48- gtk_widget_show (location->enable_button);
49- gtk_widget_set_sensitive (location->enable_button, TRUE);
50- gtk_widget_hide (location->disable_button);
51- gtk_widget_show (location->help_label);
52+ gtk_widget_set_sensitive (location->toggle_button, TRUE);
53+ if (location->expander_status == GTK_ARROW_DOWN)
54+ gtk_widget_show (location->help_label);
55 } else {
56 set_label_text (location, TRUE);
57- gtk_widget_hide (location->enable_button);
58- gtk_widget_show (location->disable_button);
59- gtk_widget_set_sensitive (location->disable_button, TRUE);
60+ gtk_widget_set_sensitive (location->toggle_button, TRUE);
61 ubuntuone_show_error_dialog (location->uon, _("Error disabling folder"),
62 _("Could not disable folder %s for synchronizing to Ubuntu One"),
63 location->path);
64@@ -122,6 +121,12 @@
65 g_signal_handlers_disconnect_by_func (location->uon->syncdaemon, folder_created_cb, location);
66 g_signal_handlers_disconnect_by_func (location->uon->syncdaemon, folder_deleted_cb, location);
67
68+ if (location->conf_notify_id != 0)
69+ gconf_client_notify_remove (location->conf_client, location->conf_notify_id);
70+
71+ if (location->conf_client != NULL)
72+ g_object_unref (G_OBJECT (location->conf_client));
73+
74 if (location->path != NULL)
75 g_free (location->path);
76
77@@ -221,7 +226,7 @@
78 GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (location))),
79 0, GTK_MESSAGE_QUESTION,
80 GTK_BUTTONS_YES_NO,
81- question->str);
82+ "%s", question->str);
83 if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_YES)
84 result = FALSE;
85
86@@ -236,10 +241,9 @@
87 }
88
89 static void
90-disable_u1_cb (GtkButton *button, gpointer user_data)
91+disable_u1 (LocationWidget *location)
92 {
93 SyncdaemonInterface *interface;
94- LocationWidget *location = LOCATION_WIDGET (user_data);
95
96 /* Perform the removal of this folder */
97 interface = syncdaemon_daemon_get_folders_interface (location->uon->syncdaemon);
98@@ -251,9 +255,7 @@
99 location->path);
100 if (folder_info != NULL && check_shared_for_folder (location, folder_info)) {
101 set_label_text (location, FALSE);
102- gtk_widget_hide (location->disable_button);
103- gtk_widget_show (location->enable_button);
104- gtk_widget_set_sensitive (location->enable_button, FALSE);
105+ gtk_widget_set_sensitive (location->toggle_button, FALSE);
106
107 syncdaemon_folders_interface_delete (
108 SYNCDAEMON_FOLDERS_INTERFACE (interface),
109@@ -265,10 +267,9 @@
110 }
111
112 static void
113-enable_u1_cb (GtkButton *button, gpointer user_data)
114+enable_u1 (LocationWidget *location)
115 {
116 SyncdaemonInterface *interface;
117- LocationWidget *location = LOCATION_WIDGET (user_data);
118
119 /* Perform the addition of this folder */
120 interface = syncdaemon_daemon_get_folders_interface (location->uon->syncdaemon);
121@@ -281,7 +282,7 @@
122 g_free (labeltext);
123
124 start_spinner (location);
125- gtk_widget_set_sensitive (location->enable_button, FALSE);
126+ gtk_widget_set_sensitive (location->toggle_button, FALSE);
127
128 syncdaemon_folders_interface_create (SYNCDAEMON_FOLDERS_INTERFACE (interface),
129 location->path);
130@@ -289,54 +290,114 @@
131 }
132
133 static void
134+sync_toggled_cb (GtkToggleButton *button, gpointer user_data)
135+{
136+ LocationWidget *location = LOCATION_WIDGET (user_data);
137+
138+ if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (location->toggle_button)))
139+ enable_u1 (location);
140+ else
141+ disable_u1 (location);
142+}
143+
144+static gboolean
145+expander_clicked_cb (GtkWidget *widget, GdkEventButton *event, gpointer user_data)
146+{
147+ LocationWidget *location = LOCATION_WIDGET (user_data);
148+
149+ if (event->button == 1) {
150+ switch (location->expander_status) {
151+ case GTK_ARROW_DOWN: /* expanded */
152+ gconf_client_set_bool (location->conf_client, EXPANDER_STATUS_KEY, FALSE, NULL);
153+ break;
154+ case GTK_ARROW_RIGHT: /* collapsed */
155+ gconf_client_set_bool (location->conf_client, EXPANDER_STATUS_KEY, TRUE, NULL);
156+ break;
157+ }
158+ }
159+
160+ return FALSE;
161+}
162+
163+static void
164+config_changed_cb (GConfClient *client, guint cnx_id, GConfEntry *entry, gpointer user_data)
165+{
166+ LocationWidget *location = LOCATION_WIDGET (user_data);
167+
168+ if (g_strcmp0 (gconf_entry_get_key (entry), EXPANDER_STATUS_KEY) == 0) {
169+ if (gconf_value_get_bool (gconf_entry_get_value (entry))) {
170+ location->expander_status = GTK_ARROW_DOWN;
171+ gtk_widget_show (location->help_label);
172+ } else {
173+ location->expander_status = GTK_ARROW_RIGHT;
174+ gtk_widget_hide (location->help_label);
175+ }
176+
177+ gtk_arrow_set (GTK_ARROW (location->expander), location->expander_status, GTK_SHADOW_IN);
178+ }
179+}
180+
181+static void
182 location_widget_init (LocationWidget *location)
183 {
184 GtkWidget *table, *box;
185
186 location->path = NULL;
187- location->info_label = location->enable_button = NULL;
188+ location->info_label = NULL;
189+
190+ /* Read expander status from GConf */
191+ location->conf_client = gconf_client_get_default ();
192+ gconf_client_add_dir (location->conf_client, EXPANDER_STATUS_SECTION, GCONF_CLIENT_PRELOAD_RECURSIVE, NULL);
193+ location->conf_notify_id = gconf_client_notify_add (location->conf_client,
194+ EXPANDER_STATUS_SECTION,
195+ (GConfClientNotifyFunc) config_changed_cb,
196+ location,
197+ NULL,
198+ NULL);
199+
200+ if (gconf_client_get_bool (location->conf_client, EXPANDER_STATUS_KEY, NULL))
201+ location->expander_status = GTK_ARROW_DOWN;
202+ else
203+ location->expander_status = GTK_ARROW_RIGHT;
204
205 /* Create the widgets in the interface */
206- table = gtk_table_new (3, 2, FALSE);
207+ table = gtk_table_new (2, 4, FALSE);
208 gtk_widget_show (table);
209 gtk_box_pack_start (GTK_BOX (location), table, TRUE, TRUE, 0);
210
211+ box = gtk_event_box_new ();
212+ g_signal_connect (G_OBJECT (box), "button-press-event",
213+ G_CALLBACK (expander_clicked_cb), location);
214+ gtk_widget_show (box);
215+ gtk_table_attach (GTK_TABLE (table), box, 0, 1, 0, 1,
216+ GTK_FILL, GTK_FILL, 3, 3);
217+
218+ location->expander = gtk_arrow_new (location->expander_status, GTK_SHADOW_IN);
219+ gtk_widget_show (location->expander);
220+ gtk_container_add (GTK_CONTAINER (box), location->expander);
221+
222 location->info_label = gtk_label_new ("<b>Ubuntu One</b>");
223 gtk_label_set_use_markup (GTK_LABEL (location->info_label), TRUE);
224 gtk_misc_set_alignment (GTK_MISC (location->info_label), 0.0, 0.5);
225 gtk_widget_show (location->info_label);
226- gtk_table_attach (GTK_TABLE (table), location->info_label, 0, 1, 0, 1,
227- GTK_EXPAND | GTK_FILL, GTK_FILL, 3, 3);
228-
229- box = gtk_vbox_new (FALSE, 3);
230- gtk_widget_show (box);
231- gtk_table_attach (GTK_TABLE (table), box, 0, 1, 1, 2,
232- GTK_FILL | GTK_EXPAND, GTK_FILL, 3, 3);
233+ gtk_table_attach (GTK_TABLE (table), location->info_label, 1, 2, 0, 1,
234+ GTK_EXPAND | GTK_FILL | GTK_SHRINK, GTK_FILL, 3, 3);
235
236 location->help_label = gtk_label_new (_("These files are not backed up and will not be available in your other computers"));
237 gtk_label_set_use_markup (GTK_LABEL (location->help_label), TRUE);
238 gtk_misc_set_alignment (GTK_MISC (location->help_label), 0.0, 0.5);
239- gtk_box_pack_start (GTK_BOX (box), location->help_label, TRUE, TRUE, 0);
240+ gtk_table_attach (GTK_TABLE (table), location->help_label, 1, 3, 1, 2,
241+ GTK_EXPAND | GTK_FILL | GTK_SHRINK, GTK_FILL, 3, 3);
242
243 location->spinner = gtk_spinner_new ();
244- gtk_table_attach (GTK_TABLE (table), location->spinner, 1, 2, 0, 2,
245+ gtk_table_attach (GTK_TABLE (table), location->spinner, 2, 3, 0, 1,
246 GTK_SHRINK, GTK_SHRINK, 3, 3);
247
248 /* Buttons */
249- box = gtk_vbox_new (FALSE, 3);
250- gtk_widget_show (box);
251- gtk_table_attach (GTK_TABLE (table), box, 2, 3, 0, 2,
252+ location->toggle_button = gtk_check_button_new_with_label (_("Synchronize folder"));
253+ gtk_widget_show (location->toggle_button);
254+ gtk_table_attach (GTK_TABLE (table), location->toggle_button, 3, 4, 0, 1,
255 GTK_FILL, GTK_FILL, 3, 3);
256-
257- location->disable_button = gtk_button_new_with_label (_("Cancel Sync"));
258- g_signal_connect (G_OBJECT (location->disable_button), "clicked",
259- G_CALLBACK (disable_u1_cb), location);
260- gtk_box_pack_start (GTK_BOX (box), location->disable_button, FALSE, FALSE, 0);
261-
262- location->enable_button = gtk_button_new_with_label (_("Sync now"));
263- g_signal_connect (G_OBJECT (location->enable_button), "clicked",
264- G_CALLBACK (enable_u1_cb), location);
265- gtk_box_pack_start (GTK_BOX (box), location->enable_button, FALSE, FALSE, 0);
266 }
267
268 static gboolean
269@@ -393,13 +454,18 @@
270
271 if (ubuntuone_is_storagefs (uon, path, &is_root)) {
272 /* Create label and disable button */
273+ gtk_widget_hide (location->expander);
274 set_label_text (location, TRUE);
275- if (is_root && !is_special_udf (uon, path))
276- gtk_widget_show (location->disable_button);
277+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (location->toggle_button), TRUE);
278+ if (!is_root || is_special_udf (uon, path))
279+ gtk_widget_set_sensitive (location->toggle_button, FALSE);
280 } else {
281 /* Check if this is the 'Shared with me' folder */
282 if (is_special_udf (uon, path)) {
283+ gtk_widget_hide (location->expander);
284 set_label_text (location, TRUE);
285+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (location->toggle_button), TRUE);
286+ gtk_widget_set_sensitive (location->toggle_button, FALSE);
287 } else {
288 GSList *udfs, *l;
289 SyncdaemonInterface *interface;
290@@ -416,10 +482,10 @@
291 }
292
293 g_slist_free (udfs);
294-
295+
296+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (location->toggle_button), FALSE);
297 if (allow_enabling) {
298 set_label_text (location, FALSE);
299- gtk_widget_show (location->enable_button);
300 } else {
301 gchar *labeltext;
302
303@@ -431,11 +497,18 @@
304 gtk_label_set_text (GTK_LABEL (location->help_label),
305 _("This folder cannot be synchronized because it contains "
306 "one or more folders that already synchronized"));
307- gtk_widget_show (location->help_label);
308+ if (location->expander_status == GTK_ARROW_DOWN)
309+ gtk_widget_show (location->help_label);
310+
311+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (location->toggle_button), FALSE);
312+ gtk_widget_set_sensitive (location->toggle_button, FALSE);
313 }
314 }
315 }
316
317+ g_signal_connect (G_OBJECT (location->toggle_button), "toggled",
318+ G_CALLBACK (sync_toggled_cb), location);
319+
320 gtk_widget_show (GTK_WIDGET (location));
321
322 return GTK_WIDGET (location);
323
324=== modified file 'nautilus/location-widget.h'
325--- nautilus/location-widget.h 2010-07-13 20:46:57 +0000
326+++ nautilus/location-widget.h 2010-07-27 11:29:41 +0000
327@@ -23,6 +23,7 @@
328 #define __LOCATION_WIDGET_H__
329
330 #include <gtk/gtk.h>
331+#include <gconf/gconf-client.h>
332 #include "ubuntuone-nautilus.h"
333
334 #define TYPE_LOCATION_WIDGET (location_widget_get_type ())
335@@ -38,11 +39,15 @@
336 /* Private data */
337 UbuntuOneNautilus *uon;
338 gchar *path;
339+ GtkWidget *expander;
340+ GtkArrowType expander_status;
341 GtkWidget *info_label;
342 GtkWidget *help_label;
343 GtkWidget *spinner;
344- GtkWidget *enable_button;
345- GtkWidget *disable_button;
346+ GtkWidget *toggle_button;
347+
348+ GConfClient *conf_client;
349+ guint conf_notify_id;
350 } LocationWidget;
351
352 typedef struct {

Subscribers

People subscribed via source and target branches