|
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: This class is for first form view for msg settings |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "msgsettingsform.h" |
|
19 #include "msgsettingsdataformcustomitem.h" |
|
20 |
|
21 #include <hbdataformmodelitem.h> |
|
22 #include <hbdataformmodel.h> |
|
23 #include <hbcombobox.h> |
|
24 #include <hbpushbutton.h> |
|
25 |
|
26 #include "debugtraces.h" |
|
27 |
|
28 //Localized constants |
|
29 #define LOC_RECEIVING_SERVICE_MESSAGES hbTrId("txt_messaging_setlabel_receiving_service_messages") |
|
30 |
|
31 #define LOC_OFF hbTrId("txt_messaging_setlabel_val_off") |
|
32 #define LOC_REDUCED_SUPPORT hbTrId("txt_messaging_setlabel_val_reduced_support") |
|
33 #define LOC_FULL_SUPPORT hbTrId("txt_messaging_setlabel_val_full_support") |
|
34 #define LOC_ADVANCED hbTrId("txt_messaging_button_advanced") |
|
35 #define LOC_CHAR_ENCODING hbTrId("txt_messaging_setlabel_character_encoding") |
|
36 #define LOC_MMS_SETTINGS hbTrId("txt_messaging_subhead_mms_settings") |
|
37 #define LOC_SMS_CENTRE_SETTINGS hbTrId("txt_messaging_subhead_sms_message_centre_settings") |
|
38 |
|
39 #define LOC_MMS_CREATION_MODE hbTrId("txt_messaging_setlabel_mms_creation_mode") |
|
40 #define LOC_MMS_RETRIEVAL hbTrId("txt_messaging_setlabel_mms_retrieval") |
|
41 #define LOC_ALLOW_ANONYMOUS_MMS hbTrId("txt_messaging_setlabel_allow_anonymous_mms_message") |
|
42 #define LOC_RECEIVE_MMS_ADVERTS hbTrId("txt_messaging_setlabel_receive_mms_adverts") |
|
43 #define LOC_MMS_AP_IN_USE hbTrId("txt_messaging_setlabel_mms_access_point_in_use") |
|
44 #define LOC_SMS_CENTRE_IN_USE hbTrId("txt_messaging_setlabel_sms_message_centre_in_use") |
|
45 #define LOC_ADD_NEW hbTrId("txt_messaging_button_add_new") |
|
46 #define LOC_ALWAYS_AUTOMATIC hbTrId("txt_messaging_setlabel_val_always_automatic") |
|
47 #define LOC_AUTO_HOME_NETWORK hbTrId("txt_messaging_setlabel_val_auto_home_network") |
|
48 #define LOC_MANUAL hbTrId("txt_messaging_setlabel_val_manual") |
|
49 #define LOC_MMS_YES hbTrId("txt_messaging_setlabel_allow_anonymous_mms_val_yes") |
|
50 #define LOC_MMS_NO hbTrId("txt_messaging_setlabel_allow_anonymous_mms_val_no") |
|
51 |
|
52 MsgSettingsForm::MsgSettingsForm( |
|
53 MsgSettingsView::SettingsView settingsView, |
|
54 QGraphicsItem *parent) : |
|
55 HbDataForm(parent) |
|
56 { |
|
57 mSettingEngine = new MsgSettingEngine(); |
|
58 |
|
59 //custom prototype |
|
60 MsgSettingsDataFormCustomItem* customPrototype = |
|
61 new MsgSettingsDataFormCustomItem(this); |
|
62 |
|
63 QList<HbAbstractViewItem*> protos = this->itemPrototypes(); |
|
64 protos.append(customPrototype); |
|
65 this->setItemPrototypes(protos); |
|
66 |
|
67 mSmsMCSettingsGroup << LOC_SMS_CENTRE_IN_USE << LOC_ADD_NEW; |
|
68 |
|
69 //initialize the form model |
|
70 initSettingModel(settingsView); |
|
71 } |
|
72 |
|
73 MsgSettingsForm::~MsgSettingsForm() |
|
74 { |
|
75 delete mSettingEngine; |
|
76 } |
|
77 |
|
78 void MsgSettingsForm::initSettingModel( |
|
79 MsgSettingsView::SettingsView settingsView) |
|
80 { |
|
81 settingsModel = new HbDataFormModel(0); |
|
82 |
|
83 MsgSettingEngine::CharacterEncoding charEncoding = |
|
84 MsgSettingEngine::ReducedSupport; |
|
85 |
|
86 mSettingEngine->settingsCharEncoding(charEncoding); |
|
87 |
|
88 // 1. Character encoding |
|
89 HbDataFormModelItem *characterEncoding = |
|
90 new HbDataFormModelItem(HbDataFormModelItem::ComboBoxItem, |
|
91 LOC_CHAR_ENCODING, |
|
92 0); |
|
93 QStringList charEncodingList; |
|
94 charEncodingList << LOC_REDUCED_SUPPORT << LOC_FULL_SUPPORT; |
|
95 |
|
96 int index = int (charEncoding); |
|
97 |
|
98 characterEncoding->setContentWidgetData("items", charEncodingList); |
|
99 characterEncoding->setContentWidgetData("currentIndex", index); |
|
100 |
|
101 settingsModel->appendDataFormItem(characterEncoding, |
|
102 settingsModel->invisibleRootItem()); |
|
103 this->addConnection(characterEncoding, |
|
104 SIGNAL(currentIndexChanged(int)), |
|
105 this, |
|
106 SLOT(changeCharEncoding(int))); |
|
107 |
|
108 // 2. MMS Settings |
|
109 HbDataFormModelItem* mmsGroup = |
|
110 new HbDataFormModelItem(HbDataFormModelItem::GroupItem, |
|
111 LOC_MMS_SETTINGS, |
|
112 0); |
|
113 |
|
114 settingsModel->appendDataFormItem(mmsGroup, |
|
115 settingsModel->invisibleRootItem()); |
|
116 |
|
117 addMMSGroupItem(mmsGroup); |
|
118 |
|
119 // 4. SMS Settings |
|
120 mSmsMCGroup = new HbDataFormModelItem(HbDataFormModelItem::GroupItem, |
|
121 LOC_SMS_CENTRE_SETTINGS, |
|
122 0); |
|
123 |
|
124 settingsModel->appendDataFormItem(mSmsMCGroup, |
|
125 settingsModel->invisibleRootItem()); |
|
126 |
|
127 addSmsMCGroupItem(mSmsMCGroup); |
|
128 |
|
129 this->setModel(settingsModel); |
|
130 |
|
131 if (settingsView == MsgSettingsView::MMSView) |
|
132 { |
|
133 //set MMS Settings as expanded |
|
134 expandGroup(mmsGroup,true); |
|
135 } |
|
136 |
|
137 } |
|
138 |
|
139 void MsgSettingsForm::refreshViewForm() |
|
140 { |
|
141 updateSmsMCGroupItem(mSmsMCGroup); |
|
142 } |
|
143 |
|
144 void MsgSettingsForm::updateSmsMCGroupItem(HbDataFormModelItem* parent) |
|
145 { |
|
146 //1. update the combobox model item |
|
147 int defaultServiceCenter = -1; |
|
148 mSmsServiceList.clear(); |
|
149 mSettingEngine->allSMSMessageCenter(mSmsServiceList, defaultServiceCenter); |
|
150 |
|
151 //set the content widget data again |
|
152 smsMessageCenter->setContentWidgetData("items", mSmsServiceList); |
|
153 if(defaultServiceCenter > 0) |
|
154 { |
|
155 smsMessageCenter->setContentWidgetData("currentIndex", |
|
156 defaultServiceCenter); |
|
157 } |
|
158 |
|
159 //2. refresh all the custom buttons again |
|
160 int childCount = parent->childCount(); |
|
161 int totalServices = mSmsServiceList.count(); |
|
162 |
|
163 //custom buttons start from index 1 till childCount-2 |
|
164 int list_index = 0, child_index = 1; |
|
165 for (; list_index < totalServices && child_index <= childCount - 2; list_index++, child_index++) |
|
166 { |
|
167 //get the existing custom item instance |
|
168 HbDataFormModelItem* customItem = parent->childAt(child_index); |
|
169 customItem->setContentWidgetData("text", mSmsServiceList.at(list_index)); |
|
170 } |
|
171 |
|
172 //if extra child items are remaining then delete those from parent |
|
173 for(;child_index <= childCount - 2; |
|
174 child_index++) |
|
175 { |
|
176 parent->removeChild(child_index); |
|
177 } |
|
178 |
|
179 //create all new custom items if new are added in list |
|
180 //CUSTOM SETTING ITEM HbButton |
|
181 HbDataFormModelItem::DataItemType |
|
182 customButtonGeneral = |
|
183 static_cast<HbDataFormModelItem::DataItemType> (HbDataFormModelItem::CustomItemBase |
|
184 + 1); |
|
185 for (; list_index < totalServices; list_index++, child_index++) |
|
186 { |
|
187 HbDataFormModelItem* newChild = |
|
188 new HbDataFormModelItem(customButtonGeneral); |
|
189 |
|
190 newChild->setContentWidgetData("text", mSmsServiceList.at(list_index)); |
|
191 parent->insertChild(child_index, newChild); |
|
192 |
|
193 this->addConnection(newChild, |
|
194 SIGNAL(clicked()), |
|
195 this, |
|
196 SLOT(onPressedCustomButton())); |
|
197 } |
|
198 |
|
199 } |
|
200 |
|
201 void MsgSettingsForm::addMMSGroupItem(HbDataFormModelItem* parent) |
|
202 { |
|
203 //read settings |
|
204 MsgSettingEngine::MmsRetrieval retrieval = |
|
205 MsgSettingEngine::AlwaysAutomatic; |
|
206 bool allowAnonymous = true; |
|
207 bool allowAdverts = true; |
|
208 |
|
209 mSettingEngine->advanceMmsSettings(retrieval, |
|
210 allowAnonymous, |
|
211 allowAdverts); |
|
212 |
|
213 // add all the mms group item |
|
214 |
|
215 HbDataFormModelItem *mmsRetrieval = |
|
216 new HbDataFormModelItem(HbDataFormModelItem::ComboBoxItem, |
|
217 LOC_MMS_RETRIEVAL, |
|
218 0); |
|
219 |
|
220 QStringList mmsRetrievalList; |
|
221 mmsRetrievalList << LOC_ALWAYS_AUTOMATIC << LOC_AUTO_HOME_NETWORK |
|
222 << LOC_MANUAL << LOC_OFF; |
|
223 |
|
224 mmsRetrieval->setContentWidgetData("items", mmsRetrievalList); |
|
225 mmsRetrieval->setContentWidgetData("currentIndex", int (retrieval)); |
|
226 this->addConnection(mmsRetrieval, |
|
227 SIGNAL(currentIndexChanged(int)), |
|
228 this, |
|
229 SLOT(changeMMSRetrievalMode(int))); |
|
230 |
|
231 HbDataFormModelItem *anonymousMMS = |
|
232 new HbDataFormModelItem(HbDataFormModelItem::ToggleValueItem, |
|
233 LOC_ALLOW_ANONYMOUS_MMS, |
|
234 0); |
|
235 |
|
236 QStringList anonymousMMSList; |
|
237 anonymousMMSList << LOC_MMS_NO << LOC_MMS_YES; |
|
238 |
|
239 int defaultIndex = int (allowAnonymous); |
|
240 int alternateIndex = (defaultIndex + 1) % anonymousMMSList.count(); |
|
241 |
|
242 anonymousMMS->setContentWidgetData("text", |
|
243 anonymousMMSList.at(defaultIndex)); |
|
244 anonymousMMS->setContentWidgetData("additionalText", |
|
245 anonymousMMSList.at(alternateIndex)); |
|
246 this->addConnection(anonymousMMS, |
|
247 SIGNAL(clicked()), |
|
248 this, |
|
249 SLOT(allowAnonymousMMS())); |
|
250 |
|
251 HbDataFormModelItem *mmsAdverts = |
|
252 new HbDataFormModelItem(HbDataFormModelItem::ToggleValueItem, |
|
253 LOC_RECEIVE_MMS_ADVERTS, |
|
254 0); |
|
255 |
|
256 QStringList mmsAdvertsList; |
|
257 mmsAdvertsList << LOC_MMS_NO << LOC_MMS_YES; |
|
258 |
|
259 defaultIndex = int (allowAdverts); |
|
260 alternateIndex = (defaultIndex + 1) % mmsAdvertsList.count(); |
|
261 |
|
262 mmsAdverts->setContentWidgetData("text", mmsAdvertsList.at(defaultIndex)); |
|
263 mmsAdverts->setContentWidgetData("additionalText", |
|
264 mmsAdvertsList.at(alternateIndex)); |
|
265 |
|
266 this->addConnection(mmsAdverts, |
|
267 SIGNAL(clicked()), |
|
268 this, |
|
269 SLOT(allowMMSAdverts())); |
|
270 |
|
271 HbDataFormModelItem *accessPoint = |
|
272 new HbDataFormModelItem(HbDataFormModelItem::ComboBoxItem, |
|
273 LOC_MMS_AP_IN_USE, |
|
274 0); |
|
275 |
|
276 QStringList mmsList; |
|
277 int defaultAccessPointIndex = -1; |
|
278 |
|
279 mSettingEngine->allMMsAcessPoints(mmsList, defaultAccessPointIndex); |
|
280 accessPoint->setContentWidgetData("items", mmsList); |
|
281 if (defaultAccessPointIndex >= 0) |
|
282 { |
|
283 accessPoint->setContentWidgetData("currentIndex", |
|
284 defaultAccessPointIndex); |
|
285 } |
|
286 QDEBUG_WRITE_FORMAT("Settings: adding accesspoints..", defaultAccessPointIndex); |
|
287 this->addConnection(accessPoint, |
|
288 SIGNAL(currentIndexChanged(int)), |
|
289 this, |
|
290 SLOT(changeAccessPoint(int))); |
|
291 |
|
292 parent->appendChild(mmsRetrieval); |
|
293 parent->appendChild(anonymousMMS); |
|
294 parent->appendChild(mmsAdverts); |
|
295 parent->appendChild(accessPoint); |
|
296 } |
|
297 |
|
298 void MsgSettingsForm::addSmsMCGroupItem(HbDataFormModelItem* parent) |
|
299 { |
|
300 // add all the sms message center group item |
|
301 smsMessageCenter |
|
302 = new HbDataFormModelItem(HbDataFormModelItem::ComboBoxItem, |
|
303 mSmsMCSettingsGroup.at(0), |
|
304 0); |
|
305 |
|
306 int defaultServiceCenter = -1; |
|
307 mSmsServiceList.clear(); |
|
308 |
|
309 mSettingEngine->allSMSMessageCenter(mSmsServiceList, defaultServiceCenter); |
|
310 smsMessageCenter->setContentWidgetData("items", mSmsServiceList); |
|
311 if (defaultServiceCenter >= 0) |
|
312 { |
|
313 smsMessageCenter->setContentWidgetData("currentIndex", |
|
314 defaultServiceCenter); |
|
315 } |
|
316 |
|
317 this->addConnection(smsMessageCenter, |
|
318 SIGNAL(currentIndexChanged(int)), |
|
319 this, |
|
320 SLOT(onSMSCurrentIndexChanged(int))); |
|
321 |
|
322 parent->appendChild(smsMessageCenter); |
|
323 |
|
324 //CUSTOM SETTING ITEM HbButton |
|
325 HbDataFormModelItem::DataItemType |
|
326 customButtonGeneral = |
|
327 static_cast<HbDataFormModelItem::DataItemType> (HbDataFormModelItem::CustomItemBase |
|
328 + 1); |
|
329 |
|
330 int totalServices = mSmsServiceList.count(); |
|
331 for (int index = 0; index < totalServices; index++) |
|
332 { |
|
333 HbDataFormModelItem *newMessageCenters = |
|
334 settingsModel->appendDataFormItem(customButtonGeneral, |
|
335 QString(""), |
|
336 parent); |
|
337 |
|
338 newMessageCenters->setContentWidgetData("text", |
|
339 mSmsServiceList.at(index)); |
|
340 this->addConnection(newMessageCenters, |
|
341 SIGNAL(clicked()), |
|
342 this, |
|
343 SLOT(onPressedCustomButton())); |
|
344 } |
|
345 |
|
346 HbDataFormModelItem *newMessageCenters = |
|
347 settingsModel->appendDataFormItem(customButtonGeneral, |
|
348 QString(""), |
|
349 parent); |
|
350 |
|
351 newMessageCenters->setContentWidgetData("text", mSmsMCSettingsGroup.at(1)); |
|
352 this->addConnection(newMessageCenters, |
|
353 SIGNAL(clicked()), |
|
354 this, |
|
355 SLOT(onPressedCustomButton())); |
|
356 } |
|
357 |
|
358 void MsgSettingsForm::changeCharEncoding(int index) |
|
359 { |
|
360 //set the character encoding |
|
361 mSettingEngine->setCharacterEncoding(MsgSettingEngine::CharacterEncoding(index)); |
|
362 } |
|
363 |
|
364 void MsgSettingsForm::changeMMSRetrievalMode(int index) |
|
365 { |
|
366 mSettingEngine->setMMSRetrieval(MsgSettingEngine::MmsRetrieval(index)); |
|
367 } |
|
368 |
|
369 void MsgSettingsForm::allowAnonymousMMS() |
|
370 { |
|
371 HbPushButton *btn = qobject_cast<HbPushButton *> (sender()); |
|
372 |
|
373 if (btn) |
|
374 { |
|
375 QString btnText = btn->text(); |
|
376 |
|
377 //check if the button pressed was Yes or NO |
|
378 if (LOC_MMS_YES == btnText) |
|
379 { |
|
380 mSettingEngine->setAnonymousMessages(true); |
|
381 } |
|
382 else |
|
383 { |
|
384 mSettingEngine->setAnonymousMessages(false); |
|
385 } |
|
386 } |
|
387 } |
|
388 |
|
389 void MsgSettingsForm::allowMMSAdverts() |
|
390 { |
|
391 HbPushButton *btn = qobject_cast<HbPushButton *> (sender()); |
|
392 |
|
393 if (btn) |
|
394 { |
|
395 QString btnText = btn->text(); |
|
396 |
|
397 //check if the button pressed was Yes or NO |
|
398 if (LOC_MMS_NO == btnText) |
|
399 { |
|
400 mSettingEngine->setReceiveMMSAdverts(false); |
|
401 } |
|
402 else |
|
403 { |
|
404 mSettingEngine->setReceiveMMSAdverts(true); |
|
405 } |
|
406 } |
|
407 } |
|
408 |
|
409 void MsgSettingsForm::changeAccessPoint(int index) |
|
410 { |
|
411 // save to the mms settings |
|
412 mSettingEngine->setMMSAccesspoint(index); |
|
413 } |
|
414 |
|
415 void MsgSettingsForm::onPressedCustomButton() |
|
416 { |
|
417 HbPushButton *btn = qobject_cast<HbPushButton *> (sender()); |
|
418 |
|
419 if (btn) |
|
420 { |
|
421 QString btnText = btn->text(); |
|
422 if (btnText == mSmsMCSettingsGroup.at(1)) |
|
423 { |
|
424 // emit the signal to open add view |
|
425 emit newSMSCCenterClicked(-1); |
|
426 } |
|
427 else |
|
428 { |
|
429 int index = mSmsServiceList.indexOf(btnText); |
|
430 emit newSMSCCenterClicked(index); |
|
431 } |
|
432 } |
|
433 } |
|
434 |
|
435 void MsgSettingsForm::onSMSCurrentIndexChanged(int index) |
|
436 { |
|
437 //set into msg settings |
|
438 mSettingEngine->setSMSMessageCenter(index); |
|
439 } |
|
440 |
|
441 void MsgSettingsForm::expandGroup(HbDataFormModelItem* group,bool expand) |
|
442 { |
|
443 QModelIndex index = settingsModel->indexFromItem(group); |
|
444 |
|
445 if(index.isValid()) |
|
446 { |
|
447 this->setExpanded(index, expand); |
|
448 } |
|
449 } |
|
450 //EOF |