messagingapp/msgui/conversationview/src/msgconversationview.cpp
changeset 44 36f374c67aa8
parent 43 35b64624a9e7
child 47 5b14749788d7
child 52 12db4185673b
equal deleted inserted replaced
43:35b64624a9e7 44:36f374c67aa8
    65 #define LOC_COMMON_DELETE hbTrId("txt_common_menu_delete")
    65 #define LOC_COMMON_DELETE hbTrId("txt_common_menu_delete")
    66 #define LOC_COMMON_FORWARD hbTrId("txt_common_menu_forward")
    66 #define LOC_COMMON_FORWARD hbTrId("txt_common_menu_forward")
    67 #define LOC_COMMON_DOWNLOAD hbTrId("txt_messaging_menu_download")
    67 #define LOC_COMMON_DOWNLOAD hbTrId("txt_messaging_menu_download")
    68 #define LOC_COMMON_SEND  hbTrId("txt_common_button_send") 
    68 #define LOC_COMMON_SEND  hbTrId("txt_common_button_send") 
    69 #define LOC_COMMON_SAVE  hbTrId("txt_common_menu_save")
    69 #define LOC_COMMON_SAVE  hbTrId("txt_common_menu_save")
    70 #define LOC_BUTTON_DELETE hbTrId("txt_common_button_delete")
       
    71 #define LOC_BUTTON_CANCEL hbTrId("txt_common_button_cancel")
       
    72 #define LOC_BUTTON_OK hbTrId("txt_common_button_ok")
       
    73 
    70 
    74 #define LOC_DELETE_MESSAGE hbTrId("txt_messaging_dialog_delete_message")
    71 #define LOC_DELETE_MESSAGE hbTrId("txt_messaging_dialog_delete_message")
    75 #define LOC_SAVE_TO_CONTACTS hbTrId("txt_messaging_menu_save_to_contacts")
    72 #define LOC_SAVE_TO_CONTACTS hbTrId("txt_messaging_menu_save_to_contacts")
    76 
    73 
    77 //main menu
    74 //main menu
    83 #define LOC_ADD_SUBJECT     hbTrId("txt_messaging_opt_add_subject")
    80 #define LOC_ADD_SUBJECT     hbTrId("txt_messaging_opt_add_subject")
    84 
    81 
    85 #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")
    86 #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_settings_incomplete")
    87 #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")
    88 #define LOC_CONTACT_SAVED hbTrId("txt_messaging_dpopinfo_contact_saved")
    85 
    89 
    86 
    90 const int INVALID_MSGID = -1;
    87 const int INVALID_MSGID = -1;
    91 const int INVALID_CONVID = -1;
    88 const int INVALID_CONVID = -1;
    92 const int CONTACT_INSERTION_MODE = 1;
    89 const int CONTACT_INSERTION_MODE = 1;
    93 const int VCARD_INSERTION_MODE = 0;
    90 const int VCARD_INSERTION_MODE = 0;
   103     mMessageModel(NULL),
   100     mMessageModel(NULL),
   104     mEditorWidget(NULL),
   101     mEditorWidget(NULL),
   105     mContactCardWidget(contactCardWidget),
   102     mContactCardWidget(contactCardWidget),
   106     mSendUtil(NULL),
   103     mSendUtil(NULL),
   107     mVkbHost(NULL),
   104     mVkbHost(NULL),
       
   105     mVisibleIndex(),
   108     mVkbopened(false),
   106     mVkbopened(false),
   109     mVisibleIndex()
   107     mModelPopulated(false),
   110 {
   108     mViewReady(false)
   111     connect(this->mainWindow(),SIGNAL(viewReady()),this,SLOT(onViewReady()));
   109 {
   112     //create send utils
   110     //create send utils
   113     mSendUtil = new MsgSendUtil(this);
   111     mSendUtil = new MsgSendUtil(this);
   114     //initialize view
   112     //initialize view
   115     setupView();
   113     setupView();
   116     setupMenu();
   114     setupMenu();
       
   115     
       
   116     connect(ConversationsEngine::instance(), 
       
   117                      SIGNAL(conversationModelUpdated()),
       
   118                      this, 
       
   119                      SLOT(scrollToBottom()));
       
   120 
       
   121     connect(ConversationsEngine::instance(), 
       
   122                          SIGNAL(conversationViewEmpty()),
       
   123                          this, 
       
   124                          SLOT(onConversationViewEmpty()));
   117 }
   125 }
   118 
   126 
   119 //---------------------------------------------------------------
   127 //---------------------------------------------------------------
   120 // MsgConversationView::~MsgConversationView
   128 // MsgConversationView::~MsgConversationView
   121 // @see header file
   129 // @see header file
   207     HbAction* clearConversation = mainMenu->addAction(QString());
   215     HbAction* clearConversation = mainMenu->addAction(QString());
   208     connect(mainMenu, SIGNAL(aboutToShow()), this, SLOT(menuAboutToShow()));
   216     connect(mainMenu, SIGNAL(aboutToShow()), this, SLOT(menuAboutToShow()));
   209 }
   217 }
   210 
   218 
   211 //---------------------------------------------------------------
   219 //---------------------------------------------------------------
       
   220 // MsgConversationView::fetchMoreConversations
       
   221 // @see header file
       
   222 //---------------------------------------------------------------
       
   223 void MsgConversationView::fetchMoreConversations()
       
   224 {
       
   225     if (mViewReady && mModelPopulated) {
       
   226         ConversationsEngine::instance()->fetchMoreConversations();
       
   227         mViewReady = mModelPopulated = false;
       
   228     }
       
   229 }
       
   230 
       
   231 //---------------------------------------------------------------
   212 // MsgConversationView::refreshView()
   232 // MsgConversationView::refreshView()
   213 // @see header file
   233 // @see header file
   214 //---------------------------------------------------------------
   234 //---------------------------------------------------------------
   215 void MsgConversationView::refreshView()
   235 void MsgConversationView::refreshView()
   216 {
   236 {
   238 void MsgConversationView::scrollToBottom()
   258 void MsgConversationView::scrollToBottom()
   239 {
   259 {
   240     const int rowCnt = mMessageModel->rowCount();
   260     const int rowCnt = mMessageModel->rowCount();
   241     mConversationList->scrollTo(
   261     mConversationList->scrollTo(
   242             mMessageModel->index(rowCnt - 1, 0));
   262             mMessageModel->index(rowCnt - 1, 0));
       
   263 }
       
   264 
       
   265 void MsgConversationView::onConversationViewEmpty()
       
   266 {
       
   267     QVariantList param;
       
   268     param << MsgBaseView::CLV; // target view
       
   269     param << MsgBaseView::CV; // source view
       
   270     emit switchView(param);
   243 }
   271 }
   244 
   272 
   245 //---------------------------------------------------------------
   273 //---------------------------------------------------------------
   246 // MsgConversationView::longPressed
   274 // MsgConversationView::longPressed
   247 // @see header file
   275 // @see header file
   332         HbAction *contextItem = contextMenu->addAction(LOC_SAVE_TO_CONTACTS);
   360         HbAction *contextItem = contextMenu->addAction(LOC_SAVE_TO_CONTACTS);
   333         connect(contextItem, SIGNAL(triggered()),this, SLOT(openItem()));
   361         connect(contextItem, SIGNAL(triggered()),this, SLOT(openItem()));
   334         return;
   362         return;
   335         }
   363         }
   336     if( (sendingState == ConvergedMessage::SentState ) ||
   364     if( (sendingState == ConvergedMessage::SentState ) ||
   337         (sendingState == ConvergedMessage::Resend ) ||
       
   338         (sendingState == ConvergedMessage::Failed ) ||
       
   339         (direction == ConvergedMessage::Incoming))
   365         (direction == ConvergedMessage::Incoming))
   340     {
   366     {
   341         HbAction *contextItem = contextMenu->addAction(LOC_COMMON_OPEN);
   367         HbAction *contextItem = contextMenu->addAction(LOC_COMMON_OPEN);
   342         connect(contextItem, SIGNAL(triggered()),this, SLOT(openItem()));
   368         connect(contextItem, SIGNAL(triggered()),this, SLOT(openItem()));
   343     }
   369     }
   476         }
   502         }
   477     }
   503     }
   478     deactivateInputBlocker();
   504     deactivateInputBlocker();
   479     if( sendResult == KErrNotFound)
   505     if( sendResult == KErrNotFound)
   480     {
   506     {
   481     HbMessageBox::question(LOC_DIALOG_SMS_SETTINGS_INCOMPLETE, this, SLOT(onDialogSettingsLaunch(HbAction*)), LOC_BUTTON_OK, LOC_BUTTON_CANCEL);
   507     HbMessageBox::question(LOC_DIALOG_SMS_SETTINGS_INCOMPLETE, this,
       
   508                            SLOT(onDialogSettingsLaunch(HbAction*)), 
       
   509                            HbMessageBox::Ok | HbMessageBox::Cancel);
   482     }
   510     }
   483 }
   511 }
   484 
   512 
   485 //---------------------------------------------------------------
   513 //---------------------------------------------------------------
   486 // MsgConversationView::contactsFetchedForVCards
   514 // MsgConversationView::contactsFetchedForVCards
   584 //---------------------------------------------------------------
   612 //---------------------------------------------------------------
   585 void MsgConversationView::fetchAudio()
   613 void MsgConversationView::fetchAudio()
   586 {
   614 {
   587     // Launch Audio fetcher view
   615     // Launch Audio fetcher view
   588     QVariantList params;
   616     QVariantList params;
       
   617     QByteArray dataArray;
       
   618     QDataStream messageStream
       
   619     (&dataArray, QIODevice::WriteOnly | QIODevice::Append);
       
   620 
       
   621     ConvergedMessage message;
       
   622     message.setBodyText(mEditorWidget->content());
       
   623     // add address from contact-card to to-field
       
   624     ConvergedMessageAddress address;
       
   625     address.setAlias(mContactCardWidget->address().at(0)->alias());
       
   626     address.setAddress(mContactCardWidget->address().at(0)->address());
       
   627     message.addToRecipient(address);
       
   628     message.serialize(messageStream);
       
   629 
   589     params << MsgBaseView::AUDIOFETCHER; // target view
   630     params << MsgBaseView::AUDIOFETCHER; // target view
   590     params << MsgBaseView::CV; // source view
   631     params << MsgBaseView::CV; // source view
       
   632     params << dataArray;
   591     emit switchView(params);
   633     emit switchView(params);
   592 }
   634 }
   593 
   635 
   594 //---------------------------------------------------------------
   636 //---------------------------------------------------------------
   595 // MsgConversationView::contactsFetched
   637 // MsgConversationView::contactsFetched
   709 // Deletes the message
   751 // Deletes the message
   710 //---------------------------------------------------------------
   752 //---------------------------------------------------------------
   711 void MsgConversationView::deleteItem()
   753 void MsgConversationView::deleteItem()
   712     {
   754     {
   713     HbMessageBox::question(LOC_DELETE_MESSAGE,this,SLOT(onDialogdeleteMsg(HbAction*)),
   755     HbMessageBox::question(LOC_DELETE_MESSAGE,this,SLOT(onDialogdeleteMsg(HbAction*)),
   714                              LOC_BUTTON_DELETE,
   756                            HbMessageBox::Delete | HbMessageBox::Cancel);
   715                              LOC_BUTTON_CANCEL);
       
   716 }
   757 }
   717 
   758 
   718 //---------------------------------------------------------------
   759 //---------------------------------------------------------------
   719 // MsgConversationView::openItem()
   760 // MsgConversationView::openItem()
   720 // Opens the message
   761 // Opens the message
   786 void MsgConversationView::launchBtDisplayService(const QModelIndex & index)
   827 void MsgConversationView::launchBtDisplayService(const QModelIndex & index)
   787 {
   828 {
   788     qint32 messageId = index.data(ConvergedMsgId).toLongLong();
   829     qint32 messageId = index.data(ConvergedMsgId).toLongLong();
   789 
   830 
   790     QList<QVariant> args;
   831     QList<QVariant> args;
   791     QString serviceName("com.nokia.services.btmsgdispservices.displaymsg");
   832     QString serviceName("com.nokia.services.btmsgdispservices");
   792     QString operation("displaymsg(int)");
   833     QString operation("displaymsg(int)");
   793     XQAiwRequest* request;
   834     XQAiwRequest* request;
   794     XQApplicationManager appManager;
   835     XQApplicationManager appManager;
   795     request = appManager.create(serviceName, "displaymsg", operation, true); // embedded
   836     request = appManager.create(serviceName, "displaymsg", operation, false); // embedded
   796     
   837     
   797     if ( request == NULL )
   838     if ( request == NULL )
   798         {
   839         {
   799         return;
   840         return;
   800         }
   841         }
   801 
   842 
   802     args << QVariant(messageId);
   843     args << QVariant(messageId);
       
   844     request->setSynchronous(true);
   803     
   845     
   804     request->setArguments(args);
   846     request->setArguments(args);
   805     request->send();
   847     request->send();
   806     delete request;    
   848     delete request;    
   807 }
   849 }
   857     if (ConvergedMessage::BioMsg == messageType)
   899     if (ConvergedMessage::BioMsg == messageType)
   858     {
   900     {
   859         if (ConvergedMessage::RingingTone == messageSubType)
   901         if (ConvergedMessage::RingingTone == messageSubType)
   860         {
   902         {
   861             HbMessageBox::question(LOC_DIALOG_SAVE_RINGTONE, this,
   903             HbMessageBox::question(LOC_DIALOG_SAVE_RINGTONE, this,
   862                     SLOT(onDialogSaveTone(HbAction*)), LOC_COMMON_SAVE, LOC_BUTTON_CANCEL);
   904                                    SLOT(onDialogSaveTone(HbAction*)), 
       
   905                                    HbMessageBox::Save | HbMessageBox::Cancel);
   863             return;
   906             return;
   864         }
   907         }
   865         else if(ConvergedMessage::Provisioning == messageSubType)
   908         else if(ConvergedMessage::Provisioning == messageSubType)
   866         {
   909         {
   867             int messageId = index.data(ConvergedMsgId).toInt();
   910             int messageId = index.data(ConvergedMsgId).toInt();
   879         {
   922         {
   880             QString filepath = index.data(Attachments).toStringList().at(0);
   923             QString filepath = index.data(Attachments).toStringList().at(0);
   881             bool result = MsgContactsUtil::launchVCardViewer(filepath);
   924             bool result = MsgContactsUtil::launchVCardViewer(filepath);
   882             if(result)
   925             if(result)
   883             {
   926             {
   884                 HbNotificationDialog::launchDialog(LOC_CONTACT_SAVED);
   927                 
   885                 int messageId = index.data(ConvergedMsgId).toInt();
   928                 int messageId = index.data(ConvergedMsgId).toInt();
   886                 QList<int> msgIdList;
   929                 QList<int> msgIdList;
   887                 if(index.data(UnReadStatus).toInt())
   930                 if(index.data(UnReadStatus).toInt())
   888                 {
   931                 {
   889                     msgIdList.clear();
   932                     msgIdList.clear();
   899         }
   942         }
   900     }
   943     }
   901     else if (ConvergedMessage::BT == messageType)
   944     else if (ConvergedMessage::BT == messageType)
   902     {
   945     {
   903         launchBtDisplayService(index);
   946         launchBtDisplayService(index);
       
   947         QList<int> msgIdList;
       
   948         if(index.data(UnReadStatus).toInt())
       
   949             {
       
   950             msgIdList.clear();
       
   951             msgIdList << messageId;
       
   952             ConversationsEngine::instance()->markMessagesRead(msgIdList);
       
   953             }
   904         return;
   954         return;
   905     }
   955     }
   906     else if(ConvergedMessage::MmsNotification == messageType)
   956     else if(ConvergedMessage::MmsNotification == messageType)
   907     {
   957     {
   908         qint32 messageId = index.data(ConvergedMsgId).toLongLong();    
   958         qint32 messageId = index.data(ConvergedMsgId).toLongLong();    
   916            return;
   966            return;
   917         }
   967         }
   918         else
   968         else
   919         {
   969         {
   920             //TODO: use logical str name
   970             //TODO: use logical str name
   921             HbMessageBox::question("Download Message?",this,SLOT(onDialogDownLoadMsg(HbAction*)),
   971             HbMessageBox::question("Download Message?",this,
   922                 LOC_COMMON_DOWNLOAD,
   972                                    SLOT(onDialogDownLoadMsg(HbAction*)),
   923                 LOC_BUTTON_CANCEL);
   973                                    HbMessageBox::Yes | HbMessageBox::Cancel);
   924             return;
   974             return;
   925         }
   975         }
   926     }
   976     }
   927 
   977 
   928     int direction = index.data(Direction).toInt();
   978     int direction = index.data(Direction).toInt();
   935     
   985     
   936     // check whether message is in sending progress, then donot launch viewer.
   986     // check whether message is in sending progress, then donot launch viewer.
   937     int location = index.data(MessageLocation).toInt();
   987     int location = index.data(MessageLocation).toInt();
   938     int sendingState = index.data(SendingState).toInt();
   988     int sendingState = index.data(SendingState).toInt();
   939     
   989     
   940     //If message is in Sending state or is Scheduled to be sent later,
   990     //If message is in any other state other than 'Sent'
   941     //do not open the message
   991     //do not open the message
   942     if(sendingState == ConvergedMessage::Suspended ||
   992     if(direction == ConvergedMessage::Outgoing 
   943             sendingState == ConvergedMessage::Scheduled ||
   993             && sendingState != ConvergedMessage::SentState )
   944             sendingState == ConvergedMessage::Sending ||
   994            
   945             sendingState == ConvergedMessage::Waiting)
       
   946     {
   995     {
   947         return;
   996         return;
   948     }
   997     }
   949 
   998 
   950     //TODO: sendingState check should be removed once msg
       
   951     // movement lock issue is resolved from mw
       
   952     if( !((location == ConvergedMessage::Inbox) ||
       
   953         (location == ConvergedMessage::Sent) ||
       
   954         (sendingState == ConvergedMessage::SentState)||
       
   955         (sendingState == ConvergedMessage::Failed) ||
       
   956         (sendingState == ConvergedMessage::Resend)))
       
   957     {// do not launch viewer, show a note
       
   958         HbNotificationDialog* dlg = new HbNotificationDialog();
       
   959         dlg->setFocusPolicy(Qt::NoFocus);
       
   960         QString text(tr("Message Locked"));
       
   961         dlg->setText(text);
       
   962         dlg->setDismissPolicy(HbPopup::TapAnywhere);
       
   963         dlg->setAttribute(Qt::WA_DeleteOnClose, true);
       
   964         dlg->show();
       
   965         return;
       
   966 	}
       
   967    
   999    
   968     
  1000     
   969     // contact Id
  1001     // contact Id
   970     qint32 contactId = index.data(ContactId).toLongLong();  
  1002     qint32 contactId = index.data(ContactId).toLongLong();  
   971 	    
  1003 	    
  1061             // now add fetched contacts from contact selection dialog
  1093             // now add fetched contacts from contact selection dialog
  1062             for(int i = 0; i < contactList.count(); i++ )
  1094             for(int i = 0; i < contactList.count(); i++ )
  1063             {
  1095             {
  1064                 ConvergedMessageAddress* address = new ConvergedMessageAddress;
  1096                 ConvergedMessageAddress* address = new ConvergedMessageAddress;
  1065                 address->setAlias(contactList[i].mDisplayName);
  1097                 address->setAlias(contactList[i].mDisplayName);
  1066                 address->setAddress(contactList[i].mPhoneNumber);
  1098                 if(!contactList[i].mPhoneNumber.isEmpty())
       
  1099                 {
       
  1100                     address->setAddress(contactList[i].mPhoneNumber);
       
  1101                 }
       
  1102                 else
       
  1103                 {
       
  1104                     address->setAddress(contactList[i].mEmailAddress);
       
  1105                 }
  1067                 addresses.append(address);
  1106                 addresses.append(address);
  1068             }
  1107             }
  1069             message.addToRecipients(addresses);
  1108             message.addToRecipients(addresses);
  1070         }
  1109         }
  1071     }
  1110     }
  1093 //---------------------------------------------------------------
  1132 //---------------------------------------------------------------
  1094 // MsgConversationView::populateConversationsView
  1133 // MsgConversationView::populateConversationsView
  1095 // @see header file
  1134 // @see header file
  1096 //---------------------------------------------------------------
  1135 //---------------------------------------------------------------
  1097 void MsgConversationView::populateConversationsView()
  1136 void MsgConversationView::populateConversationsView()
  1098 {
  1137 {    
  1099     bool b = connect(ConversationsEngine::instance(), 
  1138     mModelPopulated = true;
  1100                      SIGNAL(conversationModelUpdated()),
       
  1101                      this, 
       
  1102                      SLOT(scrollToBottom()));
       
  1103 
       
  1104     mConversationList->setModel(mMessageModel);
  1139     mConversationList->setModel(mMessageModel);
  1105     
  1140     
  1106     refreshView();
  1141     refreshView();
  1107     scrollToBottom();
  1142     scrollToBottom();
       
  1143     fetchMoreConversations();
  1108 }
  1144 }
  1109 
  1145 
  1110 //---------------------------------------------------------------
  1146 //---------------------------------------------------------------
  1111 // MsgConversationView::saveRingingTone
  1147 // MsgConversationView::saveRingingTone
  1112 // @see header file
  1148 // @see header file
  1357 // MsgConversationView::onViewReady
  1393 // MsgConversationView::onViewReady
  1358 // @see header file
  1394 // @see header file
  1359 //---------------------------------------------------------------
  1395 //---------------------------------------------------------------
  1360 void MsgConversationView::onViewReady()
  1396 void MsgConversationView::onViewReady()
  1361 {
  1397 {
       
  1398     mViewReady = true;
  1362     //Disconnect list View's signals, for avoiding execution of the default implementaion
  1399     //Disconnect list View's signals, for avoiding execution of the default implementaion
  1363     disconnect(mainWindow(), SIGNAL(aboutToChangeOrientation()), mConversationList, 0);
  1400     disconnect(mainWindow(), SIGNAL(aboutToChangeOrientation()), mConversationList, 0);
  1364     disconnect(mainWindow(), SIGNAL(orientationChanged(Qt: rientation)), mConversationList, 0);
  1401     disconnect(mainWindow(), SIGNAL(orientationChanged(Qt: rientation)), mConversationList, 0);
       
  1402     
       
  1403    fetchMoreConversations();
  1365 }
  1404 }
  1366 // EOF
  1405 // EOF