uiservicetab/vimpstui/src/cvimpstuiextensionfactory.cpp
branchRCL_3
changeset 23 9a48e301e94b
equal deleted inserted replaced
22:3104fc151679 23:9a48e301e94b
       
     1 /*
       
     2 * Copyright (c) 2008 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: Extension factory for VIMPSTUi
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "cvimpstuiextensionfactory.h"
       
    21 
       
    22 // System includes
       
    23 #include <coemain.h>
       
    24 #include <coeutils.h>
       
    25 #include <bautils.h>
       
    26 #include <aknViewAppUi.h>
       
    27 #include <StringLoader.h>
       
    28 
       
    29 // Pbk2
       
    30 #include <MPbk2UIExtensionView.h>
       
    31 #include <CPbk2UIExtensionView.h>
       
    32 
       
    33 
       
    34 // xSP extension manager
       
    35 #include <MxSPViewMapper.h>
       
    36 #include <MxSPContactManager.h>
       
    37 
       
    38 
       
    39 #include "vimpstextentionuiuid.h"
       
    40 #include <vimpstuires.rsg>
       
    41 
       
    42 
       
    43 #include "cvimpstuiviewmanager.h"
       
    44 #include "cvimpstuiextensionservice.h"
       
    45 
       
    46 #include "cvimpstenginefactory.h"
       
    47 #include "cvimpstuitabbedview.h"
       
    48 #include "cvimpstuisearchview.h"
       
    49 #include "tvimpstconsts.h"
       
    50 #include "cvimpstuiblockview.h"
       
    51 
       
    52 #include "uiservicetabtracer.h"
       
    53 #include "cvimpstuimenuextension.h"
       
    54 
       
    55 // ================= MEMBER FUNCTIONS =======================
       
    56 
       
    57 inline CVIMPSTUiExtensionFactory::CVIMPSTUiExtensionFactory() :
       
    58 											iCoeEnv( *CCoeEnv::Static() )
       
    59     {
       
    60     }
       
    61 
       
    62 
       
    63 // --------------------------------------------------------------------------
       
    64 // CVIMPSTUiExtensionFactory::ConstructL
       
    65 // --------------------------------------------------------------------------
       
    66 //
       
    67 void CVIMPSTUiExtensionFactory::ConstructL()
       
    68     {
       
    69     
       
    70     // Load the Resource File
       
    71 	TRACER_AUTO;
       
    72 	TFileName resPathWithoutDrive;
       
    73     resPathWithoutDrive.Zero();
       
    74     resPathWithoutDrive.Append( KResourceDir() );
       
    75     resPathWithoutDrive.Append( KResourceFileName() );
       
    76     
       
    77     TFileName path;    
       
    78     Dll::FileName(path); //get the location of the dll
       
    79     
       
    80     TDriveName drive( TParsePtrC( path ).Drive( ) ); // solve drive
       
    81 
       
    82     // leave to stack, LC method
       
    83     HBufC* resourceFilePath = HBufC::NewLC( KMaxResourcePathLength );
       
    84     TPtr ptr( resourceFilePath->Des() );
       
    85     ptr.Append( resPathWithoutDrive ); // without drive
       
    86     ptr.Insert( 0, drive ); // insert drive
       
    87 
       
    88     // NearestLanguageFile takes only TFileName
       
    89     path.Zero();
       
    90     path.Append( *resourceFilePath );
       
    91 
       
    92     if ( path.Length() != 0 )
       
    93         {
       
    94         BaflUtils::NearestLanguageFile( iCoeEnv.FsSession(), path );
       
    95         }
       
    96 	
       
    97 	CleanupStack::PopAndDestroy();
       
    98 
       
    99 	iResourceOffset = iCoeEnv.AddResourceFileL(path);
       
   100     
       
   101 	iEngineFactoryInstance = CVIMPSTEngineFactory::InstanceL();
       
   102 	
       
   103     iEngine = CVIMPSTUIViewManager::NewL( 
       
   104         			KNullDesC(), *this );  
       
   105     iMenuExtension = CVIMPSTUIMenuExtension::NewL();  
       
   106     // Get's all sevices
       
   107     CreateServicesL();
       
   108      
       
   109     }
       
   110 
       
   111 
       
   112 // --------------------------------------------------------------------------
       
   113 // CVIMPSTUiExtensionFactory::NewL
       
   114 // --------------------------------------------------------------------------
       
   115 //
       
   116 CVIMPSTUiExtensionFactory* CVIMPSTUiExtensionFactory::NewL()
       
   117     {
       
   118 	TRACER_AUTO;
       
   119     CVIMPSTUiExtensionFactory* self = new (ELeave) CVIMPSTUiExtensionFactory;
       
   120     CleanupStack::PushL(self);
       
   121     self->ConstructL();
       
   122     CleanupStack::Pop(self);
       
   123     
       
   124     return self;
       
   125     }
       
   126 
       
   127 
       
   128 // --------------------------------------------------------------------------
       
   129 // CVIMPSTUiExtensionFactory::~CVIMPSTUiExtensionFactory
       
   130 // --------------------------------------------------------------------------
       
   131 //
       
   132 CVIMPSTUiExtensionFactory::~CVIMPSTUiExtensionFactory()
       
   133     {
       
   134 	TRACER_AUTO;
       
   135     delete iEngine;
       
   136     
       
   137     iCoeEnv.DeleteResourceFile( iResourceOffset );
       
   138     
       
   139     //for deleting iEngineFactoryInstance
       
   140     CVIMPSTEngineFactory::Release();
       
   141     
       
   142     delete iMenuExtension;
       
   143     
       
   144     }
       
   145 
       
   146 
       
   147 
       
   148 // --------------------------------------------------------------------------
       
   149 // CVIMPSTUiExtensionFactory::CreateViewL
       
   150 // --------------------------------------------------------------------------
       
   151 //
       
   152 CxSPBaseView* CVIMPSTUiExtensionFactory::CreateViewL( TUid aViewId, CPbk2UIExtensionView& aView )
       
   153     {
       
   154 	TRACER_AUTO;
       
   155     CxSPBaseView* view = NULL;
       
   156     
       
   157     TInt oldView;
       
   158 	TInt err = iMapper->GetOldView( KIMCONTACTSEXTNIMPLEMENTATIONUID, aViewId.iUid, oldView );
       
   159 	
       
   160     if( !err )
       
   161 	    {
       
   162 	    
       
   163         for ( TInt index = 0 ; 
       
   164               index < iEngine->ServiceCount() && !view ; 
       
   165               index++ )
       
   166             {
       
   167             if ( iEngine->Service( index ).HasViewId( oldView ) )
       
   168                 {
       
   169 				if ( IsTabbedId( oldView ) )
       
   170 						{
       
   171 	                		view = iEngine->Service( index ).TabbedViewL(
       
   172 	                        *iMapper, 
       
   173 	                        *iContactManager, 
       
   174 	                        aView,
       
   175 	                        oldView, 
       
   176 	                        aViewId,
       
   177 	                        iEngine->Service(index).ServiceEngine() );                
       
   178                 		}
       
   179 				else if ( IsSearchId( oldView ) )
       
   180 						{
       
   181 						view = iEngine->Service( index ).SearchViewL(
       
   182 						*iMapper, 
       
   183 						*iContactManager, 
       
   184 						aView,
       
   185 						oldView, 
       
   186 						aViewId,
       
   187 						iEngine->Service(index).ServiceEngine() );               
       
   188 						}
       
   189 				else if(IsBlockeId( oldView ))
       
   190 					{
       
   191 						view = iEngine->Service( index ).BlockViewL(
       
   192 						*iMapper, 
       
   193 						*iContactManager, 
       
   194 						aView,
       
   195 						oldView, 
       
   196 						iEngine->Service(index).ServiceEngine() );               
       
   197 					}
       
   198 				}
       
   199 
       
   200 			}
       
   201 	    }
       
   202    
       
   203     return view;
       
   204     }
       
   205   
       
   206   
       
   207 // --------------------------------------------------------------------------
       
   208 // CVIMPSTUiExtensionFactory::RegisterViewMapper
       
   209 // --------------------------------------------------------------------------
       
   210 //    
       
   211 void CVIMPSTUiExtensionFactory::RegisterViewMapper( MxSPViewMapper& aMapper )
       
   212 	{
       
   213 	iMapper = &aMapper;
       
   214 	}
       
   215   
       
   216   
       
   217 // --------------------------------------------------------------------------
       
   218 // CVIMPSTUiExtensionFactory::ViewInfoResource
       
   219 // --------------------------------------------------------------------------
       
   220 //                               
       
   221 TInt CVIMPSTUiExtensionFactory::ViewInfoResource() const
       
   222 	{
       
   223 	TRACER_AUTO;
       
   224 	// Indicate KErrNotFound. This way static resources are not used but
       
   225     // xSP Extension Manager queries data. Exception: If IM is not
       
   226     // supported, indicate it via resource for simplicity
       
   227     TInt ret = KErrNotFound;
       
   228     
       
   229     // add the FeatureManager checks for IM here
       
   230     
       
   231     // Check for any service 
       
   232     if ( !iEngine->ServiceCount()  )
       
   233         {
       
   234         ret = R_IM_CONTACTS_VIEW_INFO;
       
   235         }
       
   236     
       
   237     return ret;
       
   238 	}
       
   239 
       
   240 
       
   241 
       
   242 // --------------------------------------------------------------------------
       
   243 // CVIMPSTUiExtensionFactory::Id
       
   244 // --------------------------------------------------------------------------
       
   245 //    	
       
   246 TUint32 CVIMPSTUiExtensionFactory::Id() const
       
   247 	{
       
   248 	return KIMCONTACTSEXTNIMPLEMENTATIONUID;
       
   249 	}		
       
   250 
       
   251 
       
   252 // --------------------------------------------------------------------------
       
   253 // CVIMPSTUiExtensionFactory::Name()
       
   254 // --------------------------------------------------------------------------
       
   255 //
       
   256 const TDesC& CVIMPSTUiExtensionFactory::Name() const
       
   257 	{
       
   258 	_LIT(KNull, " ");
       
   259 	return KNull;	
       
   260 	}
       
   261 
       
   262 
       
   263 // --------------------------------------------------------------------------
       
   264 // CVIMPSTUiExtensionFactory::RegisterContactManager
       
   265 // --------------------------------------------------------------------------
       
   266 //	
       
   267 void CVIMPSTUiExtensionFactory::RegisterContactManager( MxSPContactManager& aManager )
       
   268 	{
       
   269 	iContactManager = &aManager;
       
   270 	}
       
   271 
       
   272 
       
   273 
       
   274 // --------------------------------------------------------------------------
       
   275 // CVIMPSTUiExtensionFactory::SetVPbkContactManager
       
   276 // --------------------------------------------------------------------------
       
   277 //	
       
   278 void CVIMPSTUiExtensionFactory::SetVPbkContactManager( CVPbkContactManager& /*aVPbkContactManager*/ )
       
   279 	{	
       
   280 	}
       
   281 
       
   282 // --------------------------------------------------------------------------
       
   283 // CVIMPSTUiExtensionFactory::UpdateStorePropertiesL
       
   284 // --------------------------------------------------------------------------
       
   285 //	
       
   286 void CVIMPSTUiExtensionFactory::UpdateStorePropertiesL( CPbk2StorePropertyArray& /*aPropertyArray*/ )
       
   287 	{	
       
   288 	}
       
   289 // --------------------------------------------------------------------------
       
   290 // CVIMPSTUiExtensionFactory::ViewInfoCount
       
   291 // --------------------------------------------------------------------------
       
   292 //	
       
   293 TInt CVIMPSTUiExtensionFactory::ViewInfoCount() const 
       
   294 	{	
       
   295 	return iEngine->ViewInfoCount();	
       
   296 	}
       
   297 // --------------------------------------------------------------------------
       
   298 // CVIMPSTUiExtensionFactory::ViewInfo
       
   299 // --------------------------------------------------------------------------
       
   300 //	
       
   301 const MxSPViewInfo* CVIMPSTUiExtensionFactory::ViewInfo( TInt aIndex ) const 
       
   302 	{	
       
   303 	return iEngine->ViewInfo( aIndex );	
       
   304 	}
       
   305 	
       
   306 
       
   307 // ---------------------------------------------------------------------------
       
   308 // CVIMPSTUiExtensionFactory::CreateServicesL()
       
   309 // ---------------------------------------------------------------------------
       
   310 //  
       
   311 void CVIMPSTUiExtensionFactory::CreateServicesL()
       
   312     {
       
   313 	TRACER_AUTO;
       
   314     // Get all available services   
       
   315     RPointerArray<MVIMPSTEngine> engines;
       
   316     
       
   317     if (iEngineFactoryInstance)
       
   318 	    {
       
   319 	    iEngineFactoryInstance->GetServiceEnginePtr(engines);      
       
   320 	    TRACE("CreateServicesL() engines.Count(): %d", engines.Count());
       
   321     // iterate the service array
       
   322     for ( TInt index = 0; index < engines.Count() ; index++ )        
       
   323         {
       
   324         //ServiceId is used to create unique view id for each service, to avoid the reuse of view id of existing service to newly installed service
       
   325         TInt ServiceId = engines[index]->ServiceId();
       
   326         iEngine->AddNewClientL( ServiceId, *engines[index], 
       
   327                 ( KVIMPSTTabbedViewIdBase + ServiceId ), ( KVIMPSTSearchViewIdBase + ServiceId), (KVIMPSTBlockedViewIdBase +ServiceId ), *iMenuExtension);
       
   328         }
       
   329     
       
   330     engines.Reset();
       
   331     engines.Close();
       
   332 	    }
       
   333   
       
   334     }	
       
   335 	
       
   336 // ---------------------------------------------------------------------------
       
   337 // CVIMPSTUiExtensionFactory::IsSearchId()
       
   338 // ---------------------------------------------------------------------------
       
   339 //  
       
   340 TBool CVIMPSTUiExtensionFactory::IsSearchId( TUint aId )
       
   341     {
       
   342     return ( aId >= KVIMPSTSearchViewIdBase && aId<KVIMPSTBlockedViewIdBase);
       
   343     }
       
   344     
       
   345 // ---------------------------------------------------------------------------
       
   346 // CVIMPSTUiExtensionFactory::IsSearchId()
       
   347 // ---------------------------------------------------------------------------
       
   348 //  
       
   349 TBool CVIMPSTUiExtensionFactory::IsBlockeId( TUint aId )
       
   350     {
       
   351     return ( aId >= KVIMPSTBlockedViewIdBase );
       
   352     }
       
   353     
       
   354 // ---------------------------------------------------------------------------
       
   355 // CVIMPSTUiExtensionFactory::IsTabbedId()
       
   356 // ---------------------------------------------------------------------------
       
   357 //  
       
   358 TBool CVIMPSTUiExtensionFactory::IsTabbedId( TUint aId )
       
   359     {
       
   360     return ( aId >= KVIMPSTTabbedViewIdBase && aId < KVIMPSTSearchViewIdBase );
       
   361     }
       
   362 	
       
   363 //  End of File