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
|
/* -*- Mode: C; c-basic-offset: 4; tab-width: 4 -*- */
%%
headers
#include <time.h>
#include <Python.h>
#include "config.h"
#define NO_IMPORT_PYGOBJECT
#include "pygobject.h"
#include "override_common.h"
#include "evo-ecal-environment.h"
#include "evo-calendar.h"
static PyObject *
_helper_wrap_glist_of_evo_locations(GList *locations)
{
PyObject *result;
int i;
if ((result = PyList_New (g_list_length (locations))) == NULL)
return NULL;
i = 0;
for (; locations != NULL; locations = locations->next) {
evo_location_t *path = (evo_location_t *) locations->data;
PyObject *t = PyTuple_New (2);
if (path->name == NULL) {
Py_INCREF (Py_None);
PyTuple_SET_ITEM (t, 0, Py_None);
} else {
PyTuple_SET_ITEM (t, 0, PyString_FromString(path->name));
}
if (path->uri == NULL) {
Py_INCREF (Py_None);
PyTuple_SET_ITEM (t, 1, Py_None);
} else {
PyTuple_SET_ITEM (t, 1, PyString_FromString(path->uri));
}
PyList_SET_ITEM (result, i, t);
i++;
}
return result;
}
%%
modulename ecal
%%
import gobject.GObject as PyGObject_Type
%%
ignore-glob
init
free_*
*_get_type
%%
override evo_environment_list_calendars noargs
static PyObject*
_wrap_evo_environment_list_calendars(PyGObject *self)
{
GList *list = NULL;
list = evo_environment_list_cal_sources(E_CAL_SOURCE_TYPE_EVENT);
return _helper_wrap_glist_of_evo_locations(list);
}
%%
override evo_environment_list_task_sources noargs
static PyObject*
_wrap_evo_environment_list_task_sources(PyGObject *self)
{
GList *list = NULL;
list = evo_environment_list_cal_sources(E_CAL_SOURCE_TYPE_TODO);
return _helper_wrap_glist_of_evo_locations(list);
}
%%
override evo_environment_list_memo_sources noargs
static PyObject*
_wrap_evo_environment_list_memo_sources(PyGObject *self)
{
GList *list = NULL;
list = evo_environment_list_cal_sources(E_CAL_SOURCE_TYPE_JOURNAL);
return _helper_wrap_glist_of_evo_locations(list);
}
%%
override evo_cal_source_get_all_objects noargs
static PyObject*
_wrap_evo_cal_source_get_all_objects(PyGObject *self)
{
GList *objects = NULL;
GError *error = NULL;
e_cal_get_object_list_as_comp(
E_CAL(self->obj),
"#t",
&objects,
&error);
//Fixme: Check error
//evo_cal_source_print_all_objects(E_CAL(self->obj));
return _helper_wrap_gobject_glist(objects);
}
%%
override e_cal_component_new kwargs
static int
_wrap_e_cal_component_new(PyGObject *self, PyObject *args, PyObject *kwargs)
{
static char *kwlist[] = { "ical", "type", NULL };
gchar *ical = NULL;
int type = E_CAL_COMPONENT_NO_TYPE;
ECalComponent *comp = NULL;
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i|z:ECalComponent.__init__",
kwlist, &type, &ical))
return -1;
if (ical) {
comp = (ECalComponent *) e_cal_component_new_from_string(ical);
} else {
comp = (ECalComponent *) e_cal_component_new();
e_cal_component_set_new_vtype(comp, type);
}
if (!comp) {
PyErr_SetString(PyExc_RuntimeError, "could not create ECalComponent object");
return -1;
} else {
self->obj = (GObject*) comp;
return 0;
}
}
%%
override e_cal_get_component_as_string args
static PyObject *
_wrap_e_cal_get_component_as_string(PyGObject *self, PyObject *args)
{
char *s;
PyGObject *obj;
icalcomponent *ic;
if (!PyArg_ParseTuple(args, "O!:ECal.get_component_as_string", &PyECalComponent_Type, (PyGObject **)&obj))
return NULL;
ic = e_cal_component_get_icalcomponent(E_CAL_COMPONENT(obj->obj));
s = e_cal_get_component_as_string(E_CAL(self->obj),ic);
return PyString_FromString(s);
}
%%
override evo_cal_component_get_due noargs
static PyObject *
_wrap_evo_cal_component_get_due(PyGObject *self)
{
ECalComponent *calcomponent;
ECalComponentDateTime dt;
glong t;
calcomponent = E_CAL_COMPONENT(self->obj);
e_cal_component_get_due(calcomponent, &dt);
if (dt.value == NULL) {
e_cal_component_free_datetime(&dt);
Py_INCREF(Py_None);
return Py_None;
}
t = icaltime_as_timet_with_zone(*(dt.value),
icaltimezone_get_utc_timezone());
e_cal_component_free_datetime(&dt);
return PyInt_FromLong(t);
}
%%
override evo_cal_component_set_due args
static PyObject *
_wrap_evo_cal_component_set_due(PyGObject *self, PyObject *args)
{
ECalComponent *calcomponent;
ECalComponentDateTime *dt;
PyObject* due;
if (PyTuple_Size(args) != 1) {
PyErr_SetString(PyExc_RuntimeError, "ECalComponent.set_due takes exactly 1 argument");
return NULL;
}
calcomponent = E_CAL_COMPONENT(self->obj);
due = PyTuple_GET_ITEM(args, 0);
if (due == Py_None) {
// TV-TODO: how to clear the due date do this? gnome bugzilla #452915
//e_cal_component_set_due(calcomponent, NULL);
icalcomponent *ic = e_cal_component_get_icalcomponent (calcomponent);
icalproperty *ip = icalcomponent_get_first_property(ic, ICAL_DUE_PROPERTY);
if (ip != NULL) {
icalcomponent_remove_property (ic, ip);
icalproperty_free (ip);
}
e_cal_component_set_icalcomponent(calcomponent, ic);
e_cal_component_rescan(calcomponent);
Py_INCREF(Py_None);
return Py_None;
}
else if (! PyInt_Check(due)) {
PyErr_SetString(PyExc_RuntimeError, "due date must be int timestamp or None");
return NULL;
}
dt = g_malloc0 (sizeof (ECalComponentDateTime));
dt->value = g_malloc0 (sizeof (struct icaltimetype));
(*dt->value) = icaltime_from_timet(PyInt_AsLong(due), TRUE);
e_cal_component_set_due(calcomponent, dt);
Py_INCREF(Py_None);
return Py_None;
}
%%
override evo_cal_component_get_categories_list noargs
static PyObject *
_wrap_evo_cal_component_get_categories_list(PyGObject *self)
{
ECalComponent *calcomponent;
GSList* categories;
GSList* l;
PyObject* res;
int i = 0;
calcomponent = E_CAL_COMPONENT(self->obj);
e_cal_component_get_categories_list(calcomponent, &categories);
if (categories == NULL)
return PyList_New(0);
res = PyList_New(g_slist_length(categories));
for (l = categories; l; l = l->next, i++)
PyList_SetItem(res, i, PyString_FromString(l->data));
e_cal_component_free_categories_list(categories);
return res;
}
%%
override evo_cal_component_set_categories_list args
static PyObject *
_wrap_evo_cal_component_set_categories_list(PyGObject *self, PyObject *args)
{
ECalComponent *calcomponent;
GSList* categories = NULL;
PyObject* list;
char* item;
int i;
// TV-TODO: allow tuple?
if (!PyArg_ParseTuple(args, "O!:ECalComponent.set_categories_list",
&PyList_Type,&list))
return NULL;
for (i = PyList_Size(list)-1; i >= 0; i--) {
item = PyString_AsString(PyList_GetItem(list, i));
if (item == NULL) {
g_slist_free(categories);
return NULL;
}
categories = g_slist_prepend(categories, item);
}
calcomponent = E_CAL_COMPONENT(self->obj);
e_cal_component_set_categories_list(calcomponent, categories);
Py_INCREF(Py_None);
return Py_None;
}
|