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-shares-interface.h>
24
#include "ubuntuone-nautilus.h"
26
/* this is the wrong place for this, but it'll have to do for now */
28
ubuntuone_nautilus_check_shares_and_public_files (UbuntuOneNautilus *uon, SyncdaemonFolderInfo *folder_info, GtkWidget *widget)
30
SyncdaemonInterface *interface;
31
GHashTable *shares = NULL;
32
gboolean result = TRUE;
34
interface = syncdaemon_daemon_get_shares_interface (uon->syncdaemon);
35
if (SYNCDAEMON_IS_SHARES_INTERFACE (interface)) {
36
GSList *shared_list, *l;
38
shared_list = syncdaemon_shares_interface_get_shared (SYNCDAEMON_SHARES_INTERFACE (interface));
39
for (l = shared_list; l != NULL; l = l->next) {
40
SyncdaemonShareInfo *share_info = SYNCDAEMON_SHARE_INFO (shared_list->data);
42
if (g_str_has_prefix (syncdaemon_share_info_get_path (share_info),
43
syncdaemon_folder_info_get_path (folder_info))
44
&& syncdaemon_share_info_get_accepted (share_info)) {
46
const gchar *username;
50
shares = g_hash_table_new (g_str_hash, g_str_equal);
52
g_hash_table_lookup_extended (shares,
53
syncdaemon_share_info_get_path (share_info),
57
/* Add the share and the user it's shared with to the hash table */
58
if (syncdaemon_share_info_get_user_visible_name (share_info) != NULL)
59
username = syncdaemon_share_info_get_user_visible_name (share_info);
61
username = syncdaemon_share_info_get_username (share_info);
63
users = g_slist_append (users, (gpointer) username);
64
g_hash_table_insert (shares,
65
(gpointer) syncdaemon_share_info_get_path (share_info),
70
g_slist_free (shared_list);
72
/* If there are shares, ask the user what to do */
80
question = g_string_new (_("This folder contains folders that have been shared:\n\n"));
82
g_hash_table_iter_init (&iter, shares);
83
while (g_hash_table_iter_next (&iter, (gpointer) &path, (gpointer) &users)) {
86
question = g_string_append (question, "\t- ");
87
question = g_string_append (question, path);
88
question = g_string_append (question, " (");
90
while (users != NULL) {
91
gchar *username = (gchar *) users->data;
94
question = g_string_append (question, ", ");
95
question = g_string_append (question, username);
97
users = g_slist_remove (users, username);
101
question = g_string_append (question, ")\n");
104
question = g_string_append (question, _("\nThis action will un-share these items. Other users"
105
" will no longer be able to access these files."
106
" Would you like to proceed?"));
108
dialog = gtk_message_dialog_new (
109
GTK_WINDOW (gtk_widget_get_toplevel (widget)),
110
0, GTK_MESSAGE_QUESTION,
112
"%s", question->str);
113
if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_YES)
116
gtk_widget_destroy (dialog);
117
g_string_free (question, TRUE);
118
g_hash_table_destroy (shares);
126
/* Now check for published files */
131
gboolean has_published = FALSE;
133
question = g_string_new (_("This folder contains files that have been published:\n\n"));
135
g_hash_table_iter_init (&iter, uon->public);
136
while (g_hash_table_iter_next (&iter, (gpointer *) &key, (gpointer *) &value)) {
137
if (g_str_has_prefix (key, syncdaemon_folder_info_get_path (folder_info))) {
138
has_published = TRUE;
140
question = g_string_append (question, "\t- ");
141
question = g_string_append (question, key);
142
question = g_string_append (question, " (");
143
question = g_string_append (question, value);
144
question = g_string_append (question, ")\n");
148
question = g_string_append (question, _("\nThis action will un-publish these items. Other users"
149
" will no longer be able to access these files."
150
" Would you like to proceeed?"));
155
dialog = gtk_message_dialog_new (
156
GTK_WINDOW (gtk_widget_get_toplevel (widget)),
157
0, GTK_MESSAGE_QUESTION,
159
"%s", question->str);
160
if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_YES)
163
gtk_widget_destroy (dialog);
166
g_string_free (question, TRUE);