Merge lp:~dobey/ubuntuone-client/gsd-quota-fixes-stable into lp:ubuntuone-client/stable-1-4

Proposed by dobey
Status: Merged
Approved by: dobey
Approved revision: 746
Merged at revision: 747
Proposed branch: lp:~dobey/ubuntuone-client/gsd-quota-fixes-stable
Merge into: lp:ubuntuone-client/stable-1-4
Diff against target: 249 lines (+112/-56)
3 files modified
gsd-plugin/gsd-ubuntuone.c (+107/-51)
gsd-plugin/gsd-ubuntuone.h (+1/-1)
gsd-plugin/test-send-signal.py (+4/-4)
To merge this branch: bzr merge lp:~dobey/ubuntuone-client/gsd-quota-fixes-stable
Reviewer Review Type Date Requested Status
Roberto Alsina (community) Approve
Manuel de la Peña (community) Approve
Review via email: mp+46153@code.launchpad.net

Commit message

Only show the dialog after a short timeout, to allow coallescing of signals
Only show the dialog once per day at most
Just show() the dialog if it's already visible, rather than recreating it

To post a comment you must log in.
Revision history for this message
Manuel de la Peña (mandel) wrote :

+1

review: Approve
Revision history for this message
Roberto Alsina (ralsina) wrote :

+1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'gsd-plugin/gsd-ubuntuone.c'
2--- gsd-plugin/gsd-ubuntuone.c 2010-09-30 14:23:05 +0000
3+++ gsd-plugin/gsd-ubuntuone.c 2011-01-13 17:01:57 +0000
4@@ -42,58 +42,93 @@
5 #define UPGRADE_SUBSCRIPTION_URI "http://one.ubuntu.com/plans/"
6 #define CHECKED_BOOKMARK_FILE_KEY "/apps/gnome_settings_daemon/plugins/ubuntuone/checked_bookmark_file"
7
8+#define DAY_IN_SECONDS (60 * 60 * 24)
9+
10+/* For passing data into a GSourceFunc */
11+typedef struct _GsdUbuntuOneData GsdUbuntuOneData;
12+
13+struct _GsdUbuntuOneData
14+{
15+ GtkWidget *dialog;
16+ guint timeout_id;
17+ guint last_shown;
18+
19+ gchar * message;
20+ gboolean show_upgrade_link;
21+};
22+
23+static void
24+gsd_ubuntuone_data_free (GsdUbuntuOneData *data)
25+{
26+ if (data->dialog) {
27+ gtk_widget_destroy (data->dialog);
28+ data->dialog = NULL;
29+ }
30+
31+ if (data->timeout_id) {
32+ g_source_remove (data->timeout_id);
33+ data->timeout_id = 0;
34+ }
35+
36+ if (data->message)
37+ g_free (data->message);
38+
39+ g_free (data);
40+}
41+
42+
43 static void
44 dialog_closed_callback (GtkDialog *dialog,
45 gint response_id,
46 gpointer user_data)
47 {
48- GsdUbuntuOne *plugin = GSD_UBUNTUONE (user_data);
49+ GsdUbuntuOneData *data = (GsdUbuntuOneData *) (user_data);
50
51- g_debug ("dialog closed %d", response_id);
52- gtk_widget_destroy (GTK_WIDGET (plugin->out_of_space_dialog));
53- plugin->out_of_space_dialog = NULL;
54+ gtk_widget_destroy (GTK_WIDGET (data->dialog));
55+ data->dialog = NULL;
56 }
57
58-static void
59-show_out_of_space_dialog (GsdUbuntuOne *plugin,
60- const gchar *title,
61- const gchar *body,
62- gboolean show_upgrade_link)
63+static gboolean
64+show_out_of_space_dialog (GsdUbuntuOneData *data)
65 {
66- GError *error = NULL;
67+ if ((time (NULL) - DAY_IN_SECONDS) < data->last_shown) {
68+ return FALSE;
69+ }
70
71- if (plugin->out_of_space_dialog != NULL) {
72- gtk_widget_destroy (GTK_WIDGET (plugin->out_of_space_dialog));
73- plugin->out_of_space_dialog = NULL;
74+ if (data->dialog != NULL) {
75+ gtk_widget_show (GTK_WIDGET (data->dialog));
76+ return FALSE;
77 }
78-
79- g_debug ("notification: %s - %s", title, body);
80-
81- plugin->out_of_space_dialog = gtk_message_dialog_new (NULL,
82- GTK_DIALOG_NO_SEPARATOR,
83- GTK_MESSAGE_WARNING,
84- GTK_BUTTONS_CLOSE,
85- "%s",
86- body);
87-
88- gtk_window_set_skip_taskbar_hint (GTK_WINDOW (plugin->out_of_space_dialog), FALSE);
89- gtk_window_set_title (GTK_WINDOW (plugin->out_of_space_dialog), title);
90- gtk_window_set_icon_name (GTK_WINDOW (plugin->out_of_space_dialog), "ubuntuone");
91- gtk_window_set_position (GTK_WINDOW (plugin->out_of_space_dialog), GTK_WIN_POS_CENTER);
92-
93- if (show_upgrade_link) {
94+
95+ data->dialog = gtk_message_dialog_new (NULL,
96+ 0,
97+ GTK_MESSAGE_WARNING,
98+ GTK_BUTTONS_CLOSE,
99+ "%s",
100+ data->message);
101+
102+ gtk_window_set_skip_taskbar_hint (GTK_WINDOW (data->dialog), FALSE);
103+ gtk_window_set_title (GTK_WINDOW (data->dialog), NO_SPACE_TITLE);
104+ gtk_window_set_icon_name (GTK_WINDOW (data->dialog), "ubuntuone");
105+ gtk_window_set_position (GTK_WINDOW (data->dialog), GTK_WIN_POS_CENTER);
106+
107+ if (data->show_upgrade_link) {
108 GtkWidget *upgrade_link;
109
110 upgrade_link = gtk_link_button_new_with_label (UPGRADE_SUBSCRIPTION_URI,
111 UPGRADE_SUBSCRIPTION_TEXT);
112 gtk_widget_show (GTK_WIDGET (upgrade_link));
113- gtk_dialog_add_action_widget (GTK_DIALOG (plugin->out_of_space_dialog),
114+ gtk_dialog_add_action_widget (GTK_DIALOG (data->dialog),
115 upgrade_link, 0);
116 }
117
118- g_signal_connect (G_OBJECT (plugin->out_of_space_dialog), "response",
119- G_CALLBACK (dialog_closed_callback), plugin);
120- gtk_widget_show (plugin->out_of_space_dialog);
121+ g_signal_connect (G_OBJECT (data->dialog), "response",
122+ G_CALLBACK (dialog_closed_callback), data);
123+ gtk_widget_show (data->dialog);
124+
125+ data->last_shown = time (NULL);
126+
127+ return FALSE;
128 }
129
130
131@@ -102,21 +137,37 @@
132 GHashTable *file_info,
133 gpointer user_data)
134 {
135- gchar * volume_type;
136- GsdUbuntuOne *plugin = GSD_UBUNTUONE (user_data);
137-
138- volume_type = g_hash_table_lookup (file_info, "type");
139- if (g_strcmp0 (volume_type, "Share") == 0) {
140- gchar * other_visible_name, * path, * message;
141-
142- other_visible_name = g_hash_table_lookup (file_info, "other_visible_name");
143- path = g_hash_table_lookup (file_info, "path");
144- message = g_strdup_printf (NO_SPACE_SHARE, path, other_visible_name);
145- show_out_of_space_dialog (plugin, NO_SPACE_TITLE, message, FALSE);
146- g_free (message);
147- } else {
148- show_out_of_space_dialog (plugin, NO_SPACE_TITLE, NO_SPACE, TRUE);
149- }
150+ gchar *volume_type, *owner_id;
151+ GsdUbuntuOne *plugin = GSD_UBUNTUONE (user_data);
152+ GsdUbuntuOneData *data;
153+
154+ volume_type = g_hash_table_lookup (file_info, "type");
155+ owner_id = g_hash_table_lookup (file_info, "owner_id");
156+ data = g_hash_table_lookup (plugin->map_quota_dialogs, owner_id);
157+
158+ if (data == NULL) {
159+ data = g_new0 (GsdUbuntuOneData, 1);
160+
161+ /* Set up the data to use in the dialog */
162+ if (g_strcmp0 (volume_type, "Share") == 0) {
163+ gchar * other_visible_name, * path;
164+ other_visible_name = g_hash_table_lookup (file_info, "other_visible_name");
165+ path = g_hash_table_lookup (file_info, "path");
166+ data->message = g_strdup_printf (NO_SPACE_SHARE, path, other_visible_name);
167+ data->show_upgrade_link = FALSE;
168+ } else {
169+ data->message = g_strdup (NO_SPACE);
170+ data->show_upgrade_link = TRUE;
171+ }
172+ g_hash_table_replace (plugin->map_quota_dialogs, g_strdup (owner_id), data);
173+ }
174+
175+ /* Set up the timeout for letting lots of signals queue */
176+ if (data->timeout_id != 0) {
177+ g_source_remove (data->timeout_id);
178+ data->timeout_id = 0;
179+ }
180+ data->timeout_id = g_timeout_add_seconds (10, (GSourceFunc) show_out_of_space_dialog, data);
181 }
182
183 static void
184@@ -223,10 +274,8 @@
185 SyncdaemonAuthentication *auth;
186
187 plugin = GSD_UBUNTUONE (data);
188- g_debug ("Performing delayed syncdaemon init");
189
190 plugin->syncdaemon = syncdaemon_daemon_new ();
191- plugin->out_of_space_dialog = NULL;
192 g_signal_connect (G_OBJECT (plugin->syncdaemon), "quota_exceeded",
193 G_CALLBACK (quota_exceeded_callback), plugin);
194
195@@ -244,6 +293,10 @@
196 static void
197 gsd_ubuntuone_init (GsdUbuntuOne *plugin)
198 {
199+ plugin->map_quota_dialogs = g_hash_table_new_full (g_str_hash,
200+ g_str_equal,
201+ g_free,
202+ (GDestroyNotify) gsd_ubuntuone_data_free);
203 }
204
205 void
206@@ -262,7 +315,10 @@
207 GObjectClass *parent_class = G_OBJECT_CLASS (klass);
208
209 if (plugin->syncdaemon != NULL)
210- g_object_unref (plugin->syncdaemon);
211+ g_object_unref (plugin->syncdaemon);
212+
213+ if (plugin->map_quota_dialogs != NULL)
214+ g_hash_table_destroy (plugin->map_quota_dialogs);
215
216 parent_class->dispose (object);
217 }
218
219=== modified file 'gsd-plugin/gsd-ubuntuone.h'
220--- gsd-plugin/gsd-ubuntuone.h 2010-09-30 13:38:53 +0000
221+++ gsd-plugin/gsd-ubuntuone.h 2011-01-13 17:01:57 +0000
222@@ -47,7 +47,7 @@
223
224 /*< private >*/
225 SyncdaemonDaemon *syncdaemon;
226- GtkWidget *out_of_space_dialog;
227+ GHashTable *map_quota_dialogs;
228 };
229
230 struct _GsdUbuntuOneClass
231
232=== modified file 'gsd-plugin/test-send-signal.py'
233--- gsd-plugin/test-send-signal.py 2010-07-14 04:11:20 +0000
234+++ gsd-plugin/test-send-signal.py 2011-01-13 17:01:57 +0000
235@@ -38,11 +38,11 @@
236 "type": "UDF",
237 }
238 SAMPLE_SHARE_INFO = {
239- "volume_id": "sample_volume_id",
240- "owner_id": "sample_owner_id",
241- "volume_name": "sample_volume_name",
242+ "volume_id": "other_volume_id",
243+ "owner_id": "other_owner_id",
244+ "volume_name": "other_volume_name",
245 "type": "Share",
246- "other_visible_name": "Some Body",
247+ "other_visible_name": "Other User",
248 "path": "~/A shared folder",
249 }
250

Subscribers

People subscribed via source and target branches

to all changes: