~facundo/ubuntuone-client/support-initial-disconnection

« back to all changes in this revision

Viewing changes to nautilus/utils.c

  • Committer: Tarmac
  • Author(s): Rodrigo Moya
  • Date: 2010-08-25 20:19:03 UTC
  • mfrom: (649.3.9 check-published-files)
  • Revision ID: tarmac-20100825201903-jv40ycy979hg62gw
Check that the user has no published files before disabling a UDF (LP: #603576)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * UbuntuOne Nautilus plugin
 
3
 *
 
4
 * Authors: Rodrigo Moya <rodrigo.moya@canonical.com>
 
5
 *
 
6
 * Copyright 2009-2010 Canonical Ltd.
 
7
 *
 
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.
 
11
 *
 
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.
 
16
 *
 
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/>.
 
19
 *
 
20
 */
 
21
 
 
22
#include <glib/gi18n.h>
 
23
#include <libsyncdaemon/syncdaemon-shares-interface.h>
 
24
#include "ubuntuone-nautilus.h"
 
25
 
 
26
/* this is the wrong place for this, but it'll have to do for now */
 
27
gboolean
 
28
ubuntuone_nautilus_check_shares_and_public_files (UbuntuOneNautilus *uon, SyncdaemonFolderInfo *folder_info, GtkWidget *widget)
 
29
{
 
30
        SyncdaemonInterface *interface;
 
31
        GHashTable *shares = NULL;
 
32
        gboolean result = TRUE;
 
33
 
 
34
        interface = syncdaemon_daemon_get_shares_interface (uon->syncdaemon);
 
35
        if (SYNCDAEMON_IS_SHARES_INTERFACE (interface)) {
 
36
                GSList *shared_list, *l;
 
37
 
 
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);
 
41
 
 
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)) {
 
45
                                gchar *path;
 
46
                                const gchar *username;
 
47
                                GSList *users = NULL;
 
48
 
 
49
                                if (shares == NULL)
 
50
                                        shares = g_hash_table_new (g_str_hash, g_str_equal);
 
51
 
 
52
                                g_hash_table_lookup_extended (shares,
 
53
                                                              syncdaemon_share_info_get_path (share_info),
 
54
                                                              (gpointer *) &path,
 
55
                                                              (gpointer *) &users);
 
56
 
 
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);
 
60
                                else
 
61
                                        username = syncdaemon_share_info_get_username (share_info);
 
62
 
 
63
                                users = g_slist_append (users, (gpointer) username);
 
64
                                g_hash_table_insert (shares,
 
65
                                                     (gpointer) syncdaemon_share_info_get_path (share_info),
 
66
                                                     (gpointer) users);
 
67
                        }
 
68
                }
 
69
 
 
70
                g_slist_free (shared_list);
 
71
 
 
72
                /* If there are shares, ask the user what to do */
 
73
                if (shares != NULL) {
 
74
                        GtkWidget *dialog;
 
75
                        GHashTableIter iter;
 
76
                        GString *question;
 
77
                        gchar *path;
 
78
                        GSList *users;
 
79
 
 
80
                        question = g_string_new (_("This folder contains folders that have been shared:\n\n"));
 
81
 
 
82
                        g_hash_table_iter_init (&iter, shares);
 
83
                        while (g_hash_table_iter_next (&iter, (gpointer) &path, (gpointer) &users)) {
 
84
                                gint count = 0;
 
85
 
 
86
                                question = g_string_append (question, "\t- ");
 
87
                                question = g_string_append (question, path);
 
88
                                question = g_string_append (question, " (");
 
89
 
 
90
                                while (users != NULL) {
 
91
                                        gchar *username = (gchar *) users->data;
 
92
 
 
93
                                        if (count > 0)
 
94
                                                question = g_string_append (question, ", ");
 
95
                                        question = g_string_append (question, username);
 
96
 
 
97
                                        users = g_slist_remove (users, username);
 
98
                                        count += 1;
 
99
                                }
 
100
 
 
101
                                question = g_string_append (question, ")\n");
 
102
                        }
 
103
 
 
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?"));
 
107
 
 
108
                        dialog = gtk_message_dialog_new (
 
109
                                GTK_WINDOW (gtk_widget_get_toplevel (widget)),
 
110
                                0, GTK_MESSAGE_QUESTION,
 
111
                                GTK_BUTTONS_YES_NO,
 
112
                                "%s", question->str);
 
113
                        if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_YES)
 
114
                                result = FALSE;
 
115
 
 
116
                        gtk_widget_destroy (dialog);
 
117
                        g_string_free (question, TRUE);
 
118
                        g_hash_table_destroy (shares);
 
119
 
 
120
                        if (!result)
 
121
                                return FALSE;
 
122
                }
 
123
 
 
124
        }
 
125
 
 
126
        /* Now check for published files */
 
127
        if (uon->gotpubs) {
 
128
                GHashTableIter iter;
 
129
                gchar *key, *value;
 
130
                GString *question;
 
131
                gboolean has_published = FALSE;
 
132
 
 
133
                question = g_string_new (_("This folder contains files that have been published:\n\n"));
 
134
 
 
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;
 
139
 
 
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");
 
145
                        }
 
146
                }
 
147
 
 
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?"));
 
151
 
 
152
                if (has_published) {
 
153
                        GtkWidget *dialog;
 
154
 
 
155
                        dialog = gtk_message_dialog_new (
 
156
                                GTK_WINDOW (gtk_widget_get_toplevel (widget)),
 
157
                                0, GTK_MESSAGE_QUESTION,
 
158
                                GTK_BUTTONS_YES_NO,
 
159
                                "%s", question->str);
 
160
                        if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_YES)
 
161
                                result = FALSE;
 
162
 
 
163
                        gtk_widget_destroy (dialog);
 
164
                }
 
165
 
 
166
                g_string_free (question, TRUE);
 
167
        }
 
168
 
 
169
        return result;
 
170
}