15 * |
15 * |
16 */ |
16 */ |
17 #include "cntdetaileditor.h" |
17 #include "cntdetaileditor.h" |
18 #include "cnteditorfactory.h" |
18 #include "cnteditorfactory.h" |
19 #include "cntgroupeditormodel.h" |
19 #include "cntgroupeditormodel.h" |
|
20 #include "cntsavemanager.h" |
20 #include "cntglobal.h" |
21 #include "cntglobal.h" |
|
22 |
21 #include <cntviewparams.h> |
23 #include <cntviewparams.h> |
22 #include <hbmenu.h> |
24 #include <hbmenu.h> |
23 #include <hbaction.h> |
25 #include <hbaction.h> |
24 #include <hbmainwindow.h> |
26 #include <hbmainwindow.h> |
25 #include <hbview.h> |
27 #include <hbview.h> |
27 #include <hbaction.h> |
29 #include <hbaction.h> |
28 #include <hblineedit.h> |
30 #include <hblineedit.h> |
29 #include <hbinputeditorinterface.h> |
31 #include <hbinputeditorinterface.h> |
30 #include <hbinputstandardfilters.h> |
32 #include <hbinputstandardfilters.h> |
31 #include <cntdebug.h> |
33 #include <cntdebug.h> |
|
34 #include <hbscrollarea.h> |
|
35 #include <hbscrollbar.h> |
|
36 #include <hbdevicenotificationdialog.h> |
|
37 #include <hbparameterlengthlimiter.h> |
|
38 |
|
39 #include <QApplication> |
32 |
40 |
33 const char *CNT_DETAILEDITOR_XML = ":/xml/contacts_detail_editor.docml"; |
41 const char *CNT_DETAILEDITOR_XML = ":/xml/contacts_detail_editor.docml"; |
34 |
42 |
35 CntDetailEditor::CntDetailEditor( int aId ) : |
43 CntDetailEditor::CntDetailEditor( int aId ) : |
36 QObject(), |
44 QObject(), |
55 |
64 |
56 mEditorFactory = new CntEditorFactory(); |
65 mEditorFactory = new CntEditorFactory(); |
57 |
66 |
58 mSoftkey = new HbAction(Hb::BackNaviAction, mView); |
67 mSoftkey = new HbAction(Hb::BackNaviAction, mView); |
59 connect( mSoftkey, SIGNAL(triggered()), this, SLOT(saveChanges()) ); |
68 connect( mSoftkey, SIGNAL(triggered()), this, SLOT(saveChanges()) ); |
|
69 |
|
70 // closing the application from task swapper or end key will cause the contact to be saved |
|
71 connect( qApp, SIGNAL(aboutToQuit()), this, SLOT(saveContact())); |
60 } |
72 } |
61 |
73 |
62 CntDetailEditor::~CntDetailEditor() |
74 CntDetailEditor::~CntDetailEditor() |
63 { |
75 { |
64 mView->deleteLater(); |
76 mView->deleteLater(); |
|
77 |
65 delete mDataForm; |
78 delete mDataForm; |
|
79 mDataForm = NULL; |
66 delete mDataFormModel; |
80 delete mDataFormModel; |
|
81 mDataFormModel = NULL; |
67 delete mHeader; |
82 delete mHeader; |
|
83 mHeader = NULL; |
68 delete mLoader; |
84 delete mLoader; |
|
85 mLoader = NULL; |
69 delete mEditorFactory; |
86 delete mEditorFactory; |
|
87 mEditorFactory = NULL; |
|
88 delete mSaveManager; |
|
89 mSaveManager = NULL; |
70 } |
90 } |
71 |
91 |
72 void CntDetailEditor::setViewId( int aId ) |
92 void CntDetailEditor::setViewId( int aId ) |
73 { |
93 { |
74 mId = aId; |
94 mId = aId; |
106 selectedContact = aArgs.value(ESelectedContact).value<QContact>(); |
126 selectedContact = aArgs.value(ESelectedContact).value<QContact>(); |
107 connect( mDataForm, SIGNAL(itemShown(const QModelIndex&)), this, SLOT(handleItemShown(const QModelIndex&)) ); |
127 connect( mDataForm, SIGNAL(itemShown(const QModelIndex&)), this, SLOT(handleItemShown(const QModelIndex&)) ); |
108 } |
128 } |
109 mEditorFactory->setupEditorView(*this, selectedContact); |
129 mEditorFactory->setupEditorView(*this, selectedContact); |
110 |
130 |
|
131 QString myCard = mArgs.value( EMyCard ).toString(); |
|
132 QContactLocalId localId = selectedContact.localId(); |
|
133 QContactLocalId selfContactId = mViewManager->contactManager(SYMBIAN_BACKEND)->selfContactId(); |
|
134 bool isMyCard = ( localId == selfContactId && localId != 0 ) || !myCard.isEmpty(); |
|
135 |
|
136 if (isMyCard) |
|
137 { |
|
138 mSaveManager = new CntSaveManager(CntSaveManager::EMyCard); |
|
139 } |
|
140 else if ( mId == groupEditorView ) |
|
141 { |
|
142 mSaveManager = new CntSaveManager(CntSaveManager::EGroup); |
|
143 } |
|
144 else |
|
145 { |
|
146 mSaveManager = new CntSaveManager(); |
|
147 } |
|
148 |
111 mDataForm->setItemRecycling(true); |
149 mDataForm->setItemRecycling(true); |
112 |
150 |
113 // add new field if required |
151 // add new field if required |
114 if ( aArgs.value(ESelectedAction).toString() == CNT_ADD_ACTION ) |
152 if ( aArgs.value(ESelectedAction).toString() == CNT_ADD_ACTION ) |
115 { |
153 { |
116 mDataFormModel->insertDetailField(); |
154 mDataFormModel->insertDetailField(); |
117 } |
155 } |
|
156 mDataForm->setVerticalScrollBarPolicy(HbScrollArea::ScrollBarAsNeeded); |
|
157 mDataForm->setScrollingStyle(HbScrollArea::PanWithFollowOn); |
|
158 mDataForm->verticalScrollBar()->setInteractive(true); |
118 } |
159 } |
119 |
160 |
120 void CntDetailEditor::deactivate() |
161 void CntDetailEditor::deactivate() |
121 { |
162 { |
122 if( mId == groupEditorView) { |
163 if( mId == groupEditorView) { |
157 if ( groupModel->isConferenceNumber(aIndex) ) |
198 if ( groupModel->isConferenceNumber(aIndex) ) |
158 { |
199 { |
159 HbDataFormViewItem* viewItem = static_cast<HbDataFormViewItem*>(mDataForm->itemByIndex( aIndex )); |
200 HbDataFormViewItem* viewItem = static_cast<HbDataFormViewItem*>(mDataForm->itemByIndex( aIndex )); |
160 HbLineEdit* edit = static_cast<HbLineEdit*>( viewItem->dataItemContentWidget() ); |
201 HbLineEdit* edit = static_cast<HbLineEdit*>( viewItem->dataItemContentWidget() ); |
161 edit->setInputMethodHints( Qt::ImhDialableCharactersOnly ); |
202 edit->setInputMethodHints( Qt::ImhDialableCharactersOnly ); |
|
203 } |
|
204 else |
|
205 { |
|
206 HbDataFormViewItem* viewItem = static_cast<HbDataFormViewItem*>(mDataForm->itemByIndex( aIndex )); |
|
207 HbLineEdit* edit = static_cast<HbLineEdit*>( viewItem->dataItemContentWidget() ); |
|
208 edit->setInputMethodHints( Qt::ImhNoPredictiveText ); |
162 } |
209 } |
163 } |
210 } |
164 else |
211 else |
165 { |
212 { |
166 HbDataFormViewItem* viewItem = static_cast<HbDataFormViewItem*>(mDataForm->itemByIndex( aIndex )); |
213 HbDataFormViewItem* viewItem = static_cast<HbDataFormViewItem*>(mDataForm->itemByIndex( aIndex )); |
182 var.setValue(selected); |
229 var.setValue(selected); |
183 mArgs.insert(ESelectedContact, var); |
230 mArgs.insert(ESelectedContact, var); |
184 mViewManager->back( mArgs ); |
231 mViewManager->back( mArgs ); |
185 } |
232 } |
186 |
233 |
|
234 /*! |
|
235 Saves all changes made to details (type of details depends on |
|
236 in which editor we are) of a contact. Doesn't save the contact. |
|
237 */ |
187 void CntDetailEditor::saveChanges() |
238 void CntDetailEditor::saveChanges() |
188 { |
239 { |
189 mDataFormModel->saveContactDetails(); |
240 mDataFormModel->saveContactDetails(); |
190 |
241 |
191 QContact selected( *mDataFormModel->contact() ); |
242 QContact selected( *mDataFormModel->contact() ); |
206 } |
257 } |
207 |
258 |
208 mViewManager->back( mArgs ); |
259 mViewManager->back( mArgs ); |
209 } |
260 } |
210 |
261 |
|
262 /*! |
|
263 First saves all changes made to details (type of details depends on |
|
264 in which editor we are) of a contact and then saves the contact. This |
|
265 is only called when phonebook is being closed either from task swapper |
|
266 or by end key. |
|
267 */ |
|
268 void CntDetailEditor::saveContact() |
|
269 { |
|
270 mDataFormModel->saveContactDetails(); |
|
271 |
|
272 QString name = mViewManager->contactManager(SYMBIAN_BACKEND)->synthesizedDisplayLabel(*mDataFormModel->contact()); |
|
273 |
|
274 if (name.isEmpty()) |
|
275 { |
|
276 name = hbTrId("txt_phob_list_unnamed"); |
|
277 } |
|
278 |
|
279 CntSaveManager::CntSaveResult result = mSaveManager->saveContact(mDataFormModel->contact(), mViewManager->contactManager(SYMBIAN_BACKEND)); |
|
280 |
|
281 if (mId != groupEditorView) |
|
282 { |
|
283 switch (result) |
|
284 { |
|
285 case CntSaveManager::ESaved: |
|
286 HbDeviceNotificationDialog::notification(QString(),HbParameterLengthLimiter(hbTrId("txt_phob_dpophead_contact_1_saved")).arg(name)); |
|
287 break; |
|
288 case CntSaveManager::EUpdated: |
|
289 HbDeviceNotificationDialog::notification(QString(),HbParameterLengthLimiter(hbTrId("txt_phob_dpophead_contacts_1_updated")).arg(name)); |
|
290 break; |
|
291 case CntSaveManager::EFailed: |
|
292 HbDeviceNotificationDialog::notification(QString(),hbTrId("SAVING FAILED!")); |
|
293 break; |
|
294 case CntSaveManager::EDeleted: |
|
295 case CntSaveManager::ENothingDone: |
|
296 default: |
|
297 break; |
|
298 } |
|
299 } |
|
300 } |
|
301 |
211 void CntDetailEditor::setHeader(QString aHeader) |
302 void CntDetailEditor::setHeader(QString aHeader) |
212 { |
303 { |
213 if (!mHeader) { |
304 if (!mHeader) { |
214 mHeader = static_cast<HbGroupBox*> (document()->findWidget(QString("headerBox"))); |
305 mHeader = static_cast<HbGroupBox*> (document()->findWidget(QString("headerBox"))); |
215 } |
306 } |