Symbian Developer Library

SYMBIAN OS V6.1 EDITION FOR C++

[Index] [Glossary] [Previous] [Next]



How to use the model classes


Construct and open the model

A model must be constructed and then opened before it can be used. Opening the model associates it with a file (document) containing agenda data. Agenda data is accessed via the agenda server, provided by RAgnServ.

The following example shows how to construct and open the model and connect to the agenda server.

RAgendaServ* agnServer = RAgendaServ::NewL(); // allocate and construct server
CleanupStack::PushL(agnServer);
agnServer->Connect(); // connect to the agenda server
CleanupClosePushL(*agnServer); // guarantees that the server's Close() method gets called

CAgnEntryModel* model = CAgnEntryModel::NewL(); // allocate and construct model
CleanupStack::PushL(model);
model->SetServer(agnServer); // set server pointer for model
model->OpenL(fileName) // Open file using server
// ...Use agenda model API as normal - invokes corresponding server functions
CleanupStack::PopAndDestroy(3); // model, close session with server, agnServer

Note that a separate instance of the RAgendaServ class is required for each agenda file that is open — only one file can be open at any one time in the same server session.


Model states

The agenda model has a state which at any time has one of three states (defined by CAgnEntryModel), ENoFile, EBlocked, or EOk. When a model is created using NewL(), it has a state of ENoFile, to indicate that although the object has been constructed it cannot yet access any data as it has not been associated with a file (document).

NewL() takes a single argument, a pointer to a function supplied by the application. This function is called when the model's state moves either to or from the EBlocked state. While the model is being opened its state is EBlocked; as soon as the process of opening the model has completed, its state changes to EOk.


Progress monitoring

OpenL() may take different parameters depending on whether you are opening an entry model or an instance (or indexed) model.

For the instance and indexed models, OpenL() may take additional parameters which allow the model to be opened either synchronously or asynchronously. The advantage of opening the model asynchronously is that it allows progress information to be displayed in the user interface while the model is being opened — especially useful when opening large agenda documents.

The aProgressCallBack argument is a pointer to a class supplying a function, MAgnProgressCallBack::Progress(), which is called at intervals while the model is being opened and which is passed a percentage value indicating how far the open action has completed. Implementing this requires an active scheduler. One of the application classes, typically the class implementing the user interface view, should be derived from the mixin class MAgnProgressCallBack, and should implement MAgnProgressCallBack::Progress().

[Top]


Getting entries

To get entries from the model, you have to use a different method depending on whether you are using the instance model or the entry model.

To get entries from the entry model:

[Top]


Adding entries

To add an entry to the model, use CAgnEntryModel::AddEntryL() (entry model) or CAgnModel::AddEntryL() (instance model).

[Top]


Updating existing entries

To update an existing entry, use CAgnEntryModel::UpdateEntryL(). To update an instance, use CAgnModel::UpdateInstanceL().

[Top]


Deleting entries

To delete an entry, use CAgnEntryModel::DeleteEntryL(). To delete an instance use CAgnModel::DeleteInstanceL().