~didrocks/ubuntuone-client/dont-suffer-zg-crash

« back to all changes in this revision

Viewing changes to gsd-plugin/gsd-ubuntuone.c

  • Committer: Bazaar Package Importer
  • Author(s): Rodney Dawes
  • Date: 2011-01-25 16:42:52 UTC
  • mto: This revision was merged to the branch mainline in revision 64.
  • Revision ID: james.westby@ubuntu.com-20110125164252-rl1pybasx1nsqgoy
Tags: upstream-1.5.3
ImportĀ upstreamĀ versionĀ 1.5.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
42
42
#define UPGRADE_SUBSCRIPTION_URI "http://one.ubuntu.com/plans/"
43
43
#define CHECKED_BOOKMARK_FILE_KEY "/apps/gnome_settings_daemon/plugins/ubuntuone/checked_bookmark_file"
44
44
 
 
45
#define DAY_IN_SECONDS (60 * 60 * 24)
 
46
 
 
47
/* For passing data into a GSourceFunc */
 
48
typedef struct _GsdUbuntuOneData GsdUbuntuOneData;
 
49
 
 
50
struct _GsdUbuntuOneData
 
51
{
 
52
        GtkWidget *dialog;
 
53
        guint timeout_id;
 
54
        guint last_shown;
 
55
 
 
56
        gchar * message;
 
57
        gboolean show_upgrade_link;
 
58
};
 
59
 
 
60
static void
 
61
gsd_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
 
45
80
static void
46
81
dialog_closed_callback (GtkDialog *dialog,
47
82
                        gint response_id,
48
83
                        gpointer user_data)
49
84
{
50
 
        GsdUbuntuOne *plugin = GSD_UBUNTUONE (user_data);
 
85
        GsdUbuntuOneData *data = (GsdUbuntuOneData *) (user_data);
51
86
 
52
 
        g_debug ("dialog closed %d", response_id);
53
 
        gtk_widget_destroy (GTK_WIDGET (plugin->out_of_space_dialog));
54
 
        plugin->out_of_space_dialog = NULL;
 
87
        gtk_widget_destroy (GTK_WIDGET (data->dialog));
 
88
        data->dialog = NULL;
55
89
}
56
90
 
57
 
static void
58
 
show_out_of_space_dialog (GsdUbuntuOne *plugin,
59
 
                          const gchar *title,
60
 
                          const gchar *body,
61
 
                          gboolean show_upgrade_link)
 
91
static gboolean
 
92
show_out_of_space_dialog (GsdUbuntuOneData *data)
62
93
{
63
 
        if (plugin->out_of_space_dialog != NULL) {
64
 
                gtk_widget_destroy (GTK_WIDGET (plugin->out_of_space_dialog));
65
 
                plugin->out_of_space_dialog = NULL;
 
94
        if ((time (NULL) - DAY_IN_SECONDS) < data->last_shown) {
 
95
                return FALSE;
 
96
        }
 
97
 
 
98
        if (data->dialog != NULL) {
 
99
                gtk_widget_show (GTK_WIDGET (data->dialog));
 
100
                return FALSE;
66
101
        }
67
 
        
68
 
        g_debug ("notification: %s - %s", title, body);
69
 
 
70
 
        plugin->out_of_space_dialog = gtk_message_dialog_new (NULL,
71
 
                                                              GTK_DIALOG_NO_SEPARATOR,
72
 
                                                              GTK_MESSAGE_WARNING,
73
 
                                                              GTK_BUTTONS_CLOSE,
74
 
                                                              "%s",
75
 
                                                              body);
76
 
 
77
 
        gtk_window_set_skip_taskbar_hint (GTK_WINDOW (plugin->out_of_space_dialog), FALSE);
78
 
        gtk_window_set_title (GTK_WINDOW (plugin->out_of_space_dialog), title);
79
 
        gtk_window_set_icon_name (GTK_WINDOW (plugin->out_of_space_dialog), "ubuntuone");
80
 
        gtk_window_set_position (GTK_WINDOW (plugin->out_of_space_dialog), GTK_WIN_POS_CENTER);
81
 
 
82
 
        if (show_upgrade_link) {
 
102
 
 
103
        data->dialog = gtk_message_dialog_new (NULL,
 
104
                                               0,
 
105
                                               GTK_MESSAGE_WARNING,
 
106
                                               GTK_BUTTONS_CLOSE,
 
107
                                               "%s",
 
108
                                               data->message);
 
109
 
 
110
        gtk_window_set_skip_taskbar_hint (GTK_WINDOW (data->dialog), FALSE);
 
111
        gtk_window_set_title (GTK_WINDOW (data->dialog), NO_SPACE_TITLE);
 
112
        gtk_window_set_icon_name (GTK_WINDOW (data->dialog), "ubuntuone");
 
113
        gtk_window_set_position (GTK_WINDOW (data->dialog), GTK_WIN_POS_CENTER);
 
114
 
 
115
        if (data->show_upgrade_link) {
83
116
                GtkWidget *upgrade_link;
84
117
 
85
118
                upgrade_link = gtk_link_button_new_with_label (UPGRADE_SUBSCRIPTION_URI,
86
119
                                                               UPGRADE_SUBSCRIPTION_TEXT);
87
120
                gtk_widget_show (GTK_WIDGET (upgrade_link));
88
 
                gtk_dialog_add_action_widget (GTK_DIALOG (plugin->out_of_space_dialog),
 
121
                gtk_dialog_add_action_widget (GTK_DIALOG (data->dialog),
89
122
                                              upgrade_link, 0);
90
123
        }
91
124
 
92
 
        g_signal_connect (G_OBJECT (plugin->out_of_space_dialog), "response",
93
 
                          G_CALLBACK (dialog_closed_callback), plugin);
94
 
        gtk_widget_show (plugin->out_of_space_dialog);
 
125
        g_signal_connect (G_OBJECT (data->dialog), "response",
 
126
                          G_CALLBACK (dialog_closed_callback), data);
 
127
        gtk_widget_show (data->dialog);
 
128
 
 
129
        data->last_shown = time (NULL);
 
130
 
 
131
        return FALSE;
95
132
}
96
133
 
97
134
 
100
137
                         GHashTable *file_info,
101
138
                         gpointer user_data)
102
139
{
103
 
        gchar * volume_type;
104
 
        GsdUbuntuOne *plugin = GSD_UBUNTUONE (user_data);
105
 
 
106
 
        volume_type = g_hash_table_lookup (file_info, "type");
107
 
        if (g_strcmp0 (volume_type, "Share") == 0) {
108
 
                gchar * other_visible_name, * path, * message;
109
 
 
110
 
                other_visible_name = g_hash_table_lookup (file_info, "other_visible_name");
111
 
                path = g_hash_table_lookup (file_info, "path");
112
 
                message = g_strdup_printf (NO_SPACE_SHARE, path, other_visible_name);
113
 
                show_out_of_space_dialog (plugin, NO_SPACE_TITLE, message, FALSE);
114
 
                g_free (message);
115
 
        } else {
116
 
                show_out_of_space_dialog (plugin, NO_SPACE_TITLE, NO_SPACE, TRUE);
117
 
        }
 
140
        gchar *volume_type, *owner_id;
 
141
        GsdUbuntuOne *plugin = GSD_UBUNTUONE (user_data);
 
142
        GsdUbuntuOneData *data;
 
143
 
 
144
        volume_type = g_hash_table_lookup (file_info, "type");
 
145
        owner_id = g_hash_table_lookup (file_info, "owner_id");
 
146
        data = g_hash_table_lookup (plugin->map_quota_dialogs, owner_id);
 
147
 
 
148
        if (data == NULL) {
 
149
                data = g_new0 (GsdUbuntuOneData, 1);
 
150
 
 
151
                /* Set up the data to use in the dialog */
 
152
                if (g_strcmp0 (volume_type, "Share") == 0) {
 
153
                        gchar * other_visible_name, * path;
 
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);
118
171
}
119
172
 
120
173
static void
221
274
        SyncdaemonAuthentication *auth;
222
275
 
223
276
        plugin = GSD_UBUNTUONE (data);
224
 
        g_debug ("Performing delayed syncdaemon init");
225
277
 
226
278
        plugin->syncdaemon = syncdaemon_daemon_new ();
227
 
        plugin->out_of_space_dialog = NULL;
228
279
        g_signal_connect (G_OBJECT (plugin->syncdaemon), "quota_exceeded",
229
280
                          G_CALLBACK (quota_exceeded_callback), plugin);
230
281
 
231
282
        /* Check for authentication */
232
283
        auth = syncdaemon_daemon_get_authentication (plugin->syncdaemon);
233
 
        if (syncdaemon_authentication_has_credentials (auth))
234
 
                check_bookmark_file ();
235
 
        else
236
 
                g_signal_connect (auth, "credentials_found",
237
 
                                  G_CALLBACK (credentials_found_cb), NULL);
 
284
        g_signal_connect (auth, "credentials_found",
 
285
                          G_CALLBACK (credentials_found_cb), NULL);
238
286
 
239
287
        return FALSE;
240
288
}
242
290
static void
243
291
gsd_ubuntuone_init (GsdUbuntuOne *plugin)
244
292
{
 
293
        plugin->map_quota_dialogs = g_hash_table_new_full (g_str_hash,
 
294
                                                           g_str_equal,
 
295
                                                           g_free,
 
296
                                                           (GDestroyNotify) gsd_ubuntuone_data_free);
245
297
}
246
298
 
247
299
void
260
312
        GObjectClass *parent_class = G_OBJECT_CLASS (klass);
261
313
 
262
314
        if (plugin->syncdaemon != NULL)
263
 
              g_object_unref (plugin->syncdaemon);
 
315
                g_object_unref (plugin->syncdaemon);
 
316
 
 
317
        if (plugin->map_quota_dialogs != NULL)
 
318
                g_hash_table_destroy (plugin->map_quota_dialogs);
264
319
 
265
320
        parent_class->dispose (object);
266
321
}