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 304 305 306 307 308 309 310 311
|
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*-
* ex: set ts=8: */
/* Evolution calendar - caldav backend
*
* Copyright (C) 2005 Novell, Inc.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 2 of the GNU 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*
* Author: Christian Kellner <gicmo@gnome.org>
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#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 <calendar/gui/e-cal-config.h>
#include <libedataserver/e-url.h>
#include <libedataserver/e-account-list.h>
#include <libecal/e-cal.h>
#include <string.h>
/*****************************************************************************/
/* prototypes */
int e_plugin_lib_enable (EPluginLib *ep,
int enable);
GtkWidget * oge_caldav (EPlugin *epl,
EConfigHookItemFactoryData *data);
/*****************************************************************************/
/* plugin intialization */
static void
ensure_caldav_source_group ()
{
ESourceList *slist;
ESourceGroup *group;
if (!e_cal_get_sources (&slist, E_CAL_SOURCE_TYPE_EVENT, NULL)) {
g_warning ("Could not get calendar source list from GConf!");
return;
}
group = e_source_list_peek_group_by_name (slist, _("CalDAV"));
if (group == NULL) {
gboolean res;
group = e_source_group_new (_("CalDAV"), "caldav://");
res = e_source_list_add_group (slist, group, -1);
if (res == FALSE) {
g_warning ("Could not add CalDAV source group!");
} else {
e_source_list_sync (slist, NULL);
}
g_object_unref (group);
g_object_unref (slist);
}
}
int
e_plugin_lib_enable (EPluginLib *ep, int enable)
{
if (enable) {
g_print ("CalDAV Eplugin starting up ...\n");
ensure_caldav_source_group ();
}
return 0;
}
/*****************************************************************************/
/* the location field for caldav sources */
/* stolen from calendar-weather eplugin */
static gchar *
print_uri_noproto (EUri *uri)
{
gchar *uri_noproto;
if (uri->port != 0)
uri_noproto = g_strdup_printf (
"%s%s%s%s%s%s%s:%d%s%s%s",
uri->user ? uri->user : "",
uri->authmech ? ";auth=" : "",
uri->authmech ? uri->authmech : "",
uri->passwd ? ":" : "",
uri->passwd ? uri->passwd : "",
uri->user ? "@" : "",
uri->host ? uri->host : "",
uri->port,
uri->path ? uri->path : "",
uri->query ? "?" : "",
uri->query ? uri->query : "");
else
uri_noproto = g_strdup_printf (
"%s%s%s%s%s%s%s%s%s%s",
uri->user ? uri->user : "",
uri->authmech ? ";auth=" : "",
uri->authmech ? uri->authmech : "",
uri->passwd ? ":" : "",
uri->passwd ? uri->passwd : "",
uri->user ? "@" : "",
uri->host ? uri->host : "",
uri->path ? uri->path : "",
uri->query ? "?" : "",
uri->query ? uri->query : "");
return uri_noproto;
}
static void
location_changed (GtkEntry *editable, ESource *source)
{
EUri *euri;
char *ruri;
const char *uri;
uri = gtk_entry_get_text (GTK_ENTRY (editable));
euri = e_uri_new (uri);
ruri = print_uri_noproto (euri);
e_source_set_relative_uri (source, ruri);
g_free (ruri);
e_uri_free (euri);
}
static void
ssl_changed (GtkToggleButton *button, ESource *source)
{
e_source_set_property(source, "ssl",
gtk_toggle_button_get_active(button) ? "1" : "0");
}
static void
user_changed (GtkEntry *editable, ESource *source)
{
EUri *euri;
char *uri;
char *ruri;
const char *user;
uri = e_source_get_uri (source);
user = gtk_entry_get_text (GTK_ENTRY (editable));
if (uri == NULL) {
g_free (uri);
return;
}
euri = e_uri_new (uri);
g_free (euri->user);
if (user != NULL) {
euri->user = g_strdup (user);
e_source_set_property (source, "auth", "1");
} else {
e_source_set_property (source, "auth", NULL);
}
e_source_set_property (source, "username", euri->user);
ruri = print_uri_noproto (euri);
e_source_set_relative_uri (source, ruri);
g_free (ruri);
e_uri_free (euri);
}
GtkWidget *
oge_caldav (EPlugin *epl,
EConfigHookItemFactoryData *data)
{
ECalConfigTargetSource *t = (ECalConfigTargetSource *) data->target;
ESource *source;
ESourceGroup *group;
EUri *euri;
GtkWidget *parent;
GtkWidget *lurl;
GtkWidget *cssl;
GtkWidget *location;
GtkWidget *widget;
GtkWidget *luser;
GtkWidget *user;
char *uri;
char *username;
const char *ssl_prop;
gboolean ssl_enabled;
int row;
source = t->source;
group = e_source_peek_group (source);
widget = NULL;
if (!g_str_has_prefix (e_source_group_peek_base_uri (group),
"caldav")) {
return NULL;
}
/* Extract the username from the uri so we can prefill the
* dialog right, remove the username from the url then */
uri = e_source_get_uri (source);
euri = e_uri_new (uri);
g_free (uri);
if (euri == NULL) {
return NULL;
}
username = euri->user;
euri->user = NULL;
uri = e_uri_to_string (euri, FALSE);
ssl_prop = e_source_get_property (source, "ssl");
if (ssl_prop && ssl_prop[0] == '1') {
ssl_enabled = TRUE;
} else {
ssl_enabled = FALSE;
}
/* Build up the UI */
parent = data->parent;
row = GTK_TABLE (parent)->nrows;
lurl = gtk_label_new_with_mnemonic (_("_URL:"));
gtk_widget_show (lurl);
gtk_misc_set_alignment (GTK_MISC (lurl), 0.0, 0.5);
gtk_table_attach (GTK_TABLE (parent),
lurl, 0, 1,
row, row+1,
GTK_FILL, 0, 0, 0);
location = gtk_entry_new ();
gtk_widget_show (location);
gtk_entry_set_text (GTK_ENTRY (location), uri);
gtk_table_attach (GTK_TABLE (parent), location,
1, 2, row, row+1,
GTK_EXPAND | GTK_FILL, 0, 0, 0);
gtk_label_set_mnemonic_widget (GTK_LABEL (lurl), location);
g_signal_connect (G_OBJECT (location),
"changed",
G_CALLBACK (location_changed),
source);
cssl = gtk_check_button_new_with_mnemonic (_("Use _SSL"));
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(cssl), ssl_enabled);
gtk_widget_show (cssl);
gtk_table_attach (GTK_TABLE (parent),
cssl, 1, 2,
row + 1, row + 2,
GTK_FILL, 0, 0, 0);
g_signal_connect (G_OBJECT (cssl),
"toggled",
G_CALLBACK (ssl_changed),
source);
luser = gtk_label_new_with_mnemonic (_("User_name:"));
gtk_widget_show (luser);
gtk_misc_set_alignment (GTK_MISC (luser), 0.0, 0.5);
gtk_table_attach (GTK_TABLE (parent),
luser, 0, 1,
row + 2, row + 3,
GTK_FILL, 0, 0, 0);
user = gtk_entry_new ();
gtk_widget_show (user);
gtk_entry_set_text (GTK_ENTRY (user), username ? username : "");
gtk_table_attach (GTK_TABLE (parent), user,
1, 2, row + 2, row + 3,
GTK_EXPAND | GTK_FILL, 0, 0, 0);
gtk_label_set_mnemonic_widget (GTK_LABEL (luser), user);
g_signal_connect (G_OBJECT (user),
"changed",
G_CALLBACK (user_changed),
source);
g_free (uri);
g_free (username);
return widget;
}
|