phonebookui/Phonebook2/Commands/src/CPbk2CommandFactory.cpp
changeset 0 e686773b3f54
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 /*
       
     2 * Copyright (c) 2005-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:  Creates Phonebook 2 command objects.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "CPbk2CommandFactory.h"
       
    21 
       
    22 // Phonebook 2
       
    23 #include <CPbk2UIExtensionManager.h>
       
    24 #include <MPbk2UIExtensionFactory.h>
       
    25 #include <cpbk2commandactivator.h>
       
    26 
       
    27 // include command handlers
       
    28 #include "CPbk2SetToneCmd.h"
       
    29 #include "cpbk2activatecntinfoviewcmd.h"
       
    30 
       
    31 /// Unnamed namespace for local definitions
       
    32 namespace {
       
    33 
       
    34 typedef MPbk2Command* (CPbk2CommandFactory::*CommandCreationFunction)
       
    35     (MPbk2ContactUiControl&) const;
       
    36 
       
    37 /// mapping table entries
       
    38 struct TPbk2CommandIdMapping
       
    39     {
       
    40     /// Phonebook2 command id
       
    41     TPbk2CommandId iCommandId; 
       
    42     /// command handler factory function
       
    43     CommandCreationFunction iCreationFunctionL; 
       
    44     };
       
    45 
       
    46 /// mapping table contains Phonebook2 command id's and function pointers to 
       
    47 /// command handlers
       
    48 static const TPbk2CommandIdMapping CommandIdMapping[] =
       
    49     {
       
    50     {EPbk2CmdPersonalRingingTone,
       
    51         &CPbk2CommandFactory::CreateSetToneCommandL},
       
    52     {EPbk2CmdOpenMeViews,
       
    53         &CPbk2CommandFactory::CreateActivateCntInfoViewCommandL},
       
    54     {EPbk2CmdLast,
       
    55         NULL}
       
    56     };
       
    57 
       
    58 } /// namespace
       
    59 
       
    60 
       
    61 // ================= MEMBER FUNCTIONS =======================
       
    62 
       
    63 inline CPbk2CommandFactory::CPbk2CommandFactory()
       
    64     {
       
    65     }
       
    66 
       
    67 inline void CPbk2CommandFactory::ConstructL()
       
    68     {
       
    69     iExtensionManager = CPbk2UIExtensionManager::InstanceL();
       
    70     }
       
    71 
       
    72 CPbk2CommandFactory* CPbk2CommandFactory::NewL()
       
    73     {
       
    74     CPbk2CommandFactory* self = new (ELeave) CPbk2CommandFactory;
       
    75     CleanupStack::PushL(self);
       
    76     self->ConstructL();
       
    77     CleanupStack::Pop(self);
       
    78     return self;
       
    79     }
       
    80 
       
    81 CPbk2CommandFactory::~CPbk2CommandFactory()
       
    82     {
       
    83     Release(iExtensionManager);
       
    84     }
       
    85 
       
    86 MPbk2Command* CPbk2CommandFactory::CreateCommandForIdL(
       
    87         TPbk2CommandId aCommandId,
       
    88         MPbk2ContactUiControl& aUiControl) const
       
    89     {
       
    90     MPbk2Command* cmd = iExtensionManager->FactoryL()->
       
    91             CreatePbk2CommandForIdL(aCommandId, aUiControl);
       
    92     if (!cmd)
       
    93         {
       
    94         // search mapping table for command handler
       
    95         for (TInt i = 0; CommandIdMapping[i].iCommandId != EPbk2CmdLast; ++i)
       
    96             {
       
    97             if (CommandIdMapping[i].iCommandId == aCommandId)
       
    98                 {
       
    99                 // command id handler found, create command object
       
   100                 // through mapping table function pointer
       
   101                 cmd = (this->*CommandIdMapping[i].iCreationFunctionL)(aUiControl);
       
   102                 break;
       
   103                 }
       
   104             }
       
   105         }
       
   106 
       
   107     if ( cmd )
       
   108         {
       
   109         // activator takes control of created command
       
   110         MPbk2Command* activator = 
       
   111             CPbk2CommandActivator::NewL( cmd, aUiControl );
       
   112         cmd = activator;
       
   113         }
       
   114 
       
   115     return cmd;
       
   116     }
       
   117 
       
   118 MPbk2Command* CPbk2CommandFactory::CreateSetToneCommandL(
       
   119         MPbk2ContactUiControl& aUiControl) const
       
   120     {
       
   121     return CPbk2SetToneCmd::NewL(aUiControl);
       
   122     }
       
   123 
       
   124 MPbk2Command* CPbk2CommandFactory::CreateActivateCntInfoViewCommandL(
       
   125             MPbk2ContactUiControl& aUiControl) const
       
   126     {
       
   127     return CPbk2ActivateCntInfoViewCmd::NewL(aUiControl);
       
   128     }
       
   129 
       
   130 // End of File
       
   131