📄 msg1.cpp
字号:
// represents the internal operation that is going on. We are creating a new entry asyncronously
// within the msg store index
iOperation=iMsvEntry->CreateL(newEntry,iStatus);
);
iState=ESmsSendCreateMessage;
SetActive();
if (err!=KErrNone)
{ // simulate request completion on error - so only 1 place to handle all errors
TRequestStatus* q=(&iStatus);
User::RequestComplete(q,err);
}
return(ETrue);
}
void CMessageEngine::MsgCreationCompleteL(const TMsvId aId)
//
// The new SMS has been created, now attempt to do everything to cause it to be xmit-able
//
{
if (iMtm==NULL || iMsvEntry->Entry().iMtm!=iMtm->Entry().Entry().iMtm)
{ // we dont have an mtm or mtm for this entry is different to one we currently have
delete(iMtm);
iMtm=NULL;
iMtm=iMtmRegistry->NewMtmL(iMsvEntry->Entry().iMtm);
}
iMtm->SetCurrentEntryL(iMsvEntry); // set indicated entry as current one
TMsvEntry tEntry=iMtm->Entry().Entry();
// Set message body from our msg text
CRichText& mtmBody=iMtm->Body();
mtmBody.Reset();
mtmBody.InsertL(0,iMessageBody);
// set the destination address
tEntry.iDetails.Set(iDestinationAddress);
tEntry.SetInPreparation(EFalse); // were no longer preparing msg
tEntry.SetSendingState(KMsvSendStateWaiting);// cos were now waiting to send
tEntry.iDate.UniversalTime();
// To handle the sms specifics we start using SmsMtm specifics
CSmsClientMtm* smsMtm=static_cast<CSmsClientMtm*>(iMtm);
smsMtm->RestoreServiceAndSettingsL();
// CSmsHeader encapsulates data specific for sms messages,
// like service center number and options for sending.
CSmsSettings* sendOptions=CSmsSettings::NewL();
CleanupStack::PushL(sendOptions);
sendOptions->SetStatusReportHandling(CSmsSettings::EMoveReportToInboxVisible);
sendOptions->CopyL(smsMtm->ServiceSettings()); // restore existing settings
sendOptions->SetDelivery(ESmsDeliveryImmediately); // set to be delivered immediately
CSmsHeader& header=smsMtm->SmsHeader();
header.SetSmsSettingsL(*sendOptions);
CleanupStack::PopAndDestroy(); // sendOptions
// If no SMC address, attempt to use a default SMC address - if none give up
if (header.Message().ServiceCenterAddress().Length()==0)
{
CSmsSettings& serviceSettings=smsMtm->ServiceSettings();
if (!serviceSettings.ServiceCenterCount())
User::Leave(KErrCouldNotConnect); // no SMC - give up here
header.Message().SetServiceCenterAddressL(serviceSettings.GetServiceCenter(
serviceSettings.DefaultServiceCenter()).Address());
if (!header.Message().ServiceCenterAddress().Length())
User::Leave(KErrCouldNotConnect); // no SMC - give up here
}
// Add our recipient to the list, takes in two TDesCs, first is real address and second
// is an alias - works also without the alias parameter.
smsMtm->AddAddresseeL(iDestinationAddress,tEntry.iDetails);
// save message to server
smsMtm->SaveMessageL();
// move the message from the drafts folder to the outbox folder
iMsvEntry->SetEntryL(tEntry.Parent());
iOperation=iMsvEntry->MoveL(tEntry.Id(),KMsvGlobalOutBoxIndexEntryId,iStatus);
iState=ESmsSendMoveMessageToOutBox;
SetActive();
}
void CMessageEngine::DoCancel()
// cancel the outstanding request
{
if (iOperation)
iOperation->Cancel();
}
void CMessageEngine::RunL()
{
TBuf<128>bb;
TMsvLocalOperationProgress progress;
TInt err=iStatus.Int();
switch (iState)
{
case ESmsSendCreateMessage: // we were creating the SMS msg
if (err==KErrNone)
{
progress=McliUtils::GetLocalProgressL(*iOperation);
if (progress.iError!=KErrNone)
{ // some messaging error being reported
err=progress.iError;
}
else
{
TRAP(err,
// in general its bad to assume that iMsvEntry has not changed
// especially in an async system so we set it here
iMsvEntry->SetEntryL(progress.iId);
DeleteOperation();
MsgCreationCompleteL(progress.iId);
);
}
}
if (err!=KErrNone)
{
DeleteOperation();
_LIT(KCreateErr,"Create err %d");
bb.Format(KCreateErr,err);
iObserver->LogInfo(bb);
iState=ESmsSendIdle;
}
break;
case ESmsSendMoveMessageToOutBox:
if (err==KErrNone)
{
progress=McliUtils::GetLocalProgressL(*iOperation);
if (progress.iError!=KErrNone)
{ // some messaging error being reported
err=progress.iError;
}
else
{ // moving to outbox has completed sucessfully, start sending the msg
TRAP(err,
iSendSelection->AppendL(progress.iId); // add our message to the selection
DeleteOperation();
TBuf8<4> junk;
iOperation=iMtm->InvokeAsyncFunctionL(ESmsMtmCommandScheduleCopy,*iSendSelection,junk,iStatus);
iState=ESmsSendTransmittingMessage;
SetActive();
);
}
}
if (err!=KErrNone)
{
DeleteOperation();
_LIT(KMoveErr,"Move err %d");
bb.Format(KMoveErr,err);
iObserver->LogInfo(bb);
iState=ESmsSendIdle;
}
break;
case ESmsSendTransmittingMessage: // finished ESmsMtmCommandScheduleCopy
DeleteOperation();
_LIT(KScheduledOK,"Scheduled OK");
_LIT(KScheduledErr,"Schedule err %d");
if (err==KErrNone)
bb=KScheduledOK;
else
bb.Format(KScheduledErr,err);
iObserver->LogInfo(bb);
iState=ESmsSendIdle;
break;
default:
break;
}
}
//////////////////////////////////////////////////////////////////////////////////
class CAppSpecificListView : public CQikViewBase, public MMsgEngineObserver
{
protected:
// from CQikViewBase
TVwsViewId ViewId() const;
void HandleCommandL(CQikCommand& aCommand);
void ViewConstructL();
void ViewDeactivated();
void ViewActivatedL(const TVwsViewId& aPrevViewId,const TUid aCustomMessageId,const TDesC8& aCustomMessage);
// from MMsgEngineObserver
void LogInfo(const TDesC& aBuf);
// new methods
void RebuildListbox();
public:
// new methods
~CAppSpecificListView();
CAppSpecificListView(CAppSpecificUi& aAppUi);
protected:
CMessageEngine* iEngine;
CLogText* iLogText;
};
CAppSpecificListView::~CAppSpecificListView()
{
delete(iEngine);
delete(iLogText);
}
CAppSpecificListView::CAppSpecificListView(CAppSpecificUi& aAppUi) :
CQikViewBase(aAppUi,KNullViewId)
{}
TVwsViewId CAppSpecificListView::ViewId() const
//
// All views are uniquely identified within the entire system. A TVwsViewId consists of
// the application uid (uid3) and app specific view uid
//
{
return(KViewIdListView);
}
void CAppSpecificListView::HandleCommandL(CQikCommand& aCommand)
//
// Handle the commands coming in from the controls that can deliver cmds..
//
{
switch (aCommand.Id())
{
case EAppCmdSendText:
_LIT(KMessageStoreExampleSMS,"Message store example SMS");
_LIT(KPhoneNumber,"+449999123456"); // a dummy number in public code !!
iEngine->StartSendText(KMessageStoreExampleSMS,KPhoneNumber);
break;
default: // e.g. the back button...
CQikViewBase::HandleCommandL(aCommand);
break;
}
}
void CAppSpecificListView::RebuildListbox()
//
// Rebuild the listbox from scratch
//
{
TRAPD(err,
CQikListBox* listbox=LocateControlByUniqueHandle<CQikListBox>(EAppSpecificListViewListId);
listbox->RemoveAllItemsL();
MQikListBoxModel& model(listbox->Model());
model.ModelBeginUpdateLC();
TInt count=iLogText->Count();
for (TInt i=0;i<count;i++)
{
MQikListBoxData* lbData=model.NewDataL(MQikListBoxModel::EDataNormal);
CleanupClosePushL(*lbData);
lbData->AddTextL(iLogText->At(i),EQikListBoxSlotText1);
CleanupStack::PopAndDestroy(lbData);
}
model.ModelEndUpdateL();
);
}
void CAppSpecificListView::LogInfo(const TDesC& aBuf)
// Called back by the engine to add some log text to output log so operations are visible
{
// This is an example app. Logging content to the list box in this fashion cannot be
// recommended for commerical quality applications
iLogText->LogText(aBuf);
RebuildListbox();
}
void CAppSpecificListView::ViewConstructL()
{
// Loads information about the UI configurations this view supports
// together with definition of each view.
ViewConstructFromResourceL(R_APP_VIEW_CONFIGURATIONS);
iLogText=new(ELeave)CLogText;
iLogText->ConstructL();
iEngine=new(ELeave)CMessageEngine(this);
iEngine->ConstructL();
TBuf<64>bb;
iEikonEnv->ReadResourceL(bb,R_STR_APP_TITLE);
ViewContext()->AddTextL(1,bb);
}
void CAppSpecificListView::ViewDeactivated()
//
// Here we choose to remove all items from the list box. This saves memory.
//
{
}
void CAppSpecificListView::ViewActivatedL(
//
// The view is being activated. Generate the listbox content. Move highlight to current entry.
//
const TVwsViewId& aPrevViewId,
const TUid aCustomMessageId,
const TDesC8& aCustomMessage)
{
RebuildListbox();
}
//////////////////////////////////////////////////////////////////////////////
CAppSpecificUi::~CAppSpecificUi()
{
}
void CAppSpecificUi::ConstructL()
//
// Normal primary entry point to a Symbian App
//
{
CQikAppUi::ConstructL();
// We create and add a list view.
CAppSpecificListView* list=new(ELeave)CAppSpecificListView(*this);
CleanupStack::PushL(list);
list->ConstructL();
AddViewL(*list); // takes ownership
CleanupStack::Pop(list);
SetDefaultViewL(*list);
}
/////////////////////////////////////////////////////////////////////////////////////////////
// Standard Symbian application framework code when creating an application
class CAppSpecificDocument : public CQikDocument
{
protected:
CQikAppUi* CreateAppUiL();
public:
CAppSpecificDocument(CQikApplication& aApp);
static CAppSpecificDocument* NewL(CQikApplication& aApp);
protected:
};
CAppSpecificDocument::CAppSpecificDocument(CQikApplication& aApp) :
CQikDocument(aApp)
{
__DECLARE_NAME(_S("CAppSpecificDocument"));
}
CAppSpecificDocument* CAppSpecificDocument::NewL(CQikApplication& aApp)
{
return(new(ELeave)CAppSpecificDocument(aApp));
}
CQikAppUi* CAppSpecificDocument::CreateAppUiL()
{
return(new(ELeave)CAppSpecificUi);
}
//////////////////////////////////////////////////////////////////////////////////
// Standard Symbian application framework code when creating an application
class CAppSpecificApplication : public CQikApplication
{
protected:
TUid AppDllUid() const;
CApaDocument* CreateDocumentL();
};
TUid CAppSpecificApplication::AppDllUid() const
{
return(KAppSpecificUid);
}
CApaDocument* CAppSpecificApplication::CreateDocumentL()
{
return(CAppSpecificDocument::NewL(*this));
}
//////////////////////////////////////////////////////////////////////////////////
// Standard Symbian application start up code
LOCAL_C CApaApplication* NewApplication()
{
return(new CAppSpecificApplication);
}
GLDEF_C TInt E32Main()
{
return(EikStart::RunApplication(NewApplication));
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -