19 |
19 |
20 // SYSTEM INCLUDES |
20 // SYSTEM INCLUDES |
21 #include <HbStyle> |
21 #include <HbStyle> |
22 #include <HbIconItem> |
22 #include <HbIconItem> |
23 #include <HbTextItem> |
23 #include <HbTextItem> |
24 #include <HbFrameDrawer> |
24 #include <HbTapGesture> |
25 //#include <HbGesture> |
25 #include <HbInstantFeedback> |
26 //#include <HbGestureSceneFilter> |
|
27 #include <HbWidgetFeedback> |
|
28 #include <HbFrameItem> |
26 #include <HbFrameItem> |
29 #include <qcontactphonenumber.h> |
27 #include <qcontactphonenumber.h> |
30 #include <qcontactavatar.h> |
28 #include <qcontactavatar.h> |
31 #include <xqaiwrequest.h> |
29 #include <xqaiwrequest.h> |
32 #include <xqappmgr.h> |
30 #include <xqappmgr.h> |
33 #include <XQServiceRequest.h> |
31 #include <xqservicerequest.h> |
34 #include <cntservicescontact.h> |
32 #include <cntservicescontact.h> |
35 #include <QGraphicsSceneMouseEvent> |
33 #include <QGraphicsSceneMouseEvent> |
36 #include <HbMenu> |
34 #include <HbMenu> |
37 #include <HbMainWindow> |
|
38 #include <thumbnailmanager_qt.h> |
35 #include <thumbnailmanager_qt.h> |
|
36 #include <QTimer> |
39 |
37 |
40 #include <ccsdefs.h> |
38 #include <ccsdefs.h> |
41 |
39 |
42 // USER INCLUDES |
40 // USER INCLUDES |
43 #include "conversationsenginedefines.h" |
41 #include "conversationsenginedefines.h" |
44 #include "debugtraces.h" |
|
45 #include "conversationsengine.h" |
42 #include "conversationsengine.h" |
46 #include "convergedmessage.h" |
43 #include "convergedmessage.h" |
47 #include "msgcontacthandler.h" |
44 #include "msgcontacthandler.h" |
48 |
45 |
49 // LOCAL CONSTANTS |
46 // LOCAL CONSTANTS |
50 const QString DEFAULT_AVATAR_ICON("qtg_large_avatar"); |
47 const QString DEFAULT_AVATAR_ICON("qtg_large_avatar"); |
51 const QString BT_ICON("qtg_large_bluetooth"); |
48 const QString BT_ICON("qtg_large_bluetooth"); |
52 const QString BACKGROUND_FRAME_NORMAL("qtg_fr_groupbox"); |
49 const QString BG_FRAME_NORMAL("qtg_fr_groupbox_normal"); |
53 const QString GROUPBOX_BG_FRAME_PRESSED("qtg_fr_groupbox_pressed"); |
50 const QString BG_FRAME_PRESSED("qtg_fr_groupbox_pressed"); |
54 |
|
55 |
51 |
56 // LOCALIZATION CONSTANTS |
52 // LOCALIZATION CONSTANTS |
57 #define LOC_RECEIVED_FILES hbTrId("txt_messaging_title_received_files") |
53 #define LOC_RECEIVED_FILES hbTrId("txt_messaging_title_received_files") |
58 #define LOC_MENU_CONTACT_INFO hbTrId("txt_messaging_menu_open_contact_info") |
54 #define LOC_MENU_CONTACT_INFO hbTrId("txt_messaging_menu_open_contact_info") |
59 #define LOC_COMMON_MENU_CALL hbTrId("txt_common_menu_call_verb") |
55 #define LOC_COMMON_MENU_CALL hbTrId("txt_common_menu_call_verb") |
64 //--------------------------------------------------------------- |
60 //--------------------------------------------------------------- |
65 // MsgContactCardWidget::MsgContactCardWidget |
61 // MsgContactCardWidget::MsgContactCardWidget |
66 // @see header |
62 // @see header |
67 //--------------------------------------------------------------- |
63 //--------------------------------------------------------------- |
68 MsgContactCardWidget::MsgContactCardWidget(QGraphicsItem *parent) : |
64 MsgContactCardWidget::MsgContactCardWidget(QGraphicsItem *parent) : |
69 HbWidget(parent), mMenuShown(false), mAvatarIconItem(NULL), mPresenceIconItem(NULL), |
65 HbWidget(parent), mIgnoreEvents(false), mAvatarIconItem(NULL), mPresenceIconItem(NULL), |
70 mAddressTextItem(NULL),mThumbnailManager(NULL) |
66 mAddressTextItem(NULL), mThumbnailManager(NULL) |
71 { |
67 { |
72 init(); |
68 init(); |
73 setBackGround(BACKGROUND_FRAME_NORMAL); |
|
74 connectSignals(true); |
|
75 |
|
76 connect(this->mainWindow(), SIGNAL(viewReady()), this, SLOT(initGesture())); |
|
77 } |
69 } |
78 |
70 |
79 //--------------------------------------------------------------- |
71 //--------------------------------------------------------------- |
80 // MsgContactCardWidget::~MsgContactCardWidget |
72 // MsgContactCardWidget::~MsgContactCardWidget |
81 // @see header |
73 // @see header |
82 //--------------------------------------------------------------- |
74 //--------------------------------------------------------------- |
83 MsgContactCardWidget::~MsgContactCardWidget() |
75 MsgContactCardWidget::~MsgContactCardWidget() |
84 { |
76 { |
85 /* if (mGestureFilter) { |
|
86 removeSceneEventFilter(mGestureFilter); |
|
87 }*/ |
|
88 } |
77 } |
89 |
78 |
90 //--------------------------------------------------------------- |
79 //--------------------------------------------------------------- |
91 // MsgContactCardWidget::init |
80 // MsgContactCardWidget::init |
92 // @see header |
81 // @see header |
93 //--------------------------------------------------------------- |
82 //--------------------------------------------------------------- |
94 void MsgContactCardWidget::init() |
83 void MsgContactCardWidget::init() |
95 { |
84 { |
|
85 this->setProperty("state", "normal"); |
|
86 this->grabGesture(Qt::TapGesture); |
|
87 |
|
88 HbFrameItem *frameItem = new HbFrameItem(BG_FRAME_NORMAL, HbFrameDrawer::NinePieces, this); |
|
89 this->setBackgroundItem(frameItem); |
|
90 |
96 mAvatarIconItem = new HbIconItem(this); |
91 mAvatarIconItem = new HbIconItem(this); |
97 HbStyle::setItemName(mAvatarIconItem, "avatar"); |
92 HbStyle::setItemName(mAvatarIconItem, "avatar"); |
98 |
93 |
99 mPresenceIconItem = new HbIconItem(this); |
94 mPresenceIconItem = new HbIconItem(this); |
100 HbStyle::setItemName(mPresenceIconItem, "presence"); |
95 HbStyle::setItemName(mPresenceIconItem, "presence"); |
192 } |
187 } |
193 |
188 |
194 setAddress(contactName); |
189 setAddress(contactName); |
195 |
190 |
196 // Set Avatar |
191 // Set Avatar |
197 QList<QContact> contactList = |
192 QList<QContact> contactList = MsgContactHandler::findContactList(mContactNumber); |
198 MsgContactHandler::findContactList(mContactNumber); |
193 |
199 |
|
200 if (!contactList.isEmpty()) { |
194 if (!contactList.isEmpty()) { |
201 QList<QContactAvatar> avatarDetails = |
195 QList<QContactAvatar> avatarDetails = contactList.at(0).details<QContactAvatar> (); |
202 contactList.at(0).details<QContactAvatar> (); |
196 |
203 |
|
204 if (!avatarDetails.isEmpty()) { |
197 if (!avatarDetails.isEmpty()) { |
205 mThumbnailManager->getThumbnail( |
198 mThumbnailManager->getThumbnail(avatarDetails.at(0).imageUrl().toString()); |
206 avatarDetails.at(0).imageUrl().toString()); |
|
207 } |
199 } |
208 } |
200 } |
209 |
201 |
210 // Set default avatar till actual is set. |
202 // Set default avatar till actual is set. |
211 setAvatar(HbIcon(DEFAULT_AVATAR_ICON)); |
203 setAvatar(HbIcon(DEFAULT_AVATAR_ICON)); |
221 setAddress(""); |
213 setAddress(""); |
222 setAvatar(HbIcon()); |
214 setAvatar(HbIcon()); |
223 } |
215 } |
224 |
216 |
225 //--------------------------------------------------------------- |
217 //--------------------------------------------------------------- |
226 // MsgContactCardWidget::initGesture |
218 // MsgContactCardWidget::gestureEvent |
227 // @see header file |
219 // @see header file |
228 //--------------------------------------------------------------- |
220 //--------------------------------------------------------------- |
229 void MsgContactCardWidget::initGesture() |
221 void MsgContactCardWidget::gestureEvent(QGestureEvent *event) |
230 { |
222 { |
231 // Create gesture filter |
223 HbTapGesture *tapGesture = qobject_cast<HbTapGesture*> (event->gesture(Qt::TapGesture)); |
232 /* QGraphicsScene* sc = this->scene(); |
224 if (tapGesture) { |
233 mGestureFilter = new HbGestureSceneFilter(Qt::LeftButton, this); |
225 switch (tapGesture->state()) { |
234 |
226 case Qt::GestureStarted: |
235 // Add gestures for longpress |
227 { |
236 HbGesture* gestureLongpressed = new HbGesture(HbGesture::longpress, 5); |
228 // Trigger haptic feedback. |
237 |
229 HbInstantFeedback::play(HbFeedback::Basic); |
238 mGestureFilter->addGesture(gestureLongpressed); |
230 setPressed(true); |
239 |
231 break; |
240 connect(gestureLongpressed, SIGNAL(longPress(QPointF)), this, SLOT(handleLongPress(QPointF))); |
232 } |
241 |
233 case Qt::GestureUpdated: |
242 //install gesture filter. |
234 { |
243 this->installSceneEventFilter(mGestureFilter); |
235 if (HbTapGesture::TapAndHold == tapGesture->tapStyleHint()) { |
244 |
236 // Handle longtap. |
245 disconnect(this->mainWindow(), SIGNAL(viewReady()), this, SLOT(initGesture()));*/ |
237 setPressed(false); |
246 } |
238 handleLongPress(tapGesture->scenePosition()); |
247 |
239 } |
248 //--------------------------------------------------------------- |
240 break; |
249 // MsgContactCardWidget::mousePressEvent |
241 } |
250 // @see header file |
242 case Qt::GestureFinished: |
251 //--------------------------------------------------------------- |
243 { |
252 void MsgContactCardWidget::mousePressEvent(QGraphicsSceneMouseEvent *event) |
244 HbInstantFeedback::play(HbFeedback::Basic); |
253 { |
245 if (HbTapGesture::Tap == tapGesture->tapStyleHint()) { |
254 mMenuShown = false; |
246 // Handle short tap. |
255 |
247 setPressed(false); |
256 HbWidgetFeedback::triggered(this, Hb::InstantPressed); |
248 openContactInfo(); |
257 |
249 } |
258 setBackGround(GROUPBOX_BG_FRAME_PRESSED); |
250 break; |
259 |
251 } |
260 event->accept(); |
252 case Qt::GestureCanceled: |
261 } |
253 { |
262 |
254 HbInstantFeedback::play(HbFeedback::Basic); |
263 //--------------------------------------------------------------- |
255 setPressed(false); |
264 // MsgContactCardWidget::mouseReleaseEvent |
256 break; |
265 // @see header file |
257 } |
266 //--------------------------------------------------------------- |
258 } |
267 void MsgContactCardWidget::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) |
259 } |
268 { |
260 else { |
269 setBackGround(BACKGROUND_FRAME_NORMAL); |
261 HbWidget::gestureEvent(event); |
270 |
262 } |
271 if (this->rect().contains(event->pos()) && !mMenuShown) { |
263 } |
272 HbWidgetFeedback::triggered(this, Hb::InstantClicked); |
264 |
273 emit clicked(); |
265 //--------------------------------------------------------------- |
274 } |
266 // MsgContactCardWidget::setPressed |
275 |
267 // @see header file |
276 event->accept(); |
268 //--------------------------------------------------------------- |
277 } |
269 void MsgContactCardWidget::setPressed(bool pressed) |
278 |
270 { |
279 //--------------------------------------------------------------- |
271 HbFrameItem *frameItem = static_cast<HbFrameItem *> (this->backgroundItem()); |
280 // MsgContactCardWidget::setBackGround |
272 if (pressed) { |
281 // @see header file |
273 this->setProperty("state", "pressed"); |
282 //--------------------------------------------------------------- |
274 frameItem->frameDrawer().setFrameGraphicsName(BG_FRAME_PRESSED); |
283 void MsgContactCardWidget::setBackGround(const QString& bg) |
275 } |
284 { |
276 else { |
285 HbFrameItem* backGround = new HbFrameItem(this); |
277 this->setProperty("state", "normal"); |
286 backGround->frameDrawer().setFrameGraphicsName(bg); |
278 frameItem->frameDrawer().setFrameGraphicsName(BG_FRAME_NORMAL); |
287 backGround->frameDrawer().setFrameType(HbFrameDrawer::NinePieces); |
279 } |
288 this->setBackgroundItem(backGround); |
|
289 this->repolish(); |
|
290 } |
280 } |
291 |
281 |
292 //--------------------------------------------------------------- |
282 //--------------------------------------------------------------- |
293 // MsgContactCardWidget::handleLongPress |
283 // MsgContactCardWidget::handleLongPress |
294 // @see header file |
284 // @see header file |
295 //--------------------------------------------------------------- |
285 //--------------------------------------------------------------- |
296 void MsgContactCardWidget::handleLongPress(QPointF position) |
286 void MsgContactCardWidget::handleLongPress(const QPointF &position) |
297 { |
287 { |
|
288 // Check if events need to be ignored/accepted |
|
289 if (mIgnoreEvents) { |
|
290 return; |
|
291 } |
|
292 |
298 if (KBluetoothMsgsConversationId != ConversationsEngine::instance()->getCurrentConversationId()) { |
293 if (KBluetoothMsgsConversationId != ConversationsEngine::instance()->getCurrentConversationId()) { |
299 HbMenu* contextMenu = new HbMenu(); |
294 HbMenu* contextMenu = new HbMenu(); |
300 contextMenu->setDismissPolicy(HbPopup::TapAnywhere); |
295 contextMenu->setDismissPolicy(HbPopup::TapAnywhere); |
301 contextMenu->setAttribute(Qt::WA_DeleteOnClose, true); |
296 contextMenu->setAttribute(Qt::WA_DeleteOnClose, true); |
302 contextMenu->setPreferredPos(position); |
297 contextMenu->setPreferredPos(position); |
309 if (contactId < 0) { |
304 if (contactId < 0) { |
310 contextMenu->addAction(LOC_SAVETO_CONTACTS, this, SLOT(addToContacts())); |
305 contextMenu->addAction(LOC_SAVETO_CONTACTS, this, SLOT(addToContacts())); |
311 } |
306 } |
312 |
307 |
313 contextMenu->show(); |
308 contextMenu->show(); |
314 |
309 } |
315 mMenuShown = true; |
310 } |
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 |
311 |
334 //--------------------------------------------------------------- |
312 //--------------------------------------------------------------- |
335 // MsgContactCardWidget::openContactInfo |
313 // MsgContactCardWidget::openContactInfo |
336 // @see header |
314 // @see header |
337 //--------------------------------------------------------------- |
315 //--------------------------------------------------------------- |
338 void MsgContactCardWidget::openContactInfo() |
316 void MsgContactCardWidget::openContactInfo() |
339 { |
317 { |
|
318 this->ungrabGesture(Qt::TapGesture); |
|
319 |
|
320 // Check if events need to be ignored/accepted |
|
321 if (mIgnoreEvents) { |
|
322 return; |
|
323 } |
|
324 |
340 QString operation; |
325 QString operation; |
341 QList<QVariant> args; |
326 QList<QVariant> args; |
342 if (KBluetoothMsgsConversationId != ConversationsEngine::instance()->getCurrentConversationId()) { |
327 if (KBluetoothMsgsConversationId != ConversationsEngine::instance()->getCurrentConversationId()) { |
343 int contactId = resolveContactId(mContactNumber); |
328 int contactId = resolveContactId(mContactNumber); |
344 if (contactId > 0) { |
329 if (contactId > 0) { |
371 |
356 |
372 request->setArguments(args); |
357 request->setArguments(args); |
373 request->send(); |
358 request->send(); |
374 delete request; |
359 delete request; |
375 } |
360 } |
|
361 |
|
362 //fire timer to regrab gesture after some delay. |
|
363 QTimer::singleShot(300,this,SLOT(regrabGesture())); |
376 } |
364 } |
377 |
365 |
378 //--------------------------------------------------------------- |
366 //--------------------------------------------------------------- |
379 // MsgContactCardWidget::resolveContactId |
367 // MsgContactCardWidget::resolveContactId |
380 // @see header |
368 // @see header |
381 //--------------------------------------------------------------- |
369 //--------------------------------------------------------------- |
382 int MsgContactCardWidget::resolveContactId(const QString& value) |
370 int MsgContactCardWidget::resolveContactId(const QString& value) |
383 { |
371 { |
384 QString displayLabel; |
372 QString displayLabel; |
385 |
373 |
386 return MsgContactHandler::resolveContactDisplayName( |
374 int count; |
387 value, |
375 return MsgContactHandler::resolveContactDisplayName(value, displayLabel, count); |
388 displayLabel, |
|
389 0); |
|
390 } |
376 } |
391 |
377 |
392 //--------------------------------------------------------------- |
378 //--------------------------------------------------------------- |
393 // MsgContactCardWidget::call |
379 // MsgContactCardWidget::call |
394 // @see header |
380 // @see header |
395 //--------------------------------------------------------------- |
381 //--------------------------------------------------------------- |
396 void MsgContactCardWidget::call() |
382 void MsgContactCardWidget::call() |
397 { |
383 { |
398 //Launch dialer service |
384 //Launch dialer service |
399 QString serviceName("com.nokia.services.telephony"); |
385 QString serviceName("com.nokia.symbian.ICallDial"); |
400 QString operation("dial(QString)"); |
386 QString operation("dial(QString)"); |
401 |
387 |
402 XQServiceRequest* serviceRequest = new XQServiceRequest(serviceName, operation, false); |
388 XQServiceRequest* serviceRequest = new XQServiceRequest(serviceName, operation, false); |
403 |
389 |
404 connect(serviceRequest, SIGNAL(requestCompleted(QVariant)), this, |
390 connect(serviceRequest, SIGNAL(requestCompleted(QVariant)), this, |
424 //--------------------------------------------------------------- |
410 //--------------------------------------------------------------- |
425 void MsgContactCardWidget::handleOk(const QVariant& result) |
411 void MsgContactCardWidget::handleOk(const QVariant& result) |
426 { |
412 { |
427 Q_UNUSED(result) |
413 Q_UNUSED(result) |
428 |
414 |
429 QList<QContact> matchingContacts = |
415 QList<QContact> matchingContacts = MsgContactHandler::findContactList(mContactNumber); |
430 MsgContactHandler::findContactList(mContactNumber); |
|
431 |
416 |
432 if (!matchingContacts.isEmpty()) { |
417 if (!matchingContacts.isEmpty()) { |
433 setAddress(matchingContacts.at(0).displayLabel()); |
418 setAddress(matchingContacts.at(0).displayLabel()); |
434 |
419 |
435 QList<QContactAvatar> avatarDetails = |
420 QList<QContactAvatar> avatarDetails = matchingContacts.at(0).details<QContactAvatar> (); |
436 matchingContacts.at(0).details<QContactAvatar> (); |
421 |
437 |
|
438 if (!avatarDetails.isEmpty()) { |
422 if (!avatarDetails.isEmpty()) { |
439 mThumbnailManager->getThumbnail( |
423 mThumbnailManager->getThumbnail(avatarDetails.at(0).imageUrl().toString()); |
440 avatarDetails.at(0).imageUrl().toString()); |
|
441 } |
424 } |
442 } |
425 } |
443 } |
426 } |
444 |
427 |
445 //--------------------------------------------------------------- |
428 //--------------------------------------------------------------- |
480 } |
463 } |
481 else { |
464 else { |
482 setAvatar(HbIcon(DEFAULT_AVATAR_ICON)); |
465 setAvatar(HbIcon(DEFAULT_AVATAR_ICON)); |
483 } |
466 } |
484 } |
467 } |
485 //--------------------------------------------------------------- |
468 |
486 // MsgContactCardWidget::connectSignals |
469 //--------------------------------------------------------------- |
487 // @see header |
470 // MsgContactCardWidget::ignoreSignals |
488 //--------------------------------------------------------------- |
471 // @see header |
489 void MsgContactCardWidget::connectSignals(bool yes) |
472 //--------------------------------------------------------------- |
490 { |
473 void MsgContactCardWidget::ignoreSignals(bool yes) |
491 if (yes) { |
474 { |
492 connect(this, SIGNAL(clicked()), this, SLOT(openContactInfo())); |
475 mIgnoreEvents = yes; |
493 } |
476 } |
494 else { |
477 |
495 disconnect(this, SIGNAL(clicked()), this, SLOT(openContactInfo())); |
478 //--------------------------------------------------------------- |
496 } |
479 // MsgContactCardWidget::regrabGesture |
|
480 // @see header file |
|
481 //--------------------------------------------------------------- |
|
482 void MsgContactCardWidget::regrabGesture() |
|
483 { |
|
484 this->grabGesture(Qt::TapGesture); |
497 } |
485 } |
498 // EOF |
486 // EOF |