📄 helloworldview.cpp
字号:
// HelloWorldView.cpp
//
// ?Symbian Software Ltd 2005. All rights reserved.
//
#include <QikCommand.h>
#include "HelloWorldAppUi.h"
#include "HelloWorldView.h"
#include "HelloWorld.hrh"
#include "HelloWorldExternalInterface.h"
#include <HelloWorld.rsg>
// begin by chen
#include <cntdb.h> // CContactDatabase
#include <cntitem.h> // CContactICCEntry
#include <cntfldst.h> // CContactTextField
// end by chen
/**
Creates and constructs the view.
@param aAppUi Reference to the AppUi
@return Pointer to a CHelloWorldView object
*/
CHelloWorldView* CHelloWorldView::NewLC(CQikAppUi& aAppUi)
{
CHelloWorldView* self = new (ELeave) CHelloWorldView(aAppUi);
CleanupStack::PushL(self);
self->ConstructL();
return self;
}
/**
Constructor for the view.
Passes the application UI reference to the construction of the super class.
KNullViewId should normally be passed as parent view for the applications
default view. The parent view is the logical view that is normally activated
when a go back command is issued. KNullViewId will activate the system
default view.
@param aAppUi Reference to the application UI
*/
CHelloWorldView::CHelloWorldView(CQikAppUi& aAppUi)
: CQikViewBase(aAppUi, KNullViewId)
{
}
/**
Destructor for the view
*/
CHelloWorldView::~CHelloWorldView()
{
}
/**
2nd stage construction of the view.
*/
void CHelloWorldView::ConstructL()
{
// Calls ConstructL that initialises the standard values.
// This should always be called in the concrete view implementations.
BaseConstructL();
}
/**
Inherited from CQikViewBase and called upon by the UI Framework.
It creates the view from resource.
*/
void CHelloWorldView::ViewConstructL()
{
// Loads information about the UI configurations this view supports
// together with definition of each view.
ViewConstructFromResourceL(R_HELLOWORLD_UI_CONFIGURATIONS);
}
/**
Returns the view Id
@return Returns the Uid of the view
*/
TVwsViewId CHelloWorldView::ViewId()const
{
return TVwsViewId(KUidHelloWorldApp, KUidHelloWorldView);
}
/**
Handles all commands in the view.
Called by the UI framework when a command has been issued.
The command Ids are defined in the .hrh file.
@param aCommand The command to be executed
@see CQikViewBase::HandleCommandL
*/
void CHelloWorldView::HandleCommandL(CQikCommand& aCommand)
{
switch(aCommand.Id())
{
// Just issue simple info messages to show that
// the commands have been selected
case EHelloWorldInfoPrint1Cmd:
{
// begin by chen
CContactDatabase* cdb = CContactDatabase::OpenL();
CleanupStack::PushL(cdb);
TContactItemId tid = cdb->ICCTemplateIdL();
CContactItem* temp = cdb->ReadContactLC(tid);
CContactICCEntry* icc = CContactICCEntry::NewL(*temp);
TContactItemId id = icc->Id();
CleanupStack::PopAndDestroy(temp);
CleanupStack::PushL(icc);
CContactItemFieldSet& fields = icc->CardFields();
TInt index = fields.Find(KUidContactFieldFamilyName);
// in a real world application we should create the field if index is KErrNotFound
// but here we simply leave
User::LeaveIfError(index);
CContactItemField& name = fields[index];
_LIT(KMyName, "Ziteng Chen");
name.TextStorage()->SetTextL(KMyName);
index = fields.Find(KUidContactFieldPhoneNumber);
User::LeaveIfError(index);
CContactItemField& number = fields[index];
_LIT(KMyNumber, "1234567890");
number.TextStorage()->SetTextL(KMyNumber);
cdb->AddNewContactL(*icc);
CleanupStack::PopAndDestroy(icc);
TContactItemId gid = cdb->PhonebookGroupIdL();
cdb->AddContactToGroupL(id, gid);
CleanupStack::PopAndDestroy(cdb);
// end by chen
// Shows an infoprint
/* begin by chen
iEikonEnv->InfoMsg(R_HELLOWORLD_INFOPRINT1_TEXT);
end by chen */
break;
}
case EHelloWorldInfoPrint2Cmd:
{
// begin by chen
RFileWriteStream file;
_LIT(KFileName, "c:\\Media files\\helloworld.txt");
TUint mode = EFileWrite+EFileStreamText+EFileShareAny;
User::LeaveIfError(file.Replace(iCoeEnv->FsSession(), KFileName, mode));
CleanupClosePushL(file);
file.WriteUint16L(0xFEFF); // Windows unicode file header.
CContactDatabase* cdb = CContactDatabase::OpenL();
CleanupStack::PushL(cdb);
TContactItemId tid = cdb->ICCTemplateIdL();
_LIT(KCdbICCTemplateIdL, "CContactDatabase::ICCTemplateIdL(), id=0x%x");
_LIT(KCrLf, "\x0D\x0A");
TBuf<256> buf;
buf.Format(KCdbICCTemplateIdL, tid);
file.WriteL(buf);
file.WriteL(KCrLf);
CContactItem* temp = cdb->ReadContactLC(tid);
CContactItemFieldSet& fields = temp->CardFields();
TInt count = fields.Count();
_LIT(KCdbContactItemFieldSet, "CContactItemFieldSet::Count(), count=%d");
buf.Format(KCdbContactItemFieldSet, count);
file.WriteL(buf);
file.WriteL(KCrLf);
for(TInt i=0; i<count; i++)
{
const CContactItemField& field = fields[i];
TPtrC label = field.Label();
const CContentType& ct = field.ContentType();
TInt ctc = ct.FieldTypeCount();
_LIT(KCdbContactItemFieldLabel, " CContactItemField: %S, types=%d");
buf.Format(KCdbContactItemFieldLabel, &label, ctc);
file.WriteL(buf);
file.WriteL(KCrLf);
for(TInt j=0; j<ctc; j++)
{
TFieldType ft = ct.FieldType(j);
_LIT(KCdbCContentType, " CContentType::FieldType(%d), type=0x%x");
buf.Format(KCdbCContentType, j, ft.iUid);
file.WriteL(buf);
file.WriteL(KCrLf);
}
}
CleanupStack::PopAndDestroy(temp);
CleanupStack::PopAndDestroy(cdb);
CleanupStack::PopAndDestroy(); // file
// end by chen
// Shows an infoprint
/* begin by chen
iEikonEnv->InfoMsg(R_HELLOWORLD_INFOPRINT2_TEXT);
end by chen */
break;
}
case EHelloWorldInfoPrint3Cmd:
{
// Shows an infoprint
iEikonEnv->InfoMsg(R_HELLOWORLD_INFOPRINT3_TEXT);
break;
}
// Go back and exit command will be passed to the CQikViewBase to handle.
default:
CQikViewBase::HandleCommandL(aCommand);
break;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -