|
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 |
|
18 |
|
19 #include <QPluginLoader> |
|
20 #include <hbdataformmodel.h> |
|
21 #include <cpplugininterface.h> |
|
22 #include <cpsettingformitemdata.h> |
|
23 #include <cpitemdatahelper.h> |
|
24 #include <cppluginutility.h> |
|
25 #include <cppluginloader.h> |
|
26 #include "cptelephonypluginview.h" |
|
27 #include "cppluginlogging.h" |
|
28 |
|
29 /*! |
|
30 \class CpTelephonyPluginView |
|
31 \brief The class CpTelephonyPluginView |
|
32 loads child setting plugins contained |
|
33 in "Telephony" view. |
|
34 */ |
|
35 |
|
36 // Local constants |
|
37 const char* PLUGIN_NAME_CALLSPLUGIN = "cpcallsplugin"; |
|
38 const char* PLUGIN_NAME_VMBXPLUGIN = "vmbxcpplugin"; |
|
39 const char* PLUGIN_NAME_DIVERTPLUGIN = "cpdivertplugin"; |
|
40 const char* PLUGIN_NAME_BARRINGPLUGIN = "cpbarringplugin"; |
|
41 |
|
42 /*! |
|
43 Constructor. |
|
44 */ |
|
45 CpTelephonyPluginView::CpTelephonyPluginView() : |
|
46 CpBaseSettingView(0,0), |
|
47 m_helper(NULL) |
|
48 { |
|
49 DPRINT << ": IN"; |
|
50 |
|
51 HbDataForm *form = qobject_cast<HbDataForm*>(widget()); |
|
52 if (form) { |
|
53 HbDataFormModel *model = new HbDataFormModel(form); |
|
54 form->setHeading(hbTrId("txt_phone_subhead_telephone")); |
|
55 // Create and initialize plugin's item data helper |
|
56 m_helper = initializeItemDataHelper(); |
|
57 QList<CpSettingFormItemData*> items; |
|
58 |
|
59 DPRINT << ": Loading cpcallsplugin"; |
|
60 items.append(groupItemFromPlugin( |
|
61 PLUGIN_NAME_CALLSPLUGIN)); |
|
62 CpSettingFormItemData* expandedItem = items.last(); |
|
63 |
|
64 DPRINT << ": Loading vmbxcpplugin"; |
|
65 items.append(groupItemFromPlugin( |
|
66 PLUGIN_NAME_VMBXPLUGIN)); |
|
67 |
|
68 DPRINT << ": Loading cpdivertsplugin"; |
|
69 items.append(groupItemFromPlugin( |
|
70 PLUGIN_NAME_DIVERTPLUGIN)); |
|
71 |
|
72 DPRINT << ": Loading cpbarringplugin"; |
|
73 items.append(groupItemFromPlugin( |
|
74 PLUGIN_NAME_BARRINGPLUGIN)); |
|
75 |
|
76 // Insert items to form model |
|
77 foreach (CpSettingFormItemData* i, items) { |
|
78 model->appendDataFormItem(i); |
|
79 } |
|
80 |
|
81 form->setModel(model); |
|
82 |
|
83 if (expandedItem) { |
|
84 QModelIndex expandedItemIndex = model->indexFromItem(expandedItem); |
|
85 |
|
86 if (expandedItemIndex.isValid()) { |
|
87 form->setExpanded(expandedItemIndex, true); |
|
88 } |
|
89 } |
|
90 } |
|
91 |
|
92 DPRINT << ": OUT"; |
|
93 } |
|
94 |
|
95 /*! |
|
96 Constructor with param list. |
|
97 */ |
|
98 CpTelephonyPluginView::CpTelephonyPluginView(const QVariantList ¶ms) : |
|
99 CpBaseSettingView(0,0), |
|
100 m_helper(NULL) |
|
101 { |
|
102 HbDataForm *form = qobject_cast<HbDataForm*>(widget()); |
|
103 if (form){ |
|
104 HbDataFormModel *model = new HbDataFormModel; |
|
105 form->setHeading(hbTrId("txt_phone_subhead_telephone")); |
|
106 m_helper = initializeItemDataHelper(); |
|
107 QList<CpSettingFormItemData*> items; |
|
108 TBool expanded(false); |
|
109 CpSettingFormItemData* expandedItem(NULL); |
|
110 foreach (QVariant var, params){ |
|
111 items.append(groupItemFromPlugin(var.toString())); |
|
112 if(!expanded){ |
|
113 expandedItem = items.last(); |
|
114 expanded = true; |
|
115 } |
|
116 } |
|
117 // Insert items to form model |
|
118 foreach (CpSettingFormItemData* i, items) { |
|
119 model->appendDataFormItem(i); |
|
120 } |
|
121 form->setModel(model); |
|
122 if (expandedItem) { |
|
123 QModelIndex expandedItemIndex = model->indexFromItem(expandedItem); |
|
124 |
|
125 if (expandedItemIndex.isValid()) { |
|
126 form->setExpanded(expandedItemIndex, true); |
|
127 } |
|
128 } |
|
129 } |
|
130 } |
|
131 |
|
132 /*! |
|
133 Destructor. |
|
134 */ |
|
135 CpTelephonyPluginView::~CpTelephonyPluginView() |
|
136 { |
|
137 DPRINT << ": IN"; |
|
138 qDeleteAll(m_plugins); |
|
139 delete m_helper; |
|
140 DPRINT << ": OUT"; |
|
141 } |
|
142 |
|
143 /*! |
|
144 Load group item for given plugin name. |
|
145 */ |
|
146 QList<CpSettingFormItemData*> CpTelephonyPluginView::groupItemFromPlugin( |
|
147 const QString& plugin) |
|
148 { |
|
149 DPRINT << ": IN"; |
|
150 |
|
151 QList<CpSettingFormItemData*> items; |
|
152 CpPluginInterface *p(NULL); |
|
153 try { |
|
154 p = CpPluginLoader::loadCpPluginInterface(plugin); |
|
155 if (p && m_helper) { |
|
156 m_plugins.append(p); |
|
157 items = p->createSettingFormItemData(*m_helper); |
|
158 } |
|
159 } catch(...) { |
|
160 DCRITICAL << ": CATCH ERROR, item creation failed!"; |
|
161 delete p; |
|
162 } |
|
163 |
|
164 DPRINT << ": OUT"; |
|
165 return items; |
|
166 } |
|
167 |
|
168 /*! |
|
169 Item data helper initialization. |
|
170 */ |
|
171 CpItemDataHelper* CpTelephonyPluginView::initializeItemDataHelper() |
|
172 { |
|
173 DPRINT; |
|
174 return new CpItemDataHelper(qobject_cast<HbDataForm*>(widget())); |
|
175 } |
|
176 |
|
177 // End of File. |