emailuis/nmhswidget/src/nmhswidgettitlerow.cpp
changeset 23 2dc6caa42ec3
parent 18 578830873419
child 30 759dc5235cdb
--- a/emailuis/nmhswidget/src/nmhswidgettitlerow.cpp	Mon May 03 12:23:15 2010 +0300
+++ b/emailuis/nmhswidget/src/nmhswidgettitlerow.cpp	Fri May 14 15:41:10 2010 +0300
@@ -16,97 +16,156 @@
  */
 
 #include <QDebug>
+#include <QtGui>
 #include <QGraphicsLinearLayout>
 #include <hbdocumentloader.h>
 #include <hblabel.h>
+#include <HbPushButton>
 #include "nmicons.h"
 #include "nmhswidgettitlerow.h"
 #include "nmhswidgetconsts.h"
 
-NmHsWidgetTitleRow::NmHsWidgetTitleRow(QGraphicsItem *parent, Qt::WindowFlags flags)
-    : HbWidget(parent, flags),
-      mMailboxIcon(0),
-      mMailboxInfo(0),
-      mAccountName(0),
-      mUnreadCount(0)
+NmHsWidgetTitleRow::NmHsWidgetTitleRow(QGraphicsItem *parent, Qt::WindowFlags flags) :
+    HbWidget(parent, flags), 
+    mMailboxIcon(0), 
+    mMailboxInfo(0), 
+    mUnreadCountLabel(0),
+    mCollapseExpIconLabel(0), 
+    mAccountName(0), 
+    mUnreadCount(0)
 {
     qDebug() << "NmHsWidgetTitleRow::NmHsWidgetTitleRow IN -->>";
-    
-    loadDocML();
-    
+
     qDebug() << "NmHsWidgetTitleRow::NmHsWidgetTitleRow OUT <<--";
 }
 
 /*!
-    Destructor
-*/
+ Destructor
+ */
 NmHsWidgetTitleRow::~NmHsWidgetTitleRow()
 {
     qDebug() << "NmHsWidgetTitleRow::~NmHsWidgetTitleRow IN -->>";
 
     qDebug() << "NmHsWidgetTitleRow::~NmHsWidgetTitleRow OUT <<--";
 }
-    
+
 /*!
-    Loads layout data and child items from docml file
-*/
-void NmHsWidgetTitleRow::loadDocML()
+ Loads layout data and child items from docml file. Must be called after constructor.
+ /return true if loading succeeded, otherwise false. False indicates that object is unusable
+ */
+bool NmHsWidgetTitleRow::loadDocML()
 {
-    qDebug() << "NmHsWidgetTitleRow::loadDocML IN -->>";
+    QT_TRY{
+        qDebug() << "NmHsWidgetTitleRow::loadDocML IN -->>";
     
-    QGraphicsLinearLayout *layout = new QGraphicsLinearLayout(Qt::Vertical);
-    layout->setContentsMargins(KNmHsWidgetContentsMargin, KNmHsWidgetContentsMargin,
+        // Use document loader to load the contents
+        HbDocumentLoader loader;
+        bool ok(false);
+        loader.load(KNmHsWidgetTitleRowDocML, &ok);
+        if (!ok) {
+            qDebug() << "NmHsWidgetTitleRow::loadDocML Fail @ loader -->>";
+            return false; //failure
+        }
+    
+        //Create layout
+        QGraphicsLinearLayout *layout = new QGraphicsLinearLayout(Qt::Vertical);
+    
+        layout->setContentsMargins(KNmHsWidgetContentsMargin, KNmHsWidgetContentsMargin,
             KNmHsWidgetContentsMargin, KNmHsWidgetContentsMargin);
-    layout->setSpacing(KNmHsWidgetContentsMargin);    
+        layout->setSpacing(KNmHsWidgetContentsMargin);
+        setLayout(layout); //pass the ownership
     
-    // Use document loader to load the contents
-    HbDocumentLoader loader;
-    bool ok = false;
-    loader.load( KNmHsWidgetTitleRowDocML, &ok);
-    Q_ASSERT_X(ok, "nmhswidget", "invalid title docml file");
+        // find container widget
+        QGraphicsWidget *container = loader.findWidget(KNmHsWidgetTitleRowContainer);
+        if (!container) {
+            qDebug() << "NmHsWidgetTitleRow::loadDocML Fail @ container -->>";
+            return false;
+        }
+        layout->addItem(container);
     
-    // find container widget
-    QGraphicsWidget *container = loader.findWidget(KNmHsWidgetTitleRowContainer);
-    Q_ASSERT_X((container != 0), "nmhswidget", "container not found!");
-    layout->addItem(container);
+        //child items possible to update
+        mMailboxIcon = static_cast<HbLabel*> (loader.findWidget(KNmHsWidgetTitleRowMailboxIcon));
+        mMailboxInfo = static_cast<HbLabel*> (loader.findWidget(KNmHsWidgetTitleRowMailboxNameLabel));
+        mUnreadCountLabel = static_cast<HbLabel*> (loader.findWidget(
+            KNmHsWidgetTitleRowUnreadCountLabel));
+        mCollapseExpIconLabel = static_cast<HbPushButton*> (loader.findWidget(
+            KNmHsWidgetTitleRowCollapseExpandIconLabel));
     
-    //child items possible to update
-    mMailboxIcon = static_cast<HbLabel*>(loader.findWidget(KNmHsWidgetTitleRowMailboxIcon));
-    mMailboxIcon->setIcon(NmIcons::getIcon(NmIcons::NmIconDefaultMailbox));
-    mMailboxInfo = static_cast<HbLabel*>(loader.findWidget(KNmHsWidgetTitleRowMailboxNameLabel));
-
-    setLayout(layout);
+        if (!mMailboxIcon || !mMailboxInfo || !mUnreadCountLabel || !mCollapseExpIconLabel) {
+            qDebug() << "NmHsWidgetTitleRow::loadDocML Fail @ icons & labels -->>";
+            return false;
+        }
     
-    qDebug() << "NmHsWidgetTitleRow::loadDocML OUT <<--";
+        //Expand collapse button
+        connect(mCollapseExpIconLabel, SIGNAL(clicked()), this, SIGNAL(expandCollapseButtonPressed()));
+    
+        qDebug() << "NmHsWidgetTitleRow::loadDocML OUT <<--";
+        return true;
+    }
+    QT_CATCH(...){
+        return false;
+    }
 }
 
 /*!
-    Slot for updating account name, calls updateData to update ui.
-*/
-void NmHsWidgetTitleRow::updateAccountName(const QString& accountName )
-    {
+ Slot for updating account name, calls updateData to update ui.
+ */
+void NmHsWidgetTitleRow::updateAccountName(const QString& accountName)
+{
+    qDebug() << "NmHsWidgetTitleRow::updateAccountName IN -->>";
     mAccountName = accountName;
     updateData();
-    }
+    qDebug() << "NmHsWidgetTitleRow::updateAccountName OUT <<--";
+}
 
 /*!
-    Slot for updating unread count, calls updateData to update ui.
-*/
-void NmHsWidgetTitleRow::updateUnreadCount(const int& unreadCount )
-    {
+ Set account icon name
+ */
+void NmHsWidgetTitleRow::setAccountIcon(const QString& accountIconName)
+{
+    qDebug() << "NmHsWidgetTitleRow::setAccountIcon -- accountIconName" << accountIconName;
+    mMailboxIcon->setIcon(accountIconName);
+    qDebug() << "NmHsWidgetTitleRow::setAccountIcon OUT <<--";
+}
+
+/*!
+ Slot for updating unread count, calls updateData to update ui.
+ */
+void NmHsWidgetTitleRow::updateUnreadCount(const int& unreadCount)
+{
+    qDebug() << "NmHsWidgetTitleRow::updateUnreadCount IN -->>";
     mUnreadCount = unreadCount;
     updateData();
-    }
+    qDebug() << "NmHsWidgetTitleRow::updateUnreadCount OUT <<--";
+}
 
 /*!
-    Update the data displayed in the UI
-*/
+ Update the data displayed in the UI
+ */
 void NmHsWidgetTitleRow::updateData()
-    {
-    //TODO: Sprint 3: use localization for displaying data
-    QString info = mAccountName;
-    info.append(" (");
-    info.append( QString::number(mUnreadCount));
-    info.append(")");
-    mMailboxInfo->setPlainText(info);
+{
+    qDebug() << "NmHsWidgetTitleRow::updateData() IN -->>";
+    mMailboxInfo->setPlainText(mAccountName);
+    //If unread count is -1, hide the unread count label completely.
+    //This indicates that there are no mails at all (or the initial sync is not done)
+    if (mUnreadCount != -1) {
+        QString unreadCount(hbTrId("txt_mail_widget_list_l1").arg(mUnreadCount));
+        mUnreadCountLabel->setPlainText(unreadCount);
+        mUnreadCountLabel->setVisible(true);
+    }
+    else {
+        mUnreadCountLabel->setVisible(false);
     }
+    qDebug() << "NmHsWidgetTitleRow::updateData() OUT <<--";
+}
+
+/*!
+ mousePressEvent(QGraphicsSceneMouseEvent *event)
+ */
+void NmHsWidgetTitleRow::mousePressEvent(QGraphicsSceneMouseEvent *event)
+{
+    qDebug() << "NmHsWidgetTitleRow::mousePressEvent() IN -->>";
+    Q_UNUSED(event); 
+	emit mailboxLaunchTriggered();
+    qDebug() << "NmHsWidgetTitleRow::mousePressEvent() OUT <<--";
+}