?? mmsexamplecontainer.cpp
字號:
/*
* ============================================================================
* Name : CMMSExampleContainer from MMSExampleContainer.h
* Part of : MMSExample
* Created : 04.11.2006 by Forum Nokia
* Implementation notes:
* Initial content was generated by Nokia Series 60 AppWizard.
* Version : 2.0
* Copyright: Nokia Corporation
* ============================================================================
*/
// INCLUDE FILES
#include "MMSExampleContainer.h"
#include "MMSExample.hrh"
#include "MMSExamplePanics.pan"
#include <eikrted.h> //RichText Editor
#include <txtrich.h> // CRichText
#include <mtclreg.h> // for CClientMtmRegistry
#include <msvids.h> // for Message type IDs
#include <mmsclient.h> // for CMmsClientMtm
#include <AknQueryDialog.h> // for CAknTextQueryDialog
#include <barsread.h> // for TResourceReader
#include <f32file.h>
#include <coeutils.h> // Check the file exist
#ifdef __SERIES60_3X__ //3rd edition onwards
#include <CMsvMimeHeaders.h> //Attachemt mimeheader
#include <MMsvAttachmentManager.h> //Attachment manager
#endif
#ifndef __HARDCODED_PATHS__//3rd and 2nd edition used
#include <PathInfo.h>
#define KDirPictures PathInfo::ImagesPath()
#define KPhoneRootPath PathInfo::PhoneMemoryRootPath()
#else//S60 1st edition used
_LIT(KDirPictures,"c:\\Nokia\\Images\\");
#endif
//Constants
const TInt KMaxAddressLength = 20; // maximum length for a recipient address
_LIT(KFileName, "mmsexample.jpg"); //Attachment file name
//
// CMMSExampleContainer
//
/*
-------------------------------------------------------------------------------
CMMSExampleContainer::ConstructL()
Description: 2nd phase Constructor.
-------------------------------------------------------------------------------
*/
void CMMSExampleContainer::ConstructL(const TRect& aRect)
{
CreateWindowL();
iRecipient = HBufC::NewL(KMaxAddressLength);// for recipient address (gsm number)
// Create CMsvSession
iSession = CMsvSession::OpenAsyncL(*this);// new session is opened asynchronously
// Create RichTextEditor
iRtEd = new (ELeave) CEikRichTextEditor;
// Setting RichTextEditor flags
iRtEd->SetAknEditorCase(EAknEditorLowerCase);
// Fixed case
iRtEd->SetAknEditorFlags
(
EAknEditorFlagFixedCase| //Set up the Allowed Cases
EAknEditorFlagEnableScrollBars // Set up the scroller
);
iRtEd->ConstructL(this,0,0,CEikEdwin::ENoAutoSelection|CEikEdwin::EReadOnly);
iRtEd->SetFocus(ETrue);
iRtEd->UpdateScrollBarsL();
SetRect(aRect);
ActivateL();
SizeChanged();
}
/*
-----------------------------------------------------------------------------
CMMSExampleContainer::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 CMMSExampleContainer::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 );
_LIT(KSessionOpen, "Server session opened.");
EchoL(KSessionOpen);
}
// ---------------------------------------------------------
// CRTEContainer::SizeChanged()
// Called by framework when the view size is changed
// ---------------------------------------------------------
//
void CMMSExampleContainer::SizeChanged()
{
TRect rect = Rect();
#ifdef __SERIES60_3X__//3rd edition
TRect ScrollBarRect = iRtEd->ScrollBarFrame()->VerticalScrollBar()->Rect();
//In 3rd edition CEikRichTextEditor draw the view for the whole rect and
//the scrollbar doesn't show. That is a reason why CEikRichTextEditor Width() is
//rect.Width()-ScrollBarRect.Width()
iRtEd->SetExtent(TPoint(0,0),
TSize(rect.Width()-ScrollBarRect.Width(), rect.Height()));
#else//2nd edition
iRtEd->SetExtent(TPoint(0,0),
TSize(rect.Width(), rect.Height()));
#endif
}
/*
-----------------------------------------------------------------------------
CMMSExampleContainer::~CMMSExampleAppUi()
Destructor.
-----------------------------------------------------------------------------
*/
CMMSExampleContainer::~CMMSExampleContainer()
{
delete iRtEd;
delete iRecipient;
delete iMmsMtm;
delete iMtmReg;
delete iMsvEntry;
delete iSession; // session must be deleted last (and constructed first)
}
/*
-----------------------------------------------------------------------------
CMMSExampleContainer::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.
-----------------------------------------------------------------------------
*/
void CMMSExampleContainer::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;
case EMsvEntriesCreated:
//Listening when new message is arrived in inbox
if (aArg2 && *(static_cast<TMsvId*>(aArg2)) == KMsvGlobalInBoxIndexEntryId)
{
CMsvEntrySelection* entries = static_cast<CMsvEntrySelection*>(aArg1);
if( entries->Count() >= 1 )
{
_LIT(KMessageReceived, "Message received.");
EchoL(KMessageReceived);
_LIT(KSOpenInbox, "Open inbox.");
EchoL(KSOpenInbox);
}
else
{
Panic(EMmsEngineInternal);
}
}
default:
break;
}
}
/*
-----------------------------------------------------------------------------
CMMSExampleContainer::Draw()
Simple Draw method.
-----------------------------------------------------------------------------
*/
void CMMSExampleContainer::Draw(const TRect& aRect) const
{
CWindowGc& gc = SystemGc();
gc.SetPenStyle(CGraphicsContext::ENullPen);
gc.SetBrushColor(KRgbWhite);
gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
gc.DrawRect(aRect);
}
/*
-----------------------------------------------------------------------------
CMMSExampleContainer::InitializeCommunicationsL()
Initialize a new message and ask the user for a recipient address.
Return values: ETrue or EFalse
-----------------------------------------------------------------------------
*/
TBool CMMSExampleContainer::InitializeCommunicationsL()
{
// First the recipients address
// we get it from a data query dialog.
TBuf<20> addr = iRecipient->Des();
CAknTextQueryDialog* telNumDialog = CAknTextQueryDialog::NewL(addr, CAknQueryDialog::ENoTone);
if (!telNumDialog->ExecuteLD(R_MMSEXAMPLE_TEL_NUMBER_DIALOG))
return EFalse;
iRecipient->Des() = addr; // Note that the user can give both numeric and textual data in the query dialog,
// so the address can be a GSM number or an e-mail address.
// set up a new message
return CreateNewMessageL();
}
/*
-----------------------------------------------------------------------------
CMMSExampleContainer::CreateNewMessageL()
Creates a new message server entry and set up default values.
In case the attachment file does not found method return EFalse
otherwise ETrue.
There are differenses how to add attachment file between 2nd and 3rd edition.
-----------------------------------------------------------------------------
*/
TBool CMMSExampleContainer::CreateNewMessageL()
{
_LIT(KCreatingMessage, "Creating message.");
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -