📄 mmsdemo1appui.cpp
字号:
/*
* ============================================================================
* Name : CMMSDemo1AppUi from MMSDemo1AppUi.cpp
* Part of : MMSDemo1
* Created : 28.10.2002 by Forum Nokia
* Implementation notes:
* Initial content was generated by Series 60 AppWizard.
* Version :
* Copyright: Nokia Corp. 2003
* ============================================================================
*/
// INCLUDE FILES
#include "MMSDemo1AppUi.h"
#include "MMSDemo1MainContainer.h"
#include "MMSDemo1Engine.h"
#include "MMSDemo1Form.h" // for own message editor
#include <MMSDemo1.rsg>
#include "mmsdemo1.hrh"
#include <avkon.hrh> // for LISTBOX settings
#include <msvids.h> // for Message type IDs
#include <f32file.h> // for RFile
#include <utf.h> // for CnvUtfConverter
#include <txtetext.h> // for CPlainText
#include <barsread.h> // for TResourceReader
#include <aknnavide.h> // for CAknNavigationDecorator
#include <f32file.h> // for RFile
#include <apgcli.h> // for RApaLsSession
#include <aknglobalnote.h> // for AknGlobalNote
// CONSTANTS
const TInt KAttachmentTextLimit = 300;
const TUid KMmsDemo1ViewId = { 1 };
// MMSDemo1 message MIME type (wad for Web Address Description,
// combining a URL address and some describing text).
_LIT(KMMSDemo1MimeType, "text/vnd.wad");
// Wap Browser's constants UId
const TInt KWmlBrowserUid = 0x10008D39;
// ================= MEMBER FUNCTIONS =======================
//
// ----------------------------------------------------------
// CMMSDemo1AppUi::ConstructL()
// ?implementation_description
// ----------------------------------------------------------
//
void CMMSDemo1AppUi::ConstructL()
{
BaseConstructL();
iEmbedded = EFalse;
// checking the embedding status
if (iDoorObserver)
{
// Change CBA
CEikButtonGroupContainer::Current()->SetCommandSetL(R_MMSDEMO1_SOFT_EMBEDDED);
iEmbedded = ETrue;
}
// View construction
iContainer = new (ELeave) CMMSDemo1MainContainer;
iContainer->SetMopParent(this);
iContainer->ConstructL( ClientRect() );
AddToStackL( iContainer );
// Navi pane set up
//
CEikStatusPane *sp = ((CAknAppUi*)iEikonEnv->EikAppUi())->StatusPane();
// Fetch pointer to the default navi pane control
iNaviPane = (CAknNavigationControlContainer *)sp->ControlL(TUid::Uid(EEikStatusPaneUidNavi));
TResourceReader reader;
iCoeEnv->CreateResourceReaderLC(reader, R_MMSDEMO1_NAVI_MAIN);
iNaviDecorator = iNaviPane->CreateNavigationLabelL(reader);
CleanupStack::PopAndDestroy(); // resource reader
iNaviPane->PushL(*iNaviDecorator);
sp = NULL;
// Init helper attributes & flags
//
iListIndex = 0; // - When listbox is open, this values gets the selected message index
iFormReply = 0; // - This is used to tell if user pressed "Select" (1) or "Back" (0)
// used in CompleteReadL().
iFunctionId = 0; // - This id is used to guide execution to the right function after
// closing the Message Selection ListBox.
iListOpen = EFalse; // - True when listbox is open
iMessageOpen = EFalse; // - A message has been opened from Inbox of Drafts
// this is used to differentiate from a created, forwarded or a reply message.
// construct MMS messaging engine
iMmsEngine = CMMSDemo1Engine::NewL();
}
// ----------------------------------------------------
// CMMSDemo1AppUi::~CMMSDemo1AppUi()
// Destructor
// Frees reserved resources
// ----------------------------------------------------
//
CMMSDemo1AppUi::~CMMSDemo1AppUi()
{
if(iSelection)
{
delete iSelection;
}
if ( iContainer )
{
RemoveFromStack( iContainer );
delete iContainer;
iContainer = NULL;
}
iNaviPane->Pop();
delete iNaviDecorator;
delete iMmsEngine;
}
// ------------------------------------------------------------------------------
// CMMSDemo1AppUi::::DynInitMenuPaneL(TInt aResourceId,CEikMenuPane* aMenuPane)
// This function is called by the EIKON framework just before it displays
// a menu pane. Its default implementation is empty, and by overriding it,
// the application can set the state of menu items dynamically according
// to the state of application data.
// ------------------------------------------------------------------------------
//
void CMMSDemo1AppUi::DynInitMenuPaneL(
TInt /*aResourceId*/,CEikMenuPane* /*aMenuPane*/)
{
}
// ----------------------------------------------------
// CMMSDemo1AppUi::HandleKeyEventL(
// const TKeyEvent& aKeyEvent,TEventCode /*aType*/)
// ?implementation_description
// ----------------------------------------------------
//
TKeyResponse CMMSDemo1AppUi::HandleKeyEventL(
const TKeyEvent& aKeyEvent,TEventCode /*aType*/)
{
switch ( aKeyEvent.iCode )
{
case EKeyOK:
if(iListOpen) // list open, OK key can be used to select
HandleCommandL(EMMSDemo1CmdListBoxSelect);
else
if(iEmbedded)
HandleCommandL(EMMSDemo1CmdOpenURL);
break;
default:
return EKeyWasNotConsumed;
break;
}
return EKeyWasConsumed;
}
// ----------------------------------------------------
// CMMSDemo1AppUi::HandleCommandL(TInt aCommand)
// ?implementation_description
// ----------------------------------------------------
//
void CMMSDemo1AppUi::HandleCommandL(TInt aCommand)
{
// Init params for WAP browser launching (see: case EMMSDemo1CmdOpenURL)
HBufC* param = HBufC::NewLC( 100 );
TApaTaskList taskList( CEikonEnv::Static()->WsSession() );
TUid id( TUid::Uid( KWmlBrowserUid ) );
TApaTask task = taskList.FindApp( id );
// Handle given command
//
// Here code is probably a bit difficult to follow but the main idea
// is that a open etc. command opens up a selection list from which
// the user can select a message. This selecting launches a new command
// to be handled - the original function/command is saved into a
// member variable iFunctionId, to be able to continue the right operation
// after selection list has been closed.
//
switch ( aCommand )
{
case EAknSoftkeyBack:
case EAknSoftkeyExit:
case EEikCmdExit:
{
if (iDoorObserver)
{
iDoorObserver->NotifyExit(MApaEmbeddedDocObserver::ENoChanges);
}
Exit();
break;
}
// Send current message if it is complete
case EMMSDemo1CmdSend:
SendMessageL();
break;
// Start editing a new message
case EMMSDemo1CmdNewMessage:
WriteMessageL();
break;
// Read all MMS messages from inbox into a list
// (possibly open a message if user selects one)
case EMMSDemo1CmdReadInbox:
iFunctionId = 1;
ReadMessagesL(KMsvGlobalInBoxIndexEntryId);
break;
// Read all MMS messages from Drafts into a list
// (possibly open a message if user selects one)
case EMMSDemo1CmdReadDrafts:
iFunctionId = 1;
ReadMessagesL(KMsvDraftEntryId);
break;
// Read all MMS messages from Inbox into a list
// (one at a time, delete messages that are selected by the user)
case EMMSDemo1CmdDeleteInbox:
iFunctionId = 2;
ReadMessagesL(KMsvGlobalInBoxIndexEntryId);
break;
// Read all MMS messages from Drafts into a list
// (one at a time, delete messages that are selected by the user)
case EMMSDemo1CmdDeleteDrafts:
iFunctionId = 3;
ReadMessagesL(KMsvDraftEntryId);
break;
// Create new forward message
case EMMSDemo1CmdForwardMessage:
iFunctionId = 4;
if(!iMessageOpen) // Forward command selected from the main menu
{ // i.e. message has not been opened first
ReadMessagesL(KMsvGlobalInBoxIndexEntryId);
}
else
{
// A message was already open
// now we have to continue the function forwarding, see
// EMMSDemo1CmdListBoxSelect below.
HandleCommandL(EMMSDemo1CmdListBoxSelect);
}
break;
// Create new reply message
case EMMSDemo1CmdReplyMessage:
iFunctionId = 5;
if(!iMessageOpen) // Reply command selected from the main menu
{ // i.e. message has not been opened first
ReadMessagesL(KMsvGlobalInBoxIndexEntryId);
}
else
{
// if ReadMessagesL() is called, this command is given from there
// i.e. now we have to do it manually
HandleCommandL(EMMSDemo1CmdListBoxSelect);
}
break;
// User pressed "Select" on the listbox
// Here we check the function id that was set before opening the list
case EMMSDemo1CmdListBoxSelect:
if(iListOpen)
{
iListIndex = iContainer->KillTheListboxL();
iFormReply = 1;
iListOpen = EFalse;
}
switch(iFunctionId)
{
case 1:
OpenMessageL();
break;
case 2:
DeleteMessagesL(KMsvGlobalInBoxIndexEntryId);
break;
case 3:
DeleteMessagesL(KMsvDraftEntryId);
break;
case 4:
ForwardL();
break;
case 5:
ReplyL();
break;
default:
break;
}
break;
// User pressed "Cancel" on the listbox
case EMMSDemo1CmdListBoxCancel:
iListIndex = -1; // when cancelling, ignore the reply value
iContainer->KillTheListboxL();
iFormReply = 0;
iListOpen = EFalse;
iFunctionId = 0;
break;
case EMMSDemo1CmdOpenURL:
// Open URL in WAP browser
// Parameters are separated by space
// 1st parameter: type of the further parameters
// 2nd parameter: URL
// Note: Set 4 as the first parameter, specify that second parameter will be an URL
param->Des().Append('4');
param->Des().Append(' ');
param->Des().Append(iUrl);
if ( task.Exists() )
{
HBufC8* param8 = HBufC8::NewLC( param->Length() );
param8->Des().Append( *param );
task.SendMessage( TUid::Uid( 0 ), *param8 ); // Uid is not used
CleanupStack::PopAndDestroy();
}
else
{
RApaLsSession appArcSession;
User::LeaveIfError(appArcSession.Connect()); // connect to AppArc server
TThreadId id;
appArcSession.StartDocument( *param, TUid::Uid( KWmlBrowserUid ), id );
appArcSession.Close();
}
break; // EMMSDemo1CmdOpenURL
default:
break;
}
CleanupStack::PopAndDestroy(param); // param
// setting the navi pane back to normal
if(iFunctionId == 0)
{
iNaviPane->Pop();
delete iNaviDecorator;
TResourceReader reader;
iCoeEnv->CreateResourceReaderLC(reader, R_MMSDEMO1_NAVI_MAIN);
iNaviDecorator = iNaviPane->CreateNavigationLabelL(reader);
CleanupStack::PopAndDestroy(); // resource reader
iNaviPane->PushL(*iNaviDecorator);
}
// Check if any new messages have arrived in Inbox
if( iMmsEngine->NewMessages() > 0 )
{
_LIT(KNewMessages,"You have new messages.");
// Display a Note
CAknGlobalNote* globalNote = CAknGlobalNote::NewLC();
globalNote->ShowNoteL(EAknGlobalInformationNote , KNewMessages);
CleanupStack::PopAndDestroy();
}
}
// ----------------------------------------------------
// CMMSDemo1AppUi::SendMessageL()
// ?implementation_description
// ----------------------------------------------------
//
void CMMSDemo1AppUi::SendMessageL()
{
// --- Create new message ---
if(!iMmsEngine->MessageReady()) // Check if message body has already been created.
{ // After WriteMessageL() this is not he case and
// message has to be created here.
// assume info has been checked in the form,
// Create new message
iMmsEngine->CreateMessageL();
}
if(!iForward) // forward message already has URL and Description parts
{
// parse url & description
TBuf<KAttachmentTextLimit> text;
text.Append( iUrl );
text.Append(_L(";")); // field separator
text.Append( iDesc );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -