messagingapp/msgui/conversationview/src/msgconversationbaseview.cpp
changeset 37 518b245aa84c
parent 25 84d9eb65b26f
child 38 4e4b6adb1024
--- a/messagingapp/msgui/conversationview/src/msgconversationbaseview.cpp	Mon May 03 12:29:07 2010 +0300
+++ b/messagingapp/msgui/conversationview/src/msgconversationbaseview.cpp	Fri Jun 25 15:47:40 2010 +0530
@@ -29,6 +29,8 @@
 #include <qtcontactsglobal.h>
 #include <qtcontacts.h>
 #include <ccsdefs.h>
+#include <XQSettingsManager>
+#include <QTimer>
 
 // USER INCLUDES
 #include "msgconversationview.h"
@@ -36,9 +38,13 @@
 #include "msgviewdefines.h"
 #include "conversationsenginedefines.h"
 #include "msgcontactcardwidget.h"
+#include "conversationidpsconsts.h"
 
 QTM_USE_NAMESPACE
 
+const int INVALID_MSGID = -1;
+const int INVALID_CONVID = -1;
+
 // LOCALIZATION
 #define LOC_SAVED_TO_DRAFTS    hbTrId("txt_messaging_dpopinfo_saved_to_drafts")
 
@@ -47,11 +53,10 @@
 // Constructor
 //---------------------------------------------------------------
 MsgConversationBaseView::MsgConversationBaseView(QGraphicsItem* parent) :
-MsgBaseView(parent),
-mConversationView(NULL),
-mConversationId(-1)
-{ 
-    connect(this->mainWindow(),SIGNAL(viewReady()),this,SLOT(doDelayedConstruction()));   
+    MsgBaseView(parent), mConversationId(-1), mCVIdkey(XQSettingsKey::TargetPublishAndSubscribe,
+        KMsgCVIdProperty, KMsgCVIdKey)
+{
+    connect(this->mainWindow(), SIGNAL(viewReady()), this, SLOT(doDelayedConstruction()));
     initView();
 }
 
@@ -60,7 +65,7 @@
 // Destructor
 //---------------------------------------------------------------
 MsgConversationBaseView::~MsgConversationBaseView()
-{   
+{
 }
 
 //---------------------------------------------------------------
@@ -71,12 +76,14 @@
 {
     ConversationsEngine::instance()->getConversations(convId);
     mConversationId = convId;
-    connect(this->mainWindow(),SIGNAL(viewReady()),this,SLOT(doDelayedConstruction()));
-    
-    if(mConversationView)
-        {
+    connect(this->mainWindow(), SIGNAL(viewReady()), this, SLOT(doDelayedConstruction()));
+
+    // publsih conversation id
+    mSettingsManager->writeItemValue(mCVIdkey, (int) mConversationId);
+
+    if (mConversationView) {
         mConversationView->refreshView();
-        }
+    }
 }
 
 //---------------------------------------------------------------
@@ -84,8 +91,8 @@
 // create and initialise the conversationview
 //---------------------------------------------------------------
 void MsgConversationBaseView::initView()
-    {
-    
+{
+
     // Create header widget
     mContactCard = new MsgContactCardWidget(this);
 
@@ -93,10 +100,11 @@
 
     qreal spacing = HbDeviceProfile::profile(this).unitValue();
     mMainLayout->setSpacing(spacing);
-    mMainLayout->setContentsMargins(CONTENT_MARGIN, CONTENT_MARGIN,
-                                   CONTENT_MARGIN, CONTENT_MARGIN);
+    mMainLayout->setContentsMargins(CONTENT_MARGIN, CONTENT_MARGIN, CONTENT_MARGIN, CONTENT_MARGIN);
 
     mMainLayout->addItem(mContactCard);
+    connect(mContactCard, SIGNAL(conversationIdChanged(qint64)), this,
+        SLOT(handleConversationIdChange(qint64)));
 
     /**
      * Create conversation view and connect to proper signals.
@@ -107,16 +115,15 @@
 
     mConversationView->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
 
-    connect(mConversationView, SIGNAL(closeConversationView()),
-            this, SLOT(closeConversationView()));
+    connect(mConversationView, SIGNAL(closeConversationView()), this, SLOT(closeConversationView()));
+
+    connect(mConversationView, SIGNAL(replyStarted()), this, SLOT(markMessagesAsRead()));
 
-    connect(mConversationView,SIGNAL(replyStarted()),
-            this,SLOT(markMessagesAsRead()));
+    connect(mConversationView, SIGNAL(switchView(const QVariantList&)), this,
+        SIGNAL(switchView(const QVariantList&)));
 
-    connect(mConversationView, SIGNAL(switchView(const QVariantList&)),
-            this, SIGNAL(switchView(const QVariantList&)));
-    
-    connect(mConversationView,SIGNAL(hideChrome(bool)),this,SLOT(hideChrome(bool)));
+    connect(mConversationView, SIGNAL(vkbOpened(bool)), this, SLOT(hideChrome(bool)));
+    connect(mConversationView, SIGNAL(vkbOpened(bool)), mContactCard, SLOT(ignoreSignals(bool)));
 
     this->setMenu(mConversationView->menu());
 
@@ -124,6 +131,8 @@
 
     this->setLayout(mMainLayout);
 
+    mSettingsManager = new XQSettingsManager(this);
+
 }
 
 //---------------------------------------------------------------
@@ -132,7 +141,7 @@
 //---------------------------------------------------------------
 void MsgConversationBaseView::closeConversationView()
 {
-   markMessagesAsRead();
+    markMessagesAsRead();
 }
 
 //---------------------------------------------------------------
@@ -140,30 +149,38 @@
 // Mark unread msgs in cv as read
 //---------------------------------------------------------------
 void MsgConversationBaseView::markMessagesAsRead()
-    {
-    if( mConversationId >= 0)
-        {
+{
+    if (mConversationId >= 0) {
         ConversationsEngine::instance()->markConversationRead(mConversationId);
-        }
     }
+}
 
 //---------------------------------------------------------------
 // MsgConversationBaseView::saveContentToDrafts
 // saves the editors content to drafts
 //---------------------------------------------------------------
-void MsgConversationBaseView::saveContentToDrafts()
-    {
+int MsgConversationBaseView::saveContentToDrafts()
+{
+    int msgId = INVALID_MSGID;
     bool result = false;
-    if( mConversationId >= 0)
-        {
-        result = mConversationView->saveContentToDrafts();
-        }
-    
-    if(result)
-        {
+    if (mConversationId >= 0) {
+    msgId = mConversationView->saveContentToDrafts();
+    }
+
+    if (msgId != INVALID_MSGID) {
         HbNotificationDialog::launchDialog(LOC_SAVED_TO_DRAFTS);
-        }
     }
+    return msgId;
+}
+
+//--------------------------------------------------------------- 
+// MsgConversationBaseView::conversationId 
+// get the conversation ID 
+//---------------------------------------------------------------     
+qint64 MsgConversationBaseView::conversationId()
+{
+    return mConversationId;
+}
 
 //---------------------------------------------------------------
 // MsgConversationBaseView::clearContent
@@ -180,19 +197,19 @@
 //
 //---------------------------------------------------------------
 void MsgConversationBaseView::handleOk(const QVariant& result)
-    {
+{
     Q_UNUSED(result)
-    }
+}
 
 //---------------------------------------------------------------
 // MsgConversationBaseView::handleError
 //
 //---------------------------------------------------------------
 void MsgConversationBaseView::handleError(int errorCode, const QString& errorMessage)
-    {
+{
     Q_UNUSED(errorMessage)
     Q_UNUSED(errorCode)
-    }
+}
 
 //---------------------------------------------------------------
 // MsgConversationBaseView::doDelayedConstruction
@@ -200,38 +217,70 @@
 //---------------------------------------------------------------	
 void MsgConversationBaseView::doDelayedConstruction()
 {
-    disconnect(this->mainWindow(),SIGNAL(viewReady()),this,SLOT(doDelayedConstruction()));
+    disconnect(this->mainWindow(), SIGNAL(viewReady()), this, SLOT(doDelayedConstruction()));
+    QTimer::singleShot(50, this, SLOT(handleViewReady()));
+}
+
+//---------------------------------------------------------------
+// MsgConversationBaseView::handleViewReady
+//
+//---------------------------------------------------------------	
+void MsgConversationBaseView::handleViewReady()
+{
     ConversationsEngine::instance()->fetchMoreConversations();
 }
 
 //---------------------------------------------------------------
+// MsgConversationBaseView::handleConversationIdChange
+//
+//---------------------------------------------------------------
+void MsgConversationBaseView::handleConversationIdChange(qint64 convId)
+{
+    if (INVALID_CONVID != convId && mConversationId != convId) {
+	
+        mConversationId = convId;        
+        // publsih conversation id
+        mSettingsManager->writeItemValue(mCVIdkey, (int) mConversationId);       
+    }
+}
+
+//---------------------------------------------------------------
 // MsgConversationBaseView::hideChrome
 //
 //---------------------------------------------------------------
 void MsgConversationBaseView::hideChrome(bool hide)
-    {
-    if(hide)
-        {        
+{
+    if (hide) {
         this->hideItems(Hb::StatusBarItem | Hb::TitleBarItem);
         this->setContentFullScreen(true);
-        
-        if(this->mainWindow()->orientation() == Qt::Horizontal)
-            {
+
+        if (this->mainWindow()->orientation() == Qt::Horizontal) {
             mMainLayout->removeItem(mContactCard);
             mContactCard->hide();
-            }
         }
-    else
-        {
+    }
+    else {
         this->showItems(Hb::StatusBarItem | Hb::TitleBarItem);
         this->setContentFullScreen(false);
-        
-        if(!mContactCard->isVisible())
-            {
-            mMainLayout->insertItem(0,mContactCard);
+
+        if (!mContactCard->isVisible()) {
+            mMainLayout->insertItem(0, mContactCard);
             mContactCard->show();
-            }
         }
     }
+}
 
+//---------------------------------------------------------------
+// MsgConversationBaseView::setPSCVId
+//
+//---------------------------------------------------------------
+void MsgConversationBaseView::setPSCVId(bool setId)
+{
+    if (setId) {
+        mSettingsManager->writeItemValue(mCVIdkey, (int) mConversationId);
+    }
+    else {
+        mSettingsManager->writeItemValue(mCVIdkey, -1);
+    }
+}
 // EOF