messagingapp/msgui/conversationview/src/msgconversationbaseview.cpp
changeset 23 238255e8b033
child 25 84d9eb65b26f
equal deleted inserted replaced
5:4697dfb2d7ad 23:238255e8b033
       
     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 #include "msguiutilsmanager.h"
       
    20 
       
    21 // SYSTEM INCLUDES
       
    22 #include <QSqlDatabase>
       
    23 #include <QSqlQuery>
       
    24 #include <QSqlError>
       
    25 #include <QtDebug>
       
    26 #include <QGraphicsLinearLayout>
       
    27 
       
    28 // USER INCLUDES
       
    29 #include "msgconversationview.h"
       
    30 //#include "convergedmessage.h"
       
    31 #include "conversationsengine.h"
       
    32 #include "msgviewdefines.h"
       
    33 #include "conversationsenginedefines.h"
       
    34 #include "msgcontactcardwidget.h"
       
    35 
       
    36 //---------------------------------------------------------------
       
    37 // MsgConversationBaseView::MsgConversationBaseView
       
    38 // Constructor
       
    39 //---------------------------------------------------------------
       
    40 MsgConversationBaseView::MsgConversationBaseView(QGraphicsItem* parent) :
       
    41 MsgBaseView(parent),
       
    42 mConversationView(NULL),
       
    43 mConversationId(-1)
       
    44 {   
       
    45     initView();
       
    46 }
       
    47 
       
    48 //---------------------------------------------------------------
       
    49 // MsgConversationBaseView::~MsgConversationBaseView
       
    50 // Destructor
       
    51 //---------------------------------------------------------------
       
    52 MsgConversationBaseView::~MsgConversationBaseView()
       
    53 {   
       
    54 }
       
    55 
       
    56 //---------------------------------------------------------------
       
    57 // MsgConversationBaseView::openConversationView
       
    58 // Launches conversation view for entry id and mode
       
    59 //---------------------------------------------------------------
       
    60 void MsgConversationBaseView::openConversation(qint64 convId)
       
    61 {
       
    62     ConversationsEngine::instance()->getConversations(convId);    
       
    63     mConversationId = convId;
       
    64     mConversationView->refreshView();
       
    65 }
       
    66 
       
    67 //---------------------------------------------------------------
       
    68 // MsgConversationBaseView::initView
       
    69 // create and initialise the conversationview
       
    70 //---------------------------------------------------------------
       
    71 void MsgConversationBaseView::initView()
       
    72     {
       
    73     // Create header widget
       
    74     MsgContactCardWidget *contactCardWidget = new MsgContactCardWidget();
       
    75 
       
    76     connect(contactCardWidget, SIGNAL(clicked()), this, SLOT(openContactDetails()));
       
    77 
       
    78     QGraphicsLinearLayout *mainLayout = new QGraphicsLinearLayout(Qt::Vertical);
       
    79 
       
    80     mainLayout->setContentsMargins(CONTENT_MARGIN, CONTENT_MARGIN,
       
    81                                    CONTENT_MARGIN, CONTENT_MARGIN);
       
    82 
       
    83     mainLayout->setSpacing(CONTENT_SPACING);
       
    84 
       
    85     mainLayout->addItem(contactCardWidget);
       
    86 
       
    87     /**
       
    88      * Create conversation view and connect to proper signals.
       
    89      * NOTE: contactCardWidget is NOT parent of MsgConversationView.
       
    90      * Just passing reference to MsgConversationView.
       
    91      */
       
    92     mConversationView = new MsgConversationView(contactCardWidget);
       
    93 
       
    94     connect(mConversationView, SIGNAL(closeConversationView()),
       
    95             this, SLOT(closeConversationView()));
       
    96 
       
    97     connect(mConversationView,SIGNAL(replyStarted()),
       
    98             this,SLOT(markMessagesAsRead()));
       
    99 
       
   100     connect(mConversationView, SIGNAL(switchView(const QVariantList&)),
       
   101             this, SIGNAL(switchView(const QVariantList&)));
       
   102 
       
   103     this->setMenu(mConversationView->menu());
       
   104 
       
   105     mainLayout->addItem(mConversationView);
       
   106 
       
   107     this->setLayout(mainLayout);
       
   108 
       
   109 }
       
   110 
       
   111 //---------------------------------------------------------------
       
   112 // MsgConversationBaseView::closeConversationView
       
   113 // close conversation view
       
   114 //---------------------------------------------------------------
       
   115 void MsgConversationBaseView::closeConversationView()
       
   116 {
       
   117    markMessagesAsRead();
       
   118 }
       
   119 
       
   120 //---------------------------------------------------------------
       
   121 // MsgConversationBaseView::markMessagesAsRead
       
   122 // Mark unread msgs in cv as read
       
   123 //---------------------------------------------------------------
       
   124 void MsgConversationBaseView::markMessagesAsRead()
       
   125     {
       
   126     if( mConversationId >= 0)
       
   127         {
       
   128         ConversationsEngine::instance()->markConversationRead(mConversationId);
       
   129         }
       
   130     }
       
   131 
       
   132 //---------------------------------------------------------------
       
   133 // MsgConversationBaseView::saveContentToDrafts
       
   134 // saves the editors content to drafts
       
   135 //---------------------------------------------------------------
       
   136 bool MsgConversationBaseView::saveContentToDrafts()
       
   137     {
       
   138     bool result = false;
       
   139     if( mConversationId >= 0)
       
   140         {
       
   141         result = mConversationView->saveContentToDrafts();
       
   142         }
       
   143     return result;
       
   144     }
       
   145 
       
   146 //---------------------------------------------------------------
       
   147 // MsgConversationBaseView::openContactDetails
       
   148 // close conversation view
       
   149 //---------------------------------------------------------------
       
   150 void MsgConversationBaseView::openContactDetails()
       
   151 {
       
   152     MsgUiUtilsManager uiUtilsManager(this);
       
   153     QModelIndex aIndex = ConversationsEngine::instance()->getConversationsModel()->index(0, 0);
       
   154     qint32 contactId = aIndex.data(ContactId).toLongLong();
       
   155     uiUtilsManager.openContactDetails(contactId);
       
   156 }
       
   157 
       
   158 //---------------------------------------------------------------
       
   159 // MsgConversationBaseView::clearContent
       
   160 // clears conversation view content
       
   161 //---------------------------------------------------------------
       
   162 void MsgConversationBaseView::clearContent()
       
   163 {
       
   164     ConversationsEngine::instance()->clearConversations();
       
   165     mConversationView->clearEditors();
       
   166 }
       
   167 // EOF