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 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357
|
/* evolution-python: Python bindings to libecal and libebook
* Copyright (c) 2007 John Stowers <john.stowers@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* 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 Library 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., 51 Franklin Street, Fifth Floor Boston, MA 02110-1301, USA
*/
/*
* evo-calendar.c is a wrapper around ECal and ECalComponent allowing
* access to Evolution Tasks, Memos and Calendar information
*/
#include "evo-calendar.h"
ECal *
evo_cal_source_open_source(const char *uri, ECalSourceType type)
{
ESourceList *sources = NULL;
ESource *source = NULL;
ECal *cal = NULL;
GError *gerror = NULL;
g_debug("Opening calendar source uri: %s\n", uri);
if (strcmp(uri, "default")) {
if (!e_cal_get_sources(&sources, type, &gerror)) {
g_warning("Unable to get sources for calendar (type %u): %s",
type, gerror && gerror->message ? gerror->message : "None");
g_clear_error(&gerror);
return NULL;
}
source = evo_environment_find_source(sources, uri);
if (!source) {
g_warning("Unable to find source for calendar (type %u)", type);
return NULL;
}
cal = e_cal_new(source, type);
if(!cal) {
g_warning("Failed to create new calendar (type %u)", type);
return NULL;
}
if(!e_cal_open(cal, FALSE, &gerror)) {
g_warning("Failed to open calendar (type %u): %s",
type, gerror && gerror->message? gerror->message : "None");
g_object_unref(cal);
g_clear_error(&gerror);
return NULL;
}
} else {
if (!e_cal_open_default (&cal, type, NULL, NULL, &gerror)) {
g_warning("Failed to open default calendar: %s",
gerror && gerror->message ? gerror->message : "None");
g_clear_error(&gerror);
return NULL;
}
}
return cal;
}
ECal *
evo_cal_source_open_new_with_absolute_uri(const char *name, const char *uri, ECalSourceType type)
{
ESource *source = NULL;
ECal *cal = NULL;
GError *gerror = NULL;
g_debug("Opening new calendar source uri: %s\n", uri);
source = e_source_new_with_absolute_uri(name, uri);
if (!source) {
g_warning("Unable to open source for calendar (type %u)", type);
return NULL;
}
cal = e_cal_new(source, type);
if(!cal) {
g_warning("Failed to create new calendar (type %u)", type);
return NULL;
}
if(!e_cal_open(cal, FALSE, &gerror)) {
g_warning("Failed to open calendar (type %u): %s", type,
gerror && gerror->message ? gerror->message : "None");
g_object_unref(cal);
g_clear_error(&gerror);
return NULL;
}
return cal;
}
gboolean
evo_cal_source_remove_object(ECal *ecal, ECalComponent *obj)
{
char *uid = NULL;
GError *error = NULL;
gboolean ret = FALSE;
uid = evo_cal_component_get_uid(obj);
if (uid) {
if (e_cal_remove_object(ecal, uid, &error)) {
ret = TRUE;
} else {
g_warning("failed to remove %s: %s", uid, error ? error->message : "None");
g_clear_error(&error);
}
}
g_free(uid);
return ret;
}
gboolean
evo_cal_source_update_object(ECal *ecal, ECalComponent *obj)
{
if (!e_cal_modify_object (ecal, e_cal_component_get_icalcomponent(obj),
CALOBJ_MOD_ALL, NULL))
return FALSE;
return TRUE;
}
void
evo_cal_source_print_all_objects(ECal *ecal)
{
GList* ical_objects = NULL;
GList* l = NULL;
GError *error = NULL;
char *str = NULL;
if (e_cal_get_object_list (ecal, "#t", &ical_objects, &error))
{
for (l = ical_objects; l; l = l->next) {
str = icalcomponent_as_ical_string (l->data);
g_print("%s\n", str);
}
e_cal_free_object_list (ical_objects);
}
}
char *
evo_cal_source_add_object(ECal *ecal, ECalComponent *obj)
{
char *uid;
GError *error = NULL;
//uid = e_cal_component_gen_uid ();
//e_cal_component_set_uid (comp, uid);
if (!e_cal_create_object (ecal, e_cal_component_get_icalcomponent (obj), &uid, &error)) {
g_warning("error adding object: %s\n", error ? error->message : "None");
g_clear_error (&error);
}
return uid;
}
ECalComponent *
evo_cal_source_get_object(ECal *ecal, const char *uid, const char *rid)
{
ECalComponent *comp = NULL;
icalcomponent *icalcomp = NULL;
GError *error = NULL;
if (e_cal_get_object (ecal, uid, rid, &icalcomp, &error)) {
comp = e_cal_component_new ();
if (!e_cal_component_set_icalcomponent (comp, icalcomp)) {
g_object_unref (comp);
icalcomponent_free (icalcomp);
}
} else {
g_warning("Could not find object (uid: %s): %s\n", uid, error ? error->message : "None");
g_clear_error (&error);
}
return comp;
}
char *
evo_cal_source_get_uid(ECal *ecal)
{
ESource *source = NULL;
const char *uid = NULL;
source = e_cal_get_source(ecal);
if (source)
uid = e_source_peek_uid(source);
if (uid)
return g_strdup(uid);
return NULL;
}
char *
evo_cal_component_get_uid(ECalComponent *obj)
{
const char *uid = NULL;
e_cal_component_get_uid(obj, &uid);
if (uid)
return g_strdup(uid);
else
return NULL;
}
glong
evo_cal_component_get_modified(ECalComponent *obj)
{
struct icaltimetype *tt;
tt = g_malloc0 (sizeof (struct icaltimetype));
e_cal_component_get_last_modified(obj, &tt);
if (tt)
return icaltime_as_timet(*tt);
else
return 0;
}
void
evo_cal_component_set_modified(ECalComponent *obj, glong seconds)
{
struct icaltimetype tt;
tt = icaltime_from_timet(seconds, TRUE);
e_cal_component_set_last_modified(obj, &tt);
}
icalproperty_status
evo_cal_component_get_status(ECalComponent *obj)
{
icalproperty_status status;
e_cal_component_get_status(obj, &status);
return status;
}
void
evo_cal_component_set_status(ECalComponent *obj, icalproperty_status status)
{
e_cal_component_set_status(obj, status);
}
int
evo_cal_component_get_priority(ECalComponent *comp)
{
int* pp;
int p;
e_cal_component_get_priority(comp, &pp);
if (pp == NULL)
return 0; // default taken from Ross Burton's tasks
p = *pp;
e_cal_component_free_priority(pp);
return p;
}
void
evo_cal_component_set_priority(ECalComponent *comp, int priority)
{
if (priority == 0) // 0 means no priority
e_cal_component_set_priority(comp, NULL);
else
e_cal_component_set_priority(comp, &priority);
}
char *
evo_cal_component_get_url(ECalComponent *obj)
{
const char* url;
e_cal_component_get_url(obj, &url);
if (url == NULL)
return NULL;
return g_strdup(url);
}
void
evo_cal_component_set_url(ECalComponent *obj, const char *url)
{
e_cal_component_set_url(obj, url);
}
char *
evo_cal_component_get_summary(ECalComponent *obj)
{
ECalComponentText txt;
e_cal_component_get_summary(obj, &txt);
return g_strdup(txt.value);
}
void
evo_cal_component_set_summary(ECalComponent *obj, const char *summary)
{
ECalComponentText *txt = NULL;
txt = g_malloc0(sizeof (ECalComponentText));
txt->value = g_strdup(summary);
e_cal_component_set_summary(obj, txt);
}
char *
evo_cal_component_get_description(ECalComponent *obj)
{
GSList *list = NULL;
char *desc = NULL;
ECalComponentText *txt = NULL;
e_cal_component_get_description_list(obj, &list);
//FIXME: I only return the first description. I should return them all with
//_wrap_string_glist and friends
if (list) {
txt = (ECalComponentText *)list->data;
if (txt)
desc = g_strdup(txt->value);
e_cal_component_free_text_list(list);
}
return desc;
}
void
evo_cal_component_set_description(ECalComponent *obj, const char *desc)
{
GSList l;
ECalComponentText text;
if (desc) {
text.value = g_strdup(desc);
text.altrep = NULL;
l.data = &text;
l.next = NULL;
e_cal_component_set_description_list (obj, &l);
}
}
|