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 |
* Description:
|
|
14 |
*
|
|
15 |
*/
|
|
16 |
|
|
17 |
#include "cntcontactcardview_p.h"
|
|
18 |
#include "cntthumbnailmanager.h"
|
|
19 |
|
|
20 |
#include <QGraphicsLinearLayout>
|
|
21 |
#include <QGraphicsSceneResizeEvent>
|
|
22 |
#include <QStringList>
|
|
23 |
#include <QStandardItemModel>
|
|
24 |
#include <QKeyEvent>
|
|
25 |
#include <QDir>
|
|
26 |
|
|
27 |
#include <cntservicescontact.h>
|
|
28 |
#include <qtcontacts.h>
|
|
29 |
#include <hbapplication.h>
|
|
30 |
#include <hbscrollarea.h>
|
|
31 |
#include <hblabel.h>
|
|
32 |
#include <hbmenu.h>
|
|
33 |
#include <hbview.h>
|
|
34 |
#include <hbtoolbar.h>
|
|
35 |
#include <hbgroupbox.h>
|
|
36 |
#include <hbaction.h>
|
|
37 |
#include <hbmessagebox.h>
|
|
38 |
#include <hbicon.h>
|
|
39 |
#include <hbparameterlengthlimiter.h>
|
|
40 |
#include <hbframeitem.h>
|
|
41 |
#include <hbframedrawer.h>
|
|
42 |
#include <hbselectiondialog.h>
|
|
43 |
#include <hblistview.h>
|
|
44 |
#include <hblistviewitem.h>
|
|
45 |
#include <shareui.h>
|
|
46 |
#include <maptileservice.h> //For maptile processing
|
|
47 |
#include <qversitcontactexporter.h>
|
|
48 |
#include <qversitwriter.h>
|
|
49 |
#include <xqservicerequest.h>
|
|
50 |
#include <QTimer> //Progress indication icon
|
|
51 |
#include <QApplication>
|
|
52 |
|
|
53 |
#include <cntdebug.h>
|
|
54 |
#include "cntcontactcarddatacontainer.h"
|
|
55 |
#include "cntcontactcardheadingitem.h"
|
|
56 |
#include "cntcontactcarddataitem.h"
|
|
57 |
#include "cntcontactcarddetailitem.h"
|
|
58 |
#include "cntcontactcardcontextmenu.h"
|
|
59 |
#include "cntmainwindow.h"
|
|
60 |
#include "cntstringmapper.h"
|
|
61 |
#include "cntdocumentloader.h"
|
|
62 |
#include "cntimagelabel.h"
|
|
63 |
#include "cntimageutility.h"
|
|
64 |
#include "cntfavourite.h"
|
|
65 |
#include "cntactionlauncher.h"
|
|
66 |
#include "cntpresencelistener.h"
|
|
67 |
#include "cntactionpopup.h"
|
|
68 |
#include "cntvcarddetailhandler.h"
|
|
69 |
#include "cntsavemanager.h"
|
|
70 |
#include "cntextensionmanager.h"
|
|
71 |
#include <cntabstractengine.h>
|
|
72 |
#include <cntuiextensionfactory.h>
|
|
73 |
#include <cntuicontactcardextension.h>
|
|
74 |
#include <cntuisocialextension.h>
|
|
75 |
|
|
76 |
#define CNT_MAPTILE_PROGRESS_TIMER 100 // 100 msec
|
|
77 |
#define CNT_UNKNOWN_MAPTILE_STATUS -1
|
|
78 |
|
|
79 |
// A few list items (CntInitialPopulation) will be populated before the first view;
|
|
80 |
// if there are more list items, they will be fetched and added one by one after the
|
|
81 |
// first view has been shown to the user
|
|
82 |
static const int CntListPopulationNotInProgress = -1;
|
|
83 |
static const QEvent::Type ProcessPopulateListEvent = QEvent::User;
|
|
84 |
static const int CntInitialPopulation = 8;
|
|
85 |
|
|
86 |
const char *CNT_CONTACTCARDVIEW_XML = ":/xml/contacts_contactcard.docml";
|
81
|
87 |
const QString CNT_ACTIVITY_CONTACTCARD = "ContactsCardView";
|
72
|
88 |
const char *CNT_MAPTILE_INPROGRESS_ICON = "qtg_anim_small_loading_1";
|
|
89 |
const char *CNT_MAPTILE_SEARCH_STOP_ICON = "qtg_mono_search_stop";
|
|
90 |
/*!
|
|
91 |
Constructor, initialize member variables.
|
|
92 |
\a viewManager is the parent that creates this view. \a parent is a pointer to parent QGraphicsItem (by default this is 0)
|
|
93 |
*/
|
|
94 |
CntContactCardViewPrivate::CntContactCardViewPrivate(bool isTemporary) :
|
|
95 |
QObject(),
|
|
96 |
mContainerLayout(NULL),
|
|
97 |
mContainerWidget(NULL),
|
|
98 |
mContact(NULL),
|
|
99 |
mDataContainer(NULL),
|
|
100 |
mAvatar(NULL),
|
|
101 |
mLoader(NULL),
|
|
102 |
mVCardIcon(NULL),
|
|
103 |
mShareUi(NULL),
|
|
104 |
mAcceptSendKey(true),
|
|
105 |
mPresenceListener(NULL),
|
|
106 |
mIsTemporary(isTemporary),
|
|
107 |
mIsExecutingAction(false),
|
|
108 |
mMyCardId(0),
|
|
109 |
mSaveManager(NULL),
|
|
110 |
mListPopulationProgress(CntListPopulationNotInProgress),
|
81
|
111 |
mStopListPopulation(false),
|
|
112 |
mFetchAvatar(false),
|
|
113 |
mSeparatorlabel(NULL)
|
72
|
114 |
{
|
|
115 |
bool ok;
|
|
116 |
document()->load(CNT_CONTACTCARDVIEW_XML, &ok);
|
|
117 |
if (!ok)
|
|
118 |
{
|
|
119 |
qFatal("Unable to read :/xml/contacts_contactcard.docml");
|
|
120 |
}
|
|
121 |
|
|
122 |
mView = static_cast<HbView*>(document()->findWidget("view"));
|
|
123 |
|
|
124 |
//back button
|
|
125 |
mBackKey = new HbAction(Hb::BackNaviAction, mView);
|
|
126 |
mView->setNavigationAction(mBackKey);
|
|
127 |
connect(mBackKey, SIGNAL(triggered()), this, SLOT(showPreviousView()));
|
|
128 |
|
|
129 |
mProgressTimer = new QTimer(this);
|
|
130 |
mProgressTimer->setSingleShot(true);
|
|
131 |
connect(mProgressTimer, SIGNAL(timeout()),this, SLOT(updateSpinningIndicator()));
|
|
132 |
|
|
133 |
mMaptile = new MapTileService;
|
|
134 |
if( mMaptile->isLocationFeatureEnabled(MapTileService::AppTypeContacts) )
|
|
135 |
{
|
|
136 |
//Connect for maptile status evenet
|
|
137 |
QObject::connect( mMaptile, SIGNAL(maptileFetchingStatusUpdate(int,
|
|
138 |
int,int)),this,SLOT(mapTileStatusReceived(int,int,int)));
|
|
139 |
}
|
|
140 |
|
|
141 |
mScrollArea = static_cast<HbScrollArea*>(document()->findWidget(QString("scrollArea")));
|
|
142 |
mHeadingItem = static_cast<CntContactCardHeadingItem*>(document()->findWidget(QString("cnt_contactcard_heading")));
|
|
143 |
mImageLabel = static_cast<CntImageLabel*>(document()->findWidget("cnt_contactcard_image"));
|
|
144 |
|
|
145 |
// presence listener
|
|
146 |
mPresenceListener = new CntPresenceListener();
|
|
147 |
connect(mPresenceListener, SIGNAL(fullPresenceUpdated(bool)), mHeadingItem, SLOT(setOnlineStatus(bool)));
|
|
148 |
connect(mPresenceListener, SIGNAL(accountPresenceUpdated(const QString&, bool)),
|
|
149 |
this, SLOT(updateItemPresence(const QString&, bool)));
|
|
150 |
|
|
151 |
|
|
152 |
mSaveManager = new CntSaveManager();
|
|
153 |
}
|
|
154 |
|
|
155 |
/*!
|
|
156 |
Destructor
|
|
157 |
*/
|
|
158 |
CntContactCardViewPrivate::~CntContactCardViewPrivate()
|
|
159 |
{
|
|
160 |
// stop the progress timer
|
|
161 |
if ( mProgressTimer && mProgressTimer->isActive())
|
|
162 |
{
|
|
163 |
mProgressTimer->stop();
|
|
164 |
}
|
|
165 |
|
81
|
166 |
if (mContainerLayout)
|
72
|
167 |
{
|
81
|
168 |
// Remove the separator obj from layout
|
|
169 |
mContainerLayout->removeItem(mSeparatorlabel);
|
72
|
170 |
}
|
81
|
171 |
delete mSeparatorlabel;
|
72
|
172 |
|
|
173 |
mView->deleteLater();
|
|
174 |
|
|
175 |
delete mContact;
|
|
176 |
mContact = NULL;
|
|
177 |
|
|
178 |
delete mDataContainer;
|
|
179 |
mDataContainer = NULL;
|
|
180 |
|
|
181 |
delete mAvatar;
|
|
182 |
mAvatar = NULL;
|
|
183 |
|
|
184 |
delete mLoader;
|
|
185 |
mLoader = NULL;
|
|
186 |
|
|
187 |
if (mVCardIcon)
|
|
188 |
{
|
|
189 |
delete mVCardIcon;
|
|
190 |
mVCardIcon = NULL;
|
|
191 |
}
|
|
192 |
|
|
193 |
if (mShareUi)
|
|
194 |
{
|
|
195 |
delete mShareUi;
|
|
196 |
mShareUi = NULL;
|
|
197 |
}
|
|
198 |
|
|
199 |
delete mPresenceListener;
|
|
200 |
mPresenceListener = NULL;
|
|
201 |
|
|
202 |
delete mMaptile;
|
|
203 |
mMaptile = NULL;
|
|
204 |
|
|
205 |
//delete maptile label memory
|
|
206 |
for ( int index = 0; index < mMaptileLabelList.count(); index++ )
|
|
207 |
{
|
|
208 |
if( mMaptileLabelList[index] )
|
|
209 |
{
|
|
210 |
delete mMaptileLabelList[index];
|
|
211 |
mMaptileLabelList[index] = NULL ;
|
|
212 |
}
|
|
213 |
}
|
|
214 |
|
|
215 |
delete mSaveManager;
|
|
216 |
mSaveManager = NULL;
|
|
217 |
}
|
|
218 |
|
|
219 |
/*!
|
|
220 |
Activates a previous view
|
|
221 |
*/
|
|
222 |
void CntContactCardViewPrivate::showPreviousView()
|
|
223 |
{
|
|
224 |
// stop list population, if it is still in progress
|
|
225 |
mStopListPopulation = true;
|
|
226 |
|
|
227 |
int returnValue = KCntServicesReturnValueContactNotModified;
|
|
228 |
|
|
229 |
//save the contact if avatar has been changed.
|
|
230 |
QContact contact = contactManager()->contact(mContact->localId());
|
|
231 |
if ( contact != *mContact && contactManager()->error() == QContactManager::NoError)
|
|
232 |
{
|
|
233 |
disconnect(contactManager(), SIGNAL(contactsRemoved(const QList<QContactLocalId>&)),
|
|
234 |
this, SLOT(contactDeletedFromOtherSource(const QList<QContactLocalId>&)));
|
|
235 |
CntSaveManager::CntSaveResult result = mSaveManager->saveContact(mContact, contactManager());
|
|
236 |
|
|
237 |
if (result != CntSaveManager::ENothingDone)
|
|
238 |
returnValue = KCntServicesReturnValueContactSaved;
|
|
239 |
else
|
|
240 |
returnValue = KCntServicesReturnValueContactNotModified;
|
|
241 |
}
|
|
242 |
|
|
243 |
emit backPressed(returnValue);
|
|
244 |
|
|
245 |
mViewManager->back( mArgs );
|
|
246 |
}
|
|
247 |
|
|
248 |
/*!
|
|
249 |
Activates the root view
|
|
250 |
*/
|
|
251 |
void CntContactCardViewPrivate::showRootView()
|
|
252 |
{
|
|
253 |
// stop list population, if it is still in progress
|
|
254 |
mStopListPopulation = true;
|
|
255 |
|
|
256 |
mViewManager->back( mArgs, true );
|
|
257 |
}
|
|
258 |
|
|
259 |
/*!
|
|
260 |
Handle extension action (tapping on activity stream button)
|
|
261 |
*/
|
|
262 |
void CntContactCardViewPrivate::handleExtensionAction()
|
|
263 |
{
|
|
264 |
CNT_ENTRY
|
|
265 |
CntExtensionManager& mgr = mEngine->extensionManager();
|
|
266 |
for (int i = 0; i < mgr.pluginCount(); i++)
|
|
267 |
{
|
|
268 |
CntUiSocialExtension* socialExtension = mgr.pluginAt(i)->socialExtension();
|
|
269 |
if (socialExtension)
|
|
270 |
{
|
|
271 |
CntViewParameters params;
|
|
272 |
socialExtension->handleToolbarAction(params);
|
|
273 |
if (params.count())
|
|
274 |
{
|
|
275 |
QList<int> keys = params.keys();
|
|
276 |
for (int j = 0; j < keys.count(); j++)
|
|
277 |
{
|
|
278 |
mArgs.insert(keys.at(j), params.value(keys.at(j)));
|
|
279 |
}
|
|
280 |
mViewManager->changeView(mArgs);
|
|
281 |
break;
|
|
282 |
}
|
|
283 |
}
|
|
284 |
}
|
|
285 |
|
|
286 |
CNT_EXIT
|
|
287 |
}
|
|
288 |
|
|
289 |
/*
|
|
290 |
Activates a default view and setup name label texts
|
|
291 |
*/
|
|
292 |
void CntContactCardViewPrivate::activate(const CntViewParameters aArgs)
|
|
293 |
{
|
|
294 |
CNT_ENTRY
|
81
|
295 |
|
72
|
296 |
mArgs = aArgs;
|
|
297 |
|
|
298 |
mViewManager = &mEngine->viewManager();
|
|
299 |
mThumbnailManager = &mEngine->thumbnailManager();
|
|
300 |
connect(mThumbnailManager, SIGNAL(thumbnailReady(QPixmap, void*, int, int)),
|
|
301 |
this, SLOT(thumbnailReady(QPixmap, void*, int, int)));
|
|
302 |
|
|
303 |
HbMainWindow* window = mView->mainWindow();
|
|
304 |
if (window)
|
|
305 |
{
|
|
306 |
connect(window, SIGNAL(orientationChanged(Qt::Orientation)), this, SLOT(setOrientation(Qt::Orientation)));
|
|
307 |
window->installEventFilter(this);
|
|
308 |
|
|
309 |
setOrientation(window->orientation());
|
|
310 |
}
|
|
311 |
|
|
312 |
qApp->installEventFilter(this);
|
|
313 |
|
|
314 |
QContact contact = aArgs.value(ESelectedContact).value<QContact>();
|
|
315 |
mContact = new QContact( contact );
|
|
316 |
|
|
317 |
//my card
|
|
318 |
mMyCardId = contactManager()->selfContactId();
|
|
319 |
|
|
320 |
populateHeadingItem();
|
|
321 |
|
|
322 |
populateListItems();
|
|
323 |
|
|
324 |
bool myCard = mContact->localId() == mMyCardId;
|
|
325 |
if (myCard)
|
|
326 |
{
|
|
327 |
mView->menu()->clearActions();
|
|
328 |
mView->toolBar()->removeAction(static_cast<HbAction*>(document()->findObject(QString("cnt:history"))));
|
|
329 |
}
|
|
330 |
else
|
|
331 |
{
|
|
332 |
mView->toolBar()->removeAction(static_cast<HbAction*>(document()->findObject(QString("cnt:sendMyCard"))));
|
|
333 |
}
|
|
334 |
if (mIsTemporary)
|
|
335 |
{
|
|
336 |
mView->menu()->clearActions();
|
|
337 |
mView->toolBar()->clearActions();
|
|
338 |
mView->toolBar()->addAction(static_cast<HbAction*>(document()->findObject(QString("cnt:addtocontact"))));
|
|
339 |
}
|
|
340 |
|
|
341 |
document()->findWidget("viewToolbar")->setParent(mView);
|
|
342 |
document()->findWidget("viewMenu")->setParent(mView);
|
|
343 |
|
|
344 |
// Menu items
|
|
345 |
connectAction("cnt:sendbusinesscard", SLOT(sendBusinessCard()));
|
|
346 |
connectAction("cnt:deletecontact", SLOT(deleteContact()));
|
|
347 |
connectAction("cnt:setasfavorite", SLOT(setAsFavorite()));
|
|
348 |
connectAction("cnt:removefromfavorite", SLOT(removeFromFavorite()));
|
|
349 |
connectAction("cnt:placecontacttohs", SLOT(sendToHs()));
|
|
350 |
connectAction("cnt:edit", SLOT(editContact()));
|
|
351 |
connectAction("cnt:history", SLOT(viewHistory()));
|
|
352 |
connectAction("cnt:sendMyCard", SLOT(sendBusinessCard()));
|
|
353 |
connectAction("cnt:addtocontact", SLOT(onAddedToContacts()));
|
|
354 |
connectAction("cnt:activityStream", SLOT(handleExtensionAction()));
|
|
355 |
|
|
356 |
CntExtensionManager& mgr = mEngine->extensionManager();
|
|
357 |
if (mgr.pluginCount())
|
|
358 |
{
|
|
359 |
for (int i = 0; i < mgr.pluginCount(); i++)
|
|
360 |
{
|
|
361 |
CntUiSocialExtension* socialExtension = mgr.pluginAt(i)->socialExtension();
|
|
362 |
if (socialExtension)
|
|
363 |
{
|
|
364 |
static_cast<HbAction*> (document()->findObject("cnt:activityStream"))->setEnabled(true);
|
|
365 |
break;
|
|
366 |
}
|
|
367 |
else
|
|
368 |
{
|
|
369 |
static_cast<HbAction*> (document()->findObject("cnt:activityStream"))->setEnabled(false);
|
|
370 |
}
|
|
371 |
}
|
|
372 |
}
|
|
373 |
else
|
|
374 |
{
|
|
375 |
static_cast<HbAction*> (document()->findObject("cnt:activityStream"))->setEnabled(false);
|
|
376 |
}
|
|
377 |
|
|
378 |
|
|
379 |
connect(contactManager(), SIGNAL(contactsRemoved(const QList<QContactLocalId>&)),
|
|
380 |
this, SLOT(contactDeletedFromOtherSource(const QList<QContactLocalId>&)));
|
|
381 |
|
|
382 |
emit viewActivated( mViewManager, aArgs );
|
|
383 |
|
|
384 |
CNT_EXIT
|
|
385 |
}
|
|
386 |
|
81
|
387 |
QString CntContactCardViewPrivate::externalize(QDataStream &stream)
|
|
388 |
{
|
|
389 |
// set activity parameters
|
|
390 |
CntViewParameters viewParameters;
|
|
391 |
viewParameters.insert(EViewId, mArgs.value(EViewId).toInt());
|
|
392 |
|
|
393 |
if (mArgs.value(ESelectedContact).isValid())
|
|
394 |
{
|
|
395 |
QContact contact = mArgs.value(ESelectedContact).value<QContact>();
|
|
396 |
viewParameters.insert(ESelectedContactId, contact.localId());
|
|
397 |
}
|
|
398 |
if (mArgs.value(ESelectedGroupContact).isValid())
|
|
399 |
{
|
|
400 |
QContact contact = mArgs.value(ESelectedGroupContact).value<QContact>();
|
|
401 |
viewParameters.insert(ESelectedGroupContactId, QVariant(contact.localId()));
|
|
402 |
}
|
|
403 |
if (mArgs.value(EMyCard).isValid())
|
|
404 |
{
|
|
405 |
viewParameters.insert(EMyCard, mArgs.value(EMyCard));
|
|
406 |
}
|
|
407 |
if (mArgs.value(EExtraAction).isValid())
|
|
408 |
{
|
|
409 |
viewParameters.insert(EExtraAction, mArgs.value(EExtraAction));
|
|
410 |
}
|
|
411 |
|
|
412 |
stream << viewParameters;
|
|
413 |
|
|
414 |
return CNT_ACTIVITY_CONTACTCARD;
|
|
415 |
}
|
|
416 |
|
|
417 |
bool CntContactCardViewPrivate::internalize(QDataStream &stream, CntViewParameters &viewParameters)
|
|
418 |
{
|
|
419 |
CntViewParameters tempViewParameters;
|
|
420 |
stream >> tempViewParameters;
|
|
421 |
|
|
422 |
viewParameters.insert(EViewId, tempViewParameters.value(EViewId));
|
|
423 |
|
|
424 |
if (tempViewParameters.value(ESelectedContactId).isValid())
|
|
425 |
{
|
|
426 |
QContact contact = contactManager()->contact(tempViewParameters.value(ESelectedContactId).toInt());
|
|
427 |
if (contact.isEmpty())
|
|
428 |
{
|
|
429 |
// a contact has been deleted.
|
|
430 |
return false;
|
|
431 |
}
|
|
432 |
else
|
|
433 |
{
|
|
434 |
QVariant var;
|
|
435 |
var.setValue(contact);
|
|
436 |
viewParameters.insert(ESelectedContact, var);
|
|
437 |
}
|
|
438 |
}
|
|
439 |
if (tempViewParameters.value(ESelectedGroupContactId).isValid())
|
|
440 |
{
|
|
441 |
QVariant var;
|
|
442 |
var.setValue(contactManager()->contact(tempViewParameters.value(ESelectedGroupContactId).toInt()));
|
|
443 |
viewParameters.insert(ESelectedGroupContact, var);
|
|
444 |
}
|
|
445 |
if (tempViewParameters.value(EMyCard).isValid())
|
|
446 |
{
|
|
447 |
viewParameters.insert(EMyCard, tempViewParameters.value(EMyCard));
|
|
448 |
}
|
|
449 |
if (tempViewParameters.value(EMyCard).isValid())
|
|
450 |
{
|
|
451 |
viewParameters.insert(EExtraAction, tempViewParameters.value(EExtraAction));
|
|
452 |
}
|
|
453 |
|
|
454 |
return true;
|
|
455 |
}
|
|
456 |
|
72
|
457 |
void CntContactCardViewPrivate::populateHeadingItem()
|
|
458 |
{
|
|
459 |
CNT_ENTRY
|
|
460 |
|
|
461 |
Q_ASSERT(mHeadingItem != NULL && mContact != NULL);
|
|
462 |
|
|
463 |
mHeadingItem->setDetails(mContact);
|
|
464 |
|
|
465 |
bool myCard = mContact->localId() == mMyCardId;
|
|
466 |
|
|
467 |
if (!mIsTemporary)
|
|
468 |
{
|
|
469 |
connect(mHeadingItem, SIGNAL(passLongPressed(const QPointF&)), this, SLOT(drawMenu(const QPointF&)), Qt::UniqueConnection);
|
|
470 |
connect(mHeadingItem, SIGNAL(passShortPressed(const QPointF&)), this, SLOT(doChangeImage()), Qt::UniqueConnection);
|
|
471 |
connect(mImageLabel, SIGNAL(iconClicked()), this, SLOT(doChangeImage()), Qt::UniqueConnection);
|
|
472 |
connect(mImageLabel, SIGNAL(iconLongPressed(const QPointF&)), this, SLOT(drawMenu(const QPointF&)), Qt::UniqueConnection);
|
|
473 |
}
|
|
474 |
else
|
|
475 |
{
|
|
476 |
mHeadingItem->ungrabGesture(Qt::TapGesture);
|
|
477 |
mImageLabel->ungrabGesture(Qt::TapGesture);
|
|
478 |
}
|
81
|
479 |
|
72
|
480 |
bool online;
|
|
481 |
mInitiialPrecenceData = mPresenceListener->initialPresences(*mContact, online);
|
|
482 |
mHeadingItem->setOnlineStatus(online);
|
|
483 |
|
81
|
484 |
if (!myCard)
|
|
485 |
{
|
72
|
486 |
bool setAsFavorite = CntFavourite::isMemberOfFavouriteGroup(contactManager(), mContact);
|
|
487 |
mHeadingItem->setFavoriteStatus(setAsFavorite); // if contact is part of favourites group
|
|
488 |
static_cast<HbAction *>(document()->findObject("cnt:setasfavorite"))->setVisible( !setAsFavorite );
|
|
489 |
static_cast<HbAction *>(document()->findObject("cnt:removefromfavorite"))->setVisible( setAsFavorite );
|
|
490 |
}
|
|
491 |
|
|
492 |
// avatar
|
|
493 |
QList<QContactAvatar> details = mContact->details<QContactAvatar>();
|
|
494 |
for (int i = 0;i < details.count();i++)
|
|
495 |
{
|
|
496 |
if (details.at(i).imageUrl().isValid())
|
|
497 |
{
|
81
|
498 |
if (!mAvatar || *mAvatar != details.at(i))
|
72
|
499 |
{
|
|
500 |
delete mAvatar;
|
|
501 |
mAvatar = new QContactAvatar(details.at(i));
|
81
|
502 |
mFetchAvatar = true;
|
72
|
503 |
}
|
|
504 |
break;
|
|
505 |
}
|
|
506 |
}
|
|
507 |
|
|
508 |
CNT_EXIT
|
|
509 |
}
|
|
510 |
|
|
511 |
void CntContactCardViewPrivate::populateListItems()
|
|
512 |
{
|
|
513 |
CNT_ENTRY
|
|
514 |
|
|
515 |
Q_ASSERT(mContact != NULL && mScrollArea != NULL);
|
|
516 |
|
81
|
517 |
if (mListPopulationProgress == CntListPopulationNotInProgress)
|
|
518 |
{
|
72
|
519 |
mListPopulationProgress = 0;
|
|
520 |
|
81
|
521 |
if (!mDataContainer)
|
|
522 |
{
|
72
|
523 |
mDataContainer = new CntContactCardDataContainer(
|
|
524 |
mMaptile,
|
|
525 |
mEngine->extensionManager(),
|
|
526 |
mView->mainWindow()->orientation());
|
|
527 |
}
|
|
528 |
|
|
529 |
// fill the data container with contact details
|
|
530 |
mDataContainer->setContactData(mContact);
|
|
531 |
|
81
|
532 |
if (mContainerLayout)
|
|
533 |
{
|
|
534 |
// Remove the separator obj from previous layout
|
|
535 |
// It needs to be reused
|
|
536 |
mContainerLayout->removeItem(mSeparatorlabel);
|
72
|
537 |
}
|
81
|
538 |
// initialize
|
|
539 |
mScrollArea->setScrollDirections(Qt::Vertical);
|
|
540 |
|
|
541 |
mContainerWidget = new QGraphicsWidget();
|
|
542 |
mScrollArea->setContentWidget(mContainerWidget); // takes ownership.
|
|
543 |
|
|
544 |
mContainerLayout = new QGraphicsLinearLayout(Qt::Vertical);
|
|
545 |
mContainerLayout->setContentsMargins(0, 0, 0, 0);
|
|
546 |
mContainerLayout->setSpacing(0);
|
|
547 |
mContainerLayout->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
|
|
548 |
|
|
549 |
mContainerWidget->setLayout(mContainerLayout); // takes ownership.
|
72
|
550 |
}
|
|
551 |
|
|
552 |
|
|
553 |
do {
|
81
|
554 |
if (mListPopulationProgress == mDataContainer->itemCount() || mStopListPopulation)
|
|
555 |
{
|
|
556 |
if (!mStopListPopulation && mFetchAvatar)
|
|
557 |
{
|
|
558 |
// fetch the avatar if it has not yet been fetched
|
|
559 |
mFetchAvatar = false;
|
|
560 |
mThumbnailManager->getThumbnail(ThumbnailManager::ThumbnailLarge, mAvatar->imageUrl().toString());
|
|
561 |
}
|
72
|
562 |
// population of the list has completed
|
|
563 |
mListPopulationProgress = CntListPopulationNotInProgress;
|
|
564 |
mStopListPopulation = false;
|
|
565 |
disconnect(mView->mainWindow(), SIGNAL(viewReady()), this, SLOT(populateListItems()));
|
81
|
566 |
CNT_EXIT_ARGS("population completed")
|
72
|
567 |
return;
|
|
568 |
}
|
|
569 |
|
|
570 |
CntContactCardDataItem* dataItem = mDataContainer->dataItem(mListPopulationProgress);
|
|
571 |
int pos = dataItem->position();
|
|
572 |
|
|
573 |
// communication methods
|
|
574 |
if (pos < CntContactCardDataItem::ESeparator && dataItem->isFocusable())
|
|
575 |
{
|
|
576 |
CntContactCardDetailItem* item = new CntContactCardDetailItem(mListPopulationProgress, mContainerWidget);
|
|
577 |
|
|
578 |
connect(item, SIGNAL(clicked()), this, SLOT(onItemActivated()));
|
|
579 |
|
|
580 |
if (!mIsTemporary)
|
|
581 |
{
|
|
582 |
connect(item, SIGNAL(longPressed(const QPointF&)), this, SLOT(onLongPressed(const QPointF&)));
|
|
583 |
}
|
|
584 |
|
|
585 |
if (mContact->isPreferredDetail(dataItem->action(), dataItem->detail()))
|
|
586 |
{
|
|
587 |
dataItem->setSecondaryIcon(HbIcon("qtg_mono_favourites"));
|
|
588 |
mPreferredItems.insert(dataItem->action(), item);
|
|
589 |
}
|
|
590 |
|
|
591 |
if (dataItem->detail().definitionName() == QContactOnlineAccount::DefinitionName)
|
|
592 |
{
|
|
593 |
for (int i = 0;i < mInitiialPrecenceData.keys().count();i++)
|
|
594 |
{
|
|
595 |
QString fullAccount = mInitiialPrecenceData.keys().at(i);
|
|
596 |
QContactOnlineAccount account = dataItem->detail();
|
|
597 |
QString currentFullAccount = account.serviceProvider() + ':' + account.accountUri();
|
|
598 |
if (fullAccount == currentFullAccount)
|
|
599 |
{
|
|
600 |
if (mInitiialPrecenceData.values().at(i))
|
|
601 |
{
|
|
602 |
dataItem->setSecondaryIcon(HbIcon("qtg_small_online"));
|
|
603 |
}
|
|
604 |
mPresenceItems.insert(fullAccount, item);
|
|
605 |
break;
|
|
606 |
}
|
|
607 |
}
|
|
608 |
}
|
|
609 |
|
|
610 |
item->setDetails(dataItem);
|
|
611 |
mContainerLayout->addItem(item);
|
|
612 |
}
|
|
613 |
|
|
614 |
// separator
|
|
615 |
else if (pos == CntContactCardDataItem::ESeparator)
|
81
|
616 |
{
|
|
617 |
if (!mSeparatorlabel)
|
|
618 |
{
|
|
619 |
HbFrameItem* frameItem = new HbFrameItem(QString("qtg_fr_list_separator"), HbFrameDrawer::NinePieces);
|
|
620 |
mSeparatorlabel = static_cast<HbLabel*>(document()->findWidget(QString("separator")));
|
|
621 |
mSeparatorlabel->setPlainText(dataItem->titleText());
|
|
622 |
mSeparatorlabel->setBackgroundItem(frameItem); // takes ownership
|
|
623 |
mSeparatorlabel->setParent(this);
|
|
624 |
}
|
|
625 |
mContainerLayout->addItem(mSeparatorlabel);
|
72
|
626 |
}
|
|
627 |
|
|
628 |
// details
|
|
629 |
else
|
|
630 |
{
|
|
631 |
//map support (image only)
|
|
632 |
if (pos >= CntContactCardDataItem::EAddress && pos <= CntContactCardDataItem::EAddressWork && !dataItem->icon().isNull())
|
|
633 |
{
|
|
634 |
int addressType = MapTileService::AddressPreference;
|
|
635 |
|
|
636 |
if( pos == CntContactCardDataItem::EAddressHome )
|
|
637 |
{
|
|
638 |
addressType = MapTileService::AddressHome;
|
|
639 |
}
|
|
640 |
else if( pos == CntContactCardDataItem::EAddressWork )
|
|
641 |
{
|
|
642 |
addressType = MapTileService::AddressWork;
|
|
643 |
}
|
|
644 |
|
|
645 |
HbLabel* maptileLabel = loadMaptileLabel( addressType );
|
|
646 |
setMaptileLabel( maptileLabel, dataItem->icon() );
|
|
647 |
mContainerLayout->addItem( maptileLabel );
|
|
648 |
mMaptileLabelList.insert( addressType, maptileLabel );
|
|
649 |
}
|
|
650 |
//other details
|
|
651 |
else
|
|
652 |
{
|
|
653 |
CntContactCardDetailItem* item = new CntContactCardDetailItem(mListPopulationProgress, mContainerWidget, false);
|
|
654 |
|
|
655 |
//To check whether maptile status icon is set with the address
|
|
656 |
if( ( dataItem->titleText() == hbTrId("txt_phob_formlabel_address") ||
|
|
657 |
dataItem->titleText() == hbTrId("txt_phob_formlabel_address_home")||
|
|
658 |
dataItem->titleText() == hbTrId("txt_phob_formlabel_address_work") ) &&
|
|
659 |
dataItem->secondaryIcon().iconName() == QString(CNT_MAPTILE_INPROGRESS_ICON) )
|
|
660 |
|
|
661 |
{
|
|
662 |
//Information for displaying maptile fetching progress bar.
|
|
663 |
//Memory will be deleted from the queue.
|
|
664 |
CntContactCardMapTileDetail* detail = new CntContactCardMapTileDetail;
|
|
665 |
detail->mContactId = mContact->localId();
|
|
666 |
|
|
667 |
if( dataItem->titleText() == hbTrId("txt_phob_formlabel_address") )
|
|
668 |
{
|
|
669 |
detail->mAddressType = MapTileService::AddressPreference;
|
|
670 |
}
|
|
671 |
else if ( dataItem->titleText() == hbTrId("txt_phob_formlabel_address_home") )
|
|
672 |
{
|
|
673 |
detail->mAddressType = MapTileService::AddressHome;
|
|
674 |
}
|
|
675 |
else if( dataItem->titleText() == hbTrId("txt_phob_formlabel_address_work") )
|
|
676 |
{
|
|
677 |
detail->mAddressType = MapTileService::AddressWork;
|
|
678 |
}
|
|
679 |
|
|
680 |
detail->mProgressCount = 0;
|
|
681 |
detail->mDetailItem = item;
|
|
682 |
detail->maptileStatus = CNT_UNKNOWN_MAPTILE_STATUS;
|
|
683 |
mAddressList.append( detail );
|
|
684 |
|
|
685 |
//Update the spinning indicator
|
|
686 |
updateSpinningIndicator();
|
|
687 |
|
|
688 |
}
|
|
689 |
item->setDetails(dataItem);
|
|
690 |
mContainerLayout->addItem(item);
|
|
691 |
}
|
|
692 |
}
|
|
693 |
|
|
694 |
++mListPopulationProgress;
|
|
695 |
} while (mListPopulationProgress < CntInitialPopulation);
|
|
696 |
|
81
|
697 |
if (mListPopulationProgress <= CntInitialPopulation)
|
|
698 |
{
|
72
|
699 |
connect(mView->mainWindow(), SIGNAL(viewReady()), this, SLOT(populateListItems()));
|
81
|
700 |
}
|
|
701 |
else
|
|
702 |
{
|
72
|
703 |
disconnect(mView->mainWindow(), SIGNAL(viewReady()), this, SLOT(populateListItems()));
|
|
704 |
HbApplication::instance()->postEvent(this, new QEvent(ProcessPopulateListEvent));
|
81
|
705 |
|
|
706 |
if (mFetchAvatar)
|
|
707 |
{
|
|
708 |
// initial view has been shown, so starting fetching the avatar
|
|
709 |
mFetchAvatar = false;
|
|
710 |
mThumbnailManager->getThumbnail(ThumbnailManager::ThumbnailLarge, mAvatar->imageUrl().toString());
|
|
711 |
}
|
72
|
712 |
}
|
|
713 |
|
|
714 |
CNT_EXIT
|
|
715 |
}
|
|
716 |
|
|
717 |
/*
|
|
718 |
Connects the action with a slot and also sets the view as the parent for the action.
|
|
719 |
*/
|
|
720 |
void CntContactCardViewPrivate::connectAction(QString actionName, const char* slot)
|
|
721 |
{
|
|
722 |
HbAction *action = qobject_cast<HbAction *>(document()->findObject(actionName));
|
81
|
723 |
if (action)
|
|
724 |
{
|
72
|
725 |
action->setParent(mView);
|
81
|
726 |
if (slot != NULL)
|
|
727 |
{
|
72
|
728 |
connect(action, SIGNAL(triggered()), this, slot);
|
|
729 |
}
|
|
730 |
}
|
|
731 |
}
|
|
732 |
|
|
733 |
/*
|
|
734 |
Updates the maptile fetching spinning indicator icon
|
|
735 |
*/
|
|
736 |
void CntContactCardViewPrivate::updateSpinningIndicator()
|
|
737 |
{
|
81
|
738 |
CNT_ENTRY
|
|
739 |
|
|
740 |
// Check all address details( Preferred, Home, Work )
|
|
741 |
for (int index = 0 ; index < mAddressList.count();)
|
72
|
742 |
{
|
81
|
743 |
// Maptile status not received update the rotating icon
|
|
744 |
if (mAddressList[index]->maptileStatus == CNT_UNKNOWN_MAPTILE_STATUS)
|
72
|
745 |
{
|
81
|
746 |
QString iconName("qtg_anim_small_loading_");
|
|
747 |
mAddressList[index]->mProgressCount = mAddressList[index]->mProgressCount % 10 + 1;
|
|
748 |
iconName.append(QVariant(mAddressList[index]->mProgressCount).toString());
|
72
|
749 |
|
81
|
750 |
HbIcon icon(iconName);
|
|
751 |
mAddressList[index]->mDetailItem->setSecondaryIconItem(icon);
|
|
752 |
mAddressList[index]->mDetailItem->update();
|
|
753 |
mProgressTimer->start(CNT_MAPTILE_PROGRESS_TIMER);
|
|
754 |
index++;
|
72
|
755 |
}
|
|
756 |
else
|
|
757 |
{
|
81
|
758 |
// Maptile status received. Show the maptile image if available
|
72
|
759 |
MapTileService::AddressType sourceAddressType =
|
81
|
760 |
static_cast <MapTileService::AddressType>(mAddressList[index]->mAddressType);
|
72
|
761 |
|
|
762 |
QContactLocalId contactId = mContact->localId();
|
|
763 |
|
81
|
764 |
if (mAddressList[index] != NULL)
|
72
|
765 |
{
|
81
|
766 |
if (mAddressList[index]->maptileStatus == MapTileService::MapTileFetchingCompleted)
|
|
767 |
{
|
|
768 |
// Read the maptile path and update the image
|
|
769 |
QString imagePath;
|
|
770 |
mMaptile->getMapTileImage(
|
|
771 |
contactId, sourceAddressType, imagePath, mView->mainWindow()->orientation());
|
72
|
772 |
|
81
|
773 |
if (!imagePath.isEmpty())
|
|
774 |
{
|
|
775 |
//Empty icon. Clear the inprogress icon
|
|
776 |
HbIcon emptyIcon;
|
|
777 |
mAddressList[index]->mDetailItem->setSecondaryIconItem(emptyIcon);
|
72
|
778 |
|
81
|
779 |
HbIcon icon(imagePath);
|
72
|
780 |
|
81
|
781 |
HbLabel* maptileLabel = loadMaptileLabel(sourceAddressType);
|
|
782 |
setMaptileLabel(maptileLabel, icon);
|
|
783 |
mMaptileLabelList.insert(sourceAddressType, maptileLabel);
|
|
784 |
|
|
785 |
//find the index of the item and insert maptile in the next index
|
|
786 |
for (int itemIndex = 0 ; itemIndex < mContainerLayout->count(); itemIndex++)
|
|
787 |
{
|
|
788 |
if (mContainerLayout->itemAt(itemIndex) == mAddressList[index]->mDetailItem)
|
|
789 |
{
|
|
790 |
mContainerLayout->insertItem(itemIndex + 1, maptileLabel);
|
|
791 |
break;
|
|
792 |
}
|
|
793 |
}
|
|
794 |
}
|
|
795 |
else
|
|
796 |
{
|
|
797 |
//Maptile image not available. Show the search stop icon
|
|
798 |
setMaptileSearchStopIcon(index);
|
|
799 |
}
|
|
800 |
}
|
|
801 |
else
|
|
802 |
{
|
|
803 |
//Maptile fetching failed. Show the search stop icon
|
|
804 |
setMaptileSearchStopIcon(index);
|
|
805 |
}
|
72
|
806 |
|
81
|
807 |
delete mAddressList[index];
|
|
808 |
mAddressList.removeAt(index);
|
72
|
809 |
}
|
|
810 |
else
|
|
811 |
{
|
81
|
812 |
//increment the index now
|
|
813 |
index++;
|
72
|
814 |
}
|
|
815 |
}
|
|
816 |
}
|
|
817 |
}
|
|
818 |
|
|
819 |
/*
|
|
820 |
* Sets the search stop icon to secondary icon item
|
|
821 |
*/
|
81
|
822 |
void CntContactCardViewPrivate::setMaptileSearchStopIcon(int index)
|
72
|
823 |
{
|
81
|
824 |
if (index < mAddressList.count())
|
72
|
825 |
{
|
|
826 |
QString iconName(CNT_MAPTILE_SEARCH_STOP_ICON);
|
|
827 |
HbIcon icon(iconName);
|
81
|
828 |
mAddressList[index]->mDetailItem->setSecondaryIconItem(icon);
|
72
|
829 |
mAddressList[index]->mDetailItem->update();
|
|
830 |
}
|
|
831 |
}
|
|
832 |
|
81
|
833 |
/*!
|
|
834 |
Slot to receive the maptile status information.
|
|
835 |
*/
|
|
836 |
void CntContactCardViewPrivate::mapTileStatusReceived(int contactid, int addressType, int status)
|
72
|
837 |
{
|
81
|
838 |
// Update the maptile status information for all 3( Preferred, Work, Home ) address
|
|
839 |
for (int index = 0; index < mAddressList.count(); index++)
|
72
|
840 |
{
|
81
|
841 |
if (mAddressList[index]->mContactId == contactid &&
|
|
842 |
mAddressList[index]->mAddressType == addressType)
|
72
|
843 |
{
|
|
844 |
mAddressList[index]->maptileStatus = status;
|
|
845 |
}
|
|
846 |
}
|
81
|
847 |
|
72
|
848 |
updateSpinningIndicator();
|
|
849 |
}
|
|
850 |
|
81
|
851 |
/*!
|
|
852 |
Updates correct maptile image when screen orientation changes.
|
|
853 |
*/
|
72
|
854 |
void CntContactCardViewPrivate::updateMaptileImage()
|
|
855 |
{
|
81
|
856 |
// If there is no maptile displayed, return immediately
|
|
857 |
if (mMaptileLabelList.count() > 0)
|
72
|
858 |
{
|
|
859 |
QContactLocalId contactId = mContact->localId();
|
|
860 |
|
|
861 |
QList<QContactAddress> addressDetails = mContact->details<QContactAddress>();
|
|
862 |
|
|
863 |
//address
|
|
864 |
QString contextHome(QContactAddress::ContextHome.operator QString());
|
|
865 |
QString contextWork(QContactAddress::ContextWork.operator QString());
|
|
866 |
MapTileService::AddressType sourceAddressType
|
81
|
867 |
= MapTileService::AddressPreference;
|
72
|
868 |
|
|
869 |
QString imagePath;
|
|
870 |
|
81
|
871 |
for (int i = 0; i < addressDetails.count(); i++)
|
72
|
872 |
{
|
81
|
873 |
if (!addressDetails[i].contexts().isEmpty() &&
|
|
874 |
addressDetails[i].contexts().at(0) == contextHome)
|
72
|
875 |
{
|
|
876 |
sourceAddressType = MapTileService::AddressHome;
|
|
877 |
}
|
81
|
878 |
else if (!addressDetails[i].contexts().isEmpty() &&
|
|
879 |
addressDetails[i].contexts().at(0) == contextWork)
|
72
|
880 |
{
|
|
881 |
sourceAddressType = MapTileService::AddressWork;
|
|
882 |
}
|
81
|
883 |
|
72
|
884 |
int status = mMaptile->getMapTileImage(
|
|
885 |
contactId,
|
|
886 |
sourceAddressType,
|
|
887 |
imagePath,
|
81
|
888 |
mView->mainWindow()->orientation());
|
|
889 |
if (!imagePath.isEmpty())
|
72
|
890 |
{
|
81
|
891 |
HbIcon icon(imagePath);
|
|
892 |
HbLabel* label = mMaptileLabelList.value(sourceAddressType);
|
|
893 |
if (label)
|
72
|
894 |
{
|
81
|
895 |
setMaptileLabel(label, icon);
|
72
|
896 |
}
|
|
897 |
}
|
|
898 |
}
|
|
899 |
}
|
|
900 |
}
|
|
901 |
|
|
902 |
|
81
|
903 |
/*!
|
|
904 |
Asscoiate the maptile label widget with maptile image.
|
|
905 |
*/
|
|
906 |
void CntContactCardViewPrivate::setMaptileLabel(HbLabel*& mapLabel, const HbIcon& icon)
|
72
|
907 |
{
|
|
908 |
mapLabel->clear();
|
81
|
909 |
mapLabel->setIcon(icon);
|
|
910 |
|
|
911 |
qreal leftMarginSize;
|
|
912 |
mapLabel->getContentsMargins(&leftMarginSize, 0, 0, 0);
|
|
913 |
mapLabel->setPreferredSize(QSizeF(icon.width() + leftMarginSize, icon.height()));
|
72
|
914 |
}
|
|
915 |
|
81
|
916 |
/*!
|
|
917 |
Load the maptile label based on the address type.
|
|
918 |
*/
|
|
919 |
HbLabel* CntContactCardViewPrivate::loadMaptileLabel(int addressType)
|
72
|
920 |
{
|
|
921 |
HbLabel* maptileLabel = NULL;
|
|
922 |
|
81
|
923 |
if (addressType == MapTileService::AddressPreference)
|
72
|
924 |
{
|
|
925 |
maptileLabel = static_cast<HbLabel*>(document()->findWidget(QString("maptilePreferenceWidget")));
|
|
926 |
}
|
81
|
927 |
else if (addressType == MapTileService::AddressHome)
|
72
|
928 |
{
|
81
|
929 |
maptileLabel = static_cast<HbLabel*>(document()->findWidget(QString("maptileHomeWidget")));
|
72
|
930 |
}
|
81
|
931 |
else if (addressType == MapTileService::AddressWork)
|
72
|
932 |
{
|
81
|
933 |
maptileLabel = static_cast<HbLabel*>(document()->findWidget(QString("maptileWorkWidget")));
|
72
|
934 |
}
|
|
935 |
|
|
936 |
return maptileLabel;
|
|
937 |
}
|
|
938 |
|
|
939 |
/*
|
|
940 |
* Update the presence status icon of action item with the given accountUri
|
|
941 |
*/
|
|
942 |
void CntContactCardViewPrivate::updateItemPresence(const QString& accountUri, bool online)
|
|
943 |
{
|
|
944 |
CntContactCardDetailItem* item = mPresenceItems.value(accountUri);
|
|
945 |
|
|
946 |
if (item)
|
|
947 |
{
|
|
948 |
if (online)
|
|
949 |
{
|
|
950 |
mDataContainer->dataItem(item->index())->setSecondaryIcon(HbIcon("qtg_small_online"));
|
|
951 |
}
|
|
952 |
else
|
|
953 |
{
|
|
954 |
mDataContainer->dataItem(item->index())->setSecondaryIcon(HbIcon());
|
|
955 |
}
|
|
956 |
item->setDetails(mDataContainer->dataItem(item->index()));
|
|
957 |
}
|
|
958 |
}
|
|
959 |
|
|
960 |
void CntContactCardViewPrivate::thumbnailReady(const QPixmap& pixmap, void *data, int id, int error)
|
|
961 |
{
|
|
962 |
CNT_ENTRY
|
|
963 |
|
|
964 |
Q_UNUSED(data);
|
|
965 |
Q_UNUSED(id);
|
|
966 |
if (!error)
|
|
967 |
{
|
|
968 |
HbIcon icon(pixmap);
|
|
969 |
mHeadingItem->setIcon(icon);
|
|
970 |
mVCardIcon = new HbIcon(pixmap);
|
|
971 |
mImageLabel->clear();
|
|
972 |
mImageLabel->setIcon(pixmap);
|
|
973 |
}
|
|
974 |
|
|
975 |
CNT_EXIT
|
|
976 |
}
|
|
977 |
|
|
978 |
/*!
|
|
979 |
Place contact to homescreen as widget
|
|
980 |
*/
|
|
981 |
void CntContactCardViewPrivate::sendToHs()
|
|
982 |
{
|
|
983 |
QVariantHash preferences;
|
|
984 |
preferences["contactId"] = mContact->localId();
|
|
985 |
|
|
986 |
XQServiceRequest snd("com.nokia.symbian.IHomeScreenClient",
|
|
987 |
"addWidget(QString,QVariantHash)"
|
|
988 |
,false);
|
|
989 |
snd << QString("contactwidgethsplugin");
|
|
990 |
snd << preferences;
|
|
991 |
snd.send();
|
|
992 |
|
|
993 |
/*
|
|
994 |
if (mRequest)
|
|
995 |
{
|
|
996 |
delete mRequest;
|
|
997 |
mRequest = 0;
|
|
998 |
}
|
|
999 |
|
|
1000 |
mRequest = mAppManager.create("com.nokia.symbian.IHomeScreenClient", "addWidget(QString,QVariantHash)", false);
|
|
1001 |
|
|
1002 |
if (mRequest)
|
|
1003 |
{
|
|
1004 |
QList<QVariant> args;
|
|
1005 |
QVariantHash preferences;
|
|
1006 |
preferences["contactId"] = mContact->localId();
|
|
1007 |
args << preferences;
|
|
1008 |
args << QString("contactwidgethsplugin");
|
|
1009 |
mRequest->setArguments(args);
|
|
1010 |
mRequest->send();
|
|
1011 |
}
|
|
1012 |
*/
|
|
1013 |
}
|
|
1014 |
|
|
1015 |
/*!
|
|
1016 |
Launch contact editor
|
|
1017 |
*/
|
|
1018 |
void CntContactCardViewPrivate::editContact()
|
|
1019 |
{
|
|
1020 |
QVariant var;
|
|
1021 |
var.setValue(*mContact);
|
|
1022 |
|
|
1023 |
mArgs.insert(ESelectedContact, var);
|
|
1024 |
mArgs.insert(EViewId, editView);
|
|
1025 |
|
|
1026 |
mViewManager->changeView( mArgs );
|
|
1027 |
}
|
|
1028 |
|
|
1029 |
void CntContactCardViewPrivate::addToGroup()
|
|
1030 |
{
|
|
1031 |
}
|
|
1032 |
|
|
1033 |
void CntContactCardViewPrivate::setAsFavorite()
|
|
1034 |
{
|
|
1035 |
QContactId id = mContact->id();
|
|
1036 |
CntFavourite::addContactToFavouriteGroup( contactManager(), id );
|
|
1037 |
|
|
1038 |
QContact c = contactManager()->contact(mContact->localId());
|
|
1039 |
|
|
1040 |
delete mContact;
|
|
1041 |
mContact = NULL;
|
|
1042 |
|
|
1043 |
mContact = new QContact(c);
|
|
1044 |
|
|
1045 |
qobject_cast<HbAction *>(document()->findObject("cnt:removefromfavorite"))->setVisible(true);
|
|
1046 |
qobject_cast<HbAction *>(document()->findObject("cnt:setasfavorite"))->setVisible(false);
|
|
1047 |
mHeadingItem->setFavoriteStatus(true);
|
|
1048 |
}
|
|
1049 |
|
|
1050 |
void CntContactCardViewPrivate::removeFromFavorite()
|
|
1051 |
{
|
|
1052 |
QContactId id = mContact->id();
|
|
1053 |
CntFavourite::removeContactFromFavouriteGroup( contactManager(), id );
|
|
1054 |
|
|
1055 |
QContact c = contactManager()->contact(mContact->localId());
|
|
1056 |
|
|
1057 |
delete mContact;
|
|
1058 |
mContact = NULL;
|
|
1059 |
|
|
1060 |
mContact = new QContact(c);
|
|
1061 |
|
|
1062 |
qobject_cast<HbAction *>(document()->findObject("cnt:removefromfavorite"))->setVisible(false);
|
|
1063 |
qobject_cast<HbAction *>(document()->findObject("cnt:setasfavorite"))->setVisible(true);
|
|
1064 |
mHeadingItem->setFavoriteStatus(false);
|
|
1065 |
}
|
|
1066 |
|
|
1067 |
/*!
|
|
1068 |
Delete contact
|
|
1069 |
*/
|
|
1070 |
void CntContactCardViewPrivate::deleteContact()
|
|
1071 |
{
|
|
1072 |
QString name = contactManager()->synthesizedContactDisplayLabel(*mContact);
|
|
1073 |
if (name.isEmpty())
|
|
1074 |
{
|
|
1075 |
name = hbTrId("txt_phob_list_unnamed");
|
|
1076 |
}
|
|
1077 |
|
81
|
1078 |
HbMessageBox::question(HbParameterLengthLimiter("txt_phob_info_delete_1").arg(name), this, SLOT(handleDeleteContact(int)),
|
72
|
1079 |
HbMessageBox::Delete | HbMessageBox::Cancel);
|
|
1080 |
}
|
|
1081 |
|
|
1082 |
/*!
|
|
1083 |
Handle action for deleting a contact
|
|
1084 |
*/
|
|
1085 |
void CntContactCardViewPrivate::handleDeleteContact(int action)
|
|
1086 |
{
|
|
1087 |
if (action == HbMessageBox::Delete)
|
|
1088 |
{
|
|
1089 |
disconnect(contactManager(), SIGNAL(contactsRemoved(const QList<QContactLocalId>&)),
|
|
1090 |
this, SLOT(contactDeletedFromOtherSource(const QList<QContactLocalId>&)));
|
|
1091 |
|
|
1092 |
bool success = contactManager()->removeContact(mContact->localId());
|
|
1093 |
|
|
1094 |
int returnValue = success ? KCntServicesReturnValueContactDeleted : KCntServicesReturnValueContactNotModified;
|
|
1095 |
|
|
1096 |
emit backPressed(returnValue);
|
|
1097 |
|
|
1098 |
mViewManager->back( mArgs, true );
|
|
1099 |
}
|
|
1100 |
}
|
|
1101 |
|
|
1102 |
/*!
|
|
1103 |
Launch history view
|
|
1104 |
*/
|
|
1105 |
void CntContactCardViewPrivate::viewHistory()
|
|
1106 |
{
|
|
1107 |
QVariant var;
|
|
1108 |
var.setValue(*mContact);
|
|
1109 |
mArgs.insert(ESelectedContact, var);
|
|
1110 |
mArgs.insert(EViewId, historyView);
|
|
1111 |
|
|
1112 |
mViewManager->changeView( mArgs );
|
|
1113 |
}
|
|
1114 |
|
|
1115 |
/*!
|
|
1116 |
Deactivate the view
|
|
1117 |
*/
|
|
1118 |
void CntContactCardViewPrivate::deactivate()
|
|
1119 |
{
|
|
1120 |
}
|
|
1121 |
|
|
1122 |
/*!
|
|
1123 |
Send the business card / my card
|
|
1124 |
*/
|
|
1125 |
void CntContactCardViewPrivate::sendBusinessCard()
|
|
1126 |
{
|
|
1127 |
CNT_ENTRY
|
|
1128 |
|
|
1129 |
// Check if the contact has an image.
|
|
1130 |
QList<QContactAvatar> avatars = mContact->details<QContactAvatar>();
|
|
1131 |
bool imageExists( false );
|
|
1132 |
/*foreach(QContactAvatar a, mContact->details<QContactAvatar>())
|
|
1133 |
{
|
|
1134 |
if (!a.imageUrl().isEmpty())
|
|
1135 |
{
|
|
1136 |
imageExists = true;
|
|
1137 |
HbMessageBox *note = new HbMessageBox(
|
|
1138 |
hbTrId("txt_phob_info_add_contact_card_image_to_business_c"),
|
|
1139 |
HbMessageBox::MessageTypeQuestion);
|
|
1140 |
note->setIcon(*mVCardIcon);
|
|
1141 |
note->clearActions();
|
|
1142 |
|
|
1143 |
HbAction* ok = new HbAction(hbTrId("txt_common_button_ok"), note);
|
|
1144 |
HbAction* cancel = new HbAction(hbTrId("txt_common_button_cancel"), note);
|
|
1145 |
|
|
1146 |
ok->setObjectName( "ok" );
|
|
1147 |
cancel->setObjectName( "cancel" );
|
|
1148 |
|
|
1149 |
note->addAction( ok );
|
|
1150 |
note->addAction( cancel );
|
|
1151 |
|
|
1152 |
note->setModal( true );
|
|
1153 |
note->setAttribute(Qt::WA_DeleteOnClose, true );
|
|
1154 |
note->open( this, SLOT(handleSendBusinessCard(HbAction*)));
|
|
1155 |
break;
|
|
1156 |
}
|
|
1157 |
}*/
|
|
1158 |
|
|
1159 |
if ( !imageExists )
|
|
1160 |
{
|
|
1161 |
CNT_LOG_ARGS("snd vCard without image")
|
|
1162 |
handleSendBusinessCard( NULL ); // no image
|
|
1163 |
}
|
|
1164 |
|
|
1165 |
CNT_EXIT
|
|
1166 |
}
|
|
1167 |
|
|
1168 |
/*!
|
|
1169 |
Set orientation of the view
|
|
1170 |
*/
|
|
1171 |
void CntContactCardViewPrivate::setOrientation(Qt::Orientation orientation)
|
|
1172 |
{
|
|
1173 |
if (orientation == Qt::Vertical)
|
|
1174 |
{
|
|
1175 |
// reading "portrait" section
|
|
1176 |
document()->load(CNT_CONTACTCARDVIEW_XML, "portrait");
|
|
1177 |
}
|
|
1178 |
else
|
|
1179 |
{
|
|
1180 |
// reading "landscape" section
|
|
1181 |
document()->load(CNT_CONTACTCARDVIEW_XML, "landscape");
|
|
1182 |
}
|
|
1183 |
//Update the maptile image
|
|
1184 |
updateMaptileImage();
|
|
1185 |
}
|
|
1186 |
|
|
1187 |
/*!
|
|
1188 |
Called after user clicked on the listview.
|
|
1189 |
*/
|
|
1190 |
void CntContactCardViewPrivate::onItemActivated()
|
|
1191 |
{
|
|
1192 |
CntContactCardDetailItem *item = qobject_cast<CntContactCardDetailItem*>(sender());
|
|
1193 |
int index = item->index();
|
|
1194 |
CntContactCardDataItem& dataItem = *mDataContainer->dataItem(index);
|
|
1195 |
QString action = mDataContainer->dataItem(index)->action();
|
|
1196 |
CntUiContactCardExtension* extension = dataItem.contactCardExtension();
|
|
1197 |
if (!extension)
|
|
1198 |
{
|
|
1199 |
//It's not an extension action.
|
|
1200 |
// Check if action is internal
|
|
1201 |
QList<QContactActionDescriptor> actionDescriptors = QContactAction::actionDescriptors(action, "symbian", 1);
|
|
1202 |
if (0 < actionDescriptors.count())
|
|
1203 |
{
|
|
1204 |
// These actions are considered internal(vendor=symbian and version=1)
|
|
1205 |
executeAction(*mContact, dataItem.detail(), action, item);
|
|
1206 |
}
|
|
1207 |
else
|
|
1208 |
{
|
|
1209 |
//Handle dynamic actions differently
|
|
1210 |
executeDynamicAction(*mContact, dataItem.detail(), dataItem.actionDescriptor());
|
|
1211 |
}
|
|
1212 |
} else {
|
|
1213 |
// The action is from an extension
|
|
1214 |
int indexWithinPlugin = dataItem.contactCardExtensionActionIndex();
|
|
1215 |
extension->handleShortPress(indexWithinPlugin);
|
|
1216 |
}
|
|
1217 |
}
|
|
1218 |
|
|
1219 |
/*!
|
|
1220 |
Execute the call / message / email action
|
|
1221 |
*/
|
|
1222 |
void CntContactCardViewPrivate::executeAction(QContact& aContact, const QContactDetail& aDetail, const QString& aAction, CntContactCardDetailItem* aItem)
|
|
1223 |
{
|
|
1224 |
if (mIsExecutingAction)
|
|
1225 |
{
|
|
1226 |
return;
|
|
1227 |
}
|
|
1228 |
else
|
|
1229 |
{
|
|
1230 |
mIsExecutingAction = true;
|
|
1231 |
}
|
|
1232 |
|
|
1233 |
CntActionLauncher* other = new CntActionLauncher(*contactManager(), aAction);
|
|
1234 |
connect(other, SIGNAL(actionExecuted(CntActionLauncher*)), this, SLOT(actionExecuted(CntActionLauncher*)));
|
|
1235 |
if (aItem && aContact.preferredDetail(aAction).isEmpty())
|
|
1236 |
{
|
|
1237 |
setPreferredAction(aAction, aDetail, aItem);
|
|
1238 |
}
|
|
1239 |
other->execute(aContact, aDetail);
|
|
1240 |
}
|
|
1241 |
|
|
1242 |
|
|
1243 |
/*!
|
|
1244 |
Execute the call / message / email action
|
|
1245 |
*/
|
|
1246 |
void CntContactCardViewPrivate::executeAction(QContact& aContact, const QContactDetail& aDetail, const QString& aAction)
|
|
1247 |
{
|
|
1248 |
//TODO: need refactoring
|
|
1249 |
CntContactCardDetailItem* detailItem = NULL;
|
|
1250 |
for (int index = 0; index < mDataContainer->itemCount(); index++)
|
|
1251 |
{
|
|
1252 |
QContactDetail detail = mDataContainer->dataItem(index)->detail();
|
|
1253 |
QString action = mDataContainer->dataItem(index)->action();
|
|
1254 |
if (detail == aDetail && action == aAction)
|
|
1255 |
{
|
|
1256 |
detailItem = static_cast<CntContactCardDetailItem*>(mContainerLayout->itemAt(index));
|
|
1257 |
break;
|
|
1258 |
}
|
|
1259 |
}
|
|
1260 |
executeAction(aContact, aDetail, aAction, detailItem);
|
|
1261 |
mAcceptSendKey=true;
|
|
1262 |
}
|
|
1263 |
|
|
1264 |
/*!
|
|
1265 |
Execute dynamic action
|
|
1266 |
*/
|
|
1267 |
void CntContactCardViewPrivate::executeDynamicAction(QContact& aContact, QContactDetail aDetail, QContactActionDescriptor aActionDescriptor)
|
|
1268 |
{
|
|
1269 |
if (mIsExecutingAction)
|
|
1270 |
{
|
|
1271 |
return;
|
|
1272 |
}
|
|
1273 |
else
|
|
1274 |
{
|
|
1275 |
mIsExecutingAction = true;
|
|
1276 |
}
|
|
1277 |
|
|
1278 |
CntActionLauncher* other = new CntActionLauncher(*contactManager());
|
|
1279 |
connect(other, SIGNAL(actionExecuted(CntActionLauncher*)), this, SLOT(actionExecuted(CntActionLauncher*)));
|
|
1280 |
other->execute(aContact, aDetail, aActionDescriptor);
|
|
1281 |
}
|
|
1282 |
|
|
1283 |
void CntContactCardViewPrivate::actionExecuted(CntActionLauncher* aAction)
|
|
1284 |
{
|
|
1285 |
aAction->deleteLater();
|
|
1286 |
mIsExecutingAction = false;
|
|
1287 |
}
|
|
1288 |
|
|
1289 |
/*!
|
|
1290 |
Item specific menu
|
|
1291 |
*/
|
|
1292 |
void CntContactCardViewPrivate::onLongPressed(const QPointF &aCoords)
|
|
1293 |
{
|
|
1294 |
CntContactCardDetailItem *item = qobject_cast<CntContactCardDetailItem*>(sender());
|
|
1295 |
int index = item->index();
|
|
1296 |
|
|
1297 |
CntContactCardContextMenu *menu = new CntContactCardContextMenu( item );
|
|
1298 |
HbAction *communicationAction = 0;
|
|
1299 |
HbAction *dynamicAction = 0;
|
|
1300 |
HbAction *videoCommunicationAction = 0;
|
|
1301 |
HbAction *preferredAction = 0;
|
|
1302 |
CntStringMapper stringMapper;
|
|
1303 |
|
|
1304 |
QString action = mDataContainer->dataItem(index)->action();
|
|
1305 |
QContactDetail detail = mDataContainer->dataItem(index)->detail();
|
|
1306 |
|
|
1307 |
if (action.compare("call", Qt::CaseInsensitive) == 0)
|
|
1308 |
{
|
|
1309 |
QContactDetail detail = mDataContainer->dataItem(index)->detail();
|
|
1310 |
if (detail.definitionName() == QContactPhoneNumber::DefinitionName)
|
|
1311 |
{
|
|
1312 |
QContactPhoneNumber number = static_cast<QContactPhoneNumber>(detail);
|
|
1313 |
QString context = number.contexts().isEmpty() ? QString() : number.contexts().first();
|
|
1314 |
QString subtype = number.subTypes().isEmpty() ? number.definitionName() : number.subTypes().first();
|
|
1315 |
|
|
1316 |
communicationAction = menu->addAction(stringMapper.getItemSpecificMenuLocString(subtype, context));
|
|
1317 |
videoCommunicationAction = menu->addAction(hbTrId("txt_phob_menu_call_video_number"));
|
|
1318 |
}
|
|
1319 |
}
|
|
1320 |
else if (action.compare("message", Qt::CaseInsensitive) == 0)
|
|
1321 |
{
|
|
1322 |
communicationAction = menu->addAction(hbTrId("txt_phob_menu_send_message"));
|
|
1323 |
}
|
|
1324 |
else if (action.compare("email", Qt::CaseInsensitive) == 0)
|
|
1325 |
{
|
|
1326 |
if (!detail.contexts().isEmpty())
|
|
1327 |
{
|
|
1328 |
communicationAction = menu->addAction(stringMapper.getItemSpecificMenuLocString(detail.definitionName(), detail.contexts().first()));
|
|
1329 |
}
|
|
1330 |
else
|
|
1331 |
{
|
|
1332 |
communicationAction = menu->addAction(stringMapper.getItemSpecificMenuLocString(detail.definitionName(), QString()));
|
|
1333 |
}
|
|
1334 |
}
|
|
1335 |
else if (action.compare("url", Qt::CaseInsensitive) == 0)
|
|
1336 |
{
|
|
1337 |
if (!detail.contexts().isEmpty())
|
|
1338 |
{
|
|
1339 |
communicationAction = menu->addAction(stringMapper.getItemSpecificMenuLocString(detail.definitionName(), detail.contexts().first()));
|
|
1340 |
}
|
|
1341 |
else
|
|
1342 |
{
|
|
1343 |
communicationAction = menu->addAction(stringMapper.getItemSpecificMenuLocString(detail.definitionName(), QString()));
|
|
1344 |
}
|
|
1345 |
}
|
|
1346 |
else if (1 > QContactAction::actionDescriptors(action, "symbian", 1).count())
|
|
1347 |
{
|
|
1348 |
// Do verification that action is not internal type(vendor=symbian and version=1)
|
|
1349 |
// If hard coded action is not found, fetch localization from dynamic action
|
|
1350 |
// and create dynamic action item.
|
|
1351 |
dynamicAction = menu->addAction(mDataContainer->dataItem(index)->longPressText());
|
|
1352 |
}
|
|
1353 |
|
|
1354 |
if (action.compare("call", Qt::CaseInsensitive) == 0)
|
|
1355 |
{
|
|
1356 |
preferredAction = menu->addAction(hbTrId("txt_phob_menu_set_as_default_number"));
|
|
1357 |
}
|
|
1358 |
else if (action.compare("message", Qt::CaseInsensitive) == 0)
|
|
1359 |
{
|
|
1360 |
preferredAction = menu->addAction(hbTrId("txt_phob_menu_set_as_default_number"));
|
|
1361 |
}
|
|
1362 |
else if (action.compare("email", Qt::CaseInsensitive) == 0)
|
|
1363 |
{
|
|
1364 |
preferredAction = menu->addAction(hbTrId("txt_phob_menu_set_as_default_email"));
|
|
1365 |
}
|
|
1366 |
|
|
1367 |
if (mContact->isPreferredDetail(action, detail) && preferredAction)
|
|
1368 |
{
|
|
1369 |
preferredAction->setEnabled(false);
|
|
1370 |
}
|
|
1371 |
|
|
1372 |
if ( communicationAction )
|
|
1373 |
{
|
|
1374 |
communicationAction->setObjectName( "communicationAction" );
|
|
1375 |
}
|
|
1376 |
if ( videoCommunicationAction )
|
|
1377 |
{
|
|
1378 |
videoCommunicationAction->setObjectName( "videoCommunicationAction" );
|
|
1379 |
}
|
|
1380 |
|
|
1381 |
if ( dynamicAction )
|
|
1382 |
{
|
|
1383 |
dynamicAction->setObjectName( "dynamicAction" );
|
|
1384 |
}
|
|
1385 |
|
|
1386 |
if ( preferredAction )
|
|
1387 |
{
|
|
1388 |
preferredAction->setObjectName( "preferredAction" );
|
|
1389 |
menu->insertSeparator(preferredAction);
|
|
1390 |
}
|
|
1391 |
|
|
1392 |
menu->setPreferredPos( aCoords );
|
|
1393 |
menu->setAttribute( Qt::WA_DeleteOnClose, true );
|
|
1394 |
menu->open( this, SLOT(handleMenuAction(HbAction*)) );
|
|
1395 |
}
|
|
1396 |
|
|
1397 |
void CntContactCardViewPrivate::handleMenuAction(HbAction* aAction)
|
|
1398 |
{
|
|
1399 |
CntContactCardContextMenu* menu = static_cast<CntContactCardContextMenu*>(sender());
|
|
1400 |
CntContactCardDetailItem *item = menu->item();
|
|
1401 |
int index = item->index();
|
|
1402 |
|
|
1403 |
QString action = mDataContainer->dataItem(index)->action();
|
|
1404 |
QContactDetail detail = mDataContainer->dataItem(index)->detail();
|
|
1405 |
|
|
1406 |
QString name = aAction->objectName();
|
|
1407 |
|
|
1408 |
if ( name == "communicationAction" )
|
|
1409 |
{
|
|
1410 |
executeAction(*mContact, detail, action, item);
|
|
1411 |
}
|
|
1412 |
|
|
1413 |
if ( name == "videoCommunicationAction" )
|
|
1414 |
{
|
|
1415 |
//service name latter on should come from service table.
|
|
1416 |
executeAction(*mContact, detail, "videocall", item);
|
|
1417 |
}
|
|
1418 |
if ( name == "dynamicAction" )
|
|
1419 |
{
|
|
1420 |
executeDynamicAction(*mContact, detail, mDataContainer->dataItem(index)->actionDescriptor());
|
|
1421 |
}
|
|
1422 |
|
|
1423 |
if ( name == "preferredAction" )
|
|
1424 |
{
|
|
1425 |
setPreferredAction(action, detail, item);
|
|
1426 |
}
|
|
1427 |
}
|
|
1428 |
|
|
1429 |
/*!
|
|
1430 |
Set selected detail as preferred for selected action in detail item
|
|
1431 |
*/
|
|
1432 |
void CntContactCardViewPrivate::setPreferredAction(const QString &aAction, const QContactDetail &aDetail, CntContactCardDetailItem *aDetailItem)
|
|
1433 |
{
|
|
1434 |
if (aAction == "call" || aAction == "message" || aAction == "email")
|
|
1435 |
{
|
|
1436 |
mContact->setPreferredDetail(aAction, aDetail);
|
|
1437 |
contactManager()->saveContact(mContact);
|
|
1438 |
if (mPreferredItems.contains(aAction))
|
|
1439 |
{
|
|
1440 |
CntContactCardDetailItem *oldItem = mPreferredItems.value(aAction);
|
|
1441 |
mDataContainer->dataItem(oldItem->index())->setSecondaryIcon(HbIcon());
|
|
1442 |
oldItem->setDetails(mDataContainer->dataItem(oldItem->index()));
|
|
1443 |
}
|
|
1444 |
|
|
1445 |
mDataContainer->dataItem(aDetailItem->index())->setSecondaryIcon(HbIcon("qtg_mono_favourites"));
|
|
1446 |
aDetailItem->setDetails(mDataContainer->dataItem(aDetailItem->index()));
|
|
1447 |
|
|
1448 |
mPreferredItems.insert(aAction, aDetailItem);
|
|
1449 |
}
|
|
1450 |
}
|
|
1451 |
|
|
1452 |
|
|
1453 |
void CntContactCardViewPrivate::handleSendBusinessCard( HbAction* aAction )
|
|
1454 |
{
|
|
1455 |
CNT_ENTRY
|
|
1456 |
Q_UNUSED(aAction);
|
|
1457 |
|
|
1458 |
QList<QContact> list;
|
|
1459 |
/*if ( aAction && aAction->objectName() == "cancel" )
|
|
1460 |
{
|
|
1461 |
QContact tmpContact( *mContact );
|
|
1462 |
foreach ( QContactAvatar a, tmpContact.details<QContactAvatar>() )
|
|
1463 |
{
|
|
1464 |
tmpContact.removeDetail( &a );
|
|
1465 |
}
|
|
1466 |
list.append( tmpContact );
|
|
1467 |
}
|
|
1468 |
else
|
|
1469 |
{
|
|
1470 |
list.append( *mContact );
|
|
1471 |
}*/
|
|
1472 |
QContact tmpContact( *mContact );
|
|
1473 |
foreach ( QContactAvatar a, tmpContact.details<QContactAvatar>() )
|
|
1474 |
{
|
|
1475 |
tmpContact.removeDetail( &a );
|
|
1476 |
}
|
|
1477 |
|
|
1478 |
//temproral solution for a contact without name - add an empty name,
|
|
1479 |
//so vcard construction doesn't fail
|
|
1480 |
//TODO: use custom handler again when new QVersitContactExporterDetailHandlerV2
|
|
1481 |
//(part of QtVersit) is available in the platform
|
|
1482 |
QList<QContactName> names = tmpContact.details<QContactName>();
|
|
1483 |
if (names.count() > 0)
|
|
1484 |
{
|
|
1485 |
QContactName name = names.at(0);
|
|
1486 |
if (name.firstName().isEmpty() && name.lastName().isEmpty())
|
|
1487 |
{
|
|
1488 |
//empty first and last names - update with empty string
|
|
1489 |
name.setFirstName(QString(""));
|
|
1490 |
tmpContact.saveDetail(&name);
|
|
1491 |
}
|
|
1492 |
}
|
|
1493 |
else
|
|
1494 |
{
|
|
1495 |
//no name detail - create one
|
|
1496 |
QContactName name;
|
|
1497 |
name.setFirstName(QString(""));
|
|
1498 |
tmpContact.saveDetail(&name);
|
|
1499 |
} //temproral solution for a contact without name - add an empty name,
|
|
1500 |
//so vcard construction doesn't fail - end
|
|
1501 |
|
|
1502 |
list.append( tmpContact );
|
|
1503 |
|
|
1504 |
QString tempDir = QDir::tempPath().append("/tempcntvcard");
|
|
1505 |
QDir dir(tempDir);
|
|
1506 |
|
|
1507 |
// Temporary directory to store the vCard file
|
|
1508 |
if (!dir.exists())
|
|
1509 |
{
|
|
1510 |
// Create a temp directory
|
|
1511 |
if (!QDir::temp().mkdir("tempcntvcard"))
|
|
1512 |
{
|
|
1513 |
return;
|
|
1514 |
}
|
|
1515 |
}
|
|
1516 |
else
|
|
1517 |
{
|
|
1518 |
// Empty the temp directory since the other vCards are not required
|
|
1519 |
QStringList l = dir.entryList();
|
|
1520 |
foreach(QString s, l)
|
|
1521 |
{
|
|
1522 |
if (dir.exists(s))
|
|
1523 |
{
|
|
1524 |
dir.remove(s);
|
|
1525 |
}
|
|
1526 |
}
|
|
1527 |
}
|
|
1528 |
|
|
1529 |
QString vCardName;
|
|
1530 |
if ( mContact->displayLabel().isEmpty() ) {
|
|
1531 |
vCardName = hbTrId("txt_phob_list_unnamed").append(".vcf");
|
|
1532 |
}
|
|
1533 |
else {
|
|
1534 |
// Remove invalid characters from file name
|
|
1535 |
QString filename = mContact->displayLabel().trimmed();
|
|
1536 |
QString invalidChars("?*<>/\"|\\:");
|
|
1537 |
QChar replaceChar('_');
|
|
1538 |
QChar *data = filename.data();
|
|
1539 |
int count(0);
|
|
1540 |
while ( !data->isNull() ) {
|
|
1541 |
if ( invalidChars.contains(*data) ) {
|
|
1542 |
*data = replaceChar;
|
|
1543 |
count++;
|
|
1544 |
}
|
|
1545 |
++data;
|
|
1546 |
}
|
|
1547 |
|
|
1548 |
// Check if filename contains only special characters
|
|
1549 |
if ( count == filename.count() )
|
|
1550 |
filename = "_";
|
|
1551 |
vCardName = filename.append(".vcf");
|
|
1552 |
}
|
|
1553 |
|
|
1554 |
|
|
1555 |
QString vCardPath = dir.absolutePath().append(QDir::separator());
|
|
1556 |
vCardPath.append(vCardName);
|
|
1557 |
vCardPath = QDir::toNativeSeparators(vCardPath);
|
|
1558 |
|
|
1559 |
QVersitContactExporter exporter;
|
|
1560 |
//TODO: use custom handler again when new QVersitContactExporterDetailHandlerV2
|
|
1561 |
//(part of QtVersit) is available in the platform
|
|
1562 |
//CntVCardDetailHandler hanlder;
|
|
1563 |
//exporter.setDetailHandler(&hanlder);
|
|
1564 |
// The vCard version needs to be 2.1 due to backward compatiblity when sending
|
|
1565 |
if (exporter.exportContacts(list, QVersitDocument::VCard21Type))
|
|
1566 |
{
|
|
1567 |
CNT_LOG_ARGS("VCard21Type");
|
|
1568 |
QList<QVersitDocument> docs = exporter.documents();
|
|
1569 |
QFile f(vCardPath);
|
|
1570 |
if ( f.open(QIODevice::WriteOnly) )
|
|
1571 |
{
|
|
1572 |
CNT_LOG_ARGS("write VCard");
|
|
1573 |
// Start creating the vCard
|
|
1574 |
QVersitWriter writer;
|
|
1575 |
writer.setDevice(&f);
|
|
1576 |
|
|
1577 |
bool ret = writer.startWriting(docs);
|
|
1578 |
ret = writer.waitForFinished();
|
|
1579 |
|
|
1580 |
// Create the vCard and send it to messaging service
|
|
1581 |
if (!mShareUi) {
|
|
1582 |
mShareUi = new ShareUi();
|
|
1583 |
}
|
|
1584 |
QStringList l;
|
|
1585 |
l << vCardPath;
|
|
1586 |
mShareUi->send(l, true);
|
|
1587 |
}
|
|
1588 |
}
|
|
1589 |
|
|
1590 |
CNT_EXIT
|
|
1591 |
}
|
|
1592 |
|
|
1593 |
|
|
1594 |
/*!
|
|
1595 |
Called after the user clicked "Change Image" from popup menu after
|
|
1596 |
longpressing the image in this view.
|
|
1597 |
*/
|
|
1598 |
void CntContactCardViewPrivate::doChangeImage()
|
|
1599 |
{
|
|
1600 |
QVariant var;
|
|
1601 |
var.setValue(*mContact);
|
|
1602 |
|
|
1603 |
mArgs.insert(ESelectedContact, var);
|
|
1604 |
mArgs.insert(EViewId, imageEditorView);
|
|
1605 |
|
|
1606 |
mViewManager->changeView( mArgs );
|
|
1607 |
}
|
|
1608 |
|
|
1609 |
/*!
|
|
1610 |
Called after the user clicked "Remove Image" from popup menu after
|
|
1611 |
longpressing the image in this view.
|
|
1612 |
*/
|
|
1613 |
void CntContactCardViewPrivate::doRemoveImage()
|
|
1614 |
{
|
|
1615 |
if (mAvatar)
|
|
1616 |
{
|
|
1617 |
CntImageUtility imageUtility;
|
|
1618 |
QString filePath=mAvatar->imageUrl().toString();
|
|
1619 |
|
|
1620 |
bool success = mContact->removeDetail(mAvatar);
|
|
1621 |
if (success)
|
|
1622 |
{
|
|
1623 |
if (!filePath.isEmpty())
|
|
1624 |
{
|
|
1625 |
// Check if image removable.
|
|
1626 |
CntImageUtility imageUtility;
|
|
1627 |
if(imageUtility.isImageRemovable(filePath))
|
|
1628 |
{
|
|
1629 |
imageUtility.removeImage(filePath);
|
|
1630 |
}
|
|
1631 |
}
|
|
1632 |
mAvatar->setImageUrl(QUrl());
|
|
1633 |
mImageLabel->clear();
|
|
1634 |
mImageLabel->setAvatarIcon(HbIcon("qtg_large_add_contact_picture"));
|
|
1635 |
mHeadingItem->setIcon(HbIcon("qtg_large_add_contact_picture"));
|
|
1636 |
|
|
1637 |
disconnect(contactManager(), SIGNAL(contactsRemoved(const QList<QContactLocalId>&)),
|
|
1638 |
this, SLOT(contactDeletedFromOtherSource(const QList<QContactLocalId>&)));
|
|
1639 |
CntSaveManager::CntSaveResult result = mSaveManager->saveContact(mContact, contactManager());
|
|
1640 |
}
|
|
1641 |
}
|
|
1642 |
}
|
|
1643 |
|
|
1644 |
/*!
|
|
1645 |
Draw the image specific content menu
|
|
1646 |
*/
|
|
1647 |
void CntContactCardViewPrivate::drawMenu(const QPointF &aCoords)
|
|
1648 |
{
|
|
1649 |
HbMenu *menu = new HbMenu();
|
|
1650 |
menu->addAction(hbTrId("txt_phob_menu_change_picture"), this, SLOT(doChangeImage()) );
|
|
1651 |
if (mAvatar && !mAvatar->imageUrl().isEmpty())
|
|
1652 |
{
|
|
1653 |
menu->addAction(hbTrId("txt_phob_menu_remove_image"), this, SLOT(doRemoveImage()) );
|
|
1654 |
}
|
|
1655 |
menu->setAttribute( Qt::WA_DeleteOnClose );
|
|
1656 |
menu->setPreferredPos( aCoords );
|
|
1657 |
menu->open();
|
|
1658 |
}
|
|
1659 |
|
|
1660 |
/*!
|
|
1661 |
Return the pointer to the document loader
|
|
1662 |
*/
|
|
1663 |
CntDocumentLoader* CntContactCardViewPrivate::document()
|
|
1664 |
{
|
|
1665 |
if (!mLoader)
|
|
1666 |
{
|
|
1667 |
mLoader = new CntDocumentLoader();
|
|
1668 |
}
|
|
1669 |
return mLoader;
|
|
1670 |
}
|
|
1671 |
|
|
1672 |
/*!
|
|
1673 |
Return pointer to the contact manager
|
|
1674 |
*/
|
|
1675 |
QContactManager* CntContactCardViewPrivate::contactManager()
|
|
1676 |
{
|
|
1677 |
return &mEngine->contactManager(SYMBIAN_BACKEND);
|
|
1678 |
}
|
|
1679 |
|
|
1680 |
bool CntContactCardViewPrivate::eventFilter(QObject *obj, QEvent *event)
|
|
1681 |
{
|
|
1682 |
if (event->type() == ProcessPopulateListEvent && obj == this) {
|
|
1683 |
populateListItems();
|
|
1684 |
return true;
|
|
1685 |
}
|
|
1686 |
|
|
1687 |
if (event->type() == QEvent::KeyPress && obj == mView->mainWindow())
|
|
1688 |
{
|
|
1689 |
QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
|
|
1690 |
if (keyEvent->key() == Qt::Key_Yes)
|
|
1691 |
{
|
|
1692 |
return sendKeyPressed();
|
|
1693 |
}
|
|
1694 |
}
|
|
1695 |
|
|
1696 |
// Update the contact only when the application is in the backgound
|
|
1697 |
// This avoids flickering when the contact card is in focus
|
|
1698 |
if ( event->type() == QEvent::ApplicationActivate )
|
|
1699 |
{
|
|
1700 |
CNT_LOG_ARGS("app activated")
|
|
1701 |
|
|
1702 |
disconnect(contactManager(), SIGNAL(contactsChanged(const QList<QContactLocalId>&)),
|
|
1703 |
this, SLOT(contactUpdatedFromOtherSource(const QList<QContactLocalId>&)));
|
|
1704 |
|
|
1705 |
QContact c = contactManager()->contact(mContact->localId());
|
|
1706 |
|
|
1707 |
QContactTimestamp latestTimeStamp = c.detail<QContactTimestamp>();
|
|
1708 |
QContactTimestamp localTimeStamp = mContact->detail<QContactTimestamp>();
|
|
1709 |
|
|
1710 |
// Once we regain focus check if the contact was modified in the background
|
|
1711 |
if (contactManager()->error() == QContactManager::NoError
|
|
1712 |
&& latestTimeStamp.lastModified() > localTimeStamp.lastModified())
|
|
1713 |
{
|
81
|
1714 |
mListPopulationProgress = CntListPopulationNotInProgress;
|
|
1715 |
|
72
|
1716 |
if (mContact)
|
|
1717 |
delete mContact;
|
|
1718 |
mContact = new QContact(c);
|
|
1719 |
|
|
1720 |
populateHeadingItem();
|
|
1721 |
populateListItems();
|
|
1722 |
}
|
|
1723 |
}
|
|
1724 |
|
|
1725 |
if ( event->type() == QEvent::ApplicationDeactivate )
|
|
1726 |
{
|
|
1727 |
CNT_LOG_ARGS("app deactivated")
|
|
1728 |
|
|
1729 |
connect(contactManager(), SIGNAL(contactsChanged(const QList<QContactLocalId>&)),
|
|
1730 |
this, SLOT(contactUpdatedFromOtherSource(const QList<QContactLocalId>&)), Qt::UniqueConnection);
|
|
1731 |
}
|
|
1732 |
|
|
1733 |
return false;
|
|
1734 |
}
|
|
1735 |
|
|
1736 |
bool CntContactCardViewPrivate::sendKeyPressed()
|
|
1737 |
{
|
|
1738 |
int count = 0;
|
|
1739 |
bool keyConsumed = false;
|
|
1740 |
|
|
1741 |
for (int index = 0; index < mDataContainer->itemCount(); index++)
|
|
1742 |
{
|
|
1743 |
CntContactCardDataItem* dataItem = mDataContainer->dataItem(index);
|
|
1744 |
if (dataItem->action().compare("call", Qt::CaseInsensitive) == 0)
|
|
1745 |
{
|
|
1746 |
count++;
|
|
1747 |
}
|
|
1748 |
}
|
|
1749 |
|
|
1750 |
if (count)
|
|
1751 |
{
|
|
1752 |
QContactDetail preferredDetail = mContact->preferredDetail("call");
|
|
1753 |
if (!preferredDetail.isEmpty())
|
|
1754 |
{
|
|
1755 |
keyConsumed = true;
|
|
1756 |
executeAction(*mContact, preferredDetail, "call");
|
|
1757 |
}
|
|
1758 |
else if (count == 1 )
|
|
1759 |
{
|
|
1760 |
keyConsumed = true;
|
|
1761 |
executeAction( *mContact, mContact->details<QContactPhoneNumber>().first(), "call");
|
|
1762 |
}
|
|
1763 |
else if(count >= 2 && mAcceptSendKey)
|
|
1764 |
{
|
|
1765 |
keyConsumed = true;
|
|
1766 |
mAcceptSendKey = false;
|
|
1767 |
CntActionPopup *actionPopup = new CntActionPopup(mContact);
|
|
1768 |
actionPopup->showActionPopup("call");
|
|
1769 |
connect( actionPopup, SIGNAL(executeContactAction(QContact&, QContactDetail, QString)), this,
|
|
1770 |
SLOT(executeAction(QContact&, QContactDetail, QString)));
|
|
1771 |
connect( actionPopup, SIGNAL(actionPopupCancelPressed()), this,
|
|
1772 |
SLOT(sendKeyCancelSlot()));
|
|
1773 |
}
|
|
1774 |
else
|
|
1775 |
{
|
|
1776 |
//ignore
|
|
1777 |
}
|
|
1778 |
}
|
|
1779 |
|
|
1780 |
return keyConsumed;
|
|
1781 |
}
|
|
1782 |
|
|
1783 |
void CntContactCardViewPrivate::sendKeyCancelSlot()
|
|
1784 |
{
|
|
1785 |
mAcceptSendKey = true;
|
|
1786 |
}
|
|
1787 |
|
|
1788 |
void CntContactCardViewPrivate::onAddedToContacts()
|
|
1789 |
{
|
|
1790 |
emit addToContacts();
|
|
1791 |
}
|
|
1792 |
|
|
1793 |
void CntContactCardViewPrivate::contactDeletedFromOtherSource(const QList<QContactLocalId>& contactIds)
|
|
1794 |
{
|
|
1795 |
if ( contactIds.contains(mContact->localId()) )
|
|
1796 |
{
|
|
1797 |
// Do not switch to the previous view immediately. List views are
|
|
1798 |
// not updated properly if this is not done in the event loop
|
|
1799 |
QTimer::singleShot(0, this, SLOT(showRootView()));
|
|
1800 |
}
|
|
1801 |
}
|
|
1802 |
|
|
1803 |
void CntContactCardViewPrivate::contactUpdatedFromOtherSource(const QList<QContactLocalId>& contactIds)
|
|
1804 |
{
|
|
1805 |
if ( contactIds.contains(mContact->localId()) )
|
|
1806 |
{
|
|
1807 |
QContact c = contactManager()->contact(mContact->localId());
|
|
1808 |
if (contactManager()->error() == QContactManager::NoError)
|
|
1809 |
{
|
81
|
1810 |
mListPopulationProgress = CntListPopulationNotInProgress;
|
|
1811 |
|
72
|
1812 |
if (mContact)
|
|
1813 |
delete mContact;
|
|
1814 |
mContact = new QContact(c);
|
|
1815 |
|
|
1816 |
populateHeadingItem();
|
|
1817 |
populateListItems();
|
|
1818 |
}
|
|
1819 |
}
|
|
1820 |
}
|
|
1821 |
|
|
1822 |
// end of file
|