|
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 #include "cptelephonypluginview.h" |
|
19 #include "cpplugincommon.h" |
|
20 #include "cppluginlogging.h" |
|
21 #include <QPluginLoader> |
|
22 #include <QApplication> |
|
23 #include <QLocale> |
|
24 #include <QTranslator> |
|
25 #include <hbdataformmodel.h> |
|
26 #include <cppluginplatinterface.h> |
|
27 #include <cpsettingformitemdata.h> |
|
28 #include <cpitemdatahelper.h> |
|
29 |
|
30 CpTelephonyPluginView::CpTelephonyPluginView() : |
|
31 CpBaseSettingView(), |
|
32 m_helper(NULL) |
|
33 { |
|
34 DPRINT << ": IN"; |
|
35 |
|
36 // Localization file loading |
|
37 QTranslator translator; |
|
38 QString lang = QLocale::system().name(); |
|
39 QString path = "z:/resource/qt/translations/"; |
|
40 DPRINT << ": loading translation: " << QString(path + "telephone_cp_" + lang); |
|
41 bool translatorLoaded = translator.load(path + "telephone_cp_" + lang); |
|
42 DPRINT << ": translator loaded: " << translatorLoaded; |
|
43 if (translatorLoaded) { |
|
44 qApp->installTranslator(&translator); |
|
45 DPRINT << ": translator installed"; |
|
46 } |
|
47 |
|
48 HbDataForm *form = settingForm(); |
|
49 if (form) { |
|
50 HbDataFormModel *model = new HbDataFormModel; |
|
51 form->setHeading(hbTrId("Telephone settings")); |
|
52 // Create and initialize plugin's item data helper |
|
53 m_helper = initializeItemDataHelper(); |
|
54 HbDataFormModelItem *item(NULL); |
|
55 |
|
56 DPRINT << ": Loading cpcallsplugin"; |
|
57 // Load calls plugin |
|
58 item = groupItemFromPlugin("cpcallsplugin"); |
|
59 if (item) { |
|
60 model->appendDataFormItem(item); |
|
61 } |
|
62 |
|
63 // Load diverts plugin |
|
64 DPRINT << ": Loading cpdivertsplugin"; |
|
65 item = groupItemFromPlugin("cpdivertplugin"); |
|
66 if (item) { |
|
67 model->appendDataFormItem(item); |
|
68 } |
|
69 |
|
70 // Load call mailboxes plugin |
|
71 DPRINT << ": Loading vmbxcpplugin"; |
|
72 item = groupItemFromPlugin("vmbxcpplugin"); |
|
73 if (item) { |
|
74 model->appendDataFormItem(item); |
|
75 } |
|
76 |
|
77 form->setModel(model); |
|
78 } |
|
79 |
|
80 DPRINT << ": OUT"; |
|
81 } |
|
82 |
|
83 CpTelephonyPluginView::~CpTelephonyPluginView() |
|
84 { |
|
85 DPRINT << ": IN"; |
|
86 |
|
87 delete m_helper; |
|
88 |
|
89 DPRINT << ": OUT"; |
|
90 } |
|
91 |
|
92 HbDataFormModelItem* CpTelephonyPluginView::groupItemFromPlugin( const QString& plugin ) |
|
93 { |
|
94 DPRINT << ": IN"; |
|
95 |
|
96 CpSettingFormItemData *item(NULL); |
|
97 CpPluginPlatInterface *p(NULL); |
|
98 try { |
|
99 p = Tools::loadCpPlugin(plugin); |
|
100 if (p && m_helper){ |
|
101 item = p->createSettingFormItemData(*m_helper); |
|
102 if (item){ |
|
103 item->setType(HbDataFormModelItem::GroupItem); |
|
104 QObject::connect( |
|
105 settingForm(), SIGNAL(itemShown(QModelIndex)), |
|
106 item, SLOT(itemShown(QModelIndex))); |
|
107 DPRINT << "plugin:" << plugin; |
|
108 } |
|
109 } |
|
110 } catch(...) { |
|
111 DPRINT << "CATCH ERROR"; |
|
112 delete p; |
|
113 } |
|
114 |
|
115 DPRINT << ": OUT"; |
|
116 return item; |
|
117 } |
|
118 |
|
119 void CpTelephonyPluginView::onConnectionAdded(HbDataFormModelItem *item, |
|
120 const QString &signal, |
|
121 QObject *receiver, |
|
122 const QString &method) |
|
123 { |
|
124 DPRINT << ": IN"; |
|
125 |
|
126 if (HbDataForm *form = settingForm()) { |
|
127 form->addConnection(item, signal.toAscii(), receiver, method.toAscii()); |
|
128 } |
|
129 |
|
130 DPRINT << ": OUT"; |
|
131 } |
|
132 |
|
133 void CpTelephonyPluginView::onConnectionRemoved(HbDataFormModelItem *item, |
|
134 const QString &signal, |
|
135 QObject *receiver, |
|
136 const QString &method) |
|
137 { |
|
138 DPRINT << ": IN"; |
|
139 |
|
140 if (HbDataForm *form = settingForm()) { |
|
141 form->removeConnection(item, signal.toAscii(), receiver, method.toAscii()); |
|
142 } |
|
143 |
|
144 DPRINT << ": OUT"; |
|
145 } |
|
146 |
|
147 void CpTelephonyPluginView::onPrototypeAdded(HbAbstractViewItem *prototype) |
|
148 { |
|
149 DPRINT << ": IN"; |
|
150 |
|
151 if (HbDataForm *form = settingForm()) { |
|
152 QList<HbAbstractViewItem *> prototypes = form->itemPrototypes(); |
|
153 prototypes.append(prototype); |
|
154 form->setItemPrototypes(prototypes); |
|
155 } |
|
156 |
|
157 DPRINT << ": OUT"; |
|
158 } |
|
159 |
|
160 CpItemDataHelper* CpTelephonyPluginView::initializeItemDataHelper() |
|
161 { |
|
162 DPRINT << ": IN"; |
|
163 |
|
164 CpItemDataHelper *itemDataHelper = new CpItemDataHelper; |
|
165 DPRINT << "itemDataHelper:" << reinterpret_cast<int>(itemDataHelper); |
|
166 itemDataHelper->bindToForm(settingForm()); |
|
167 connect(itemDataHelper, |
|
168 SIGNAL(connectionAdded(HbDataFormModelItem*, QString, QObject *, QString)), |
|
169 this, |
|
170 SLOT(onConnectionAdded(HbDataFormModelItem*, QString, QObject *, QString))); |
|
171 connect(itemDataHelper, |
|
172 SIGNAL(connectionRemoved(HbDataFormModelItem*, QString, QObject *, QString)), |
|
173 this, |
|
174 SLOT(onConnectionRemoved(HbDataFormModelItem*, QString, QObject *, QString))); |
|
175 connect(itemDataHelper, |
|
176 SIGNAL(prototypeAdded(HbAbstractViewItem *)), |
|
177 this, |
|
178 SLOT(onPrototypeAdded(HbAbstractViewItem *))); |
|
179 |
|
180 DPRINT << ": OUT : helper signals connected"; |
|
181 return itemDataHelper; |
|
182 } |
|
183 |
|
184 // End of File. |