📄 mguardmsghandler.cpp,v
字号:
head 1.1;branch 1.1.1;access ;symbols v1:1.1.1.1 vendor:1.1.1;locks ; strict;comment @// @;1.1date 2007.07.09.13.13.51; author administrator; state Exp;branches 1.1.1.1;next ;deltatype text;permissions 644;1.1.1.1date 2007.07.09.13.13.51; author administrator; state Exp;branches ;next ;permissions 644;desc@@1.1log@Initial revision@text@/** ============================================================================* Name : from MGuardsmshandler.cpp* Part of : MGuardMain* Created : July 9 2007 by xueyw* Implementation notes:* Initial content was generated by Series 60 Application Wizard.* Version :* Copyright: * ============================================================================*/// INCLUDE FILES#include <e32std.h>#include <msvids.h>#include <msvstd.h>#include <smsclnt.h>#include <smut.h>#include <mtclreg.h>#include <smscmds.h>#include <mtmuibas.h>#include <mtmdef.h>#include <apgcli.h>#include <txtrich.h>#include <txtstyle.h>#include <eikdll.h>#include <apacmdln.h>#include "smutset.h"#include "smuthdr.h"#include "MGuardMsgHandler.h"// ============================ MEMBER FUNCTIONS ===============================// -----------------------------------------------------------------------------// CSmsHandler::CSmsHandler()// C++ default constructor can NOT contain any code, that might leave.// -----------------------------------------------------------------------------//CSmsHandler::CSmsHandler() //: CActive( EPriorityStandard ) { }// -----------------------------------------------------------------------------// CSmsHandler::ConstructL()// Symbian 2nd phase constructor can leave.// -----------------------------------------------------------------------------//void CSmsHandler::ConstructL() { // The time last message received iLastMsgTime = 0; _LIT(KFilename,"c:\\msglog2.txt"); // Write to file for later usage if ( KErrNone != aFileSession.Connect() ) return; if ( KErrNone != logFile.Replace( aFileSession, KFilename, EFileWrite | EFileStream ) ) { logFile.Close(); aFileSession.Close(); } logFile.Write( _L8("Before OpenAsyncL") ); // Session to message server is opened asynchronously. iSession = CMsvSession::OpenAsyncL( *this ); // Entry selection for all received messages. iSelection = new ( ELeave ) CMsvEntrySelection(); iMtmRegistry = 0; // For testing purpose only //TInt aError; //TRequestStatus aStatus; // TInt aSeek = 0; }// -----------------------------------------------------------------------------// CSmsHandler::NewL()// Two-phased constructor.// -----------------------------------------------------------------------------//CSmsHandler* CSmsHandler::NewL() { CSmsHandler* self = NewLC(); CleanupStack::Pop( self ); return self; }// -----------------------------------------------------------------------------// CSmsHandler::NewLC()// Two-phased constructor.// -----------------------------------------------------------------------------//CSmsHandler* CSmsHandler::NewLC() { CSmsHandler* self = new ( ELeave ) CSmsHandler(); CleanupStack::PushL( self ); self->ConstructL(); return self; }// ----------------------------------------------------------// CSmsHandler::~CSmsHandler()// Destructor.// ----------------------------------------------------------//CSmsHandler::~CSmsHandler() {// Cancel(); logFile.Close (); aFileSession.Close (); delete iOperation; delete iMtmUiRegistry; delete iSelection; delete iSmsMtm; delete iMtmRegistry; delete iSession; // session must be deleted last }// -----------------------------------------------------------------------------// CSmsHandler::HandleSessionEventL()// Handles notifications of events from the Message Server.// -----------------------------------------------------------------------------//void CSmsHandler::HandleSessionEventL( TMsvSessionEvent aEvent, TAny* aArg1, TAny* aArg2, TAny* /*aArg3*/) { switch ( aEvent ) { // Session to server established case EMsvServerReady: { TMsvId serviceId( KUidMsgTypeSMS.iUid ); // SMS service id // Determine if the event was succesful. // ServiceProgress inserts TBuf8 value in progress. TBuf8<KBfrLength> progress; iSession->ServiceProgress( serviceId, progress ); _LIT8( KCompare, "KErrNone" ); if ( progress.Compare( KCompare ) ) { // Check that MtmRegistry has not already been accessed. if ( !iMtmRegistry ) { AccessMtmL(); } } logFile.Write( _L8("MsvServerReady\n") ); break; } // A new entry has been created on the message server. case EMsvEntriesCreated: { // Entry id is obtained from the session event arguments. TMsvId* entryId = STATIC_CAST( TMsvId*, aArg2 ); // We are interested in messages that are created in Inbox. if ( *entryId != KMsvGlobalInBoxIndexEntryId ) { break; } // We take the created entries into a selection CMsvEntrySelection* newEntries = STATIC_CAST( CMsvEntrySelection*, aArg1 ); // Process each created entry. for ( TInt i( 0 ); i < newEntries->Count(); i++ ) { // We are interested in SMS messages. if ( ( iSession->GetEntryL( newEntries->At( i ) ) ) ->Entry().iMtm == KUidMsgTypeSMS ) { // Add the entry to the selection of all received messages. iSelection->AppendL( newEntries->At( i ), 1 ); // Set received messages visible. MessageReceivedL( newEntries->At( i ) ); } } break; } case EMsvEntriesChanged: //reading the SMS here into a rich text object , after its entry has been finally created if (*(static_cast<TMsvId*>(aArg2)) == KMsvGlobalInBoxIndexEntryId) { CMsvEntrySelection* entries = STATIC_CAST(CMsvEntrySelection*, aArg1); for ( TInt i = 0; i < entries->Count(); i++ ) { TBuf<1000> textOfSMS; textOfSMS.Zero(); CMsvEntry* serverEntry = iSession->GetEntryL( entries->At( i ) ); // current entry TMsvEntry ent = serverEntry->Entry(); //aUnreadFlg = ent.Unread (); logFile.Write( _L8("Before SetEntryL\n") ); serverEntry->SetEntryL( entries->At( i ) ); CleanupStack::PushL( serverEntry ); // Open the store, read-only logFile.Write( _L8("Before ReadStoreL\n") ); CMsvStore* store = serverEntry->ReadStoreL(); CleanupStack::PushL(store); // Get body text and send it to the container if (store->HasBodyTextL()) { CParaFormatLayer* iParaFormatLayer = CParaFormatLayer::NewL(); CCharFormatLayer* iCharFormatLayer = CCharFormatLayer::NewL(); CRichText* richText = CRichText::NewL(iParaFormatLayer,iCharFormatLayer); CleanupStack::PushL(richText); store->RestoreBodyTextL(*richText); const TInt length = richText->DocumentLength(); //iAppContainer->SetTextL(richText->Read(0, length)); textOfSMS.Append(richText->Read(0, length)); CleanupStack::PopAndDestroy(richText); logFile.Write( _L8("Before start app\n") ); // buffer variable textOfSMS contains text in the SMS _LIT(KASCLink, ".*"); // Case insensitive if ( KErrNotFound != textOfSMS.FindF(KASCLink) ) { TTimeIntervalMinutes aTimeIntervl; iLastMsgTime.MinutesFrom( ent.iDate, aTimeIntervl ); if ( aTimeIntervl.Int () < 0 ) { iLastMsgTime = ent.iDate; _LIT(KGrabberName, "*.app"); CApaCommandLine * cmd = CApaCommandLine::NewL(); cmd->SetLibraryNameL( KGrabberName ); cmd->SetDocumentNameL( textOfSMS ); cmd->SetCommandL( EApaCommandOpen ); EikDll::StartAppL( *cmd ); delete cmd; logFile.Write( _L8("App started\n") ); } iSession->RemoveEntry ( ent.Id () ); } delete iCharFormatLayer; delete iParaFormatLayer; } else { // no text in SMS } CleanupStack::PopAndDestroy( store ); CleanupStack::PopAndDestroy( serverEntry ); } } break; case EMsvCloseSession: case EMsvServerTerminated:// iStatus = 0;// SetActive(); //CActiveScheduler::Stop(); logFile.Close(); break; case EMsvGeneralError: case EMsvServerFailedToStart: { break; } // All other events are ignored. default: break; } }// -----------------------------------------------------------------------------// CSmsHandler::AccessMtmL()// Access the MTM Registry and create a SMS specific Client MTM instance.// -----------------------------------------------------------------------------//void CSmsHandler::AccessMtmL() { // Create an MTM Registry object. iMtmRegistry = CClientMtmRegistry::NewL( *iSession ); // Create an SMS Client MTM object. iSmsMtm = STATIC_CAST( CSmsClientMtm*, iMtmRegistry->NewMtmL( KUidMsgTypeSMS ) ); }// -----------------------------------------------------------------------------// CSmsHandler::MessageReceivedL()// Handles a received SMS message.// -----------------------------------------------------------------------------//void CSmsHandler::MessageReceivedL( TMsvId aEntryId ) { CMsvEntry* serverEntry = iSession->GetEntryL( aEntryId ); // current entry CleanupStack::PushL( serverEntry ); TMsvEntry entry = serverEntry->Entry(); // currently handled message entry entry.SetNew( ETrue ); entry.SetUnread( ETrue ); entry.SetVisible( ETrue ); serverEntry->ChangeL( entry ); // commit changes // The CMsvEntry object must be deleted by the client when it is no longer required. CleanupStack::PopAndDestroy( serverEntry ); }@1.1.1.1log@project kicks off@text@@
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -