messagingapp/msgservices/msgserviceapp/src/msgserviceviewmanager.cpp
changeset 27 e4592d119491
child 34 84197e66a4bd
equal deleted inserted replaced
25:84d9eb65b26f 27:e4592d119491
       
     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:  Manages differnt messaging views.
       
    15  *
       
    16  */
       
    17 
       
    18 #include "msgserviceviewmanager.h"
       
    19 
       
    20 #include <HbMainWindow>
       
    21 #include <HbAction>
       
    22 #include <HbApplication>
       
    23 #include <HbMessageBox.h>
       
    24 
       
    25 #include <xqserviceutil.h>
       
    26 #include <xqappmgr.h>
       
    27 
       
    28 #include "msgunieditorview.h"
       
    29 #include "unifiedviewer.h"
       
    30 #include "msgstorehandler.h"
       
    31 
       
    32 #include "msgsettingsview.h"
       
    33 #include "convergedmessageid.h"
       
    34 #include "ringbc.h"
       
    35 #include "unidatamodelloader.h"
       
    36 #include "unidatamodelplugininterface.h"
       
    37 
       
    38 // LOCALIZATION
       
    39 #define LOC_BUTTON_DELETE hbTrId("txt_common_button_delete")
       
    40 #define LOC_BUTTON_CANCEL hbTrId("txt_common_button_cancel")
       
    41 #define LOC_DELETE_MESSAGE hbTrId("txt_messaging_dialog_delete_message")
       
    42 #define LOC_DLG_SAVE_RINGTONE hbTrId("txt_conversations_dialog_save_ringing_tone")
       
    43 #define LOC_BUTTON_SAVE hbTrId("txt_common_menu_save")
       
    44 
       
    45 //----------------------------------------------------------------------------
       
    46 // MsgViewInterface::MsgViewInterface
       
    47 // @see header
       
    48 //----------------------------------------------------------------------------
       
    49 MsgServiceViewManager::MsgServiceViewManager(MsgStoreHandler* storeHandler,
       
    50         HbMainWindow* mainWindow, QObject* parent) :
       
    51         QObject(parent), mMainWindow(mainWindow), mUniEditor(NULL),
       
    52         mUniViewer(NULL), mSettingsView(NULL), mBackAction(NULL),
       
    53         mStoreHandler(storeHandler),mMessageId(-1)
       
    54     {
       
    55     //creating back action.
       
    56     mBackAction = new HbAction(Hb::BackNaviAction, this);
       
    57     connect(mBackAction, SIGNAL(triggered()), this, SLOT(onBackAction()));
       
    58     
       
    59     // create a temp view : which is required for lazy loading of other views
       
    60     HbView* tempView = new HbView();
       
    61     mMainWindow->addView(tempView);
       
    62     mMainWindow->setCurrentView(tempView);
       
    63     }
       
    64 
       
    65 //----------------------------------------------------------------------------
       
    66 // MsgServiceViewManager::~MsgServiceViewManager
       
    67 // @see header
       
    68 //----------------------------------------------------------------------------
       
    69 MsgServiceViewManager::~MsgServiceViewManager()
       
    70     {
       
    71   
       
    72     }
       
    73 
       
    74 //----------------------------------------------------------------------------
       
    75 // MsgServiceViewManager::onBackAction
       
    76 // @see header
       
    77 //----------------------------------------------------------------------------
       
    78 void MsgServiceViewManager::onBackAction()
       
    79     {
       
    80     switch(mCurrentView)
       
    81         {
       
    82         case MsgBaseView::UNIEDITOR:
       
    83             {
       
    84             mUniEditor->saveContentToDrafts();
       
    85             HbApplication::quit();
       
    86             break;
       
    87             }
       
    88         case MsgBaseView::MSGSETTINGS:
       
    89             {
       
    90             //delete the settings instance
       
    91             if (mSettingsView)
       
    92             {
       
    93                 mMainWindow->removeView(mSettingsView);
       
    94                 delete mSettingsView;
       
    95                 mSettingsView = NULL;
       
    96             }
       
    97             if(mUniEditor)
       
    98                 {
       
    99                 mMainWindow->setCurrentView(mUniEditor);
       
   100                 mCurrentView = MsgBaseView::UNIEDITOR;
       
   101                 }
       
   102             else 
       
   103                 {
       
   104                 ConvergedMessage message;
       
   105                 QVariantList param;
       
   106                 QByteArray dataArray;
       
   107                 QDataStream messageStream(&dataArray, 
       
   108                         QIODevice::WriteOnly | QIODevice::Append);
       
   109                 message.serialize(messageStream);
       
   110                 param << dataArray;
       
   111 
       
   112                 // switch to editor
       
   113                 switchToUniEditor(param);
       
   114                 }
       
   115             break;
       
   116             }
       
   117         case MsgBaseView::UNIVIEWER: 
       
   118         default:
       
   119             {
       
   120             HbApplication::quit();
       
   121             break;
       
   122             }
       
   123             
       
   124         }
       
   125     }
       
   126 
       
   127 //----------------------------------------------------------------------------
       
   128 // MsgServiceViewManager::switchView
       
   129 // @see header
       
   130 //----------------------------------------------------------------------------
       
   131 void MsgServiceViewManager::switchView(const QVariantList& data)
       
   132     {
       
   133     int viewId = data.at(0).toInt();
       
   134     switch (viewId) {
       
   135         case MsgBaseView::UNIEDITOR:
       
   136             {
       
   137             // except first 2 parameters pass other parameters
       
   138             QVariantList editorData;
       
   139             for(int a = 2; a < data.length(); ++a)
       
   140                 {
       
   141                 editorData << data.at(a);
       
   142                 }
       
   143             switchToUniEditor(editorData);
       
   144             break;
       
   145             }
       
   146 
       
   147         case MsgBaseView::MSGSETTINGS:
       
   148             {
       
   149             switchToMsgSettings(data);
       
   150             break;
       
   151             }
       
   152         default: 
       
   153             {
       
   154             HbApplication::quit();
       
   155             }
       
   156     }
       
   157     }
       
   158 
       
   159 //----------------------------------------------------------------------------
       
   160 // MsgServiceViewManager::send
       
   161 // @see header
       
   162 //----------------------------------------------------------------------------
       
   163 void MsgServiceViewManager::send(const QString phoneNumber, 
       
   164         const qint32 contactId, 
       
   165         const QString displayName)
       
   166     {
       
   167     ConvergedMessage message;
       
   168     ConvergedMessageAddress address;
       
   169     address.setAddress(phoneNumber);
       
   170     address.setAlias(displayName);
       
   171     message.addToRecipient(address);
       
   172 
       
   173     QVariantList param;
       
   174     QByteArray dataArray;
       
   175     QDataStream messageStream(&dataArray, 
       
   176             QIODevice::WriteOnly | QIODevice::Append);
       
   177     message.serialize(messageStream);
       
   178     param << dataArray;
       
   179     
       
   180     // switch to editor
       
   181     switchToUniEditor(param);
       
   182     
       
   183     XQServiceUtil::toBackground(false);
       
   184     }
       
   185 
       
   186 //----------------------------------------------------------------------------
       
   187 // MsgServiceViewManager::send
       
   188 // @see header
       
   189 //----------------------------------------------------------------------------
       
   190 void MsgServiceViewManager::send(const QString phoneNumber, 
       
   191         const QString alias, 
       
   192         const QString bodyText)
       
   193     {
       
   194     ConvergedMessage message;
       
   195     ConvergedMessageAddress address;
       
   196     address.setAddress(phoneNumber);
       
   197     address.setAlias(alias);
       
   198     message.addToRecipient(address);
       
   199     message.setBodyText(bodyText);
       
   200 
       
   201     QVariantList param;
       
   202     QByteArray dataArray;
       
   203     QDataStream messageStream(&dataArray, 
       
   204             QIODevice::WriteOnly | QIODevice::Append);
       
   205     message.serialize(messageStream);
       
   206     param << dataArray;
       
   207 
       
   208     // switch to editor
       
   209     switchToUniEditor(param);
       
   210     
       
   211     XQServiceUtil::toBackground(false);
       
   212     }
       
   213 
       
   214 //----------------------------------------------------------------------------
       
   215 // MsgServiceViewManager::send
       
   216 // @see header
       
   217 //----------------------------------------------------------------------------
       
   218 void MsgServiceViewManager::send(QVariant data)
       
   219     {
       
   220     ConvergedMessage message;
       
   221     ConvergedMessageAttachmentList attachmentList;
       
   222     // handle multiple files from sendUI
       
   223     // e.g. contacts can send multiple vcards
       
   224     QStringList receivedFiles = data.toStringList();
       
   225     int recFileCount = receivedFiles.count();
       
   226     for (int i = 0; i < recFileCount; i++) {
       
   227     ConvergedMessageAttachment *attachment =
       
   228     new ConvergedMessageAttachment(receivedFiles.at(i));
       
   229     attachmentList.append(attachment);
       
   230     }
       
   231     message.addAttachments(attachmentList);
       
   232 
       
   233     QVariantList param;
       
   234     QByteArray dataArray;
       
   235     QDataStream messageStream(&dataArray, 
       
   236             QIODevice::WriteOnly | QIODevice::Append);
       
   237     message.serialize(messageStream);
       
   238     param << dataArray;
       
   239 
       
   240     // switch to editor
       
   241     switchToUniEditor(param);
       
   242     
       
   243     XQServiceUtil::toBackground(false);
       
   244     }
       
   245 
       
   246 //----------------------------------------------------------------------------
       
   247 // MsgServiceViewManager::switchToUniEditor
       
   248 // @see header
       
   249 //----------------------------------------------------------------------------
       
   250 void MsgServiceViewManager::switchToUniEditor(const QVariantList& editorData)
       
   251     {
       
   252     // construct
       
   253     if (!mUniEditor) {
       
   254     mUniEditor = new MsgUnifiedEditorView();
       
   255     mMainWindow->addView(mUniEditor);
       
   256     mUniEditor->setNavigationAction(mBackAction);
       
   257     connect(mUniEditor, SIGNAL(switchView(const QVariantList&)), this,
       
   258             SLOT(switchView(const QVariantList&)));
       
   259     // construct completion : viewReady() signal was not called when 
       
   260     // editor is constructed first time.
       
   261    // mUniEditor->doDelayedConstruction();
       
   262     }
       
   263     
       
   264     // populate
       
   265     mUniEditor->populateContent(editorData);
       
   266     
       
   267     // set current view as editor
       
   268     mMainWindow->setCurrentView(mUniEditor);
       
   269     mCurrentView = MsgBaseView::UNIEDITOR;
       
   270     }
       
   271 
       
   272 //----------------------------------------------------------------------------
       
   273 // MsgServiceViewManager::switchToMsgSettings
       
   274 // @see header
       
   275 //----------------------------------------------------------------------------
       
   276 void MsgServiceViewManager::switchToMsgSettings(const QVariantList& data)
       
   277     {
       
   278     MsgSettingsView::SettingsView view = MsgSettingsView::DefaultView;
       
   279     
       
   280     if (mCurrentView == MsgBaseView::UNIEDITOR)
       
   281     {
       
   282         view = (MsgSettingsView::SettingsView)data.at(2).toInt();
       
   283     }
       
   284     
       
   285     mCurrentView = MsgBaseView::MSGSETTINGS;
       
   286 
       
   287     if (!mSettingsView) {        
       
   288     mSettingsView = new MsgSettingsView(view);
       
   289     mSettingsView->setNavigationAction(mBackAction);
       
   290     mMainWindow->addView(mSettingsView);
       
   291     }
       
   292     mMainWindow->setCurrentView(mSettingsView);
       
   293     }
       
   294 
       
   295 //----------------------------------------------------------------------------
       
   296 // MsgServiceViewManager::view
       
   297 // @see header
       
   298 //----------------------------------------------------------------------------
       
   299 void MsgServiceViewManager::view(int msgId)
       
   300     {
       
   301     int msgType;
       
   302     int msgSubType;
       
   303    
       
   304     mMessageId = msgId;
       
   305     // Mark as read and get message type
       
   306     mStoreHandler->markAsReadAndGetType(msgId,msgType,msgSubType);
       
   307     
       
   308     switch (msgType) {
       
   309         case ConvergedMessage::Sms:
       
   310         case ConvergedMessage::Mms:
       
   311         case ConvergedMessage::MmsNotification:
       
   312             {
       
   313             handleSmsMmsMsg(msgId);
       
   314             break;
       
   315             }
       
   316         case ConvergedMessage::BioMsg:
       
   317             {
       
   318             if (msgSubType == ConvergedMessage::RingingTone) {
       
   319             handleRingtoneMsg(msgId);
       
   320             }
       
   321             else if (msgSubType == ConvergedMessage::Provisioning) {
       
   322             handleProvisoningMsg(msgId);
       
   323             }
       
   324             break;
       
   325             }
       
   326         case ConvergedMessage::BT:
       
   327             {
       
   328             handleBTMessage(msgId);
       
   329             break;
       
   330             }
       
   331         default:
       
   332             {
       
   333             // for un supported message show delete option
       
   334             HbMessageBox::question(LOC_DELETE_MESSAGE, 
       
   335                 this,SLOT(onDialogDeleteMsg(HbAction*)),    
       
   336                 LOC_BUTTON_DELETE,
       
   337                 LOC_BUTTON_CANCEL);
       
   338             break;
       
   339             }
       
   340     }
       
   341     }
       
   342 
       
   343 // ----------------------------------------------------------------------------
       
   344 // MsgServiceViewManager::handleSmsMmsMsg
       
   345 // @see header
       
   346 // ----------------------------------------------------------------------------
       
   347 void MsgServiceViewManager::handleSmsMmsMsg(int msgId)
       
   348     {
       
   349     if (!mUniViewer) {
       
   350     mUniViewer = new UnifiedViewer(msgId);
       
   351     mUniViewer->setNavigationAction(mBackAction);
       
   352     mMainWindow->addView(mUniViewer);
       
   353     connect(mUniViewer, SIGNAL(switchView(const QVariantList&)), this,
       
   354             SLOT(switchView(const QVariantList&)));
       
   355     }
       
   356     mUniViewer->populateContent(msgId, true, 1);
       
   357 
       
   358     mMainWindow->setCurrentView(mUniViewer);
       
   359     
       
   360     // set current view as viewer
       
   361     mCurrentView = MsgBaseView::UNIVIEWER;
       
   362     }
       
   363 
       
   364 // ----------------------------------------------------------------------------
       
   365 // MsgServiceViewManager::handleRingtoneMsg
       
   366 // @see header
       
   367 // ----------------------------------------------------------------------------
       
   368 void MsgServiceViewManager::handleRingtoneMsg(int msgId)
       
   369     {
       
   370     mMessageId = msgId;
       
   371     HbMessageBox::question(LOC_DLG_SAVE_RINGTONE, this,
       
   372         SLOT(onDialogSaveTone(HbAction*)), LOC_BUTTON_SAVE, LOC_BUTTON_CANCEL);
       
   373     }
       
   374 
       
   375 // ----------------------------------------------------------------------------
       
   376 // MsgServiceViewManager::handleProvisoningMsg
       
   377 // @see header
       
   378 // ----------------------------------------------------------------------------
       
   379 void MsgServiceViewManager::handleProvisoningMsg(int msgId)
       
   380     {
       
   381     QString messageId;
       
   382     messageId.setNum(msgId);
       
   383 
       
   384     XQApplicationManager* aiwMgr = new XQApplicationManager();
       
   385 
       
   386     XQAiwRequest* request = aiwMgr->create("com.nokia.services.MDM", 
       
   387             "Provisioning",
       
   388             "ProcessMessage(QString)", true); // embedded
       
   389 
       
   390     if (request) {
       
   391     QList<QVariant> args;
       
   392     args << QVariant(messageId);
       
   393     request->setArguments(args);
       
   394 
       
   395     // Send the request
       
   396     bool res = request->send();
       
   397 
       
   398     // Cleanup
       
   399     delete request;
       
   400     }
       
   401 
       
   402     delete aiwMgr;
       
   403 
       
   404     // close the application once its handled
       
   405     HbApplication::quit();
       
   406     }
       
   407 
       
   408 //-----------------------------------------------------------------------------
       
   409 //MsgServiceViewManager::handleBTMessage()
       
   410 //@see header
       
   411 //-----------------------------------------------------------------------------
       
   412 void MsgServiceViewManager::handleBTMessage(int msgId)
       
   413     {
       
   414     XQApplicationManager* aiwMgr = new XQApplicationManager();
       
   415     XQAiwRequest* request = 
       
   416     aiwMgr->create("com.nokia.services.btmsgdispservices", "displaymsg",
       
   417             "displaymsg(int)", true); // embedded
       
   418 
       
   419     if (request) {
       
   420     QList<QVariant> args;
       
   421     args << QVariant(msgId);
       
   422     request->setArguments(args);
       
   423 
       
   424     // Send the request
       
   425     bool res = request->send();
       
   426 
       
   427     // Cleanup
       
   428     delete request;
       
   429     }
       
   430 
       
   431     delete aiwMgr;
       
   432 
       
   433     // close the application once its handled
       
   434     HbApplication::quit();
       
   435     }
       
   436 
       
   437 //-----------------------------------------------------------------------------
       
   438 //MsgServiceViewManager::onDialogDeleteMsg()
       
   439 //@see header
       
   440 //-----------------------------------------------------------------------------
       
   441 void MsgServiceViewManager::onDialogDeleteMsg(HbAction* action)
       
   442 {
       
   443     HbMessageBox *dlg = qobject_cast<HbMessageBox*> (sender());
       
   444     if (action == dlg->actions().at(0)) {
       
   445         mStoreHandler->deleteMessage(mMessageId);
       
   446     }
       
   447     HbApplication::quit(); // exit after handling
       
   448 }
       
   449 
       
   450 //-----------------------------------------------------------------------------
       
   451 //MsgServiceViewManager::onDialogSaveTone()
       
   452 //@see header
       
   453 //-----------------------------------------------------------------------------
       
   454 
       
   455 void MsgServiceViewManager::onDialogSaveTone(HbAction* action)
       
   456     {
       
   457         HbMessageBox *dlg = qobject_cast<HbMessageBox*> (sender());
       
   458         if (action == dlg->actions().at(0)) {
       
   459 
       
   460             UniDataModelLoader* pluginLoader = new UniDataModelLoader();
       
   461             UniDataModelPluginInterface* pluginInterface = pluginLoader->getDataModelPlugin(
       
   462                 ConvergedMessage::BioMsg);
       
   463             pluginInterface->setMessageId(mMessageId);
       
   464             UniMessageInfoList attachments = pluginInterface->attachmentList();
       
   465 
       
   466             QString attachmentPath = attachments.at(0)->path();
       
   467 
       
   468             RingBc* ringBc = new RingBc();
       
   469             ringBc->saveTone(attachmentPath);
       
   470 
       
   471             // clear attachement list : its allocated at data model
       
   472             while (!attachments.isEmpty()) {
       
   473                 delete attachments.takeFirst();
       
   474             }
       
   475 
       
   476             delete ringBc;
       
   477             delete pluginLoader;
       
   478         }
       
   479 
       
   480         // close the application once its handled
       
   481         HbApplication::quit();
       
   482 }
       
   483