phonebookengines/cntactions/src/cntactionfactory.cpp
changeset 40 b46a585f6909
equal deleted inserted replaced
37:fd64c38c277d 40:b46a585f6909
       
     1 /*
       
     2 * Copyright (c) 2009 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:
       
    15 *
       
    16 */
       
    17 #ifndef ACTIONFACTORYPLUGINTARGET
       
    18 #define ACTIONFACTORYPLUGINTARGET cntactionplugin
       
    19 #endif
       
    20 #ifndef ACTIONFACTORYPLUGINNAME
       
    21 #define ACTIONFACTORYPLUGINNAME SymbianActionFactory
       
    22 #endif
       
    23 
       
    24 #include "cntactionfactory.h"
       
    25 #include "cntcallaction.h"
       
    26 #include "cntvideocallaction.h"
       
    27 #include "cntmessageaction.h"
       
    28 #include "cntemailaction.h"
       
    29 #include "cntbrowseraction.h"
       
    30 
       
    31 #define makestr(x) (#x)
       
    32 #define makename(x) makestr(x)
       
    33 
       
    34 
       
    35 //Factory class
       
    36 CntActionFactory::CntActionFactory() 
       
    37 {
       
    38 	actionList.append(new CntCallAction());
       
    39 	actionList.append(new CntVideoCallAction());
       
    40     actionList.append(new CntMessageAction());
       
    41     actionList.append(new CntEmailAction());
       
    42     actionList.append(new CntBrowserAction());
       
    43 }
       
    44 
       
    45 CntActionFactory::~CntActionFactory()
       
    46 {
       
    47 	 while (!actionList.isEmpty())
       
    48 	     delete actionList.takeFirst();
       
    49 }
       
    50 
       
    51 QString CntActionFactory::name() const
       
    52 {
       
    53     return QString(makename(ACTIONFACTORYPLUGINNAME));
       
    54 }
       
    55 
       
    56 
       
    57 QList<QContactActionDescriptor> CntActionFactory::actionDescriptors() const
       
    58 {
       
    59    QList<QContactActionDescriptor> descriptorList; 
       
    60    
       
    61    //loop through all the actions and add the descriptor to the list
       
    62    for (int i = 0; i < actionList.size(); i++)
       
    63    {
       
    64 	   descriptorList << actionList.at(i)->actionDescriptor();   
       
    65    }
       
    66    
       
    67    return descriptorList;
       
    68 }
       
    69 
       
    70 QContactAction* CntActionFactory::instance(const QContactActionDescriptor& descriptor) const
       
    71 {
       
    72     QContactAction *action(0);
       
    73 	
       
    74     //loop through the actions and return the one that supports the descriptor
       
    75     for (int i = 0; i < actionList.size() && action == 0; i++)
       
    76     {
       
    77     	if (actionList.at(i)->actionDescriptionSupported(descriptor)){
       
    78     		//create a new heap object of the action
       
    79     		action = actionList.at(i)->clone();
       
    80     	}    
       
    81     }
       
    82   
       
    83     return action;
       
    84 }
       
    85 
       
    86 QVariantMap CntActionFactory::actionMetadata(const QContactActionDescriptor& descriptor) const
       
    87 {
       
    88     Q_UNUSED(descriptor);
       
    89     
       
    90     return QVariantMap();
       
    91 }
       
    92 
       
    93 Q_EXPORT_PLUGIN2(ACTIONFACTORYPLUGINTARGET, CntActionFactory);