agenda.cpp
来自「在手机操作系统symbina上使用的一个脚本扩展语言的代码实现,可以参考用于自己」· C++ 代码 · 共 2,012 行 · 第 1/4 页
CPP
2,012 行
// Agenda.cpp - Agenda OPX Source
//
// Copyright (c) 1997-2000 Symbian Ltd. All rights reserved.
#include <s32file.h>
#include <coeutils.h>
#include <txtfmlyr.h>
#include <eikenv.h>
#include <agmmodel.h>
#include <agmtodos.h>
#include <oplerr.h>
#include "Agenda.h"
/* ----------------------------------------------------------------------
Constructor
---------------------------------------------------------------------- */
CAgendaOpx::CAgendaOpx(OplAPI& aOplAPI)
:COpxBase(aOplAPI)
{
}
/* ----------------------------------------------------------------------
EPOC standard method
---------------------------------------------------------------------- */
CAgendaOpx* CAgendaOpx::NewL(OplAPI& aOplAPI)
{
CAgendaOpx* self = new (ELeave) CAgendaOpx(aOplAPI);
CleanupStack::PushL(self);
self->ConstructL();
CleanupStack::Pop();
return self;
}
/* ----------------------------------------------------------------------
EPOC standard method - do any construction which may leave
---------------------------------------------------------------------- */
void CAgendaOpx::ConstructL()
{
iParaFormatLayer = CParaFormatLayer::NewL();
iCharFormatLayer = CCharFormatLayer::NewL();
iAgnServ=RAgendaServ::NewL();
}
/* ----------------------------------------------------------------------
Destructor
---------------------------------------------------------------------- */
CAgendaOpx::~CAgendaOpx()
{
delete iParaFormatLayer;
delete iCharFormatLayer;
if (iAgnServ)
{
iAgnServ->Close();
delete iAgnServ;
}
delete iModel;
delete iAgnIter;
Dll::FreeTls();
}
/* ======================================================================
OPX API functions start here
====================================================================== */
/* ----------------------------------------------------------------------
Open an existing agenda file
OPL parameters:
Name of Agenda file
OPL return value:
None
---------------------------------------------------------------------- */
void CAgendaOpx::OpenL(OplAPI& aAPI,CAgendaOpx& aOpx)
{
TPtrC16 aFileName = aAPI.PopString();
// Check if already open & if so silently close old file
if (aOpx.iModel!=NULL)
DoCloseL(aOpx);
// Check file exists
if (!ConeUtils::FileExists(aFileName))
User::Leave(KErrNotFound);
aOpx.iModel = CAgnEntryModel::NewL();
if (!aOpx.iAgnServ)
{
aOpx.iAgnServ=RAgendaServ::NewL();
}
User::LeaveIfError(aOpx.iAgnServ->Connect());
aOpx.iModel->SetServer(aOpx.iAgnServ);
aOpx.iModel->SetMode(CAgnEntryModel::EClient);
aOpx.iModel->OpenL(aFileName);
// Construct object for iterating over agenda entries
aOpx.iAgnIter = new (ELeave) TAgnEntryIter(aOpx.iModel);
aOpx.iAgnIter->SetToFirstL();
aAPI.Push(0.0);
}
/* ----------------------------------------------------------------------
Close the agenda file
OPL parameters:
None
OPL return value:
None
---------------------------------------------------------------------- */
void CAgendaOpx::CloseL(OplAPI& aAPI,CAgendaOpx& aOpx)
{
// ignore if not open
if (aOpx.iModel!=NULL)
DoCloseL(aOpx);
aAPI.Push(0.0);
}
/* ----------------------------------------------------------------------
Write an entry to the file
OPL parameters:
Handle of entry
OPL return value:
Entry id
---------------------------------------------------------------------- */
void CAgendaOpx::AddL(OplAPI& aAPI,CAgendaOpx& aOpx)
{
CAgnEntry* entry = (CAgnEntry*)aAPI.PopInt32();
if (entry==NULL)
User::Leave(KOplErrInvalidArgs);
TAgnEntryId id;
TRAPD(err, id = aOpx.iModel->AddEntryL(entry));
// retry if error
if (err<0)
id = aOpx.iModel->AddEntryL(entry);
aAPI.Push((TInt32)id.Value());
}
/* ----------------------------------------------------------------------
Update an entry in the file
OPL parameters:
Handle of entry
OPL return value:
None
---------------------------------------------------------------------- */
void CAgendaOpx::ModifyL(OplAPI& aAPI,CAgendaOpx& aOpx)
{
CAgnEntry* entry = (CAgnEntry*)aAPI.PopInt32();
if (entry==NULL)
User::Leave(KOplErrInvalidArgs);
aOpx.iModel->UpdateEntryL(entry);
aAPI.Push(0.0);
}
/* ----------------------------------------------------------------------
Delete an entry in the file
OPL parameters:
Handle of entry
OPL return value:
None
---------------------------------------------------------------------- */
void CAgendaOpx::DeleteL(OplAPI& aAPI,CAgendaOpx& aOpx)
{
CAgnEntry* entry = (CAgnEntry*)aAPI.PopInt32();
if (entry==NULL)
User::Leave(KOplErrInvalidArgs);
aOpx.iModel->DeleteEntryL(entry);
aAPI.Push(0.0);
}
/* ----------------------------------------------------------------------
Fetch an entry in the file
OPL parameters:
ID of entry (see Add() and EnGetId())
OPL return value:
ID of entry
---------------------------------------------------------------------- */
void CAgendaOpx::FetchL(OplAPI& aAPI,CAgendaOpx& aOpx)
{
TAgnId id(aAPI.PopInt32());
CAgnEntry* entry = aOpx.iModel->FetchEntryL(id);
aAPI.Push((TInt32)entry);
}
/* ----------------------------------------------------------------------
Return first entry in agenda file - used with NextEntry()
OPL parameters:
None
OPL return value:
Handle of entry or 0 if no more
---------------------------------------------------------------------- */
void CAgendaOpx::FirstEntryL(OplAPI& aAPI,CAgendaOpx& aOpx)
{
if (aOpx.iAgnIter->SetToFirstL())
{
TAgnEntryId id=aOpx.iAgnIter->At();
CAgnEntry* entry = aOpx.iModel->FetchEntryL(id);
aAPI.Push(CastEntryL(entry));
}
else
aAPI.Push((TInt32)0);
}
/* ----------------------------------------------------------------------
Get next entry in Agenda file - see also GetFirstEntry()
OPL parameters:
None
OPL return value:
Handle of entry or 0 if no more
---------------------------------------------------------------------- */
void CAgendaOpx::NextEntryL(OplAPI& aAPI,CAgendaOpx& aOpx)
{
TAgnEntryId id;
CAgnEntry* entry=NULL;
do
{
if (entry)
delete entry;
if (aOpx.iAgnIter->NextL())
{
id=aOpx.iAgnIter->At();
entry = aOpx.iModel->FetchEntryL(id);
}
else
{
aAPI.Push((TInt32)0);
return;
}
}while (entry->ReplicationData().HasBeenDeleted());
aAPI.Push(CastEntryL(entry));
}
/* ----------------------------------------------------------------------
Create a new appointment
OPL parameters:
None
OPL return value:
Handle to appointment
---------------------------------------------------------------------- */
void CAgendaOpx::EnNewApptL(OplAPI& aAPI,CAgendaOpx& aOpx)
{
CAgnAppt* appt = CAgnAppt::NewL(aOpx.iParaFormatLayer,aOpx.iCharFormatLayer);
// default to today
TTime today;
today.HomeTime();
appt->SetStartAndEndDateTime(today);
aAPI.Push((TInt32)appt);
}
/* ----------------------------------------------------------------------
Create a new todo
OPL parameters:
None
OPL return value:
Handle to todo
---------------------------------------------------------------------- */
void CAgendaOpx::EnNewTodoL(OplAPI& aAPI,CAgendaOpx& aOpx)
{
CAgnTodo* todo = CAgnTodo::NewL(aOpx.iParaFormatLayer,aOpx.iCharFormatLayer);
// default to first todo list
CArrayFixFlat<TAgnTodoListId>* TodoListIds = aOpx.iModel->TodoListIdsL();
if (TodoListIds->Count()>0)
{
TAgnId id=(*TodoListIds)[0].Value();
todo->SetTodoListId(TAgnTodoListId(id));
}
delete TodoListIds;
aAPI.Push((TInt32)todo);
}
/* ----------------------------------------------------------------------
Create a new event
OPL parameters:
None
OPL return value:
Handle to event
---------------------------------------------------------------------- */
void CAgendaOpx::EnNewEventL(OplAPI& aAPI,CAgendaOpx& aOpx)
{
CAgnEvent* event = CAgnEvent::NewL(aOpx.iParaFormatLayer,aOpx.iCharFormatLayer);
// default to today
TTime today;
today.HomeTime();
event->SetStartAndEndDate(today);
aAPI.Push((TInt32)event);
}
/* ----------------------------------------------------------------------
Create a new anniversary
OPL parameters:
None
OPL return value:
Handle to anniversary
---------------------------------------------------------------------- */
void CAgendaOpx::EnNewAnnivL(OplAPI& aAPI,CAgendaOpx& aOpx)
{
CAgnAnniv* anniv = CAgnAnniv::NewL(aOpx.iParaFormatLayer,aOpx.iCharFormatLayer);
// default to today
TTime today;
today.HomeTime();
anniv->SetStartAndEndDate(today);
aAPI.Push((TInt32)anniv);
}
/* ----------------------------------------------------------------------
Set the title of an entry
OPL parameters:
Handle of entry
String text
OPL return value:
None
---------------------------------------------------------------------- */
void CAgendaOpx::EnSetTextL(OplAPI& aAPI,CAgendaOpx& /*aOpx*/)
{
TPtrC text = aAPI.PopString();
CAgnEntry* entry = (CAgnEntry*)aAPI.PopInt32();
if (entry==NULL)
User::Leave(KOplErrInvalidArgs);
entry->RichTextL()->Reset();
entry->RichTextL()->InsertL(0, text);
aAPI.Push(0.0);
}
/* ----------------------------------------------------------------------
Set the year symbol of an entry
OPL parameters:
Handle of entry
Symbol
OPL return value:
None
---------------------------------------------------------------------- */
void CAgendaOpx::EnSetSymbolL(OplAPI& aAPI,CAgendaOpx& /*aOpx*/)
{
TPtrC symbol = aAPI.PopString();
CAgnEntry* entry = (CAgnEntry*)aAPI.PopInt32();
if (entry==NULL)
User::Leave(KOplErrInvalidArgs);
if (symbol.Length())
{
entry->SetHasEntrySymbol(ETrue);
entry->SetEntrySymbol(symbol[0]);
}
else
{
entry->SetHasEntrySymbol(EFalse);
}
aAPI.Push(0.0);
}
/* ----------------------------------------------------------------------
Set the alarm of an entry
OPL parameters:
Handle of entry
Days warning
Hour
Minute
Sound name (may be null string)
OPL return value:
None
---------------------------------------------------------------------- */
void CAgendaOpx::EnSetAlarmL(OplAPI& aAPI,CAgendaOpx& /*aOpx*/)
{
TPtrC sndname = aAPI.PopString();
TInt32 minute = aAPI.PopInt32();
TInt32 hour = aAPI.PopInt32();
TInt32 days = aAPI.PopInt32();
CAgnEntry* entry = (CAgnEntry*)aAPI.PopInt32();
if (entry==NULL)
User::Leave(KOplErrInvalidArgs);
if (sndname.Length()==0 && days==-1 && hour==-1 && minute==-1)
{
entry->SetHasAlarm(EFalse);
}
else
{
if (days<0 || days>31 || hour<0 || hour>24 || minute<0 || minute>60)
User::Leave(KOplErrInvalidArgs);
TTimeIntervalDays interDays(days);
TTimeIntervalMinutes alarmTime((hour * 60) + minute);
entry->SetAlarm(interDays, alarmTime);
if (sndname.Length())
entry->SetAlarmSoundNameL(sndname);
entry->SetHasAlarm(ETrue);
}
aAPI.Push(0.0);
}
/* ----------------------------------------------------------------------
Set the crossout state of a entry
NOTE: todo entries have a date associated with the cross-out and
this date will be set to todays date
OPL parameters:
Handle of entry
Flag
1=crossed out
0=not crossed out
OPL return value:
None
---------------------------------------------------------------------- */
void CAgendaOpx::EnSetCrossOutL(OplAPI& aAPI,CAgendaOpx& /*aOpx*/)
{
TInt16 flag = aAPI.PopInt16();
CAgnEntry* entry = (CAgnEntry*)aAPI.PopInt32();
if (entry==NULL)
User::Leave(KOplErrInvalidArgs);
if (flag>0)
{
if (entry->Type()==CAgnEntry::ETodo)
{
TTime today;
today.HomeTime();
((CAgnTodo*)entry)->CrossOut(today.DateTime());
}
else
entry->SetIsCrossedOut(ETrue);
}
else
{
if (entry->Type()==CAgnEntry::ETodo)
((CAgnTodo*)entry)->UnCrossOut();
else
entry->SetIsCrossedOut(EFalse);
}
aAPI.Push(0.0);
}
/* ----------------------------------------------------------------------
Set the tentative flag for an entry
OPL parameters:
Handle of entry
flag, 1=set tentative, 0=clear
OPL return value:
None
---------------------------------------------------------------------- */
void CAgendaOpx::EnSetTentativeL(OplAPI& aAPI,CAgendaOpx& /*aOpx*/)
{
TInt16 flag = aAPI.PopInt16();
CAgnEntry* entry = (CAgnEntry*)aAPI.PopInt32();
if (entry==NULL)
User::Leave(KOplErrInvalidArgs);
if (flag)
entry->SetIsTentative(ETrue);
else
entry->SetIsTentative(EFalse);
aAPI.Push(0.0);
}
#if 0
// FIX ME: this need writing!!!
/* ----------------------------------------------------------------------
Make an entry repeating
OPL parameters:
Handle of entry
Repeat type
Repeat interval
Repeat count (0=forever)
OPL return value:
None
---------------------------------------------------------------------- */
void CAgendaOpx::EnSetRepeatL(OplAPI& aAPI,CAgendaOpx& /*aOpx*/)
{
TInt32 count = aAPI.PopInt32();
TInt32 interval = aAPI.PopInt32();
TInt32 type = aAPI.PopInt32();
CAgnEntry* entry = (CAgnEntry*)aAPI.PopInt32();
if (entry==NULL)
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?