~rodrigo-moya/ubuntuone-client/fix-617656

« back to all changes in this revision

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

  • Committer: Alejandro J. Cura
  • Date: 2010-07-14 04:11:20 UTC
  • mto: This revision was merged to the branch mainline in revision 578.
  • Revision ID: alecu@canonical.com-20100714041120-va8cjghubtb01s03
starting from scratch

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "config.h"
 
2
 
 
3
#include <glib/gi18n-lib.h>
 
4
#include <gmodule.h>
 
5
#include <gtk/gtk.h>
 
6
 
 
7
#include "gnome-settings-daemon/gnome-settings-plugin.h"
 
8
#include "gsd-ubuntuone.h"
 
9
#include "gsd-ubuntuone-ui.h"
 
10
 
 
11
#ifdef REGISTER_PLUGIN
 
12
GNOME_SETTINGS_PLUGIN_REGISTER (GsdUbuntuOne, gsd_ubuntuone)
 
13
#else
 
14
G_DEFINE_TYPE (GsdUbuntuOne, gsd_ubuntuone, G_TYPE_OBJECT);
 
15
G_DEFINE_TYPE (GnomeSettingsPlugin, gnome_settings_plugin, G_TYPE_OBJECT);
 
16
#endif
 
17
 
 
18
#define NO_SPACE _("Your Ubuntu One storage is full. Follow the link below to upgrade your subscription.")
 
19
#define NO_SPACE_SHARE _("There is no available space on the folder:\n\"%s\" shared by %s")
 
20
#define NO_SPACE_TITLE _("Out of space")
 
21
#define UPGRADE_SUBSCRIPTION _("Upgrade Subscription")
 
22
 
 
23
static void dialog_closed_callback (GtkDialog *dialog,
 
24
                                    gint response_id,
 
25
                                    gpointer user_data)
 
26
{
 
27
        GsdUbuntuOne *plugin = GSD_UBUNTUONE (user_data);
 
28
        g_debug ("dialog closed %d", response_id);
 
29
        gtk_widget_destroy (GTK_WIDGET (plugin->out_of_space_dialog));
 
30
        plugin->out_of_space_dialog = NULL;
 
31
}
 
32
 
 
33
static void
 
34
show_out_of_space_dialog (GsdUbuntuOne *plugin,
 
35
                          const gchar *title,
 
36
                          const gchar *body,
 
37
                          gboolean show_upgrade_link)
 
38
{
 
39
        GtkBuilder *builder;
 
40
        GError *error = NULL;
 
41
        GtkLinkButton *upgrade_link;
 
42
        GtkResponseType result;
 
43
 
 
44
        if (plugin->out_of_space_dialog != NULL) {
 
45
                gtk_widget_destroy (GTK_WIDGET (plugin->out_of_space_dialog));
 
46
                plugin->out_of_space_dialog = NULL;
 
47
        }
 
48
        
 
49
        builder = gtk_builder_new ();
 
50
        if (!gtk_builder_add_from_string (builder, gsd_ubuntuone_ui, -1, &error)) {
 
51
                g_warning ("Couldn't load builder file: %s", error->message);
 
52
                g_error_free (error);
 
53
        }
 
54
        g_debug ("builder succeeded!");
 
55
        g_debug ("notification: %s - %s", title, body);
 
56
 
 
57
        plugin->out_of_space_dialog = GTK_DIALOG (gtk_builder_get_object (builder, "out_of_space_dialog"));
 
58
 
 
59
        gtk_window_set_skip_taskbar_hint (GTK_WINDOW (plugin->out_of_space_dialog), FALSE);
 
60
 
 
61
        upgrade_link = GTK_LINK_BUTTON (gtk_builder_get_object (builder, "upgrade_link"));
 
62
        gtk_builder_connect_signals (builder, NULL);
 
63
        g_object_unref (builder);
 
64
 
 
65
        gtk_window_set_title (GTK_WINDOW (plugin->out_of_space_dialog), title);
 
66
        g_object_set (plugin->out_of_space_dialog, "text", body, NULL);
 
67
        if (!show_upgrade_link) {
 
68
                gtk_widget_hide (GTK_WIDGET (upgrade_link));
 
69
        }
 
70
 
 
71
        gtk_button_set_label (GTK_BUTTON (upgrade_link), UPGRADE_SUBSCRIPTION);
 
72
 
 
73
        g_signal_connect (G_OBJECT (plugin->out_of_space_dialog), "response",
 
74
                      G_CALLBACK (dialog_closed_callback), plugin);
 
75
        gtk_widget_show (GTK_WIDGET (plugin->out_of_space_dialog));
 
76
}
 
77
 
 
78
 
 
79
static void
 
80
quota_exceeded_callback (SyncdaemonDaemon *daemon,
 
81
                         GHashTable *file_info,
 
82
                         gpointer user_data)
 
83
{
 
84
        gchar * volume_type;
 
85
        GsdUbuntuOne *plugin = GSD_UBUNTUONE (user_data);
 
86
        volume_type = g_hash_table_lookup (file_info, "type");
 
87
        if (volume_type != NULL && strcmp (volume_type, "Share") == 0) {
 
88
                gchar * other_visible_name, * path, * message;
 
89
                other_visible_name = g_hash_table_lookup (file_info, "other_visible_name");
 
90
                path = g_hash_table_lookup (file_info, "path");
 
91
                message = g_strdup_printf (NO_SPACE_SHARE, path, other_visible_name);
 
92
                show_out_of_space_dialog (plugin, NO_SPACE_TITLE, message, FALSE);
 
93
                g_free (message);
 
94
        } else {
 
95
                show_out_of_space_dialog (plugin, NO_SPACE_TITLE, NO_SPACE, TRUE);
 
96
        }
 
97
}
 
98
 
 
99
static gboolean
 
100
delayed_syncdaemon_start (gpointer data)
 
101
{
 
102
        GsdUbuntuOne *plugin;
 
103
        plugin = GSD_UBUNTUONE (data);
 
104
        g_debug ("Performing delayed syncdaemon init");
 
105
 
 
106
        plugin->syncdaemon = syncdaemon_daemon_new ();
 
107
        plugin->out_of_space_dialog = NULL;
 
108
        g_signal_connect (G_OBJECT (plugin->syncdaemon), "quota_exceeded",
 
109
                          G_CALLBACK (quota_exceeded_callback), plugin);
 
110
        return FALSE;
 
111
}
 
112
 
 
113
static void
 
114
gsd_ubuntuone_init (GsdUbuntuOne *plugin)
 
115
{
 
116
}
 
117
 
 
118
void
 
119
gsd_ubuntuone_activate (GnomeSettingsPlugin *gsp_object)
 
120
{
 
121
        GsdUbuntuOne *plugin = GSD_UBUNTUONE (gsp_object);
 
122
        g_timeout_add (DELAYED_START_TIMEOUT, delayed_syncdaemon_start, plugin);
 
123
}
 
124
 
 
125
static void
 
126
gsd_ubuntuone_dispose (GObject *object)
 
127
{
 
128
        GsdUbuntuOne *plugin = GSD_UBUNTUONE (object);
 
129
        GsdUbuntuOneClass *klass = GSD_UBUNTUONE_GET_CLASS (object);
 
130
        GObjectClass *parent_class = G_OBJECT_CLASS (klass);
 
131
 
 
132
        if (plugin->syncdaemon)
 
133
              g_object_unref (plugin->syncdaemon);
 
134
 
 
135
        parent_class->dispose (object);
 
136
}
 
137
 
 
138
static void
 
139
gsd_ubuntuone_class_init (GsdUbuntuOneClass *klass)
 
140
{
 
141
        GObjectClass *g_class = G_OBJECT_CLASS (klass);
 
142
        GnomeSettingsPluginClass *gsp_class = GNOME_SETTINGS_PLUGIN_CLASS (klass);
 
143
 
 
144
        g_class->dispose = gsd_ubuntuone_dispose;
 
145
        gsp_class->activate = gsd_ubuntuone_activate;
 
146
}