--- a/emailuis/nmhswidget/src/nmhswidget.cpp Fri Apr 16 14:51:52 2010 +0300
+++ b/emailuis/nmhswidget/src/nmhswidget.cpp Mon May 03 12:23:15 2010 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
+ * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
* All rights reserved.
* This component and the accompanying materials are made available
* under the terms of "Eclipse Public License v1.0"
@@ -18,6 +18,7 @@
#include <QtGui>
#include <QGraphicsLinearLayout>
#include <hbcolorscheme.h>
+#include "nmcommon.h"
#include "nmhswidget.h"
#include "nmhswidgetemailengine.h"
#include "nmmessageenvelope.h"
@@ -27,15 +28,15 @@
NmHsWidget::NmHsWidget(QGraphicsItem *parent, Qt::WindowFlags flags)
: HbWidget(parent, flags),
- mEngine( new NmHsWidgetEmailEngine() ),
+ mEngine(0),
mRowLayout(0),
- mTitleRow( new NmHsWidgetTitleRow() )
+ mTitleRow( new NmHsWidgetTitleRow() ),
+ mAccountId(0)
{
qDebug() << "NmHsWidget::NmHsWidget IN -->>";
-
+
this->setContentsMargins( KNmHsWidgetContentsMargin, KNmHsWidgetContentsMargin,
KNmHsWidgetContentsMargin, KNmHsWidgetContentsMargin);
-
//Setup layout
mRowLayout = new QGraphicsLinearLayout(Qt::Vertical);
mRowLayout->setContentsMargins(KNmHsWidgetContentsMargin, KNmHsWidgetContentsMargin,
@@ -44,23 +45,6 @@
mRowLayout->addItem(mTitleRow);
setLayout(mRowLayout);
- //Do the initial data setting
- updateAccountName( mEngine->accountName() );
- updateMailData();
- updateUnreadCount( mEngine->unreadCount() );
-
- //Get signals about changes in mail data
- connect(mEngine, SIGNAL( mailDataChanged() )
- ,this, SLOT( updateMailData() ) );
-
- //Get Signals about changes in unread count
- connect(mEngine, SIGNAL( unreadCountChanged(const int&) )
- ,this, SLOT( updateUnreadCount(const int&) ) );
-
- //Get signals about account name changes
- connect(mEngine, SIGNAL( accountNameChanged(const QString&) )
- ,this, SLOT( updateAccountName(const QString&) ) );
-
qDebug() << "NmHsWidget::NmHsWidget OUT <<--";
}
@@ -79,12 +63,61 @@
}
/*!
+ \fn void NmHsWidget::onShow()
+
+ Shows the widget
+*/
+void NmHsWidget::onShow()
+{
+ qDebug() << "NmHsWidget::onShow IN -->>";
+ if (mEngine)
+ {
+ mEngine->activate();
+ }
+ qDebug() << "NmHsWidget::onShow OUT <<--";
+}
+
+
+/*!
+ \fn void NmHsWidget::onHide()
+
+ Hides the widget
+*/
+void NmHsWidget::onHide()
+{
+ qDebug() << "NmHsWidget::onHide IN -->>";
+ if (mEngine)
+ {
+ mEngine->suspend();
+ }
+ qDebug() << "NmHsWidget::onHide OUT <<--";
+}
+
+
+/*!
Initializes the widget.
*/
void NmHsWidget::onInitialize()
{
qDebug() << "NmHsWidget::onInitialize IN -->>";
+
+ mEngine = new NmHsWidgetEmailEngine( mAccountId );
+ mTitleRow->updateAccountName(mEngine->accountName());
+ updateMailData();
+ mTitleRow->updateUnreadCount(mEngine->unreadCount());
+ //Get signals about changes in mail data
+ connect(mEngine, SIGNAL( mailDataChanged() )
+ ,this, SLOT( updateMailData() ) );
+
+ //Get Signals about changes in unread count
+ connect(mEngine, SIGNAL( unreadCountChanged(const int&) )
+ ,mTitleRow, SLOT( updateUnreadCount(const int&) ) );
+
+ //Get signals about account name changes
+ connect(mEngine, SIGNAL( accountNameChanged(const QString&) )
+ ,mTitleRow, SLOT( updateAccountName(const QString&) ) );
+
qDebug() << "NmHsWidget::onInitialize OUT <<--";
}
@@ -119,32 +152,6 @@
}
/*!
- updateAccountName slot
-*/
-void NmHsWidget::updateAccountName(const QString& accountName)
-{
- qDebug() << "NmHsWidget::updateAccountName IN -->>";
- qDebug() << "New account name is: " << accountName;
-
- mTitleRow->updateAccountName(accountName);
-
- qDebug() << "NmHsWidget::updateAccountName OUT <<--";
-}
-
-/*!
- updateUnreadCount slot
-*/
-void NmHsWidget::updateUnreadCount(const int& unreadCount )
-{
- qDebug() << "NmHsWidget::updateUnreadCount IN -->>";
- qDebug() << "New unread count is: " << QString::number(unreadCount);
-
- mTitleRow->updateUnreadCount(unreadCount);
-
- qDebug() << "NmHsWidget::updateUnreadCount OUT <<--";
-}
-
-/*!
updateMailData slot
*/
void NmHsWidget::updateMailData()
@@ -170,16 +177,51 @@
}
/*!
+ Sets monitored account id from given string
+ Needed for home screen framework thich supports only QString type properties
+*/
+void NmHsWidget::setAccountId(const QString &text)
+{
+ qDebug() << "NmHsWidget::setAccountId IN -->>";
+ bool ok;
+ quint64 id = text.toULongLong(&ok);
+ if (!ok)
+ {
+ // TODO: assert here if conversion failed?
+ qDebug() << "NmHsWidget::setAccountId: invalid account ID data!!!";
+ mAccountId.setId(0);
+ }
+ else
+ {
+ mAccountId.setId(id);
+ }
+ qDebug() << "NmHsWidget::setAccountId OUT <<--";
+}
+
+/*!
+ Returns monitored account id as a string
+ Needed for home screen framework which supports only QString type properties
+*/
+QString NmHsWidget::accountId() const
+{
+ qDebug() << "NmHsWidget::accountId()";
+ return QString::number(mAccountId.id());
+}
+
+/*!
Updates list to include correct amount of mail row widgets
*/
void NmHsWidget::updateMailRowsList(int mailCount)
{
qDebug() << "NmHsWidget::updateMailRowsList IN -->>";
+ qDebug() << "NmHsWidget - mMailRows.count() == " << mMailRows.count();
+ qDebug() << "NmHsWidget - ordered count == " << mailCount;
while (mMailRows.count() != mailCount)
{
//more mails to show than rows
if (mMailRows.count() < mailCount)
{
+ qDebug() << "NmHsWidget - add new mail row";
NmHsWidgetEmailRow *row = new NmHsWidgetEmailRow();
mMailRows.append(row);
mRowLayout->addItem(row);
@@ -187,6 +229,7 @@
//too many rows
else if (mMailRows.count() > mailCount)
{
+ qDebug() << "NmHsWidget - remove mail row";
mRowLayout->removeItem(mMailRows.last());
delete mMailRows.takeLast();
}
@@ -194,3 +237,29 @@
__ASSERT_ALWAYS( mMailRows.count() == mailCount, User::Panic(_L("Invalid"), 500) );
qDebug() << "NmHsWidget::updateMailRowsList OUT <<--";
}
+
+/*!
+ mousePressEvent(QGraphicsSceneMouseEvent *event)
+*/
+void NmHsWidget::mousePressEvent(QGraphicsSceneMouseEvent *event)
+{
+ qDebug() << "NmHsWidget::mousePressEvent IN -->>";
+
+ if (mTitleRow->rect().contains(event->pos()))
+ {
+ mEngine->launchMailAppInboxView();
+ }
+ else
+ {
+ for (int i=0; i < mMailRows.count(); i++)
+ {
+ QRectF tmpRect = mMailRows.at(i)->geometry(); // rect();
+ if (tmpRect.contains(event->pos()))
+ {
+ mEngine->launchMailAppMailViewer(mMailRows.at(i)->messageId());
+ break;
+ }
+ }
+ }
+ qDebug() << "NmHsWidget::mousePressEvent OUT <<--";
+}