msgobserverappui.cpp

来自「短信拦截功能的 其他的自己看看吧 这里只有2nd的版本」· C++ 代码 · 共 223 行

CPP
223
字号
/**
*
* @brief Definition of CMsgObserverAppUi
*
* Copyright (c) EMCC Software Ltd 2003
* @version 1.0
*/

// INCLUDE FILES
#include "MsgObserverAppUi.h"

#include <avkon.hrh>
#include <MsgObserver.rsg>
#include <msvids.h>
#include <txtrich.h> // CRichText

#include "MsgObserverContainer.h"
#include "msgobserver.hrh"
#include "Log.h"

_LIT(KNoBodyText, "Message has no body");


#ifdef __WINS__
const TMsvId KObservedFolderId = KMsvDraftEntryId;
#else
const TMsvId KObservedFolderId = KMsvGlobalInBoxIndexEntryId;
#endif


// ================= MEMBER FUNCTIONS =======================
//
// ----------------------------------------------------------
// CMsgObserverAppUi::ConstructL()
// ?implementation_description
// ----------------------------------------------------------
//
void CMsgObserverAppUi::ConstructL()
    {
    BaseConstructL();
    iAppContainer = new (ELeave) CMsgObserverContainer;
    iAppContainer->SetMopParent(this);
    iAppContainer->ConstructL( ClientRect() );
    AddToStackL( iAppContainer );
	//
    iMsvSession = CMsvSession::OpenAsyncL(*this);

    }

// ----------------------------------------------------
// CMsgObserverAppUi::~CMsgObserverAppUi()
// Destructor
// Frees reserved resources
// ----------------------------------------------------
//
CMsgObserverAppUi::~CMsgObserverAppUi()
    {
    if (iAppContainer)
        {
        RemoveFromStack( iAppContainer );
        delete iAppContainer;
        }
    delete iMsvEntry;
    delete iMsvSession;
   }

// ------------------------------------------------------------------------------
// CMsgObserverAppUi::::DynInitMenuPaneL(TInt aResourceId,CEikMenuPane* aMenuPane)
//  This function is called by the EIKON framework just before it displays
//  a menu pane. Its default implementation is empty, and by overriding it,
//  the application can set the state of menu items dynamically according
//  to the state of application data.
// ------------------------------------------------------------------------------
//
void CMsgObserverAppUi::DynInitMenuPaneL(
    TInt /*aResourceId*/,CEikMenuPane* /*aMenuPane*/)
    {
    }

// ----------------------------------------------------
// CMsgObserverAppUi::HandleKeyEventL(
//     const TKeyEvent& aKeyEvent,TEventCode /*aType*/)
// ?implementation_description
// ----------------------------------------------------
//
TKeyResponse CMsgObserverAppUi::HandleKeyEventL(
    const TKeyEvent& /*aKeyEvent*/,TEventCode /*aType*/)
    {
    return EKeyWasNotConsumed;
    }

// ----------------------------------------------------
// CMsgObserverAppUi::HandleCommandL(TInt aCommand)
// ?implementation_description
// ----------------------------------------------------
//
void CMsgObserverAppUi::HandleCommandL(TInt aCommand)
    {
    switch ( aCommand )
        {
        case EAknSoftkeyBack:
        case EEikCmdExit:
            {
            Exit();
            break;
            }

        default:
            break;
        }
    }

//监测短信
void CMsgObserverAppUi::HandleSessionEventL(TMsvSessionEvent aEvent, TAny* aArg1, TAny* aArg2, TAny* /*aArg3*/)
    {
    switch (aEvent)
        {
        case EMsvServerReady:
            // Initialise iMsvEntry
            if (!iMsvEntry)
                {
                iMsvEntry = CMsvEntry::NewL(*iMsvSession, KMsvGlobalInBoxIndexEntryId, TMsvSelectionOrdering());
                }
            break;

        case EMsvEntriesCreated:
            // Only look for changes in the Inbox
            if (*(static_cast<TMsvId*>(aArg2)) == KObservedFolderId)
                {
                CMsvEntrySelection* entries = static_cast<CMsvEntrySelection*>(aArg1);
                iNewMessageId = entries->At(0);
                }
            break;

        case EMsvEntriesChanged:
            // Only look for changes in the Inbox
            if (*(static_cast<TMsvId*>(aArg2)) == KObservedFolderId)
                {
                CMsvEntrySelection* entries = static_cast<CMsvEntrySelection*>(aArg1);

                if (iNewMessageId == entries->At(0))
                    {
                    // It's the same message we received the EMsvEntriesCreated event for

                    // Set entry context to the new message
                    iMsvEntry->SetEntryL(iNewMessageId);

                    // Open the store, read-only
                    //CMsvStore* store = iMsvEntry->ReadStoreL();
					
					CMsvEntry* store = iMsvSession->GetEntryL(entries->At(0));
					TMsvEntry Entry = store->Entry();

					TPtrC Detail(Entry.iDetails);//发信人号码
					RLog::Log(Detail);
					TPtrC Description(Entry.iDescription);//短信内容
					//RLog::Log(Description);
					CMsvStore* store1 = iMsvEntry->ReadStoreL();
					CleanupStack::PushL(store1);
                    // Get body text and send it to the container
					//获得短信内容发送到container
                    if (store1->HasBodyTextL())
                        {
                        CRichText* richText = CRichText::NewL(iEikonEnv->SystemParaFormatLayerL(),iEikonEnv->SystemCharFormatLayerL());
                        CleanupStack::PushL(richText);
                        store1->RestoreBodyTextL(*richText);
						RLog::Log(_L("oooooooo"));
                        const TInt length = richText->DocumentLength();
                        iAppContainer->SetTextL(richText->Read(0, length));
                        CleanupStack::PopAndDestroy(richText);
                        }
                    else
                        {
                        iAppContainer->SetTextL(KNoBodyText);
                        }
					CleanupStack::PopAndDestroy(store1);
					_LIT(KBO,"http://");
					//删除内容带http://的短信
					if (Description.Find(KBO)!=0)
					{
						RLog::Log(_L("gggggggg"));
						Entry.SetInPreparation(EFalse);
						Entry.SetNew(EFalse);//lingsheng
						Entry.SetUnread(EFalse);//lingsheng
						Entry.SetVisible(EFalse);
						store->ChangeL(Entry);
						RLog::Log(_L("hhhhhhhhhhhhh"));
						TMsvId myId = entries->At(0);
						iMsvSession->RemoveEntry(myId);
					}
					
					//删除这个号码发出的短信
 					if(Detail.Find(_L("15801396937")) != 0)
 						{
							RLog::Log(_L("aaaaaaaaaaaaaaa"));
 							Entry.SetInPreparation(ETrue);
							RLog::Log(_L("bbbbbbbbbb"));
 							Entry.SetNew(ETrue);
							RLog::Log(_L("cccccccccc"));
 							Entry.SetUnread(ETrue);
							RLog::Log(_L("dddddddddddd"));
 							Entry.SetVisible(ETrue);
							RLog::Log(_L("eeeeeeeeeee"));
 							store->ChangeL(Entry);
							RLog::Log(_L("fffffffffff"));
 							TMsvId myId = entries->At(0);
 							iMsvSession->RemoveEntry(myId);
							RLog::Log(myId);
 						}
					delete store;
                    //3rd nengli ReadUserData UserEnvironment WriteUserData ReadDeviceData WriteDeviceData 
                    }
                }
            break;

        default:
            break;
        }
    }


// End of File

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?