×
Namespaces

Variants
Actions

获得最近的通话

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

文章
hoolee 在 10 Feb 2009 创建
最后由 hamishwillee 在 15 Dec 2011 编辑

CS000849


  • 开发伙伴平台:

S60 3rd Edition, MR

S60 3rd Edition, FP1

S60 3rd Edition, FP2 Beta


  • 详细描述

下列代码示例演示了通过S60活动对象框架获得最近的通话记录。


MMP文件 需要下列链接库

LIBRARY  logcli.lib


头文件

#ifndef __LOGHANDLER_H_
#define __LOGHANDLER_H_
 
#include <e32base.h>
#include <logcli.h> // CLogClient
#include <logview.h> // CLogViewRecent
 
enum TTask
{
EGetRecent,
ESleep
};
 
class CLogHandler : public CActive
{
public:
/**
* Symbian OS default constructor
*/
CLogHandler();
 
/**
* 2nd phase constructor.
*/
static CLogHandler* NewL();
 
/**
* 2nd phase constructor.
*/
static CLogHandler* NewLC();
 
/**
* Destructor
*/
~CLogHandler();
 
/**
* Reads recent events from the main event database
*/
void ReadRecentEventsL();
 
private:
/**
* Symbian 2-phase constructor
*/
void ConstructL();
 
/**
* From CActive
*/
void RunL();
 
/**
* From CActive
*/
TInt RunError(TInt anError);
 
/**
* From CActive
*/
void DoCancel();
 
/**
* Handles a single recent event.
*/
void HandleRecentEventL(const CLogEvent& anEvent);
 
private: // Data
RFs iFs;
 
CLogClient* iLogClient;
CLogViewRecent* iLogViewRecent;
 
TTask iTask; // Task for RunL
};
 
#endif /*__LOGHANDLER_H_*/


源文件

#include <aknnotewrappers.h>
#include <e32base.h>
#include <logcli.h> // CLogClient
#include <logview.h> // CLogViewRecent
#include <logwrap.h> // CLogEvent
 
#include "LogHandler.h"
 
/**
* Constructor. Defines the priority for this active object.
*/
CLogHandler::CLogHandler() : CActive(EPriorityStandard)
{
}
 
/**
* 2nd phase constructor.
*/
CLogHandler* CLogHandler::NewL()
{
CLogHandler* self = CLogHandler::NewLC();
CleanupStack::Pop(self);
return self;
}
 
/**
* 2nd phase constructor.
*/
CLogHandler* CLogHandler::NewLC()
{
CLogHandler* self = new (ELeave) CLogHandler();
CleanupStack::PushL(self);
self->ConstructL();
return self;
}
 
/**
* 2nd phase constructor.
*/
void CLogHandler::ConstructL()
{
User::LeaveIfError(iFs.Connect());
 
// Establish connection to log engine
iLogClient = CLogClient::NewL(iFs);
iLogViewRecent = CLogViewRecent::NewL(*iLogClient);
 
iTask = ESleep; // Default task for RunL
 
CActiveScheduler::Add(this);
}
 
/**
* Destructor.
*/
CLogHandler::~CLogHandler()
{
Cancel();
 
delete iLogViewRecent;
delete iLogClient;
 
iFs.Close();
}
 
/**
* From CActive.
*/
void CLogHandler::RunL()
{
switch (iTask)
{
case EGetRecent:
{
// Retrieve the event and handle it
HandleRecentEventL(iLogViewRecent->Event());
 
// If there are more events in the log engine database...
if (iLogViewRecent->NextL(iStatus))
{
if (iStatus == KErrNone)
{
// ... set active to get the next one
SetActive();
}
}
else
{
// No more events. Go to sleep.
iTask = ESleep;
}
break;
}
 
case ESleep:
default:
{
break;
}
}
}
 
/**
* From CActive.
*/
TInt CLogHandler::RunError(TInt anError)
{
return anError;
}
 
/**
* From CActive.
*/
void CLogHandler::DoCancel()
{
// Cancel the appropriate task
switch (iTask)
{
case EGetRecent:
{
iLogViewRecent->Cancel();
}
 
case ESleep:
default:
{
break;
}
}
}
 
/**
* Reads recent events from the main event database
*/
void CLogHandler::ReadRecentEventsL()
{
if (iLogViewRecent->SetRecentListL(KLogNullRecentList, iStatus))
{
if (iStatus == KErrNone)
{
// If there are events in the log view, set this active object active
// to get the events from the main event database. See RunL().
iTask = EGetRecent;
SetActive();
}
}
else
{
_LIT(KTxt, "No recent calls.");
CAknInformationNote* note = new (ELeave)CAknInformationNote(ETrue);
note->ExecuteLD(KTxt);
}
}
 
/**
* Displays a recent event in an information note.
*/
void CLogHandler::HandleRecentEventL(const CLogEvent& anEvent)
{
TBuf<255> buffer;
_LIT(KTxt, "Description: %S\nNumber: %S");
buffer.Format(KTxt, &(anEvent.Description()), &(anEvent.Number()));
CAknInformationNote* note = new (ELeave)CAknInformationNote(ETrue);
note->ExecuteLD(buffer);
}
This page was last modified on 15 December 2011, at 09:09.
47 page views in the last 30 days.
×