1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
|
/*
*
* Copyright (C) 2008 Matthias Braun <matze@braunis.de>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 2 of the GNU Lesser General Public
* License as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* * You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <string.h>
#include <glib/gi18n-lib.h>
#include <glib.h>
#include <gtk/gtk.h>
#include <e-util/e-config.h>
#include <e-util/e-plugin.h>
#include <e-util/e-plugin-util.h>
#include <addressbook/gui/widgets/eab-config.h>
#include <libedataserver/e-source.h>
#include <libedataserver/e-source-list.h>
#include <libedataserver/e-account-list.h>
#define BASE_URI "webdav://"
typedef struct {
ESource *source;
GtkWidget *box;
GtkEntry *url_entry;
GtkEntry *username_entry;
GtkToggleButton *avoid_ifmatch_toggle;
} ui_data;
GtkWidget *
plugin_webdav_contacts(EPlugin *epl, EConfigHookItemFactoryData *data);
gint
e_plugin_lib_enable(EPlugin *ep, gint enable);
static void
ensure_webdav_contacts_source_group(void)
{
ESourceList *source_list;
source_list = e_source_list_new_for_gconf_default("/apps/evolution/addressbook/sources");
if (source_list == NULL) {
return;
}
e_source_list_ensure_group (source_list, _("WebDAV"), BASE_URI, FALSE);
g_object_unref (source_list);
}
static void
remove_webdav_contacts_source_group(void)
{
ESourceList *source_list;
ESourceGroup *group;
source_list = e_source_list_new_for_gconf_default("/apps/evolution/addressbook/sources");
if (source_list == NULL) {
return;
}
group = e_source_list_peek_group_by_base_uri (source_list, BASE_URI);
if (group) {
GSList *sources;
sources = e_source_group_peek_sources(group);
if (NULL == sources) {
e_source_list_remove_group(source_list, group);
e_source_list_sync(source_list, NULL);
}
}
g_object_unref(source_list);
}
static void
set_ui_from_source(ui_data *data)
{
ESource *source = data->source;
const gchar *url = e_source_get_uri(source);
SoupURI *suri = soup_uri_new (url);
gchar *url_ui;
const gchar *property;
gboolean use_ssl;
gboolean avoid_ifmatch;
property = e_source_get_property(source, "use_ssl");
if (property != NULL && strcmp(property, "1") == 0) {
use_ssl = TRUE;
} else {
use_ssl = FALSE;
}
property = e_source_get_property(source, "avoid_ifmatch");
if (property != NULL && strcmp(property, "1") == 0) {
avoid_ifmatch = TRUE;
} else {
avoid_ifmatch = FALSE;
}
gtk_toggle_button_set_active(data->avoid_ifmatch_toggle, avoid_ifmatch);
/* it's really a http or https protocol */
if (suri)
soup_uri_set_scheme (suri, use_ssl ? "https" : "http");
/* remove user/username and set user field */
if (suri && suri->user != NULL) {
gtk_entry_set_text (data->username_entry, suri->user);
soup_uri_set_user (suri, NULL);
} else {
gtk_entry_set_text(data->username_entry, "");
}
if (suri)
url_ui = soup_uri_to_string (suri, FALSE);
else
url_ui = g_strdup ("");
gtk_entry_set_text (data->url_entry, url_ui);
g_free (url_ui);
if (suri)
soup_uri_free (suri);
}
static void
set_source_from_ui (ui_data *data)
{
ESource *source = data->source;
gboolean avoid_ifmatch = gtk_toggle_button_get_active(data->avoid_ifmatch_toggle);
const gchar *url = gtk_entry_get_text(data->url_entry);
SoupURI *suri = soup_uri_new (url);
gchar *url_noprotocol;
gboolean use_ssl;
if (!suri)
return;
e_source_set_property(source, "avoid_ifmatch", avoid_ifmatch ? "1" : "0");
/* put username into uri */
soup_uri_set_user (suri, gtk_entry_get_text (data->username_entry));
if (suri->user && *suri->user) {
e_source_set_property(source, "auth", "plain/password");
e_source_set_property(source, "username", suri->user);
} else {
e_source_set_property(source, "auth", NULL);
e_source_set_property(source, "username", NULL);
}
/* set use_ssl based on protocol in URL */
if (suri->scheme && g_str_equal (suri->scheme, "https")) {
use_ssl = TRUE;
} else {
use_ssl = FALSE;
}
e_source_set_property(source, "use_ssl", use_ssl ? "1" : "0");
url_noprotocol = e_plugin_util_uri_no_proto (suri);
e_source_set_relative_uri (source, url_noprotocol);
g_free (url_noprotocol);
soup_uri_free (suri);
}
static void
destroy_ui_data (gpointer data)
{
ui_data *ui = data;
if (ui && ui->box)
gtk_widget_destroy (ui->box);
g_free (ui);
}
GtkWidget *
plugin_webdav_contacts(EPlugin *epl, EConfigHookItemFactoryData *data)
{
EABConfigTargetSource *t = (EABConfigTargetSource *) data->target;
ESource *source;
GtkWidget *parent;
GtkWidget *vbox;
GtkWidget *section;
GtkWidget *vbox2;
GtkBox *hbox;
GtkWidget *spacer;
GtkWidget *label;
ui_data *uidata;
gchar *buff;
source = t->source;
g_object_set_data (G_OBJECT (epl), "wwidget", NULL);
if (!e_plugin_util_is_group_proto (e_source_peek_group (source), BASE_URI)) {
return NULL;
}
uidata = g_malloc0(sizeof(uidata[0]));
uidata->source = source;
/* Build up the UI */
parent = data->parent;
vbox = gtk_widget_get_ancestor(gtk_widget_get_parent(parent), GTK_TYPE_VBOX);
vbox2 = gtk_vbox_new(FALSE, 6);
gtk_box_pack_start(GTK_BOX(vbox), vbox2, FALSE, FALSE, 0);
section = gtk_label_new(NULL);
buff = g_strconcat ("<b>", _("Server"), "</b>", NULL);
gtk_label_set_markup(GTK_LABEL(section), buff);
g_free (buff);
gtk_misc_set_alignment(GTK_MISC(section), 0.0, 0.0);
gtk_box_pack_start(GTK_BOX(vbox2), section, FALSE, FALSE, 0);
hbox = GTK_BOX(gtk_hbox_new(FALSE, 10));
gtk_box_pack_start(GTK_BOX(vbox2), GTK_WIDGET(hbox), TRUE, TRUE, 0);
spacer = gtk_label_new(" ");
gtk_box_pack_start(hbox, spacer, FALSE, FALSE, 0);
label = gtk_label_new(_("URL:"));
gtk_box_pack_start(hbox, label, FALSE, FALSE, 0);
uidata->url_entry = GTK_ENTRY(gtk_entry_new());
gtk_box_pack_start(hbox, GTK_WIDGET(uidata->url_entry), TRUE, TRUE, 0);
hbox = GTK_BOX(gtk_hbox_new(FALSE, 10));
gtk_box_pack_start(GTK_BOX(vbox2), GTK_WIDGET(hbox), TRUE, TRUE, 0);
spacer = gtk_label_new(" ");
gtk_box_pack_start(hbox, spacer, FALSE, FALSE, 0);
label = gtk_label_new_with_mnemonic(_("User_name:"));
gtk_box_pack_start(hbox, label, FALSE, FALSE, 0);
uidata->username_entry = GTK_ENTRY(gtk_entry_new());
gtk_box_pack_start(hbox, GTK_WIDGET(uidata->username_entry), TRUE, TRUE, 0);
hbox = GTK_BOX(gtk_hbox_new(FALSE, 10));
gtk_box_pack_start(GTK_BOX(vbox2), GTK_WIDGET(hbox), TRUE, TRUE, 0);
spacer = gtk_label_new(" ");
gtk_box_pack_start(hbox, spacer, FALSE, FALSE, 0);
uidata->avoid_ifmatch_toggle = GTK_TOGGLE_BUTTON(
gtk_check_button_new_with_mnemonic(
_("_Avoid IfMatch (needed on Apache < 2.2.8)")));
gtk_box_pack_start(hbox, GTK_WIDGET(uidata->avoid_ifmatch_toggle),
FALSE, FALSE, 0);
set_ui_from_source(uidata);
gtk_widget_show_all(vbox2);
uidata->box = vbox2;
g_object_set_data_full(G_OBJECT(epl), "wwidget", uidata, destroy_ui_data);
g_signal_connect (uidata->box, "destroy", G_CALLBACK (gtk_widget_destroyed), &uidata->box);
g_signal_connect_swapped (G_OBJECT(uidata->username_entry), "changed", G_CALLBACK (set_source_from_ui), uidata);
g_signal_connect_swapped (G_OBJECT(uidata->url_entry), "changed", G_CALLBACK (set_source_from_ui), uidata);
g_signal_connect_swapped (G_OBJECT(uidata->avoid_ifmatch_toggle), "toggled", G_CALLBACK (set_source_from_ui), uidata);
return NULL;
}
gint
e_plugin_lib_enable(EPlugin *ep, gint enable)
{
if (enable) {
ensure_webdav_contacts_source_group();
} else {
remove_webdav_contacts_source_group();
}
return 0;
}
|