?? mmsexample.cpp
字號:
/*
MMSExample.CPP - source file for MMSExample application
*/
#include <mtclreg.h> // for CClientMtmRegistry
#include <msvids.h> // for Message type IDs
#include <mmsclient.h> // for CMmsClientMtm
#include <AknQueryDialog.h> // for CAknTextQueryDialog
#include "MMSExample.h" // own definitions
#include "MMSExample.hrh" // own resource header
#include <MMSExample.rsg>
// Own constants
const TUid KUidMMSExample = { 0x101F402F }; // MMSExample application UID
const TInt KMaxAddressLength = 80; // maximum length for a recipient address
const TUid KMMSExampleViewId = { 1 }; // UID of MMSExample view
//
// CMMSExampleContainer
//
/*
-------------------------------------------------------------------------------
CMMSExampleContainer::ConstructL()
Description: 2nd phase Constructor.
Return value: N/A
-------------------------------------------------------------------------------
*/
void CMMSExampleContainer::ConstructL()
{
CreateWindowL();
}
/*
-----------------------------------------------------------------------------
CMMSExampleContainer::Draw()
Simple Draw method.
-----------------------------------------------------------------------------
*/
void CMMSExampleContainer::Draw(const TRect& /*aRect*/) const
{
CWindowGc& gc = SystemGc();
gc.Clear();
// Draw text "MMS Example for Series 60"
gc.SetPenColor(KRgbBlack);
const CFont* fontUsed = iEikonEnv->TitleFont();
gc.UseFont(fontUsed);
TInt baseline = (Rect().Height() / 2) - fontUsed->AscentInPixels()*2; // set text 2 * text ascent abowe the centerline
TInt margin=0; // margin is zero so that the text will be cenetred
_LIT(K1stLine,"MMS example");
gc.DrawText(K1stLine,Rect(),baseline,CGraphicsContext::ECenter, margin);
baseline = (Rect().Height() / 2) + fontUsed->AscentInPixels()*2; // 2nd line goes below the centerline
_LIT(K2ndLine,"for Series 60");
gc.DrawText(K2ndLine, Rect(), baseline, CGraphicsContext::ECenter, margin);
}
//
// CMMSExampleAppView
//
/*
-----------------------------------------------------------------------------
CMMSExampleAppView::NewL()
2nd phase construction.
Return values: CMMSExampleAppView*
-----------------------------------------------------------------------------
*/
CMMSExampleAppView* CMMSExampleAppView::NewL()
{
CMMSExampleAppView* self=NewLC();
CleanupStack::Pop(); // self
return self;
}
/*
-----------------------------------------------------------------------------
CMMSExampleAppView::NewLC()
2nd phase construction. Created object is put into CleanupStack
before calling ConstructL(). Note that object is left in CS so the caller
must take care of popping it out.
Return values: CMMSExampleAppView*
-----------------------------------------------------------------------------
*/
CMMSExampleAppView* CMMSExampleAppView::NewLC()
{
CMMSExampleAppView* self = new(ELeave) CMMSExampleAppView();
CleanupStack::PushL(self);
self->ConstructL();
return self;
}
/*
-----------------------------------------------------------------------------
CMMSExampleAppView::CMMSExampleAppView()
C++ constructor
-----------------------------------------------------------------------------
*/
CMMSExampleAppView::CMMSExampleAppView()
{
}
/*
-----------------------------------------------------------------------------
CMMSExampleAppView::ConstructL()
2nd phase constructor.
Return value: N/A
-----------------------------------------------------------------------------
*/
void CMMSExampleAppView::ConstructL()
{
}
/*
-------------------------------------------------------------------------------
~CMMSExampleAppView()
Description: Destructor.
Return value: N/A
-------------------------------------------------------------------------------
*/
CMMSExampleAppView::~CMMSExampleAppView()
{
if(iContainer)
AppUi()->RemoveFromStack(iContainer);
}
/*
-------------------------------------------------------------------------------
CMMSExampleAppView::Id()
Description: Returns the id of the view object.
Return value: TUid
-------------------------------------------------------------------------------
*/
TUid CMMSExampleAppView::Id() const
{
return KMMSExampleViewId;
}
/*
-------------------------------------------------------------------------------
CMMSExampleAppView::DoActivateL()
Description: Activate this view.
Return value: N/A
-------------------------------------------------------------------------------
*/
void CMMSExampleAppView::DoActivateL(const TVwsViewId& /*aPrevViewId*/, TUid /*aCustomMessageId*/, const TDesC8& /*aCustomMessage*/ )
{
if (!iContainer) // container hasn't been created yet
{
// Then construct the UI components
iContainer = new(ELeave) CMMSExampleContainer;
iContainer->ConstructL(); // Construct a view control
iContainer->SetRect(ClientRect()); // Sets view control's extent to the space available
}
iContainer->ActivateL(); // Activate the view control
}
/*
-------------------------------------------------------------------------------
CMMSExampleAppView::DoDeactivate()
Description: Deactivate this view.
Return value: N/A
-------------------------------------------------------------------------------
*/
void CMMSExampleAppView::DoDeactivate()
{
if (iContainer)
{
delete iContainer;
iContainer = NULL;
}
}
//
// CMMSExampleAppUi
//
/*
-----------------------------------------------------------------------------
CMMSExampleAppUi::ConstructL()
2nd phase constructor
-----------------------------------------------------------------------------
*/
void CMMSExampleAppUi::ConstructL()
{
BaseConstructL(); // init this AppUi with standard values
iRecipient = HBufC::NewL(KMaxAddressLength); // for recipient address (gsm number or E-Mail addr)
// Create CMsvSession
iSession = CMsvSession::OpenAsyncL(*this); // new session is opened asynchronously
// CompleteConstructL() is called when async finishes
// Series60 view launching
CMMSExampleAppView* view = CMMSExampleAppView::NewLC();
AddViewL(view); // add created view to this AppUi
ActivateLocalViewL( view->Id() ); // activate view
CleanupStack::Pop(); // view
}
/*
-----------------------------------------------------------------------------
CMMSExampleAppUi::~CMMSExampleAppUi()
Destructor.
-----------------------------------------------------------------------------
*/
CMMSExampleAppUi::~CMMSExampleAppUi()
{
delete iRecipient;
delete iMmsMtm;
delete iMtmReg;
delete iSession; // session must be deleted last (and constructed first)
}
/*
-----------------------------------------------------------------------------
CMMSExampleAppUi::CompleteConstructL()
Creates client MTM registry when session is ready for use.
This completes model construction and is called after 'server
ready' event is received after async opening of CMsvSession.
-----------------------------------------------------------------------------
*/
void CMMSExampleAppUi::CompleteConstructL()
{
// We get a MtmClientRegistry from our session
// this registry is used to instantiate new mtms.
iMtmReg = CClientMtmRegistry::NewL(*iSession);
iMmsMtm = (CMmsClientMtm*) iMtmReg->NewMtmL( KUidMsgTypeMultimedia );
// notify the user with a InfoWin (this will be shown in emulator only)
iEikonEnv->InfoMsg(_L("Server session opened."));
}
/*
-----------------------------------------------------------------------------
CMMSExampleAppUi::HandleSessionEventL()
Receives session events from observer and calls event handling functions.
Note that if additional session event handlers are defined
in the session, they are called before this function (as this is the
main session observer).
The type of event is indicated by the value of aEvent. The
interpretation of the TAny arguments depends on this type. For most
event types, the action that is taken, for example updating the
display, is client-specific. All clients though should respond to
EMsvCloseSession and EMsvServerTerminated events.
-----------------------------------------------------------------------------
*/
void CMMSExampleAppUi::HandleSessionEventL(TMsvSessionEvent aEvent, TAny* /*aArg1*/, TAny* /*aArg2*/, TAny* /*aArg3*/)
{
switch (aEvent)
{
// This event tells us that the session has been opened
case EMsvServerReady:
CompleteConstructL(); // Construct the mtm registry & MMS mtm
break;
default:
// All other events are ignored
break;
}
}
/*
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -