calendarmodule.cpp
来自「python s60 1.4.5版本的源代码」· C++ 代码 · 共 2,399 行 · 第 1/5 页
CPP
2,399 行
return SPyErr_SetFromSymbianOSErr(error);
}
ADD_REPEAT
}
break;
case MONTHLY_BY_DATES_REPEAT:
{
TCalRRule rpt(TCalRRule::EMonthly);
GET_REP_START_AND_END
SET_REPEAT_DATES
if(repeatDays){
if(!PyList_Check(repeatDays)){
PyErr_SetString(PyExc_SyntaxError,
"monthly repeat dates must be given in a list");
return NULL;
}
if(PyList_Size(repeatDays)>0){
TRAP(error,
repeatDateArray = new (ELeave) RArray<TInt>(PyList_Size(repeatDays)));
if(error!=KErrNone){
return SPyErr_SetFromSymbianOSErr(error);
}
}
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)");
repeatDateArray->Close();
delete repeatDateArray;
return NULL;
}
TRAP(error, {
repeatDateArray->AppendL(PyInt_AsLong(day));
});
if(error!=KErrNone){
repeatDateArray->Close();
delete repeatDateArray;
return SPyErr_SetFromSymbianOSErr(error);
}
}
}
if(repeatDateArray!=NULL){
rpt.SetByMonthDay(*repeatDateArray);
repeatDateArray->Close();
}else{
TRAP(error, {
repeatDateArray = new (ELeave) RArray<TInt>(1);
CleanupClosePushL(*repeatDateArray);
repeatDateArray->AppendL(startTime.DayNoInMonth());
rpt.SetByMonthDay(*repeatDateArray);
CleanupStack::PopAndDestroy(repeatDateArray);
});
}
delete repeatDateArray;
if(error!=KErrNone){
return SPyErr_SetFromSymbianOSErr(error);
};
ADD_REPEAT
}
break;
case MONTHLY_BY_DAYS_REPEAT:
{
TCalRRule rpt(TCalRRule::EMonthly);
GET_REP_START_AND_END
SET_REPEAT_DATES
// Add repeat days.
if(repeatDays){
if(!PyList_Check(repeatDays)){
PyErr_SetString(PyExc_SyntaxError,
"monthly repeat days must be given in a list");
return NULL;
}
if(PyList_Size(repeatDays)>0){
TRAP(error,
repeatDayOfMonthArray = new (ELeave) RArray<TCalRRule::TDayOfMonth>(PyList_Size(repeatDays)));
if(error!=KErrNone){
return SPyErr_SetFromSymbianOSErr(error);
}
}
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);
repeatDayOfMonthArray->Close();
delete repeatDayOfMonthArray;
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");
repeatDayOfMonthArray->Close();
delete repeatDayOfMonthArray;
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");
repeatDayOfMonthArray->Close();
delete repeatDayOfMonthArray;
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");
repeatDayOfMonthArray->Close();
delete repeatDayOfMonthArray;
return NULL;
}
weekNumInt++;
if(weekNumInt==5){
weekNumInt=-1; // because of >=3.0 SDK.
}
TCalRRule::TDayOfMonth dayOfMonth(static_cast<TDay>(dayNumInt),weekNumInt);
TRAP(error, {
repeatDayOfMonthArray->AppendL(dayOfMonth);
});
if(error!=KErrNone){
Py_DECREF(weekKey);
Py_DECREF(dayKey);
repeatDayOfMonthArray->Close();
delete repeatDayOfMonthArray;
return SPyErr_SetFromSymbianOSErr(error);
}
}
Py_DECREF(weekKey);
Py_DECREF(dayKey);
}
if(repeatDayOfMonthArray!=NULL){
rpt.SetByDay(*repeatDayOfMonthArray);
repeatDayOfMonthArray->Close();
}else{
TInt week = 0;
TRAP(error, {
repeatDayOfMonthArray = new (ELeave) RArray<TCalRRule::TDayOfMonth>(1);
CleanupClosePushL(*repeatDayOfMonthArray);
week = (startTime.DayNoInMonth()/DAYS_IN_WEEK)+1;
if(week==5){
week = -1;
}
TCalRRule::TDayOfMonth dayOfMonth(startTime.DayNoInWeek(),week);
repeatDayOfMonthArray->AppendL(dayOfMonth);
rpt.SetByDay(*repeatDayOfMonthArray);
CleanupStack::PopAndDestroy(repeatDateArray);
});
}
delete repeatDayOfMonthArray;
if(error!=KErrNone){
return SPyErr_SetFromSymbianOSErr(error);
}
ADD_REPEAT
}
break;
case YEARLY_BY_DATE_REPEAT:
{
TCalRRule rpt(TCalRRule::EYearly);
GET_REP_START_AND_END
SET_REPEAT_DATES
ADD_REPEAT
}
break;
case YEARLY_BY_DAY_REPEAT:
{
TCalRRule rpt(TCalRRule::EYearly);
GET_REP_START_AND_END
SET_REPEAT_DATES
// 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;
}
weekInt++;
if(weekInt==5){
weekInt=-1; // because of >=3.0 SDK.
}
TCalRRule::TDayOfMonth dayOfMonth(static_cast<TDay>(dayInt),weekInt);
RArray<TCalRRule::TDayOfMonth> arr;
RArray<TMonth> monthArr;
TRAP(error, {
arr.AppendL(dayOfMonth);
rpt.SetByDay(arr);
monthArr.AppendL(static_cast<TMonth>(monthInt));
rpt.SetByMonth(monthArr);
});
monthArr.Close();
arr.Close();
if(error!=KErrNone){
return SPyErr_SetFromSymbianOSErr(error);
};
}
ADD_REPEAT
}
break;
default:
PyErr_SetString(PyExc_SyntaxError, "illegal repeat definition");
return NULL;
}
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)
{
TInt error = KErrNone;
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;
RArray<TCalTime>* exceptionArray = NULL;
TBool eternalRepeat = EFalse;
TBool timeSet = EFalse;
if (!PyArg_ParseTuple(args, "O!", &PyDict_Type, &repeatDict)){
return NULL;
}
TRAP(error, {
TCalTime startTime = self->entry->StartTimeL();
if(startTime.TimeUtcL() != Time::NullTTime()){
timeSet = ETrue;
};
});
if(error!=KErrNone){
return SPyErr_SetFromSymbianOSErr(error);
}
if(timeSet == EFalse){
PyErr_SetString(PyExc_RuntimeError, "entry's time not set");
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){
PyErr_SetString(PyExc_TypeError, "interval must be int and >0");
return NULL;
}
interval = PyInt_AsLong(value);
}
// Repeat days
GET_VALUE_FROM_DICT(KRepeatDays, repeatDict)
repeatDays = value;
// Repeat type
GET_VALUE_FROM_DICT(KRepeatType, repeatDict)
if(value){
if(!PyString_Check(value)){
PyErr_SetString(PyExc_TypeError, "repeat type must be string");
return NULL;
}
TPtrC8 valuePtr((TUint8*)PyString_AsString(value), PyString_Size(value));
if(0 == valuePtr.Compare(KDaily)){
repeatIndicator = DAILY_REPEAT;
}else if(0 == valuePtr.Compare(KWeekly)){
repeatIndicator = WEEKLY_REPEAT;
}else if(0 == valuePtr.Compare(KMonthlyByDates)){
repeatIndicator = MONTHLY_BY_DATES_REPEAT;
}else if(0 == valuePtr.Compare(KMonthlyByDays)){
repeatIndicator = MONTHLY_BY_DAYS_REPEAT;
}else if(0 == valuePtr.Compare(KYearlyByDate)){
repeatIndicator = YEARLY_BY_DATE_REPEAT;
}else if(0 == valuePtr.Compare(KYearlyByDay)){
repeatIndicator = YEARLY_BY_DAY_REPEAT;
}else if(0 == valuePtr.Compare(KRepeatNone)){
repeatIndicator = NOT_REPEATED;
}else{
PyErr_SetString(PyExc_ValueError, "illegal repeat type");
return NULL;
}
}
// Exceptions
GET_VALUE_FROM_DICT(KExceptions, repeatDict)
if(value){
if(!PyList_Check(value)){
PyErr_SetString(PyExc_SyntaxError, "exceptions must be given in a list");
return NULL;
}
if(PyList_Size(value)>0){
TRAP(error,
exceptionArray = new (ELeave) RArray<TCalTime>(PyList_Size(value)));
if(error!=KErrNone){
return SPyErr_SetFromSymbianOSErr(error);
}
}
for(TInt i=0;i<PyList_Size(value);i++){
PyObject* listItem = PyList_GetItem(value, i);
if(PyFloat_Check(listItem)){
TCalTime calTime;
TTime ttime;
pythonRealUtcAsTTime(PyFloat_AsDouble(listItem),ttime);
if(Check_time_validity(ttime) == EFalse){
exceptionArray->Close();
delete exceptionArray;
PyErr_SetString(PyExc_ValueError, "illegal value for exception date");
return NULL;
}
TRAP(error, {
calTime.SetTimeUtcL(ttime);
exceptionArray->AppendL(calTime);
});
if(error!=KErrNone){
exceptionArray->Close();
delete exceptionArray;
return SPyErr_SetFromSymbianOSErr(error);
}
}else{
exceptionArray->Close();
delete exceptionArray;
PyErr_SetString(PyExc_TypeError, "exception dates must be floats");
return NULL;
}
}
}
retVal = Entry_install_repeat_data(self, startDate, endDate, interval,
repeatIndicator, exceptionArray,
repeatDays, eternalRepeat);
if(exceptionArray!=NULL){
exceptionArray->Close();
delete exceptionArray;
}
return retVal;
}
/*
* Returns entry's recurrence (="days") information.
*/
extern "C" PyObject *
Entry_recurrence_data(Entry_object* self, PyObject* repeatDataDict, TCalRRule& rpt)
{
TInt error = KErrNone;
PyObject* dayList = NULL;
PyObject* key = NULL;
PyObject* repeatType = NULL;
key = Py_BuildValue("s", (const char*)(&KRepeatType)->Ptr());
if(key==NULL){
return NULL;
}
repeatType = PyDict_GetItem(repeatDataDict, key);
Py_DECREF(key);
TPtrC8 typePtr((TUint8*)PyString_AsString(repeatType), PyString_Size(repeatType));
if(0 == typePtr.Compare(KWeekly)){
RArray<TDay> days;
TRAP(error, {
rpt.GetByDayL(days);
});
if(error!=KErrNone){
return SPyErr_SetFromSymbianOSErr(error);
}
dayList = PyList_New(days.Count());
CHECK_DAYLIST_CREATION
for(TInt i=0;i<days.Count();i++){
PyObject* dayNum = Py_BuildValue("i", days[i]);
SET_ITEM_TO_DAYLIST
}
days.Close();
}else if(0 == typePtr.Compare(KMonthlyByDates)){
RArray<TInt> days;
TRAP(error, {
rpt.GetByMonthDayL(days);
});
if(error!=KErrNone){
days.Close();
return SPyErr_SetFromSymbianOSErr(error);
}
dayList = PyList_New(days.Count());
CHECK_DAYLIST_CREATION
for(TInt i=0;i<days.Count();i++){
PyObject* dayNum = Py_BuildValue("i", days[i]);
SET_ITEM_TO_DAYLIST
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?