author | William Roberts <williamr@symbian.org> |
Thu, 22 Jul 2010 16:32:06 +0100 | |
branch | GCC_SURGE |
changeset 47 | 5b14749788d7 |
parent 27 | e4592d119491 |
parent 44 | 36f374c67aa8 |
permissions | -rw-r--r-- |
31 | 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 |
#include "msgsettingsdataformcustomitem.h" |
|
21 |
||
22 |
#include <hbdataformviewitem.h> |
|
23 |
#include <hbdataformmodelitem.h> |
|
24 |
#include <hbdataformmodel.h> |
|
25 |
#include <hblineedit.h> |
|
26 |
#include <HbNotificationDialog> |
|
27 |
#include <hbinputeditorinterface.h> |
|
28 |
#include <hbmessagebox.h> |
|
29 |
#include <HbAction> |
|
30 |
#include "debugtraces.h" |
|
31 |
||
32 |
//Localized constants |
|
33 |
#define LOC_SMS_CENTRE_NAME hbTrId("txt_messaging_setlabel_message_centre_name") |
|
34 |
#define LOC_SMS_CENTRE_NUMBER hbTrId("txt_messaging_setlabel_message_centre_number") |
|
35 |
#define LOC_SMS_CENTRE_DELETE hbTrId("txt_messaging_button_delete_message_centre") |
|
36 |
#define LOC_MESSAGE_CENTER_SAVED hbTrId("txt_messaging_setlabel_message_centre_saved") |
|
37 |
||
38 |
MsgSMSCenterSettingsForm::MsgSMSCenterSettingsForm(int view, |
|
39 |
QGraphicsItem *parent) : |
|
40 |
HbDataForm(parent), mEdit1(0), mEdit2(0), mView(view) |
|
41 |
{ |
|
42 |
QString heading; |
|
43 |
if (mView > -1) |
|
44 |
{ |
|
45 |
//add the custom prototype only for edit items |
|
46 |
MsgSettingsDataFormCustomItem* customPrototype = |
|
47 |
new MsgSettingsDataFormCustomItem(this); |
|
48 |
||
49 |
QList<HbAbstractViewItem*> protos = this->itemPrototypes(); |
|
50 |
protos.append(customPrototype); |
|
51 |
this->setItemPrototypes(protos); |
|
52 |
} |
|
53 |
||
54 |
bool b = connect(this, |
|
55 |
SIGNAL(itemShown(const QModelIndex&)), |
|
56 |
this, |
|
57 |
SLOT(onItemShown(const QModelIndex&))); |
|
58 |
||
59 |
QDEBUG_WRITE_FORMAT("MsgSMSCenterSettingsForm::MsgSMSCenterSettingsForm initialized.. ", b) |
|
60 |
||
61 |
mSettingEngine = new MsgSettingEngine(); |
|
62 |
||
63 |
initSettingModel(); |
|
64 |
} |
|
65 |
||
66 |
MsgSMSCenterSettingsForm::~MsgSMSCenterSettingsForm() |
|
67 |
{ |
|
68 |
delete mSettingEngine; |
|
69 |
} |
|
70 |
||
71 |
void MsgSMSCenterSettingsForm::initSettingModel() |
|
72 |
{ |
|
73 |
QDEBUG_WRITE("MsgSMSCenterSettingsForm::initSettingModel"); |
|
74 |
HbDataFormModel *settingsmodel = new HbDataFormModel(); |
|
75 |
||
76 |
if (mView != -1) |
|
77 |
{ |
|
78 |
mSettingEngine->smsCenterNameAndNumber(mView, |
|
79 |
mCenterName, |
|
80 |
mCenterNumber); |
|
81 |
} |
|
82 |
||
83 |
messageCenterName = new HbDataFormModelItem(HbDataFormModelItem::TextItem, |
|
84 |
LOC_SMS_CENTRE_NAME, |
|
85 |
0); |
|
86 |
||
87 |
messageCenterName->setContentWidgetData("text", mCenterName); |
|
88 |
||
89 |
settingsmodel->appendDataFormItem(messageCenterName, |
|
90 |
settingsmodel->invisibleRootItem()); |
|
91 |
||
92 |
messageCenterNumber |
|
93 |
= new HbDataFormModelItem(HbDataFormModelItem::TextItem, |
|
94 |
LOC_SMS_CENTRE_NUMBER, |
|
95 |
0); |
|
96 |
||
97 |
messageCenterNumber->setContentWidgetData("text", mCenterNumber); |
|
98 |
||
99 |
settingsmodel->appendDataFormItem(messageCenterNumber, |
|
100 |
settingsmodel->invisibleRootItem()); |
|
101 |
||
102 |
if (mView != -1) /// edit case delete button required |
|
103 |
{ |
|
104 |
//CUSTOM SETTING ITEM HbButton |
|
105 |
HbDataFormModelItem::DataItemType |
|
106 |
customButtonGeneral = |
|
107 |
static_cast<HbDataFormModelItem::DataItemType> ( |
|
108 |
HbDataFormModelItem::CustomItemBase + 1); |
|
109 |
||
110 |
HbDataFormModelItem |
|
111 |
*deleteMessageCentre = |
|
112 |
settingsmodel->appendDataFormItem( |
|
113 |
customButtonGeneral, |
|
114 |
QString(""), |
|
115 |
settingsmodel->invisibleRootItem()); |
|
116 |
||
117 |
deleteMessageCentre->setContentWidgetData("text", |
|
118 |
LOC_SMS_CENTRE_DELETE); |
|
119 |
this->addConnection(deleteMessageCentre, |
|
120 |
SIGNAL(clicked()), |
|
121 |
this, |
|
122 |
SLOT(onPressedCustomButton())); |
|
123 |
} |
|
124 |
||
125 |
this->setModel(settingsmodel); |
|
126 |
} |
|
127 |
||
128 |
void MsgSMSCenterSettingsForm::commitChanges() |
|
129 |
{ |
|
130 |
//commit changes |
|
131 |
QString centerName; |
|
132 |
QString centerNumber; |
|
133 |
||
134 |
if (mEdit1) |
|
135 |
centerName = mEdit1->text(); |
|
136 |
||
137 |
if (mEdit2) |
|
138 |
centerNumber = mEdit2->text(); |
|
139 |
||
140 |
// check if any of the field are empty |
|
141 |
// OR the data unchanged, then return dont commit |
|
142 |
if (centerName.isEmpty() || centerNumber.isEmpty() || (centerName |
|
143 |
== mCenterName && centerNumber == mCenterNumber)) |
|
144 |
{ |
|
145 |
//if mCenterName or mCenterNumber is empty do not commit. |
|
146 |
return; |
|
147 |
} |
|
148 |
||
149 |
QDEBUG_WRITE("MsgSMSCenterSettingsForm::commitChanges"); |
|
150 |
if (mView == -1) |
|
151 |
{ |
|
152 |
mSettingEngine->addSmsMessageCenter(centerName, centerNumber); |
|
153 |
} |
|
154 |
else |
|
155 |
{ |
|
156 |
mSettingEngine->editSmsMessageCenter(centerName, |
|
157 |
centerNumber, |
|
158 |
mView); |
|
159 |
||
160 |
HbNotificationDialog::launchDialog(LOC_MESSAGE_CENTER_SAVED); |
|
161 |
} |
|
162 |
QDEBUG_WRITE("ex MsgSMSCenterSettingsForm::commitChanges"); |
|
163 |
} |
|
164 |
||
165 |
void MsgSMSCenterSettingsForm::onItemShown(const QModelIndex& topLeft) |
|
166 |
{ |
|
167 |
||
168 |
QDEBUG_WRITE("DataForm MsgSMSCenterSettingsForm::onItemShown"); |
|
169 |
HbDataFormModelItem *itemData = |
|
170 |
static_cast<HbDataFormModel *> (model())->itemFromIndex(topLeft); |
|
171 |
||
172 |
if (itemData && itemData == messageCenterName && !mEdit1) |
|
173 |
{ |
|
174 |
QDEBUG_WRITE("messageCenterName updated.."); |
|
175 |
HbDataFormViewItem* item1 = |
|
176 |
static_cast<HbDataFormViewItem*>(this->itemByIndex(topLeft)); |
|
177 |
mEdit1 = static_cast<HbLineEdit*>(item1->dataItemContentWidget()); |
|
178 |
} |
|
179 |
else if (itemData && itemData == messageCenterNumber && !mEdit2) |
|
180 |
{ |
|
181 |
QDEBUG_WRITE("messageCenterNumber updated.."); |
|
182 |
HbDataFormViewItem* item1 = |
|
183 |
static_cast<HbDataFormViewItem*>(this->itemByIndex(topLeft)); |
|
184 |
mEdit2 = static_cast<HbLineEdit*>(item1->dataItemContentWidget()); |
|
185 |
mEdit2->setInputMethodHints(Qt::ImhPreferNumbers); |
|
186 |
||
187 |
} |
|
188 |
} |
|
189 |
||
190 |
void MsgSMSCenterSettingsForm::onPressedCustomButton() |
|
191 |
{ |
|
44
36f374c67aa8
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
192 |
HbMessageBox::question(LOC_SMS_CENTRE_DELETE, this, |
36f374c67aa8
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
193 |
SLOT(onDialogDeleteMsgCentre(HbAction*)), |
36f374c67aa8
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
194 |
HbMessageBox::Delete | HbMessageBox::Cancel); |
31 | 195 |
} |
196 |
||
197 |
void MsgSMSCenterSettingsForm::onDialogDeleteMsgCentre(HbAction* action) |
|
198 |
{ |
|
199 |
HbMessageBox *dlg = qobject_cast<HbMessageBox*> (sender()); |
|
200 |
if (action == dlg->actions().at(0)) { |
|
201 |
//delete from m/w -- mView is the index to delete |
|
202 |
mSettingEngine->deleteSmsMessageCenter(mView); |
|
203 |
emit deleteMessageCentreAndClose(); |
|
204 |
} |
|
205 |
} |
|
206 |
||
207 |
//eof |
|
208 |