messagingapp/msgui/conversationview/src/msgconversationview.cpp
changeset 41 25fe1fe642e3
parent 38 4e4b6adb1024
child 46 b1f0785c289d
equal deleted inserted replaced
40:224522e33db9 41:25fe1fe642e3
    78 #define LOC_VCARD           hbTrId("txt_messaging_list_business_card")
    78 #define LOC_VCARD           hbTrId("txt_messaging_list_business_card")
    79 #define LOC_ADD_RECIPIENTS  hbTrId("txt_messaging_opt_add_recipients")
    79 #define LOC_ADD_RECIPIENTS  hbTrId("txt_messaging_opt_add_recipients")
    80 #define LOC_ADD_SUBJECT     hbTrId("txt_messaging_opt_add_subject")
    80 #define LOC_ADD_SUBJECT     hbTrId("txt_messaging_opt_add_subject")
    81 
    81 
    82 #define LOC_MSG_SEND_FAILED hbTrId("txt_messaging_dialog_message_sending_failed")
    82 #define LOC_MSG_SEND_FAILED hbTrId("txt_messaging_dialog_message_sending_failed")
    83 #define LOC_DIALOG_SMS_SETTINGS_INCOMPLETE hbTrId("txt_messaging_dialog_sms_settings_incomplete")
    83 #define LOC_DIALOG_SMS_SETTINGS_INCOMPLETE hbTrId("txt_messaging_dialog_sms_message_centre_does_not_e")
    84 #define LOC_DIALOG_SAVE_RINGTONE hbTrId("txt_conversations_dialog_save_ringing_tone")
    84 #define LOC_DIALOG_SAVE_RINGTONE hbTrId("txt_conversations_dialog_save_ringing_tone")
       
    85 #define LOC_MMS_RETRIEVAL_FAILED hbTrId("txt_messaging_dialog_mms_retrieval_failed")
    85 
    86 
    86 
    87 
    87 const int INVALID_MSGID = -1;
    88 const int INVALID_MSGID = -1;
    88 const int INVALID_CONVID = -1;
    89 const int INVALID_CONVID = -1;
    89 const int CONTACT_INSERTION_MODE = 1;
    90 const int CONTACT_INSERTION_MODE = 1;
   272 
   273 
   273 //---------------------------------------------------------------
   274 //---------------------------------------------------------------
   274 // MsgConversationView::longPressed
   275 // MsgConversationView::longPressed
   275 // @see header file
   276 // @see header file
   276 //---------------------------------------------------------------
   277 //---------------------------------------------------------------
   277 void MsgConversationView::longPressed(HbAbstractViewItem* viewItem,
   278 void MsgConversationView::longPressed(HbAbstractViewItem* viewItem, const QPointF& point)
   278     const QPointF& point)
   279 { 
   279 {    
   280     showContextMenu(viewItem,point,HbPopup::TopLeftCorner);
   280     MsgConversationViewItem* item = qgraphicsitem_cast<
       
   281             MsgConversationViewItem *> (viewItem);
       
   282 
       
   283     // Show the item-specific menu
       
   284     if (this->isVisible())
       
   285     {
       
   286         //If message is in Sending state or is Scheduled to be sent later,
       
   287         //do not allow any operations on the message
       
   288         int sendingState = item->modelIndex().data(SendingState).toInt();
       
   289         if(sendingState == ConvergedMessage::Scheduled ||
       
   290                    sendingState == ConvergedMessage::Sending ||
       
   291                    sendingState == ConvergedMessage::Waiting)
       
   292            {
       
   293                return;
       
   294            }
       
   295         // Create new menu
       
   296         HbMenu* contextMenu = new HbMenu();
       
   297         contextMenu->setAttribute(Qt::WA_DeleteOnClose);
       
   298         contextMenu->setPreferredPos(point);
       
   299         setContextMenu(item, contextMenu, sendingState);
       
   300         contextMenu->show();
       
   301 
       
   302     }
       
   303     
       
   304 }
   281 }
   305 
   282 
   306 //---------------------------------------------------------------
   283 //---------------------------------------------------------------
   307 // MsgConversationView::setContextMenu
   284 // MsgConversationView::setContextMenu
   308 // @see header
   285 // @see header
   309 //---------------------------------------------------------------
   286 //---------------------------------------------------------------
   310 
       
   311 void MsgConversationView::setContextMenu(MsgConversationViewItem* item, HbMenu* contextMenu, int sendingState)
   287 void MsgConversationView::setContextMenu(MsgConversationViewItem* item, HbMenu* contextMenu, int sendingState)
   312 {
   288 {
   313     addOpenItemToContextMenu(item , contextMenu,sendingState);
   289     addOpenItemToContextMenu(item , contextMenu,sendingState);
   314     addResendItemToContextMenu(item, contextMenu, sendingState);
   290     addResendItemToContextMenu(item, contextMenu, sendingState);
   315     addForwardItemToContextMenu(item, contextMenu, sendingState);
   291     addForwardItemToContextMenu(item, contextMenu, sendingState);
   356         }
   332         }
   357     if ((messageSubType == ConvergedMessage::VCard) &&
   333     if ((messageSubType == ConvergedMessage::VCard) &&
   358         (direction == ConvergedMessage::Incoming))
   334         (direction == ConvergedMessage::Incoming))
   359         {
   335         {
   360         HbAction *contextItem = contextMenu->addAction(LOC_SAVE_TO_CONTACTS);
   336         HbAction *contextItem = contextMenu->addAction(LOC_SAVE_TO_CONTACTS);
   361         connect(contextItem, SIGNAL(triggered()),this, SLOT(openItem()));
   337         connect(contextItem, SIGNAL(triggered()),this, SLOT(saveVCard()));
   362         return;
   338         return;
   363         }
   339         }
   364     if( (sendingState == ConvergedMessage::SentState ) ||
   340     if( (sendingState == ConvergedMessage::SentState &&
       
   341          messageSubType != ConvergedMessage::VCard) ||
   365         (direction == ConvergedMessage::Incoming))
   342         (direction == ConvergedMessage::Incoming))
   366     {
   343     {
   367         HbAction *contextItem = contextMenu->addAction(LOC_COMMON_OPEN);
   344         HbAction *contextItem = contextMenu->addAction(LOC_COMMON_OPEN);
   368         connect(contextItem, SIGNAL(triggered()),this, SLOT(openItem()));
   345         connect(contextItem, SIGNAL(triggered()),this, SLOT(openItem()));
   369     }
   346     }
   377 
   354 
   378 void MsgConversationView::addResendItemToContextMenu(MsgConversationViewItem* item, HbMenu* contextMenu, int sendingState)
   355 void MsgConversationView::addResendItemToContextMenu(MsgConversationViewItem* item, HbMenu* contextMenu, int sendingState)
   379 {
   356 {
   380     Q_UNUSED(item)
   357     Q_UNUSED(item)
   381     int direction = item->modelIndex().data(Direction).toInt();
   358     int direction = item->modelIndex().data(Direction).toInt();
   382     
   359     int messageSubType = item->modelIndex().data(MessageSubType).toInt();
   383     if( (direction == ConvergedMessage::Outgoing)&&
   360     
       
   361     
       
   362     if( ((direction == ConvergedMessage::Outgoing) &&
       
   363         (messageSubType != ConvergedMessage::VCard))&&
   384         ((sendingState == ConvergedMessage::Resend ) ||
   364         ((sendingState == ConvergedMessage::Resend ) ||
   385         (sendingState == ConvergedMessage::Suspended )||
   365         (sendingState == ConvergedMessage::Suspended )||
   386         (sendingState == ConvergedMessage::Failed )))
   366         (sendingState == ConvergedMessage::Failed )))
   387     {
   367     {
   388         HbAction *contextItem = contextMenu->addAction(LOC_COMMON_SEND);
   368         HbAction *contextItem = contextMenu->addAction(LOC_COMMON_SEND);
   720     if(index.isValid())
   700     if(index.isValid())
   721     {
   701     {
   722         qint32 messageId = index.data(ConvergedMsgId).toLongLong();    
   702         qint32 messageId = index.data(ConvergedMsgId).toLongLong();    
   723         if(!(ConversationsEngine::instance()->resendMessage(messageId)))
   703         if(!(ConversationsEngine::instance()->resendMessage(messageId)))
   724         {
   704         {
   725             HbMessageBox::warning(LOC_MSG_SEND_FAILED);
   705             HbMessageBox::warning(LOC_MSG_SEND_FAILED, 0, 0, HbMessageBox::Ok);
   726         }
   706         }
   727     }
   707     }
   728     
   708     
   729 }
   709 }
   730 
   710 
   735 void MsgConversationView::downloadMessage()
   715 void MsgConversationView::downloadMessage()
   736 {
   716 {
   737     QModelIndex index = mConversationList->currentIndex();
   717     QModelIndex index = mConversationList->currentIndex();
   738     if(index.isValid())
   718     if(index.isValid())
   739     {
   719     {
   740         qint32 messageId = index.data(ConvergedMsgId).toLongLong();    
   720         qint32 messageId = index.data(ConvergedMsgId).toLongLong();
   741         if(ConversationsEngine::instance()->downloadMessage(messageId)!=KErrNone)
   721         if(ConversationsEngine::instance()->downloadMessage(messageId)!=KErrNone)
   742         {
   722         {
   743             HbMessageBox::warning("Message Retrieval Failed!"); //TODO: use logical str name
   723             HbMessageBox::warning(LOC_MMS_RETRIEVAL_FAILED, 0, 0, HbMessageBox::Ok);
   744         }
   724         }
   745     }
   725     }
   746     
   726     
   747 }
   727 }
   748 
   728 
   918             }
   898             }
   919             return;
   899             return;
   920         }
   900         }
   921         else if(ConvergedMessage::VCard == messageSubType)
   901         else if(ConvergedMessage::VCard == messageSubType)
   922         {
   902         {
   923             QString filepath = index.data(Attachments).toStringList().at(0);
   903             handleShortTap();
   924             bool result = MsgContactsUtil::launchVCardViewer(filepath);
       
   925             if(result)
       
   926             {
       
   927                 
       
   928                 int messageId = index.data(ConvergedMsgId).toInt();
       
   929                 QList<int> msgIdList;
       
   930                 if(index.data(UnReadStatus).toInt())
       
   931                 {
       
   932                     msgIdList.clear();
       
   933                     msgIdList << messageId;
       
   934                     ConversationsEngine::instance()->markMessagesRead(msgIdList);
       
   935                 }
       
   936             }
       
   937             return;
   904             return;
   938         }
   905         }
   939         else if(ConvergedMessage::VCal == messageSubType)
   906         else if(ConvergedMessage::VCal == messageSubType)
   940         {
   907         {
   941             return;
   908             return;
   953             }
   920             }
   954         return;
   921         return;
   955     }
   922     }
   956     else if(ConvergedMessage::MmsNotification == messageType)
   923     else if(ConvergedMessage::MmsNotification == messageType)
   957     {
   924     {
   958         qint32 messageId = index.data(ConvergedMsgId).toLongLong();    
   925         qint32 messageId = index.data(ConvergedMsgId).toLongLong();
   959         if(!ConversationsEngine::instance()->downloadOperationSupported(messageId))           
   926         if(!ConversationsEngine::instance()->downloadOperationSupported(messageId))           
   960         {
   927         {
   961            int notificationState = index.data(NotificationStatus).toInt();
   928            int notificationState = index.data(NotificationStatus).toInt();
   962            if( notificationState == ConvergedMessage::NotifExpired)
   929            if( notificationState == ConvergedMessage::NotifExpired)
   963            {
   930            {
  1344 {
  1311 {
  1345     HbMessageBox *dlg = qobject_cast<HbMessageBox*> (sender());
  1312     HbMessageBox *dlg = qobject_cast<HbMessageBox*> (sender());
  1346     if (action == dlg->actions().at(0)) {
  1313     if (action == dlg->actions().at(0)) {
  1347         downloadMessage();
  1314         downloadMessage();
  1348     }
  1315     }
       
  1316     
       
  1317     //if message unread, mark as read now
       
  1318     QModelIndex index = mConversationList->currentIndex();
       
  1319     qint32 messageId = index.data(ConvergedMsgId).toLongLong();
       
  1320     QList<int> msgIdList;
       
  1321     if(index.data(UnReadStatus).toInt())
       
  1322     {
       
  1323         msgIdList.clear();
       
  1324         msgIdList << messageId;
       
  1325         ConversationsEngine::instance()->markMessagesRead(msgIdList);
       
  1326     }
  1349 }
  1327 }
  1350 
  1328 
  1351 //---------------------------------------------------------------
  1329 //---------------------------------------------------------------
  1352 // MsgConversationView::onDialogSaveTone
  1330 // MsgConversationView::onDialogSaveTone
  1353 // @see header file
  1331 // @see header file
  1400     disconnect(mainWindow(), SIGNAL(aboutToChangeOrientation()), mConversationList, 0);
  1378     disconnect(mainWindow(), SIGNAL(aboutToChangeOrientation()), mConversationList, 0);
  1401     disconnect(mainWindow(), SIGNAL(orientationChanged(Qt: rientation)), mConversationList, 0);
  1379     disconnect(mainWindow(), SIGNAL(orientationChanged(Qt: rientation)), mConversationList, 0);
  1402     
  1380     
  1403    fetchMoreConversations();
  1381    fetchMoreConversations();
  1404 }
  1382 }
       
  1383 
       
  1384 //---------------------------------------------------------------
       
  1385 // MsgConversationView::handleShortTap
       
  1386 // @see header file
       
  1387 //---------------------------------------------------------------
       
  1388 void MsgConversationView::handleShortTap()
       
  1389 {
       
  1390     HbAbstractViewItem* item = mConversationList->currentViewItem();
       
  1391     QRectF rc = item->rect();
       
  1392     QPointF p = item->mapToScene(rc.center());
       
  1393     
       
  1394     showContextMenu(item,p,HbPopup::TopEdgeCenter);
       
  1395 }
       
  1396 
       
  1397 //---------------------------------------------------------------
       
  1398 // MsgConversationView::handleShortTap
       
  1399 // @see header file
       
  1400 //---------------------------------------------------------------
       
  1401 void MsgConversationView::showContextMenu(HbAbstractViewItem* viewItem,const QPointF& point, int placement)
       
  1402 {    
       
  1403     MsgConversationViewItem* item = qgraphicsitem_cast<MsgConversationViewItem *>(viewItem);
       
  1404 
       
  1405     // Show the item-specific menu
       
  1406     if (this->isVisible())
       
  1407     {
       
  1408         //If message is in Sending state or is Scheduled to be sent later,
       
  1409         //do not allow any operations on the message
       
  1410         int sendingState = item->modelIndex().data(SendingState).toInt();
       
  1411         
       
  1412         if(sendingState == ConvergedMessage::Scheduled ||
       
  1413             sendingState == ConvergedMessage::Sending ||
       
  1414             sendingState == ConvergedMessage::Waiting)
       
  1415             {
       
  1416                 return;
       
  1417             }
       
  1418         // Create new menu
       
  1419         HbMenu* contextMenu = new HbMenu();
       
  1420         contextMenu->setAttribute(Qt::WA_DeleteOnClose);
       
  1421         contextMenu->setPreferredPos(point,HbPopup::Placement(placement));
       
  1422         setContextMenu(item, contextMenu, sendingState);
       
  1423         contextMenu->show();
       
  1424     }
       
  1425 }
       
  1426 
       
  1427 //---------------------------------------------------------------
       
  1428 // MsgConversationView::saveVCard
       
  1429 // @see header file
       
  1430 //---------------------------------------------------------------
       
  1431 void MsgConversationView::saveVCard()
       
  1432 {
       
  1433     QModelIndex index = mConversationList->currentIndex();
       
  1434     
       
  1435     QString filepath = index.data(Attachments).toStringList().at(0);
       
  1436     bool result = MsgContactsUtil::launchVCardViewer(filepath);
       
  1437     if(result)
       
  1438     {
       
  1439         int messageId = index.data(ConvergedMsgId).toInt();
       
  1440         QList<int> msgIdList;
       
  1441         if(index.data(UnReadStatus).toInt())
       
  1442         {
       
  1443             msgIdList.clear();
       
  1444             msgIdList << messageId;
       
  1445             ConversationsEngine::instance()->markMessagesRead(msgIdList);
       
  1446         }
       
  1447     } 
       
  1448 }
  1405 // EOF
  1449 // EOF