⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 calendarmodule.cpp

📁 python s60 1.4.5版本的源代码
💻 CPP
📖 第 1 页 / 共 5 页
字号:

  pythonRealAsTTime(startDate, startTTime);
  pythonRealAsTTime(endDate, endTTime);
  
  return CalendarDb_search_instances(self, startTTime, endTTime, filter, searchText);
}
  

/*
 * Returns all instances (instance = entry's unique id + 
 * datetime of the specific occurrence of the entry)
 * of the given month.
 */
extern "C" PyObject *
CalendarDb_monthly_instances(CalendarDb_object* self, PyObject *args)
{
  TReal month = 0;
  TInt filter = 0;
  TTime monthTTime;
  TTime monthStartTTime;
  TTime monthEndTTime;
  TDateTime monthStart;
  TDateTime monthEnd;
  if (!PyArg_ParseTuple(args, "d|i", &month, &filter)){ 
    return NULL;
  }

  pythonRealAsTTime(month, monthTTime);    
  if(Check_time_validity(monthTTime)==EFalse){
    PyErr_SetString(PyExc_ValueError, "illegal date value");
    return NULL;
  }
  
  monthStart = monthTTime.DateTime();
  monthStart.SetDay(0);
  
  monthEnd = monthTTime.DateTime();
  monthEnd.SetDay(monthTTime.DaysInMonth()-1);

  monthStartTTime = monthStart;
  monthEndTTime = monthEnd;
  
  return CalendarDb_search_instances(self,monthStartTTime,monthEndTTime,filter,NULL);  
}


/*
 * Returns all instances (instance = entry's unique id + 
 * datetime of the specific occurrence of the entry)
 * of the given day.
 */
extern "C" PyObject *
CalendarDb_daily_instances(CalendarDb_object* self, PyObject *args)
{
  TReal day = 0;
  TTime startTTime;
  TTime endTTime;
  TInt filter = 0;
  if (!PyArg_ParseTuple(args, "d|i", &day, &filter)){ 
    return NULL;
  }
 
  pythonRealAsTTime(day, startTTime);
  endTTime = startTTime;
  return CalendarDb_search_instances(self,startTTime,endTTime,filter,NULL);  
}



/*
 * Entry methods.
 */

 
 
/*
 * Creates new calendar entry "wrapper" object.
 * -fetches the entry identified by uniqueId from the 
 * database and wraps that into the python object.
 * -if uniqueId is KNullEntryId a new entry is created (but 
 * not added to the database until entry.commit() is called).
 * in this case entry's unique id will remain as KNullEntryId 
 * until the entry is added (by committing) into the database. 
 */
extern "C" PyObject *
new_Entry_object(CalendarDb_object* self, 
                 TCalLocalUid uniqueId, 
                 CCalEntry::TType entryType,
                 const TDesC8* globalUid)
{      
  TInt err = KErrNone;
  CCalEntry* entry = NULL;
  Entry_object* entryObj = NULL;
  
  if(KNullEntryId == uniqueId){    
    // Create new entry.
    TRAP(err, {
      //TODO: HERE IS PROTECTION NEEDED, if globalUid ==NULL, program will panic
      HBufC8* uidBuf = HBufC8::NewLC(globalUid->Length());
      *uidBuf = *globalUid;
      // note that CCalEntry takes the ownership of uidBuf.
      entry = CCalEntry::NewL(entryType, uidBuf, CCalEntry::EMethodNone, 0);
      CleanupStack::Pop(uidBuf);
    });
    if(err != KErrNone){
      return SPyErr_SetFromSymbianOSErr(err);
    } 
    //Initialise time to TCalTime::MinTime() instead to Time::NullTTime().
    //There's a platform bug that Time::NullTTime() can't be used 
    //with TCalTime::StartTimeL() and similar functions.
    TCalTime minTime;
    minTime.SetTimeUtcL(TCalTime::MinTime());     
  	entry->SetStartAndEndTimeL(minTime, minTime);
  }
  else{    
    // Wrap an existing entry.
    TRAP(err, {
      entry = self->entryViewAdapter->iEntryView->FetchL(uniqueId);
    });
    if(err != KErrNone){
      return SPyErr_SetFromSymbianOSErr(err);
    } 
    if(entry==NULL){
      PyErr_SetString(PyExc_RuntimeError, "no such entry");
      return NULL;
    } 
  } 
   
  entryObj = PyObject_New(Entry_object, Entry_type); 
  if(entryObj == NULL){
    delete entry;
    return PyErr_NoMemory();
  }
 
  entryObj->calendarDb = self;
  entryObj->entry = entry; 
   
  Py_INCREF(self); // increase the database's reference count so that it cannot be deleted
                   // until all the entries have been deleted (otherwise a crash will follow).
  return (PyObject*)entryObj;
};
 

/*
 * Check if this is an originating entry (returns 1) or
 * modifying entry (returns 0).
 */ 
extern "C" PyObject *
Entry_originating_entry(Entry_object* self, PyObject* /*args*/)
{
  TInt error = KErrNone;
  TInt originatingEntry = 0;
  TCalTime calTime;
  TRAP(error, {
    calTime = self->entry->RecurrenceIdL();
    if(EFalse==Check_time_validity(calTime.TimeUtcL())){
      // "recurrence id" not set => this is an originating entry.
      originatingEntry = 1;
    }
  });
  if(error!=KErrNone){
    return SPyErr_SetFromSymbianOSErr(error);
  }
  
  return Py_BuildValue("i", originatingEntry);
}

/*
 * Saves the entry into the database.
 * -new entries are added into the database, old entries are updated.
 */ 
extern "C" PyObject *
Entry_commit(Entry_object* self, PyObject* /*args*/)
{  
  TInt error = KErrNone;
  TInt updateSuccess = 0;
  TCalLocalUid uid = 0;
  TBool timeSet = EFalse;
  TInt originatingEntry = 0;
  RPointerArray<CCalEntry>* entryArray = NULL;
  
  TRAP(error, {
    TCalTime startTime = self->entry->StartTimeL();
    if(startTime.TimeUtcL() != TCalTime::MinTime()){
      timeSet = ETrue;
    };
  });     
  if(error!=KErrNone){
    return SPyErr_SetFromSymbianOSErr(error);
  }
  if(timeSet == EFalse){
    PyErr_SetString(PyExc_RuntimeError, "entry's time not set");
    return NULL;
  };
  
  TRAP(error, { 
    uid = self->entry->LocalUidL();
    entryArray = new (ELeave) RPointerArray<CCalEntry>(1);
  });
  if(error!=KErrNone){
    return SPyErr_SetFromSymbianOSErr(error);
  }
  
  TRAP(error, entryArray->AppendL(self->entry));
  if(error != KErrNone){
    entryArray->Close();
    delete entryArray;
    return SPyErr_SetFromSymbianOSErr(error);
  }
    
  TRAP(error, {
    TCalTime calTime = self->entry->RecurrenceIdL();
    if(EFalse==Check_time_validity(calTime.TimeUtcL())){
      // "recurrence id" not set => this is an originating entry.
      originatingEntry = 1;
    }
  });
  if(error != KErrNone){
    entryArray->Close();
    delete entryArray;
    return SPyErr_SetFromSymbianOSErr(error);
  }
  
  if(uid == KNullEntryId || !originatingEntry){
    // Compeletely new entry or modifying (non-originate) entry.
    TRAP(error,self->calendarDb->entryViewAdapter->iEntryView->StoreL(*entryArray,updateSuccess));
  }else{    
    // Entry already exists in the database, but must be updated.
    TRAP(error,self->calendarDb->entryViewAdapter->iEntryView->UpdateL(*entryArray,updateSuccess));
  }
  entryArray->Close();
  delete entryArray;
  if(error != KErrNone){
    return SPyErr_SetFromSymbianOSErr(error);
  }
  if(updateSuccess<1){ 
    PyErr_SetString(PyExc_RuntimeError, "entry could not be stored");
    return NULL;
  };
  
  Py_INCREF(Py_None);
  return Py_None;
}


/*
 * Returns the type of the entry (appt, event, anniv, todo, reminder).
 */
extern "C" PyObject *
Entry_entry_type(Entry_object* self, PyObject* /*args*/)
{
  TInt error = KErrNone;
  TInt entryType = 0;
  TRAP(error, {
    entryType = self->entry->EntryTypeL();
  });
  if(error!=KErrNone){
    return SPyErr_SetFromSymbianOSErr(error);
  }
  return Py_BuildValue("i", entryType);
}


/*
 * Returns entry's content text.
 */
extern "C" PyObject *
Entry_content(Entry_object* self, PyObject* /*args*/)
{ 
  PyObject* ret = NULL;
  HBufC* buf = NULL;
  TRAPD(error, {    
    buf = HBufC::NewL(self->entry->SummaryL().Length());
    CleanupStack::PushL(buf);
    *buf = self->entry->SummaryL();
    CleanupStack::Pop(); // buf.
  });
  if(error!=KErrNone){
    return SPyErr_SetFromSymbianOSErr(error);
  }

  ret = Py_BuildValue("u#", buf->Ptr(), buf->Length()); 
  delete buf;

  return ret;
}


/*
 * Returns entry's description text.
 */
extern "C" PyObject *
Entry_description(Entry_object* self, PyObject* /*args*/)
{ 
  PyObject* ret = NULL;
  HBufC* buf = NULL;
  TRAPD(error, {
    buf = HBufC::NewL(self->entry->DescriptionL().Length());
    CleanupStack::PushL(buf);
    *buf = self->entry->DescriptionL();
    CleanupStack::Pop(); // buf.
  });
  if(error!=KErrNone){
    return SPyErr_SetFromSymbianOSErr(error);
  }

  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)
{
  TInt error = KErrNone;
  PyObject* content = NULL;
  if (!PyArg_ParseTuple(args, "U", &content)){ 
    return NULL;
  }

  TPtrC contentPtr((TUint16*) PyUnicode_AsUnicode(content), 
                   PyUnicode_GetSize(content));
                   
  TRAP(error, {
    self->entry->SetSummaryL(contentPtr);
  });
  if(error!=KErrNone){
    return SPyErr_SetFromSymbianOSErr(error);
  }
  
  Py_INCREF(Py_None);
  return Py_None;
}


/*
 * Sets the Description (text) of the entry.
 */
extern "C" PyObject *
Entry_set_description(Entry_object* self, PyObject* args)
{
  TInt error = KErrNone;
  PyObject* description = NULL;
  if (!PyArg_ParseTuple(args, "U", &description)){ 
    return NULL;
  }

  TPtrC descriptionPtr((TUint16*) PyUnicode_AsUnicode(description), 
                   PyUnicode_GetSize(description));

  TRAP(error, {
    self->entry->SetDescriptionL(descriptionPtr);
  });
  if(error!=KErrNone){
    return SPyErr_SetFromSymbianOSErr(error);
  }

  Py_INCREF(Py_None);
  return Py_None;
}


/*
 * Returns entry's location text. 
 */
extern "C" PyObject *
Entry_location(Entry_object* self, PyObject* /*args*/)
{
  PyObject* ret = NULL;
  HBufC* buf = NULL;
  TRAPD(error, {    
    buf = HBufC::NewL(self->entry->LocationL().Length());
    CleanupStack::PushL(buf);
    *buf = self->entry->LocationL();
    CleanupStack::Pop(); // buf.
  });
  if(error!=KErrNone){
    return SPyErr_SetFromSymbianOSErr(error);
  }
  
  ret = Py_BuildValue("u#", buf->Ptr(), buf->Length()); 
  delete buf;
  
  return ret;
}


/*
 * Sets entry's location information (text). 
 */
extern "C" PyObject *
Entry_set_location(Entry_object* self, PyObject* args)
{
  PyObject* location = NULL;
  if (!PyArg_ParseTuple(args, "U", &location)){ 
    return NULL;
  }
  TPtrC locationPtr((TUint16*) PyUnicode_AsUnicode(location), 
                    PyUnicode_GetSize(location));
  TRAPD(error, {
    self->entry->SetLocationL(locationPtr);
  });
  if(error!=KErrNone){
    return SPyErr_SetFromSymbianOSErr(error);
  }
  Py_INCREF(Py_None);
  return Py_None;
}


/*
 * Returns entry's id. 
 */
extern "C" PyObject *
Entry_unique_id(Entry_object* self, PyObject* /*args*/)
{ 
  TInt error = KErrNone;
  TCalLocalUid id = 0;
  TRAP(error, {
    id = self->entry->LocalUidL(); 
  });
  if(error!=KErrNone){
    return SPyErr_SetFromSymbianOSErr(error);
  }
  
  return Py_BuildValue("i", id); 
}


/*
 * Returns entry's start datetime.
 */
extern "C" PyObject *
Entry_start_datetime(Entry_object* self, PyObject* /*args*/)
{
  TTime startTTime;
  TInt error = KErrNone;
   
  error = GetStartTime(*(self->entry), startTTime);
  if(error != KErrNone){
    return SPyErr_SetFromSymbianOSErr(error);
  }
  if(startTTime==TCalTime::MinTime()){
    Py_INCREF(Py_None);
    return Py_None;
  }
  
  return ttimeAsPythonFloat(startTTime); 
}


/*
 * Returns entry's end datetime.
 */
extern "C" PyObject *
Entry_end_datetime(Entry_object* self, PyObject* /*args*/)
{
  TTime endTTime;
  TInt error = KErrNone;
  
  GetEndTime(*(self->entry), endTTime);
  if(error != KErrNone){
    return SPyErr_SetFromSymbianOSErr(error);
  }
  if(endTTime==TCalTime::MinTime()){
    Py_INCREF(Py_None);
    return Py_None;
  }
  return ttimeAsPythonFloat(endTTime); 
}


/*
 * Sets entry's start and end datetime.
 */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -