📄 calendarmodule.cpp
字号:
break;
}
if(EFalse!=Is_null_time(startTTime)){
Py_INCREF(Py_None);
return Py_None;
}
return ttimeAsPythonFloatUtc(startTTime);
}
/*
* Returns entry's end datetime.
*/
extern "C" PyObject *
Entry_end_datetime(Entry_object* self, PyObject* /*args*/)
{
TTime endTTime;
switch(self->entryItem->Type()){
case CAgnEntry::EAppt:
{
endTTime = self->entryItem->CastToAppt()->EndDateTime();
}
break;
case CAgnEntry::EEvent:
{
endTTime = self->entryItem->CastToEvent()->EndDate();
}
break;
case CAgnEntry::EAnniv:
{
endTTime = self->entryItem->CastToAnniv()->EndDate();
}
break;
case CAgnEntry::ETodo:
{
endTTime = self->entryItem->CastToTodo()->DueDate();
}
break;
}
if(EFalse!=Is_null_time(endTTime)){
Py_INCREF(Py_None);
return Py_None;
}
return ttimeAsPythonFloatUtc(endTTime);
}
/*
* Returns the content (text) of the entry.
*/
extern "C" PyObject *
Entry_content(Entry_object* self, PyObject* /*args*/)
{
PyObject* ret = NULL;
HBufC* buf = NULL;
TRAPD(error, {
if(self->entryItem->RichTextL()!=NULL){
buf = HBufC::NewL(self->entryItem->RichTextL()->DocumentLength());
CleanupStack::PushL(buf);
self->entryItem->RichTextL()->Extract((TDes&)buf->Des(), 0);
CleanupStack::Pop(); // buf.
}
});
if(error!=KErrNone){
return SPyErr_SetFromSymbianOSErr(error);
}
if(NULL==buf){
return Py_BuildValue("u#", "", 0);
}
ret = Py_BuildValue("u#", buf->Ptr(), buf->Length());
delete buf;
return ret;
}
/*
* Sets the content (text) of the entry.
*/
extern "C" PyObject *
Entry_set_content(Entry_object* self, PyObject* args)
{
PyObject* content = NULL;
if (!PyArg_ParseTuple(args, "U", &content)){
return NULL;
}
TPtrC contentPtr((TUint16*) PyUnicode_AsUnicode(content),
PyUnicode_GetSize(content));
TRAPD(error, {
self->entryItem->RichTextL()->Reset();
self->entryItem->RichTextL()->InsertL(0, contentPtr);
});
if(error!=KErrNone){
return SPyErr_SetFromSymbianOSErr(error);
}
Py_INCREF(Py_None);
return Py_None;
}
/*
* Puts the given repeat information into the entry.
*/
extern "C" PyObject *
Entry_install_repeat_data(Entry_object* self,
TReal startDate,
TReal endDate,
TInt interval,
TInt repeatIndicator,
CArrayFixSeg<TReal>* exceptionArray,
PyObject* repeatDays,
TBool eternalRepeat)
{
CAgnRptDef* rpt = NULL;
TTime startTime;
TTime endTime;
switch(repeatIndicator){
case NOT_REPEATED:
{
self->entryItem->ClearRepeat();
}
break;
case DAILY_REPEAT:
{
GET_REP_START_AND_END
CREATE_RPT
TAgnDailyRpt dailyRpt;
rpt->SetDaily(dailyRpt);
SET_REPEAT_DATES
ADD_REPEAT
}
break;
case WEEKLY_REPEAT:
{
GET_REP_START_AND_END
TAgnWeeklyRpt weeklyRpt;
// Add repeat days.
if(repeatDays){
if(!PyList_Check(repeatDays)){
PyErr_SetString(PyExc_SyntaxError,
"weekly repeat days must be given in a list");
return NULL;
}
for(TInt i=0;i<PyList_Size(repeatDays);i++){
PyObject* day = PyList_GetItem(repeatDays, i);
if(!PyInt_Check(day) ||
0>PyInt_AsLong(day) ||
EFalse==isWeekday(PyInt_AsLong(day))){
PyErr_SetString(PyExc_ValueError,
"bad value for weekly repeat day");
return NULL;
}
weeklyRpt.SetDay(static_cast<TDay>(PyInt_AsLong(day)));
}
}
if(weeklyRpt.NumDaysSet()==0){
// default repeat day.
weeklyRpt.SetDay(startTime.DayNoInWeek());
}
CREATE_RPT
rpt->SetWeekly(weeklyRpt);
SET_REPEAT_DATES
ADD_REPEAT
}
break;
case MONTHLY_BY_DATES_REPEAT:
{
GET_REP_START_AND_END
TAgnMonthlyByDatesRpt monthlyRpt;
// Add repeat dates.
if(repeatDays){
if(!PyList_Check(repeatDays)){
PyErr_SetString(PyExc_SyntaxError,
"monthly repeat dates must be given in a list");
return NULL;
}
for(TInt i=0;i<PyList_Size(repeatDays);i++){
PyObject* day = PyList_GetItem(repeatDays, i);
if(!PyInt_Check(day) ||
0>PyInt_AsLong(day) ||
PyInt_AsLong(day)>=DAYS_IN_MONTH){
PyErr_SetString(PyExc_ValueError,
"monthly repeat dates must be integers (0-30)");
return NULL;
}
monthlyRpt.SetDate(PyInt_AsLong(day));
}
}
if(monthlyRpt.NumDatesSet()==0){
// default repeat date.
monthlyRpt.SetDate(startTime.DayNoInMonth());
}
CREATE_RPT
rpt->SetMonthlyByDates(monthlyRpt);
SET_REPEAT_DATES
ADD_REPEAT
}
break;
case MONTHLY_BY_DAYS_REPEAT:
{
GET_REP_START_AND_END
TAgnMonthlyByDaysRpt monthlyRpt;
// Add repeat days.
if(repeatDays){
if(!PyList_Check(repeatDays)){
PyErr_SetString(PyExc_SyntaxError,
"monthly repeat days must be given in a list");
return NULL;
}
PyObject* weekKey = Py_BuildValue("s", (const char*)(&KWeek)->Ptr());
PyObject* dayKey = Py_BuildValue("s", (const char*)(&KDay)->Ptr());
if(!(weekKey && dayKey)){
Py_XDECREF(weekKey);
Py_XDECREF(dayKey);
return NULL;
}
for(TInt i=0;i<PyList_Size(repeatDays);i++){
PyObject* day = PyList_GetItem(repeatDays, i);
if(!PyDict_Check(day)){
Py_DECREF(weekKey);
Py_DECREF(dayKey);
PyErr_SetString(PyExc_TypeError,
"repeat day must be dictionary");
return NULL;
}
PyObject* weekNum = PyDict_GetItem(day, weekKey);
PyObject* dayNum = PyDict_GetItem(day, dayKey);
if(!(weekNum && dayNum &&
PyInt_Check(weekNum) && PyInt_Check(dayNum))){
Py_DECREF(weekKey);
Py_DECREF(dayKey);
PyErr_SetString(PyExc_SyntaxError,
"week and day must be given and they must be integers");
return NULL;
}
TInt weekNumInt = PyInt_AsLong(weekNum);
TInt dayNumInt = PyInt_AsLong(dayNum);
if(isWeekInMonth(weekNumInt)==EFalse ||
isWeekday(dayNumInt)==EFalse){
Py_DECREF(weekKey);
Py_DECREF(dayKey);
PyErr_SetString(PyExc_ValueError, "bad value for week or day");
return NULL;
}
monthlyRpt.SetDay(static_cast<TDay>(dayNumInt),
static_cast<TAgnRpt::TWeekInMonth>(weekNumInt));
}
Py_DECREF(weekKey);
Py_DECREF(dayKey);
}
if(monthlyRpt.NumDaysSet()==0){
// default repeat day.
monthlyRpt.SetDay(startTime.DayNoInWeek(),
static_cast<TAgnRpt::TWeekInMonth>(startTime.DayNoInMonth()/DAYS_IN_WEEK));
}
CREATE_RPT
rpt->SetMonthlyByDays(monthlyRpt);
SET_REPEAT_DATES
ADD_REPEAT
}
break;
case YEARLY_BY_DATE_REPEAT:
{
GET_REP_START_AND_END
CREATE_RPT
TAgnYearlyByDateRpt yearlyRpt;
rpt->SetYearlyByDate(yearlyRpt);
SET_REPEAT_DATES;
ADD_REPEAT
}
break;
case YEARLY_BY_DAY_REPEAT:
{
GET_REP_START_AND_END
TAgnYearlyByDayRpt yearlyRpt;
// Add repeat day.
if(repeatDays){
if(!PyDict_Check(repeatDays)){
PyErr_SetString(PyExc_SyntaxError,
"yearly repeat day must be given in a dictionary");
return NULL;
}
PyObject* weekKey = Py_BuildValue("s", (const char*)(&KWeek)->Ptr());
PyObject* dayKey = Py_BuildValue("s", (const char*)(&KDay)->Ptr());
PyObject* monthKey = Py_BuildValue("s", (const char*)(&KMonth)->Ptr());
if(!(weekKey && dayKey && monthKey)){
Py_XDECREF(weekKey);
Py_XDECREF(dayKey);
Py_XDECREF(monthKey);
return NULL;
}
PyObject* day = PyDict_GetItem(repeatDays, dayKey);
PyObject* week = PyDict_GetItem(repeatDays, weekKey);
PyObject* month = PyDict_GetItem(repeatDays, monthKey);
Py_DECREF(weekKey);
Py_DECREF(dayKey);
Py_DECREF(monthKey);
if(!day || !week || !month){
PyErr_SetString(PyExc_SyntaxError,
"day, week and month must be given");
return NULL;
}
if(!(PyInt_Check(day) && PyInt_Check(week) &&
PyInt_Check(month))){
PyErr_SetString(PyExc_TypeError,
"day, week and month must be integers");
return NULL;
}
TInt dayInt = PyInt_AsLong(day);
TInt weekInt = PyInt_AsLong(week);
TInt monthInt = PyInt_AsLong(month);
if(isWeekday(dayInt)==EFalse ||
isWeekInMonth(weekInt)==EFalse ||
isMonth(monthInt)==EFalse){
PyErr_SetString(PyExc_ValueError, "bad value for day, week or month");
return NULL;
}
yearlyRpt.SetStartDay(static_cast<TDay>(dayInt),
static_cast<TAgnRpt::TWeekInMonth>(weekInt),
static_cast<TMonth>(monthInt),
startTime.DateTime().Year());
// Ensure that the specified day is between start date and end date.
if(yearlyRpt.StartDate()<startTime){
yearlyRpt.SetStartDay(static_cast<TDay>(dayInt),
static_cast<TAgnRpt::TWeekInMonth>(weekInt),
static_cast<TMonth>(monthInt),
startTime.DateTime().Year()+1);
if(yearlyRpt.StartDate()>endTime-TTimeIntervalDays(1)){ // must be endTime-1 day or panic occurs!!!
PyErr_SetString(PyExc_ValueError, "yearly day of repeat must be between (repeat start date) and (repeat end date - 1 day)");
return NULL;
}
}
if(yearlyRpt.StartDate()>endTime-TTimeIntervalDays(1)){
yearlyRpt.SetStartDay(static_cast<TDay>(dayInt),
static_cast<TAgnRpt::TWeekInMonth>(weekInt),
static_cast<TMonth>(monthInt),
endTime.DateTime().Year()-1);
if(yearlyRpt.StartDate()<startTime){
PyErr_SetString(PyExc_ValueError, "yearly day of repeat must be between (repeat start date) and (repeat end date - 1 day)");
return NULL;
}
}
}else{
// default repeat date.
yearlyRpt.SetStartDay(startTime.DayNoInWeek(),
static_cast<TAgnRpt::TWeekInMonth>(startTime.DayNoInMonth()/DAYS_IN_WEEK),
startTime.DateTime().Month(),
startTime.DateTime().Year());
}
CREATE_RPT
rpt->SetYearlyByDay(yearlyRpt);
SET_REPEAT_DATES_NO_START_DAY
ADD_REPEAT
}
break;
default:
PyErr_SetString(PyExc_SyntaxError, "illegal repeat definition");
return NULL;
break;
}
Py_INCREF(Py_None);
return Py_None;
}
/*
* Parses and installs given repeat data into the entry.
*/
extern "C" PyObject *
Entry_set_repeat_data(Entry_object* self, PyObject* args)
{
PyObject* retVal = NULL;
PyObject* repeatDict = NULL;
PyObject* key = NULL;
PyObject* value = NULL;
PyObject* repeatDays = NULL;
TReal startDate = 0;
TReal endDate = 0;
TInt interval = 1;
TInt repeatIndicator = -1;
CArrayFixSeg<TReal>* exceptionArray = NULL;
TBool eternalRepeat = EFalse;
if (!PyArg_ParseTuple(args, "O!", &PyDict_Type, &repeatDict)){
return NULL;
}
// Start date
GET_VALUE_FROM_DICT(KStartDate, repeatDict)
if(value){
if(!PyFloat_Check(value)){
PyErr_SetString(PyExc_TypeError, "start date must be float");
return NULL;
}
startDate = PyFloat_AsDouble(value);
}
// End date
GET_VALUE_FROM_DICT(KEndDate, repeatDict)
if(value){
if(PyFloat_Check(value)){
endDate = PyFloat_AsDouble(value);
}else{
if(value==Py_None){
// None given as end date.
eternalRepeat=ETrue;
}else{
PyErr_SetString(PyExc_TypeError, "end date must be float (or None)");
return NULL;
}
}
}
// Interval
GET_VALUE_FROM_DICT(KInterval, repeatDict)
if(value){
if(!PyInt_Check(value) || PyInt_AsLong(value)<=0){
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -