~ubuntu-branches/ubuntu/precise/evolution/precise

« back to all changes in this revision

Viewing changes to plugins/groupwise-features/install-shared.c

  • Committer: Bazaar Package Importer
  • Author(s): Mathieu Trudel-Lapierre
  • Date: 2011-06-24 00:27:53 UTC
  • mfrom: (1.1.80 upstream)
  • Revision ID: james.westby@ubuntu.com-20110624002753-2vh1vjavlya7r103
Tags: 3.1.2-0ubuntu1
* New upstream release 3.1.2.
* debian/control: adjust Build-Depends to match new upstream requirements for
  the new release.
* debian/control: update evolution and evolution-dev Depends to require the
  right versions of e-d-s (>= 3.1, << 3.2), and drop libunique-3.0-dev.
* debian/control,
  debian/evolution.install: remove groupwise-features from the plugin list,
  it's now split out into a separate module.
* debian/patches/03_lpi.patch: refreshed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * This program is free software; you can redistribute it and/or
3
 
 * modify it under the terms of the GNU Lesser General Public
4
 
 * License as published by the Free Software Foundation; either
5
 
 * version 2 of the License, or (at your option) version 3.
6
 
 *
7
 
 * This program is distributed in the hope that it will be useful,
8
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
10
 
 * Lesser General Public License for more details.
11
 
 *
12
 
 * You should have received a copy of the GNU Lesser General Public
13
 
 * License along with the program; if not, see <http://www.gnu.org/licenses/>
14
 
 *
15
 
 *
16
 
 * Authors:
17
 
 *              Vivek Jain <jvivek@novell.com>
18
 
 *
19
 
 * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
20
 
 *
21
 
 */
22
 
 
23
 
#ifdef HAVE_CONFIG_H
24
 
#include <config.h>
25
 
#endif
26
 
 
27
 
#include <string.h>
28
 
#include <glib.h>
29
 
#include <gtk/gtk.h>
30
 
#include <glib/gi18n.h>
31
 
#include <gconf/gconf-client.h>
32
 
#include <e-util/e-config.h>
33
 
#include <e-util/e-account-utils.h>
34
 
#include <shell/e-shell.h>
35
 
#include <mail/e-mail-backend.h>
36
 
#include <mail/em-config.h>
37
 
#include <mail/em-event.h>
38
 
#include <mail/em-folder-tree.h>
39
 
#include <mail/em-folder-selector.h>
40
 
#include <e-gw-connection.h>
41
 
#include <share-folder.h>
42
 
 
43
 
struct AcceptData {
44
 
        CamelMimeMessage *msg;
45
 
        EMFolderTreeModel *model;
46
 
};
47
 
 
48
 
void org_gnome_popup_wizard (EPlugin *ep, EMEventTargetMessage *target);
49
 
 
50
 
static void
51
 
install_folder_response (EMFolderSelector *emfs, gint response, gpointer *data)
52
 
{
53
 
        struct AcceptData *accept_data = (struct AcceptData *)data;
54
 
        EMFolderTreeModel *model;
55
 
        const gchar *uri, *path;
56
 
        gint parts = 0;
57
 
        gchar **names;
58
 
        gchar *folder_name;
59
 
        gchar *parent_name;
60
 
        gchar *container_id;
61
 
        const gchar *item_id;
62
 
        CamelStore *store;
63
 
        CamelFolder *folder;
64
 
        EAccount *account;
65
 
        CamelProvider *provider;
66
 
        EGwConnection *cnc;
67
 
 
68
 
        if (response == GTK_RESPONSE_CANCEL) {
69
 
                gtk_widget_destroy (GTK_WIDGET (emfs));
70
 
        } else {
71
 
                CamelSession *session;
72
 
                EShell *shell;
73
 
 
74
 
                shell = e_shell_get_default ();
75
 
                session = e_shell_settings_get_pointer (e_shell_get_shell_settings (shell), "mail-session");
76
 
 
77
 
                model = accept_data->model;
78
 
                item_id = camel_mime_message_get_message_id (accept_data->msg);
79
 
                uri = em_folder_selector_get_selected_uri (emfs);
80
 
                path = em_folder_selector_get_selected_path (emfs);
81
 
                names = g_strsplit (path, "/", -1);
82
 
                if (names == NULL) {
83
 
                        folder_name = (gchar *)path;
84
 
                        parent_name = NULL;
85
 
                } else {
86
 
                        while (names[parts])
87
 
                                parts++;
88
 
                        folder_name = names[parts -1];
89
 
                        if (parts >= 2)
90
 
                                parent_name = names[parts -2];
91
 
                        else
92
 
                                parent_name = NULL;
93
 
                }
94
 
                store = (CamelStore *) camel_session_get_service (
95
 
                        session, uri, CAMEL_PROVIDER_STORE, NULL);
96
 
                if (store == NULL) {
97
 
                        g_strfreev (names);
98
 
                        return;
99
 
                }
100
 
 
101
 
                cnc = get_cnc (store);
102
 
                if (E_IS_GW_CONNECTION (cnc)) {
103
 
                        container_id = get_container_id (cnc, parent_name);
104
 
 
105
 
                        if (e_gw_connection_accept_shared_folder (cnc, folder_name, container_id, (gchar *)item_id, NULL) == E_GW_CONNECTION_STATUS_OK) {
106
 
 
107
 
                                /* FIXME Not passing a GCancellable or GError here. */
108
 
                                folder = camel_store_get_folder_sync (
109
 
                                        store, "Mailbox", 0, NULL, NULL);
110
 
                                /*changes = camel_folder_change_info_new ();
111
 
                                camel_folder_change_info_remove_uid (changes, (gchar *) item_id);
112
 
                                camel_folder_summary_remove_uid (folder->summary, item_id);*/
113
 
                                /* camel_folder_delete_message (folder, item_id); */
114
 
                                camel_folder_set_message_flags (
115
 
                                        folder, item_id,
116
 
                                        CAMEL_MESSAGE_DELETED,
117
 
                                        CAMEL_MESSAGE_DELETED);
118
 
                                camel_folder_summary_touch (folder->summary);
119
 
                                /* camel_object_trigger_event (CAMEL_OBJECT (folder), "folder_changed", changes); */
120
 
                                uri = camel_url_to_string (((CamelService *) store)->url, CAMEL_URL_HIDE_ALL);
121
 
                                account = e_get_account_by_source_url (uri);
122
 
                                uri = account->source->url;
123
 
                                em_folder_tree_model_remove_store (model, store);
124
 
                                provider = camel_provider_get (uri, NULL);
125
 
                                if (provider == NULL) {
126
 
                                        g_strfreev (names);
127
 
                                        return;
128
 
                                }
129
 
 
130
 
                                /* make sure the new store belongs in the tree */
131
 
                                if (!(provider->flags & CAMEL_PROVIDER_IS_STORAGE)) {
132
 
                                        g_strfreev (names);
133
 
                                        return;
134
 
                                }
135
 
 
136
 
                                em_folder_tree_model_add_store (model, store, account->name);
137
 
                                g_object_unref (store);
138
 
                        }
139
 
                }
140
 
 
141
 
                g_strfreev (names);
142
 
                gtk_widget_destroy ((GtkWidget *)emfs);
143
 
        }
144
 
 
145
 
}
146
 
 
147
 
static void
148
 
accept_free (gpointer data)
149
 
{
150
 
        struct AcceptData *accept_data = data;
151
 
 
152
 
        g_object_unref (accept_data->msg);
153
 
        g_free (accept_data);
154
 
}
155
 
 
156
 
static void
157
 
apply_clicked (GtkAssistant *assistant, CamelMimeMessage *msg)
158
 
{
159
 
        EShell *shell;
160
 
        EShellBackend *shell_backend;
161
 
        EMailSession *session;
162
 
        EMFolderTree *folder_tree;
163
 
        GtkWidget *dialog;
164
 
        struct AcceptData *accept_data;
165
 
        gchar *uri;
166
 
        gpointer parent;
167
 
 
168
 
        shell = e_shell_get_default ();
169
 
        shell_backend = e_shell_get_backend_by_name (shell, "mail");
170
 
        session = e_mail_backend_get_session (E_MAIL_BACKEND (shell_backend));
171
 
 
172
 
        parent = gtk_widget_get_toplevel (GTK_WIDGET (assistant));
173
 
        parent = gtk_widget_is_toplevel (parent) ? parent : NULL;
174
 
 
175
 
        accept_data = g_new0 (struct AcceptData, 1);
176
 
        folder_tree = (EMFolderTree *) em_folder_tree_new (session);
177
 
 
178
 
        dialog = em_folder_selector_create_new (parent, folder_tree, 0, _("Create folder"), _("Specify where to create the folder:"));
179
 
        uri = em_folder_tree_get_selected_uri (folder_tree);
180
 
        em_folder_selector_set_selected ((EMFolderSelector *) dialog, uri);
181
 
        g_free (uri);
182
 
        accept_data->msg = msg;
183
 
        g_object_ref (msg);
184
 
        accept_data->model = EM_FOLDER_TREE_MODEL (gtk_tree_view_get_model (GTK_TREE_VIEW (folder_tree)));
185
 
        g_object_set_data_full((GObject *)dialog, "accept-data", accept_data, accept_free);
186
 
        g_signal_connect (dialog, "response", G_CALLBACK (install_folder_response), accept_data);
187
 
        g_object_set_data_full((GObject *)dialog, "assistant", assistant, (GDestroyNotify)gtk_widget_destroy);
188
 
        gtk_window_set_title (GTK_WINDOW (dialog), "Install Shared Folder");
189
 
        gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
190
 
        gtk_widget_show (dialog);
191
 
}
192
 
 
193
 
void
194
 
org_gnome_popup_wizard (EPlugin *ep, EMEventTargetMessage *target)
195
 
{
196
 
        CamelInternetAddress *from_addr = NULL;
197
 
        const gchar *name;
198
 
        const gchar *email;
199
 
        CamelMimeMessage *msg = (CamelMimeMessage *) target->message;
200
 
        CamelStream *stream;
201
 
        CamelDataWrapper *dw;
202
 
        GByteArray *byte_array;
203
 
        gchar *start_message;
204
 
 
205
 
        if (!msg)
206
 
                return;
207
 
 
208
 
        if (((gchar *)camel_medium_get_header (CAMEL_MEDIUM(msg),"X-notification")) == NULL
209
 
            || (from_addr = camel_mime_message_get_from ((CamelMimeMessage *)target->message)) == NULL
210
 
            || !camel_internet_address_get (from_addr, 0, &name, &email)
211
 
            || (dw = camel_medium_get_content (CAMEL_MEDIUM (msg))) == NULL) {
212
 
                return;
213
 
        } else {
214
 
                if (CAMEL_IS_MULTIPART (dw)) {
215
 
                        dw = camel_medium_get_content ((CamelMedium *)camel_multipart_get_part ((CamelMultipart *)dw, 0));
216
 
                        if (dw == NULL)
217
 
                                return;
218
 
                }
219
 
 
220
 
                byte_array = g_byte_array_new ();
221
 
                stream = camel_stream_mem_new_with_byte_array (byte_array);
222
 
                camel_data_wrapper_write_to_stream_sync (dw, stream, NULL, NULL);
223
 
                camel_stream_write (stream, "", 1, NULL, NULL);
224
 
 
225
 
                from_addr = camel_mime_message_get_from ((CamelMimeMessage *)target->message);
226
 
                if (from_addr && camel_internet_address_get (from_addr, 0, &name, &email)) {
227
 
                        GtkWidget *page;
228
 
                        GtkAssistant *assistant = GTK_ASSISTANT (gtk_assistant_new ());
229
 
 
230
 
                        start_message = g_strdup_printf (_("The user '%s' has shared a folder with you\n\n"
231
 
                                                           "Message from '%s'\n\n\n"
232
 
                                                           "%s\n\n\n"
233
 
                                                           "Click 'Apply' to install the shared folder\n\n"),
234
 
                                                           name, name, byte_array->data);
235
 
 
236
 
                        page = gtk_label_new (start_message);
237
 
                        gtk_label_set_line_wrap (GTK_LABEL (page), TRUE);
238
 
                        gtk_misc_set_alignment (GTK_MISC (page), 0.0, 0.0);
239
 
                        gtk_misc_set_padding (GTK_MISC (page), 10, 10);
240
 
 
241
 
                        gtk_assistant_append_page (assistant, page);
242
 
                        gtk_assistant_set_page_title (assistant, page, _("Install the shared folder"));
243
 
                        gtk_assistant_set_page_type (assistant, page, GTK_ASSISTANT_PAGE_CONFIRM);
244
 
                        gtk_assistant_set_page_complete (assistant, page, TRUE);
245
 
 
246
 
                        gtk_window_set_title (GTK_WINDOW (assistant), _("Shared Folder Installation"));
247
 
                        gtk_window_set_position (GTK_WINDOW (assistant) , GTK_WIN_POS_CENTER_ALWAYS);
248
 
 
249
 
                        g_object_ref (msg);
250
 
                        g_object_set_data_full((GObject *)page, "msg", msg, g_object_unref);
251
 
 
252
 
                        g_signal_connect (assistant, "apply", G_CALLBACK (apply_clicked), msg);
253
 
 
254
 
                        gtk_widget_show_all (GTK_WIDGET (assistant));
255
 
 
256
 
                        g_free (start_message);
257
 
                } else
258
 
                        g_warning ("Could not get the sender name");
259
 
 
260
 
                g_object_unref (stream);
261
 
        }
262
 
}
263