×
Namespaces

Variants
Actions

实现日程表监测

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata

文章
huwell 在 30 Jun 2007 创建
最后由 hamishwillee 在 15 Dec 2011 编辑
  • 设备, 软件 版本: S60 2nd Edition


  • 详细描述:

概述

当日程表被其他程序添加、删除或修改后,某第三方程序可能需要知道这些变化。他们可能也想知道具体哪项日程当前被执行了。

下面的解决方案描述了如何通过在S60第二版中写下一个日程表监测DLL来完成上述需求,具体可查看关于Calendar Interim API的文档。


解决方案

1)首先生成一个独立的日程表监测DLL,如通过CAgendaObs::NewL()方法从CAgnObserver派生的一个CAgendaObs对象。 下面的小实例演示了这样的情况:

CAgnObserver* CAgendaObs::CloneL()
 
{
 
if(!iClone) // initial value (TBool) EFalse
 
{
 
// Log: Creating clone
 
CAgendaObs* result = NewL();
 
result->iClone = ETrue;
 
return result;
 
}
 
}
 
void CAgendaObs::StartObserving()
 
{
 
if(iClone)
 
{
 
//Log: Start observing
 
}
 
}
 
void CAgendaObs::StopObserving()
 
{
 
if(iClone)
 
{
 
// Log: Stop observing
 
}
 
}
 
void CAgendaObs::Send(TInt aFunction, CAgnEntry *aEntry)
 
{
 
if(iClone)
 
{
 
switch(aFunction)
 
{
 
case ENotifyAddEntry:
 
// Entry added
 
break;
 
case ENotifyDeleteEntry:
 
// Entry deleted
 
break;
 
case ENotifyUpdateEntry:
 
// Entry updated
 
break;
 
case ENotifyAddTodoList:
 
// ToDo entry added
 
break;
 
case ENotifyDeleteTodoList:
 
// ToDo entry deleted
 
break;
 
case ENotifyUpdateTodoList:
 
// ToDo entry updated
 
break;
 
default:
 
// Unexpected command
 
break;
 
}
 
}
 
}
 
void CAgendaObs::Send(TInt aFunction, CAgnTodoList *aTodoList)
 
{
 
if(iClone)
 
{
 
switch(aFunction)
 
{
 
case ENotifyAddEntry:
 
// Entry added
 
break;
 
case ENotifyDeleteEntry:
 
// Entry deleted
 
break;
 
case ENotifyUpdateEntry:
 
// Entry updated
 
break;
 
case ENotifyAddTodoList:
 
// ToDo entry added
 
break;
 
case ENotifyDeleteTodoList:
 
// ToDo entry deleted
 
break;
 
case ENotifyUpdateTodoList:
 
// ToDo entry updated
 
break;
 
default:
 
// Unexpected command
 
break;
 
}
 
}
 
}
 
void CAgendaObs::ExternalizeL(RWriteStream &aStream) const
 
{
 
//write your code here
 
if(iClone)
 
{
 
// Log: ExternalizeL called
 
}
 
//closing
 
CAgnObserver::WriteEndMarkerL(aStream);
 
}
 
void CAgendaObs::InternalizeL(RReadStream &aStream)
 
{
 
//write your code here
 
if(iClone)
 
{
 
// Log: InternalizeL called
 
}
 
//closing
 
CAgnObserver::ReadEndMarkerL(aStream);
 
}
 
// The NewL of the DLL, to be exported
 
EXPORT_C CAgendaObs* CAgendaObs::NewL()
 
{
 
CAgendaObs* self = new (ELeave) CAgendaObs();
 
CleanupStack::PushL(self);
 
self->ConstructL();
 
CleanupStack::Pop(self);
 
return self;
 
}
 
2) In another application register the observer using the following code:
 
#ifdef __WINS__
 
_LIT(KObserverFile,"agendaobs.dll");
 
#else
 
_LIT(KObserverFile,"c:\\system\\libs\\agendaobs.dll");
 
#endif
 
_LIT(KAgendaFile,"c:\\system\\data\\calendar");
 
// In ConstructL:
 
RAgendaServ *iServer = RAgendaServ::NewL();
 
iServer->Connect();
 
CAgendaObs* iObserver = CAgendaObs::NewL();
 
CAgnEntryModel *iModel = CAgnEntryModel::NewL(this);
 
iModel->SetServer(iServer);
 
iModel->OpenL(KAgendaFile);
 
// Call this method to register the observer DLL
 
void CSomeAppUi::Register()
 
{
 
if(iModel)
 
{
 
iModel->RegisterObserverL(TFileName(KObserverFile), iObserver);
 
}
 
}
 
// Before exiting, unregister the DLL
 
void CAgendaAppAppUi::Unregister()
 
{
 
if(iModel)
 
{
 
iModel->UnregisterObserverL(TFileName(KObserverFile));
 
}
 
}

注意,在MMP文件中,监测DLL要使用0x10000135作为UID2才行。

This page was last modified on 15 December 2011, at 13:13.
28 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×