searchfw/plugins/contactsplugin/src/contactssearchplugin.cpp
changeset 0 f979ecb2b13e
equal deleted inserted replaced
-1:000000000000 0:f979ecb2b13e
       
     1 /*
       
     2 * Copyright (c) 2006-2007 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:   Plugin for contactsplugin information search.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 //SYSTEM INCLUDES
       
    22 #include <e32cmn.h>
       
    23 #include <e32def.h>
       
    24 #include <bautils.h>
       
    25 #include <f32file.h>
       
    26 #include <s32mem.h>
       
    27 #include <data_caging_path_literals.hrh>
       
    28 #include <utf.h>
       
    29 #include <barsc.h>
       
    30 #include <AknsConstants.h>
       
    31 //#include <CPbk2ViewState.h>
       
    32 #include <MVPbkContactLink.h>
       
    33 #include <platform/app/Pbk2UID.h>
       
    34 #include <viewcli.h>
       
    35 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
       
    36 #include <viewclipartner.h>
       
    37 #endif
       
    38 #include <searchcommon.h>
       
    39 #include <searchcontent.h>
       
    40 #include <searchiconinfo.h>
       
    41 #include <searchdocumentid.h>
       
    42 #include <contactssearchplugin.mbg>
       
    43 #include <bautils.h>
       
    44 
       
    45 //USER INCLUDES
       
    46 #include "contactssearchplugin.h"
       
    47 #include "contactssearchplugindefines.h"
       
    48 #include "contactssearchresource.rsg"
       
    49 
       
    50 //FORWARD DECLARATION
       
    51 class CVwsSessionWrapper;
       
    52 
       
    53 
       
    54 
       
    55 // ------------------------------------------------------
       
    56 // 1st phase constructor
       
    57 // ------------------------------------------------------
       
    58 CContactSearchPlugin* CContactSearchPlugin::NewL()
       
    59 {
       
    60 	CContactSearchPlugin* self = new ( ELeave ) CContactSearchPlugin();
       
    61 	
       
    62 	CleanupStack::PushL( self );
       
    63 	self->ConstructL();
       
    64 	CleanupStack::Pop( self );
       
    65 
       
    66 	return self;
       
    67 }
       
    68 
       
    69 
       
    70 // ------------------------------------------------------
       
    71 // Desstructor
       
    72 // ------------------------------------------------------
       
    73 CContactSearchPlugin::~CContactSearchPlugin()
       
    74     {
       
    75        if(iContactsCaption)
       
    76            {
       
    77            delete iContactsCaption;
       
    78            iContactsCaption = NULL;   	
       
    79            }
       
    80        
       
    81        if(iSimCaption)
       
    82            {
       
    83            delete iSimCaption;
       
    84            iSimCaption = NULL;   	
       
    85            }
       
    86        
       
    87        if(iPhoneMemoryCaption)
       
    88            {
       
    89            delete iPhoneMemoryCaption;
       
    90            iPhoneMemoryCaption= NULL;   	
       
    91            }
       
    92        
       
    93        if(iViewSrvSession)
       
    94        {
       
    95        	delete iViewSrvSession;
       
    96        	iViewSrvSession = NULL;
       
    97        }
       
    98        
       
    99     }
       
   100     
       
   101     
       
   102 
       
   103 // ------------------------------------------------------
       
   104 // Creates a content searcher and ownership is transfered 
       
   105 // to calling function
       
   106 // ------------------------------------------------------
       
   107 //
       
   108 MSearchContentSearcher* CContactSearchPlugin::ContentSearcherL(
       
   109   const RArray<TUid>& aContentIdArray, const CSearchCondition& aCondition,
       
   110   MSearchPluginObserver& aObserver )
       
   111 {
       
   112 		
       
   113 	 for( TInt j = 0; j < aContentIdArray.Count(); j++ ) 
       
   114 	{
       
   115 	    //  create the iImagesSearcher   
       
   116 	  if( (aContentIdArray[j].iUid == KSearchCClassContactsUid.iUid ))
       
   117 	  {	
       
   118 		   iContactsSearcher = NULL;
       
   119            iContactsSearcher = CContactsSearcher::NewL( aContentIdArray,
       
   120         						aCondition, this->PluginId(),aObserver); 
       
   121            return iContactsSearcher;												
       
   122       }
       
   123 	}
       
   124 	return NULL;
       
   125 }
       
   126 
       
   127 
       
   128 // ------------------------------------------------------
       
   129 // Gets supported contents
       
   130 // ------------------------------------------------------
       
   131 //
       
   132 void CContactSearchPlugin::GetSupportedContentL( 
       
   133 			RPointerArray<CSearchContent>& aContent ) 
       
   134 {
       
   135 
       
   136     CSearchContent* content = NULL;
       
   137 	CSearchIconInfo* icon = NULL;
       
   138 	
       
   139 	content = CSearchContent::NewL( CSearchContent::ETypeContentClass );
       
   140 	CleanupStack::PushL( content );
       
   141 
       
   142 		
       
   143 	content->SetContentId( KSearchCClassContactsUid );
       
   144 	content->SetSubContentId(0 );
       
   145 	content->SetPluginId( this->PluginId() );
       
   146 	
       
   147 	
       
   148 	 
       
   149 	RFs fsSession;
       
   150 	_LIT( KContactsMifFileName, "contactssearchplugin.mif" );
       
   151     
       
   152     TPtrC driveLetter = TParsePtrC( RProcess().FileName() ).Drive();
       
   153 	TFileName mifFileName( driveLetter );
       
   154 	mifFileName.Append( KDC_APP_BITMAP_DIR );
       
   155 	mifFileName.Append( KContactsMifFileName );
       
   156 	
       
   157 	icon = CSearchIconInfo::NewL();
       
   158 	CleanupStack::PushL( icon );
       
   159 	icon->SetSkinId( KAknsIIDQgnPropFmgrFileApps );
       
   160 	icon->SetIconFileL( mifFileName );
       
   161 	
       
   162 	//Set the correct prop_file_images_sub and mask
       
   163 	icon->SetIconIndex( EMbmContactssearchpluginQgn_prop_search_contacts );
       
   164 	icon->SetIconMaskIndex( EMbmContactssearchpluginQgn_prop_search_contacts_mask );
       
   165 	CleanupStack::Pop( icon );
       
   166 	content->SetIconInfo( icon );
       
   167 	
       
   168 
       
   169 
       
   170 	content->SetCaptionL( *iContactsCaption );
       
   171 		
       
   172     aContent.Append( content );
       
   173    
       
   174     CleanupStack::Pop( content );
       
   175     
       
   176     CSearchContent* simContent = NULL;
       
   177     simContent = CSearchContent::NewL( CSearchContent::ETypeContentFolder );
       
   178     CleanupStack::PushL( simContent );
       
   179    
       
   180     // Icon for sim contacts
       
   181     CSearchIconInfo* simIconInfo = CSearchIconInfo::NewL();
       
   182     CleanupStack::PushL( simIconInfo );
       
   183     
       
   184     if( simIconInfo )
       
   185     {
       
   186 	    simIconInfo->SetIconFileL( mifFileName );
       
   187 	    simIconInfo->SetIconIndex( EMbmContactssearchpluginQgn_prop_search_contacts );
       
   188 	    simIconInfo->SetIconMaskIndex( EMbmContactssearchpluginQgn_prop_search_contacts_mask );
       
   189 	    simIconInfo->SetSkinId( KAknsIIDQgnIndiCdrReminder );
       
   190     }
       
   191 	
       
   192     if( simIconInfo && simContent )
       
   193     	simContent->SetIconInfo( simIconInfo );
       
   194     
       
   195     if(simContent && content )
       
   196     {    
       
   197     	simContent->SetContentId( KSearchCClassContactsUid );
       
   198     	simContent->SetSubContentId( KSearchCFolderSIMUid.iUid );
       
   199     	simContent->SetPluginId( this->PluginId() );
       
   200         // set caption "SIM contacts"
       
   201       	simContent->SetCaptionL( *iSimCaption );			
       
   202 		content->AddChildL( simContent );
       
   203     }
       
   204     
       
   205     CleanupStack::Pop( simIconInfo );
       
   206     CleanupStack::Pop( simContent );
       
   207     
       
   208     CSearchContent* phoneContent = NULL;
       
   209     phoneContent = CSearchContent::NewL( CSearchContent::ETypeContentFolder );
       
   210     CleanupStack::PushL( phoneContent );
       
   211     
       
   212     // Icon for Phone contacts
       
   213     CSearchIconInfo* phoneIconInfo = CSearchIconInfo::NewL();
       
   214     CleanupStack::PushL( phoneIconInfo );
       
   215     
       
   216     if( phoneIconInfo )
       
   217     {
       
   218 	    phoneIconInfo->SetIconFileL( mifFileName );
       
   219 	    phoneIconInfo->SetIconIndex( EMbmContactssearchpluginQgn_prop_search_contacts );
       
   220 	    phoneIconInfo->SetIconMaskIndex( EMbmContactssearchpluginQgn_prop_search_contacts_mask );
       
   221 	    phoneIconInfo->SetSkinId( KAknsIIDQgnIndiCdrReminder );
       
   222     }
       
   223 	
       
   224     if( phoneIconInfo && phoneContent )
       
   225     	phoneContent->SetIconInfo( phoneIconInfo );
       
   226     
       
   227     if(phoneContent && content)
       
   228     {    
       
   229     	phoneContent->SetContentId( KSearchCClassContactsUid );
       
   230     	phoneContent->SetSubContentId( KSearchCFolderPhoneUid.iUid);
       
   231     	phoneContent->SetPluginId( this->PluginId() );
       
   232     	
       
   233         // set caption "Phone contacts"
       
   234     	phoneContent->SetCaptionL( *iPhoneMemoryCaption );			
       
   235 		content->AddChildL( phoneContent );
       
   236     }
       
   237     
       
   238     CleanupStack::Pop( phoneIconInfo );
       
   239     CleanupStack::Pop( phoneContent );
       
   240     
       
   241     
       
   242 }
       
   243 
       
   244 
       
   245 
       
   246 
       
   247 // ------------------------------------------------------
       
   248 // Returns if the given content is supported or not
       
   249 // ------------------------------------------------------
       
   250 //
       
   251 TBool CContactSearchPlugin::IsSupportedContent( TUid aContentId )
       
   252 {
       
   253 	if( KSearchCClassContactsUid.iUid == aContentId.iUid 
       
   254 		|| KSearchCFolderPhoneUid.iUid == aContentId.iUid 
       
   255 		|| KSearchCFolderSIMUid.iUid == aContentId.iUid ) 
       
   256 	{
       
   257 		return ETrue;
       
   258 	}
       
   259 	
       
   260 	return EFalse;
       
   261 }
       
   262 
       
   263 
       
   264 // ------------------------------------------------------
       
   265 // Launches the application corresponding to document id
       
   266 // ------------------------------------------------------
       
   267 //
       
   268 void CContactSearchPlugin::LaunchApplicationL( const TDesC8& aLaunchInfo )
       
   269 {
       
   270 
       
   271 
       
   272  //if(aDocumentId.PluginId() == this->PluginId() )
       
   273    {       
       
   274    
       
   275     //   if( KErrNone == err)
       
   276 	  {
       
   277 		// Write parameters in a buffer
       
   278 		TBuf8<80> param;
       
   279 		
       
   280     //    MVPbkContactLink* launchContact = 
       
   281       //     iContactsSearcher->GetContactLinkAtIndexLC(myArrayIndex);
       
   282         //if(launchContact) 
       
   283         {
       
   284 		
       
   285 		RDesWriteStream stream( param );
       
   286 		stream.PushL();
       
   287 		stream.WriteInt8L( 1 );                 // opcode Version
       
   288 		stream.WriteInt8L( 1 );					// opcode EFocusedContact
       
   289 		HBufC8* buf = HBufC8::NewLC(aLaunchInfo.Length());
       
   290 		buf->Des().Append(aLaunchInfo);
       
   291 		
       
   292 		//HBufC8* buf = launchContact->PackLC();   // pack the contact link
       
   293 		stream.WriteUint16L( buf->Length() );   // write link length
       
   294 	    stream.WriteL( *buf ,buf->Length() );
       
   295 	                // write the actual link buffer
       
   296 		CleanupStack::PopAndDestroy();         // cleanup buf
       
   297 		stream.WriteInt32L( 4 );                 // opcode EFocusedFieldIndex
       
   298 		stream.WriteInt16L( KFocussedFieldIndex ); // field index 3
       
   299 		stream.CommitL();
       
   300 		CleanupStack::PopAndDestroy();
       
   301 		//CleanupStack::PopAndDestroy();         // cleanup stream
       
   302 
       
   303 		// Make view id with Phonebook's app UID3 and Contact Info View's id
       
   304 		const TVwsViewId viewId( TUid::Uid(KPbk2UID3), TUid::Uid(4) );
       
   305 
       
   306 		// Activate the view
       
   307 		iViewSrvSession->ActivateView( viewId, TUid::Uid( 0x102072a0 ), param );
       
   308 	    	
       
   309         }
       
   310         //else
       
   311         {
       
   312         //	 User::Leave( KErrNotFound );
       
   313         }
       
   314 	  }
       
   315     
       
   316    	}
       
   317 
       
   318 }
       
   319 
       
   320 
       
   321 // ------------------------------------------------------
       
   322 // Constructor
       
   323 // ------------------------------------------------------
       
   324 //
       
   325 CContactSearchPlugin::CContactSearchPlugin( )
       
   326 {
       
   327 	
       
   328 		
       
   329 }
       
   330 
       
   331     
       
   332 // ------------------------------------------------------
       
   333 // 2nd phase constructor
       
   334 // ------------------------------------------------------
       
   335 //
       
   336 void CContactSearchPlugin::ConstructL()
       
   337 {
       
   338 	RResourceFile resourceFile;    	
       
   339     HBufC* resourceFileName = HBufC::NewL( KMaxFileName );
       
   340     TPtr resourceFileNamePtr = resourceFileName->Des();
       
   341     
       
   342     TPtrC driveLetter = TParsePtrC( RProcess().FileName() ).Drive();
       
   343     RFs fsSession;
       
   344     User::LeaveIfError( fsSession.Connect() ); 
       
   345     //Read resource file
       
   346 	resourceFileNamePtr.Copy( driveLetter );  
       
   347     resourceFileNamePtr.Append( KDC_ECOM_RESOURCE_DIR );
       
   348     resourceFileNamePtr.Append( KResoureFileName );
       
   349     
       
   350     CleanupClosePushL( resourceFile );
       
   351     TFileName fileName = resourceFileName->Des();
       
   352     BaflUtils::NearestLanguageFile( fsSession,fileName );
       
   353     resourceFile.OpenL(fsSession,fileName );
       
   354   	resourceFile.ConfirmSignatureL(0);
       
   355   	
       
   356   	// Fetch the caption "contacts"
       
   357   	{
       
   358   		
       
   359   	
       
   360   	HBufC8* readBuffer = resourceFile.AllocReadLC( R_QTN_SEARCH_TYPES_CONTACTS );
       
   361 	
       
   362 	const TPtrC16 ptrReadBuffer( ( TText16*) readBuffer->Ptr(),
       
   363 								( readBuffer->Length()+1 )>>1 );		
       
   364 								
       
   365 	iContactsCaption = ptrReadBuffer.AllocL();
       
   366 	CleanupStack::PopAndDestroy( readBuffer );
       
   367 
       
   368     }
       
   369 	// Fetch the caption "SIM Contacts"
       
   370 	{
       
   371 		
       
   372 	HBufC8* readBuffer = resourceFile.AllocReadLC( R_QTN_SEARCH_SUBFOLDERS_SIM );
       
   373 	
       
   374 	const TPtrC16 ptrReadBuffer( ( TText16*) readBuffer->Ptr(),
       
   375 								( readBuffer->Length()+1 )>>1 );		
       
   376 								
       
   377 	iSimCaption = ptrReadBuffer.AllocL();
       
   378 	CleanupStack::PopAndDestroy( readBuffer );
       
   379 
       
   380 	}
       
   381 	//Fetch the caption "Phone contacts"
       
   382 	{
       
   383 		
       
   384 	HBufC8* readBuffer = resourceFile.AllocReadLC( R_QTN_SEARCH_SUBFOLDERS_PHONE );
       
   385 	
       
   386 	const TPtrC16 ptrReadBuffer( ( TText16*) readBuffer->Ptr(),
       
   387 								( readBuffer->Length()+1 )>>1 );		
       
   388 								
       
   389 	iPhoneMemoryCaption = ptrReadBuffer.AllocL();
       
   390 	
       
   391 	CleanupStack::PopAndDestroy( readBuffer );
       
   392 
       
   393 	}
       
   394 	CleanupStack::Pop( );
       
   395 	resourceFile.Close();
       
   396 	delete resourceFileName;
       
   397 	resourceFileName = NULL;
       
   398 	fsSession.Close();	
       
   399 	
       
   400 	//Create the view session
       
   401 	iViewSrvSession = CVwsSessionWrapper::NewL();
       
   402 }
       
   403 
       
   404 
       
   405 
       
   406