searchfw/plugins/notessearchplugin/src/notessearchplugin.cpp
changeset 89 b57382753122
parent 0 f979ecb2b13e
equal deleted inserted replaced
83:5aadd1120515 89:b57382753122
       
     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 note information search.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 //System Includes
       
    21 
       
    22 #include <AknsConstants.h>
       
    23 //#include <apacmdlin.h>
       
    24 #include <barsread.h> 
       
    25 #include <barsc.h>
       
    26 #include <apgcli.h>
       
    27 #include <apacmdln.h> 
       
    28 #include <fbs.h> 
       
    29 #include <utf.h>
       
    30 #include <NpdApi.h>
       
    31 #include <data_caging_path_literals.hrh>
       
    32 #include <coemain.h>
       
    33 //Search FW Common includes
       
    34 #include <searchcontentsearcher.h>
       
    35 #include <searchcondition.h>
       
    36 #include <searchcontent.h>
       
    37 #include <searchiconinfo.h>
       
    38 #include <searchdocumentid.h>
       
    39 #include <searchcommon.h>
       
    40 #include <bautils.h>
       
    41 #include <w32std.h>
       
    42 
       
    43 #include <notespluginsresource.rsg> 
       
    44 #include <notespluginicons.mbg>
       
    45 
       
    46 #include <apgtask.h>
       
    47 //User includes
       
    48 #include "notessearchplugin.h" 
       
    49 #include "notessearcher.h"
       
    50 #include "notessearchpluginutils.h"
       
    51 
       
    52 //Constants
       
    53 _LIT( KResoureFileName, "notespluginsresource.RSC" );
       
    54 _LIT( KNotesPluginMifFileName , "notespluginicons.mif" );
       
    55 _LIT  (KNotePadDocumentName, "c:Notepad.dat");
       
    56 
       
    57 // -----------------------------------------------------------------------------
       
    58 // constructor
       
    59 // -----------------------------------------------------------------------------
       
    60 //
       
    61 CNotesSearchPlugin::CNotesSearchPlugin() 
       
    62     {
       
    63     }
       
    64 
       
    65 
       
    66 // -----------------------------------------------------------------------------
       
    67 // two-phased constructor
       
    68 // -----------------------------------------------------------------------------
       
    69 //
       
    70 CNotesSearchPlugin*  CNotesSearchPlugin::NewL()
       
    71     {
       
    72     CNotesSearchPlugin*  self = new(ELeave) CNotesSearchPlugin();
       
    73     CleanupStack::PushL( self );
       
    74     (*self).ConstructL();
       
    75     CleanupStack::Pop( self );
       
    76     return self;
       
    77     }
       
    78 
       
    79 // -----------------------------------------------------------------------------
       
    80 // destrudtor
       
    81 // -----------------------------------------------------------------------------
       
    82 //
       
    83 CNotesSearchPlugin::~CNotesSearchPlugin()       
       
    84     {
       
    85     
       
    86     }
       
    87 
       
    88 // -----------------------------------------------------------------------------
       
    89 // second phase construction
       
    90 // -----------------------------------------------------------------------------
       
    91 //
       
    92 void CNotesSearchPlugin::ConstructL()
       
    93     {            
       
    94     
       
    95     }
       
    96 
       
    97 // -----------------------------------------------------------------------------
       
    98 // CNotesSearchPlugin::GetSupportedContentL
       
    99 // 
       
   100 // -----------------------------------------------------------------------------
       
   101 //
       
   102 void CNotesSearchPlugin::GetSupportedContentL( RPointerArray<CSearchContent>& aContent ) 
       
   103     {
       
   104      
       
   105      //content class notes
       
   106      CSearchContent* contentClass = CSearchContent::NewL( CSearchContent::ETypeContentClass );
       
   107      CSearchIconInfo*  classIconinfo = CSearchIconInfo::NewL( );
       
   108     
       
   109      RFs fsSession;
       
   110      RResourceFile resourceFile;    	
       
   111      TFileName resourceFileName;
       
   112 	 User::LeaveIfError( fsSession.Connect() );    
       
   113      
       
   114      
       
   115      TPtrC driveLetter = TParsePtrC( RProcess().FileName() ).Drive();
       
   116      TFileName mifFileName( driveLetter );
       
   117      mifFileName.Append( KDC_APP_BITMAP_DIR );
       
   118      mifFileName.Append( KNotesPluginMifFileName );
       
   119     
       
   120      resourceFileName.Copy( driveLetter );  
       
   121      resourceFileName.Append( KDC_ECOM_RESOURCE_DIR );
       
   122      resourceFileName.Append( KResoureFileName );
       
   123      
       
   124       BaflUtils::NearestLanguageFile( fsSession, resourceFileName );
       
   125       
       
   126      resourceFile.OpenL(fsSession, resourceFileName );
       
   127   	 resourceFile.ConfirmSignatureL(0); 
       
   128        
       
   129        
       
   130      //From <AknsConstants.h>
       
   131      classIconinfo->SetSkinId( KAknsIIDQsnFrNotepad  );    
       
   132      classIconinfo->SetIconFileL( mifFileName );
       
   133      classIconinfo->SetIconIndex( EMbmNotespluginiconsQgn_prop_nrtyp_note );
       
   134      classIconinfo->SetIconMaskIndex( EMbmNotespluginiconsQgn_prop_nrtyp_note_mask );
       
   135           
       
   136      contentClass->SetIconInfo( classIconinfo );
       
   137      contentClass->SetContentId( KSearchCClassNotesUid );
       
   138      contentClass->SetSubContentId( 0 );
       
   139      contentClass->SetPluginId( this->PluginId() ); 
       
   140      
       
   141      HBufC8* readBuffer=resourceFile.AllocReadLC( R_QTN_SEARCH_TYPES_NOTES );
       
   142 		const TPtrC16 ptrReadBuffer(( TText16*) readBuffer->Ptr(),
       
   143 									( readBuffer->Length()+1 )>>1 );	
       
   144 	 HBufC *iCaption = ptrReadBuffer.AllocL();								
       
   145 	 
       
   146      CleanupStack::PopAndDestroy( readBuffer ); 
       
   147      contentClass->SetCaptionL( *iCaption );
       
   148      aContent.Append( contentClass );
       
   149      resourceFile.Close();
       
   150      if(iCaption)
       
   151     {
       
   152     	delete iCaption;
       
   153     	iCaption = NULL;
       
   154     }
       
   155      
       
   156      }
       
   157 
       
   158 // -----------------------------------------------------------------------------
       
   159 // 
       
   160 // -----------------------------------------------------------------------------
       
   161 //
       
   162 TBool  CNotesSearchPlugin::IsSupportedContent( TUid aContentId  ) 
       
   163     {
       
   164     if( aContentId.iUid  == KSearchCClassNotesUid.iUid  /*|| aContentId == KSearchCFolderMemoUid */ )
       
   165     {
       
   166      return ETrue; 
       
   167     }
       
   168     return EFalse;
       
   169     }
       
   170 
       
   171 
       
   172 // -----------------------------------------------------------------------------
       
   173 // Creates the content searcher 
       
   174 // -----------------------------------------------------------------------------
       
   175 //
       
   176 MSearchContentSearcher* CNotesSearchPlugin::ContentSearcherL( const RArray<TUid>& aContentIdArray, 
       
   177                                                               const CSearchCondition& aCondition,
       
   178                                                               MSearchPluginObserver& aObserver)
       
   179 
       
   180     { 
       
   181     for( TInt j = 0; j < aContentIdArray.Count(); j++ ) 
       
   182 	    {
       
   183 	     
       
   184 	    if( (aContentIdArray[j].iUid == KSearchCClassNotesUid.iUid ))
       
   185 	        {	
       
   186 		    //  create the content searcher  
       
   187             iNotesSearcher =  CNotesSearcher::NewL( aContentIdArray , aCondition ,PluginId(), aObserver );					
       
   188             return iNotesSearcher;
       
   189             }
       
   190 	     }
       
   191 	
       
   192 	return NULL;   
       
   193     
       
   194     }              
       
   195 
       
   196 // -----------------------------------------------------------------------------
       
   197 // Launches the notepad application corresponding to the document id
       
   198 // -----------------------------------------------------------------------------
       
   199 //
       
   200 
       
   201 void CNotesSearchPlugin::LaunchApplicationL( const TDesC8& aLaunchInfo )
       
   202     {
       
   203             HBufC *temp = HBufC::NewL(KMaxFileName) ;
       
   204             TPtr docIdPtr = temp->Des();
       
   205             TInt noteKey;
       
   206 		    CnvUtfConverter::ConvertToUnicodeFromUtf8( docIdPtr,aLaunchInfo);
       
   207 		    TLex16 myDocId(docIdPtr);
       
   208 		    TInt err = myDocId.Val(noteKey);
       
   209 		    _LIT( KNotePadExe, "notepad.exe" ); 	
       
   210             delete   temp;
       
   211             temp = NULL;   
       
   212             if(KErrNone == err)
       
   213             {
       
   214             	
       
   215             
       
   216             if(iNotesSearcher->CheckIfEntryExistsL(noteKey))
       
   217             {
       
   218             HBufC8* numberInDecimal = aLaunchInfo.AllocLC();
       
   219             RWsSession ws;
       
   220             User::LeaveIfError( ws.Connect() );
       
   221             TUid uid( TUid::Uid( 0x10005907 ) );
       
   222             TUid uid2( TUid::Uid( 0x1000590C ) );
       
   223             TApaTaskList taskList(ws);
       
   224             TApaTask task = taskList.FindApp( uid  );
       
   225             TBool taskExists = task.Exists();
       
   226             if( taskExists ) 
       
   227                 {
       
   228                 task.SendMessage( uid2 , aLaunchInfo );
       
   229                 task.BringToForeground();
       
   230                 }
       
   231             ws.Close();
       
   232            if( !taskExists )
       
   233         	    {
       
   234         RApaLsSession apaLsSession;
       
   235         User::LeaveIfError( apaLsSession.Connect() );
       
   236         CleanupClosePushL( apaLsSession );
       
   237         
       
   238         // Prepare for the launch of notepad application
       
   239         CApaCommandLine* cmdLine = CApaCommandLine::NewLC();
       
   240 		        
       
   241         cmdLine->SetExecutableNameL( KNotePadExe );
       
   242         cmdLine->SetCommandL( EApaCommandOpen );
       
   243         cmdLine->SetDocumentNameL(KNotePadDocumentName);
       
   244 
       
   245         TPtrC8 ptr(  (TText8*)(numberInDecimal->Ptr())  ,  numberInDecimal->Des().Size() );
       
   246         cmdLine->SetTailEndL( ptr);
       
   247 
       
   248         // Launch the  notepad application
       
   249         User::LeaveIfError( apaLsSession.StartApp( *cmdLine ) );
       
   250 		        CleanupStack::PopAndDestroy( 2 );
       
   251         }
       
   252            CleanupStack::PopAndDestroy( 1 );
       
   253            }	        
       
   254 	    }
       
   255 	        else
       
   256 	        {
       
   257 	        		User::Leave( KErrNotFound );
       
   258 	        }
       
   259            
       
   260        
       
   261     }
       
   262     
       
   263 //end of file
       
   264 
       
   265