messagingapp/msgui/msgapp/src/msgviewmanager.cpp
changeset 31 ebfee66fde93
child 34 84197e66a4bd
equal deleted inserted replaced
30:6a20128ce557 31:ebfee66fde93
       
     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  * class to manage differnt messaging views.
       
    16  *
       
    17  */
       
    18 
       
    19 #include "msgviewmanager.h"
       
    20 
       
    21 #include <HbMainWindow>
       
    22 #include <HbAction>
       
    23 #include <xqserviceutil.h>
       
    24 #include <QSqlQuery>
       
    25 #include <QSqlError>
       
    26 #include <HbApplication>
       
    27 #include <xqappmgr.h>
       
    28 #include <HbMessageBox.h>
       
    29 #include <HbView>
       
    30 
       
    31 #include "conversationsengine.h"
       
    32 #include "msglistview.h"
       
    33 #include "msgunieditorview.h"
       
    34 #include "msgconversationbaseview.h"
       
    35 #include "unifiedviewer.h"
       
    36 #include "draftslistview.h"
       
    37 #include "msgsettingsview.h"
       
    38 #include "convergedmessageid.h"
       
    39 #include "ringbc.h"
       
    40 #include "unidatamodelloader.h"
       
    41 #include "unidatamodelplugininterface.h"
       
    42 
       
    43 // LOCALIZATION
       
    44 #define LOC_BUTTON_DELETE hbTrId("txt_common_button_delete")
       
    45 #define LOC_BUTTON_CANCEL hbTrId("txt_common_button_cancel")
       
    46 #define LOC_DELETE_MESSAGE hbTrId("txt_messaging_dialog_delete_message")
       
    47 #define LOC_DIALOG_SAVE_RINGTONE hbTrId("txt_conversations_dialog_save_ringing_tone")
       
    48 #define LOC_COMMON_SAVE  hbTrId("txt_common_menu_save")
       
    49 
       
    50 const qint64 NULL_CONVERSATIONID = -1;
       
    51 
       
    52 MsgViewManager::MsgViewManager(bool serviceRequest, HbMainWindow* mainWindow, QObject* parent) :
       
    53     QObject(parent), mMainWindow(mainWindow), mUniEditor(0), mListView(0), mConversationView(0),
       
    54         mUniViewer(0), mDraftsListView(0), mSettingsView(0), mBackAction(0), mServiceRequest(
       
    55             serviceRequest), mConversationId(-1), mViewServiceRequest(false),mMessageId(-1)
       
    56 {
       
    57     //creating back action.
       
    58     mBackAction = new HbAction(Hb::BackNaviAction, this);
       
    59     connect(mBackAction, SIGNAL(triggered()), this, SLOT(onBackAction()));
       
    60 
       
    61     //create clv as first view if not a service request.
       
    62     if (!mServiceRequest) {
       
    63         QVariantList param;
       
    64         param << MsgBaseView::CLV;
       
    65         param << MsgBaseView::CLV;
       
    66         switchView(param);
       
    67     }
       
    68     else
       
    69     {
       
    70         mDummyview = new HbView();
       
    71         mMainWindow->addView(mDummyview);
       
    72         mMainWindow->setCurrentView(mDummyview);
       
    73         mViewTobeDeleted << mDummyview;
       
    74     }
       
    75 }
       
    76 
       
    77 MsgViewManager::~MsgViewManager()
       
    78 {
       
    79     // TODO Auto-generated destructor stub
       
    80 }
       
    81 
       
    82 void MsgViewManager::onBackAction()
       
    83 {
       
    84     switch (mCurrentView) {
       
    85     case MsgBaseView::CLV:
       
    86     {
       
    87         // if its viewer service then quit the application
       
    88         if (mViewServiceRequest) {
       
    89             HbApplication::quit();
       
    90             break;
       
    91         }
       
    92 
       
    93         if (!mServiceRequest) {
       
    94             HbApplication::quit();
       
    95         }
       
    96         else {
       
    97             completeServiceRequest();
       
    98         }
       
    99 
       
   100         break;
       
   101     }
       
   102 
       
   103     case MsgBaseView::CV:
       
   104     {
       
   105         //Save content to drafts before switching to clv
       
   106         mConversationView->saveContentToDrafts();
       
   107 
       
   108         //marking messages as red in CV.
       
   109         mConversationView->markMessagesAsRead();
       
   110 
       
   111         // reset the conversation id published
       
   112         mConversationView->setPSCVId(false);
       
   113         
       
   114         //clearing content of cv.
       
   115         mConversationView->clearContent();
       
   116 
       
   117         // if service request for veiwer the just switch to univiewer.
       
   118         if (mViewServiceRequest) {
       
   119             mCurrentView = MsgBaseView::UNIVIEWER;
       
   120             mMainWindow->setCurrentView(mUniViewer);
       
   121             break;
       
   122         }
       
   123 
       
   124         if (mServiceRequest) {
       
   125             completeServiceRequest();
       
   126         }
       
   127         else {
       
   128             //switch to clv.
       
   129             QVariantList param;
       
   130             param << MsgBaseView::CLV;
       
   131             param << MsgBaseView::CV;
       
   132             switchView(param);
       
   133         }
       
   134 
       
   135         break;
       
   136     }
       
   137 
       
   138     case MsgBaseView::DLV:
       
   139     {
       
   140         if (mServiceRequest) {
       
   141             completeServiceRequest();
       
   142         }
       
   143         else {
       
   144             //switch to clv.
       
   145             QVariantList param;
       
   146             param << MsgBaseView::CLV;
       
   147             param << MsgBaseView::DLV;
       
   148             switchView(param);
       
   149         }
       
   150 
       
   151         break;
       
   152     }
       
   153 
       
   154     case MsgBaseView::UNIEDITOR:
       
   155     {
       
   156         //Save content to drafts before switching to clv
       
   157         mUniEditor->saveContentToDrafts();
       
   158 
       
   159         // if service request for veiwer the just switch to univiewer.
       
   160         if (mViewServiceRequest) {
       
   161             mCurrentView = MsgBaseView::UNIVIEWER;
       
   162             mMainWindow->setCurrentView(mUniViewer);
       
   163             break;
       
   164         }
       
   165 
       
   166         //switch to clv.
       
   167         if (mServiceRequest) {
       
   168             completeServiceRequest();
       
   169         }
       
   170         else {
       
   171             //switch to clv.
       
   172             QVariantList param;
       
   173             param << MsgBaseView::CLV;
       
   174             param << MsgBaseView::UNIEDITOR;
       
   175             switchView(param);
       
   176         }
       
   177 
       
   178         break;
       
   179     }
       
   180 
       
   181     case MsgBaseView::UNIVIEWER:
       
   182     {
       
   183         // if its launched via service request quit the app
       
   184         if (mViewServiceRequest) {
       
   185             HbApplication::quit();
       
   186         }
       
   187         else {
       
   188             QVariantList param;
       
   189             param << MsgBaseView::CV;
       
   190             param << MsgBaseView::UNIVIEWER;
       
   191             param << mConversationId;
       
   192             switchView(param);
       
   193 
       
   194         }
       
   195         break;
       
   196     }
       
   197     case MsgBaseView::MSGSETTINGS:
       
   198     {
       
   199         QVariantList param;
       
   200         param << MsgBaseView::DEFAULT;
       
   201         param << MsgBaseView::MSGSETTINGS;
       
   202         switchView(param);
       
   203         break;
       
   204     }
       
   205     default:
       
   206     {
       
   207         break;
       
   208     }
       
   209     }
       
   210 }
       
   211 
       
   212 void MsgViewManager::switchView(const QVariantList& data)
       
   213 {
       
   214    
       
   215     connect(mMainWindow, SIGNAL(viewReady()),this,SLOT(setViewInteractive()));
       
   216     mMainWindow->setInteractive(false);
       
   217     
       
   218     int viewId = data.at(0).toInt();
       
   219     
       
   220     switch (viewId) {
       
   221     case MsgBaseView::DEFAULT:
       
   222     {
       
   223         handleDefault(data);
       
   224         break;
       
   225     }
       
   226     case MsgBaseView::CLV:
       
   227     {
       
   228             switchToClv(data);
       
   229             break;
       
   230         }
       
   231 
       
   232         case MsgBaseView::CV:
       
   233         {
       
   234 
       
   235             switchToCv(data);
       
   236             break;
       
   237         }
       
   238 
       
   239     case MsgBaseView::DLV:
       
   240     {
       
   241         switchToDlv(data);
       
   242         break;
       
   243     }
       
   244 
       
   245     case MsgBaseView::UNIEDITOR:
       
   246     {
       
   247         switchToUniEditor(data);
       
   248         break;
       
   249     }
       
   250 
       
   251     case MsgBaseView::UNIVIEWER:
       
   252     {
       
   253         switchToUniViewer(data);
       
   254         break;
       
   255     }
       
   256 
       
   257     case MsgBaseView::MSGSETTINGS:
       
   258     {
       
   259         switchToMsgSettings(data);
       
   260         break;
       
   261     }
       
   262     }
       
   263 }
       
   264 
       
   265 void MsgViewManager::deletePreviousView()
       
   266 {
       
   267     while(mViewTobeDeleted.count())
       
   268     {
       
   269         HbView* v = mViewTobeDeleted.takeAt(0);
       
   270         mMainWindow->removeView(v);
       
   271         delete v;
       
   272     }
       
   273     disconnect(mMainWindow, SIGNAL(viewReady()), this, SLOT(deletePreviousView()));
       
   274 }
       
   275 
       
   276 
       
   277 void MsgViewManager::send(const qint32 contactId, const QString phoneNumber,
       
   278     const QString displayName)
       
   279 {
       
   280     qint64 conversationId = ConversationsEngine::instance()-> getConversationIdFromContactId(
       
   281         contactId);
       
   282 
       
   283     //set mode to viewer, if conversations found else send mode.
       
   284     QVariantList param;
       
   285     if (conversationId > 0) {
       
   286         param << MsgBaseView::CV;
       
   287         param << MsgBaseView::SERVICE;
       
   288         param << conversationId;
       
   289     }
       
   290     else {
       
   291         ConvergedMessage message;
       
   292         ConvergedMessageAddress address;
       
   293         address.setAddress(phoneNumber);
       
   294         address.setAlias(displayName);
       
   295         message.addToRecipient(address);
       
   296 
       
   297         QByteArray dataArray;
       
   298         QDataStream messageStream(&dataArray, QIODevice::WriteOnly | QIODevice::Append);
       
   299         message.serialize(messageStream);
       
   300 
       
   301         param << MsgBaseView::UNIEDITOR;
       
   302         param << MsgBaseView::SERVICE;
       
   303         param << dataArray;
       
   304     }
       
   305     switchView(param);
       
   306     XQServiceUtil::toBackground(false);
       
   307 }
       
   308 
       
   309 void MsgViewManager::send(const QString phoneNumber, const QString alias, const QString bodyText)
       
   310 {
       
   311     ConvergedMessage message;
       
   312     ConvergedMessageAddress address;
       
   313     address.setAddress(phoneNumber);
       
   314     address.setAlias(alias);
       
   315     message.addToRecipient(address);
       
   316     message.setBodyText(bodyText);
       
   317 
       
   318     QVariantList param;
       
   319     QByteArray dataArray;
       
   320     QDataStream messageStream(&dataArray, QIODevice::WriteOnly | QIODevice::Append);
       
   321     message.serialize(messageStream);
       
   322 
       
   323     param << MsgBaseView::UNIEDITOR;
       
   324     param << MsgBaseView::SERVICE;
       
   325     param << dataArray;
       
   326 
       
   327     switchView(param);
       
   328     XQServiceUtil::toBackground(false);
       
   329 }
       
   330 
       
   331 void MsgViewManager::setServiceRequest(bool request)
       
   332 {
       
   333     mServiceRequest = request;
       
   334     mViewAtServiceRequest = mCurrentView;
       
   335 }
       
   336 
       
   337 void MsgViewManager::switchToLastSavedView()
       
   338 {
       
   339     QVariantList param;
       
   340 
       
   341     switch (mViewAtServiceRequest) {
       
   342     case MsgBaseView::CV:
       
   343     {
       
   344         param << MsgBaseView::CV;
       
   345         param << MsgBaseView::SERVICE;
       
   346         param << mConversationId;
       
   347         break;
       
   348     }
       
   349     case MsgBaseView::UNIVIEWER:
       
   350     {
       
   351         param << MsgBaseView::UNIVIEWER;
       
   352         param << MsgBaseView::SERVICE;
       
   353         break;
       
   354     }
       
   355     default:
       
   356     {
       
   357         param << MsgBaseView::CLV;
       
   358         param << MsgBaseView::SERVICE;
       
   359         break;
       
   360     }
       
   361     }
       
   362     switchView(param);
       
   363 }
       
   364 
       
   365 void MsgViewManager::open(qint64 conversationId)
       
   366 {
       
   367     QVariantList param;
       
   368 
       
   369     if (conversationId < 0) {
       
   370         param << MsgBaseView::CLV;
       
   371         param << MsgBaseView::SERVICE;
       
   372         
       
   373         if( mCurrentView == MsgBaseView::CV && mConversationView)
       
   374             {
       
   375             mConversationView->setPSCVId(false);
       
   376             }
       
   377     }
       
   378     else {
       
   379         param << MsgBaseView::CV;
       
   380         param << MsgBaseView::SERVICE;
       
   381         param << conversationId;
       
   382     }
       
   383 
       
   384     switchView(param);
       
   385     XQServiceUtil::toBackground(false);
       
   386 }
       
   387 
       
   388 void MsgViewManager::send(QVariant data)
       
   389 {
       
   390     ConvergedMessage message;
       
   391     ConvergedMessageAttachmentList attachmentList;
       
   392     // handle multiple files from sendUI
       
   393     // e.g. contacts can send multiple vcards
       
   394     QStringList receivedFiles = data.toStringList();
       
   395     int recFileCount = receivedFiles.count();
       
   396     for (int i = 0; i < recFileCount; i++) {
       
   397         ConvergedMessageAttachment *attachment =
       
   398             new ConvergedMessageAttachment(receivedFiles.at(i));
       
   399         attachmentList.append(attachment);
       
   400     }
       
   401     message.addAttachments(attachmentList);
       
   402 
       
   403     QByteArray dataArray;
       
   404     QDataStream messageStream(&dataArray, QIODevice::WriteOnly | QIODevice::Append);
       
   405     message.serialize(messageStream);
       
   406 
       
   407     QVariantList param;
       
   408     param << MsgBaseView::UNIEDITOR;
       
   409     param << MsgBaseView::SERVICE;
       
   410     param << dataArray;
       
   411 
       
   412     switchView(param);
       
   413     XQServiceUtil::toBackground(false);
       
   414 }
       
   415 
       
   416 qint64 MsgViewManager::findConversationId(const QString phoneNum)
       
   417 {
       
   418     return ConversationsEngine::instance()-> getConversationIdFromAddress(phoneNum);
       
   419 }
       
   420 
       
   421 //will be depricated in future.
       
   422 void MsgViewManager::openEditor(QString phoneNumber, QString name)
       
   423 {
       
   424     ConvergedMessage message;
       
   425     ConvergedMessageAddress address;
       
   426     address.setAddress(phoneNumber);
       
   427     address.setAlias(name);
       
   428     message.addToRecipient(address);
       
   429 
       
   430     QByteArray dataArray;
       
   431     QDataStream messageStream(&dataArray, QIODevice::WriteOnly | QIODevice::Append);
       
   432     message.serialize(messageStream);
       
   433 
       
   434     QVariantList param;
       
   435     param << MsgBaseView::UNIEDITOR;
       
   436     param << MsgBaseView::SERVICE;
       
   437     param << dataArray;
       
   438 
       
   439     switchView(param);
       
   440     XQServiceUtil::toBackground(false);
       
   441 }
       
   442 
       
   443 void MsgViewManager::completeServiceRequest()
       
   444 {
       
   445     mServiceRequest = false;
       
   446     XQServiceUtil::toBackground(true);
       
   447     switchToLastSavedView();
       
   448 }
       
   449 
       
   450 void MsgViewManager::switchToClv(const QVariantList& data)
       
   451 {
       
   452     //switch to CLV.
       
   453     mCurrentView = MsgBaseView::CLV;
       
   454     mPreviousView = data.at(1).toInt();
       
   455 
       
   456     // delete case from viewer service  
       
   457     if (mViewServiceRequest && (mPreviousView == MsgBaseView::UNIVIEWER)) {
       
   458         // quit the application 
       
   459         HbApplication::quit();
       
   460     }
       
   461 
       
   462     if (mConversationView) {
       
   463         mConversationView->saveContentToDrafts();
       
   464         //clearing content of cv.
       
   465         mConversationView->clearContent();
       
   466     }
       
   467 
       
   468     if (!mListView) {
       
   469         mListView = new MsgListView();
       
   470         mListView->setNavigationAction(mBackAction);
       
   471         connect(mListView, SIGNAL(switchView(const QVariantList&)), this,
       
   472             SLOT(switchView(const QVariantList&)));
       
   473         mMainWindow->addView(mListView);
       
   474     }
       
   475 
       
   476     mMainWindow->setCurrentView(mListView);
       
   477     
       
   478     //delete UniEditor
       
   479     if (mUniEditor)
       
   480     {
       
   481         appendViewToBeDeleted(mUniEditor);
       
   482         mUniEditor = NULL;
       
   483     }
       
   484     
       
   485     //delete UniViewer
       
   486     if (mUniViewer)
       
   487     {
       
   488         appendViewToBeDeleted(mUniViewer);
       
   489         mUniViewer = NULL;
       
   490     }
       
   491 }
       
   492 
       
   493 void MsgViewManager::switchToCv(const QVariantList& data)
       
   494 {
       
   495     //switch to CV.
       
   496     mCurrentView = MsgBaseView::CV;
       
   497     mPreviousView = data.at(1).toInt();
       
   498 
       
   499     // delete case from viewer service
       
   500     if (mViewServiceRequest && (mPreviousView == MsgBaseView::UNIVIEWER)) {
       
   501         // quit the application 
       
   502         HbApplication::quit();
       
   503     }
       
   504 
       
   505     QVariant var = data.at(2);
       
   506     qint64 conversationId;
       
   507     if (var.type() == QVariant::String) {
       
   508         QString phoneNumber = var.toString();
       
   509         conversationId = findConversationId(phoneNumber);
       
   510 
       
   511         if (conversationId == NULL_CONVERSATIONID) {
       
   512             QVariantList param;
       
   513             param << MsgBaseView::CLV;
       
   514             param << MsgBaseView::CV;
       
   515             
       
   516             if( mCurrentView == MsgBaseView::CV && mConversationView){
       
   517                 mConversationView->setPSCVId(false);
       
   518                 }
       
   519             
       
   520             switchView(param);
       
   521             return;
       
   522         }
       
   523     }
       
   524     else if (var.type() == QVariant::Invalid) {
       
   525         // this case comes when a message is deleted from 
       
   526         // Unified viewer  set curent view as conversation view 
       
   527         // and return
       
   528         mMainWindow->setCurrentView(mConversationView);
       
   529 		
       
   530 		// publish already opened conversation's id
       
   531         mConversationView->setPSCVId(true);
       
   532 		
       
   533         if (mUniViewer)
       
   534         {
       
   535             appendViewToBeDeleted(mUniViewer);
       
   536             mUniViewer = NULL;
       
   537         }
       
   538 
       
   539         return;
       
   540     }
       
   541     else {
       
   542         conversationId = var.toLongLong();
       
   543     }
       
   544     //switch to CV.
       
   545     mConversationId = conversationId;
       
   546 
       
   547     if (!mConversationView) {
       
   548         mConversationView = new MsgConversationBaseView();
       
   549         mConversationView->setNavigationAction(mBackAction);
       
   550         connect(mConversationView, SIGNAL(switchView(const QVariantList&)), this,
       
   551             SLOT(switchView(const QVariantList&)));
       
   552 
       
   553         mMainWindow->addView(mConversationView);
       
   554     }
       
   555     else if (mConversationView->conversationId() != mConversationId){
       
   556   		//Save content to drafts before switching to different CV
       
   557         mConversationView->saveContentToDrafts();
       
   558         //clearing content of current cv.
       
   559         mConversationView->clearContent();
       
   560   	}	
       
   561 
       
   562     mConversationView->openConversation(conversationId);
       
   563 
       
   564     if (mServiceRequest) {
       
   565         mMainWindow->setCurrentView(mConversationView);
       
   566     }
       
   567     else {
       
   568         mMainWindow->setCurrentView(mConversationView);
       
   569     }
       
   570     
       
   571     //delete UniEditor
       
   572     if (mUniEditor)
       
   573     {
       
   574         appendViewToBeDeleted(mUniEditor);
       
   575         mUniEditor = NULL;
       
   576     }
       
   577     
       
   578     //delete UniViewer
       
   579     if (mUniViewer)
       
   580     {
       
   581         appendViewToBeDeleted(mUniViewer);
       
   582         mUniViewer = NULL;
       
   583     }
       
   584 }
       
   585 
       
   586 void MsgViewManager::switchToDlv(const QVariantList& data)
       
   587 {
       
   588     //switch to DLV.
       
   589     mCurrentView = MsgBaseView::DLV;
       
   590     mPreviousView = data.at(1).toInt();
       
   591 
       
   592     if (!mDraftsListView) {
       
   593         mDraftsListView = new DraftsListView();
       
   594         mDraftsListView->setNavigationAction(mBackAction);
       
   595         connect(mDraftsListView, SIGNAL(switchView(const QVariantList&)), this,
       
   596             SLOT(switchView(const QVariantList&)));
       
   597 
       
   598         mMainWindow->addView(mDraftsListView);
       
   599     }
       
   600     mMainWindow->setCurrentView(mDraftsListView);
       
   601 }
       
   602 
       
   603 void MsgViewManager::switchToUniEditor(const QVariantList& data)
       
   604 {
       
   605     /**
       
   606      * Editor is tried to open again before exiting the previously
       
   607      * opened editor. Multi taping in DLV or Forward.
       
   608      */
       
   609     if (mUniEditor) {
       
   610         return;
       
   611     }
       
   612 
       
   613     mCurrentView = MsgBaseView::UNIEDITOR;
       
   614     mPreviousView = data.at(1).toInt();
       
   615 
       
   616     if (mConversationView) {
       
   617         //clearing content of cv.
       
   618         mConversationView->clearContent();
       
   619     }
       
   620 
       
   621      // reset conversation id published
       
   622      if(mPreviousView == MsgBaseView::CV && mConversationView)
       
   623          {
       
   624          mConversationView->setPSCVId(false);
       
   625          }
       
   626      
       
   627     //swich to unieditor.
       
   628     if (!mUniEditor) {
       
   629         mUniEditor = new MsgUnifiedEditorView();
       
   630         mMainWindow->addView(mUniEditor);
       
   631         mUniEditor->setNavigationAction(mBackAction);
       
   632         connect(mUniEditor, SIGNAL(switchView(const QVariantList&)), this,
       
   633             SLOT(switchView(const QVariantList&)));
       
   634     }
       
   635 
       
   636     // check if additional data for unieditor's consumption is available
       
   637     if (data.length() > 2) {
       
   638         QVariantList editorData;
       
   639         // i=2 because view manager consumed first two args
       
   640         for (int i = 2; i < data.length(); i++) {
       
   641             editorData << data.at(i);
       
   642         }
       
   643 
       
   644         if (MsgBaseView::DLV == mPreviousView) {
       
   645             mUniEditor->openDraftsMessage(editorData);
       
   646         }
       
   647         else {
       
   648             mUniEditor->populateContent(editorData);
       
   649         }
       
   650     }
       
   651 
       
   652     if (mServiceRequest) {
       
   653         mMainWindow->setCurrentView(mUniEditor);
       
   654     }
       
   655     else {
       
   656         mMainWindow->setCurrentView(mUniEditor);
       
   657     }
       
   658     //delete UniViewer
       
   659     if (mUniViewer )
       
   660     {
       
   661         appendViewToBeDeleted(mUniViewer);
       
   662         mUniViewer = NULL;
       
   663     }
       
   664 }
       
   665 
       
   666 void MsgViewManager::switchToUniViewer(const QVariantList& data)
       
   667 {
       
   668     /**
       
   669      * Viewer is tried to open again before exiting the previously
       
   670      * opened viewer. Multi taping bubbles in CV.
       
   671      */
       
   672     if (mUniViewer) {
       
   673         return;
       
   674     }
       
   675 
       
   676     mCurrentView = MsgBaseView::UNIVIEWER;
       
   677     mPreviousView = data.at(1).toInt();
       
   678 
       
   679     //switch to univiewer.
       
   680     if (data.length() > 2) {
       
   681         qint32 contactId = data.at(2).toLongLong();
       
   682         QByteArray dataArray = data.at(3).toByteArray();
       
   683         int msgCount = data.at(4).toInt();
       
   684 
       
   685         ConvergedMessage *message = new ConvergedMessage;
       
   686         QDataStream stream(&dataArray, QIODevice::ReadOnly);
       
   687         message->deserialize(stream);
       
   688         qint32 messageId = message->id()->getId();
       
   689         if (!mUniViewer) {
       
   690             mUniViewer = new UnifiedViewer(messageId);
       
   691             mUniViewer->setNavigationAction(mBackAction);
       
   692             mMainWindow->addView(mUniViewer);
       
   693             connect(mUniViewer, SIGNAL(switchView(const QVariantList&)), this,
       
   694                 SLOT(switchView(const QVariantList&)));
       
   695         }
       
   696         mUniViewer->populateContent(messageId, true, msgCount);
       
   697         delete message;
       
   698     }
       
   699     
       
   700     if(mPreviousView==MsgBaseView::CV && mConversationView)
       
   701         {
       
   702         mConversationView->setPSCVId(false);
       
   703         }
       
   704     
       
   705     mMainWindow->setCurrentView(mUniViewer);
       
   706 }
       
   707 void MsgViewManager::switchToMsgSettings(const QVariantList& data)
       
   708 {
       
   709     mCurrentView = MsgBaseView::MSGSETTINGS;
       
   710     mPreviousView = data.at(1).toInt();
       
   711 
       
   712     if (!mSettingsView) {
       
   713         
       
   714         MsgSettingsView::SettingsView view = MsgSettingsView::DefaultView;
       
   715         if (mPreviousView == MsgBaseView::UNIEDITOR || mPreviousView
       
   716                         == MsgBaseView::CV)
       
   717                 {
       
   718                     view = (MsgSettingsView::SettingsView)data.at(2).toInt();         
       
   719                 }
       
   720         
       
   721         mSettingsView = new MsgSettingsView(view);
       
   722         mSettingsView->setNavigationAction(mBackAction);
       
   723         mMainWindow->addView(mSettingsView);
       
   724         mMainWindow->setCurrentView(mSettingsView);
       
   725     }
       
   726     if(mPreviousView==MsgBaseView::CV && mConversationView){
       
   727         mConversationView->setPSCVId(false);
       
   728         }
       
   729 }
       
   730 
       
   731 void MsgViewManager::handleDefault(const QVariantList& data)
       
   732 {
       
   733     //special handling incase we switch from settings-view
       
   734     int previousViewId = data.at(1).toInt();
       
   735     if (MsgBaseView::MSGSETTINGS == previousViewId) {
       
   736         //switch to view, where from settings view was launched
       
   737         mCurrentView = mPreviousView;
       
   738         mPreviousView = previousViewId;
       
   739         //remove the settings view from main window
       
   740         if (mSettingsView)
       
   741         {
       
   742             appendViewToBeDeleted(mSettingsView);
       
   743             mSettingsView = NULL;
       
   744         }
       
   745         switch (mCurrentView) {
       
   746         case MsgBaseView::CLV:
       
   747         {
       
   748             if (mListView)
       
   749                 mMainWindow->setCurrentView(mListView);
       
   750             break;
       
   751         }
       
   752         case MsgBaseView::CV:
       
   753         {
       
   754             if (mConversationView)
       
   755                 mMainWindow->setCurrentView(mConversationView);
       
   756             break;
       
   757         }
       
   758         case MsgBaseView::DLV:
       
   759         {
       
   760             if (mDraftsListView)
       
   761                 mMainWindow->setCurrentView(mDraftsListView);
       
   762             break;
       
   763         }
       
   764         case MsgBaseView::UNIEDITOR:
       
   765         {
       
   766             if (mServiceRequest) {
       
   767                 mMainWindow->setCurrentView(mUniEditor);
       
   768             }
       
   769             else {
       
   770                 mMainWindow->setCurrentView(mUniEditor);
       
   771             }
       
   772             break;
       
   773         }
       
   774         }
       
   775     }
       
   776 }
       
   777 
       
   778 void MsgViewManager::view(int msgId)
       
   779 {
       
   780     int msgType;
       
   781     int msgSubType;
       
   782     mMessageId = msgId;
       
   783     qint32 messageId(msgId);
       
   784     ConversationsEngine::instance()->markAsReadAndGetType(messageId, msgType, msgSubType);
       
   785 
       
   786     switch (msgType) {
       
   787     case ConvergedMessage::Sms:
       
   788     case ConvergedMessage::Mms:
       
   789     case ConvergedMessage::MmsNotification:
       
   790     {
       
   791         handleSmsMmsMsg(msgId);
       
   792         break;
       
   793     }
       
   794     case ConvergedMessage::BioMsg:
       
   795     {
       
   796         if (msgSubType == ConvergedMessage::RingingTone) {
       
   797             handleRingtoneMsg(msgId);
       
   798 
       
   799         }
       
   800         else if (msgSubType == ConvergedMessage::Provisioning) {
       
   801             handleProvisoningMsg(msgId);
       
   802         }
       
   803         break;
       
   804     }
       
   805     case ConvergedMessage::BT:
       
   806     {
       
   807         break;
       
   808     }
       
   809     default:
       
   810     {
       
   811         // for un supported message show delete option
       
   812         HbMessageBox::question(LOC_DELETE_MESSAGE,this,SLOT(onDialogDeleteMsg(HbAction*)),
       
   813             LOC_BUTTON_DELETE,
       
   814             LOC_BUTTON_CANCEL);
       
   815         break;
       
   816     }
       
   817     }
       
   818 }
       
   819 
       
   820 // ----------------------------------------------------------------------------
       
   821 // MsgViewManager::handleSmsMmsMsg
       
   822 // @see header
       
   823 // ----------------------------------------------------------------------------
       
   824 void MsgViewManager::handleSmsMmsMsg(int msgId)
       
   825 {
       
   826     mViewServiceRequest = true;
       
   827 
       
   828     mCurrentView = MsgBaseView::UNIVIEWER;
       
   829 
       
   830     if (!mUniViewer) {
       
   831         mUniViewer = new UnifiedViewer(msgId);
       
   832         mUniViewer->setNavigationAction(mBackAction);
       
   833         mMainWindow->addView(mUniViewer);
       
   834         connect(mUniViewer, SIGNAL(switchView(const QVariantList&)), this,
       
   835             SLOT(switchView(const QVariantList&)));
       
   836     }
       
   837     mUniViewer->populateContent(msgId, true, -1);
       
   838 
       
   839     mMainWindow->setCurrentView(mUniViewer);
       
   840 }
       
   841 
       
   842 // ----------------------------------------------------------------------------
       
   843 // MsgViewManager::handleRingtoneMsg
       
   844 // @see header
       
   845 // ----------------------------------------------------------------------------
       
   846 void MsgViewManager::handleRingtoneMsg(int msgId)
       
   847 {
       
   848     mMessageId = msgId;
       
   849     HbMessageBox::question(LOC_DIALOG_SAVE_RINGTONE, this,
       
   850         SLOT(onDialogSaveTone(HbAction*)), LOC_COMMON_SAVE, LOC_BUTTON_CANCEL);
       
   851 }
       
   852 
       
   853 // ----------------------------------------------------------------------------
       
   854 // MsgViewManager::handleProvisoningMsg
       
   855 // @see header
       
   856 // ----------------------------------------------------------------------------
       
   857 void MsgViewManager::handleProvisoningMsg(int msgId)
       
   858 {
       
   859     QString messageId;
       
   860     messageId.setNum(msgId);
       
   861 
       
   862     XQApplicationManager* aiwMgr = new XQApplicationManager();
       
   863 
       
   864     XQAiwRequest* request = aiwMgr->create("com.nokia.services.MDM", "Provisioning",
       
   865         "ProcessMessage(QString)", true); // embedded
       
   866 
       
   867     if (request) {
       
   868         QList<QVariant> args;
       
   869         args << QVariant(messageId);
       
   870         request->setArguments(args);
       
   871 
       
   872         // Send the request
       
   873         bool res = request->send();
       
   874 
       
   875         // Cleanup
       
   876         delete request;
       
   877     }
       
   878 
       
   879     delete aiwMgr;
       
   880 
       
   881     // close the application once its handled
       
   882     HbApplication::quit();
       
   883 }
       
   884 
       
   885 void MsgViewManager::setViewInteractive()
       
   886 {
       
   887     if(!mMainWindow->isInteractive())
       
   888     {
       
   889         mMainWindow->setInteractive(true);
       
   890     }
       
   891     
       
   892     disconnect(mMainWindow, SIGNAL(viewReady()),this,SLOT(setViewInteractive()));
       
   893 }
       
   894 
       
   895 void  MsgViewManager::appendViewToBeDeleted(HbView* view)
       
   896 {
       
   897     if (view)
       
   898     {
       
   899         mViewTobeDeleted << view;
       
   900         connect(mMainWindow, SIGNAL(viewReady()), this, SLOT(deletePreviousView()));
       
   901     }
       
   902 }
       
   903 
       
   904 // ----------------------------------------------------------------------------
       
   905 // MsgViewManager::onDialogDeleteMsg
       
   906 // @see header
       
   907 // ----------------------------------------------------------------------------
       
   908 void MsgViewManager::onDialogDeleteMsg(HbAction* action)
       
   909 {
       
   910     HbMessageBox *dlg = qobject_cast<HbMessageBox*> (sender());
       
   911     if (action == dlg->actions().at(0)) {
       
   912         QList<int> msgIdList;
       
   913         msgIdList << mMessageId;
       
   914         ConversationsEngine::instance()->deleteMessages(msgIdList);
       
   915     }
       
   916     HbApplication::quit(); // exit after handling
       
   917 }
       
   918 
       
   919 // ----------------------------------------------------------------------------
       
   920 // MsgViewManager::onDialogSaveTone
       
   921 // @see header
       
   922 // ----------------------------------------------------------------------------
       
   923 void MsgViewManager::onDialogSaveTone(HbAction* action)
       
   924     {
       
   925         HbMessageBox *dlg = qobject_cast<HbMessageBox*> (sender());
       
   926         if (action == dlg->actions().at(0)) {
       
   927             UniDataModelLoader* pluginLoader = new UniDataModelLoader();
       
   928             UniDataModelPluginInterface* pluginInterface = pluginLoader->getDataModelPlugin(
       
   929                 ConvergedMessage::BioMsg);
       
   930             pluginInterface->setMessageId(mMessageId);
       
   931             UniMessageInfoList attachments = pluginInterface->attachmentList();
       
   932 
       
   933             QString attachmentPath = attachments.at(0)->path();
       
   934 
       
   935             RingBc* ringBc = new RingBc();
       
   936             ringBc->saveTone(attachmentPath);
       
   937 
       
   938             // clear attachement list : its allocated at data model
       
   939             while (!attachments.isEmpty()) {
       
   940                 delete attachments.takeFirst();
       
   941             }
       
   942 
       
   943             delete ringBc;
       
   944             delete pluginLoader;
       
   945         }
       
   946 
       
   947         // close the application once its handled
       
   948         HbApplication::quit();
       
   949 }
       
   950