31
|
1 |
/*
|
|
2 |
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include "msgcontactcardwidget.h"
|
|
19 |
|
|
20 |
// SYSTEM INCLUDES
|
|
21 |
#include <HbStyle>
|
|
22 |
#include <HbIconItem>
|
|
23 |
#include <HbTextItem>
|
|
24 |
#include <HbFrameDrawer>
|
|
25 |
//#include <HbGesture>
|
|
26 |
//#include <HbGestureSceneFilter>
|
|
27 |
#include <HbWidgetFeedback>
|
|
28 |
#include <HbFrameItem>
|
|
29 |
#include <qcontactphonenumber.h>
|
|
30 |
#include <qcontactavatar.h>
|
|
31 |
#include <xqaiwrequest.h>
|
|
32 |
#include <xqappmgr.h>
|
|
33 |
#include <XQServiceRequest.h>
|
|
34 |
#include <cntservicescontact.h>
|
|
35 |
#include <QGraphicsSceneMouseEvent>
|
|
36 |
#include <HbMenu>
|
|
37 |
#include <HbMainWindow>
|
|
38 |
#include <thumbnailmanager_qt.h>
|
|
39 |
|
|
40 |
#include <ccsdefs.h>
|
|
41 |
|
|
42 |
// USER INCLUDES
|
|
43 |
#include "conversationsenginedefines.h"
|
|
44 |
#include "debugtraces.h"
|
|
45 |
#include "conversationsengine.h"
|
|
46 |
#include "convergedmessage.h"
|
|
47 |
#include "msgcontacthandler.h"
|
|
48 |
|
|
49 |
// LOCAL CONSTANTS
|
|
50 |
const QString DEFAULT_AVATAR_ICON("qtg_large_avatar");
|
|
51 |
const QString BT_ICON("qtg_large_bluetooth");
|
|
52 |
const QString BACKGROUND_FRAME_NORMAL("qtg_fr_groupbox");
|
|
53 |
const QString GROUPBOX_BG_FRAME_PRESSED("qtg_fr_groupbox_pressed");
|
|
54 |
|
|
55 |
|
|
56 |
// LOCALIZATION CONSTANTS
|
|
57 |
#define LOC_RECEIVED_FILES hbTrId("txt_messaging_title_received_files")
|
|
58 |
#define LOC_MENU_CONTACT_INFO hbTrId("txt_messaging_menu_open_contact_info")
|
|
59 |
#define LOC_COMMON_MENU_CALL hbTrId("txt_common_menu_call_verb")
|
|
60 |
#define LOC_SAVETO_CONTACTS hbTrId("txt_messaging_menu_save_to_contacts")
|
|
61 |
|
|
62 |
// LOCAL FUNCTIONS
|
|
63 |
|
|
64 |
//---------------------------------------------------------------
|
|
65 |
// MsgContactCardWidget::MsgContactCardWidget
|
|
66 |
// @see header
|
|
67 |
//---------------------------------------------------------------
|
|
68 |
MsgContactCardWidget::MsgContactCardWidget(QGraphicsItem *parent) :
|
|
69 |
HbWidget(parent), mMenuShown(false), mAvatarIconItem(NULL), mPresenceIconItem(NULL),
|
|
70 |
mAddressTextItem(NULL),mThumbnailManager(NULL)
|
|
71 |
{
|
|
72 |
init();
|
|
73 |
setBackGround(BACKGROUND_FRAME_NORMAL);
|
|
74 |
connectSignals(true);
|
|
75 |
|
|
76 |
connect(this->mainWindow(), SIGNAL(viewReady()), this, SLOT(initGesture()));
|
|
77 |
}
|
|
78 |
|
|
79 |
//---------------------------------------------------------------
|
|
80 |
// MsgContactCardWidget::~MsgContactCardWidget
|
|
81 |
// @see header
|
|
82 |
//---------------------------------------------------------------
|
|
83 |
MsgContactCardWidget::~MsgContactCardWidget()
|
|
84 |
{
|
|
85 |
/* if (mGestureFilter) {
|
|
86 |
removeSceneEventFilter(mGestureFilter);
|
|
87 |
}*/
|
|
88 |
}
|
|
89 |
|
|
90 |
//---------------------------------------------------------------
|
|
91 |
// MsgContactCardWidget::init
|
|
92 |
// @see header
|
|
93 |
//---------------------------------------------------------------
|
|
94 |
void MsgContactCardWidget::init()
|
|
95 |
{
|
|
96 |
mAvatarIconItem = new HbIconItem(this);
|
|
97 |
HbStyle::setItemName(mAvatarIconItem, "avatar");
|
|
98 |
|
|
99 |
mPresenceIconItem = new HbIconItem(this);
|
|
100 |
HbStyle::setItemName(mPresenceIconItem, "presence");
|
|
101 |
|
|
102 |
mAddressTextItem = new HbTextItem(this);
|
|
103 |
HbStyle::setItemName(mAddressTextItem, "addressText");
|
|
104 |
|
|
105 |
mThumbnailManager = new ThumbnailManager(this);
|
|
106 |
mThumbnailManager->setMode(ThumbnailManager::Default);
|
|
107 |
mThumbnailManager->setQualityPreference(ThumbnailManager::OptimizeForQuality);
|
|
108 |
mThumbnailManager->setThumbnailSize(ThumbnailManager::ThumbnailLarge);
|
|
109 |
|
|
110 |
connect(mThumbnailManager, SIGNAL(thumbnailReady(QPixmap, void*, int, int)), this,
|
|
111 |
SLOT(thumbnailReady(QPixmap, void*, int, int)));
|
|
112 |
}
|
|
113 |
|
|
114 |
//---------------------------------------------------------------
|
|
115 |
// MsgContactCardWidget::setAvatar
|
|
116 |
// @see header
|
|
117 |
//---------------------------------------------------------------
|
|
118 |
void MsgContactCardWidget::setAvatar(const HbIcon &avatar)
|
|
119 |
{
|
|
120 |
mAvatarIconItem->setIcon(avatar);
|
|
121 |
}
|
|
122 |
|
|
123 |
//---------------------------------------------------------------
|
|
124 |
// MsgContactCardWidget::setPresenceIcon
|
|
125 |
// @see header
|
|
126 |
//---------------------------------------------------------------
|
|
127 |
void MsgContactCardWidget::setPresenceIcon(const HbIcon &presenceIcon)
|
|
128 |
{
|
|
129 |
mPresenceIconItem->setIcon(presenceIcon);
|
|
130 |
}
|
|
131 |
|
|
132 |
//---------------------------------------------------------------
|
|
133 |
// MsgContactCardWidget::setAddress
|
|
134 |
// @see header
|
|
135 |
//---------------------------------------------------------------
|
|
136 |
void MsgContactCardWidget::setAddress(const QString &address)
|
|
137 |
{
|
|
138 |
mAddress = address;
|
|
139 |
mAddressTextItem->setText(address);
|
|
140 |
}
|
|
141 |
|
|
142 |
//---------------------------------------------------------------
|
|
143 |
// MsgContactCardWidget::address
|
|
144 |
// @see header
|
|
145 |
//---------------------------------------------------------------
|
|
146 |
ConvergedMessageAddressList MsgContactCardWidget::address()
|
|
147 |
{
|
|
148 |
ConvergedMessageAddressList addresses;
|
|
149 |
QModelIndex index = ConversationsEngine::instance()->getConversationsModel()->index(0, 0);
|
|
150 |
ConvergedMessageAddress* address = new ConvergedMessageAddress(
|
|
151 |
index.data(ConversationAddress).toString());
|
|
152 |
address->setAlias(mAddress);
|
|
153 |
addresses.append(address);
|
|
154 |
return addresses;
|
|
155 |
}
|
|
156 |
|
|
157 |
//---------------------------------------------------------------
|
|
158 |
// MsgContactCardWidget::updateContents
|
|
159 |
// @see header file
|
|
160 |
//---------------------------------------------------------------
|
|
161 |
void MsgContactCardWidget::updateContents()
|
|
162 |
{
|
|
163 |
// Get the Model Index
|
|
164 |
QModelIndex index = ConversationsEngine::instance()->getConversationsModel()->index(0, 0);
|
|
165 |
|
|
166 |
// Index is not valid, return.
|
|
167 |
if (!index.isValid()) {
|
|
168 |
return;
|
|
169 |
}
|
|
170 |
|
|
171 |
qint64 convId = ConversationsEngine::instance()->getCurrentConversationId();
|
|
172 |
|
|
173 |
if (KBluetoothMsgsConversationId == convId) {
|
|
174 |
setAddress(LOC_RECEIVED_FILES);
|
|
175 |
setAvatar(HbIcon(BT_ICON));
|
|
176 |
}
|
|
177 |
else {
|
|
178 |
//Set the Contact Name/Number
|
|
179 |
qint64 convId;
|
|
180 |
QString displayName;
|
|
181 |
QString contactAddress;
|
|
182 |
convId = ConversationsEngine::instance()->getCurrentConversationId();
|
|
183 |
ConversationsEngine::instance()->getContactDetails(convId, displayName, contactAddress);
|
|
184 |
|
|
185 |
mContactNumber = contactAddress;
|
|
186 |
QString contactName;
|
|
187 |
if (displayName.isEmpty()) {
|
|
188 |
contactName.append(contactAddress);
|
|
189 |
}
|
|
190 |
else {
|
|
191 |
contactName.append(displayName);
|
|
192 |
}
|
|
193 |
|
|
194 |
setAddress(contactName);
|
|
195 |
|
|
196 |
// Set Avatar
|
|
197 |
QList<QContact> contactList =
|
|
198 |
MsgContactHandler::findContactList(mContactNumber);
|
|
199 |
|
|
200 |
if (!contactList.isEmpty()) {
|
|
201 |
QList<QContactAvatar> avatarDetails =
|
|
202 |
contactList.at(0).details<QContactAvatar> ();
|
|
203 |
|
|
204 |
if (!avatarDetails.isEmpty()) {
|
|
205 |
mThumbnailManager->getThumbnail(
|
|
206 |
avatarDetails.at(0).imageUrl().toString());
|
|
207 |
}
|
|
208 |
}
|
|
209 |
|
|
210 |
// Set default avatar till actual is set.
|
|
211 |
setAvatar(HbIcon(DEFAULT_AVATAR_ICON));
|
|
212 |
}
|
|
213 |
}
|
|
214 |
|
|
215 |
//---------------------------------------------------------------
|
|
216 |
// MsgContactCardWidget::clearContent
|
|
217 |
// @see header file
|
|
218 |
//---------------------------------------------------------------
|
|
219 |
void MsgContactCardWidget::clearContent()
|
|
220 |
{
|
|
221 |
setAddress("");
|
|
222 |
setAvatar(HbIcon());
|
|
223 |
}
|
|
224 |
|
|
225 |
//---------------------------------------------------------------
|
|
226 |
// MsgContactCardWidget::initGesture
|
|
227 |
// @see header file
|
|
228 |
//---------------------------------------------------------------
|
|
229 |
void MsgContactCardWidget::initGesture()
|
|
230 |
{
|
|
231 |
// Create gesture filter
|
|
232 |
/* QGraphicsScene* sc = this->scene();
|
|
233 |
mGestureFilter = new HbGestureSceneFilter(Qt::LeftButton, this);
|
|
234 |
|
|
235 |
// Add gestures for longpress
|
|
236 |
HbGesture* gestureLongpressed = new HbGesture(HbGesture::longpress, 5);
|
|
237 |
|
|
238 |
mGestureFilter->addGesture(gestureLongpressed);
|
|
239 |
|
|
240 |
connect(gestureLongpressed, SIGNAL(longPress(QPointF)), this, SLOT(handleLongPress(QPointF)));
|
|
241 |
|
|
242 |
//install gesture filter.
|
|
243 |
this->installSceneEventFilter(mGestureFilter);
|
|
244 |
|
|
245 |
disconnect(this->mainWindow(), SIGNAL(viewReady()), this, SLOT(initGesture()));*/
|
|
246 |
}
|
|
247 |
|
|
248 |
//---------------------------------------------------------------
|
|
249 |
// MsgContactCardWidget::mousePressEvent
|
|
250 |
// @see header file
|
|
251 |
//---------------------------------------------------------------
|
|
252 |
void MsgContactCardWidget::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
|
253 |
{
|
|
254 |
mMenuShown = false;
|
|
255 |
|
|
256 |
HbWidgetFeedback::triggered(this, Hb::InstantPressed);
|
|
257 |
|
|
258 |
setBackGround(GROUPBOX_BG_FRAME_PRESSED);
|
|
259 |
|
|
260 |
event->accept();
|
|
261 |
}
|
|
262 |
|
|
263 |
//---------------------------------------------------------------
|
|
264 |
// MsgContactCardWidget::mouseReleaseEvent
|
|
265 |
// @see header file
|
|
266 |
//---------------------------------------------------------------
|
|
267 |
void MsgContactCardWidget::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
|
268 |
{
|
|
269 |
setBackGround(BACKGROUND_FRAME_NORMAL);
|
|
270 |
|
|
271 |
if (this->rect().contains(event->pos()) && !mMenuShown) {
|
|
272 |
HbWidgetFeedback::triggered(this, Hb::InstantClicked);
|
|
273 |
emit clicked();
|
|
274 |
}
|
|
275 |
|
|
276 |
event->accept();
|
|
277 |
}
|
|
278 |
|
|
279 |
//---------------------------------------------------------------
|
|
280 |
// MsgContactCardWidget::setBackGround
|
|
281 |
// @see header file
|
|
282 |
//---------------------------------------------------------------
|
|
283 |
void MsgContactCardWidget::setBackGround(const QString& bg)
|
|
284 |
{
|
|
285 |
HbFrameItem* backGround = new HbFrameItem(this);
|
|
286 |
backGround->frameDrawer().setFrameGraphicsName(bg);
|
|
287 |
backGround->frameDrawer().setFrameType(HbFrameDrawer::NinePieces);
|
|
288 |
this->setBackgroundItem(backGround);
|
|
289 |
this->repolish();
|
|
290 |
}
|
|
291 |
|
|
292 |
//---------------------------------------------------------------
|
|
293 |
// MsgContactCardWidget::handleLongPress
|
|
294 |
// @see header file
|
|
295 |
//---------------------------------------------------------------
|
|
296 |
void MsgContactCardWidget::handleLongPress(QPointF position)
|
|
297 |
{
|
|
298 |
if (KBluetoothMsgsConversationId != ConversationsEngine::instance()->getCurrentConversationId()) {
|
|
299 |
HbMenu* contextMenu = new HbMenu();
|
|
300 |
contextMenu->setDismissPolicy(HbPopup::TapAnywhere);
|
|
301 |
contextMenu->setAttribute(Qt::WA_DeleteOnClose, true);
|
|
302 |
contextMenu->setPreferredPos(position);
|
|
303 |
|
|
304 |
contextMenu->addAction(LOC_MENU_CONTACT_INFO, this, SLOT(openContactInfo()));
|
|
305 |
contextMenu->addAction(LOC_COMMON_MENU_CALL, this, SLOT(call()));
|
|
306 |
|
|
307 |
//If contact doesn't exist in phonebook then add another menu item "Save to Contacts"
|
|
308 |
int contactId = resolveContactId(mContactNumber);
|
|
309 |
if (contactId < 0) {
|
|
310 |
contextMenu->addAction(LOC_SAVETO_CONTACTS, this, SLOT(addToContacts()));
|
|
311 |
}
|
|
312 |
|
|
313 |
contextMenu->show();
|
|
314 |
|
|
315 |
mMenuShown = true;
|
|
316 |
}
|
|
317 |
}
|
|
318 |
|
|
319 |
//---------------------------------------------------------------
|
|
320 |
// MsgContactCardWidget::overrideFeedback
|
|
321 |
// @see header file
|
|
322 |
//---------------------------------------------------------------
|
|
323 |
/*HbFeedback::InstantEffect MsgContactCardWidget::overrideFeedback(Hb::InstantInteraction interaction) const
|
|
324 |
{
|
|
325 |
switch (interaction) {
|
|
326 |
case Hb::InstantPressed:
|
|
327 |
case Hb::InstantClicked:
|
|
328 |
return HbFeedback::Basic;
|
|
329 |
default:
|
|
330 |
return HbFeedback::None;
|
|
331 |
}
|
|
332 |
}*/
|
|
333 |
|
|
334 |
//---------------------------------------------------------------
|
|
335 |
// MsgContactCardWidget::openContactInfo
|
|
336 |
// @see header
|
|
337 |
//---------------------------------------------------------------
|
|
338 |
void MsgContactCardWidget::openContactInfo()
|
|
339 |
{
|
|
340 |
QString operation;
|
|
341 |
QList<QVariant> args;
|
|
342 |
if (KBluetoothMsgsConversationId != ConversationsEngine::instance()->getCurrentConversationId()) {
|
|
343 |
int contactId = resolveContactId(mContactNumber);
|
|
344 |
if (contactId > 0) {
|
|
345 |
//open existing contact card
|
|
346 |
operation = QString("open(int)");
|
|
347 |
args << contactId;
|
|
348 |
}
|
|
349 |
else {
|
|
350 |
//populate data and open unknown contact template
|
|
351 |
operation = QString("editCreateNew(QString,QString)");
|
|
352 |
QString type = QContactPhoneNumber::DefinitionName;
|
|
353 |
|
|
354 |
args << type;
|
|
355 |
args << mAddress;
|
|
356 |
}
|
|
357 |
//service stuff.
|
|
358 |
QString serviceName("com.nokia.services.phonebookservices");
|
|
359 |
|
|
360 |
XQAiwRequest* request;
|
|
361 |
XQApplicationManager appManager;
|
|
362 |
request = appManager.create(serviceName, "Fetch", operation, true); // embedded
|
|
363 |
if (request == NULL) {
|
|
364 |
return;
|
|
365 |
}
|
|
366 |
|
|
367 |
// Result handlers
|
|
368 |
connect(request, SIGNAL(requestOk(const QVariant&)), this, SLOT(handleOk(const QVariant&)));
|
|
369 |
connect(request, SIGNAL(requestError(const QVariant&)), this,
|
|
370 |
SLOT(handleError(const QVariant&)));
|
|
371 |
|
|
372 |
request->setArguments(args);
|
|
373 |
request->send();
|
|
374 |
delete request;
|
|
375 |
}
|
|
376 |
}
|
|
377 |
|
|
378 |
//---------------------------------------------------------------
|
|
379 |
// MsgContactCardWidget::resolveContactId
|
|
380 |
// @see header
|
|
381 |
//---------------------------------------------------------------
|
|
382 |
int MsgContactCardWidget::resolveContactId(const QString& value)
|
|
383 |
{
|
|
384 |
QString displayLabel;
|
|
385 |
|
|
386 |
return MsgContactHandler::resolveContactDisplayName(
|
|
387 |
value,
|
|
388 |
displayLabel,
|
|
389 |
0);
|
|
390 |
}
|
|
391 |
|
|
392 |
//---------------------------------------------------------------
|
|
393 |
// MsgContactCardWidget::call
|
|
394 |
// @see header
|
|
395 |
//---------------------------------------------------------------
|
|
396 |
void MsgContactCardWidget::call()
|
|
397 |
{
|
|
398 |
//Launch dialer service
|
|
399 |
QString serviceName("com.nokia.services.telephony");
|
|
400 |
QString operation("dial(QString)");
|
|
401 |
|
|
402 |
XQServiceRequest* serviceRequest = new XQServiceRequest(serviceName, operation, false);
|
|
403 |
|
|
404 |
connect(serviceRequest, SIGNAL(requestCompleted(QVariant)), this,
|
|
405 |
SLOT(onServiceRequestCompleted()));
|
|
406 |
|
|
407 |
connect(serviceRequest, SIGNAL(requestError(int)), this, SLOT(onServiceRequestCompleted()));
|
|
408 |
|
|
409 |
*serviceRequest << mContactNumber;
|
|
410 |
serviceRequest->send();
|
|
411 |
}
|
|
412 |
|
|
413 |
//---------------------------------------------------------------
|
|
414 |
// MsgContactCardWidget::addToContacts
|
|
415 |
// @see header
|
|
416 |
//---------------------------------------------------------------
|
|
417 |
void MsgContactCardWidget::addToContacts()
|
|
418 |
{
|
|
419 |
}
|
|
420 |
|
|
421 |
//---------------------------------------------------------------
|
|
422 |
// MsgContactCardWidget::handleOk
|
|
423 |
// @see header
|
|
424 |
//---------------------------------------------------------------
|
|
425 |
void MsgContactCardWidget::handleOk(const QVariant& result)
|
|
426 |
{
|
|
427 |
Q_UNUSED(result)
|
|
428 |
|
|
429 |
QList<QContact> matchingContacts =
|
|
430 |
MsgContactHandler::findContactList(mContactNumber);
|
|
431 |
|
|
432 |
if (!matchingContacts.isEmpty()) {
|
|
433 |
setAddress(matchingContacts.at(0).displayLabel());
|
|
434 |
|
|
435 |
QList<QContactAvatar> avatarDetails =
|
|
436 |
matchingContacts.at(0).details<QContactAvatar> ();
|
|
437 |
|
|
438 |
if (!avatarDetails.isEmpty()) {
|
|
439 |
mThumbnailManager->getThumbnail(
|
|
440 |
avatarDetails.at(0).imageUrl().toString());
|
|
441 |
}
|
|
442 |
}
|
|
443 |
}
|
|
444 |
|
|
445 |
//---------------------------------------------------------------
|
|
446 |
// MsgContactCardWidget::handleError
|
|
447 |
// @see header
|
|
448 |
//---------------------------------------------------------------
|
|
449 |
void MsgContactCardWidget::handleError(int errorCode, const QString& errorMessage)
|
|
450 |
{
|
|
451 |
Q_UNUSED(errorMessage)
|
|
452 |
Q_UNUSED(errorCode)
|
|
453 |
}
|
|
454 |
|
|
455 |
//---------------------------------------------------------------
|
|
456 |
// MsgContactCardWidget::onServiceRequestCompleted
|
|
457 |
// @see header
|
|
458 |
//---------------------------------------------------------------
|
|
459 |
void MsgContactCardWidget::onServiceRequestCompleted()
|
|
460 |
{
|
|
461 |
//service request is now complete. delete it.
|
|
462 |
XQServiceRequest* request = qobject_cast<XQServiceRequest*> (sender());
|
|
463 |
if (request) {
|
|
464 |
delete request;
|
|
465 |
}
|
|
466 |
}
|
|
467 |
|
|
468 |
//---------------------------------------------------------------
|
|
469 |
// MsgContactCardWidget::thumbnailReady
|
|
470 |
// @see header
|
|
471 |
//---------------------------------------------------------------
|
|
472 |
void MsgContactCardWidget::thumbnailReady(const QPixmap& pixmap, void *data, int id, int error)
|
|
473 |
{
|
|
474 |
Q_UNUSED(data)
|
|
475 |
Q_UNUSED(id)
|
|
476 |
|
|
477 |
if (!error) {
|
|
478 |
QIcon icon(pixmap);
|
|
479 |
setAvatar(HbIcon(icon));
|
|
480 |
}
|
|
481 |
else {
|
|
482 |
setAvatar(HbIcon(DEFAULT_AVATAR_ICON));
|
|
483 |
}
|
|
484 |
}
|
|
485 |
//---------------------------------------------------------------
|
|
486 |
// MsgContactCardWidget::connectSignals
|
|
487 |
// @see header
|
|
488 |
//---------------------------------------------------------------
|
|
489 |
void MsgContactCardWidget::connectSignals(bool yes)
|
|
490 |
{
|
|
491 |
if (yes) {
|
|
492 |
connect(this, SIGNAL(clicked()), this, SLOT(openContactInfo()));
|
|
493 |
}
|
|
494 |
else {
|
|
495 |
disconnect(this, SIGNAL(clicked()), this, SLOT(openContactInfo()));
|
|
496 |
}
|
|
497 |
}
|
|
498 |
// EOF
|