📄 calendarmodule.cpp
字号:
if(PyList_SetItem(idList, i, instanceInfo)<0){
Py_DECREF(idList);
monthList->Reset();
delete monthList;
return NULL;
}
}
monthList->Reset();
delete monthList;
return idList;
}
/*
* Returns all instances (instance = entry's unique id +
* datetime of the specific occurrence of the entry)
* of the given day.
* -the day is the day (of the calendar like "11/02/2005")
* the given datetime parameter belongs to (it has no
* matter which moment of this day the datetime specifies).
* -returns list of instances like [{"unique_id":543245,
* "datetime":14565645.0}, {"unique_id":653456, "datetime":14565655.0}].
*/
extern "C" PyObject *
CalendarDb_daily_instances(CalendarDb_object* self, PyObject *args)
{
CHECK_AGENDA_STATE_DB
TReal day = 0;
CAgnDayList<TAgnInstanceId>* dayList = NULL;
TInt filterInt = 0;
if (!PyArg_ParseTuple(args, "d|i", &day, &filterInt)){
return NULL;
}
TTime dayTTime;
pythonRealAsTTime(day, dayTTime);
if(Check_time_validity(dayTTime)==EFalse){
PyErr_SetString(PyExc_ValueError, "illegal date value");
return NULL;
}
TTime today;
today.HomeTime();
TAgnFilter filter;
setFilterData(filter, filterInt);
// Create a day list.
TRAPD(error, {
dayList = CAgnDayList<TAgnInstanceId>::NewL(dayTTime.DateTime());
self->agendaModel->PopulateDayInstanceListL(dayList, filter, today);
});
if(error!=KErrNone){
if(dayList){
dayList->Reset();
delete dayList;
}
return SPyErr_SetFromSymbianOSErr(error);
}
PyObject* idList = PyList_New(dayList->Count());
if(idList==NULL){
dayList->Reset();
delete dayList;
return PyErr_NoMemory();
}
for(TInt i=0;i<dayList->Count();i++){
TAgnInstanceId id = (*dayList)[i];
PyObject* instanceInfo =
Py_BuildValue("{s:i,s:d}", (const char*)(&KUniqueId)->Ptr(),
self->agendaServer->GetUniqueId(id),
(const char*)(&KDateTime)->Ptr(),
time_as_UTC_TReal(AgnDateTime::AgnDateToTTime(id.Date())));
if(instanceInfo==NULL){
Py_DECREF(idList);
dayList->Reset();
delete dayList;
return NULL;
}
if(PyList_SetItem(idList, i, instanceInfo)<0){
Py_DECREF(idList);
dayList->Reset();
delete dayList;
return NULL;
}
}
dayList->Reset();
delete dayList;
return idList;
}
/*
* Finds instances (that occur between the specified time interval) by search string.
* -Only returns instances of one day (the first day that has instance that
* meets the criteria).
*/
extern "C" PyObject *
CalendarDb_find_instances(CalendarDb_object* self, PyObject *args)
{
CHECK_AGENDA_STATE_DB
TReal startDate = 0;
TReal endDate = 0;
PyObject* searchText = NULL;
TInt filterInt = 0;
CAgnDayList<TAgnInstanceId>* dayList = NULL;
if (!PyArg_ParseTuple(args, "ddU|i", &startDate, &endDate, &searchText, &filterInt)){
return NULL;
}
TPtrC searchTextPtr((TUint16*) PyUnicode_AsUnicode(searchText),
PyUnicode_GetSize(searchText));
TTime startTTime;
TTime endTTime;
pythonRealAsTTime(startDate, startTTime);
pythonRealAsTTime(endDate, endTTime);
startTTime=truncToDate(startTTime);
endTTime=truncToDate(endTTime);
if(Check_time_validity(startTTime)==EFalse || Check_time_validity(endTTime)==EFalse){
PyErr_SetString(PyExc_ValueError, "illegal date value");
return NULL;
}
if(startTTime>endTTime){
PyErr_SetString(PyExc_ValueError, "start date greater than end date");
return NULL;
}
TTime today;
today.HomeTime();
TAgnFilter filter;
setFilterData(filter, filterInt);
// Create a day list.
TRAPD(error, {
dayList = CAgnDayList<TAgnInstanceId>::NewL(startTTime.DateTime());
self->agendaModel->FindNextInstanceL(dayList, searchTextPtr, startTTime, endTTime, filter, today);
});
if(error!=KErrNone){
if(dayList){
dayList->Reset();
delete dayList;
}
return SPyErr_SetFromSymbianOSErr(error);
}
PyObject* idList = PyList_New(dayList->Count());
if(idList==NULL){
dayList->Reset();
delete dayList;
return PyErr_NoMemory();
}
for(TInt i=0;i<dayList->Count();i++){
TAgnInstanceId id = (*dayList)[i];
PyObject* instanceInfo =
Py_BuildValue("{s:i,s:d}", (const char*)(&KUniqueId)->Ptr(),
self->agendaServer->GetUniqueId(id),
(const char*)(&KDateTime)->Ptr(),
time_as_UTC_TReal(AgnDateTime::AgnDateToTTime(id.Date())));
if(instanceInfo==NULL){
Py_DECREF(idList);
dayList->Reset();
delete dayList;
return NULL;
}
if(PyList_SetItem(idList, i, instanceInfo)<0){
Py_DECREF(idList);
dayList->Reset();
delete dayList;
return NULL;
}
}
dayList->Reset();
delete dayList;
return idList;
}
/*
* Returns todos in the specified todo list.
*/
extern "C" PyObject *
CalendarDb_todos_in_list(CalendarDb_object* self, PyObject* args)
{
CHECK_AGENDA_STATE_DB
CAgnTodoInstanceList* todoList = NULL;
TInt32 todoListId = 0;
if (!PyArg_ParseTuple(args, "i", &todoListId)){
return NULL;
}
// Get the entries in the list.
TTime today;
today.HomeTime();
TRAPD(error, {
todoList = CAgnTodoInstanceList::NewL(TAgnTodoListId(todoListId));
self->agendaModel->PopulateTodoInstanceListL(todoList, today);
});
if(error!=KErrNone){
if(todoList){
todoList->Reset();
delete todoList;
}
return SPyErr_SetFromSymbianOSErr(error);
}
PyObject* idList = PyList_New(todoList->Count());
if(idList==NULL){
todoList->Reset();
delete todoList;
return PyErr_NoMemory();
}
for(TInt i=0;i<todoList->Count();i++){
TAgnInstanceId id = (*todoList)[i];
PyObject* instanceId=
Py_BuildValue("i", self->agendaServer->GetUniqueId(id));
if(instanceId==NULL){
Py_DECREF(idList);
todoList->Reset();
delete todoList;
return NULL;
}
if(PyList_SetItem(idList, i, instanceId)<0){
Py_DECREF(idList);
todoList->Reset();
delete todoList;
return NULL;
}
}
todoList->Reset();
delete todoList;
return idList;
}
/*
* Returns information (id and name) of existing todo lists.
* -returned data is like {11:"To-do list", 6543456:"my own todo list"}
*/
extern "C" PyObject *
CalendarDb_todo_lists(CalendarDb_object* self, PyObject* /*args*/)
{
CHECK_AGENDA_STATE_DB
CAgnTodoListNames* todoListNames = NULL;
TRAPD(error, {
todoListNames = CAgnTodoListNames::NewL();
self->agendaModel->PopulateTodoListNamesL(todoListNames);
});
if(error!=KErrNone){
delete todoListNames;
return SPyErr_SetFromSymbianOSErr(error);
}
PyObject* listInfo = PyDict_New();
if(listInfo==NULL){
delete todoListNames;
return PyErr_NoMemory();
}
for(TInt i=0;i<todoListNames->Count();i++){
PyObject* listId = Py_BuildValue("i", todoListNames->TodoListId(i).Id());
if(listId==NULL){
Py_DECREF(listInfo);
delete todoListNames;
return NULL;
}
PyObject* listName =
Py_BuildValue("u#", todoListNames->TodoListName(i).Ptr(),
todoListNames->TodoListName(i).Length());
if(listName==NULL){
Py_DECREF(listInfo);
Py_DECREF(listId);
delete todoListNames;
return NULL;
}
TInt err = PyDict_SetItem(listInfo, listId, listName);
Py_DECREF(listId);
Py_DECREF(listName);
if(err<0){
Py_DECREF(listInfo);
delete todoListNames;
return NULL;
}
}
delete todoListNames;
return listInfo;
}
/*
* Returns id of the default todo list.
*/
extern "C" PyObject *
CalendarDb_default_todo_list(CalendarDb_object* self, PyObject* /*args*/)
{
CHECK_AGENDA_STATE_DB
CAgnTodoListNames* todoListNames = NULL;
TRAPD(error, {
todoListNames = CAgnTodoListNames::NewL();
self->agendaModel->PopulateTodoListNamesL(todoListNames);
});
if(error!=KErrNone){
delete todoListNames;
return SPyErr_SetFromSymbianOSErr(error);
}
if(todoListNames->Count()<1){
delete todoListNames;
PyErr_SetString(PyExc_RuntimeError, "there are no todo lists");
}
PyObject* listId = Py_BuildValue("i", todoListNames->TodoListId(0).Id());
delete todoListNames;
return listId;
}
/*
* Creates new todo list.
* -name can be (optionally) given as a parameter.
* -returns the id of the created todo list.
*/
extern "C" PyObject *
CalendarDb_add_todo_list(CalendarDb_object* self, PyObject* args)
{
CHECK_AGENDA_STATE_DB
PyObject* todoListName = NULL;
CAgnTodoList* todoList = NULL;
TAgnTodoListId listId;
if (!PyArg_ParseTuple(args, "|U", &todoListName)){
return NULL;
}
TRAPD(error, {
todoList = CAgnTodoList::NewL();
CleanupStack::PushL(todoList);
if(todoListName){
TPtrC todoListNamePtr((TUint16*) PyUnicode_AsUnicode(todoListName),
PyUnicode_GetSize(todoListName));
todoList->SetName(todoListNamePtr);
}
listId = self->agendaModel->AddTodoListL(todoList);
CleanupStack::PopAndDestroy(); // todoList
});
if(error!=KErrNone){
return SPyErr_SetFromSymbianOSErr(error);
}
return Py_BuildValue("i", listId.Id());
}
/*
* Removes specified (specified by todo list id) todo list.
*/
extern "C" PyObject *
CalendarDb_remove_todo_list(CalendarDb_object* self, PyObject* args)
{
CHECK_AGENDA_STATE_DB
TInt32 todoListId = 0;
if (!PyArg_ParseTuple(args, "i", &todoListId)){
return NULL;
}
TRAPD(error, {
self->agendaModel->DeleteTodoListL(TAgnTodoListId(todoListId));
});
if(error!=KErrNone){
return SPyErr_SetFromSymbianOSErr(error);
}
Py_INCREF(Py_None);
return Py_None;
}
/*
* Renames specified (specified by todo list id) todo list
* according to given string parameter.
*/
extern "C" PyObject *
CalendarDb_rename_todo_list(CalendarDb_object* self, PyObject* args)
{
CHECK_AGENDA_STATE_DB
TInt32 todoListId = 0;
PyObject* todoListName = NULL;
CAgnTodoList* todoList = NULL;
if (!PyArg_ParseTuple(args, "iU", &todoListId, &todoListName)){
return NULL;
}
TRAPD(error, {
todoList = self->agendaModel->FetchTodoListL(TAgnTodoListId(todoListId));
TPtrC todoListNamePtr((TUint16*) PyUnicode_AsUnicode(todoListName),
PyUnicode_GetSize(todoListName));
todoList->SetName(todoListNamePtr);
self->agendaModel->UpdateTodoListL(todoList);
});
delete todoList;
if(error!=KErrNone){
return SPyErr_SetFromSymbianOSErr(error);
}
Py_INCREF(Py_None);
return Py_None;
}
/*
* Exports vcalendar entries from the database.
* -returned string contains entries indicated by content (unique ids)
* of the tuple given as the parameter.
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -