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 |
|
|
18 |
#include "cnteditview_p.h"
|
|
19 |
#include "cnteditviewlistmodel.h"
|
|
20 |
#include "cntdocumentloader.h"
|
|
21 |
#include "cntdetailpopup.h"
|
|
22 |
#include "cnteditviewheadingitem.h"
|
|
23 |
#include "cntthumbnailmanager.h"
|
|
24 |
#include "cntimagelabel.h"
|
|
25 |
#include "cntsavemanager.h"
|
|
26 |
#include <cntabstractengine.h>
|
|
27 |
#include "cntglobal.h"
|
|
28 |
#include "cntdebug.h"
|
|
29 |
|
|
30 |
#include <qtcontacts.h>
|
|
31 |
#include <hbdocumentloader.h>
|
|
32 |
#include <hbabstractviewitem.h>
|
|
33 |
#include <hblistviewitem.h>
|
|
34 |
#include <hbmessagebox.h>
|
|
35 |
#include <hbgroupbox.h>
|
|
36 |
#include <hbmainwindow.h>
|
|
37 |
#include <hbview.h>
|
|
38 |
#include <hblistview.h>
|
|
39 |
#include <hbaction.h>
|
|
40 |
#include <hbmenu.h>
|
|
41 |
#include <hbframebackground.h>
|
|
42 |
#include <hbparameterlengthlimiter.h>
|
|
43 |
#include <hbdevicenotificationdialog.h>
|
|
44 |
#include <xqaiwrequest.h>
|
|
45 |
#include <xqaiwdecl.h>
|
|
46 |
#include <cntservicescontact.h>
|
|
47 |
|
|
48 |
#include <QFileInfo>
|
|
49 |
#include <QApplication>
|
|
50 |
#include <QTimer>
|
|
51 |
|
|
52 |
const char *CNT_EDIT_XML = ":/xml/contacts_ev.docml";
|
|
53 |
|
|
54 |
CntEditViewPrivate::CntEditViewPrivate() :
|
|
55 |
mModel( NULL ),
|
|
56 |
mImageLabel( NULL ),
|
|
57 |
mThumbnailManager( NULL ),
|
|
58 |
mContact( NULL ),
|
|
59 |
mReq(NULL),
|
|
60 |
mMenu(NULL),
|
|
61 |
mSaveManager(NULL)
|
|
62 |
{
|
|
63 |
mDocument = new CntDocumentLoader;
|
|
64 |
|
|
65 |
bool ok;
|
|
66 |
mDocument->load( CNT_EDIT_XML, &ok );
|
|
67 |
if ( !ok ){
|
|
68 |
qFatal( "Unable to load %S", CNT_EDIT_XML );
|
|
69 |
}
|
|
70 |
mView = static_cast<HbView*>( mDocument->findWidget("view") );
|
|
71 |
|
|
72 |
mListView = static_cast<HbListView*>( mDocument->findWidget("listView") );
|
|
73 |
mListView->setLayoutName("editviewlist");
|
|
74 |
mListView->setItemPixmapCacheEnabled(true);
|
|
75 |
|
|
76 |
HbFrameBackground frame;
|
|
77 |
frame.setFrameGraphicsName("qtg_fr_list_normal");
|
|
78 |
frame.setFrameType(HbFrameDrawer::NinePieces);
|
|
79 |
mListView->listItemPrototype()->setDefaultFrame( frame );
|
|
80 |
|
|
81 |
mHeading = static_cast<CntEditViewHeadingItem*>( mDocument->findWidget("editViewHeading") );
|
|
82 |
mImageLabel = static_cast<CntImageLabel*>(mDocument->findWidget("editViewImage"));
|
|
83 |
|
|
84 |
mSoftkey = new HbAction(Hb::BackNaviAction, mView);
|
|
85 |
mDiscard = static_cast<HbAction*>( mDocument->findObject("cnt:discard") );
|
|
86 |
mDiscard->setParent(mView);
|
|
87 |
|
|
88 |
mSave = static_cast<HbAction*>( mDocument->findObject("cnt:savecontact") );
|
|
89 |
mSave->setParent(mView);
|
|
90 |
|
|
91 |
mDelete = static_cast<HbAction*>( mDocument->findObject("cnt:deletecontact") );
|
|
92 |
mDelete->setParent(mView);
|
|
93 |
|
|
94 |
HbAction* add = static_cast<HbAction*>( mDocument->findObject("cnt:adddetail_options") );
|
|
95 |
add->setParent(mView);
|
|
96 |
|
|
97 |
connect( add, SIGNAL(triggered()), this, SLOT(addDetailItem()) );
|
|
98 |
connect( mDelete, SIGNAL(triggered()), this, SLOT(deleteContact()) );
|
|
99 |
connect( mDiscard, SIGNAL(triggered()), this, SLOT(discardChanges()) );
|
|
100 |
connect( mSave, SIGNAL(triggered()), this, SLOT(saveChanges()) );
|
|
101 |
|
|
102 |
connect( mSoftkey, SIGNAL(triggered()), this, SLOT(showPreviousView()) );
|
|
103 |
connect( mImageLabel, SIGNAL(iconClicked()), this, SLOT(openImageEditor()) );
|
|
104 |
connect( mHeading, SIGNAL(textClicked()), this, SLOT(openNameEditor()) );
|
|
105 |
connect( mHeading, SIGNAL(iconClicked()), this, SLOT(openImageEditor()) );
|
|
106 |
connect( mListView, SIGNAL(activated(const QModelIndex&)), this, SLOT(activated(const QModelIndex&)) );
|
|
107 |
connect( mListView, SIGNAL(longPressed(HbAbstractViewItem*,const QPointF&)), this, SLOT(longPressed(HbAbstractViewItem*,const QPointF&)) );
|
|
108 |
|
|
109 |
// closing the application from task swapper or end key will cause the contact to be saved
|
|
110 |
connect( qApp, SIGNAL(aboutToQuit()), this, SLOT(saveChanges()));
|
|
111 |
}
|
|
112 |
|
|
113 |
CntEditViewPrivate::~CntEditViewPrivate()
|
|
114 |
{
|
|
115 |
mView->deleteLater();
|
|
116 |
|
|
117 |
delete mDocument;
|
|
118 |
mDocument = NULL;
|
|
119 |
delete mModel;
|
|
120 |
mModel = NULL;
|
|
121 |
delete mContact;
|
|
122 |
mContact = NULL;
|
|
123 |
if (mMenu)
|
|
124 |
{
|
|
125 |
delete mMenu;
|
|
126 |
mMenu = NULL;
|
|
127 |
}
|
|
128 |
|
|
129 |
delete mSaveManager;
|
|
130 |
mSaveManager = NULL;
|
|
131 |
}
|
|
132 |
|
|
133 |
void CntEditViewPrivate::setOrientation(Qt::Orientation orientation)
|
|
134 |
{
|
|
135 |
if (orientation == Qt::Vertical)
|
|
136 |
{
|
|
137 |
// reading "portrait" section
|
|
138 |
mDocument->load( CNT_EDIT_XML, "portrait" );
|
|
139 |
}
|
|
140 |
else
|
|
141 |
{
|
|
142 |
// reading "landscape" section
|
|
143 |
mDocument->load( CNT_EDIT_XML, "landscape" );
|
|
144 |
}
|
|
145 |
}
|
|
146 |
|
|
147 |
void CntEditViewPrivate::activate( const CntViewParameters aArgs )
|
|
148 |
{
|
|
149 |
CNT_ENTRY
|
|
150 |
|
|
151 |
mArgs = aArgs;
|
|
152 |
mMgr = &mEngine->viewManager();
|
|
153 |
|
|
154 |
if ( mView->navigationAction() != mSoftkey)
|
|
155 |
{
|
|
156 |
mView->setNavigationAction(mSoftkey);
|
|
157 |
}
|
|
158 |
HbMainWindow* window = mView->mainWindow();
|
|
159 |
if ( window )
|
|
160 |
{
|
|
161 |
connect(window, SIGNAL(viewReady()), this, SLOT(setScrollPosition()) );
|
|
162 |
connect(window, SIGNAL(orientationChanged(Qt::Orientation)), this, SLOT(setOrientation(Qt::Orientation)));
|
|
163 |
setOrientation(window->orientation());
|
|
164 |
}
|
|
165 |
|
|
166 |
QString myCard = mArgs.value( EMyCard ).toString();
|
|
167 |
QString selectedAction = mArgs.value( ESelectedAction ).toString();
|
|
168 |
QVariant contact = aArgs.value( ESelectedContact );
|
|
169 |
|
|
170 |
setSelectedContact( contact.value<QContact>() );
|
|
171 |
mModel = new CntEditViewListModel( *mContact, mEngine->extensionManager() );
|
|
172 |
mListView->setModel( mModel );
|
|
173 |
|
|
174 |
QContactLocalId localId = mContact->localId();
|
|
175 |
QContactManager& cm = mEngine->contactManager(SYMBIAN_BACKEND);
|
|
176 |
QContactLocalId selfContactId = cm.selfContactId();
|
|
177 |
mIsMyCard = ( localId == selfContactId && localId != 0 ) || !myCard.isEmpty();
|
|
178 |
|
|
179 |
if (mIsMyCard)
|
|
180 |
{
|
|
181 |
mSaveManager = new CntSaveManager(CntSaveManager::EMyCard);
|
|
182 |
}
|
|
183 |
else
|
|
184 |
{
|
|
185 |
mSaveManager = new CntSaveManager();
|
|
186 |
}
|
|
187 |
|
|
188 |
if ( mHeading )
|
|
189 |
mHeading->setDetails( mContact, mIsMyCard );
|
|
190 |
|
|
191 |
// if "MyCard", set slightly different heading and options menu
|
|
192 |
if ( mIsMyCard )
|
|
193 |
{
|
|
194 |
mSave->setText(hbTrId("txt_phob_opt_save_my_card"));
|
|
195 |
mDelete->setText(hbTrId("txt_phob_opt_clear_my_card"));
|
|
196 |
HbGroupBox* groupBox = static_cast<HbGroupBox*>( mDocument->findWidget("groupBox") );
|
|
197 |
if ( groupBox )
|
|
198 |
{
|
|
199 |
groupBox->setHeading(hbTrId("txt_phob_subtitle_edit_my_details"));
|
|
200 |
}
|
|
201 |
}
|
|
202 |
|
|
203 |
if ( localId == 0 && !mIsMyCard )
|
|
204 |
{
|
|
205 |
HbMenu* menu = mView->menu();
|
|
206 |
menu->removeAction( mDelete );
|
|
207 |
}
|
|
208 |
|
|
209 |
// don't delete contact which is "MyCard" or not saved yet or both.
|
|
210 |
if ( mIsMyCard && (mContact->details().count() <= 4 || localId == 0) )
|
|
211 |
{
|
|
212 |
mDelete->setEnabled( false );
|
|
213 |
}
|
|
214 |
|
|
215 |
// save and discard disabled if no changes found
|
|
216 |
if ( *mContact == cm.contact( mContact->localId()) )
|
|
217 |
{
|
|
218 |
mDiscard->setEnabled( false );
|
|
219 |
mSave->setEnabled( false );
|
|
220 |
}
|
|
221 |
|
|
222 |
mThumbnailManager = &mEngine->thumbnailManager();
|
|
223 |
connect( mThumbnailManager, SIGNAL(thumbnailReady(QPixmap, void*, int, int)),
|
|
224 |
this, SLOT(thumbnailReady(QPixmap, void*, int, int)) );
|
|
225 |
|
|
226 |
loadAvatar();
|
|
227 |
|
|
228 |
CNT_EXIT
|
|
229 |
}
|
|
230 |
|
|
231 |
void CntEditViewPrivate::deactivate()
|
|
232 |
{
|
|
233 |
}
|
|
234 |
|
|
235 |
void CntEditViewPrivate::openView(CntViewParameters& viewParams)
|
|
236 |
{
|
|
237 |
QList<int> keys = viewParams.keys();
|
|
238 |
for(int i = 0;i < keys.count();i++)
|
|
239 |
{
|
|
240 |
mArgs.insert(keys.at(i), viewParams.value(keys.at(i)));
|
|
241 |
}
|
|
242 |
mMgr->changeView( mArgs );
|
|
243 |
}
|
|
244 |
|
|
245 |
void CntEditViewPrivate::requestRefresh()
|
|
246 |
{
|
|
247 |
mModel->refreshExtensionItems();
|
|
248 |
}
|
|
249 |
|
|
250 |
void CntEditViewPrivate::showPreviousView()
|
|
251 |
{
|
|
252 |
mMgr->back( mArgs, saveChanges() );
|
|
253 |
}
|
|
254 |
|
|
255 |
void CntEditViewPrivate::activated( const QModelIndex& aIndex )
|
|
256 |
{
|
|
257 |
CntEditViewItem* item = mModel->itemAt( aIndex );
|
|
258 |
QVariant type = item->data( ERoleItemType );
|
|
259 |
if ( type == QVariant(ETypeUiExtension) )
|
|
260 |
{
|
|
261 |
item->activated(this);
|
|
262 |
}
|
|
263 |
else if( item->data(ERoleEditorViewId) == ringToneFetcherView )
|
|
264 |
{
|
|
265 |
fetchTone();
|
|
266 |
}
|
|
267 |
else
|
|
268 |
{
|
|
269 |
// open editor view
|
|
270 |
QVariant id = item->data( ERoleEditorViewId );
|
|
271 |
mArgs.insert(EViewId, id.toInt());
|
|
272 |
|
|
273 |
QVariant var;
|
|
274 |
var.setValue(*mContact);
|
|
275 |
mArgs.insert(ESelectedContact, var);
|
|
276 |
mArgs.insert(ESelectedAction, QString() );
|
|
277 |
mMgr->changeView( mArgs );
|
|
278 |
}
|
|
279 |
|
|
280 |
}
|
|
281 |
|
|
282 |
void CntEditViewPrivate::longPressed( HbAbstractViewItem* aItem, const QPointF& aCoords )
|
|
283 |
{
|
|
284 |
CntEditViewItem* item = mModel->itemAt( aItem->modelIndex() );
|
|
285 |
QVariant type = item->data( ERoleItemType );
|
|
286 |
|
|
287 |
// Ui extensions handle the long press by themselves.
|
|
288 |
if ( type == QVariant(ETypeUiExtension) )
|
|
289 |
{
|
|
290 |
item->longPressed( aCoords, this );
|
|
291 |
}
|
|
292 |
// only detail items are able to show context specific menu
|
|
293 |
else
|
|
294 |
{
|
|
295 |
if (mMenu)
|
|
296 |
{
|
|
297 |
delete mMenu;
|
|
298 |
}
|
|
299 |
mMenu = createPopup( aItem->modelIndex(), item );
|
|
300 |
mMenu->setPreferredPos( aCoords );
|
|
301 |
mMenu->setModal( true );
|
|
302 |
mMenu->open( this, SLOT(handleMenuAction(HbAction*)) );
|
|
303 |
}
|
|
304 |
}
|
|
305 |
|
|
306 |
void CntEditViewPrivate::handleMenuAction( HbAction* aAction )
|
|
307 |
{
|
|
308 |
HbMenu *menu = static_cast<HbMenu*>(sender());
|
|
309 |
if ( aAction )
|
|
310 |
{
|
|
311 |
int row = aAction->data().toInt();
|
|
312 |
mIndex = mModel->index(row, 0);
|
|
313 |
CntEditViewItem* item = mModel->itemAt( mIndex );
|
|
314 |
|
|
315 |
switch ( aAction->property("menu").toInt() )
|
|
316 |
{
|
|
317 |
case HbAction::EditRole:
|
|
318 |
{
|
|
319 |
if( item->data(ERoleEditorViewId) == ringToneFetcherView )
|
|
320 |
{
|
|
321 |
fetchTone();
|
|
322 |
menu->close();
|
|
323 |
}
|
|
324 |
else
|
|
325 |
{
|
|
326 |
editDetail( item );
|
|
327 |
}
|
|
328 |
}
|
|
329 |
break;
|
|
330 |
|
|
331 |
case HbAction::NewRole:
|
|
332 |
{
|
|
333 |
addDetail( item );
|
|
334 |
}
|
|
335 |
break;
|
|
336 |
|
|
337 |
case HbAction::DeleteRole:
|
|
338 |
{
|
|
339 |
removeDetail( item, mIndex );
|
|
340 |
}
|
|
341 |
break;
|
|
342 |
|
|
343 |
default:
|
|
344 |
break;
|
|
345 |
}
|
|
346 |
}
|
|
347 |
}
|
|
348 |
|
|
349 |
void CntEditViewPrivate::addDetailItem()
|
|
350 |
{
|
|
351 |
CntViewIdList list;
|
|
352 |
mModel->allInUseFields( list );
|
|
353 |
|
|
354 |
CntDetailPopup::selectDetail( list, this, SLOT(handleAddDetailItem(HbAction*)) );
|
|
355 |
}
|
|
356 |
|
|
357 |
void CntEditViewPrivate::handleAddDetailItem(HbAction *aAction)
|
|
358 |
{
|
|
359 |
CntDetailPopup *popup = static_cast<CntDetailPopup*>(sender());
|
|
360 |
|
|
361 |
if (popup && aAction != popup->actions().first() && popup->selectedItems().count())
|
|
362 |
{
|
|
363 |
int row = popup->selectedItems().first().toInt();
|
|
364 |
QModelIndex index = popup->model()->index(row, 0);
|
|
365 |
int id = popup->model()->data(index, Qt::UserRole).toInt();
|
|
366 |
|
|
367 |
if (id != noView )
|
|
368 |
{
|
|
369 |
mArgs.insert(EViewId, id );
|
|
370 |
|
|
371 |
switch ( id )
|
|
372 |
{
|
|
373 |
case phoneNumberEditorView:
|
|
374 |
case emailEditorView:
|
|
375 |
case urlEditorView:
|
|
376 |
case noteEditorView:
|
|
377 |
mArgs.insert( ESelectedAction, CNT_ADD_ACTION );
|
|
378 |
changeEditorView();
|
|
379 |
break;
|
|
380 |
case addressEditorView:
|
|
381 |
case dateEditorView:
|
|
382 |
case companyEditorView:
|
|
383 |
case familyDetailEditorView:
|
|
384 |
mArgs.insert( ESelectedAction, CNT_FOCUS_ACTION );
|
|
385 |
changeEditorView();
|
|
386 |
break;
|
|
387 |
case ringToneFetcherView:
|
|
388 |
fetchTone();
|
|
389 |
break;
|
|
390 |
default:
|
|
391 |
break;
|
|
392 |
}
|
|
393 |
}
|
|
394 |
}
|
|
395 |
}
|
|
396 |
|
|
397 |
void CntEditViewPrivate::changeEditorView()
|
|
398 |
{
|
|
399 |
QVariant var;
|
|
400 |
var.setValue(*mContact);
|
|
401 |
mArgs.insert(ESelectedContact, var);
|
|
402 |
mMgr->changeView( mArgs );
|
|
403 |
}
|
|
404 |
|
|
405 |
// Call IToneFetch Service
|
|
406 |
void CntEditViewPrivate::fetchTone()
|
|
407 |
{
|
|
408 |
if(mReq)
|
|
409 |
{
|
|
410 |
delete mReq;
|
|
411 |
mReq = 0;
|
|
412 |
}
|
|
413 |
//launch media fetcher
|
|
414 |
mReq = mAppMgr.create(XQI_TONE_FETCH, XQOP_TONE_FETCH, true); // read strings from header file constants
|
|
415 |
if (!mReq)
|
|
416 |
{
|
|
417 |
return;
|
|
418 |
}
|
|
419 |
else
|
|
420 |
{
|
|
421 |
connect(mReq, SIGNAL( requestOk( const QVariant&)), SLOT( ringToneFetchHandleOk(const QVariant&)) );
|
|
422 |
connect(mReq, SIGNAL( requestError( int,const QString&)), SLOT(ringToneFetchHandleError(int,const QString&)) );
|
|
423 |
}
|
|
424 |
|
|
425 |
// Make the request
|
|
426 |
mReq->send();
|
|
427 |
}
|
|
428 |
|
|
429 |
void CntEditViewPrivate::ringToneFetchHandleOk(const QVariant &result)
|
|
430 |
{
|
|
431 |
|
|
432 |
QContactRingtone ringtone = mContact->detail<QContactRingtone>();
|
|
433 |
QUrl ringtoneUrl = ringtone.audioRingtoneUrl();
|
|
434 |
QFileInfo ringtoneFileInfo(ringtoneUrl.toString());
|
|
435 |
QString ringtoneFileName = ringtoneFileInfo.fileName();
|
|
436 |
// Contact can have only one ringtone at a time
|
|
437 |
// remove existing ringtone detail if any
|
|
438 |
|
|
439 |
if(!(ringtone.isEmpty()))
|
|
440 |
{
|
|
441 |
mContact->removeDetail(&ringtone);
|
|
442 |
}
|
|
443 |
|
|
444 |
ringtone.setAudioRingtoneUrl(result.value<QString>());
|
|
445 |
mContact->saveDetail( &ringtone );
|
|
446 |
mModel->updateRingtone();
|
|
447 |
mSave->setEnabled( true );
|
|
448 |
mDiscard->setEnabled( true );
|
|
449 |
|
|
450 |
}
|
|
451 |
|
|
452 |
void CntEditViewPrivate::ringToneFetchHandleError(int errorCode, const QString& errorMessage)
|
|
453 |
{
|
|
454 |
Q_UNUSED(errorCode);
|
|
455 |
Q_UNUSED(errorMessage);
|
|
456 |
|
|
457 |
}
|
|
458 |
|
|
459 |
|
|
460 |
void CntEditViewPrivate::deleteContact()
|
|
461 |
{
|
|
462 |
CNT_ENTRY
|
|
463 |
|
|
464 |
if ( mIsMyCard )
|
|
465 |
{
|
|
466 |
HbMessageBox::question(hbTrId("txt_phob_dialog_remove_all_personal_data_from_my_c"), this,
|
|
467 |
SLOT(handleDeleteContact(int)),
|
|
468 |
HbMessageBox::Yes | HbMessageBox::No);
|
|
469 |
}
|
|
470 |
else
|
|
471 |
{
|
|
472 |
QContactManager& cm = mEngine->contactManager( SYMBIAN_BACKEND );
|
|
473 |
QString name = cm.synthesizedContactDisplayLabel( *mContact );
|
|
474 |
if (name.isEmpty())
|
|
475 |
{
|
|
476 |
name = hbTrId("txt_phob_list_unnamed");
|
|
477 |
}
|
|
478 |
|
|
479 |
HbMessageBox::question(HbParameterLengthLimiter(hbTrId("txt_phob_info_delete_1")).arg(name), this, SLOT(handleDeleteContact(int)),
|
|
480 |
HbMessageBox::Delete | HbMessageBox::Cancel);
|
|
481 |
}
|
|
482 |
|
|
483 |
CNT_EXIT
|
|
484 |
}
|
|
485 |
|
|
486 |
void CntEditViewPrivate::handleDeleteContact(int action)
|
|
487 |
{
|
|
488 |
CNT_ENTRY
|
|
489 |
|
|
490 |
Q_Q(CntEditView);
|
|
491 |
|
|
492 |
if(action == HbMessageBox::Yes || action == HbMessageBox::Delete)
|
|
493 |
{
|
|
494 |
QContactManager& cm = mEngine->contactManager( SYMBIAN_BACKEND );
|
|
495 |
|
|
496 |
disconnect(&cm, SIGNAL(contactsRemoved(const QList<QContactLocalId>&)),
|
|
497 |
this, SLOT(contactDeletedFromOtherSource(const QList<QContactLocalId>&)));
|
|
498 |
emit q->contactRemoved(cm.removeContact( mContact->localId() ));
|
|
499 |
|
|
500 |
mMgr->back( mArgs, true );
|
|
501 |
}
|
|
502 |
|
|
503 |
CNT_EXIT
|
|
504 |
}
|
|
505 |
|
|
506 |
void CntEditViewPrivate::discardChanges()
|
|
507 |
{
|
|
508 |
Q_Q(CntEditView);
|
|
509 |
|
|
510 |
emit q->changesDiscarded();
|
|
511 |
|
|
512 |
// get a fresh one from backend.
|
|
513 |
QContactManager& mgr = mEngine->contactManager(SYMBIAN_BACKEND);
|
|
514 |
setSelectedContact( mgr.contact( mContact->localId()) );
|
|
515 |
|
|
516 |
QVariant var;
|
|
517 |
var.setValue(*mContact);
|
|
518 |
|
|
519 |
mArgs.insert(ESelectedContact, var);
|
|
520 |
|
|
521 |
if ( mArgs.value( EExtraAction ).toString() == CNT_ROOT_ACTION )
|
|
522 |
{
|
|
523 |
mMgr->back( mArgs, true );
|
|
524 |
}
|
|
525 |
else
|
|
526 |
{
|
|
527 |
mMgr->back( mArgs );
|
|
528 |
}
|
|
529 |
|
|
530 |
}
|
|
531 |
|
|
532 |
bool CntEditViewPrivate::saveChanges()
|
|
533 |
{
|
|
534 |
CNT_ENTRY
|
|
535 |
|
|
536 |
Q_Q(CntEditView);
|
|
537 |
|
|
538 |
QContactManager& mgr = mEngine->contactManager(SYMBIAN_BACKEND);
|
|
539 |
QString name = mgr.synthesizedContactDisplayLabel(*mContact);
|
|
540 |
|
|
541 |
if (name.isEmpty())
|
|
542 |
{
|
|
543 |
name = hbTrId("txt_phob_list_unnamed");
|
|
544 |
}
|
|
545 |
|
|
546 |
disconnect(&mgr, SIGNAL(contactsRemoved(const QList<QContactLocalId>&)),
|
|
547 |
this, SLOT(contactDeletedFromOtherSource(const QList<QContactLocalId>&)));
|
|
548 |
CntSaveManager::CntSaveResult result = mSaveManager->saveContact(mContact, &mgr);
|
|
549 |
|
|
550 |
QVariant var;
|
|
551 |
bool backToRoot(false);
|
|
552 |
|
|
553 |
switch (result)
|
|
554 |
{
|
|
555 |
case CntSaveManager::ESaved:
|
|
556 |
emit q->contactUpdated(KCntServicesReturnValueContactSaved);
|
|
557 |
HbDeviceNotificationDialog::notification(QString(),HbParameterLengthLimiter(hbTrId("txt_phob_dpophead_contact_1_saved")).arg(name));
|
|
558 |
var.setValue(*mContact);
|
|
559 |
mArgs.insert(ESelectedContact, var);
|
|
560 |
mArgs.insert(ESelectedAction, CNT_CREATE_ACTION);
|
|
561 |
break;
|
|
562 |
case CntSaveManager::EUpdated:
|
|
563 |
emit q->contactUpdated(KCntServicesReturnValueContactSaved);
|
|
564 |
HbDeviceNotificationDialog::notification(QString(),HbParameterLengthLimiter(hbTrId("txt_phob_dpophead_contacts_1_updated")).arg(name));
|
|
565 |
var.setValue(*mContact);
|
|
566 |
mArgs.insert(ESelectedContact, var);
|
|
567 |
mArgs.insert(ESelectedAction, CNT_EDIT_ACTION);
|
|
568 |
break;
|
|
569 |
case CntSaveManager::EFailed:
|
|
570 |
emit q->contactUpdated(KCntServicesReturnValueContactNotModified);
|
|
571 |
HbDeviceNotificationDialog::notification(QString(),hbTrId("SAVING FAILED!"));
|
|
572 |
break;
|
|
573 |
case CntSaveManager::EDeleted:
|
|
574 |
emit q->contactRemoved(true);
|
|
575 |
backToRoot = true;
|
|
576 |
break;
|
|
577 |
case CntSaveManager::ENothingDone:
|
|
578 |
default:
|
|
579 |
emit q->contactUpdated(KCntServicesReturnValueContactNotModified);
|
|
580 |
break;
|
|
581 |
}
|
|
582 |
|
|
583 |
if ( mArgs.value( EExtraAction ).toString() == CNT_ROOT_ACTION )
|
|
584 |
{
|
|
585 |
backToRoot = true;
|
|
586 |
}
|
|
587 |
|
|
588 |
CNT_EXIT_ARGS(backToRoot)
|
|
589 |
|
|
590 |
return backToRoot;
|
|
591 |
}
|
|
592 |
|
|
593 |
void CntEditViewPrivate::openNameEditor()
|
|
594 |
{
|
|
595 |
QVariant var;
|
|
596 |
var.setValue(*mContact);
|
|
597 |
|
|
598 |
mArgs.insert(EViewId, namesEditorView);
|
|
599 |
mArgs.insert(ESelectedAction, QString());
|
|
600 |
mArgs.insert(ESelectedContact, var);
|
|
601 |
|
|
602 |
mMgr->changeView( mArgs );
|
|
603 |
}
|
|
604 |
|
|
605 |
void CntEditViewPrivate::openImageEditor()
|
|
606 |
{
|
|
607 |
QVariant var;
|
|
608 |
var.setValue(*mContact);
|
|
609 |
|
|
610 |
mArgs.insert(ESelectedContact, var);
|
|
611 |
mArgs.insert(ESelectedAction, QString());
|
|
612 |
mArgs.insert(EViewId, imageEditorView );
|
|
613 |
|
|
614 |
mMgr->changeView( mArgs );
|
|
615 |
}
|
|
616 |
|
|
617 |
void CntEditViewPrivate::loadAvatar()
|
|
618 |
{
|
|
619 |
QList<QContactAvatar> details = mContact->details<QContactAvatar>();
|
|
620 |
for (int i = 0;i < details.count();i++)
|
|
621 |
{
|
|
622 |
QUrl url = details.at(i).imageUrl();
|
|
623 |
if ( url.isValid() )
|
|
624 |
{
|
|
625 |
mThumbnailManager->getThumbnail( ThumbnailManager::ThumbnailLarge, url.toString() );
|
|
626 |
break;
|
|
627 |
}
|
|
628 |
}
|
|
629 |
}
|
|
630 |
|
|
631 |
void CntEditViewPrivate::setScrollPosition()
|
|
632 |
{
|
|
633 |
if ( mArgs.contains(ESelectedDetail) )
|
|
634 |
{
|
|
635 |
QContactDetail d = mArgs.value( ESelectedDetail ).value<QContactDetail>();
|
|
636 |
|
|
637 |
QModelIndex index = mModel->itemIndex( d );
|
|
638 |
if ( index.isValid() )
|
|
639 |
{
|
|
640 |
mListView->scrollTo( index, HbListView::EnsureVisible );
|
|
641 |
}
|
|
642 |
}
|
|
643 |
}
|
|
644 |
|
|
645 |
void CntEditViewPrivate::thumbnailReady( const QPixmap& pixmap, void *data, int id, int error )
|
|
646 |
{
|
|
647 |
Q_UNUSED(data);
|
|
648 |
Q_UNUSED(id);
|
|
649 |
if (!error)
|
|
650 |
{
|
|
651 |
HbIcon icon(pixmap);
|
|
652 |
mHeading->setIcon(icon);
|
|
653 |
|
|
654 |
mImageLabel->clear();
|
|
655 |
mImageLabel->setIcon(pixmap);
|
|
656 |
}
|
|
657 |
}
|
|
658 |
|
|
659 |
HbMenu* CntEditViewPrivate::createPopup( const QModelIndex aIndex, CntEditViewItem* aDetail )
|
|
660 |
{
|
|
661 |
HbMenu* menu = new HbMenu();
|
|
662 |
CntStringMapper* map = new CntStringMapper();
|
|
663 |
QVariant cd = aDetail->data( ERoleContactDetail );
|
|
664 |
QContactDetail detail = cd.value<QContactDetail>();
|
|
665 |
|
|
666 |
QVariant data( aIndex.row() );
|
|
667 |
|
|
668 |
if ( !mModel->isEmptyItem(aDetail) )
|
|
669 |
{
|
|
670 |
// add is supported only on these items:
|
|
671 |
// QContactPhonenumber, QContactOnlineAccount, QContactEmail, QContactUrl and QContactNote
|
|
672 |
QString def = detail.definitionName();
|
|
673 |
if ( def == QContactPhoneNumber::DefinitionName ||
|
|
674 |
def == QContactOnlineAccount::DefinitionName ||
|
|
675 |
def == QContactEmailAddress::DefinitionName ||
|
|
676 |
def == QContactUrl::DefinitionName ||
|
|
677 |
def == QContactNote::DefinitionName )
|
|
678 |
{
|
|
679 |
HbAction* add = menu->addAction(map->getContactEditorAddLocString(detail.definitionName(), ""));
|
|
680 |
add->setProperty( "menu", HbAction::NewRole );
|
|
681 |
add->setData( data );
|
|
682 |
}
|
|
683 |
|
|
684 |
QString context;
|
|
685 |
QString subtype;
|
|
686 |
if ( def == QContactPhoneNumber::DefinitionName )
|
|
687 |
{
|
|
688 |
QContactPhoneNumber number(detail);
|
|
689 |
context = number.contexts().isEmpty() ? QString() : number.contexts().first();
|
|
690 |
subtype = number.subTypes().isEmpty() ? number.definitionName() : number.subTypes().first();
|
|
691 |
}
|
|
692 |
else if ( def == QContactEmailAddress::DefinitionName )
|
|
693 |
{
|
|
694 |
QContactEmailAddress email(detail);
|
|
695 |
context = email.contexts().isEmpty() ? QString() : email.contexts().first();
|
|
696 |
subtype = detail.definitionName();
|
|
697 |
}
|
|
698 |
else if ( def == QContactOnlineAccount::DefinitionName )
|
|
699 |
{
|
|
700 |
QContactOnlineAccount number(detail);
|
|
701 |
context = number.contexts().isEmpty() ? QString() : number.contexts().first();
|
|
702 |
subtype = number.subTypes().isEmpty() ? number.definitionName() : number.subTypes().first();
|
|
703 |
}
|
|
704 |
else if ( def == QContactFamily::DefinitionName )
|
|
705 |
{
|
|
706 |
QStringList fields = aDetail->data(ERoleContactDetailFields).toStringList();
|
|
707 |
subtype = fields.first();
|
|
708 |
}
|
|
709 |
else
|
|
710 |
{
|
|
711 |
context = QString();
|
|
712 |
subtype = detail.definitionName();
|
|
713 |
}
|
|
714 |
|
|
715 |
HbAction* edit = menu->addAction(hbTrId("txt_common_menu_edit"));
|
|
716 |
HbAction* del = menu->addAction(map->getContactEditorDelLocString(subtype, context));
|
|
717 |
edit->setProperty( "menu", HbAction::EditRole );
|
|
718 |
del->setProperty( "menu" , HbAction::DeleteRole );
|
|
719 |
edit->setData( data );
|
|
720 |
del->setData( data );
|
|
721 |
}
|
|
722 |
else
|
|
723 |
{
|
|
724 |
HbAction* add = menu->addAction(map->getContactEditorAddLocString(detail.definitionName(), ""));
|
|
725 |
add->setProperty( "menu", HbAction::NewRole );
|
|
726 |
add->setData( data );
|
|
727 |
}
|
|
728 |
delete map;
|
|
729 |
return menu;
|
|
730 |
}
|
|
731 |
|
|
732 |
void CntEditViewPrivate::addDetail( CntEditViewItem* aDetail )
|
|
733 |
{
|
|
734 |
QVariant id = aDetail->data( ERoleEditorViewId );
|
|
735 |
|
|
736 |
mArgs.insert(EViewId, id.toInt());
|
|
737 |
mArgs.insert(ESelectedAction, CNT_ADD_ACTION );
|
|
738 |
QVariant var;
|
|
739 |
var.setValue(*mContact);
|
|
740 |
|
|
741 |
mArgs.insert(ESelectedContact, var);
|
|
742 |
|
|
743 |
mMgr->changeView( mArgs );
|
|
744 |
}
|
|
745 |
|
|
746 |
void CntEditViewPrivate::editDetail( CntEditViewItem* aDetail )
|
|
747 |
{
|
|
748 |
QVariant id = aDetail->data( ERoleEditorViewId );
|
|
749 |
|
|
750 |
mArgs.insert(EViewId, id.toInt());
|
|
751 |
mArgs.insert(ESelectedAction, QString() );
|
|
752 |
QVariant var;
|
|
753 |
var.setValue(*mContact);
|
|
754 |
|
|
755 |
mArgs.insert(ESelectedContact, var);
|
|
756 |
|
|
757 |
mMgr->changeView( mArgs );
|
|
758 |
}
|
|
759 |
|
|
760 |
void CntEditViewPrivate::removeDetail( CntEditViewItem* aDetail, const QModelIndex& aIndex )
|
|
761 |
{
|
|
762 |
mModel->removeItem( aDetail, aIndex );
|
|
763 |
mSave->setEnabled( true );
|
|
764 |
mDiscard->setEnabled( true );
|
|
765 |
}
|
|
766 |
|
|
767 |
void CntEditViewPrivate::setSelectedContact( QContact aContact )
|
|
768 |
{
|
|
769 |
CNT_ENTRY
|
|
770 |
|
|
771 |
if ( mContact )
|
|
772 |
{
|
|
773 |
delete mContact;
|
|
774 |
mContact = NULL;
|
|
775 |
}
|
|
776 |
mContact = new QContact( aContact );
|
|
777 |
|
|
778 |
QContactManager& cm = mEngine->contactManager( SYMBIAN_BACKEND );
|
|
779 |
connect(&cm, SIGNAL(contactsRemoved(const QList<QContactLocalId>&)),
|
|
780 |
this, SLOT(contactDeletedFromOtherSource(const QList<QContactLocalId>&)), Qt::UniqueConnection);
|
|
781 |
|
|
782 |
CNT_EXIT
|
|
783 |
}
|
|
784 |
|
|
785 |
void CntEditViewPrivate::contactDeletedFromOtherSource(const QList<QContactLocalId>& contactIds)
|
|
786 |
{
|
|
787 |
CNT_ENTRY
|
|
788 |
|
|
789 |
if ( contactIds.contains(mContact->localId()) )
|
|
790 |
{
|
|
791 |
// Do not switch to the previous view immediately. List views are
|
|
792 |
// not updated properly if this is not done in the event loop
|
|
793 |
QTimer::singleShot(0, this, SLOT(showRootView()));
|
|
794 |
}
|
|
795 |
|
|
796 |
CNT_EXIT
|
|
797 |
}
|
|
798 |
|
|
799 |
void CntEditViewPrivate::showRootView()
|
|
800 |
{
|
|
801 |
CNT_ENTRY
|
|
802 |
|
|
803 |
Q_Q(CntEditView);
|
|
804 |
|
|
805 |
emit q->contactRemoved(true);
|
|
806 |
mMgr->back( mArgs, true );
|
|
807 |
|
|
808 |
CNT_EXIT
|
|
809 |
}
|
|
810 |
|
|
811 |
// End of File
|
|
812 |
|