~ubuntu-branches/ubuntu/precise/ubuntuone-client/precise-201112142106

« back to all changes in this revision

Viewing changes to nautilus/share-dialog.c

  • Committer: Bazaar Package Importer
  • Author(s): Rodney Dawes
  • Date: 2011-08-09 12:47:56 UTC
  • mfrom: (1.1.53 upstream)
  • Revision ID: james.westby@ubuntu.com-20110809124756-7nzilp3oix0a1yl9
Tags: 1.7.1-0ubuntu1
* New upstream release.
* debian/*:
  - Removed obsolete pycompat file
  - Removed ubuntuone-client-gnome deps and binary packaging, as it was
    moved out to separate project upstream.
  - Updated copyright to remove obsolete file reference
* debian/patches:
  - Removed patches which have been included upstream.

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
 
#ifdef HAVE_CONFIG_H
23
 
#include <config.h>
24
 
#endif
25
 
 
26
 
#include <glib/gi18n-lib.h>
27
 
#include <libsyncdaemon/libsyncdaemon.h>
28
 
#include "share-dialog.h"
29
 
#include "u1-contacts-picker.h"
30
 
 
31
 
G_DEFINE_TYPE(ShareDialog, share_dialog, GTK_TYPE_DIALOG)
32
 
 
33
 
static void
34
 
share_dialog_finalize (GObject *object)
35
 
{
36
 
        ShareDialog *dialog = SHARE_DIALOG (object);
37
 
 
38
 
        if (dialog->path != NULL)
39
 
                g_free (dialog->path);
40
 
 
41
 
        G_OBJECT_CLASS (share_dialog_parent_class)->finalize (object);
42
 
}
43
 
 
44
 
static void
45
 
share_dialog_class_init (ShareDialogClass *klass)
46
 
{
47
 
        GObjectClass *object_class = G_OBJECT_CLASS (klass);
48
 
 
49
 
        object_class->finalize = share_dialog_finalize;
50
 
}
51
 
 
52
 
static void
53
 
picker_selection_changed_cb (U1ContactsPicker *picker, gpointer user_data)
54
 
{
55
 
        GSList *selection;
56
 
        GtkWidget * dialog = (GtkWidget *) user_data;
57
 
 
58
 
        selection = u1_contacts_picker_get_selected_emails (picker);
59
 
        if (selection != NULL) {
60
 
                gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT, TRUE);
61
 
                u1_contacts_picker_free_selection_list (selection);
62
 
        } else
63
 
                gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT, FALSE);
64
 
}
65
 
 
66
 
static void
67
 
dialog_response_cb (GtkDialog *gtk_dialog,
68
 
                    gint response,
69
 
                    gpointer user_data)
70
 
{
71
 
        ShareDialog *dialog = SHARE_DIALOG (gtk_dialog);
72
 
 
73
 
        switch (response) {
74
 
        case GTK_RESPONSE_ACCEPT: {
75
 
                GSList *emails;
76
 
                SyncdaemonSharesInterface *interface;
77
 
                gboolean allow_mods = FALSE;
78
 
 
79
 
                emails = u1_contacts_picker_get_selected_emails (U1_CONTACTS_PICKER (dialog->user_picker));
80
 
                if (emails == NULL) {
81
 
                        ubuntuone_show_error_dialog (dialog->uon,
82
 
                                                     _("Error"),
83
 
                                                     _("You need to select at least one contact to share this folder with"));
84
 
 
85
 
                        return;
86
 
                }
87
 
 
88
 
                allow_mods = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->allow_mods));
89
 
 
90
 
                interface = SYNCDAEMON_SHARES_INTERFACE (syncdaemon_daemon_get_shares_interface (dialog->uon->syncdaemon));
91
 
                if (interface != NULL) {
92
 
                        syncdaemon_shares_interface_create (interface,
93
 
                                                            dialog->path,
94
 
                                                            emails,
95
 
                                                            g_path_get_basename (dialog->path),
96
 
                                                            allow_mods);
97
 
                }
98
 
 
99
 
                u1_contacts_picker_free_selection_list (emails);
100
 
        }
101
 
        default:
102
 
                gtk_widget_destroy (GTK_WIDGET (dialog));
103
 
                break;
104
 
        }
105
 
}
106
 
 
107
 
static void
108
 
share_dialog_init (ShareDialog *dialog)
109
 
{
110
 
        GtkWidget *area, *table;
111
 
 
112
 
        gtk_window_set_title (GTK_WINDOW (dialog), _("Share on Ubuntu One"));
113
 
        gtk_window_set_destroy_with_parent (GTK_WINDOW (dialog), TRUE);
114
 
        gtk_dialog_add_buttons (GTK_DIALOG (dialog),
115
 
                                GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
116
 
                                (_("Share")), GTK_RESPONSE_ACCEPT,
117
 
                                NULL);
118
 
        gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT);
119
 
        gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT, FALSE);
120
 
        gtk_window_set_icon_name (GTK_WINDOW (dialog), "ubuntuone");
121
 
        g_signal_connect (G_OBJECT (dialog), "response",
122
 
                          G_CALLBACK (dialog_response_cb), NULL);
123
 
 
124
 
        area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
125
 
 
126
 
        table = gtk_table_new (3, 2, FALSE);
127
 
        gtk_table_set_row_spacings (GTK_TABLE (table), 12);
128
 
        gtk_table_set_col_spacings (GTK_TABLE (table), 6);
129
 
        gtk_container_set_border_width (GTK_CONTAINER (table), 7);
130
 
        gtk_widget_show (table);
131
 
        gtk_container_add (GTK_CONTAINER (area), table);
132
 
 
133
 
        dialog->user_picker = u1_contacts_picker_new ();
134
 
        g_signal_connect (G_OBJECT (dialog->user_picker), "selection-changed",
135
 
                          G_CALLBACK (picker_selection_changed_cb), dialog);
136
 
        gtk_table_attach (GTK_TABLE (table), dialog->user_picker, 0, 2, 0, 2,
137
 
                          GTK_FILL | GTK_EXPAND | GTK_SHRINK,
138
 
                          GTK_FILL | GTK_EXPAND | GTK_SHRINK, 3, 3);
139
 
        gtk_widget_show (dialog->user_picker);
140
 
 
141
 
        dialog->allow_mods = gtk_check_button_new_with_mnemonic (_("_Allow Modification"));
142
 
        gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->allow_mods), TRUE); /* Default to RW */
143
 
        gtk_table_attach (GTK_TABLE (table), dialog->allow_mods, 0, 2, 2, 3, GTK_FILL, GTK_FILL, 3, 3);
144
 
        gtk_widget_show (dialog->allow_mods);
145
 
 
146
 
        gtk_widget_set_size_request (GTK_WIDGET (dialog), 500, 450);
147
 
}
148
 
 
149
 
GtkWidget *
150
 
share_dialog_new (GtkWidget *parent, UbuntuOneNautilus *uon, const gchar *path)
151
 
{
152
 
        ShareDialog *dialog;
153
 
        
154
 
        dialog = (ShareDialog *) g_object_new (TYPE_SHARE_DIALOG, NULL);
155
 
        dialog->uon = uon;
156
 
        dialog->path = g_strdup (path);
157
 
        gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (parent));
158
 
 
159
 
        return (GtkWidget *) dialog;
160
 
}