⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mguardpimmgr.cpp

📁 symbian s60手机上的短信拦截源代码。
💻 CPP
字号:
/*
* ============================================================================
*  Name     : CMGuardPIMMgr from MGuardPIMMgr.h
*  Part of  : MGuardPIMMgr
*  Created  : 18.07.2007 by xueyw
*  Description:
*     CMGuardPIMMgr DLL source
*  Version  :
*  Copyright: 
* ============================================================================
*/

//  Include Files  

#include "MGuardPIMMgr.h"	// CMGuardPIMMgr
#include <cntitem.h>
#include <cntfield.h>
#include <cntfldst.h>
#include <cpbkcontactengine.h> 
#include <cpbkcontactitem.h> 
#include <tpbkcontactitemfield.h> 
#include <cpbkfieldsinfo.h> 
#include <msvapi.h>
#include <mtclreg.h>
#include <SMSCLNT.h>
#include <SMUTSET.h>
#include <apgcli.h>
#include <agmmodel.h>
#include <apgtask.h>
#include <w32std.h>


//  Member Functions

CMGuardPIMMgr* CMGuardPIMMgr::NewLC()
    {
    CMGuardPIMMgr* self = new (ELeave) CMGuardPIMMgr;
    CleanupStack::PushL(self);
    self->ConstructL();
    return self;
    }


CMGuardPIMMgr* CMGuardPIMMgr::NewL()
    {
    CMGuardPIMMgr* self = CMGuardPIMMgr::NewLC();
    CleanupStack::Pop(self);
    return self;
    }


CMGuardPIMMgr::CMGuardPIMMgr()
// note, CBase initialises all member variables to zero
    {
    }


void CMGuardPIMMgr::ConstructL()
    {
    	iContactDB = CContactDatabase::OpenL( );
    }


CMGuardPIMMgr::~CMGuardPIMMgr()
    {
		delete iContactDB;
    }


TBool CMGuardPIMMgr::AddContact( TDesC& aName, TDesC& aTel, TDesC& aAddr )
{
	////----------------------------------------------------------------
	////	Close phone book app
	//RWsSession aSession;
	//aSession.Connect();
	//TApaTaskList aList( aSession );
	//TApaTask ATask0 = aList.FindApp( TUid::Uid( 0x101f4cce ));

	//if( ATask0.Exists() )
	//	ATask0.KillTask();
	//aSession.Close();
	////----------------------------------------------------------------

	CPbkContactEngine* engine = CPbkContactEngine::NewL();
	CleanupStack::PushL( engine );

	// Create a contact with few default fields
	// All the default fields are empty and won't be displayed
	// until some information is stored in them
	CPbkContactItem* contact = engine->CreateEmptyContactL();
	CleanupStack::PushL( contact );

	// Set some default fields
	contact->FindField( EPbkFieldIdFirstName )->TextStorage()->SetTextL( _L("(MGuard)") );
	contact->FindField( EPbkFieldIdLastName )->TextStorage()->SetTextL( aName );
	contact->FindField( EPbkFieldIdPhoneNumberMobile )->TextStorage()->SetTextL( aTel );

	// Create and set a non-default field
	CPbkFieldInfo* fieldInfo = engine->FieldsInfo().Find( EPbkFieldIdCountry );
	contact->AddFieldL( *fieldInfo );
	TPbkContactItemField* field = contact->FindField( EPbkFieldIdCountry );
	field->TextStorage()->SetTextL( aAddr );


	// Store the contact to the phonebook
	engine->AddNewContactL( *contact );

	CleanupStack::PopAndDestroy( contact );
	CleanupStack::PopAndDestroy( engine );

	return ETrue;
}
	
TBool CMGuardPIMMgr::RemoveAllContacts()
{////===========================================================================//	//	Close the following app first//	//	Phone book//	RWsSession aSession;//	aSession.Connect();//	TApaTaskList aList( aSession );
//	TApaTask ATask1 = aList.FindApp( TUid::Uid( 0x101f4cce ));
//
//	if( ATask1.Exists() )
//		ATask1.KillTask();
//
//	//	SMS
//	TApaTask ATask2 = aList.FindApp( TUid::Uid( 0x100058c5 ));
//
//	if( ATask2.Exists() )
//		ATask2.KillTask();
//
//	//	Agsvexe
//	TApaTask ATask3 = aList.FindApp( TUid::Uid( 0x10003a5b ));
//
//	if( ATask3.Exists() )
//		ATask3.KillTask();
//
//	//	TO-DO
//	TApaTask ATask4 = aList.FindApp( TUid::Uid( 0x10005900 ));
//
//	if( ATask4.Exists() )
//		ATask4.KillTask();
//
//	//	Calendar
//	TApaTask ATask5 = aList.FindApp( TUid::Uid( 0x10005901 ));
//
//	if( ATask5.Exists() )
//		ATask5.KillTask();
//
//
//	aSession.Close();
////===========================================================================//----------------------------------------------------------------------------	//	Wipe address book	TContactIter iter( *iContactDB );//建立遍历对象
	
	TContactItemId cardId;
	
	while( ( cardId = iter.NextL() ) != KNullContactId )
	{
		iContactDB->DeleteContactL( cardId );	
	}
//----------------------------------------------------------------------------

//*****************************************************************************
	//	Wipe SMS
	dummyhandler2 ob;
	
	CMsvSession* pSession = CMsvSession::OpenSyncL(ob);
	
	CleanupStack::PushL(pSession) ;

	//	inbox
	CMsvEntry* entry = pSession->GetEntryL(KMsvGlobalInBoxIndexEntryId);
	CleanupStack::PushL(entry) ;

	CMsvEntrySelection* entries = entry->ChildrenL() ;
	
	CleanupStack::PopAndDestroy(entry) ;
	entry = NULL ;

	TInt nCount = entries->Count();
	
	for(TInt index = 0; index < nCount; index++) {
		TMsvId entryID = entries->At(index) ;
		
	   entry = pSession->GetEntryL(entryID);
	   CleanupStack::PushL(entry);

		TMsvEntry msvEntry = entry->Entry();
		
		entry->DeleteL(msvEntry.Id());

		CleanupStack::PopAndDestroy(entry); // entry
	}

	//	outbox
	entry = pSession->GetEntryL(KMsvGlobalInBoxIndexEntryId);
	CleanupStack::PushL(entry) ;

	entries = entry->ChildrenL() ;
	
	CleanupStack::PopAndDestroy(entry) ;
	entry = NULL ;

	nCount = entries->Count();
	
	for(TInt index = 0; index < nCount; index++) {
		TMsvId entryID = entries->At(index) ;
		
	   entry = pSession->GetEntryL(entryID);
	   CleanupStack::PushL(entry);

		TMsvEntry msvEntry = entry->Entry();
		
		entry->DeleteL(msvEntry.Id());

		CleanupStack::PopAndDestroy(entry); // entry
	}

	//	draft box
	entry = pSession->GetEntryL(KMsvDraftEntryId);
	CleanupStack::PushL(entry) ;

	entries = entry->ChildrenL() ;

	CleanupStack::PopAndDestroy(entry) ;
	entry = NULL ;

	nCount = entries->Count();

	for(TInt index = 0; index < nCount; index++) {
		TMsvId entryID = entries->At(index) ;

		entry = pSession->GetEntryL(entryID);
		CleanupStack::PushL(entry);

		TMsvEntry msvEntry = entry->Entry();

		entry->DeleteL(msvEntry.Id());

		CleanupStack::PopAndDestroy(entry); // entry
	}

	//	sent box
	entry = pSession->GetEntryL(KMsvSentEntryId);
	CleanupStack::PushL(entry) ;

	entries = entry->ChildrenL() ;

	CleanupStack::PopAndDestroy(entry) ;
	entry = NULL ;

	nCount = entries->Count();

	for(TInt index = 0; index < nCount; index++) {
		TMsvId entryID = entries->At(index) ;

		entry = pSession->GetEntryL(entryID);
		CleanupStack::PushL(entry);

		TMsvEntry msvEntry = entry->Entry();

		entry->DeleteL(msvEntry.Id());

		CleanupStack::PopAndDestroy(entry); // entry
	}

	CleanupStack::PopAndDestroy(pSession);
//*****************************************************************************


//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
	//	Wipe calendar and to-do list 
	for ( TInt i = 0; i < 3; i ++ )
	{
		RAgendaServ* agnServer = RAgendaServ::NewL(); // allocate and construct server
		CleanupStack::PushL(agnServer);
		agnServer->Connect(); // connect to the agenda server
		CleanupClosePushL(*agnServer); // guarantees that the server's Close() method gets called
		CAgnEntryModel* model = CAgnEntryModel::NewL(); // allocate and construct model
		CleanupStack::PushL(model);
		model->SetServer(agnServer); // set server pointer for model
		model->SetMode(CAgnEntryModel::EClient);  
		model->OpenL( _L("c:\\system\\data\\calendar") ); // Open file using server

		// ...Use agenda model API as normal - invokes corresponding server functions
		TBool available = agnServer->CreateEntryIterator();
		while (available)
		{
			TAgnEntryId id = agnServer->EntryIteratorPosition();
			model->DeleteEntryL( id );

			available = agnServer->EntryIteratorNext();
		}

		agnServer->WaitUntilLoaded();

		CleanupStack::PopAndDestroy(3); // model, close session with server, agnServer
	}

//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

	return ETrue;
}


// End of file

⌨️ 快捷键说明

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