messagingapp/msgui/msgapp/src/msgviewmanager.cpp
changeset 76 60a8a215b0ec
parent 62 fdbe8253b596
--- a/messagingapp/msgui/msgapp/src/msgviewmanager.cpp	Tue Oct 05 13:58:47 2010 +0530
+++ b/messagingapp/msgui/msgapp/src/msgviewmanager.cpp	Tue Oct 19 11:30:16 2010 +0530
@@ -27,6 +27,12 @@
 #include <xqappmgr.h>
 #include <hbmessagebox.h>
 #include <HbView>
+#include <tstasksettings.h>
+#include <hbinstance.h>
+#include <xqserviceutil.h>
+#include <apgtask.h>
+#include <eikenv.h>
+#include <afactivitystorage.h>
 
 #include "conversationsengine.h"
 #include "msglistview.h"
@@ -40,6 +46,7 @@
 #include "unidatamodelloader.h"
 #include "unidatamodelplugininterface.h"
 #include "msgcontacthandler.h"
+#include "msgactivityhandler.h"
 #include "debugtraces.h"
 
 // LOCALIZATION
@@ -47,11 +54,16 @@
 #define LOC_DIALOG_SAVE_RINGTONE hbTrId("txt_conversations_dialog_save_ringing_tone")
 
 const qint64 NULL_CONVERSATIONID = -1;
+const int INVALID_MSGID = -1;
 
-MsgViewManager::MsgViewManager(bool serviceRequest, HbMainWindow* mainWindow, QObject* parent,int activityMsgId) :
-    QObject(parent), mMainWindow(mainWindow), mUniEditor(0), mListView(0), mConversationView(0),
-        mUniViewer(0), mDraftsListView(0), mSettingsView(0), mBackAction(0),
-        mServiceRequest(serviceRequest), mConversationId(-1), mViewServiceRequest(false),mMessageId(-1)
+MsgViewManager::MsgViewManager(bool serviceRequest, HbMainWindow* mainWindow,
+    QObject* parent, int activityMsgId) :
+    QObject(parent), mMainWindow(mainWindow), mUniEditor(0), mListView(0),
+            mConversationView(0), mUniViewer(0), mDraftsListView(0),
+            mSettingsView(0), mBackAction(0), mActivityHandler(0), mClient(0),
+            mServiceRequest(serviceRequest), mConversationId(-1),
+            mViewServiceRequest(false), mMessageId(-1),
+            mBringtoForground(false)
 {
     //creating back action.
     mBackAction = new HbAction(Hb::BackNaviAction, this);
@@ -83,8 +95,6 @@
 
 MsgViewManager::~MsgViewManager()
 {
-    // TODO Auto-generated destructor stub
-    mEditorData.clear();
 }
 
 void MsgViewManager::onBackAction()
@@ -99,7 +109,7 @@
         }
 
         if (!mServiceRequest) {
-            HbApplication::quit();
+            handleSendToBackGround();
         }
         else {
             completeServiceRequest();
@@ -401,6 +411,10 @@
 {
     QVariantList param;
 
+    mClient->setVisibility(true);
+    mActivityHandler->clearActivities();
+    mBringtoForground = false;    
+    
     if (conversationId < 0) {
         param << MsgBaseView::CLV;
         param << MsgBaseView::SERVICE;
@@ -708,8 +722,7 @@
         }
 
         if (MsgBaseView::DLV == mPreviousView) {
-            //Populate editor after view ready indication 
-            populateUniEditorAfterViewReady(editorData);
+            mUniEditor->openDraftsMessage(editorData);
         }
         else {
             mUniEditor->populateContent(editorData);
@@ -990,37 +1003,6 @@
 }
 
 // ----------------------------------------------------------------------------
-// MsgViewManager::populateEditorAfterViewReady
-// @see header
-// ----------------------------------------------------------------------------
-void MsgViewManager::populateUniEditorAfterViewReady(const QVariantList& editorData)
-	{
-    QCRITICAL_WRITE("MsgViewManager::populateUniEditorAfterViewReady start.");
-	 //Save the editor data and use it in ViewReady handler
-	 mEditorData = editorData;	 
-	 connect(mMainWindow, SIGNAL(viewReady()), this, SLOT(populateUniEditorView()));
-	QCRITICAL_WRITE("MsgViewManager::populateUniEditorAfterViewReady end.");
-	}
-
-// ----------------------------------------------------------------------------
-// MsgViewManager::populateUniEditorView
-// @see header
-// ----------------------------------------------------------------------------
-void MsgViewManager::populateUniEditorView()
-    {
-    QCRITICAL_WRITE("MsgViewManager::populateUniEditorView start.");
-    if (mUniEditor)
-        {
-        mUniEditor->openDraftsMessage(mEditorData);
-        }
-    mEditorData.clear();
-    
-    disconnect(mMainWindow, SIGNAL(viewReady()), this,
-            SLOT(populateUniEditorView()));
-    QCRITICAL_WRITE("MsgViewManager::populateUniEditorView end.");
-}
-
-// ----------------------------------------------------------------------------
 // MsgViewManager::onDialogDeleteMsg
 // @see header
 // ----------------------------------------------------------------------------
@@ -1166,4 +1148,126 @@
         return localId;
     }
 
+// ----------------------------------------------------------------------------
+// MsgViewManager::handleSendToBackGround
+// @see header
+// ----------------------------------------------------------------------------
+void MsgViewManager::handleSendToBackGround()
+    {
+    if(mBringtoForground == false)
+        {
+        if (!mClient)
+            mClient = new TsTaskSettings;
+        mClient->setVisibility(false);
+
+
+        mServiceRequest = false;
+        mMainWindow->lower();
+
+        mActivityHandler->saveActivity();
+
+        mMainWindow->removeView(mListView);
+        delete mListView;
+        mListView = NULL;
+
+        if(mConversationView)
+            {
+            mMainWindow->removeView(mConversationView);
+            delete mConversationView;
+            mConversationView = NULL;
+            }
+        
+        if(mUniEditor)
+            {
+            mMainWindow->removeView(mUniEditor);
+            delete mUniEditor;
+            mUniEditor = NULL;
+            }
+
+        mBringtoForground = true;
+
+        TUid appUid = RProcess().SecureId();
+        TApaTaskList taskList(CEikonEnv::Static()->WsSession());
+        TApaTask task = taskList.FindApp(appUid);
+        if(task.Exists())
+            {
+            task.SendToBackground();
+            }
+        }
+    mPreviousView = MsgBaseView::DEFAULT;
+    mCurrentView = MsgBaseView::DEFAULT;      
+    }
+
+// ----------------------------------------------------------------------------
+// MsgViewManager::handleApplicationActive
+// @see header
+// ----------------------------------------------------------------------------
+void MsgViewManager::handleApplicationActive()
+    {
+    if(mBringtoForground)
+        {
+        mServiceRequest = false;
+        mClient->setVisibility(true);
+        mActivityHandler->clearActivities();
+
+        mBringtoForground = false;        
+
+        QVariantList param;
+        param << MsgBaseView::CLV;
+        param << MsgBaseView::CLV;
+        switchView(param);
+        }
+    }
+
+// ----------------------------------------------------------------------------
+// MsgViewManager::setActivityHandler
+// @see header
+// ----------------------------------------------------------------------------
+void MsgViewManager::setActivityHandler(MsgActivityHandler* activityHandler)
+    {
+    mActivityHandler = activityHandler;
+    connect(mActivityHandler, 
+        SIGNAL(activated(Af::ActivationReason, QString, QVariantHash)), 
+        this, 
+        SLOT(handleActivated(Af::ActivationReason, QString, QVariantHash)));
+    }
+
+// ----------------------------------------------------------------------------
+// MsgViewManager::handleActivated
+// @see header
+// ----------------------------------------------------------------------------
+void MsgViewManager::handleActivated(Af::ActivationReason reason, 
+        QString name, 
+        QVariantHash parameters)
+    {
+        Q_UNUSED(parameters)
+        mClient->setVisibility(true);
+        mBringtoForground = false;        
+        mServiceRequest = false;
+
+        if( reason == Af::ActivationReasonActivity)
+            {
+            QVariant data;
+            if(name == EditorActivityName)
+                {               
+                bool ok = QMetaObject::invokeMethod(
+                    mActivityHandler->activitiyStorage(),"activityData",
+                    Q_RETURN_ARG(QVariant,data),Q_ARG(QString,name));
+                }
+            int activityMsgId = mActivityHandler->parseActivityData(data);
+            if(activityMsgId == INVALID_MSGID)
+                {
+                QVariantList param;
+                param << MsgBaseView::CLV;
+                param << MsgBaseView::CLV;
+                switchView(param);
+                }
+            else 
+                {
+                openUniEditorActivity(activityMsgId);
+                }
+            }        
+        mActivityHandler->clearActivities();
+    }
+
 //EOF