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 sms message center form view |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "msgsmscentersettingsform.h" |
|
19 #include "msgsettingengine.h" |
|
20 |
|
21 #include <hbdataformviewitem.h> |
|
22 #include <hbdataformmodelitem.h> |
|
23 #include <hbdataformmodel.h> |
|
24 #include <hblineedit.h> |
|
25 #include <hbinputeditorinterface.h> |
|
26 |
|
27 //Localized constants |
|
28 #define LOC_NEW_SMS_CENTRE hbTrId("txt_messaging_title_new_sms_message_centre") |
|
29 #define LOC_EDIT_SMS_CENTRE hbTrId("txt_messaging_title_edit_sms_message_centre") |
|
30 #define LOC_SMS_CENTRE_NAME hbTrId("txt_messaging_setlabel_message_centre_name") |
|
31 #define LOC_SMS_CENTRE_NUMBER hbTrId("txt_messaging_setlabel_message_centre_number") |
|
32 |
|
33 |
|
34 MsgSMSCenterSettingsForm::MsgSMSCenterSettingsForm(int view, QGraphicsItem *parent) : |
|
35 HbDataForm(parent), mEdit1(NULL), mEdit2(NULL), mView(view) |
|
36 { |
|
37 QString heading; |
|
38 if (mView == -1) { |
|
39 heading = LOC_NEW_SMS_CENTRE; |
|
40 } |
|
41 else { |
|
42 heading = LOC_EDIT_SMS_CENTRE; |
|
43 } |
|
44 |
|
45 this->setHeading(heading); |
|
46 |
|
47 mSettingEngine = new MsgSettingEngine(); |
|
48 |
|
49 initSettingModel(); |
|
50 |
|
51 connect(this, SIGNAL(activated(QModelIndex)), this, SLOT(onItemActivated(QModelIndex))); |
|
52 } |
|
53 |
|
54 MsgSMSCenterSettingsForm::~MsgSMSCenterSettingsForm() |
|
55 { |
|
56 delete mSettingEngine; |
|
57 } |
|
58 |
|
59 void MsgSMSCenterSettingsForm::initSettingModel() |
|
60 { |
|
61 HbDataFormModel *settingsmodel = new HbDataFormModel(); |
|
62 |
|
63 QString centerName = QString(); |
|
64 QString centerNumber = QString(); |
|
65 |
|
66 if (mView != -1) { |
|
67 mSettingEngine->smsCenterNameAndNumber(mView, centerName, centerNumber); |
|
68 } |
|
69 |
|
70 HbDataFormModelItem *messageCenterName = new HbDataFormModelItem(HbDataFormModelItem::TextItem, |
|
71 LOC_SMS_CENTRE_NAME, 0); |
|
72 |
|
73 messageCenterName->setContentWidgetData("text", centerName); |
|
74 |
|
75 settingsmodel->appendDataFormItem(messageCenterName, settingsmodel->invisibleRootItem()); |
|
76 |
|
77 HbDataFormModelItem *messageCenterNumber = new HbDataFormModelItem( |
|
78 HbDataFormModelItem::TextItem, LOC_SMS_CENTRE_NUMBER, 0); |
|
79 |
|
80 messageCenterNumber->setContentWidgetData("text", centerNumber); |
|
81 |
|
82 settingsmodel->appendDataFormItem(messageCenterNumber, settingsmodel->invisibleRootItem()); |
|
83 |
|
84 this->setModel(settingsmodel); |
|
85 } |
|
86 |
|
87 void MsgSMSCenterSettingsForm::onItemActivated(const QModelIndex &index) |
|
88 { |
|
89 HbDataFormModelItem *itemData = static_cast<HbDataFormModelItem *> (index.internalPointer()); |
|
90 // to deal with orbit change temparialy |
|
91 if (itemData->type() > HbDataFormModelItem::GroupPageItem) { |
|
92 HbDataFormModelItem *pageItemData = const_cast<HbDataFormModelItem *> (itemData->parent()); |
|
93 //get the widget of setting item |
|
94 HbWidget* widget = this->dataFormViewItem(index)->dataItemContentWidget(); |
|
95 if (pageItemData) { |
|
96 switch (pageItemData->indexOf(itemData)) { |
|
97 case 0: //name |
|
98 activateTextItem(widget, mEdit1); |
|
99 break; |
|
100 case 1: //number |
|
101 activateTextItem(widget, mEdit2); |
|
102 break; |
|
103 |
|
104 default: |
|
105 break; |
|
106 } |
|
107 } |
|
108 } |
|
109 } |
|
110 |
|
111 void MsgSMSCenterSettingsForm::activateTextItem(HbWidget* widget, HbLineEdit* &edit) |
|
112 { |
|
113 HbLineEdit* editWidget = qobject_cast<HbLineEdit *> (widget); |
|
114 |
|
115 if (editWidget) { |
|
116 edit = editWidget; |
|
117 // If Service center number |
|
118 if (edit == mEdit2) { |
|
119 HbEditorInterface editorInterface(edit); |
|
120 editorInterface.setUpAsPhoneNumberEditor(); |
|
121 } |
|
122 connect(edit, SIGNAL(editingFinished()), this, SLOT(onEditingFinished())); |
|
123 } |
|
124 } |
|
125 |
|
126 void MsgSMSCenterSettingsForm::onEditingFinished() |
|
127 { |
|
128 HbLineEdit *edit1 = qobject_cast<HbLineEdit *> (sender()); |
|
129 |
|
130 if (edit1) { |
|
131 if (edit1 == mEdit1) { |
|
132 mCenterName = edit1->text(); |
|
133 } |
|
134 else if (edit1 == mEdit2) { |
|
135 mCenterNumber = edit1->text(); |
|
136 } |
|
137 } |
|
138 } |
|
139 |
|
140 void MsgSMSCenterSettingsForm::commitChanges() |
|
141 { |
|
142 //commit changes |
|
143 mCenterName = mEdit1->text(); |
|
144 mCenterNumber = mEdit2->text(); |
|
145 |
|
146 if (mCenterName.isEmpty() || mCenterNumber.isEmpty()) { |
|
147 //if mCenterName or mCenterNumber is empty do not commit. |
|
148 return; |
|
149 } |
|
150 |
|
151 if (mView == -1) { |
|
152 mSettingEngine->addSmsMessageCenter(mCenterName, mCenterNumber); |
|
153 } |
|
154 else { |
|
155 mSettingEngine->editSmsMessageCenter(mCenterName, mCenterNumber, mView); |
|
156 } |
|
157 } |
|