📄 cmmsssendhandler.cpp
字号:
/* Copyright (c) 2004, Nokia. All rights reserved */
// INCLUDE FILES
#include <MmsClient.h>
#include <mtmdef.h>
#include <f32file.h>
#include <bautils.h>
#include <eikenv.h>
#include <eikapp.h>
#include <stringloader.h>
#include <msvids.h>
#include <mtclreg.h>
#include <mtclbase.h>
#include <txtrich.h>
#include <mmssend.rsg>
#include "mmssend.pan"
#include "mmssendEnum.rh"
#include "CMmssSendHandler.h"
#include "MMsvObserver.h"
// ================= MEMBER FUNCTIONS =======================
//
// ----------------------------------------------------------------------------
// CMmssSendHandler::NewL()
// Standard Symbian construction sequence.
// ----------------------------------------------------------------------------
//
CMmssSendHandler* CMmssSendHandler::NewL( MMsvObserver& aObserver )
{
CMmssSendHandler* self = CMmssSendHandler::NewLC( aObserver );
CleanupStack::Pop();
return self;
}
// ----------------------------------------------------------------------------
// CMmssSendHandler::NewLC()
// Standard construction sequence.
// ----------------------------------------------------------------------------
//
CMmssSendHandler* CMmssSendHandler::NewLC( MMsvObserver& aObserver )
{
CMmssSendHandler* self = new ( ELeave ) CMmssSendHandler( aObserver );
CleanupStack::PushL( self );
self->ConstructL();
return self;
}
// ----------------------------------------------------------------------------
// CMmssSendHandler::CMmssSendHandler()
// Constructor
// ----------------------------------------------------------------------------
//
CMmssSendHandler::CMmssSendHandler( MMsvObserver& aObserver )
: CMsvHandler( aObserver ), iPhase( EIdle )
{
// No implementation required
}
// ----------------------------------------------------------------------------
// CMmssSendHandler::~CMmssSendHandler()
// Destructor
// ----------------------------------------------------------------------------
//
CMmssSendHandler::~CMmssSendHandler()
{
// No implementation required
}
// ----------------------------------------------------------------------------
// TBool CMmssSendHandler::IsIdle()
// Is used to check the active object state
// ----------------------------------------------------------------------------
//
TBool CMmssSendHandler::IsIdle()
{
if ( CMsvHandler::IsIdle() && ( iPhase == EIdle ) )
{
return ETrue;
}
return EFalse;
}
// ----------------------------------------------------------------------------
// CMmssSendHandler::ConstructL()
// CMsvHandler::ConstructL();
// ----------------------------------------------------------------------------
//
void CMmssSendHandler::ConstructL()
{
CMsvHandler::ConstructL();
}
// ----------------------------------------------------------------------------
// CMmssSendHandler::RunL()
// This method is derived from CActive class
// ----------------------------------------------------------------------------
//
void CMmssSendHandler::RunL()
{
// Mtm's should always return KErrNone and clients should
// rely on other means to check on operation progress
User::LeaveIfError( iStatus.Int() );
// Determine the current operations progress
// Note : This class is only appropriate to Locally acting operations
// such as Create, Move, Delete.
// For the CMmsClientMtm::SendL, used to schedule the message for
// sending, no status is available as this is not a local operation,
// so we use the fact that sent messages are moved to the 'Sent'
// folder which we can detect using the HandleSessionEventL
// The class McliUtils is located at msvapi.h
// We could use instead of this McliUtils class for example:
// CMsvOperation::ProgressL and CMsvOperation::FinalProgress methods.
TMsvLocalOperationProgress progress;
TUid mtmUid( iOperation->Mtm() );
if ( mtmUid == KUidMsvLocalServiceMtm )
{
progress = McliUtils::GetLocalProgressL( *iOperation );
User::LeaveIfError( progress.iError );
}
else
{
// The request to schedule the message is the only non-local operation
// we request from this example
if ( iPhase != EWaitingForScheduled )
{
User::Panic( KMms, EMmsStateError );
}
}
delete iOperation;
iOperation = NULL;
switch ( iPhase )
{
case EWaitingForCreate:
{
iObserver.HandleStatusChange( MMsvObserver::ECreated );
SetMtmEntryL( progress.iId );
if ( InitializeMessageL() )
{
//Message box definitions at <msvids.h>
if ( MoveMessageEntryL( KMsvGlobalOutBoxIndexEntryId ) )
{
iPhase = EWaitingForMove;
}
else
{
iPhase = EIdle;
}
}
else
{
iPhase = EIdle;
}
break;
}
case EWaitingForMove:
{
iObserver.HandleStatusChange( MMsvObserver::EMovedToOutBox );
// We must create an entry selection for message copies
// (although now we only have one message in selection)
CMsvEntrySelection* selection = new ( ELeave ) CMsvEntrySelection;
CleanupStack::PushL( selection );
selection->AppendL( progress.iId );
// schedule the sending with the active scheduler
SetScheduledSendingStateL( *selection );
CleanupStack::PopAndDestroy( selection );
iPhase = EWaitingForScheduled;
break;
}
case EWaitingForScheduled:
{
const TMsvEntry& msvEntry = iMtm->Entry().Entry();
TInt state( msvEntry.SendingState() );
if ( state != KMsvSendStateScheduled )
{
iObserver.HandleErrorL( MMsvObserver::EScheduleFailed );
iPhase = EIdle;
}
else
{
iObserver.HandleStatusChange( MMsvObserver::EScheduledForSend );
iPhase = EWaitingForSent;
}
break;
}
case EWaitingForSent: // We handle this in HandleSessionEventL
case EIdle: // Shouldn't get triggered in this state
default:
{
break;
}
}
}
// ----------------------------------------------------------------------------
// CMmssSendHandler::CreateNewMessageL()
// Create new message entry - MMS message
// ----------------------------------------------------------------------------
//
void CMmssSendHandler::CreateNewMessageL()
{
// This represents an entry in the Message Server index
TMsvEntry newEntry;
// message type is MMS
newEntry.iMtm = KUidMsgTypeMultimedia;
// this defines the type of the entry: message
newEntry.iType = KUidMsvMessageEntry;
// ID of local service (containing the standard folders)
newEntry.iServiceId = KMsvLocalServiceIndexEntryId;
// set the date of the entry to home time
newEntry.iDate.HomeTime();
// a flag that this message is in preparation
newEntry.SetInPreparation( ETrue );
//newEntry.SetVisible(EFalse);
// - CMsvEntry accesses and acts upon a particular Message Server entry.
// - NewL() does not create a new entry, but simply a new object to access
// an existing entry.
// - It takes in as parameters the client's message server session,
// ID of the entry to access and initial sorting order of the children
// of the entry.
CMsvEntry* entry = CMsvEntry::NewL( *iSession, KMsvDraftEntryIdValue,
TMsvSelectionOrdering() );
CleanupStack::PushL( entry );
iOperation = entry->CreateL( newEntry, iStatus );
CleanupStack::PopAndDestroy( entry );
//The RunL of this class will trigger when the server completes the request
SetActive();
iPhase = EWaitingForCreate;
}
// ----------------------------------------------------------------------------
// CMmssSendHandler::SendToL()
// Create new message with give parameter (recipient and subject)
// ----------------------------------------------------------------------------
//
void CMmssSendHandler::SendToL( const TDesC& aRecipient,
const TDesC& aSubject,
TFileName aAppFullPath )
{
iRecipientText = aRecipient;
iSubjectText = aSubject;
iAppFullPath = aAppFullPath;
CreateNewMessageL();
}
// ----------------------------------------------------------------------------
// CMmssSendHandler::SetupMmsHeaderL()
// Set up the MMS message header and settings
// ----------------------------------------------------------------------------
//
TBool CMmssSendHandler::SetupMmsHeaderL()
{
if ( iMtm )
{
// To handle the Mms specifics we get handle to BaseMtm
CMmsClientMtm* mmsMtm = static_cast<CMmsClientMtm*>( iMtm );
// Restore service settings
mmsMtm->RestoreDefaultSettingsL();
// Now we could try to change the default service settings.
// CMmsCLientMtm offers a set of methods for getting and
// setting the properties. In order to call of any of these
// methods, the MTM's context must refer to an MMS message,
// otherwise a panic will occur. Forexample:
// Set the message class (default, personal...)
//mmsMtm->SetMessageClass( EMmsClassPersonal );
// Set the message expiry interval to 24 hours
//const TInt KExpiryInterval( 60 * 60 * 24 );
//mmsMtm->SetExpiryInterval( TTimeIntervalSeconds( KExpiryInterval ) );
// Aftr the message properties are handled, save changes
mmsMtm->SaveMessageL();
return ETrue;
}
return EFalse;
}
// ----------------------------------------------------------------------------
// CMmssSendHandler::PopulateMessageL()
// Add attachments to the MMS message
// ----------------------------------------------------------------------------
//
void CMmssSendHandler::PopulateMessageL( TMsvEntry& aMsvEntry )
{
// Because the memory is limited to 8KB, we have to reuse
// some variables
TFileName appFileName;
TFileName appDriveAndPath;
// Add 1.KMmsUtf8 coded text attachment to the message
TBuf<50> appText1;
TBuf<12> appName1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -