imstutils/imconversationview/imcvuiapp/src/cimcvmenuextensionmanager.cpp
changeset 0 5e5d6b214f4f
child 14 6b620215f837
equal deleted inserted replaced
-1:000000000000 0:5e5d6b214f4f
       
     1 /*
       
     2 * Copyright (c) 2007-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:   Class that provides centralized access for UI classes 
       
    15 *                to logic handling
       
    16 *
       
    17 */
       
    18 
       
    19 // INCLUDE FILES
       
    20 
       
    21 #include <eikenv.h>
       
    22 #include <coeaui.h>
       
    23 #include <coemain.h>
       
    24 #include <barsread.h>
       
    25 #include <eikmenup.h> 
       
    26 
       
    27 
       
    28 #include "cimcvmenuextensionmanager.h"
       
    29 #include "cimcvcommandinfo.h"
       
    30 
       
    31 #include "cvmenucommandinfo.hrh"
       
    32 
       
    33 
       
    34 // ================= MEMBER FUNCTIONS =======================
       
    35 
       
    36 // ---------------------------------------------------------------------------
       
    37 // CIMCVMenuExtensionManager::CIMCVMenuExtensionManager
       
    38 // ---------------------------------------------------------------------------
       
    39 // 
       
    40 CIMCVMenuExtensionManager::CIMCVMenuExtensionManager( )
       
    41 : iNewCommands( ECVMenuExtensionFirstFreeCommand )
       
    42     {
       
    43 
       
    44     }
       
    45 
       
    46 // ---------------------------------------------------------------------------
       
    47 // CIMCVMenuExtensionManager::ConstructL
       
    48 // ---------------------------------------------------------------------------
       
    49 // 
       
    50 void CIMCVMenuExtensionManager::ConstructL()
       
    51     {   
       
    52     LoadPluginL( ); 
       
    53     }
       
    54 
       
    55 // ---------------------------------------------------------------------------
       
    56 // CIMCVMenuExtensionManager::NewL
       
    57 // ---------------------------------------------------------------------------
       
    58 // 
       
    59 CIMCVMenuExtensionManager* CIMCVMenuExtensionManager::NewL( )
       
    60     { 
       
    61     CIMCVMenuExtensionManager* self = NewLC(  );
       
    62     CleanupStack::Pop(self);
       
    63     return self;
       
    64     }
       
    65 
       
    66 // ---------------------------------------------------------------------------
       
    67 // CIMCVMenuExtensionManager::NewLC
       
    68 // ---------------------------------------------------------------------------
       
    69 // 
       
    70 CIMCVMenuExtensionManager* CIMCVMenuExtensionManager::NewLC()
       
    71     {
       
    72     CIMCVMenuExtensionManager* self =
       
    73         new (ELeave) CIMCVMenuExtensionManager(  );
       
    74     CleanupStack::PushL( self );
       
    75     self->ConstructL();
       
    76     return self;
       
    77     }
       
    78 
       
    79 // ---------------------------------------------------------------------------
       
    80 // CIMCVMenuExtensionManager::~CIMCVMenuExtensionManager
       
    81 // ---------------------------------------------------------------------------
       
    82 // 
       
    83 CIMCVMenuExtensionManager::~CIMCVMenuExtensionManager()
       
    84     {   
       
    85     iCommandIdMap.ResetAndDestroy();
       
    86     iCommandIdMap.Close();
       
    87     // Reset and destroy the contents of the owned arrays,
       
    88     // this will delete the plugins.
       
    89     iPlugins.ResetAndDestroy();
       
    90     iPlugins.Close();
       
    91     
       
    92     // Close the ECOM interface
       
    93     REComSession::FinalClose();
       
    94     }
       
    95  
       
    96 // ----------------------------------------------------------------------------
       
    97 // CIMCVMenuExtensionManager::LoadPluginL
       
    98 // Loads all plugins
       
    99 // (other items were commented in a header).
       
   100 // ----------------------------------------------------------------------------
       
   101 //
       
   102 void CIMCVMenuExtensionManager::LoadPluginL( )
       
   103     {
       
   104     // plugininfo array, Owned
       
   105     RImplInfoPtrArray pluginInfo;
       
   106     iPlugins.ResetAndDestroy();
       
   107     REComSession::ListImplementationsL( KMenuCustomisationInterfaceUid,pluginInfo );
       
   108     TInt pluginCount = pluginInfo.Count();
       
   109     
       
   110     for ( TInt pluginIndex(0); pluginIndex < pluginCount; ++pluginIndex )
       
   111         {
       
   112         TUid pluginUid = pluginInfo[pluginIndex]->ImplementationUid();
       
   113         // Creates the plugin and transfers ownership of the services
       
   114         // object to the plugin.
       
   115         CIMCVMenuExtension* plugin = NULL;
       
   116         TRAPD(error, plugin = CIMCVMenuExtension::CreateImplementationL( pluginUid ));
       
   117         
       
   118         if(KErrNone != error)
       
   119             {
       
   120             // handle the error here.
       
   121             }
       
   122         else
       
   123             {
       
   124             //if its here its sure that plugin is not null;
       
   125             CleanupStack::PushL( plugin);
       
   126             
       
   127             //map the plugin commands to CV commands,
       
   128             //assings the command maintained in the commandpool,
       
   129             //for more details see 
       
   130             MapCommandL(*plugin,pluginUid.iUid);
       
   131             
       
   132             //add the plugin to the array
       
   133             CPluginInfo* newPlugin = new ( ELeave ) CIMCVMenuExtensionManager::CPluginInfo( plugin, pluginUid);    
       
   134             CleanupStack::PushL( newPlugin );
       
   135             iPlugins.AppendL( newPlugin );
       
   136             CleanupStack::Pop( newPlugin );
       
   137            
       
   138             CleanupStack::Pop( plugin );
       
   139            }
       
   140         
       
   141         }
       
   142     pluginInfo.ResetAndDestroy();
       
   143     pluginInfo.Close();
       
   144     }
       
   145 
       
   146 
       
   147 // ----------------------------------------------------------------------------
       
   148 // CIMCVMenuExtensionManager::OfferMenuPaneToPluginsL
       
   149 // Generates the list of active plugins
       
   150 // ----------------------------------------------------------------------------
       
   151 //
       
   152 void CIMCVMenuExtensionManager::OfferMenuPaneToPlugins(TInt aPreviousId, CEikMenuPane& aMenuPane,TUint aServiceId)
       
   153     {
       
   154     // Get the number of  plugins
       
   155     const TInt count = iPlugins.Count();
       
   156     // Loop though all the command handlers, If DynInitMenuPaneL leaves for one plugin, a plugin
       
   157     // error message will be displayed and the loop will continue with
       
   158     // the next command handler. If none of the plugins leave, there will
       
   159     // be only one TRAP used.
       
   160     for ( TInt index = 0; index < count; ++index )
       
   161         {
       
   162         //trap is required if one plugin leaves then it should continue with other plugins.
       
   163         TRAPD(error,iPlugins[index]->Plugin().DynInitMenuPaneL( aPreviousId,
       
   164                                                              aMenuPane,aServiceId ));
       
   165         if(KErrNone != error)
       
   166             {
       
   167             //display the appropriate error note for leaving;
       
   168             }
       
   169       
       
   170         }
       
   171     
       
   172     }
       
   173 // ----------------------------------------------------------------------------
       
   174 // CIMCVMenuExtensionManager::OfferHandleCommandToPluginsL
       
   175 // Generates the list of active plugins
       
   176 // ----------------------------------------------------------------------------
       
   177 //
       
   178 TBool CIMCVMenuExtensionManager::OfferHandleCommandToPlugins(TInt aCommandId)
       
   179     {
       
   180      //Get the number of plugins loaded
       
   181      const TInt count = iPlugins.Count();
       
   182      
       
   183      TBool retval = EFalse;
       
   184      // Loop though all the command handlers, 
       
   185      // If HandleCommandL leaves for one plugin, a plugin
       
   186      // error message will be displayed and the loop will continue with
       
   187      // the next plugin. If none of the plugins leave, there will
       
   188      // be only one TRAP used.
       
   189      for ( TInt index = 0; index < count; ++index )
       
   190          {
       
   191          TRAPD( error,retval = iPlugins[index]->Plugin().HandleCommandL( aCommandId ));
       
   192              
       
   193          if ( KErrNone != error )
       
   194              {
       
   195              // Report a problem with plugin.
       
   196              }
       
   197          }
       
   198      return retval;
       
   199     }
       
   200 
       
   201 // ----------------------------------------------------------------------------
       
   202 // CIMCVMenuExtensionManager::CPluginInfo::CPluginInfo(
       
   203 // C++ constructor
       
   204 // (other items were commented in a header).
       
   205 // ----------------------------------------------------------------------------
       
   206 //
       
   207 CIMCVMenuExtensionManager::CPluginInfo::CPluginInfo( 
       
   208         CIMCVMenuExtension* aPlugin,
       
   209         TUid aPluginUid )
       
   210 : iPlugin( aPlugin ),
       
   211 iPluginUid( aPluginUid )
       
   212             {
       
   213 
       
   214             }
       
   215 // ----------------------------------------------------------------------------
       
   216 // CIMCVMenuExtensionManager::CPluginInfo::~CPluginInfo(
       
   217 // C++ destructor
       
   218 // (other items were commented in a header).
       
   219 // ----------------------------------------------------------------------------
       
   220 //
       
   221 
       
   222 CIMCVMenuExtensionManager::CPluginInfo::~CPluginInfo() 
       
   223     {
       
   224     delete iPlugin;
       
   225     }
       
   226     
       
   227 // ----------------------------------------------------------------------------
       
   228 // CIMCVMenuExtensionManager::CPluginInfo::Plugin
       
   229 // returns a reference to the plugin
       
   230 // (other items were commented in a header).
       
   231 // ----------------------------------------------------------------------------
       
   232 //
       
   233 CIMCVMenuExtension& CIMCVMenuExtensionManager::CPluginInfo::Plugin()
       
   234     {
       
   235      return *iPlugin;
       
   236     }
       
   237 
       
   238 
       
   239 // ----------------------------------------------------------------------------
       
   240 // CIMCVMenuExtensionManager::MapCommandL
       
   241 // (other items were commented in a header).
       
   242 // ----------------------------------------------------------------------------
       
   243 // 
       
   244 void CIMCVMenuExtensionManager::MapCommandL( CIMCVMenuExtension& aMenuExtension, TInt32  aPluginId )
       
   245     { 
       
   246     TInt res = aMenuExtension.CommandInfoResource();
       
   247     if( res != KErrNotFound )
       
   248         {
       
   249         TResourceReader reader;
       
   250         CCoeEnv::Static()->CreateResourceReaderLC( reader, res );
       
   251         TInt resCount = reader.ReadInt16();
       
   252         for( TInt j = 0; j < resCount; j++ )
       
   253             {
       
   254             CIMCVCommandInfo* commandInfo = NULL;
       
   255             commandInfo = CIMCVCommandInfo::NewLC( reader,
       
   256                                                 aPluginId,
       
   257                                                 iNewCommands );
       
   258             User::LeaveIfError( iCommandIdMap.Append( commandInfo ) );
       
   259             CleanupStack::Pop(); // commandInfo
       
   260             }
       
   261         CleanupStack::PopAndDestroy(); // reader                        
       
   262         aMenuExtension.RegisterCommandMapper( *this );
       
   263        
       
   264         }
       
   265     }
       
   266 // ----------------------------------------------------------------------------
       
   267 // CIMCVMenuExtensionManager::GetNewCommand
       
   268 // from MComandMapper
       
   269 // ----------------------------------------------------------------------------
       
   270 //
       
   271 
       
   272 TInt CIMCVMenuExtensionManager::GetOldCommand( TInt32 aPluginId, TInt aNewCommand,
       
   273                                     TInt& aOldCommand ) const
       
   274     {
       
   275     TInt mapCount = iCommandIdMap.Count();
       
   276     TInt err( KErrNotFound );
       
   277     for( TInt i = 0; i < mapCount && err; i++ )
       
   278         {
       
   279         CIMCVCommandInfo* info = iCommandIdMap[i];
       
   280         if( info->PluginId() == aPluginId && info->NewCommandId() == aNewCommand )
       
   281             {
       
   282             aOldCommand = info->OldCommandId();
       
   283             err = KErrNone;
       
   284             break;
       
   285             }
       
   286         }  
       
   287         return err;
       
   288     }
       
   289 // ----------------------------------------------------------------------------
       
   290 // CIMCVMenuExtensionManager::GetNewCommand
       
   291 // from MComandMapper
       
   292 // ----------------------------------------------------------------------------
       
   293 //
       
   294     
       
   295 TInt CIMCVMenuExtensionManager::GetNewCommand( TInt32 aPluginId, TInt aOldCommand,
       
   296                                     TInt& aNewCommand ) const
       
   297     {
       
   298     TInt mapCount = iCommandIdMap.Count();
       
   299     TInt err( KErrNotFound );
       
   300     
       
   301     for( TInt i = 0; i < mapCount && err; i++ )
       
   302         {
       
   303         CIMCVCommandInfo* info = iCommandIdMap[i];
       
   304         if( info->PluginId() == aPluginId && info->OldCommandId() == aOldCommand )
       
   305             {
       
   306             aNewCommand = info->NewCommandId();
       
   307             err = KErrNone;
       
   308             break;
       
   309             }
       
   310         }   
       
   311     
       
   312     return err; 
       
   313     }
       
   314 
       
   315 
       
   316 // End of file