📄 cmmslcontroller.cpp
字号:
/* Copyright (c) 2003, Nokia. All rights reserved */
// INCLUDE FILES
#include <msvids.h> // KMsvGlobalInBoxIndexEntryId
#include <mmsclient.h>
#include <stringloader.h>
#include <mmslist.rsg>
#include "CMmslController.h"
#include "TOverrideOverFlow.h"
#include "CMmslModel.h"
// ================= MEMBER FUNCTIONS =======================
// ---------------------------------------------------------------------------
// CMmslController::NewL()
// Two-phased constructor.
// ---------------------------------------------------------------------------
//
CMmslController* CMmslController::NewL(
MMmslSessionClosed& aSessionClosed )
{
CMmslController* self = new ( ELeave )
CMmslController( aSessionClosed );
CleanupStack::PushL( self );
self->ConstructL();
CleanupStack::Pop();
return self;
}
// ---------------------------------------------------------------------------
// CMmslAppUi::ConstructL()
// Symbian 2nd phase constructor can leave.
// ---------------------------------------------------------------------------
//
void CMmslController::ConstructL()
{
iModel = CMmslModel::NewL();
//Open session to Message Server and add us as an observer
iSession = CMsvSession::OpenSyncL( *this );
iSession->AddObserverL( *this );
iCurEntries = new ( ELeave ) CMsvEntrySelection;
iMtmReg = CClientMtmRegistry::NewL( *iSession );
ReScanAllL();
}
// ---------------------------------------------------------------------------
// CMmslController::CMmslController()
// Constructor.
// ---------------------------------------------------------------------------
//
CMmslController::CMmslController( MMmslSessionClosed& aSessionClosed )
: iSessionClosed( aSessionClosed ), iContainer( NULL )
{
}
// ---------------------------------------------------------------------------
// CMmslController::~CMmslController()
// Destructor.
// Frees reserved resources.
// ---------------------------------------------------------------------------
//
CMmslController::~CMmslController()
{
delete iMtmReg;
delete iCurEntries;
delete iModel;
if( iSession )
{
iSession->RemoveObserver( *this );
delete iSession;
}
}
// ---------------------------------------------------------------------------
// CMmslController::Model()
// ---------------------------------------------------------------------------
//
CMmslModel* CMmslController::Model()
{
return iModel;
}
// ---------------------------------------------------------------------------
// CMmslController::HandleSessionEventL()
// Message Server calls this when any kind of changes occur
// anywhere in the messagin server.
// ---------------------------------------------------------------------------
//
void CMmslController::HandleSessionEventL( TMsvSessionEvent aEvent,
TAny* aArg1,
TAny* aArg2,
TAny* aArg3 )
{
switch( aEvent )
{
case EMsvEntriesDeleted: // Flow through
case EMsvEntriesMoved: // Flow through
case EMsvEntriesCreated:
//These are the changes of interest. Call LogL() to process
//the event.
LogL(aEvent, static_cast< CMsvEntrySelection* > ( aArg1 ),
static_cast< TMsvId* > ( aArg2 ),
static_cast< TMsvId* > ( aArg3 ) );
break;
case EMsvCloseSession: // Flow through
case EMsvServerTerminated: // Flow through
case EMsvGeneralError: // Flow through
case EMsvServerFailedToStart:
iSessionClosed.ServerDown( aEvent );
break;
default:
break;
}
}
// ---------------------------------------------------------------------------
// CMmslController::ScanFolderL()
// Finds messages in the folder and call LogL.
// ---------------------------------------------------------------------------
//
void CMmslController::ScanFolderL( TMsvId aFolderId )
{
TMsvSelectionOrdering order( KMsvNoGrouping, EMsvSortByDate, ETrue );
CMsvEntry* folderEntry = CMsvEntry::NewL( *iSession, aFolderId, order );
CleanupStack::PushL( folderEntry );
CMsvEntrySelection* folderSelection = folderEntry->ChildrenWithTypeL(
KUidMsvMessageEntry );
CleanupStack::PushL( folderSelection );
LogL( EMsvEntriesCreated, folderSelection, &aFolderId, 0 );
CleanupStack::PopAndDestroy( 2 ); // folderSelection, folderEntry
}
// ---------------------------------------------------------------------------
// CMmslController::ReScanAllL()
// Request scan of folders and count changes in folder.
// ---------------------------------------------------------------------------
//
TInt CMmslController::ReScanAllL()
{
TInt prevCount( iCurEntries->Count() );
ScanFolderL( KMsvGlobalInBoxIndexEntryId );
return iCurEntries->Count() - prevCount;
}
// ---------------------------------------------------------------------------
// CMmslController::DeleteItemL()
// Destroy the mms in all structures.
// ---------------------------------------------------------------------------
//
TInt CMmslController::DeleteItemL( const TDesC& aItem )
{
//Read the message Uid from aItem
TUint32 id( 0 );
TLex lexer( aItem );
lexer.SkipSpace();
TChar ch = lexer.Get();
while ( ( ch != '\t' ) && ( ch != 0 ) ) // Finding end of 1.st line
{
ch = lexer.Get();
}
lexer.SkipSpace();
lexer.Val( id, EHex );
if ( iCurEntries->Find( id ) == KErrNotFound )
{
return KErrNotFound;
}
iSession->RemoveEntry( id );
return KErrNone;
}
// ---------------------------------------------------------------------------
// CMmslController::LogL()
// Update internal structures after changes of the MMS.
// ---------------------------------------------------------------------------
//
void CMmslController::LogL( TMsvSessionEvent aEvent,
CMsvEntrySelection* aSelection,
TMsvId* aParent, TMsvId* aOldParent )
{
if( !iSession )
{
return;
}
const TInt count( aSelection->Count() );
TBool messageOK;
for ( TInt i( 0 ); i < count; i++ )
{
TMsvEntry msgEntry; // class that represents the entry (a local cache)
TMsvId ownerServiceId;
TMsvId msgEntryId = ( *aSelection )[ i ];
messageOK = ETrue;
//if EMsvEntriesDeleted GetEntry fails so do not call it
if ( aEvent != EMsvEntriesDeleted )
{
if( iSession->GetEntry( msgEntryId, ownerServiceId, msgEntry )
!= KErrNone )
{
messageOK = EFalse;
}
if( msgEntry.iType != KUidMsvMessageEntry )
{
messageOK = EFalse;
}
}
if ( messageOK )
{
TBuf<64> str;
//An instance of the TDesOverflow derived class used to suppress
//the panic that would be generated if buffer length was exceeded
//in calls to AppendFormat
TOverrideOverFlow noOflo;
if ( ( aEvent == EMsvEntriesMoved
|| aEvent == EMsvEntriesCreated )
&& ( *aParent == KMsvGlobalInBoxIndexEntryId ) )
{
if ( ( iCurEntries->Find( msgEntryId ) == KErrNotFound ) &&
( msgEntry.iMtm == KUidMsgTypeMultimedia ) )
{
// Entry appeared into Inbox -> save mms info
iCurEntries->AppendL( msgEntryId );
CMmsClientMtm* iMmsClient = ( CMmsClientMtm * )
iMtmReg->NewMtmL( KUidMsgTypeMultimedia );
CleanupStack::PushL( iMmsClient );
iMmsClient->SwitchCurrentEntryL( msgEntryId );
iMmsClient->LoadMessageL();
TPtrC sender = iMmsClient->Sender();
if( sender.Length() != 0 )
{
_LIT( KSenderFormat, "\t%S \t" );
str.AppendFormat( KSenderFormat, &noOflo, &sender );
}
else
{
HBufC16* buf = StringLoader::LoadLC(
R_MMSLIST_SENDER_UNKNOWN );
str.AppendFormat( buf->Des(), &noOflo );
CleanupStack::PopAndDestroy( buf );
}
HBufC16* idFormat = StringLoader::LoadLC(
R_MMSLIST_IDFORMAT );
str.AppendFormat( idFormat->Des(), &noOflo, msgEntryId );
CleanupStack::PopAndDestroy( idFormat );
TBuf<32> buf;
HBufC16* dateFormat = StringLoader::LoadLC(
R_MMSLIST_DATEFORMAT );
msgEntry.iDate.FormatL( buf, dateFormat->Des() );
CleanupStack::PopAndDestroy( dateFormat );
str.Append( buf );
HBufC16* at = StringLoader::LoadLC(
R_MMSLIST_AT );
str.Append( at->Des() );
CleanupStack::PopAndDestroy( at );
HBufC16* timeFormat = StringLoader::LoadLC(
R_MMSLIST_TIMEFORMAT );
msgEntry.iDate.FormatL( buf, timeFormat->Des() );
CleanupStack::PopAndDestroy( timeFormat );
_LIT( KStringFormat, "%S");
str.AppendFormat( KStringFormat, &noOflo, &buf );
iModel->AddItemL( str );
iModel->SortArray();
if( iContainer )
{
iContainer->iListBox->HandleItemAdditionL();
}
CleanupStack::PopAndDestroy(1); // iMmsClient
}
}
else
{
if ( ( aEvent == EMsvEntriesDeleted ) ||
( ( aEvent == EMsvEntriesMoved ) &&
( *aOldParent == KMsvGlobalInBoxIndexEntryId ) ) )
{
// Entry removed from Inbox
TInt index( iCurEntries->Find( msgEntryId ) );
if( index != KErrNotFound )
{
iCurEntries->Delete( index );
iModel->Delete( index );
if( iContainer )
{
iContainer->iListBox->HandleItemAdditionL();
}
}
}
}
} // messageOK
} // for
}
// ---------------------------------------------------------------------------
// CMmslController::SetContainer()
// ---------------------------------------------------------------------------
//
void CMmslController::SetContainer( CMmslContainer* aContainer )
{
iContainer = aContainer;
}
// ---------------------------------------------------------------------------
// CMmslController::GetSenderL()
// Find sender number of mms.
// ---------------------------------------------------------------------------
//
void CMmslController::GetSenderL( const TDesC& aItem, TDes& aSender ) const
{
//Read the message originator from aItem
TLex lexer( aItem );
lexer.SkipSpace();
// An instance of the TDesOverflow derived class used to suppress
// the panic that would be generated if buffer length was exceeded
// in calls to AppendFormat
TOverrideOverFlow noOflo;
aSender.AppendFormat( lexer.NextToken(), &noOflo );
}
// ---------------------------------------------------------------------------
// CMmslController::GetMessageL()
// Find text part of mms
// ---------------------------------------------------------------------------
//
void CMmslController::GetMessageL( const TDesC& aItem,
TDes& aMessageText ) const
{
//Read the message Uid from aItem
TUint32 id = 0;
TLex lexer( aItem );
lexer.SkipSpace();
TChar ch( lexer.Get() );
while ( ( ch != '\t' ) && ( ch != 0 ) ) // Finding end of 1.st line
{
ch = lexer.Get();
}
lexer.SkipSpace();
lexer.Val( id, EHex );
if( iCurEntries->Find( id ) == KErrNotFound )
{
return;
}
CMsvEntry* msvEntry = iSession->GetEntryL( id );
CleanupStack::PushL( msvEntry );
const TMsvEntry& msgEntry = msvEntry->Entry();
CBaseMtm* clientMtm = iMtmReg->NewMtmL( msgEntry.iMtm );
CleanupStack::PushL( clientMtm );
clientMtm->SwitchCurrentEntryL( msvEntry->EntryId() );
// An instance of the TDesOverflow derived class used to suppress
// the panic that would be generated if buffer length was exceeded
// in calls to AppendFormat
TOverrideOverFlow noOflo;
// Text is located in iDescription field.
aMessageText.AppendFormat( msgEntry.iDescription, &noOflo );
CleanupStack::PopAndDestroy( 2 ); // clientMtm, msvEntry
};
// End of File
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -