messagingapp/msgui/conversationview/src/msgconversationbaseview.cpp
branchRCL_3
changeset 57 ebe688cedc25
equal deleted inserted replaced
54:fa1df4b99609 57:ebe688cedc25
       
     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:Conversation Base view.
       
    15  *
       
    16  */
       
    17 
       
    18 #include "msgconversationbaseview.h"
       
    19 
       
    20 // SYSTEM INCLUDES
       
    21 #include <QGraphicsLinearLayout>
       
    22 #include <HbMainWindow>
       
    23 #include <HbDeviceNotificationDialog>
       
    24 
       
    25 #include <xqaiwrequest.h>
       
    26 #include <xqappmgr.h>
       
    27 
       
    28 #include <cntservicescontact.h>
       
    29 #include <qtcontactsglobal.h>
       
    30 #include <qtcontacts.h>
       
    31 #include <ccsdefs.h>
       
    32 #include <XQSettingsManager>
       
    33 #include <QTimer>
       
    34 
       
    35 // USER INCLUDES
       
    36 #include "msgconversationview.h"
       
    37 #include "conversationsengine.h"
       
    38 #include "msgviewdefines.h"
       
    39 #include "conversationsenginedefines.h"
       
    40 #include "msgcontactcardwidget.h"
       
    41 #include "conversationidpsconsts.h"
       
    42 
       
    43 QTM_USE_NAMESPACE
       
    44 
       
    45 const int INVALID_MSGID = -1;
       
    46 const int INVALID_CONVID = -1;
       
    47 
       
    48 // LOCALIZATION
       
    49 #define LOC_SAVED_TO_DRAFTS    hbTrId("txt_messaging_dpopinfo_saved_to_drafts")
       
    50 
       
    51 //---------------------------------------------------------------
       
    52 // MsgConversationBaseView::MsgConversationBaseView
       
    53 // Constructor
       
    54 //---------------------------------------------------------------
       
    55 MsgConversationBaseView::MsgConversationBaseView(QGraphicsItem* parent) :
       
    56     MsgBaseView(parent), mConversationId(-1), mCVIdkey(XQSettingsKey::TargetPublishAndSubscribe,
       
    57         KMsgCVIdProperty, KMsgCVIdKey)
       
    58 {
       
    59     connect(this->mainWindow(), SIGNAL(viewReady()), this, SLOT(doDelayedConstruction()));
       
    60     initView();
       
    61 }
       
    62 
       
    63 //---------------------------------------------------------------
       
    64 // MsgConversationBaseView::~MsgConversationBaseView
       
    65 // Destructor
       
    66 //---------------------------------------------------------------
       
    67 MsgConversationBaseView::~MsgConversationBaseView()
       
    68 {
       
    69 }
       
    70 
       
    71 //---------------------------------------------------------------
       
    72 // MsgConversationBaseView::openConversationView
       
    73 // Launches conversation view for entry id and mode
       
    74 //---------------------------------------------------------------
       
    75 void MsgConversationBaseView::openConversation(qint64 convId)
       
    76 {
       
    77     ConversationsEngine::instance()->getConversations(convId);
       
    78     mConversationId = convId;
       
    79     connect(this->mainWindow(), SIGNAL(viewReady()), this, SLOT(doDelayedConstruction()));
       
    80 
       
    81     // publsih conversation id
       
    82     mSettingsManager->writeItemValue(mCVIdkey, (int) mConversationId);
       
    83 
       
    84     if (mConversationView) {
       
    85         mConversationView->refreshView();
       
    86     }
       
    87 }
       
    88 
       
    89 //---------------------------------------------------------------
       
    90 // MsgConversationBaseView::initView
       
    91 // create and initialise the conversationview
       
    92 //---------------------------------------------------------------
       
    93 void MsgConversationBaseView::initView()
       
    94 {
       
    95 
       
    96     // Create header widget
       
    97     mContactCard = new MsgContactCardWidget(this);
       
    98 
       
    99     mMainLayout = new QGraphicsLinearLayout(Qt::Vertical);
       
   100 
       
   101     qreal spacing = HbDeviceProfile::profile(this).unitValue();
       
   102     mMainLayout->setSpacing(spacing);
       
   103     mMainLayout->setContentsMargins(CONTENT_MARGIN, CONTENT_MARGIN, CONTENT_MARGIN, CONTENT_MARGIN);
       
   104 
       
   105     mMainLayout->addItem(mContactCard);
       
   106     connect(mContactCard, SIGNAL(conversationIdChanged(qint64)), this,
       
   107         SLOT(handleConversationIdChange(qint64)));
       
   108 
       
   109     /**
       
   110      * Create conversation view and connect to proper signals.
       
   111      * NOTE: contactCardWidget is NOT parent of MsgConversationView.
       
   112      * Just passing reference to MsgConversationView.
       
   113      */
       
   114     mConversationView = new MsgConversationView(mContactCard);
       
   115 
       
   116     mConversationView->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
       
   117 
       
   118     connect(mConversationView, SIGNAL(closeConversationView()), this, SLOT(closeConversationView()));
       
   119 
       
   120     connect(mConversationView, SIGNAL(replyStarted()), this, SLOT(markMessagesAsRead()));
       
   121 
       
   122     connect(mConversationView, SIGNAL(switchView(const QVariantList&)), this,
       
   123         SIGNAL(switchView(const QVariantList&)));
       
   124 
       
   125     connect(mConversationView, SIGNAL(vkbOpened(bool)), this, SLOT(hideChrome(bool)));
       
   126 
       
   127     this->setMenu(mConversationView->menu());
       
   128 
       
   129     mMainLayout->addItem(mConversationView);
       
   130 
       
   131     this->setLayout(mMainLayout);
       
   132 
       
   133     mSettingsManager = new XQSettingsManager(this);
       
   134 
       
   135 }
       
   136 
       
   137 //---------------------------------------------------------------
       
   138 // MsgConversationBaseView::closeConversationView
       
   139 // close conversation view
       
   140 //---------------------------------------------------------------
       
   141 void MsgConversationBaseView::closeConversationView()
       
   142 {
       
   143     markMessagesAsRead();
       
   144 }
       
   145 
       
   146 //---------------------------------------------------------------
       
   147 // MsgConversationBaseView::markMessagesAsRead
       
   148 // Mark unread msgs in cv as read
       
   149 //---------------------------------------------------------------
       
   150 void MsgConversationBaseView::markMessagesAsRead()
       
   151 {
       
   152     if (mConversationId >= 0) {
       
   153         ConversationsEngine::instance()->markConversationRead(mConversationId);
       
   154     }
       
   155 }
       
   156 
       
   157 //---------------------------------------------------------------
       
   158 // MsgConversationBaseView::saveContentToDrafts
       
   159 // saves the editors content to drafts
       
   160 //---------------------------------------------------------------
       
   161 int MsgConversationBaseView::saveContentToDrafts()
       
   162 {
       
   163     int msgId = INVALID_MSGID;
       
   164     if (mConversationId >= 0) {
       
   165     msgId = mConversationView->saveContentToDrafts();
       
   166     }
       
   167 
       
   168     if (msgId != INVALID_MSGID) {
       
   169         HbDeviceNotificationDialog::notification("", LOC_SAVED_TO_DRAFTS);
       
   170     }
       
   171     return msgId;
       
   172 }
       
   173 
       
   174 //--------------------------------------------------------------- 
       
   175 // MsgConversationBaseView::conversationId 
       
   176 // get the conversation ID 
       
   177 //---------------------------------------------------------------     
       
   178 qint64 MsgConversationBaseView::conversationId()
       
   179 {
       
   180     return mConversationId;
       
   181 }
       
   182 
       
   183 //---------------------------------------------------------------
       
   184 // MsgConversationBaseView::clearContent
       
   185 // clears conversation view content
       
   186 //---------------------------------------------------------------
       
   187 void MsgConversationBaseView::clearContent()
       
   188 {
       
   189     ConversationsEngine::instance()->clearConversations();
       
   190     mConversationView->clearEditors();
       
   191 }
       
   192 
       
   193 //---------------------------------------------------------------
       
   194 // MsgConversationBaseView::handleOk
       
   195 //
       
   196 //---------------------------------------------------------------
       
   197 void MsgConversationBaseView::handleOk(const QVariant& result)
       
   198 {
       
   199     Q_UNUSED(result)
       
   200 }
       
   201 
       
   202 //---------------------------------------------------------------
       
   203 // MsgConversationBaseView::handleError
       
   204 //
       
   205 //---------------------------------------------------------------
       
   206 void MsgConversationBaseView::handleError(int errorCode, const QString& errorMessage)
       
   207 {
       
   208     Q_UNUSED(errorMessage)
       
   209     Q_UNUSED(errorCode)
       
   210 }
       
   211 
       
   212 //---------------------------------------------------------------
       
   213 // MsgConversationBaseView::doDelayedConstruction
       
   214 //
       
   215 //---------------------------------------------------------------	
       
   216 void MsgConversationBaseView::doDelayedConstruction()
       
   217 {
       
   218     disconnect(this->mainWindow(), SIGNAL(viewReady()), this, SLOT(doDelayedConstruction()));
       
   219     QTimer::singleShot(50, this, SLOT(handleViewReady()));
       
   220 }
       
   221 
       
   222 //---------------------------------------------------------------
       
   223 // MsgConversationBaseView::handleViewReady
       
   224 //
       
   225 //---------------------------------------------------------------	
       
   226 void MsgConversationBaseView::handleViewReady()
       
   227 {
       
   228     mConversationView->onViewReady();
       
   229 }
       
   230 
       
   231 //---------------------------------------------------------------
       
   232 // MsgConversationBaseView::handleConversationIdChange
       
   233 //
       
   234 //---------------------------------------------------------------
       
   235 void MsgConversationBaseView::handleConversationIdChange(qint64 convId)
       
   236 {
       
   237     if (INVALID_CONVID != convId && mConversationId != convId) {
       
   238 	
       
   239         mConversationId = convId;        
       
   240         // publsih conversation id
       
   241         mSettingsManager->writeItemValue(mCVIdkey, (int) mConversationId);       
       
   242     }
       
   243 }
       
   244 
       
   245 //---------------------------------------------------------------
       
   246 // MsgConversationBaseView::hideChrome
       
   247 //
       
   248 //---------------------------------------------------------------
       
   249 void MsgConversationBaseView::hideChrome(bool hide)
       
   250 {
       
   251     if (hide) {
       
   252         this->hideItems(Hb::StatusBarItem | Hb::TitleBarItem);
       
   253         this->setContentFullScreen(true);
       
   254 
       
   255         if (this->mainWindow()->orientation() == Qt::Horizontal) {
       
   256             mMainLayout->removeItem(mContactCard);
       
   257             mContactCard->hide();
       
   258         }
       
   259     }
       
   260     else {
       
   261         this->showItems(Hb::StatusBarItem | Hb::TitleBarItem);
       
   262         this->setContentFullScreen(false);
       
   263 
       
   264         if (!mContactCard->isVisible()) {
       
   265             mMainLayout->insertItem(0, mContactCard);
       
   266             mContactCard->show();
       
   267         }
       
   268     }
       
   269     
       
   270     //forcing relayouting
       
   271     mMainLayout->activate();
       
   272 }
       
   273 
       
   274 //---------------------------------------------------------------
       
   275 // MsgConversationBaseView::setPSCVId
       
   276 //
       
   277 //---------------------------------------------------------------
       
   278 void MsgConversationBaseView::setPSCVId(bool setId)
       
   279 {
       
   280     if (setId) {
       
   281         mSettingsManager->writeItemValue(mCVIdkey, (int) mConversationId);
       
   282     }
       
   283     else {
       
   284         mSettingsManager->writeItemValue(mCVIdkey, -1);
       
   285     }
       
   286 }
       
   287 // EOF