72
|
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:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
#include "cntdetaileditor.h"
|
|
18 |
#include "cnteditorfactory.h"
|
|
19 |
#include "cntgroupeditormodel.h"
|
|
20 |
#include "cntsavemanager.h"
|
|
21 |
#include "cntglobal.h"
|
|
22 |
|
|
23 |
#include <cntviewparams.h>
|
|
24 |
#include <hbmenu.h>
|
|
25 |
#include <hbaction.h>
|
|
26 |
#include <hbmainwindow.h>
|
|
27 |
#include <hbview.h>
|
|
28 |
#include <hbdocumentloader.h>
|
|
29 |
#include <hbaction.h>
|
|
30 |
#include <hblineedit.h>
|
|
31 |
#include <hbinputeditorinterface.h>
|
|
32 |
#include <hbinputstandardfilters.h>
|
|
33 |
#include <cntdebug.h>
|
|
34 |
#include <hbscrollarea.h>
|
|
35 |
#include <hbscrollbar.h>
|
|
36 |
#include <hbdevicenotificationdialog.h>
|
|
37 |
#include <hbparameterlengthlimiter.h>
|
|
38 |
#include <hbshrinkingvkbhost.h>
|
|
39 |
|
|
40 |
#include <QApplication>
|
|
41 |
#include <QTimer>
|
|
42 |
|
|
43 |
const char *CNT_DETAILEDITOR_XML = ":/xml/contacts_detail_editor.docml";
|
|
44 |
|
|
45 |
CntDetailEditor::CntDetailEditor( int aId ) :
|
|
46 |
QObject(),
|
|
47 |
mDataFormModel(NULL),
|
|
48 |
mHeader(NULL),
|
|
49 |
mId(aId),
|
|
50 |
mView(NULL),
|
|
51 |
mLoader(NULL),
|
|
52 |
mViewManager(NULL),
|
|
53 |
mEditorFactory(NULL),
|
|
54 |
mCancel(NULL),
|
|
55 |
mVirtualKeyboard(NULL)
|
|
56 |
{
|
|
57 |
bool ok;
|
|
58 |
document()->load(CNT_DETAILEDITOR_XML, &ok);
|
|
59 |
if (!ok) {
|
|
60 |
qFatal("Unable to read %S", CNT_DETAILEDITOR_XML);
|
|
61 |
}
|
|
62 |
else {
|
|
63 |
mView = static_cast<HbView*> (document()->findWidget(QString("view")));
|
|
64 |
mDataForm = static_cast<HbDataForm*> (document()->findWidget(QString("dataForm")));
|
|
65 |
}
|
|
66 |
|
|
67 |
mEditorFactory = new CntEditorFactory();
|
|
68 |
|
|
69 |
mSoftkey = new HbAction(Hb::BackNaviAction, mView);
|
|
70 |
connect( mSoftkey, SIGNAL(triggered()), this, SLOT(saveChanges()) );
|
|
71 |
|
|
72 |
// closing the application from task swapper or end key will cause the contact to be saved
|
|
73 |
connect( qApp, SIGNAL(aboutToQuit()), this, SLOT(saveContact()));
|
|
74 |
}
|
|
75 |
|
|
76 |
CntDetailEditor::~CntDetailEditor()
|
|
77 |
{
|
|
78 |
mView->deleteLater();
|
|
79 |
|
|
80 |
delete mDataForm;
|
|
81 |
mDataForm = NULL;
|
|
82 |
delete mDataFormModel;
|
|
83 |
mDataFormModel = NULL;
|
|
84 |
delete mHeader;
|
|
85 |
mHeader = NULL;
|
|
86 |
delete mLoader;
|
|
87 |
mLoader = NULL;
|
|
88 |
delete mEditorFactory;
|
|
89 |
mEditorFactory = NULL;
|
|
90 |
delete mVirtualKeyboard;
|
|
91 |
mVirtualKeyboard = NULL;
|
|
92 |
}
|
|
93 |
|
|
94 |
void CntDetailEditor::setViewId( int aId )
|
|
95 |
{
|
|
96 |
mId = aId;
|
|
97 |
}
|
|
98 |
|
|
99 |
void CntDetailEditor::setInsertAction( const QString aInsert )
|
|
100 |
{
|
|
101 |
HbAction* insert = new HbAction( aInsert, mView );
|
|
102 |
mView->menu()->insertAction(mCancel, insert);
|
|
103 |
connect( insert, SIGNAL(triggered()), this, SLOT(insertField()) );
|
|
104 |
}
|
|
105 |
|
|
106 |
void CntDetailEditor::activate( const CntViewParameters aArgs )
|
|
107 |
{
|
|
108 |
mViewManager = &mEngine->viewManager();
|
|
109 |
mArgs = aArgs; //don't loose the params while swiching between editview and editorviews.
|
|
110 |
|
|
111 |
mCancel = static_cast<HbAction*>(document()->findObject("cnt:discardchanges"));
|
|
112 |
mCancel->setParent(mView);
|
|
113 |
mView->menu()->addAction(mCancel);
|
|
114 |
connect( mCancel, SIGNAL(triggered()), this, SLOT(discardChanges()) );
|
|
115 |
mCancel->setDisabled(true);
|
|
116 |
|
|
117 |
if ( mView->navigationAction() != mSoftkey) {
|
|
118 |
mView->setNavigationAction(mSoftkey);
|
|
119 |
}
|
|
120 |
|
|
121 |
if ( mId == groupEditorView )
|
|
122 |
{
|
81
|
123 |
mContact = aArgs.value(ESelectedGroupContact).value<QContact>();
|
72
|
124 |
connect( mDataForm, SIGNAL(itemShown(const QModelIndex&)), this, SLOT(handleItemShown(const QModelIndex&)) );
|
|
125 |
}
|
|
126 |
else
|
|
127 |
{
|
81
|
128 |
mContact = aArgs.value(ESelectedContact).value<QContact>();
|
72
|
129 |
connect( mDataForm, SIGNAL(itemShown(const QModelIndex&)), this, SLOT(handleItemShown(const QModelIndex&)) );
|
|
130 |
}
|
|
131 |
|
|
132 |
QContactManager& cm = mEngine->contactManager(SYMBIAN_BACKEND);
|
|
133 |
connect(&cm, SIGNAL(contactsRemoved(const QList<QContactLocalId>&)),
|
|
134 |
this, SLOT(contactDeletedFromOtherSource(const QList<QContactLocalId>&)));
|
|
135 |
|
81
|
136 |
mEditorFactory->setupEditorView(*this, mContact);
|
72
|
137 |
mDataForm->setItemRecycling(true);
|
|
138 |
|
|
139 |
// add new field if required
|
|
140 |
if ( aArgs.value(ESelectedAction).toString() == CNT_ADD_ACTION )
|
|
141 |
{
|
|
142 |
mDataFormModel->insertDetailField();
|
|
143 |
}
|
|
144 |
|
|
145 |
connect(mDataFormModel, SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)),
|
|
146 |
this, SLOT(enableDiscardChanges(/*const QModelIndex &, const QModelIndex &*/)));
|
|
147 |
|
|
148 |
mDataForm->setVerticalScrollBarPolicy(HbScrollArea::ScrollBarAsNeeded);
|
|
149 |
mDataForm->setScrollingStyle(HbScrollArea::PanWithFollowOn);
|
|
150 |
mDataForm->verticalScrollBar()->setInteractive(true);
|
|
151 |
|
|
152 |
mVirtualKeyboard = new HbShrinkingVkbHost(mView);
|
|
153 |
}
|
|
154 |
|
|
155 |
void CntDetailEditor::deactivate()
|
|
156 |
{
|
|
157 |
QContactManager& mgr = mEngine->contactManager(SYMBIAN_BACKEND);
|
|
158 |
|
|
159 |
disconnect(&mgr, SIGNAL(contactsRemoved(const QList<QContactLocalId>&)),
|
|
160 |
this, SLOT(contactDeletedFromOtherSource(const QList<QContactLocalId>&)));
|
81
|
161 |
|
|
162 |
delete mVirtualKeyboard;
|
|
163 |
mVirtualKeyboard = NULL;
|
72
|
164 |
}
|
|
165 |
|
|
166 |
bool CntDetailEditor::isDefault() const
|
|
167 |
{
|
|
168 |
return false;
|
|
169 |
}
|
|
170 |
|
|
171 |
HbView* CntDetailEditor::view() const
|
|
172 |
{
|
|
173 |
return mView;
|
|
174 |
}
|
|
175 |
|
|
176 |
HbDocumentLoader* CntDetailEditor::document()
|
|
177 |
{
|
|
178 |
if (!mLoader) {
|
|
179 |
mLoader = new HbDocumentLoader();
|
|
180 |
}
|
|
181 |
|
|
182 |
return mLoader;
|
|
183 |
}
|
|
184 |
|
|
185 |
void CntDetailEditor::insertField()
|
|
186 |
{
|
|
187 |
mDataFormModel->insertDetailField();
|
|
188 |
mDataForm->scrollTo(mDataFormModel->index(mDataFormModel->rowCount() - 1, 0), HbAbstractItemView::PositionAtBottom);
|
|
189 |
}
|
|
190 |
|
|
191 |
void CntDetailEditor::handleItemShown(const QModelIndex& aIndex )
|
|
192 |
{
|
|
193 |
HbDataFormModelItem* modelItem = mDataFormModel->itemFromIndex( aIndex );
|
|
194 |
|
|
195 |
if ( modelItem->type() == HbDataFormModelItem::TextItem )
|
|
196 |
{
|
|
197 |
HbDataFormViewItem* viewItem = static_cast<HbDataFormViewItem*>(mDataForm->itemByIndex( aIndex ));
|
|
198 |
HbLineEdit* edit = static_cast<HbLineEdit*>( viewItem->dataItemContentWidget() );
|
|
199 |
QString objName;
|
|
200 |
|
|
201 |
if ( mId == groupEditorView )
|
|
202 |
{
|
|
203 |
CntGroupEditorModel* groupModel = static_cast<CntGroupEditorModel*>( mDataFormModel );
|
|
204 |
if ( groupModel->isConferenceNumber(aIndex) )
|
|
205 |
{
|
|
206 |
edit->setInputMethodHints( Qt::ImhDialableCharactersOnly );
|
|
207 |
objName = "Conference number line edit %1";
|
|
208 |
}
|
|
209 |
else
|
|
210 |
{
|
|
211 |
edit->setInputMethodHints( Qt::ImhNoPredictiveText );
|
|
212 |
objName = "Group name line edit %1";
|
|
213 |
}
|
|
214 |
}
|
|
215 |
else
|
|
216 |
{
|
|
217 |
edit->setInputMethodHints( Qt::ImhNoPredictiveText );
|
|
218 |
|
|
219 |
if (modelItem->contentWidgetData( "preferDigits" ).toBool())
|
|
220 |
{
|
|
221 |
edit->setInputMethodHints( Qt::ImhPreferNumbers | Qt::ImhNoPredictiveText );
|
|
222 |
}
|
|
223 |
|
|
224 |
objName = mDataFormModel->detail().definitionName() + " line edit %1";
|
|
225 |
}
|
|
226 |
|
|
227 |
// Naming UI components for automation testability
|
|
228 |
edit->setObjectName(objName.arg(aIndex.row()));
|
|
229 |
}
|
|
230 |
}
|
|
231 |
|
|
232 |
void CntDetailEditor::discardChanges()
|
|
233 |
{
|
|
234 |
QContact selected( *mDataFormModel->contact() );
|
|
235 |
QVariant var;
|
|
236 |
var.setValue(selected);
|
|
237 |
mArgs.insert(ESelectedContact, var);
|
|
238 |
mViewManager->back( mArgs );
|
|
239 |
}
|
|
240 |
|
|
241 |
/*!
|
|
242 |
Saves all changes made to details (type of details depends on
|
|
243 |
in which editor we are) of a contact. Doesn't save the contact.
|
|
244 |
*/
|
|
245 |
void CntDetailEditor::saveChanges()
|
|
246 |
{
|
|
247 |
mDataFormModel->saveContactDetails();
|
|
248 |
|
|
249 |
QContact selected( *mDataFormModel->contact() );
|
|
250 |
QVariant var;
|
|
251 |
var.setValue(selected);
|
|
252 |
if ( mId == groupEditorView )
|
|
253 |
{
|
|
254 |
mArgs.insert(ESelectedGroupContact, var);
|
|
255 |
}
|
|
256 |
else
|
|
257 |
{
|
|
258 |
mArgs.insert(ESelectedContact, var);
|
|
259 |
|
|
260 |
QContactDetail selectedDetail( mDataFormModel->detail() );
|
|
261 |
QVariant var2;
|
|
262 |
var2.setValue( selectedDetail );
|
|
263 |
mArgs.insert( ESelectedDetail, var2 );
|
|
264 |
}
|
|
265 |
|
|
266 |
mViewManager->back( mArgs );
|
|
267 |
}
|
|
268 |
|
|
269 |
/*!
|
|
270 |
First saves all changes made to details (type of details depends on
|
|
271 |
in which editor we are) of a contact and then saves the contact. This
|
|
272 |
is only called when phonebook is being closed either from task swapper
|
|
273 |
or by end key.
|
|
274 |
*/
|
|
275 |
void CntDetailEditor::saveContact()
|
|
276 |
{
|
|
277 |
mDataFormModel->saveContactDetails();
|
|
278 |
QContactManager& mgr = mEngine->contactManager( SYMBIAN_BACKEND );
|
|
279 |
QString name = mgr.synthesizedContactDisplayLabel(*mDataFormModel->contact());
|
|
280 |
|
|
281 |
if (name.isEmpty())
|
|
282 |
{
|
|
283 |
name = hbTrId("txt_phob_list_unnamed");
|
|
284 |
}
|
|
285 |
|
81
|
286 |
QString myCard = mArgs.value( EMyCard ).toString();
|
|
287 |
QContactLocalId localId = mContact.localId();
|
|
288 |
QContactLocalId selfContactId = mgr.selfContactId();
|
|
289 |
bool isMyCard = ( localId == selfContactId && localId != 0 ) || !myCard.isEmpty();
|
|
290 |
|
|
291 |
CntSaveManager::CntSaveResult result;
|
|
292 |
CntSaveManager& saveMgr = mEngine->saveManager();
|
|
293 |
if (isMyCard) {
|
|
294 |
result = saveMgr.saveMyCard( mDataFormModel->contact(), &mgr );
|
|
295 |
}
|
|
296 |
else if ( mId == groupEditorView ) {
|
|
297 |
result = saveMgr.saveGroup( mDataFormModel->contact(), &mgr );
|
|
298 |
}
|
|
299 |
else {
|
|
300 |
result = saveMgr.saveContact( mDataFormModel->contact(), &mgr );
|
|
301 |
}
|
|
302 |
|
|
303 |
if (mId != groupEditorView) {
|
72
|
304 |
switch (result)
|
|
305 |
{
|
|
306 |
case CntSaveManager::ESaved:
|
81
|
307 |
HbDeviceNotificationDialog::notification(QString(),HbParameterLengthLimiter("txt_phob_dpophead_contact_1_saved").arg(name));
|
72
|
308 |
break;
|
|
309 |
case CntSaveManager::EUpdated:
|
81
|
310 |
HbDeviceNotificationDialog::notification(QString(),HbParameterLengthLimiter("txt_phob_dpophead_contacts_1_updated").arg(name));
|
72
|
311 |
break;
|
|
312 |
case CntSaveManager::EFailed:
|
|
313 |
HbDeviceNotificationDialog::notification(QString(),hbTrId("SAVING FAILED!"));
|
|
314 |
break;
|
|
315 |
case CntSaveManager::EDeleted:
|
|
316 |
case CntSaveManager::ENothingDone:
|
|
317 |
default:
|
|
318 |
break;
|
|
319 |
}
|
|
320 |
}
|
|
321 |
}
|
|
322 |
|
|
323 |
void CntDetailEditor::setHeader(QString aHeader)
|
|
324 |
{
|
|
325 |
if (!mHeader) {
|
|
326 |
mHeader = static_cast<HbGroupBox*> (document()->findWidget(QString("headerBox")));
|
|
327 |
}
|
|
328 |
mHeader->setHeading(aHeader);
|
|
329 |
}
|
|
330 |
|
|
331 |
void CntDetailEditor::setDetails(CntDetailEditorModel* aModel, HbAbstractViewItem* aPrototype)
|
|
332 |
{
|
|
333 |
//Append custom view item prototype
|
|
334 |
if ( aPrototype )
|
|
335 |
{
|
|
336 |
QList <HbAbstractViewItem*> protos = mDataForm->itemPrototypes();
|
|
337 |
protos.append( aPrototype );
|
|
338 |
mDataForm->setItemPrototypes( protos );
|
|
339 |
}
|
|
340 |
|
|
341 |
mDataFormModel = aModel;
|
|
342 |
mDataForm->setModel( mDataFormModel );
|
|
343 |
|
|
344 |
}
|
|
345 |
|
|
346 |
int CntDetailEditor::viewId() const
|
|
347 |
{
|
|
348 |
return mId;
|
|
349 |
}
|
|
350 |
|
|
351 |
/*!
|
|
352 |
Go back to the root view
|
|
353 |
*/
|
|
354 |
void CntDetailEditor::showRootView()
|
|
355 |
{
|
|
356 |
mViewManager->back( mArgs, true );
|
|
357 |
}
|
|
358 |
|
|
359 |
|
|
360 |
void CntDetailEditor::contactDeletedFromOtherSource(const QList<QContactLocalId>& contactIds)
|
|
361 |
{
|
|
362 |
CNT_ENTRY
|
|
363 |
|
|
364 |
QContact normalContact = mArgs.value(ESelectedContact).value<QContact>();
|
|
365 |
QContact groupContact = mArgs.value(ESelectedGroupContact).value<QContact>();
|
|
366 |
if ( contactIds.contains(normalContact.localId()) || contactIds.contains(groupContact.localId()) )
|
|
367 |
{
|
|
368 |
// Do not switch to the previous view immediately. List views are
|
|
369 |
// not updated properly if this is not done in the event loop
|
|
370 |
QTimer::singleShot(0, this, SLOT(showRootView()));
|
|
371 |
}
|
|
372 |
CNT_EXIT
|
|
373 |
}
|
|
374 |
|
|
375 |
void CntDetailEditor::enableDiscardChanges()
|
|
376 |
{
|
|
377 |
mCancel->setDisabled(false);
|
|
378 |
}
|
|
379 |
|
|
380 |
// End of File
|