2
* UbuntuOne Nautilus plugin
4
* Authors: Rodrigo Moya <rodrigo.moya@canonical.com>
6
* Copyright 2009-2010 Canonical Ltd.
8
* This program is free software: you can redistribute it and/or modify it
9
* under the terms of the GNU General Public License version 3, as published
10
* by the Free Software Foundation.
12
* This program is distributed in the hope that it will be useful, but
13
* WITHOUT ANY WARRANTY; without even the implied warranties of
14
* MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
15
* PURPOSE. See the GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License along
18
* with this program. If not, see <http://www.gnu.org/licenses/>.
22
#include <glib/gi18n.h>
23
#include <libsyncdaemon/syncdaemon-folders-interface.h>
24
#include <libsyncdaemon/syncdaemon-shares-interface.h>
25
#include "location-widget.h"
27
G_DEFINE_TYPE(LocationWidget, location_widget, GTK_TYPE_HBOX)
30
set_label_text (LocationWidget *location, gboolean enabled)
34
labeltext = g_strdup_printf ("<b>Ubuntu One</b> %s",
35
enabled ? _("enabled") : _("disabled"));
36
gtk_label_set_markup (GTK_LABEL (location->info_label), labeltext);
41
folder_created_cb (SyncdaemonDaemon *daemon, gboolean success, SyncdaemonFolderInfo *folder_info, gpointer user_data)
44
LocationWidget *location = LOCATION_WIDGET (user_data);
46
path = syncdaemon_folder_info_get_path (folder_info);
47
g_warning ("in folder_created_cb with path = %s", path);
48
if (g_strcmp0 (path, location->path) == 0) {
49
set_label_text (location, success);
51
gtk_widget_hide (location->enable_button);
52
gtk_widget_show (location->disable_button);
53
gtk_widget_set_sensitive (location->disable_button, TRUE);
55
gtk_widget_show (location->enable_button);
56
gtk_widget_set_sensitive (location->enable_button, TRUE);
57
gtk_widget_hide (location->disable_button);
58
ubuntuone_show_error_dialog (location->uon, _("Error enabling folder"),
59
_("Could not enable folder %s for synchronizing to Ubuntu One"),
66
folder_deleted_cb (SyncdaemonDaemon *daemon, gboolean success, SyncdaemonFolderInfo *folder_info, gpointer user_data)
69
LocationWidget *location = LOCATION_WIDGET (user_data);
71
path = syncdaemon_folder_info_get_path (folder_info);
72
if (g_strcmp0 (path, location->path) == 0) {
74
set_label_text (location, FALSE);
75
gtk_widget_show (location->enable_button);
76
gtk_widget_set_sensitive (location->enable_button, TRUE);
77
gtk_widget_hide (location->disable_button);
79
set_label_text (location, TRUE);
80
gtk_widget_hide (location->enable_button);
81
gtk_widget_show (location->disable_button);
82
gtk_widget_set_sensitive (location->disable_button, TRUE);
83
ubuntuone_show_error_dialog (location->uon, _("Error disabling folder"),
84
_("Could not disable folder %s for synchronizing to Ubuntu One"),
91
location_widget_finalize (GObject *object)
93
LocationWidget *location = LOCATION_WIDGET (object);
95
g_signal_handlers_disconnect_by_func (location->uon->syncdaemon, folder_created_cb, location);
96
g_signal_handlers_disconnect_by_func (location->uon->syncdaemon, folder_deleted_cb, location);
98
if (location->path != NULL)
99
g_free (location->path);
101
G_OBJECT_CLASS (location_widget_parent_class)->finalize (object);
105
location_widget_class_init (LocationWidgetClass *klass)
107
GObjectClass *object_class = G_OBJECT_CLASS (klass);
109
object_class->finalize = location_widget_finalize;
113
disable_u1_cb (GtkButton *button, gpointer user_data)
115
SyncdaemonInterface *interface;
117
LocationWidget *location = LOCATION_WIDGET (user_data);
119
/* Update label to show progress */
120
labeltext = g_strdup_printf (_("Disabling %s folder for synchronization on Ubuntu One..."), location->path);
121
gtk_label_set_text (GTK_LABEL (location->info_label), labeltext);
123
gtk_widget_set_sensitive (location->disable_button, FALSE);
125
/* Perform the removal of this folder */
126
interface = syncdaemon_daemon_get_folders_interface (location->uon->syncdaemon);
127
if (interface != NULL) {
128
SyncdaemonFolderInfo *folder_info;
130
folder_info = syncdaemon_folders_interface_get_info (
131
SYNCDAEMON_FOLDERS_INTERFACE (interface),
133
if (folder_info != NULL) {
134
syncdaemon_folders_interface_delete (
135
SYNCDAEMON_FOLDERS_INTERFACE (interface),
136
syncdaemon_folder_info_get_volume_id (folder_info));
138
g_object_unref (G_OBJECT (folder_info));
144
enable_u1_cb (GtkButton *button, gpointer user_data)
146
SyncdaemonInterface *interface;
148
LocationWidget *location = LOCATION_WIDGET (user_data);
150
/* Update label to show progress */
151
labeltext = g_strdup_printf (_("Enabling %s folder for synchronization on Ubuntu One..."), location->path);
152
gtk_label_set_text (GTK_LABEL (location->info_label), labeltext);
154
gtk_widget_set_sensitive (location->enable_button, FALSE);
156
/* Perform the addition of this folder */
157
interface = syncdaemon_daemon_get_folders_interface (location->uon->syncdaemon);
158
if (interface != NULL) {
159
syncdaemon_folders_interface_create (SYNCDAEMON_FOLDERS_INTERFACE (interface),
165
location_widget_init (LocationWidget *location)
167
location->path = NULL;
168
location->info_label = location->enable_button = NULL;
170
/* Create the widgets in the interface */
171
location->info_label = gtk_label_new ("<b>Ubuntu One</b>");
172
gtk_label_set_use_markup (GTK_LABEL (location->info_label), TRUE);
173
gtk_misc_set_alignment (GTK_MISC (location->info_label), 0.0, 0.5);
174
gtk_widget_show (location->info_label);
175
gtk_box_pack_start (GTK_BOX (location), location->info_label, TRUE, FALSE, 0);
177
location->disable_button = gtk_button_new_with_label (_("Disable"));
178
g_signal_connect (G_OBJECT (location->disable_button), "clicked",
179
G_CALLBACK (disable_u1_cb), location);
180
gtk_box_pack_end (GTK_BOX (location), location->disable_button, FALSE, FALSE, 0);
182
location->enable_button = gtk_button_new_with_label (_("Enable"));
183
g_signal_connect (G_OBJECT (location->enable_button), "clicked",
184
G_CALLBACK (enable_u1_cb), location);
185
gtk_box_pack_end (GTK_BOX (location), location->enable_button, FALSE, FALSE, 0);
189
location_widget_new (UbuntuOneNautilus *uon, const gchar *path)
191
LocationWidget *location;
194
g_return_val_if_fail (uon != NULL, NULL);
195
g_return_val_if_fail (path != NULL, NULL);
197
location = (LocationWidget *) g_object_new (TYPE_LOCATION_WIDGET, NULL);
199
location->path = g_strdup (path);
201
/* Connect to Syncdaemon signals */
202
g_signal_connect (G_OBJECT (uon->syncdaemon), "folder_created",
203
G_CALLBACK (folder_created_cb), location);
204
g_signal_connect (G_OBJECT (uon->syncdaemon), "folder_deleted",
205
G_CALLBACK (folder_deleted_cb), location);
207
if (ubuntuone_is_storagefs (uon, path, &is_root)) {
208
/* Create label and disable button */
209
set_label_text (location, TRUE);
210
if (is_root && strcmp (path, uon->managed) != 0)
211
gtk_widget_show (location->disable_button);
213
set_label_text (location, FALSE);
214
gtk_widget_show (location->enable_button);
217
gtk_widget_show (GTK_WIDGET (location));
219
return GTK_WIDGET (location);