|
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: Implementation of the settings widget |
|
15 * |
|
16 */ |
|
17 #include "settingswidget.h" |
|
18 #include <hbdialog.h> |
|
19 #include <hbcheckbox.h> |
|
20 #include <qgraphicslinearlayout.h> |
|
21 #include <hbaction.h> |
|
22 #include <hblabel.h> |
|
23 #include <qsignalmapper.h> |
|
24 #include <hbtooltip.h> |
|
25 #include <qsettings.h> |
|
26 #include <hbinputdialog.h> |
|
27 #include<hbscrollarea.h> |
|
28 #include <qgraphicswidget.h> |
|
29 #include <hbglobal.h> |
|
30 |
|
31 //---------------------------------------------------------------------------------------------------------------------------- |
|
32 //SettingsWidget::SettingsWidget() |
|
33 // |
|
34 //---------------------------------------------------------------------------------------------------------------------------- |
|
35 SettingsWidget::SettingsWidget() : |
|
36 HbWidget() |
|
37 { |
|
38 deviceCategoryList = (QStringList() << hbTrId("txt_search_list_device") |
|
39 << hbTrId("txt_search_list_contatcs") << hbTrId( |
|
40 "txt_search_list_media") << hbTrId("txt_search_list_messagemail") |
|
41 << hbTrId("txt_search_list_calendarnotes") << hbTrId( |
|
42 "txt_search_list_applications") << hbTrId( |
|
43 "txt_search_list_all_other_files")); |
|
44 internetCategoryList = (QStringList() << hbTrId( |
|
45 "txt_search_list_internet") << "Google" << "Bing"); |
|
46 |
|
47 QGraphicsLinearLayout *linearLayout = new QGraphicsLinearLayout( |
|
48 Qt::Vertical); |
|
49 |
|
50 setLayout(linearLayout); |
|
51 |
|
52 popup = new HbDialog(); |
|
53 popup->setDismissPolicy(HbDialog::NoDismiss); |
|
54 |
|
55 popup->setTimeout(HbDialog::NoTimeout); |
|
56 |
|
57 HbAction * action = new HbAction(hbTrId("txt_common_button_ok"), popup); |
|
58 connect(action, SIGNAL(triggered()), this, SLOT(checkBoxOkEvent())); |
|
59 popup->setPrimaryAction(action); |
|
60 |
|
61 action = new HbAction(hbTrId("txt_common_button_cancel"), popup); |
|
62 connect(action, SIGNAL(triggered()), this, SLOT(checkBoxCancelEvent())); |
|
63 popup->setSecondaryAction(action); |
|
64 |
|
65 //device category creation |
|
66 |
|
67 HbCheckBox *checkboxitem = NULL; |
|
68 |
|
69 signalMapper = new QSignalMapper(this); |
|
70 |
|
71 for (int i = 0; i < deviceCategoryList.count(); i++) |
|
72 { |
|
73 checkboxitem = new HbCheckBox(deviceCategoryList.at(i)); |
|
74 |
|
75 mDeviceCheckBoxList.append(checkboxitem); |
|
76 |
|
77 signalMapper->setMapping(mDeviceCheckBoxList.at(i), i); |
|
78 |
|
79 connect(mDeviceCheckBoxList.at(i), SIGNAL(stateChanged(int)), |
|
80 signalMapper, SLOT(map())); |
|
81 |
|
82 if (i == 0) |
|
83 { |
|
84 //arrange device search &internet search |
|
85 linearLayout->addItem(mDeviceCheckBoxList.at(i)); |
|
86 } |
|
87 else |
|
88 { |
|
89 //arrange other subcategoriess |
|
90 mDeviceCheckBoxList.at(i)->setContentsMargins(20, 0, 0, 0); |
|
91 linearLayout->addItem(mDeviceCheckBoxList.at(i)); |
|
92 } |
|
93 } |
|
94 int j = 0; |
|
95 for (int i = deviceCategoryList.count(); i < internetCategoryList.count() |
|
96 + deviceCategoryList.count(); i++) |
|
97 { |
|
98 |
|
99 checkboxitem = new HbCheckBox(internetCategoryList.at(j)); |
|
100 |
|
101 mInternetCheckBoxList.append(checkboxitem); |
|
102 |
|
103 signalMapper->setMapping(mInternetCheckBoxList.at(j), i); |
|
104 |
|
105 connect(mInternetCheckBoxList.at(j), SIGNAL(stateChanged(int)), |
|
106 signalMapper, SLOT(map())); |
|
107 |
|
108 if (i == deviceCategoryList.count()) |
|
109 { |
|
110 //arrange device search &internet search |
|
111 linearLayout->addItem(mInternetCheckBoxList.at(j)); |
|
112 } |
|
113 else |
|
114 { |
|
115 //arrange other subcategoriess |
|
116 mInternetCheckBoxList.at(j)->setContentsMargins(20, 0, 0, 0); |
|
117 linearLayout->addItem(mInternetCheckBoxList.at(j)); |
|
118 |
|
119 } |
|
120 j++; |
|
121 } |
|
122 |
|
123 connect(signalMapper, SIGNAL(mapped(int)), this, SLOT(itemChecked(int))); |
|
124 |
|
125 //Heading label |
|
126 |
|
127 HbLabel *label = new HbLabel(hbTrId( |
|
128 "txt_search_qtl_dialog_pri_heading_delimiter")); |
|
129 popup->setHeadingWidget(label); |
|
130 |
|
131 HbScrollArea* scrollArea = new HbScrollArea(popup); |
|
132 scrollArea->setScrollDirections(Qt::Vertical); |
|
133 scrollArea->setFlag(QGraphicsItem::ItemClipsChildrenToShape, true); |
|
134 scrollArea->setContentWidget(this); |
|
135 popup->setContentWidget(scrollArea); |
|
136 |
|
137 // loadSettingsFrominiFile(); |
|
138 } |
|
139 //---------------------------------------------------------------------------------------------------------------------------- |
|
140 //SettingsWidget::~SettingsWidget() |
|
141 // |
|
142 //---------------------------------------------------------------------------------------------------------------------------- |
|
143 SettingsWidget::~SettingsWidget() |
|
144 { |
|
145 delete signalMapper; |
|
146 //delete popup; |
|
147 } |
|
148 //---------------------------------------------------------------------------------------------------------------------------- |
|
149 //SettingsWidget::launchSettingWidget() |
|
150 // |
|
151 //---------------------------------------------------------------------------------------------------------------------------- |
|
152 void SettingsWidget::launchSettingWidget() |
|
153 { |
|
154 loadSettingsFrominiFile(); |
|
155 setActionVisibility(); |
|
156 popup->show(); |
|
157 } |
|
158 //---------------------------------------------------------------------------------------------------------------------------- |
|
159 //SettingsWidget::setActionVisibility() |
|
160 // |
|
161 //---------------------------------------------------------------------------------------------------------------------------- |
|
162 void SettingsWidget::setActionVisibility() |
|
163 { |
|
164 bool noItemSelected = true; |
|
165 for (int i = 0; i < mDeviceCheckBoxList.count(); i++) |
|
166 { |
|
167 if (mDeviceCheckBoxList.at(i)->checkState() == Qt::Checked) |
|
168 { |
|
169 noItemSelected = false; |
|
170 } |
|
171 } |
|
172 for (int i = 0; i < mInternetCheckBoxList.count(); i++) |
|
173 { |
|
174 if (mInternetCheckBoxList.at(i)->checkState() == Qt::Checked) |
|
175 { |
|
176 noItemSelected = false; |
|
177 } |
|
178 } |
|
179 if (!noItemSelected) |
|
180 { |
|
181 popup->primaryAction()->setVisible(true); |
|
182 } |
|
183 else |
|
184 { |
|
185 popup->primaryAction()->setVisible(false); |
|
186 } |
|
187 } |
|
188 //---------------------------------------------------------------------------------------------------------------------------- |
|
189 //SettingsWidget::itemChecked( int selectedIndex) |
|
190 // |
|
191 //---------------------------------------------------------------------------------------------------------------------------- |
|
192 void SettingsWidget::itemChecked(int selectedIndex) |
|
193 { |
|
194 int totalcount = deviceCategoryList.count() |
|
195 + internetCategoryList.count(); |
|
196 |
|
197 if (selectedIndex == 0) // validating the parent category "devices" |
|
198 { |
|
199 if ((mDeviceCheckBoxList.at(selectedIndex)->checkState() |
|
200 == Qt::Checked)) |
|
201 { |
|
202 isInternetSelected = false; |
|
203 checkSubCategories(0); |
|
204 unCheckSubCategories(0); |
|
205 } |
|
206 else |
|
207 { |
|
208 unCheckSubCategories(1); |
|
209 } |
|
210 setActionVisibility(); |
|
211 return; |
|
212 } |
|
213 else if (selectedIndex == deviceCategoryList.count())// validating the parent category "internet" |
|
214 { |
|
215 if (mInternetCheckBoxList.at(selectedIndex |
|
216 - deviceCategoryList.count())->checkState() == Qt::Checked) |
|
217 { |
|
218 isInternetSelected = true; |
|
219 checkSubCategories(1); |
|
220 unCheckSubCategories(1); |
|
221 } |
|
222 else |
|
223 { |
|
224 unCheckSubCategories(0); |
|
225 } |
|
226 setActionVisibility(); |
|
227 return; |
|
228 } |
|
229 if (selectedIndex < deviceCategoryList.count())// validating the sub categories under "devices" |
|
230 { |
|
231 if (mDeviceCheckBoxList.at(selectedIndex)->checkState() |
|
232 == Qt::Checked) |
|
233 { |
|
234 isInternetSelected = false; |
|
235 unCheckSubCategories(0); |
|
236 |
|
237 } |
|
238 } |
|
239 else // validating the sub categories under "internet" |
|
240 { |
|
241 int curentindex = (selectedIndex + internetCategoryList.count()) |
|
242 - (deviceCategoryList.count() + internetCategoryList.count()); |
|
243 |
|
244 if (mInternetCheckBoxList.at(curentindex)->checkState() |
|
245 == Qt::Checked) |
|
246 { |
|
247 isInternetSelected = true; |
|
248 unCheckSubCategories(1); |
|
249 //return; |
|
250 } |
|
251 } |
|
252 setActionVisibility(); |
|
253 } |
|
254 //---------------------------------------------------------------------------------------------------------------------------- |
|
255 //SettingsWidget::check(int checkSubCategory) |
|
256 // |
|
257 //---------------------------------------------------------------------------------------------------------------------------- |
|
258 void SettingsWidget::checkSubCategories(int checkSubCategory) |
|
259 { |
|
260 if (checkSubCategory == 0) |
|
261 { |
|
262 for (int i = 0; i < mDeviceCheckBoxList.count(); i++) |
|
263 { |
|
264 mDeviceCheckBoxList.at(i)->setCheckState(Qt::Checked); |
|
265 } |
|
266 } |
|
267 else |
|
268 { |
|
269 for (int i = 0; i < mInternetCheckBoxList.count(); i++) |
|
270 { |
|
271 mInternetCheckBoxList.at(i)->setCheckState(Qt::Checked); |
|
272 } |
|
273 } |
|
274 } |
|
275 //---------------------------------------------------------------------------------------------------------------------------- |
|
276 //SettingsWidget::unCheckSubCategories(int unCheckSubCategory) |
|
277 // |
|
278 //---------------------------------------------------------------------------------------------------------------------------- |
|
279 void SettingsWidget::unCheckSubCategories(int unCheckSubCategory) |
|
280 { |
|
281 if (unCheckSubCategory == 0) |
|
282 { |
|
283 for (int i = 0; i < mInternetCheckBoxList.count(); i++) |
|
284 { |
|
285 mInternetCheckBoxList.at(i)->setCheckState(Qt::Unchecked); |
|
286 } |
|
287 } |
|
288 else |
|
289 { |
|
290 for (int i = 0; i < mDeviceCheckBoxList.count(); i++) |
|
291 { |
|
292 mDeviceCheckBoxList.at(i)->setCheckState(Qt::Unchecked); |
|
293 } |
|
294 } |
|
295 } |
|
296 //---------------------------------------------------------------------------------------------------------------------------- |
|
297 //SettingsWidget::checkBoxCancelEvent() |
|
298 // |
|
299 //---------------------------------------------------------------------------------------------------------------------------- |
|
300 void SettingsWidget::checkBoxCancelEvent() |
|
301 { |
|
302 loadSettingsFrominiFile();//bug fix for cancel event selection should not reflect "go" button |
|
303 emit settingsEvent(false); |
|
304 } |
|
305 //---------------------------------------------------------------------------------------------------------------------------- |
|
306 //void SettingsWidget::checkBoxOkEvent() |
|
307 // |
|
308 //---------------------------------------------------------------------------------------------------------------------------- |
|
309 |
|
310 void SettingsWidget::checkBoxOkEvent() |
|
311 { |
|
312 storeSettingsToiniFile(); |
|
313 emit settingsEvent(true); |
|
314 } |
|
315 //---------------------------------------------------------------------------------------------------------------------------- |
|
316 //void SettingsWidget::storeSettingsToiniFile() |
|
317 // |
|
318 //---------------------------------------------------------------------------------------------------------------------------- |
|
319 |
|
320 void SettingsWidget::storeSettingsToiniFile() |
|
321 { |
|
322 QSettings appSettings("Search.ini", QSettings::IniFormat); |
|
323 |
|
324 appSettings.setValue("DeviceCount", mDeviceCheckBoxList.count()); |
|
325 for (int i = 0; i < mDeviceCheckBoxList.count(); i++) |
|
326 { |
|
327 if (mDeviceCheckBoxList.at(i)->checkState() == Qt::Checked) |
|
328 { |
|
329 appSettings.setValue(mDeviceCheckBoxList.at(i)->text(), 1); |
|
330 emit selectedItemCategory(i, true); |
|
331 } |
|
332 else |
|
333 { |
|
334 appSettings.setValue(mDeviceCheckBoxList.at(i)->text(), 0); |
|
335 emit selectedItemCategory(i, false); |
|
336 } |
|
337 } |
|
338 // int totalcount = i; |
|
339 appSettings.setValue("InternetCount", mInternetCheckBoxList.count()); |
|
340 for (int i = 0; i < mInternetCheckBoxList.count(); i++) |
|
341 { |
|
342 if (mInternetCheckBoxList.at(i)->checkState() == Qt::Checked) |
|
343 { |
|
344 appSettings.setValue(mInternetCheckBoxList.at(i)->text(), 1); |
|
345 // emit selectedcategory(totalcount,true); |
|
346 } |
|
347 else |
|
348 { |
|
349 appSettings.setValue(mInternetCheckBoxList.at(i)->text(), 0); |
|
350 //emit selectedcategory(totalcount,false); |
|
351 } |
|
352 // totalcount++; |
|
353 } |
|
354 } |
|
355 |
|
356 //---------------------------------------------------------------------------------------------------------------------------- |
|
357 //void SettingsWidget::loadSettingsFrominiFile() |
|
358 // |
|
359 //---------------------------------------------------------------------------------------------------------------------------- |
|
360 |
|
361 void SettingsWidget::loadSettingsFrominiFile() |
|
362 { |
|
363 enableDefaultSettings(); |
|
364 isInternetSelected = false; |
|
365 QSettings appSettings("Search.ini", QSettings::IniFormat); |
|
366 int ret = 0; |
|
367 for (int i = 0; i < mDeviceCheckBoxList.count(); i++) |
|
368 { |
|
369 ret = appSettings.value(mDeviceCheckBoxList.at(i)->text()).toInt(); |
|
370 if (ret) |
|
371 { |
|
372 mDeviceCheckBoxList.at(i)->setCheckState(Qt::Checked); |
|
373 emit selectedItemCategory(i, true); |
|
374 } |
|
375 else |
|
376 { |
|
377 mDeviceCheckBoxList.at(i)->setCheckState(Qt::Unchecked); |
|
378 emit selectedItemCategory(i, false); |
|
379 } |
|
380 } |
|
381 for (int i = 0; i < mInternetCheckBoxList.count(); i++) |
|
382 { |
|
383 |
|
384 ret = appSettings.value(mInternetCheckBoxList.at(i)->text()).toInt(); |
|
385 if (ret) |
|
386 { |
|
387 isInternetSelected = true; |
|
388 mInternetCheckBoxList.at(i)->setCheckState(Qt::Checked); |
|
389 // emit selectedcategory(mInternetCheckBoxList.at(i)->text(),true); |
|
390 } |
|
391 else |
|
392 { |
|
393 mInternetCheckBoxList.at(i)->setCheckState(Qt::Unchecked); |
|
394 // emit selectedcategory(mInternetCheckBoxList.at(i)->text(),false); |
|
395 } |
|
396 } |
|
397 |
|
398 } |
|
399 //---------------------------------------------------------------------------------------------------------------------------- |
|
400 //SettingsWidget::isInternetSearchOptionSelected() |
|
401 // |
|
402 //---------------------------------------------------------------------------------------------------------------------------- |
|
403 bool SettingsWidget::isInternetSearchOptionSelected() |
|
404 { |
|
405 return isInternetSelected; |
|
406 } |
|
407 //---------------------------------------------------------------------------------------------------------------------------- |
|
408 //void SettingsWidget::changeDeviceInternetCheck() |
|
409 // |
|
410 //---------------------------------------------------------------------------------------------------------------------------- |
|
411 void SettingsWidget::changeDeviceInternetCheck() |
|
412 { |
|
413 if (isInternetSearchOptionSelected() == true) |
|
414 { |
|
415 mDeviceCheckBoxList.at(0)->setCheckState(Qt::Checked); |
|
416 |
|
417 } |
|
418 else |
|
419 |
|
420 { |
|
421 |
|
422 mInternetCheckBoxList.at(0)->setCheckState(Qt::Checked); |
|
423 |
|
424 } |
|
425 |
|
426 emit settingsChanged(); |
|
427 } |
|
428 //---------------------------------------------------------------------------------------------------------------------------- |
|
429 //void SettingsWidget::enableDefaultSettings() |
|
430 // |
|
431 //---------------------------------------------------------------------------------------------------------------------------- |
|
432 void SettingsWidget::enableDefaultSettings() |
|
433 { |
|
434 QSettings appSettings("Search.ini", QSettings::IniFormat); |
|
435 if (!appSettings.contains("DeviceCount")) // change the settings for the first time only |
|
436 { |
|
437 appSettings.setValue("DeviceCount", mDeviceCheckBoxList.count()); |
|
438 for (int i = 0; i < mDeviceCheckBoxList.count(); i++) |
|
439 { |
|
440 // mDeviceCheckBoxList.at(i)->setCheckState(Qt::Checked); |
|
441 appSettings.setValue(mDeviceCheckBoxList.at(i)->text(), 1); |
|
442 } |
|
443 for (int i = 0; i < mInternetCheckBoxList.count(); i++) |
|
444 { |
|
445 //mInternetCheckBoxList.at(i)->setCheckState(Qt::Unchecked); |
|
446 appSettings.setValue(mInternetCheckBoxList.at(i)->text(), 0); |
|
447 } |
|
448 // storeSettingsToiniFile(); |
|
449 } |
|
450 |
|
451 } |