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
=== modified file 'gsd-plugin/gsd-ubuntuone.c'
--- gsd-plugin/gsd-ubuntuone.c 2010-09-30 14:23:05 +0000
+++ gsd-plugin/gsd-ubuntuone.c 2011-01-13 17:01:57 +0000
@@ -42,58 +42,93 @@
42#define UPGRADE_SUBSCRIPTION_URI "http://one.ubuntu.com/plans/"42#define UPGRADE_SUBSCRIPTION_URI "http://one.ubuntu.com/plans/"
43#define CHECKED_BOOKMARK_FILE_KEY "/apps/gnome_settings_daemon/plugins/ubuntuone/checked_bookmark_file"43#define CHECKED_BOOKMARK_FILE_KEY "/apps/gnome_settings_daemon/plugins/ubuntuone/checked_bookmark_file"
4444
45#define DAY_IN_SECONDS (60 * 60 * 24)
46
47/* For passing data into a GSourceFunc */
48typedef struct _GsdUbuntuOneData GsdUbuntuOneData;
49
50struct _GsdUbuntuOneData
51{
52 GtkWidget *dialog;
53 guint timeout_id;
54 guint last_shown;
55
56 gchar * message;
57 gboolean show_upgrade_link;
58};
59
60static void
61gsd_ubuntuone_data_free (GsdUbuntuOneData *data)
62{
63 if (data->dialog) {
64 gtk_widget_destroy (data->dialog);
65 data->dialog = NULL;
66 }
67
68 if (data->timeout_id) {
69 g_source_remove (data->timeout_id);
70 data->timeout_id = 0;
71 }
72
73 if (data->message)
74 g_free (data->message);
75
76 g_free (data);
77}
78
79
45static void80static void
46dialog_closed_callback (GtkDialog *dialog,81dialog_closed_callback (GtkDialog *dialog,
47 gint response_id,82 gint response_id,
48 gpointer user_data)83 gpointer user_data)
49{84{
50 GsdUbuntuOne *plugin = GSD_UBUNTUONE (user_data);85 GsdUbuntuOneData *data = (GsdUbuntuOneData *) (user_data);
5186
52 g_debug ("dialog closed %d", response_id);87 gtk_widget_destroy (GTK_WIDGET (data->dialog));
53 gtk_widget_destroy (GTK_WIDGET (plugin->out_of_space_dialog));88 data->dialog = NULL;
54 plugin->out_of_space_dialog = NULL;
55}89}
5690
57static void91static gboolean
58show_out_of_space_dialog (GsdUbuntuOne *plugin,92show_out_of_space_dialog (GsdUbuntuOneData *data)
59 const gchar *title,
60 const gchar *body,
61 gboolean show_upgrade_link)
62{93{
63 GError *error = NULL;94 if ((time (NULL) - DAY_IN_SECONDS) < data->last_shown) {
95 return FALSE;
96 }
6497
65 if (plugin->out_of_space_dialog != NULL) {98 if (data->dialog != NULL) {
66 gtk_widget_destroy (GTK_WIDGET (plugin->out_of_space_dialog));99 gtk_widget_show (GTK_WIDGET (data->dialog));
67 plugin->out_of_space_dialog = NULL;100 return FALSE;
68 }101 }
69 102
70 g_debug ("notification: %s - %s", title, body);103 data->dialog = gtk_message_dialog_new (NULL,
71104 0,
72 plugin->out_of_space_dialog = gtk_message_dialog_new (NULL,105 GTK_MESSAGE_WARNING,
73 GTK_DIALOG_NO_SEPARATOR,106 GTK_BUTTONS_CLOSE,
74 GTK_MESSAGE_WARNING,107 "%s",
75 GTK_BUTTONS_CLOSE,108 data->message);
76 "%s",109
77 body);110 gtk_window_set_skip_taskbar_hint (GTK_WINDOW (data->dialog), FALSE);
78111 gtk_window_set_title (GTK_WINDOW (data->dialog), NO_SPACE_TITLE);
79 gtk_window_set_skip_taskbar_hint (GTK_WINDOW (plugin->out_of_space_dialog), FALSE);112 gtk_window_set_icon_name (GTK_WINDOW (data->dialog), "ubuntuone");
80 gtk_window_set_title (GTK_WINDOW (plugin->out_of_space_dialog), title);113 gtk_window_set_position (GTK_WINDOW (data->dialog), GTK_WIN_POS_CENTER);
81 gtk_window_set_icon_name (GTK_WINDOW (plugin->out_of_space_dialog), "ubuntuone");114
82 gtk_window_set_position (GTK_WINDOW (plugin->out_of_space_dialog), GTK_WIN_POS_CENTER);115 if (data->show_upgrade_link) {
83
84 if (show_upgrade_link) {
85 GtkWidget *upgrade_link;116 GtkWidget *upgrade_link;
86117
87 upgrade_link = gtk_link_button_new_with_label (UPGRADE_SUBSCRIPTION_URI,118 upgrade_link = gtk_link_button_new_with_label (UPGRADE_SUBSCRIPTION_URI,
88 UPGRADE_SUBSCRIPTION_TEXT);119 UPGRADE_SUBSCRIPTION_TEXT);
89 gtk_widget_show (GTK_WIDGET (upgrade_link));120 gtk_widget_show (GTK_WIDGET (upgrade_link));
90 gtk_dialog_add_action_widget (GTK_DIALOG (plugin->out_of_space_dialog),121 gtk_dialog_add_action_widget (GTK_DIALOG (data->dialog),
91 upgrade_link, 0);122 upgrade_link, 0);
92 }123 }
93124
94 g_signal_connect (G_OBJECT (plugin->out_of_space_dialog), "response",125 g_signal_connect (G_OBJECT (data->dialog), "response",
95 G_CALLBACK (dialog_closed_callback), plugin);126 G_CALLBACK (dialog_closed_callback), data);
96 gtk_widget_show (plugin->out_of_space_dialog);127 gtk_widget_show (data->dialog);
128
129 data->last_shown = time (NULL);
130
131 return FALSE;
97}132}
98133
99134
@@ -102,21 +137,37 @@
102 GHashTable *file_info,137 GHashTable *file_info,
103 gpointer user_data)138 gpointer user_data)
104{139{
105 gchar * volume_type;140 gchar *volume_type, *owner_id;
106 GsdUbuntuOne *plugin = GSD_UBUNTUONE (user_data);141 GsdUbuntuOne *plugin = GSD_UBUNTUONE (user_data);
107142 GsdUbuntuOneData *data;
108 volume_type = g_hash_table_lookup (file_info, "type");143
109 if (g_strcmp0 (volume_type, "Share") == 0) {144 volume_type = g_hash_table_lookup (file_info, "type");
110 gchar * other_visible_name, * path, * message;145 owner_id = g_hash_table_lookup (file_info, "owner_id");
111146 data = g_hash_table_lookup (plugin->map_quota_dialogs, owner_id);
112 other_visible_name = g_hash_table_lookup (file_info, "other_visible_name");147
113 path = g_hash_table_lookup (file_info, "path");148 if (data == NULL) {
114 message = g_strdup_printf (NO_SPACE_SHARE, path, other_visible_name);149 data = g_new0 (GsdUbuntuOneData, 1);
115 show_out_of_space_dialog (plugin, NO_SPACE_TITLE, message, FALSE);150
116 g_free (message);151 /* Set up the data to use in the dialog */
117 } else {152 if (g_strcmp0 (volume_type, "Share") == 0) {
118 show_out_of_space_dialog (plugin, NO_SPACE_TITLE, NO_SPACE, TRUE);153 gchar * other_visible_name, * path;
119 }154 other_visible_name = g_hash_table_lookup (file_info, "other_visible_name");
155 path = g_hash_table_lookup (file_info, "path");
156 data->message = g_strdup_printf (NO_SPACE_SHARE, path, other_visible_name);
157 data->show_upgrade_link = FALSE;
158 } else {
159 data->message = g_strdup (NO_SPACE);
160 data->show_upgrade_link = TRUE;
161 }
162 g_hash_table_replace (plugin->map_quota_dialogs, g_strdup (owner_id), data);
163 }
164
165 /* Set up the timeout for letting lots of signals queue */
166 if (data->timeout_id != 0) {
167 g_source_remove (data->timeout_id);
168 data->timeout_id = 0;
169 }
170 data->timeout_id = g_timeout_add_seconds (10, (GSourceFunc) show_out_of_space_dialog, data);
120}171}
121172
122static void173static void
@@ -223,10 +274,8 @@
223 SyncdaemonAuthentication *auth;274 SyncdaemonAuthentication *auth;
224275
225 plugin = GSD_UBUNTUONE (data);276 plugin = GSD_UBUNTUONE (data);
226 g_debug ("Performing delayed syncdaemon init");
227277
228 plugin->syncdaemon = syncdaemon_daemon_new ();278 plugin->syncdaemon = syncdaemon_daemon_new ();
229 plugin->out_of_space_dialog = NULL;
230 g_signal_connect (G_OBJECT (plugin->syncdaemon), "quota_exceeded",279 g_signal_connect (G_OBJECT (plugin->syncdaemon), "quota_exceeded",
231 G_CALLBACK (quota_exceeded_callback), plugin);280 G_CALLBACK (quota_exceeded_callback), plugin);
232281
@@ -244,6 +293,10 @@
244static void293static void
245gsd_ubuntuone_init (GsdUbuntuOne *plugin)294gsd_ubuntuone_init (GsdUbuntuOne *plugin)
246{295{
296 plugin->map_quota_dialogs = g_hash_table_new_full (g_str_hash,
297 g_str_equal,
298 g_free,
299 (GDestroyNotify) gsd_ubuntuone_data_free);
247}300}
248301
249void302void
@@ -262,7 +315,10 @@
262 GObjectClass *parent_class = G_OBJECT_CLASS (klass);315 GObjectClass *parent_class = G_OBJECT_CLASS (klass);
263316
264 if (plugin->syncdaemon != NULL)317 if (plugin->syncdaemon != NULL)
265 g_object_unref (plugin->syncdaemon);318 g_object_unref (plugin->syncdaemon);
319
320 if (plugin->map_quota_dialogs != NULL)
321 g_hash_table_destroy (plugin->map_quota_dialogs);
266322
267 parent_class->dispose (object);323 parent_class->dispose (object);
268}324}
269325
=== modified file 'gsd-plugin/gsd-ubuntuone.h'
--- gsd-plugin/gsd-ubuntuone.h 2010-09-30 13:38:53 +0000
+++ gsd-plugin/gsd-ubuntuone.h 2011-01-13 17:01:57 +0000
@@ -47,7 +47,7 @@
4747
48 /*< private >*/48 /*< private >*/
49 SyncdaemonDaemon *syncdaemon;49 SyncdaemonDaemon *syncdaemon;
50 GtkWidget *out_of_space_dialog;50 GHashTable *map_quota_dialogs;
51};51};
5252
53struct _GsdUbuntuOneClass53struct _GsdUbuntuOneClass
5454
=== modified file 'gsd-plugin/test-send-signal.py'
--- gsd-plugin/test-send-signal.py 2010-07-14 04:11:20 +0000
+++ gsd-plugin/test-send-signal.py 2011-01-13 17:01:57 +0000
@@ -38,11 +38,11 @@
38 "type": "UDF",38 "type": "UDF",
39}39}
40SAMPLE_SHARE_INFO = {40SAMPLE_SHARE_INFO = {
41 "volume_id": "sample_volume_id",41 "volume_id": "other_volume_id",
42 "owner_id": "sample_owner_id",42 "owner_id": "other_owner_id",
43 "volume_name": "sample_volume_name",43 "volume_name": "other_volume_name",
44 "type": "Share",44 "type": "Share",
45 "other_visible_name": "Some Body",45 "other_visible_name": "Other User",
46 "path": "~/A shared folder",46 "path": "~/A shared folder",
47}47}
4848

Subscribers

People subscribed via source and target branches

to all changes: