|
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 |
|
18 #include <hbmainwindow> |
|
19 #include <hbdataform> |
|
20 #include <hbdataformmodel> |
|
21 #include <hbdataformmodelitem> |
|
22 #include <hbdataformviewitem> |
|
23 #include <qgraphicslinearlayout> |
|
24 #include <qvalidator> |
|
25 #include <qintvalidator> |
|
26 #include <qmodelindex> |
|
27 #include <hblineedit> |
|
28 #include <hbvalidator> |
|
29 #include <hbeditorinterface> |
|
30 #include <hbabstractitemview.h> |
|
31 |
|
32 #include "pisettingsview.h" |
|
33 #include "pimainview.h" |
|
34 #include "notifications.h" |
|
35 #include "piprofilerengine.h" |
|
36 #include "pluginattributes.h" |
|
37 |
|
38 const QStringList OUTPUTMODES = (QStringList() << "Debug output" << "File system"); |
|
39 |
|
40 PISettingsView::PISettingsView(PIProfilerEngine *engine) : |
|
41 mEngine(engine), mGeneralAttributes(), mPluginList(0), mSettingForm(0), mModel(0), |
|
42 mGeneralSettingsGroup(0), mPluginSettingsGroup(0), mOutputItem(0), mFileLocation(0), |
|
43 mPrefix(0), mSamplingPeriod(0) |
|
44 |
|
45 { |
|
46 this->setTitle("Settings"); |
|
47 |
|
48 //create setting form |
|
49 mSettingForm = new HbDataForm(this); |
|
50 |
|
51 //create a model class |
|
52 mModel = new HbDataFormModel(this); |
|
53 |
|
54 this->createGeneralSettingForms(); |
|
55 |
|
56 // Set created model model to form |
|
57 mSettingForm->setModel(mModel); |
|
58 |
|
59 // Set widget into view |
|
60 setWidget(mSettingForm); |
|
61 |
|
62 // load general settings into data form |
|
63 loadGeneralSettings(); |
|
64 |
|
65 // Let us know when list is shown |
|
66 connect(mSettingForm, SIGNAL(itemShown(const QModelIndex)), this, |
|
67 SLOT(addTextValidators(const QModelIndex))); |
|
68 |
|
69 // Set general group as expanded. |
|
70 /*HbDataFormViewItem *viewItem = mSettingForm->dataFormViewItem(mModel->indexFromItem( |
|
71 mGeneralSettingsGroup)); |
|
72 viewItem->setExpanded(true);*/ |
|
73 |
|
74 } |
|
75 |
|
76 // --------------------------------------------------------------------------- |
|
77 |
|
78 PISettingsView::~PISettingsView() |
|
79 { |
|
80 if (mSettingForm != 0) { |
|
81 delete mSettingForm; |
|
82 mSettingForm = 0; |
|
83 } |
|
84 |
|
85 if (mModel != 0) { |
|
86 delete mModel; |
|
87 mModel = 0; |
|
88 } |
|
89 } |
|
90 |
|
91 // --------------------------------------------------------------------------- |
|
92 |
|
93 void PISettingsView::addTextValidators(const QModelIndex index) |
|
94 { |
|
95 HbDataFormModelItem *modelItem = mModel->itemFromIndex(index); |
|
96 |
|
97 // Check if item is integer text box |
|
98 if (modelItem->contentWidgetData(QString("TextboxType")) == QString("integer")) { |
|
99 |
|
100 QString value = modelItem->contentWidgetData(QString("text")).toString(); |
|
101 // Create validator that accepts only integer values. |
|
102 HbValidator *validator = new HbValidator(this); |
|
103 validator->addField(new QIntValidator(0, 10000, validator), "1"); |
|
104 |
|
105 // Line editor widget from form |
|
106 HbDataFormViewItem *viewItem = qobject_cast<HbDataFormViewItem *> (mSettingForm->itemByIndex(index)); |
|
107 HbWidget *widget = viewItem->dataItemContentWidget(); |
|
108 HbLineEdit *editor = static_cast<HbLineEdit *> (widget); |
|
109 |
|
110 if (editor != 0) { |
|
111 // Create interface and attach lineEdit to it. |
|
112 HbEditorInterface editInterface(editor); |
|
113 // set editor as phone number editor so that inserting numbers is easier |
|
114 editor->setInputMethodHints(Qt::ImhDigitsOnly); |
|
115 editor->setValidator(validator); |
|
116 } |
|
117 modelItem->setContentWidgetData(QString("text"), value); |
|
118 |
|
119 } |
|
120 |
|
121 } |
|
122 |
|
123 // --------------------------------------------------------------------------- |
|
124 |
|
125 void PISettingsView::createGeneralSettingForms() |
|
126 { |
|
127 |
|
128 // Add data into setting model |
|
129 |
|
130 // General settings group |
|
131 mGeneralSettingsGroup = mModel->appendDataFormGroup(QString("General settings"), |
|
132 mModel->invisibleRootItem()); |
|
133 |
|
134 // Output drop down list |
|
135 mOutputItem = mModel->appendDataFormItem(HbDataFormModelItem::ComboBoxItem, |
|
136 QString("Output to"), mGeneralSettingsGroup); |
|
137 mOutputItem->setContentWidgetData(QString("items"), OUTPUTMODES); |
|
138 |
|
139 // Data file location textbox |
|
140 mFileLocation = mModel->appendDataFormItem(HbDataFormModelItem::TextItem, QString( |
|
141 "Save file in"), mGeneralSettingsGroup); |
|
142 mFileLocation->setContentWidgetData("maxLength", 64); |
|
143 |
|
144 // File name textbox |
|
145 mPrefix = mModel->appendDataFormItem(HbDataFormModelItem::TextItem, QString("File prefix"), |
|
146 mGeneralSettingsGroup); |
|
147 mPrefix->setContentWidgetData("maxLength", 64); |
|
148 |
|
149 // Period that used when using timed progfiling |
|
150 mSamplingPeriod = mModel->appendDataFormItem(HbDataFormModelItem::TextItem, QString( |
|
151 "Sampling period(s)"), mGeneralSettingsGroup); |
|
152 mSamplingPeriod->setContentWidgetData(QString("TextboxType"), QString("integer")); |
|
153 mSamplingPeriod->setContentWidgetData("maxLength", 64); |
|
154 |
|
155 } |
|
156 |
|
157 // --------------------------------------------------------------------------- |
|
158 |
|
159 void PISettingsView::createPluginSpecificSettings() |
|
160 { |
|
161 |
|
162 // Create plug-in specific group |
|
163 mPluginSettingsGroup = mModel->appendDataFormGroup(QString("Plug-in specific settings"), |
|
164 mModel->invisibleRootItem()); |
|
165 |
|
166 if (mPluginList != 0) { |
|
167 |
|
168 for (int index = 0; index < mPluginList->size(); index++) { |
|
169 |
|
170 // create plug-in specific settings group for each plug-in which has own settings |
|
171 if (mPluginList->at(index).mItemCount > 0 || mPluginList->at(index).mSampleRate != -1) { |
|
172 |
|
173 // Create settings group |
|
174 HbDataFormModelItem *mPluginGroup = mModel->appendDataFormGroup(QString( |
|
175 mPluginList->at(index).mName), mPluginSettingsGroup); |
|
176 |
|
177 |
|
178 // get plugin attributes |
|
179 PluginAttributes attributes = mPluginList->at(index); |
|
180 |
|
181 // Create sample rate item if it is needed |
|
182 if (attributes.mSampleRate != -1) { |
|
183 attributes.mFormItemSampleRate = mModel->appendDataFormItem( |
|
184 HbDataFormModelItem::TextItem, "Sample rate (ms)", mPluginGroup); |
|
185 attributes.mFormItemSampleRate->setContentWidgetData(QString("TextboxType"), QString( |
|
186 "integer")); |
|
187 |
|
188 attributes.mFormItemSampleRate->setContentWidgetData("text", |
|
189 attributes.mSampleRate); |
|
190 } |
|
191 |
|
192 // create other setting items |
|
193 attributes.mFormItemSettingItem1 = createPluginSettingItem( |
|
194 &attributes.mSettingItem1, mPluginGroup); |
|
195 attributes.mFormItemSettingItem2 = createPluginSettingItem( |
|
196 &attributes.mSettingItem2, mPluginGroup); |
|
197 attributes.mFormItemSettingItem3 = createPluginSettingItem( |
|
198 &attributes.mSettingItem3, mPluginGroup); |
|
199 attributes.mFormItemSettingItem4 = createPluginSettingItem( |
|
200 &attributes.mSettingItem4, mPluginGroup); |
|
201 attributes.mFormItemSettingItem5 = createPluginSettingItem( |
|
202 &attributes.mSettingItem5, mPluginGroup); |
|
203 attributes.mFormItemSettingItem6 = createPluginSettingItem( |
|
204 &attributes.mSettingItem6, mPluginGroup); |
|
205 mPluginList->replace(index, attributes); |
|
206 } |
|
207 } |
|
208 } |
|
209 |
|
210 } |
|
211 |
|
212 // --------------------------------------------------------------------------- |
|
213 |
|
214 HbDataFormModelItem *PISettingsView::createPluginSettingItem(const SettingItem *item, |
|
215 HbDataFormModelItem *parentGroup) |
|
216 { |
|
217 // create individual plug-in setting item |
|
218 |
|
219 HbDataFormModelItem *settingItem = 0; |
|
220 if (item->mSettingText != QString("")) { |
|
221 switch (item->mType) { |
|
222 case SettingItem::SettingItemTypeBool: |
|
223 settingItem = mModel->appendDataFormItem(HbDataFormModelItem::CheckBoxItem, |
|
224 item->mUIText, parentGroup); |
|
225 bool value = false; |
|
226 if (item->mValue == "true") { |
|
227 value = true; |
|
228 } |
|
229 settingItem->setContentWidgetData("tristate", value); |
|
230 |
|
231 break; |
|
232 case SettingItem::SettingItemTypeHex: |
|
233 settingItem = mModel->appendDataFormItem(HbDataFormModelItem::TextItem, item->mUIText, |
|
234 parentGroup); |
|
235 settingItem->setContentWidgetData("text", item->mValue); |
|
236 settingItem->setContentWidgetData("maxLength", 64); |
|
237 |
|
238 break; |
|
239 |
|
240 case SettingItem::SettingItemTypeInt: |
|
241 settingItem = mModel->appendDataFormItem(HbDataFormModelItem::TextItem, item->mUIText, |
|
242 parentGroup); |
|
243 settingItem->setContentWidgetData("text", item->mValue); |
|
244 settingItem->setContentWidgetData(QString("TextboxType"), QString("integer")); |
|
245 settingItem->setContentWidgetData("maxLength", 64); |
|
246 |
|
247 break; |
|
248 |
|
249 case SettingItem::SettingItemTypeText: |
|
250 HbDataFormModelItem *settingItem = mModel->appendDataFormItem( |
|
251 HbDataFormModelItem::TextItem, item->mUIText, parentGroup); |
|
252 settingItem->setContentWidgetData("text", item->mValue); |
|
253 settingItem->setContentWidgetData("maxLength", 64); |
|
254 |
|
255 break; |
|
256 |
|
257 } |
|
258 } |
|
259 return settingItem; |
|
260 |
|
261 } |
|
262 |
|
263 // --------------------------------------------------------------------------- |
|
264 |
|
265 void PISettingsView::loadGeneralSettings() |
|
266 { |
|
267 // load general settings from engine |
|
268 mEngine->getGeneralSettings(mGeneralAttributes); |
|
269 |
|
270 // set output item correct |
|
271 if (mGeneralAttributes.mTraceOutput == "file_system") { |
|
272 mOutputItem->setContentWidgetData(QString("currentIndex"), OUTPUT_MODE_FILE); |
|
273 } |
|
274 else { |
|
275 mOutputItem->setContentWidgetData(QString("currentIndex"), OUTPUT_MODE_DEBUG); |
|
276 } |
|
277 |
|
278 mFileLocation->setContentWidgetData(QString("text"), mGeneralAttributes.mSaveFileDrive); |
|
279 mPrefix->setContentWidgetData(QString("text"), mGeneralAttributes.mTraceFilePrefix); |
|
280 mSamplingPeriod->setContentWidgetData(QString("text"), mGeneralAttributes.mTimedSamplingPeriod); |
|
281 |
|
282 } |
|
283 |
|
284 // --------------------------------------------------------------------------- |
|
285 |
|
286 GeneralAttributes &PISettingsView::getGeneralAttributes() |
|
287 { |
|
288 // Read items from ui elements and save them into mGeneralAttributes |
|
289 |
|
290 |
|
291 QString fileLocation = mFileLocation->contentWidgetData(QString("text")).toString(); |
|
292 if (fileLocation.length() > 0 && mEngine->checkTraceLocationSanity(fileLocation)) { |
|
293 mGeneralAttributes.mSaveFileDrive = fileLocation; |
|
294 } |
|
295 else { |
|
296 Notifications::showErrorNote("Invalid path, check settings!"); |
|
297 mFileLocation->setContentWidgetData(QString("text"), mGeneralAttributes.mSaveFileDrive); |
|
298 } |
|
299 bool ok = false; |
|
300 mGeneralAttributes.mTimedSamplingPeriod |
|
301 = mSamplingPeriod->contentWidgetData(QString("text")).toInt(&ok); |
|
302 |
|
303 if (!ok) { |
|
304 // this should not happen because intvalidator is set into text box |
|
305 qWarning("Unable to convert sampling period to integer"); |
|
306 |
|
307 } |
|
308 mGeneralAttributes.mTraceFilePrefix = mPrefix->contentWidgetData(QString("text")).toString(); |
|
309 |
|
310 if (mOutputItem->contentWidgetData(QString("currentIndex")).toInt(&ok) == OUTPUT_MODE_FILE) { |
|
311 mGeneralAttributes.mTraceOutput = QString("file_system"); |
|
312 } |
|
313 else { |
|
314 mGeneralAttributes.mTraceOutput = QString("debug_output"); |
|
315 } |
|
316 |
|
317 return mGeneralAttributes; |
|
318 |
|
319 } |
|
320 |
|
321 // --------------------------------------------------------------------------- |
|
322 |
|
323 void PISettingsView::setPluginSettings(QList<PluginAttributes> *pluginList) |
|
324 { |
|
325 mPluginList = pluginList; |
|
326 createPluginSpecificSettings(); |
|
327 } |
|
328 |
|
329 // --------------------------------------------------------------------------- |
|
330 |
|
331 |
|
332 void PISettingsView::readPluginSettingItemValue(HbDataFormModelItem *dataFormItem, |
|
333 SettingItem *settingItem) |
|
334 { |
|
335 if (settingItem != 0 && dataFormItem != 0) { |
|
336 // check if item type is bool, convert bool to string |
|
337 if (settingItem->mType == SettingItem::SettingItemTypeBool) { |
|
338 bool checkboxValue = true; |
|
339 checkboxValue = dataFormItem->contentWidgetData(QString("tristate")).toBool(); |
|
340 |
|
341 if(checkboxValue){ |
|
342 settingItem->mValue = QString("true"); |
|
343 } |
|
344 else{ |
|
345 settingItem->mValue = QString("false"); |
|
346 } |
|
347 |
|
348 } |
|
349 // otherwise save text straight into settin item |
|
350 else { |
|
351 settingItem->mValue = dataFormItem->contentWidgetData("text").toString(); |
|
352 } |
|
353 } |
|
354 } |
|
355 |
|
356 // --------------------------------------------------------------------------- |
|
357 |
|
358 void PISettingsView::readPluginSettings() |
|
359 { |
|
360 // Read Plug-in setting item and save values into m |
|
361 for (int index = 0; index < mPluginList->size(); index++) { |
|
362 |
|
363 PluginAttributes attributes = mPluginList->at(index); |
|
364 |
|
365 readPluginSettingItemValue(attributes.mFormItemSettingItem1, &attributes.mSettingItem1); |
|
366 readPluginSettingItemValue(attributes.mFormItemSettingItem2, &attributes.mSettingItem2); |
|
367 readPluginSettingItemValue(attributes.mFormItemSettingItem3, &attributes.mSettingItem3); |
|
368 readPluginSettingItemValue(attributes.mFormItemSettingItem4, &attributes.mSettingItem4); |
|
369 readPluginSettingItemValue(attributes.mFormItemSettingItem5, &attributes.mSettingItem5); |
|
370 readPluginSettingItemValue(attributes.mFormItemSettingItem6, &attributes.mSettingItem6); |
|
371 |
|
372 if (attributes.mFormItemSampleRate != 0) { |
|
373 bool ok = false; |
|
374 attributes.mSampleRate |
|
375 = attributes.mFormItemSampleRate->contentWidgetData("text").toInt(&ok); |
|
376 if (!ok) { |
|
377 // this should not happen because intvalidator is set into text box |
|
378 qWarning("Unable to convert sample rate to integer"); |
|
379 } |
|
380 } |
|
381 |
|
382 mPluginList->replace(index, attributes); |
|
383 |
|
384 } |
|
385 |
|
386 } |
|
387 |
|
388 // --------------------------------------------------------------------------- |
|
389 |
|
390 void PISettingsView::expandPluginGroup(int uid) |
|
391 { |
|
392 |
|
393 // FIXME some of the methods is deprecating fix once new methods available. |
|
394 //collapse all group items |
|
395 /*HbDataFormViewItem *viewItem = 0; |
|
396 viewItem = mSettingForm->dataFormViewItem(mModel->indexFromItem(mPluginSettingsGroup)); |
|
397 if (viewItem != 0) { |
|
398 viewItem->setExpanded(false); |
|
399 } |
|
400 viewItem = mSettingForm->dataFormViewItem(mModel->indexFromItem(mGeneralSettingsGroup)); |
|
401 if (viewItem != 0) { |
|
402 viewItem->setExpanded(false); |
|
403 } |
|
404 // Set plugin group as expanded. |
|
405 viewItem = mSettingForm->dataFormViewItem(mModel->indexFromItem(mPluginSettingsGroup)); |
|
406 if (viewItem != 0) { |
|
407 viewItem->setExpanded(true); |
|
408 } |
|
409 // find group item which has same uid number |
|
410 for (int index = 0; index < mPluginSettingsGroup->childCount(); index++) { |
|
411 HbDataFormModelItem *item = mPluginSettingsGroup->childAt(index); |
|
412 bool ok = false; |
|
413 int groupUid = item->data(HbDataFormModelItem::KeyRole).toInt(&ok); |
|
414 if (ok) { |
|
415 if (uid == groupUid) { |
|
416 // Set group as expanded |
|
417 viewItem = mSettingForm->dataFormViewItem(mModel->indexFromItem(item)); |
|
418 if (viewItem != 0) { |
|
419 viewItem->setExpanded(true); |
|
420 } |
|
421 |
|
422 // scroll view so that group is shown |
|
423 mSettingForm->scrollTo(mModel->indexFromItem(item), |
|
424 HbAbstractItemView::PositionAtTop); |
|
425 break; |
|
426 |
|
427 } |
|
428 } |
|
429 |
|
430 }*/ |
|
431 |
|
432 } |
|
433 |
|
434 // --------------------------------------------------------------------------- |