messagingapp/msgservices/msgserviceapp/src/msgserviceviewmanager.cpp
changeset 67 fc91263aee62
parent 62 fdbe8253b596
child 73 ecf6a73a9186
equal deleted inserted replaced
65:d8ac8e5e4721 67:fc91263aee62
    15  *
    15  *
    16  */
    16  */
    17 
    17 
    18 #include "msgserviceviewmanager.h"
    18 #include "msgserviceviewmanager.h"
    19 
    19 
       
    20 #include <QFileInfo>
       
    21 #include <QDir>
       
    22 #include <QFile>
    20 #include <QPixmap>
    23 #include <QPixmap>
    21 #include <HbMainWindow>
    24 #include <HbMainWindow>
    22 #include <HbAction>
    25 #include <HbAction>
    23 #include <HbApplication>
    26 #include <HbApplication>
    24 #include <hbmessagebox.h>
    27 #include <HbMessageBox>
       
    28 #include <HbDeviceMessageBox>
       
    29 #include <HbSplashScreen>
    25 
    30 
    26 #include <xqserviceutil.h>
    31 #include <xqserviceutil.h>
    27 #include <xqappmgr.h>
    32 #include <xqappmgr.h>
    28 
    33 
    29 #include "msgunieditorview.h"
    34 #include "msgunieditorview.h"
    30 #include "unifiedviewer.h"
    35 #include "unifiedviewer.h"
    31 #include "msgstorehandler.h"
    36 #include "msgstorehandler.h"
    32 
       
    33 #include "msgsettingsview.h"
    37 #include "msgsettingsview.h"
    34 #include "convergedmessageid.h"
    38 #include "convergedmessageid.h"
    35 #include "ringbc.h"
    39 #include "ringbc.h"
    36 #include "unidatamodelloader.h"
    40 #include "unidatamodelloader.h"
    37 #include "unidatamodelplugininterface.h"
    41 #include "unidatamodelplugininterface.h"
       
    42 #include "msgcontacthandler.h"
    38 
    43 
    39 // CONSTANTS
    44 // CONSTANTS
    40 static const char SEND_EFFECT[] = "sendeffect";
    45 static const char SEND_EFFECT[] = "sendeffect";
    41 static const char SEND_EFFECT_FILE[] = ":/effects/sendeffect.fxml";
    46 static const char SEND_EFFECT_FILE[] = ":/effects/sendeffect.fxml";
    42 
    47 
    43 // LOCALIZATION
    48 // LOCALIZATION
    44 #define LOC_DELETE_MESSAGE hbTrId("txt_messaging_dialog_delete_message")
    49 #define LOC_DELETE_MESSAGE hbTrId("txt_messaging_dialog_delete_message")
    45 #define LOC_DLG_SAVE_RINGTONE hbTrId("txt_conversations_dialog_save_ringing_tone")
    50 // TODO: LOC
       
    51 #define LOC_DELETED_MESSAGE "Message is deleted"
       
    52 #define LOC_CANNOT_OPEN_MESSAGE "Message in outbox. Cannot be opened"
       
    53 #define LOC_UNKNOWN_MSG_TYPE "Unknown Message Type"
    46 
    54 
    47 //----------------------------------------------------------------------------
    55 //----------------------------------------------------------------------------
    48 // MsgViewInterface::MsgViewInterface
    56 // MsgViewInterface::MsgViewInterface
    49 // @see header
    57 // @see header
    50 //----------------------------------------------------------------------------
    58 //----------------------------------------------------------------------------
    51 MsgServiceViewManager::MsgServiceViewManager(MsgStoreHandler* storeHandler,
    59 MsgServiceViewManager::MsgServiceViewManager(MsgStoreHandler* storeHandler,
    52         HbMainWindow* mainWindow, QObject* parent) :
    60         HbMainWindow* mainWindow, QObject* parent) :
    53         QObject(parent), mMainWindow(mainWindow), mUniEditor(NULL),
    61         QObject(parent), mMainWindow(mainWindow), mUniEditor(NULL),
    54         mUniViewer(NULL), mSettingsView(NULL), mBackAction(NULL),
    62         mUniViewer(NULL), mSettingsView(NULL), mBackAction(NULL),
    55         mStoreHandler(storeHandler),mMessageId(-1)
    63         mStoreHandler(storeHandler)
    56     {
    64     {
    57     //creating back action.
    65     //creating back action.
    58     mBackAction = new HbAction(Hb::BackNaviAction, this);
    66     mBackAction = new HbAction(Hb::BackNaviAction, this);
    59     connect(mBackAction, SIGNAL(triggered()), this, SLOT(onBackAction()));
    67     connect(mBackAction, SIGNAL(triggered()), this, SLOT(onBackAction()));
    60     
    68     
   144                 editorData << data.at(a);
   152                 editorData << data.at(a);
   145                 }
   153                 }
   146             switchToUniEditor(editorData);
   154             switchToUniEditor(editorData);
   147             break;
   155             break;
   148             }
   156             }
   149 
       
   150         case MsgBaseView::MSGSETTINGS:
   157         case MsgBaseView::MSGSETTINGS:
   151             {
   158             {
   152             switchToMsgSettings(data);
   159             switchToMsgSettings(data);
   153             break;
   160             break;
   154             }
   161             }
   175 void MsgServiceViewManager::send(const QString phoneNumber, 
   182 void MsgServiceViewManager::send(const QString phoneNumber, 
   176         const qint32 contactId, 
   183         const qint32 contactId, 
   177         const QString displayName)
   184         const QString displayName)
   178     {
   185     {
   179     Q_UNUSED(contactId);
   186     Q_UNUSED(contactId);
       
   187     mMainWindow->show();
   180     ConvergedMessage message;
   188     ConvergedMessage message;
   181     ConvergedMessageAddress address;
   189     ConvergedMessageAddress address;
   182     address.setAddress(phoneNumber);
   190     address.setAddress(phoneNumber);
   183     address.setAlias(displayName);
   191     address.setAlias(displayName);
   184     message.addToRecipient(address);
   192     message.addToRecipient(address);
   202 //----------------------------------------------------------------------------
   210 //----------------------------------------------------------------------------
   203 void MsgServiceViewManager::send(const QString phoneNumber, 
   211 void MsgServiceViewManager::send(const QString phoneNumber, 
   204         const QString alias, 
   212         const QString alias, 
   205         const QString bodyText)
   213         const QString bodyText)
   206     {
   214     {
       
   215     mMainWindow->show();
   207     ConvergedMessage message;
   216     ConvergedMessage message;
   208     ConvergedMessageAddress address;
   217     ConvergedMessageAddress address;
   209     address.setAddress(phoneNumber);
   218     address.setAddress(phoneNumber);
   210     address.setAlias(alias);
   219     address.setAlias(alias);
   211     message.addToRecipient(address);
   220     message.addToRecipient(address);
   229 // @see header
   238 // @see header
   230 //----------------------------------------------------------------------------
   239 //----------------------------------------------------------------------------
   231 void MsgServiceViewManager::send(const QVariantMap addressList, 
   240 void MsgServiceViewManager::send(const QVariantMap addressList, 
   232               const QString bodyText)
   241               const QString bodyText)
   233     {
   242     {
   234     QStringList phoneNumList = addressList.keys();
   243     mMainWindow->show();
   235  
   244     QStringList phoneNumList = addressList.keys(); 
   236     ConvergedMessageAddressList addrList; 
   245     ConvergedMessageAddressList addrList;
   237 	
       
   238     int count = phoneNumList.count();
   246     int count = phoneNumList.count();
   239     for( int i = 0; i < count; ++ i )
   247     for( int i = 0; i < count; ++ i )
   240         {
   248         {
   241         QString phNum = phoneNumList[i];
   249         QString phNum = phoneNumList[i];
   242         ConvergedMessageAddress* address = new ConvergedMessageAddress(phNum,
   250         ConvergedMessageAddress* address = new ConvergedMessageAddress(phNum,
   265 // MsgServiceViewManager::send
   273 // MsgServiceViewManager::send
   266 // @see header
   274 // @see header
   267 //----------------------------------------------------------------------------
   275 //----------------------------------------------------------------------------
   268 void MsgServiceViewManager::send(QVariant data)
   276 void MsgServiceViewManager::send(QVariant data)
   269     {
   277     {
       
   278     mMainWindow->show();
   270     ConvergedMessage message;
   279     ConvergedMessage message;
   271     ConvergedMessageAttachmentList attachmentList;
   280     ConvergedMessageAttachmentList attachmentList;
   272     // handle multiple files from sendUI
   281     // handle multiple files from sendUI
   273     // e.g. contacts can send multiple vcards
   282     // e.g. contacts can send multiple vcards
   274     QStringList receivedFiles = data.toStringList();
   283     QStringList receivedFiles = data.toStringList();
   296 //----------------------------------------------------------------------------
   305 //----------------------------------------------------------------------------
   297 // MsgServiceViewManager::switchToUniEditor
   306 // MsgServiceViewManager::switchToUniEditor
   298 // @see header
   307 // @see header
   299 //----------------------------------------------------------------------------
   308 //----------------------------------------------------------------------------
   300 void MsgServiceViewManager::switchToUniEditor(const QVariantList& editorData)
   309 void MsgServiceViewManager::switchToUniEditor(const QVariantList& editorData)
   301     {
   310 {
   302     // construct
   311     // construct
   303     if (!mUniEditor) {
   312     if (!mUniEditor)
   304     mUniEditor = new MsgUnifiedEditorView();
   313     {
   305     mMainWindow->addView(mUniEditor);
   314         mUniEditor = new MsgUnifiedEditorView();
   306     mUniEditor->setNavigationAction(mBackAction);
   315         mMainWindow->addView(mUniEditor);
   307     connect(mUniEditor, SIGNAL(switchView(const QVariantList&)), this,
   316         mUniEditor->setNavigationAction(mBackAction);
   308             SLOT(switchView(const QVariantList&)));
   317         connect(mUniEditor, SIGNAL(switchView(const QVariantList&)), this,
   309     // construct completion : viewReady() signal was not called when 
   318                 SLOT(switchView(const QVariantList&)));
   310     // editor is constructed first time.
       
   311    // mUniEditor->doDelayedConstruction();
       
   312     }
   319     }
   313     
   320     
   314     // populate
   321     // populate
   315     mUniEditor->populateContent(editorData);
   322     mUniEditor->populateContent(editorData);
   316     
   323     
   317     // set current view as editor
   324     // set current view as editor
   318     mMainWindow->setCurrentView(mUniEditor);
   325     mMainWindow->setCurrentView(mUniEditor);
   319     mCurrentView = MsgBaseView::UNIEDITOR;
   326     mCurrentView = MsgBaseView::UNIEDITOR;
   320     }
   327 }
   321 
   328 
   322 //----------------------------------------------------------------------------
   329 //----------------------------------------------------------------------------
   323 // MsgServiceViewManager::switchToMsgSettings
   330 // MsgServiceViewManager::switchToMsgSettings
   324 // @see header
   331 // @see header
   325 //----------------------------------------------------------------------------
   332 //----------------------------------------------------------------------------
   326 void MsgServiceViewManager::switchToMsgSettings(const QVariantList& data)
   333 void MsgServiceViewManager::switchToMsgSettings(const QVariantList& data)
   327     {
   334 {
   328     MsgSettingsView::SettingsView view = MsgSettingsView::DefaultView;
   335     MsgSettingsView::SettingsView view = MsgSettingsView::DefaultView;
   329     
   336     
   330     if (mCurrentView == MsgBaseView::UNIEDITOR)
   337     if (mCurrentView == MsgBaseView::UNIEDITOR)
   331     {
   338     {
   332         view = (MsgSettingsView::SettingsView)data.at(2).toInt();
   339         view = (MsgSettingsView::SettingsView)data.at(2).toInt();
   333     }
   340     }
   334     
   341 
   335     mCurrentView = MsgBaseView::MSGSETTINGS;
   342     mCurrentView = MsgBaseView::MSGSETTINGS;
   336 
   343 
   337     if (!mSettingsView) {        
   344     if (!mSettingsView)
   338     mSettingsView = new MsgSettingsView(view);
   345     {        
   339     mSettingsView->setNavigationAction(mBackAction);
   346         mSettingsView = new MsgSettingsView(view);
   340     mMainWindow->addView(mSettingsView);
   347         mSettingsView->setNavigationAction(mBackAction);
       
   348         mMainWindow->addView(mSettingsView);
   341     }
   349     }
   342     mMainWindow->setCurrentView(mSettingsView);
   350     mMainWindow->setCurrentView(mSettingsView);
   343     }
   351 }
       
   352 
       
   353 //----------------------------------------------------------------------------
       
   354 // MsgServiceViewManager::showPopup
       
   355 // @see header
       
   356 //----------------------------------------------------------------------------
       
   357 void MsgServiceViewManager::showPopup(const QString& dispText)
       
   358 {
       
   359     HbDeviceMessageBox msgbox;
       
   360     msgbox.setMessageBoxType(HbMessageBox::MessageTypeInformation);
       
   361     msgbox.setText(dispText);
       
   362     msgbox.setAction(NULL, HbDeviceMessageBox::AcceptButtonRole);
       
   363     msgbox.exec();
       
   364     msgbox.close();
       
   365 }
   344 
   366 
   345 //----------------------------------------------------------------------------
   367 //----------------------------------------------------------------------------
   346 // MsgServiceViewManager::view
   368 // MsgServiceViewManager::view
   347 // @see header
   369 // @see header
   348 //----------------------------------------------------------------------------
   370 //----------------------------------------------------------------------------
   349 void MsgServiceViewManager::view(int msgId)
   371 void MsgServiceViewManager::view(int msgId)
   350     {
   372 {
       
   373     // Check if the message is present in store
       
   374     if(!mStoreHandler->exists(msgId))
       
   375     {
       
   376         showPopup(LOC_DELETED_MESSAGE);
       
   377         HbApplication::quit();
       
   378         return;
       
   379     }
       
   380 
       
   381     // Check if the given message is locked for viewing
       
   382     if(mStoreHandler->locked(msgId))
       
   383     {
       
   384         // if locked, then show info-note and exit
       
   385         showPopup(LOC_CANNOT_OPEN_MESSAGE);
       
   386         HbApplication::quit();
       
   387         return;
       
   388     }
       
   389 
       
   390     // Mark as read and get message type
   351     int msgType;
   391     int msgType;
   352     int msgSubType;
   392     int msgSubType;   
   353    
   393     mStoreHandler->markAsRead(msgId);
   354     mMessageId = msgId;
   394     mStoreHandler->getMsgTypeInfo(msgId,msgType,msgSubType);
   355     // Mark as read and get message type
   395 
   356     mStoreHandler->markAsReadAndGetType(msgId,msgType,msgSubType);
   396     // Open draft message in editor
   357     
   397     if(mStoreHandler->isDraftMessage(msgId))
   358     switch (msgType) {
   398     {
       
   399         handleDraftMsg(msgId,msgType);
       
   400         return;
       
   401     }
       
   402 
       
   403     switch (msgType) 
       
   404     {
   359         case ConvergedMessage::Sms:
   405         case ConvergedMessage::Sms:
   360         case ConvergedMessage::Mms:
   406         case ConvergedMessage::Mms:
       
   407         {
       
   408             if (msgSubType == ConvergedMessage::VCard)
       
   409             {
       
   410                 handleVCardMsg(msgId);
       
   411             }
       
   412             else
       
   413             {
       
   414                 handleSmsMmsMsg(msgId);    
       
   415             }
       
   416             break;
       
   417         }
   361         case ConvergedMessage::MmsNotification:
   418         case ConvergedMessage::MmsNotification:
   362             {
   419         {
   363             handleSmsMmsMsg(msgId,msgType);
   420             handleMmsNotification(msgId);
   364             break;
   421             break;
   365             }
   422         }
   366         case ConvergedMessage::BioMsg:
   423         case ConvergedMessage::BioMsg:
   367             {
   424         {
   368             if (msgSubType == ConvergedMessage::RingingTone) {
   425             if (msgSubType == ConvergedMessage::RingingTone)
   369             handleRingtoneMsg(msgId);
   426             {
   370             }
   427                 handleRingtoneMsg(msgId);
   371             else if (msgSubType == ConvergedMessage::Provisioning) {
   428             }
   372             handleProvisoningMsg(msgId);
   429             else if (msgSubType == ConvergedMessage::Provisioning)
   373             }
   430             {
   374             break;
   431                 handleProvisoningMsg(msgId);
   375             }
   432             }
       
   433             else if (msgSubType == ConvergedMessage::VCard)
       
   434             {
       
   435                 handleVCardMsg(msgId);
       
   436             }
       
   437             break;
       
   438         }
   376         case ConvergedMessage::BT:
   439         case ConvergedMessage::BT:
   377             {
   440         {
   378             handleBTMessage(msgId);
   441             handleBTMessage(msgId);
   379             break;
   442             break;
   380             }
   443         }
   381         default:
   444         default:
   382             {
   445         {
   383             // for un supported message show delete option
   446             // For all remaining unsupported messages, show delete option
   384             HbMessageBox::question(LOC_DELETE_MESSAGE, 
   447             showPopup(LOC_UNKNOWN_MSG_TYPE);
   385                                    this,SLOT(onDialogDeleteMsg(HbAction*)),    
   448             HbApplication::quit();
   386                                    HbMessageBox::Delete | HbMessageBox::Cancel);
   449         }
   387             break;
   450     }
   388             }
   451 }
   389     }
       
   390     }
       
   391 
   452 
   392 // ----------------------------------------------------------------------------
   453 // ----------------------------------------------------------------------------
   393 // MsgServiceViewManager::handleKeyEvent
   454 // MsgServiceViewManager::handleKeyEvent
   394 // @see header
   455 // @see header
   395 // ----------------------------------------------------------------------------
   456 // ----------------------------------------------------------------------------
   402     }
   463     }
   403     return eventHandled;
   464     return eventHandled;
   404 }
   465 }
   405 
   466 
   406 // ----------------------------------------------------------------------------
   467 // ----------------------------------------------------------------------------
       
   468 // MsgServiceViewManager::handleDraftMsg
       
   469 // @see header
       
   470 // ----------------------------------------------------------------------------
       
   471 void MsgServiceViewManager::handleDraftMsg(int msgId, int msgType)
       
   472 {
       
   473     // show the splash-screen
       
   474     // TODO: This causes cancellation of view switching effects
       
   475 //    HbSplashScreen::start();
       
   476     connect(mMainWindow, SIGNAL(viewReady()), this, SLOT(showOnViewReady()));
       
   477     mCurrentView = MsgBaseView::UNIEDITOR;
       
   478 
       
   479     // construct editor instance (keep it minimal)
       
   480     if (!mUniEditor)
       
   481     {
       
   482         mUniEditor = new MsgUnifiedEditorView();
       
   483         mMainWindow->addView(mUniEditor);
       
   484         mUniEditor->setNavigationAction(mBackAction);
       
   485         connect(mUniEditor, SIGNAL(switchView(const QVariantList&)), this,
       
   486                 SLOT(switchView(const QVariantList&)));
       
   487     }
       
   488 
       
   489     // prepare data for unieditor
       
   490     ConvergedMessage message;
       
   491     ConvergedMessageId convergedMsgId = ConvergedMessageId(msgId);
       
   492     message.setMessageType((ConvergedMessage::MessageType) msgType);
       
   493     message.setMessageId(convergedMsgId);
       
   494     QByteArray dataArray;
       
   495     QDataStream messageStream(&dataArray, QIODevice::WriteOnly | QIODevice::Append);
       
   496     message.serialize(messageStream);
       
   497     QVariantList editorData;
       
   498     editorData << dataArray;
       
   499 
       
   500     mMainWindow->show();
       
   501     // populate data into editor
       
   502     mUniEditor->openDraftsMessage(editorData);
       
   503 }
       
   504 
       
   505 // ----------------------------------------------------------------------------
       
   506 // MsgServiceViewManager::handleVCardMsg
       
   507 // @see header
       
   508 // ----------------------------------------------------------------------------
       
   509 void MsgServiceViewManager::handleVCardMsg(int msgId)
       
   510 {
       
   511     // Extract vCard filepath
       
   512     QString filepath;
       
   513     UniDataModelLoader* pluginLoader = new UniDataModelLoader();
       
   514     UniDataModelPluginInterface* pluginInterface = 
       
   515                     pluginLoader->getDataModelPlugin(ConvergedMessage::BioMsg);
       
   516     pluginInterface->setMessageId(msgId);
       
   517 
       
   518     // Get attachment list
       
   519     UniMessageInfoList attachments = pluginInterface->attachmentList();
       
   520     if(attachments.count() > 0)
       
   521     {
       
   522         filepath = attachments.at(0)->path();    
       
   523     }
       
   524 
       
   525     // Cleanup
       
   526     foreach(UniMessageInfo* attachmentInfo,attachments)
       
   527     {
       
   528         delete attachmentInfo;
       
   529     }
       
   530     delete pluginLoader;
       
   531 
       
   532     // Get vCard display name
       
   533     QString displayName = MsgContactHandler::getVCardDisplayName(filepath);
       
   534     // TODO: use displayname to create a localized string to show in dialog
       
   535     QString loc_str = QString("Save to contacts: ").append(displayName);
       
   536     bool viewVCard = HbDeviceMessageBox::question(loc_str,
       
   537                          HbMessageBox::Ok|HbMessageBox::Cancel);
       
   538     if(!viewVCard)
       
   539     {
       
   540         HbApplication::quit();
       
   541         return;
       
   542     }
       
   543 
       
   544     // copy private-vCard file to public location for contacts access
       
   545     QDir tempDir;
       
   546     QString sharedFilePath(QDir::toNativeSeparators(tempDir.tempPath()));
       
   547     sharedFilePath.append(QDir::separator());
       
   548     QFileInfo fInfo(filepath);
       
   549     sharedFilePath.append(fInfo.fileName());
       
   550     QFile::copy(filepath, sharedFilePath);
       
   551 
       
   552     // Launch vCard viewer service
       
   553     QString service("phonebookservices");
       
   554     QString interface("com.nokia.symbian.IContactsEdit");
       
   555     QString operation("editCreateNewFromVCard(QString)");
       
   556     XQApplicationManager appManager;
       
   557     // embedded launch
       
   558     XQAiwRequest* request = 
       
   559             appManager.create(service, interface, operation, true);
       
   560     if(request)
       
   561     {
       
   562         QList<QVariant> args;
       
   563         args << sharedFilePath;
       
   564         request->setArguments(args);
       
   565         QVariant retValue;
       
   566         bool res = request->send(retValue);
       
   567         delete request;
       
   568     }
       
   569 
       
   570     // Delete shared file now
       
   571     QFile::remove(sharedFilePath);
       
   572     HbApplication::quit();
       
   573 }
       
   574 
       
   575 // ----------------------------------------------------------------------------
   407 // MsgServiceViewManager::handleSmsMmsMsg
   576 // MsgServiceViewManager::handleSmsMmsMsg
   408 // @see header
   577 // @see header
   409 // ----------------------------------------------------------------------------
   578 // ----------------------------------------------------------------------------
   410 void MsgServiceViewManager::handleSmsMmsMsg(int msgId,int msgType)
   579 void MsgServiceViewManager::handleSmsMmsMsg(int msgId)
   411 {
   580 {
   412     if(mStoreHandler->isDraftMessage(msgId))
   581     // show the splash-screen
   413     {
   582     // TODO: This causes cancellation of view switching effects
   414         ConvergedMessageId convergedMsgId = ConvergedMessageId(msgId);
   583 //    HbSplashScreen::start();
   415         ConvergedMessage message;
   584     connect(mMainWindow, SIGNAL(viewReady()), this, SLOT(showOnViewReady()));
   416         message.setMessageType((ConvergedMessage::MessageType) msgType);
   585     mCurrentView = MsgBaseView::UNIVIEWER;
   417         message.setMessageId(convergedMsgId);
   586 
   418 
   587     // construct viewer instance (keep it minimal)
   419         // Launch uni-editor view
   588     if(!mUniViewer)
   420         QByteArray dataArray;
   589     {
   421         QDataStream messageStream(&dataArray, QIODevice::WriteOnly | QIODevice::Append);
   590         mUniViewer = new UnifiedViewer(msgId);
   422         message.serialize(messageStream);
   591         mMainWindow->addView(mUniViewer);
   423 
   592         mUniViewer->setNavigationAction(mBackAction);
   424         QVariantList params;
   593         connect(mUniViewer, SIGNAL(switchView(const QVariantList&)),
   425         params << MsgBaseView::UNIEDITOR; // target view
   594                         this, SLOT(switchView(const QVariantList&)));
   426         params << MsgBaseView::SERVICE; // source view
   595     }
   427 
   596 
   428         params << dataArray;
   597     // populate the viewer
   429         
   598     mUniViewer->populateContent(msgId, true, 1);
   430         // except first 2 parameters pass other parameters
   599     mMainWindow->show();
   431         QVariantList editorData;
   600 }
   432         for(int a = 2; a < params.length(); ++a)
   601 
   433         {
   602 // ----------------------------------------------------------------------------
   434             editorData << params.at(a);
   603 // MsgServiceViewManager::handleMmsNotification
   435         }
   604 // @see header
   436         // construct
   605 // ----------------------------------------------------------------------------
   437           if (!mUniEditor) {
   606 void MsgServiceViewManager::handleMmsNotification(int msgId)
   438           mUniEditor = new MsgUnifiedEditorView();
   607 {
   439           mMainWindow->addView(mUniEditor);
   608     // set context to current entry
   440           mUniEditor->setNavigationAction(mBackAction);
   609     if( KErrNone != mStoreHandler->setNotificationMessageId(msgId))
   441           connect(mUniEditor, SIGNAL(switchView(const QVariantList&)), this,
   610     {
   442                   SLOT(switchView(const QVariantList&)));
   611         return;
   443           }
   612     }
   444           
   613 
   445           // check if additional data for unieditor's consumption is available
   614     // notification state e.g. waiting, retrieving etc
   446           mUniEditor->openDraftsMessage(editorData);
   615     QString statusStr;
   447 
   616     int status;
   448           mMainWindow->setCurrentView(mUniEditor);
   617     mStoreHandler->notificationStatus(status, statusStr);
   449           mCurrentView = MsgBaseView::UNIEDITOR;
   618 
   450     }
   619     QString displayTxt;
   451     else
   620     displayTxt.append(mStoreHandler->notificationSubject());
   452     {
   621     displayTxt.append(QChar::LineSeparator);
   453         if (!mUniViewer) {
   622     displayTxt.append(mStoreHandler->notificationMsgSize());
   454             mUniViewer = new UnifiedViewer(msgId);
   623     displayTxt.append(QChar::LineSeparator);
   455             mUniViewer->setNavigationAction(mBackAction);
   624     displayTxt.append(mStoreHandler->notificationClass());
   456             mMainWindow->addView(mUniViewer);
   625     displayTxt.append(QChar::LineSeparator);
   457             connect(mUniViewer, SIGNAL(switchView(const QVariantList&)), this,
   626     displayTxt.append(mStoreHandler->notificationExpiryDate());
   458                 SLOT(switchView(const QVariantList&)));
   627     if(!statusStr.isEmpty())
   459         }
   628     {
   460         mUniViewer->populateContent(msgId, true, 1);
   629         displayTxt.append(QChar::LineSeparator);
   461 
   630         displayTxt.append(statusStr);
   462         mMainWindow->setCurrentView(mUniViewer);
   631     }    
   463 
   632     HbDeviceMessageBox::information(displayTxt);
   464         // set current view as viewer
   633     HbApplication::quit();
   465         mCurrentView = MsgBaseView::UNIVIEWER;
   634 }
   466     }
   635 
       
   636 // ----------------------------------------------------------------------------
       
   637 // MsgServiceViewManager::showOnViewReady
       
   638 // @see header
       
   639 // ----------------------------------------------------------------------------
       
   640 void MsgServiceViewManager::showOnViewReady()
       
   641 {
       
   642     switch(mCurrentView)
       
   643     {
       
   644         case MsgBaseView::UNIVIEWER:
       
   645         {
       
   646             mMainWindow->setCurrentView(mUniViewer);
       
   647             break;
       
   648         }
       
   649         case MsgBaseView::UNIEDITOR:
       
   650         {
       
   651             mMainWindow->setCurrentView(mUniEditor);
       
   652             break;
       
   653         }
       
   654         default:
       
   655             break;
       
   656     }
       
   657     disconnect(mMainWindow, SIGNAL(viewReady()), this, SLOT(showOnViewReady()));
   467 }
   658 }
   468 
   659 
   469 // ----------------------------------------------------------------------------
   660 // ----------------------------------------------------------------------------
   470 // MsgServiceViewManager::handleRingtoneMsg
   661 // MsgServiceViewManager::handleRingtoneMsg
   471 // @see header
   662 // @see header
   472 // ----------------------------------------------------------------------------
   663 // ----------------------------------------------------------------------------
   473 void MsgServiceViewManager::handleRingtoneMsg(int msgId)
   664 void MsgServiceViewManager::handleRingtoneMsg(int msgId)
   474     {
   665 {
   475     mMessageId = msgId;
   666     // Extract rintone filepath
   476     HbMessageBox::question(LOC_DLG_SAVE_RINGTONE, this,
   667     UniDataModelLoader* pluginLoader = new UniDataModelLoader();
   477                            SLOT(onDialogSaveTone(HbAction*)),
   668     UniDataModelPluginInterface* pluginInterface = 
   478                            HbMessageBox::Save | HbMessageBox::Cancel);
   669                         pluginLoader->getDataModelPlugin(ConvergedMessage::BioMsg);
   479     }
   670     pluginInterface->setMessageId(msgId);
       
   671 
       
   672     // Get attachment list
       
   673     UniMessageInfoList attachments = pluginInterface->attachmentList();
       
   674     QString filepath;
       
   675     if(attachments.count() > 0)
       
   676     {
       
   677         filepath = attachments.at(0)->path();
       
   678     }
       
   679 
       
   680     // Cleanup
       
   681     foreach(UniMessageInfo* attachmentInfo,attachments)
       
   682     {
       
   683         delete attachmentInfo;
       
   684     }
       
   685     delete pluginLoader;
       
   686 
       
   687     RingBc* ringBc = new RingBc();
       
   688     QString filename = ringBc->toneTitle(filepath);
       
   689     // TODO: use filename to create a localized string to show in dialog
       
   690     QString loc_str = QString("Save ringtone? ").append(filename);
       
   691     bool save = HbDeviceMessageBox::question(loc_str,
       
   692                     HbMessageBox::Save | HbMessageBox::Cancel);
       
   693     if(save)
       
   694     {
       
   695         ringBc->saveTone(filepath);
       
   696     }
       
   697     delete ringBc;
       
   698     HbApplication::quit();
       
   699 }
   480 
   700 
   481 // ----------------------------------------------------------------------------
   701 // ----------------------------------------------------------------------------
   482 // MsgServiceViewManager::handleProvisoningMsg
   702 // MsgServiceViewManager::handleProvisoningMsg
   483 // @see header
   703 // @see header
   484 // ----------------------------------------------------------------------------
   704 // ----------------------------------------------------------------------------
   537     delete aiwMgr;
   757     delete aiwMgr;
   538 
   758 
   539     // close the application once its handled
   759     // close the application once its handled
   540     HbApplication::quit();
   760     HbApplication::quit();
   541     }
   761     }
   542 
       
   543 //-----------------------------------------------------------------------------
       
   544 //MsgServiceViewManager::onDialogDeleteMsg()
       
   545 //@see header
       
   546 //-----------------------------------------------------------------------------
       
   547 void MsgServiceViewManager::onDialogDeleteMsg(HbAction* action)
       
   548 {
       
   549     HbMessageBox *dlg = qobject_cast<HbMessageBox*> (sender());
       
   550     if (action == dlg->actions().at(0)) {
       
   551         mStoreHandler->deleteMessage(mMessageId);
       
   552     }
       
   553     HbApplication::quit(); // exit after handling
       
   554 }
       
   555 
       
   556 //-----------------------------------------------------------------------------
       
   557 //MsgServiceViewManager::onDialogSaveTone()
       
   558 //@see header
       
   559 //-----------------------------------------------------------------------------
       
   560 
       
   561 void MsgServiceViewManager::onDialogSaveTone(HbAction* action)
       
   562     {
       
   563         HbMessageBox *dlg = qobject_cast<HbMessageBox*> (sender());
       
   564         if (action == dlg->actions().at(0)) {
       
   565 
       
   566             UniDataModelLoader* pluginLoader = new UniDataModelLoader();
       
   567             UniDataModelPluginInterface* pluginInterface = pluginLoader->getDataModelPlugin(
       
   568                 ConvergedMessage::BioMsg);
       
   569             pluginInterface->setMessageId(mMessageId);
       
   570             UniMessageInfoList attachments = pluginInterface->attachmentList();
       
   571 
       
   572             QString attachmentPath = attachments.at(0)->path();
       
   573 
       
   574             RingBc* ringBc = new RingBc();
       
   575             ringBc->saveTone(attachmentPath);
       
   576 
       
   577             // clear attachement list : its allocated at data model
       
   578             while (!attachments.isEmpty()) {
       
   579                 delete attachments.takeFirst();
       
   580             }
       
   581 
       
   582             delete ringBc;
       
   583             delete pluginLoader;
       
   584         }
       
   585 
       
   586         // close the application once its handled
       
   587         HbApplication::quit();
       
   588 }
       
   589 
   762 
   590 //-----------------------------------------------------------------------------
   763 //-----------------------------------------------------------------------------
   591 //MsgServiceViewManager::startAnimation
   764 //MsgServiceViewManager::startAnimation
   592 //@see header
   765 //@see header
   593 //-----------------------------------------------------------------------------
   766 //-----------------------------------------------------------------------------
   713 //@see header
   886 //@see header
   714 //-----------------------------------------------------------------------------
   887 //-----------------------------------------------------------------------------
   715 
   888 
   716 void MsgServiceViewManager::send(ConvergedMessage message)
   889 void MsgServiceViewManager::send(ConvergedMessage message)
   717     {
   890     {
       
   891     mMainWindow->show();    
   718     QVariantList param;
   892     QVariantList param;
   719     QByteArray dataArray;
   893     QByteArray dataArray;
   720     QDataStream messageStream(&dataArray, QIODevice::WriteOnly | QIODevice::Append);
   894     QDataStream messageStream(&dataArray, QIODevice::WriteOnly | QIODevice::Append);
   721     
       
   722     message.serialize(messageStream);
   895     message.serialize(messageStream);
   723     param << dataArray;
   896     param << dataArray;
   724 
   897 
   725     // switch to editor
   898     // switch to editor
   726     switchToUniEditor(param);
   899     switchToUniEditor(param);