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 <HbPushButton> |
|
25 #include <HbFrameDrawer> |
24 #include <HbFrameDrawer> |
|
25 #include <HbGesture> |
|
26 #include <HbGestureSceneFilter> |
|
27 #include <HbWidgetFeedback> |
|
28 #include <HbFrameItem> |
|
29 #include <qmobilityglobal.h> |
|
30 #include <qcontactphonenumber.h> |
|
31 #include <qcontactfilter.h> |
|
32 #include <qcontactmanager.h> |
|
33 #include <qcontactdetailfilter.h> |
|
34 #include <xqaiwrequest.h> |
|
35 #include <xqappmgr.h> |
|
36 #include <XQServiceRequest.h> |
|
37 #include <cntservicescontact.h> |
|
38 #include <QGraphicsSceneMouseEvent> |
|
39 #include <HbMenu> |
|
40 #include <HbMainWindow> |
|
41 |
|
42 #include <ccsdefs.h> |
26 |
43 |
27 // USER INCLUDES |
44 // USER INCLUDES |
28 #include "conversationsenginedefines.h" |
45 #include "conversationsenginedefines.h" |
29 #include "debugtraces.h" |
46 #include "debugtraces.h" |
30 #include "conversationsengine.h" |
47 #include "conversationsengine.h" |
|
48 #include "convergedmessage.h" |
|
49 |
|
50 QTM_USE_NAMESPACE |
31 |
51 |
32 // LOCAL CONSTANTS |
52 // LOCAL CONSTANTS |
33 const QString DEFAULT_AVATAR_ICON(":/icons/qtg_large_avatar.svg"); |
53 const QString DEFAULT_AVATAR_ICON("qtg_large_avatar"); |
34 const QString ONLINE_ICON(":/icons/qtg_small_online.svg"); |
54 const QString BT_ICON("qtg_large_bluetooth"); |
35 const QString OFFLINE_ICON(":/icons/qtg_small_offline.svg"); |
55 const QString BACKGROUND_FRAME_NORMAL("qtg_fr_groupbox"); |
36 const QString BACKGROUND_FRAME("qtg_fr_list_normal"); |
56 const QString GROUPBOX_BG_FRAME_PRESSED("qtg_fr_groupbox_pressed"); |
|
57 |
37 const QString PLUGINPATH("conversationviewplugin.dll"); |
58 const QString PLUGINPATH("conversationviewplugin.dll"); |
38 |
59 |
|
60 // LOCALIZATION CONSTANTS |
|
61 #define LOC_RECEIVED_FILES hbTrId("txt_messaging_title_received_files") |
|
62 #define LOC_MENU_CONTACT_INFO hbTrId("txt_messaging_menu_open_contact_info") |
|
63 #define LOC_COMMON_MENU_CALL hbTrId("txt_common_menu_call_verb") |
|
64 #define LOC_SAVETO_CONTACTS hbTrId("txt_messaging_menu_save_to_contacts") |
|
65 |
39 //--------------------------------------------------------------- |
66 //--------------------------------------------------------------- |
40 // MsgContactCardWidget::MsgContactCardWidget |
67 // MsgContactCardWidget::MsgContactCardWidget |
41 // @see header |
68 // @see header |
42 //--------------------------------------------------------------- |
69 //--------------------------------------------------------------- |
43 MsgContactCardWidget::MsgContactCardWidget(QGraphicsItem *parent) : |
70 MsgContactCardWidget::MsgContactCardWidget(QGraphicsItem *parent) : |
44 HbAbstractButton(parent), mAvatarIconItem(NULL), |
71 HbWidget(parent), |
45 mPresenceIconItem(NULL), |
72 mMenuShown(false), |
46 mAddressTextItem(NULL) |
73 mAvatarIconItem(NULL), |
|
74 mPresenceIconItem(NULL), |
|
75 mAddressTextItem(NULL), |
|
76 mGestureFilter(NULL) |
|
77 |
47 { |
78 { |
48 int baseId = style()->registerPlugin(PLUGINPATH); |
79 int baseId = style()->registerPlugin(PLUGINPATH); |
49 QDEBUG_WRITE_FORMAT("MsgContactCardWidget BASE ID --->", baseId); |
80 QDEBUG_WRITE_FORMAT("MsgContactCardWidget BASE ID --->", baseId); |
50 setPluginBaseId(baseId); |
81 setPluginBaseId(baseId); |
51 |
82 |
52 init(); |
83 init(); |
|
84 setBackGround(BACKGROUND_FRAME_NORMAL); |
|
85 connectSignals(true); |
|
86 |
|
87 connect(this->mainWindow(),SIGNAL(viewReady()),this,SLOT(initGesture())); |
53 } |
88 } |
54 |
89 |
55 //--------------------------------------------------------------- |
90 //--------------------------------------------------------------- |
56 // MsgContactCardWidget::~MsgContactCardWidget |
91 // MsgContactCardWidget::~MsgContactCardWidget |
57 // @see header |
92 // @see header |
58 //--------------------------------------------------------------- |
93 //--------------------------------------------------------------- |
59 MsgContactCardWidget::~MsgContactCardWidget() |
94 MsgContactCardWidget::~MsgContactCardWidget() |
60 { |
95 { |
61 style()->unregisterPlugin(PLUGINPATH); |
96 style()->unregisterPlugin(PLUGINPATH); |
|
97 |
|
98 if(mGestureFilter) |
|
99 { |
|
100 removeSceneEventFilter(mGestureFilter); |
|
101 } |
62 } |
102 } |
63 |
103 |
64 //--------------------------------------------------------------- |
104 //--------------------------------------------------------------- |
65 // MsgContactCardWidget::init |
105 // MsgContactCardWidget::init |
66 // @see header |
106 // @see header |
137 // @see header file |
166 // @see header file |
138 //--------------------------------------------------------------- |
167 //--------------------------------------------------------------- |
139 void MsgContactCardWidget::updateContents() |
168 void MsgContactCardWidget::updateContents() |
140 { |
169 { |
141 // Get the Model Index |
170 // Get the Model Index |
142 QModelIndex index = |
171 QModelIndex index = ConversationsEngine::instance()->getConversationsModel()->index(0, 0); |
143 ConversationsEngine::instance()->getConversationsModel()->index(0, 0); |
172 |
144 |
173 // Index is not valid, return. |
145 //Set the Contact Name/Number |
174 if (!index.isValid()) { |
146 qint64 convId ; |
175 return; |
147 QString firstName; |
176 } |
148 QString lastName; |
177 |
149 QString contactAddress; |
178 qint64 convId = ConversationsEngine::instance()->getCurrentConversationId(); |
150 convId = ConversationsEngine::instance()->getCurrentConversationId(); |
179 |
151 ConversationsEngine::instance()->getContactDetails(convId,firstName, |
180 if (KBluetoothMsgsConversationId == convId) { |
152 lastName,contactAddress); |
181 setAddress(LOC_RECEIVED_FILES); |
153 //QString contactAddress = index.data(ConversationAddress).toString(); |
182 setAvatar(HbIcon(BT_ICON)); |
154 QString nickName;// = index.data(NickName).toString(); TODO |
183 } |
155 QString contactName; |
184 else { |
156 if (!nickName.isEmpty()) |
185 //Set the Contact Name/Number |
157 { |
186 qint64 convId; |
158 contactName.append(nickName); |
187 QString displayName; |
159 } |
188 QString contactAddress; |
160 else if (firstName.isEmpty() && lastName.isEmpty()) |
189 convId = ConversationsEngine::instance()->getCurrentConversationId(); |
161 { |
190 ConversationsEngine::instance()->getContactDetails(convId, displayName, |
162 contactName.append(contactAddress); |
191 contactAddress); |
163 } |
192 |
164 else if (lastName.isEmpty() && !firstName.isEmpty()) |
193 mContactNumber = contactAddress; |
165 { |
194 QString contactName; |
166 contactName.append(firstName); |
195 if (displayName.isEmpty()) { |
167 } |
196 contactName.append(contactAddress); |
168 else if (firstName.isEmpty() && !lastName.isEmpty()) |
197 } |
169 { |
198 else { |
170 contactName.append(lastName); |
199 contactName.append(displayName); |
|
200 } |
|
201 |
|
202 setAddress(contactName); |
|
203 |
|
204 // Set Avatar |
|
205 HbIcon avatar; |
|
206 QByteArray avatarByteArray = index.data(Avatar).toByteArray(); |
|
207 if (avatarByteArray.isEmpty()) { |
|
208 avatar = HbIcon(DEFAULT_AVATAR_ICON); |
|
209 } |
|
210 else { |
|
211 QPixmap pixmap; |
|
212 pixmap.loadFromData(avatarByteArray); |
|
213 avatar = HbIcon(QIcon(pixmap)); |
|
214 } |
|
215 setAvatar(avatar); |
|
216 } |
|
217 } |
|
218 |
|
219 //--------------------------------------------------------------- |
|
220 // MsgContactCardWidget::clearContent |
|
221 // @see header file |
|
222 //--------------------------------------------------------------- |
|
223 void MsgContactCardWidget::clearContent() |
|
224 { |
|
225 setAddress(""); |
|
226 setAvatar(HbIcon()); |
|
227 } |
|
228 |
|
229 //--------------------------------------------------------------- |
|
230 // MsgContactCardWidget::initGesture |
|
231 // @see header file |
|
232 //--------------------------------------------------------------- |
|
233 void MsgContactCardWidget::initGesture() |
|
234 { |
|
235 // Create gesture filter |
|
236 QGraphicsScene* sc = this->scene(); |
|
237 mGestureFilter = new HbGestureSceneFilter( Qt::LeftButton, this ); |
|
238 |
|
239 // Add gestures for longpress |
|
240 HbGesture* gestureLongpressed = new HbGesture( HbGesture::longpress,5 ); |
|
241 |
|
242 mGestureFilter->addGesture( gestureLongpressed ); |
|
243 |
|
244 connect( gestureLongpressed, SIGNAL(longPress(QPointF)), |
|
245 this, SLOT(handleLongPress(QPointF))); |
|
246 |
|
247 //install gesture filter. |
|
248 this->installSceneEventFilter(mGestureFilter); |
|
249 |
|
250 disconnect(this->mainWindow(),SIGNAL(viewReady()),this,SLOT(initGesture())); |
|
251 } |
|
252 |
|
253 //--------------------------------------------------------------- |
|
254 // MsgContactCardWidget::mousePressEvent |
|
255 // @see header file |
|
256 //--------------------------------------------------------------- |
|
257 void MsgContactCardWidget::mousePressEvent(QGraphicsSceneMouseEvent *event) |
|
258 { |
|
259 mMenuShown = false; |
|
260 |
|
261 HbWidgetFeedback::triggered(this, Hb::InstantPressed); |
|
262 |
|
263 setBackGround(GROUPBOX_BG_FRAME_PRESSED); |
|
264 |
|
265 event->accept(); |
|
266 } |
|
267 |
|
268 |
|
269 //--------------------------------------------------------------- |
|
270 // MsgContactCardWidget::mouseReleaseEvent |
|
271 // @see header file |
|
272 //--------------------------------------------------------------- |
|
273 void MsgContactCardWidget::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) |
|
274 { |
|
275 setBackGround(BACKGROUND_FRAME_NORMAL); |
|
276 |
|
277 if(this->rect().contains(event->pos())&& !mMenuShown) |
|
278 { |
|
279 HbWidgetFeedback::triggered(this, Hb::InstantClicked); |
|
280 emit clicked(); |
|
281 } |
|
282 |
|
283 event->accept(); |
|
284 } |
|
285 |
|
286 //--------------------------------------------------------------- |
|
287 // MsgContactCardWidget::setBackGround |
|
288 // @see header file |
|
289 //--------------------------------------------------------------- |
|
290 void MsgContactCardWidget::setBackGround(const QString& bg) |
|
291 { |
|
292 HbFrameItem* backGround = new HbFrameItem(this); |
|
293 backGround->frameDrawer().setFrameGraphicsName(bg); |
|
294 backGround->frameDrawer().setFrameType(HbFrameDrawer::NinePieces); |
|
295 this->setBackgroundItem(backGround); |
|
296 this->repolish(); |
|
297 } |
|
298 |
|
299 //--------------------------------------------------------------- |
|
300 // MsgContactCardWidget::handleLongPress |
|
301 // @see header file |
|
302 //--------------------------------------------------------------- |
|
303 void MsgContactCardWidget::handleLongPress(QPointF position) |
|
304 { |
|
305 if(KBluetoothMsgsConversationId |
|
306 != ConversationsEngine::instance()->getCurrentConversationId()) |
|
307 { |
|
308 HbMenu* contextMenu = new HbMenu(); |
|
309 contextMenu->setDismissPolicy(HbPopup::TapAnywhere); |
|
310 contextMenu->setAttribute(Qt::WA_DeleteOnClose, true); |
|
311 contextMenu->setPreferredPos(position); |
|
312 |
|
313 contextMenu->addAction(LOC_MENU_CONTACT_INFO,this, SLOT(openContactInfo())); |
|
314 contextMenu->addAction(LOC_COMMON_MENU_CALL, this, SLOT(call())); |
|
315 |
|
316 //If contact doesn't exist in phonebook then add another menu item "Save to Contacts" |
|
317 int contactId = resolveContactId(mContactNumber); |
|
318 if(contactId < 0) |
|
319 { |
|
320 contextMenu->addAction(LOC_SAVETO_CONTACTS, this, SLOT(addToContacts())); |
|
321 } |
|
322 |
|
323 contextMenu->show(); |
|
324 |
|
325 mMenuShown = true; |
|
326 } |
|
327 } |
|
328 |
|
329 //--------------------------------------------------------------- |
|
330 // MsgContactCardWidget::overrideFeedback |
|
331 // @see header file |
|
332 //--------------------------------------------------------------- |
|
333 HbFeedback::InstantEffect MsgContactCardWidget::overrideFeedback(Hb::InstantInteraction interaction) const |
|
334 { |
|
335 switch(interaction) |
|
336 { |
|
337 case Hb::InstantPressed: |
|
338 case Hb::InstantClicked: |
|
339 return HbFeedback::Basic; |
|
340 default: |
|
341 return HbFeedback::NoOverride; |
|
342 } |
|
343 } |
|
344 |
|
345 //--------------------------------------------------------------- |
|
346 // MsgContactCardWidget::openContactInfo |
|
347 // @see header |
|
348 //--------------------------------------------------------------- |
|
349 void MsgContactCardWidget::openContactInfo() |
|
350 { |
|
351 QString operation; |
|
352 QList<QVariant> args; |
|
353 if(KBluetoothMsgsConversationId |
|
354 != ConversationsEngine::instance()->getCurrentConversationId()) |
|
355 { |
|
356 int contactId = resolveContactId(mContactNumber); |
|
357 if(contactId > 0) |
|
358 { |
|
359 //open existing contact card |
|
360 operation = QString("open(int)"); |
|
361 args << contactId; |
|
362 } |
|
363 else |
|
364 { |
|
365 //populate data and open unknown contact template |
|
366 operation = QString("editCreateNew(QString,QString)"); |
|
367 QString type = QContactPhoneNumber::DefinitionName; |
|
368 |
|
369 args << type; |
|
370 args << mAddress; |
|
371 } |
|
372 //service stuff. |
|
373 QString serviceName("com.nokia.services.phonebookservices"); |
|
374 |
|
375 XQAiwRequest* request; |
|
376 XQApplicationManager appManager; |
|
377 request = appManager.create(serviceName, "Fetch", operation, true); // embedded |
|
378 if ( request == NULL ) |
|
379 { |
|
380 return; |
|
381 } |
|
382 |
|
383 // Result handlers |
|
384 connect (request, SIGNAL(requestOk(const QVariant&)), this, SLOT(handleOk(const QVariant&))); |
|
385 connect (request, SIGNAL(requestError(const QVariant&)), this, SLOT(handleError(const QVariant&))); |
|
386 |
|
387 request->setArguments(args); |
|
388 request->send(); |
|
389 delete request; |
|
390 } |
|
391 } |
|
392 |
|
393 //--------------------------------------------------------------- |
|
394 // MsgContactCardWidget::resolveContactId |
|
395 // @see header |
|
396 //--------------------------------------------------------------- |
|
397 int MsgContactCardWidget::resolveContactId(const QString& value) |
|
398 { |
|
399 int contactId = -1; |
|
400 |
|
401 QContactManager phonebookManager("symbian"); |
|
402 |
|
403 QContactDetailFilter phoneFilter; |
|
404 phoneFilter.setDetailDefinitionName(QContactPhoneNumber::DefinitionName, |
|
405 QContactPhoneNumber::FieldNumber); |
|
406 phoneFilter.setValue(value); |
|
407 phoneFilter.setMatchFlags(QContactFilter::MatchEndsWith); |
|
408 |
|
409 QList<QContactSortOrder> sortOrder; |
|
410 QList<QContact> matchingContacts = phonebookManager.contacts( |
|
411 phoneFilter, |
|
412 sortOrder, |
|
413 QStringList()); |
|
414 |
|
415 if ( matchingContacts.count() > 0 ) |
|
416 { |
|
417 contactId = matchingContacts.at(0).localId(); |
|
418 } |
|
419 |
|
420 return contactId; |
|
421 } |
|
422 |
|
423 //--------------------------------------------------------------- |
|
424 // MsgContactCardWidget::call |
|
425 // @see header |
|
426 //--------------------------------------------------------------- |
|
427 void MsgContactCardWidget::call() |
|
428 { |
|
429 //Launch dialer service |
|
430 QString serviceName("com.nokia.services.telephony"); |
|
431 QString operation("dial(QString)"); |
|
432 |
|
433 XQServiceRequest* serviceRequest = new XQServiceRequest(serviceName,operation,false); |
|
434 |
|
435 connect(serviceRequest, SIGNAL(requestCompleted(QVariant)), |
|
436 this, SLOT(onServiceRequestCompleted())); |
|
437 |
|
438 connect(serviceRequest, SIGNAL(requestError(int)), |
|
439 this, SLOT(onServiceRequestCompleted())); |
|
440 |
|
441 *serviceRequest << mContactNumber; |
|
442 serviceRequest->send(); |
|
443 } |
|
444 |
|
445 //--------------------------------------------------------------- |
|
446 // MsgContactCardWidget::addToContacts |
|
447 // @see header |
|
448 //--------------------------------------------------------------- |
|
449 void MsgContactCardWidget::addToContacts() |
|
450 { |
|
451 } |
|
452 |
|
453 //--------------------------------------------------------------- |
|
454 // MsgContactCardWidget::handleOk |
|
455 // @see header |
|
456 //--------------------------------------------------------------- |
|
457 void MsgContactCardWidget::handleOk(const QVariant& result) |
|
458 { |
|
459 Q_UNUSED(result) |
|
460 |
|
461 QContactManager phonebookManager("symbian"); |
|
462 |
|
463 QContactDetailFilter phoneFilter; |
|
464 phoneFilter.setDetailDefinitionName(QContactPhoneNumber::DefinitionName, |
|
465 QContactPhoneNumber::FieldNumber); |
|
466 phoneFilter.setValue(mContactNumber); |
|
467 phoneFilter.setMatchFlags(QContactFilter::MatchEndsWith); |
|
468 |
|
469 QList<QContactSortOrder> sortOrder; |
|
470 QList<QContact> matchingContacts = phonebookManager.contacts(phoneFilter, |
|
471 sortOrder, QStringList()); |
|
472 |
|
473 if(matchingContacts.count()) |
|
474 { |
|
475 setAddress(matchingContacts.at(0).displayLabel()); |
|
476 } |
|
477 } |
|
478 |
|
479 //--------------------------------------------------------------- |
|
480 // MsgContactCardWidget::handleError |
|
481 // @see header |
|
482 //--------------------------------------------------------------- |
|
483 void MsgContactCardWidget::handleError(int errorCode, const QString& errorMessage) |
|
484 { |
|
485 Q_UNUSED(errorMessage) |
|
486 Q_UNUSED(errorCode) |
|
487 } |
|
488 |
|
489 //--------------------------------------------------------------- |
|
490 // MsgContactCardWidget::onServiceRequestCompleted |
|
491 // @see header |
|
492 //--------------------------------------------------------------- |
|
493 void MsgContactCardWidget::onServiceRequestCompleted() |
|
494 { |
|
495 //service request is now complete. delete it. |
|
496 XQServiceRequest* request = qobject_cast<XQServiceRequest*>(sender()); |
|
497 if(request) |
|
498 { |
|
499 delete request; |
|
500 } |
|
501 } |
|
502 |
|
503 //--------------------------------------------------------------- |
|
504 // MsgContactCardWidget::connectSignals |
|
505 // @see header |
|
506 //--------------------------------------------------------------- |
|
507 void MsgContactCardWidget::connectSignals(bool yes) |
|
508 { |
|
509 if(yes) |
|
510 { |
|
511 connect(this,SIGNAL(clicked()),this,SLOT(openContactInfo())); |
171 } |
512 } |
172 else |
513 else |
173 { |
514 { |
174 // If both first Name and last name are present |
515 disconnect(this,SIGNAL(clicked()),this,SLOT(openContactInfo())); |
175 contactName.append(firstName); |
516 } |
176 contactName.append(" "); |
|
177 contactName.append(lastName); |
|
178 } |
|
179 setAddress(contactName); |
|
180 |
|
181 QByteArray avatarByteArray = index.data(Avatar).toByteArray(); |
|
182 |
|
183 HbIcon avatar; |
|
184 if (avatarByteArray.isEmpty()) |
|
185 { |
|
186 avatar = HbIcon(DEFAULT_AVATAR_ICON); |
|
187 } |
|
188 else |
|
189 { |
|
190 QPixmap pixmap; |
|
191 pixmap.loadFromData(avatarByteArray); |
|
192 avatar = HbIcon(QIcon(pixmap)); |
|
193 } |
|
194 setAvatar(avatar); |
|
195 |
|
196 } |
|
197 |
|
198 //--------------------------------------------------------------- |
|
199 // MsgContactCardWidget::clearContent |
|
200 // @see header file |
|
201 //--------------------------------------------------------------- |
|
202 void MsgContactCardWidget::clearContent() |
|
203 { |
|
204 setAddress(""); |
|
205 setAvatar(HbIcon()); |
|
206 } |
517 } |
207 // EOF |
518 // EOF |