1 /* |
|
2 * Copyright (c) 2010 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 cntexampleactionsplugin |
|
19 #endif |
|
20 #ifndef ACTIONFACTORYPLUGINNAME |
|
21 #define ACTIONFACTORYPLUGINNAME SymbianActionFactory |
|
22 #endif |
|
23 |
|
24 #include "cntexampleactionfactory.h" |
|
25 #include "cntexampleaction.h" |
|
26 #include "cntexample2action.h" |
|
27 #include "cntexamplenodetailaction.h" |
|
28 #include "cntexampledynamicaction.h" |
|
29 |
|
30 #include <qcontactonlineaccount.h> |
|
31 #include <qcontactdetailfilter.h> |
|
32 |
|
33 #define makestr(x) (#x) |
|
34 #define makename(x) makestr(x) |
|
35 |
|
36 |
|
37 //Factory class |
|
38 MobExampleActionFactory::MobExampleActionFactory() |
|
39 { |
|
40 // Next two actions are different, but for same service. These actions can be used |
|
41 // also for other services, by changing "Test service". In real plugin all these actions |
|
42 // would have been created once for each service. In this example third action is created for |
|
43 // different service for testing purposes. |
|
44 actionList.append(new MobExampleAction("staticaction1", "Test service")); |
|
45 actionList.append(new MobExample2Action("staticaction2", "Test service")); |
|
46 // This action is for second service. |
|
47 actionList.append(new MobExampleNoDetailAction("nodetailaction", "Test service 2")); |
|
48 |
|
49 // create several variants of one action and change it behaviour in run time |
|
50 MobExampleDynamicAction* nonUiItem = new MobExampleDynamicAction("dynamicaction", "Test service 2"); |
|
51 nonUiItem->setDefinitionName(QContactOnlineAccount::DefinitionName); |
|
52 QContactDetailFilter filter; |
|
53 filter.setDetailDefinitionName(QContactOnlineAccount::DefinitionName); |
|
54 nonUiItem->setFilter(filter); |
|
55 nonUiItem->setIcon(QIcon()); |
|
56 nonUiItem->setTitleField(""); |
|
57 nonUiItem->setTitleFieldDetail(""); |
|
58 actionList.append(nonUiItem); |
|
59 |
|
60 MobExampleDynamicAction* emptyValueField = new MobExampleDynamicAction("dynamicaction2", "Test service 2"); |
|
61 emptyValueField->setDefinitionName(QContactOnlineAccount::DefinitionName); |
|
62 QContactDetailFilter filter2; |
|
63 filter2.setDetailDefinitionName(QContactOnlineAccount::DefinitionName); |
|
64 emptyValueField->setFilter(filter2); |
|
65 emptyValueField->setIcon(QIcon()); |
|
66 emptyValueField->setTitleFieldDetail(QContactOnlineAccount::FieldServiceProvider); |
|
67 emptyValueField->setValueField(""); |
|
68 actionList.append(emptyValueField); |
|
69 } |
|
70 |
|
71 MobExampleActionFactory::~MobExampleActionFactory() |
|
72 { |
|
73 while (!actionList.isEmpty()) |
|
74 delete actionList.takeFirst(); |
|
75 } |
|
76 |
|
77 QString MobExampleActionFactory::name() const |
|
78 { |
|
79 return QString(makename(ACTIONFACTORYPLUGINNAME)); |
|
80 } |
|
81 |
|
82 |
|
83 QList<QContactActionDescriptor> MobExampleActionFactory::actionDescriptors() const |
|
84 { |
|
85 QList<QContactActionDescriptor> descriptorList; |
|
86 |
|
87 //loop through all the actions and add the descriptor to the list |
|
88 for (int i = 0; i < actionList.size(); i++) |
|
89 { |
|
90 descriptorList << actionList.at(i)->actionDescriptor(); |
|
91 } |
|
92 |
|
93 return descriptorList; |
|
94 } |
|
95 |
|
96 QContactAction* MobExampleActionFactory::instance(const QContactActionDescriptor& descriptor) const |
|
97 { |
|
98 QContactAction *action(0); |
|
99 |
|
100 //loop through the actions and return the one that supports the descriptor |
|
101 for (int i = 0; i < actionList.size() && action == 0; i++) |
|
102 { |
|
103 if (actionList.at(i)->actionDescriptionSupported(descriptor)){ |
|
104 //create a new heap object of the action |
|
105 action = actionList.at(i)->clone(); |
|
106 } |
|
107 } |
|
108 |
|
109 return action; |
|
110 } |
|
111 |
|
112 QVariantMap MobExampleActionFactory::actionMetadata(const QContactActionDescriptor& descriptor) const |
|
113 { |
|
114 QVariantMap map; |
|
115 |
|
116 //loop through the actions and return the one that supports the descriptor |
|
117 for (int i = 0; i < actionList.size() && map.isEmpty(); i++) |
|
118 { |
|
119 if (actionList.at(i)->actionDescriptionSupported(descriptor)) |
|
120 { |
|
121 map = actionList.at(i)->metaData(); |
|
122 } |
|
123 } |
|
124 |
|
125 return map; |
|
126 |
|
127 } |
|
128 |
|
129 Q_EXPORT_PLUGIN2(ACTIONFACTORYPLUGINTARGET, MobExampleActionFactory); |
|