emailuis/nmhswidget/src/nmhswidget.cpp
changeset 23 2dc6caa42ec3
parent 20 ecc8def7944a
child 30 759dc5235cdb
equal deleted inserted replaced
20:ecc8def7944a 23:2dc6caa42ec3
    16  */
    16  */
    17 #include <QDebug>
    17 #include <QDebug>
    18 #include <QtGui>
    18 #include <QtGui>
    19 #include <QGraphicsLinearLayout>
    19 #include <QGraphicsLinearLayout>
    20 #include <hbcolorscheme.h>
    20 #include <hbcolorscheme.h>
       
    21 #include <QTranslator>
       
    22 #include <hbframedrawer.h>
       
    23 #include <hbframeitem.h>
    21 #include "nmcommon.h"
    24 #include "nmcommon.h"
    22 #include "nmhswidget.h"
    25 #include "nmhswidget.h"
    23 #include "nmhswidgetemailengine.h"
    26 #include "nmhswidgetemailengine.h"
    24 #include "nmmessageenvelope.h"
    27 #include "nmmessageenvelope.h"
    25 #include "nmhswidgettitlerow.h"
    28 #include "nmhswidgettitlerow.h"
    26 #include "nmhswidgetemailrow.h"
    29 #include "nmhswidgetemailrow.h"
    27 #include "nmhswidgetconsts.h"
    30 #include "nmhswidgetconsts.h"
       
    31 #include "nmhswidgetdatetimeobserver.h"
    28 
    32 
    29 NmHsWidget::NmHsWidget(QGraphicsItem *parent, Qt::WindowFlags flags)
    33 NmHsWidget::NmHsWidget(QGraphicsItem *parent, Qt::WindowFlags flags)
    30     : HbWidget(parent, flags), 
    34     : HbWidget(parent, flags), 
    31       mEngine(0),
    35       mEngine(0),
    32       mRowLayout(0),
    36       mRowLayout(0),
    33       mTitleRow( new NmHsWidgetTitleRow() ),
    37       mTitleRow(0),
    34       mAccountId(0)
    38       mAccountId(0),
       
    39       mAccountIconName(0),
       
    40       mTranslator(0),
       
    41       mBackgroundFrameDrawer(0),
       
    42       mIsExpanded(true),
       
    43       mStaticWidget(true),
       
    44       mDateObserver(0)
    35 {
    45 {
    36     qDebug() << "NmHsWidget::NmHsWidget IN -->>";
    46     qDebug() << "NmHsWidget::NmHsWidget IN -->>";
    37 
    47        
    38     this->setContentsMargins( KNmHsWidgetContentsMargin, KNmHsWidgetContentsMargin,
    48     qDebug() << "NmHsWidget::NmHsWidget OUT <<--";
       
    49 }
       
    50 
       
    51 /*!
       
    52     Destructor
       
    53 */
       
    54 NmHsWidget::~NmHsWidget()
       
    55 {
       
    56     qDebug() << "NmHsWidget::~NmHsWidget IN -->>";
       
    57     if(mTranslator){
       
    58         delete mTranslator;
       
    59         mTranslator = NULL;
       
    60     }
       
    61     
       
    62     if(mEngine){
       
    63         delete mEngine;
       
    64         mEngine = NULL;
       
    65         }
       
    66     
       
    67     if(mBackgroundFrameDrawer){
       
    68         delete mBackgroundFrameDrawer;
       
    69         mBackgroundFrameDrawer = NULL;
       
    70         }
       
    71 		
       
    72 	if(mDateObserver){
       
    73         delete mDateObserver;
       
    74         mDateObserver = NULL;
       
    75         }
       
    76     qDebug() << "NmHsWidget::~NmHsWidget OUT <<--";
       
    77 }
       
    78 
       
    79 /*!
       
    80     \fn void NmHsWidget::onShow()
       
    81 
       
    82     called by home screen fw when widget gets visible
       
    83 */
       
    84 void NmHsWidget::onShow()
       
    85 {
       
    86     qDebug() << "NmHsWidget::onShow IN -->>";
       
    87     if (mEngine)
       
    88         {
       
    89         mEngine->activate();
       
    90         }
       
    91     qDebug() << "NmHsWidget::onShow OUT <<--";
       
    92 }
       
    93 
       
    94 /*!
       
    95     \fn void NmHsWidget::onHide()
       
    96 
       
    97     called by home screen fw when widget gets hidden
       
    98 */
       
    99 void NmHsWidget::onHide()
       
   100 {
       
   101     qDebug() << "NmHsWidget::onHide IN -->>";
       
   102     if (mEngine)
       
   103         {
       
   104         mEngine->suspend();
       
   105         }
       
   106     qDebug() << "NmHsWidget::onHide OUT <<--";
       
   107 }
       
   108 
       
   109 /*!
       
   110     Initializes Localization.
       
   111     /post mTranslator constructed & localization file loaded
       
   112     returns false in failure, otherwise true
       
   113 */
       
   114 bool NmHsWidget::setupLocalization()
       
   115 {
       
   116     qDebug() << "NmHsWidget::setupLocalization IN -->>";
       
   117     
       
   118     //Use correct localisation
       
   119     bool ret(false); 
       
   120     mTranslator = new QTranslator();
       
   121     QString lang = QLocale::system().name();
       
   122     ret = mTranslator->load(KNmHsWidgetLocFileName + lang, KNmHsWidgetLocLocation);
       
   123     qDebug() << "NmHsWidget::setupLocalization mTranslator->load loadSucceed:"<<ret;
       
   124     QCoreApplication::installTranslator(mTranslator);
       
   125 
       
   126     qDebug() << "NmHsWidget::setupLocalization OUT <<--";
       
   127     return ret;
       
   128 }
       
   129 
       
   130 /*!
       
   131     Initializes UI. Everything that is not done in docml files should be here.
       
   132     return true if ok, in error false.
       
   133 */
       
   134 void NmHsWidget::setupUi()
       
   135 {
       
   136     qDebug() << "NmHsWidget::setupUi IN -->>";
       
   137     setContentsMargins( KNmHsWidgetContentsMargin, KNmHsWidgetContentsMargin,
    39             KNmHsWidgetContentsMargin, KNmHsWidgetContentsMargin);
   138             KNmHsWidgetContentsMargin, KNmHsWidgetContentsMargin);
       
   139     
    40     //Setup layout
   140     //Setup layout
    41     mRowLayout = new QGraphicsLinearLayout(Qt::Vertical);
   141     mRowLayout = new QGraphicsLinearLayout(Qt::Vertical);
       
   142 
    42     mRowLayout->setContentsMargins(KNmHsWidgetContentsMargin, KNmHsWidgetContentsMargin,
   143     mRowLayout->setContentsMargins(KNmHsWidgetContentsMargin, KNmHsWidgetContentsMargin,
    43             KNmHsWidgetContentsMargin, KNmHsWidgetContentsMargin);
   144             KNmHsWidgetContentsMargin, KNmHsWidgetContentsMargin);
    44     mRowLayout->setSpacing(KNmHsWidgetContentsMargin);
   145     mRowLayout->setSpacing(KNmHsWidgetContentsMargin);
    45     mRowLayout->addItem(mTitleRow);
       
    46     setLayout(mRowLayout);
   146     setLayout(mRowLayout);
    47     
   147    
    48     qDebug() << "NmHsWidget::NmHsWidget OUT <<--";
   148    //background
    49 }
   149    mBackgroundFrameDrawer = new HbFrameDrawer( KNmHsWidgetBackgroundImage, HbFrameDrawer::NinePieces );
    50 
   150    HbFrameItem* backgroundLayoutItem = new HbFrameItem( mBackgroundFrameDrawer );
    51 /*!
   151    //set to NULL to indicate that ownership transferred
    52     Destructor
   152    mBackgroundFrameDrawer = NULL;
    53 */
   153    setBackgroundItem( backgroundLayoutItem );
    54 NmHsWidget::~NmHsWidget()
   154    
    55 {
   155    qDebug() << "NmHsWidget::setupUi OUT -->>";
    56     qDebug() << "NmHsWidget::~NmHsWidget IN -->>";
   156 }
    57     if(mEngine)
       
    58         {
       
    59         delete mEngine;
       
    60         mEngine = NULL;
       
    61         }
       
    62     qDebug() << "NmHsWidget::~NmHsWidget OUT <<--";
       
    63 }
       
    64 
       
    65 /*!
       
    66     \fn void NmHsWidget::onShow()
       
    67 
       
    68     Shows the widget
       
    69 */
       
    70 void NmHsWidget::onShow()
       
    71 {
       
    72     qDebug() << "NmHsWidget::onShow IN -->>";
       
    73     if (mEngine)
       
    74         {
       
    75         mEngine->activate();
       
    76         }
       
    77     qDebug() << "NmHsWidget::onShow OUT <<--";
       
    78 }
       
    79 
       
    80 
       
    81 /*!
       
    82     \fn void NmHsWidget::onHide()
       
    83 
       
    84     Hides the widget
       
    85 */
       
    86 void NmHsWidget::onHide()
       
    87 {
       
    88     qDebug() << "NmHsWidget::onHide IN -->>";
       
    89     if (mEngine)
       
    90         {
       
    91         mEngine->suspend();
       
    92         }
       
    93     qDebug() << "NmHsWidget::onHide OUT <<--";
       
    94 }
       
    95 
       
    96 
   157 
    97 /*!
   158 /*!
    98     Initializes the widget.
   159     Initializes the widget.
       
   160     
       
   161     called by home screen fw when widget is added to home screen
    99 */
   162 */
   100 void NmHsWidget::onInitialize()
   163 void NmHsWidget::onInitialize()
   101 {
   164 {
   102     qDebug() << "NmHsWidget::onInitialize IN -->>";
   165     QT_TRY{
   103 
   166         qDebug() << "NmHsWidget::onInitialize IN -->>";
   104     mEngine = new NmHsWidgetEmailEngine( mAccountId ); 
   167         
   105     mTitleRow->updateAccountName(mEngine->accountName());
   168         setupUi();
   106     updateMailData();
   169         //emit error if localization fails
   107     mTitleRow->updateUnreadCount(mEngine->unreadCount());
   170         if(!setupLocalization()){
   108     
   171             emit error();
   109     //Get signals about changes in mail data
   172             return;
   110     connect(mEngine, SIGNAL( mailDataChanged() )
   173         }
   111             ,this, SLOT( updateMailData() ) );
   174         
   112     
   175         //Engine construction is 2 phased. 
   113     //Get Signals about changes in unread count
   176         mEngine = new NmHsWidgetEmailEngine( mAccountId );
   114     connect(mEngine, SIGNAL( unreadCountChanged(const int&) )
   177         //Client must connect to exception signals before calling the initialize function
   115             ,mTitleRow, SLOT( updateUnreadCount(const int&) ) );
   178         //because we don't want to miss any signals.
   116     
   179         connect(mEngine, SIGNAL( exceptionOccured(const int&) )
   117     //Get signals about account name changes
   180                 ,this, SLOT( onEngineException(const int&) ) );
   118     connect(mEngine, SIGNAL( accountNameChanged(const QString&) )
   181         if(!mEngine->initialize())
   119             ,mTitleRow, SLOT( updateAccountName(const QString&) ) );
   182             {
   120 
   183             //engine construction failed. Give up.
   121     qDebug() << "NmHsWidget::onInitialize OUT <<--";  
   184             emit error();
       
   185             return;
       
   186             }
       
   187 
       
   188         //construct and load docml for title row
       
   189         mTitleRow = new NmHsWidgetTitleRow(); 
       
   190         if( !mTitleRow->loadDocML()){
       
   191             //if docml loading fails no point to proceed
       
   192             //but memoryleak must be prevented
       
   193             delete mTitleRow;
       
   194             mTitleRow = NULL;
       
   195             emit error();
       
   196             return;
       
   197         }
       
   198         mRowLayout->addItem(mTitleRow);
       
   199         mTitleRow->updateAccountName(mEngine->accountName());
       
   200     
       
   201 	    //create observer for date/time change events
       
   202 	    mDateObserver = new NmHsWidgetDateTimeObserver();
       
   203     
       
   204         updateMailData();
       
   205         mTitleRow->updateUnreadCount(mEngine->unreadCount());
       
   206         mTitleRow->setAccountIcon(mAccountIconName);
       
   207         
       
   208         //Get signals about changes in mail data
       
   209         connect(mEngine, SIGNAL( mailDataChanged() )
       
   210                 ,this, SLOT( updateMailData() ) );
       
   211         
       
   212         //Get Signals about changes in unread count
       
   213         connect(mEngine, SIGNAL( unreadCountChanged(const int&) )
       
   214                 ,mTitleRow, SLOT( updateUnreadCount(const int&) ) );
       
   215         
       
   216         //Get signals about account name changes
       
   217         connect(mEngine, SIGNAL( accountNameChanged(const QString&) )
       
   218                 ,mTitleRow, SLOT( updateAccountName(const QString&) ) );
       
   219 
       
   220 	    //Get signals about user actions
       
   221 	    connect(mTitleRow, SIGNAL( mailboxLaunchTriggered() )
       
   222 	            ,mEngine, SLOT( launchMailAppInboxView() ) );
       
   223 	    connect(mTitleRow, SIGNAL( expandCollapseButtonPressed() )
       
   224 	            ,this, SLOT( handleExpandCollapseEvent() ) );
       
   225 
       
   226 	    //resize here so homescreen will place widget correctly on screen
       
   227 	    setPreferredSize( mRowLayout->preferredSize() );
       
   228 	    if (parentWidget()) {
       
   229 	        //to place widget properly after adding to homescreen
       
   230 	        parentWidget()->resize(preferredSize()); 
       
   231 		}
       
   232         qDebug() << "NmHsWidget::onInitialize OUT <<--";  
       
   233     }
       
   234     QT_CATCH(...){
       
   235         emit error();
       
   236     }
       
   237 
   122 }
   238 }
   123 
   239 
   124 /*!
   240 /*!
   125     Uninitializes the widget.
   241     Uninitializes the widget.
       
   242     
       
   243     called by home screen fw when widget is removed from home screen
   126 */
   244 */
   127 void NmHsWidget::onUninitialize()
   245 void NmHsWidget::onUninitialize()
   128 {
   246 {
   129     qDebug() << "NmHsWidget::onUninitialize IN -->>";
   247     qDebug() << "NmHsWidget::onUninitialize IN -->>";
   130     
   248     
   131     qDebug() << "NmHsWidget::onUninitialize OUT <<--";
   249     qDebug() << "NmHsWidget::onUninitialize OUT <<--";
   132 }
       
   133 
       
   134 /*!
       
   135     Paints widget
       
   136 */
       
   137 void NmHsWidget::paint(QPainter *painter, 
       
   138                           const QStyleOptionGraphicsItem *option, 
       
   139                           QWidget *widget)
       
   140 {
       
   141     Q_UNUSED(option);
       
   142     Q_UNUSED(widget);
       
   143     //----- backgroud ----------------
       
   144     painter->setOpacity(KNmHsWidgetBackgroundOpacity);
       
   145     QColor backgroundColor(HbColorScheme::color(KBackgroundColorAttribute));
       
   146     // frame is not wanted to be drawn, thus pen color is same as backround color
       
   147     painter->setPen(QPen(backgroundColor, 0));
       
   148     painter->setBrush(backgroundColor);
       
   149     painter->drawRoundedRect(rect(), KNmHsWidgetShoulderRadius, 
       
   150             KNmHsWidgetShoulderRadius);
       
   151     painter->setOpacity(1); //set opacity back to default
       
   152 }
   250 }
   153 
   251 
   154 /*!
   252 /*!
   155     updateMailData slot
   253     updateMailData slot
   156 */
   254 */
   157 void NmHsWidget::updateMailData()
   255 void NmHsWidget::updateMailData()
   158 {
   256 {
   159     qDebug() << "NmHsWidget::updateData IN -->>";
   257     qDebug() << "NmHsWidget::updateData IN -->>";
   160     QList<NmMessageEnvelope> envelopes;
   258     QList<NmMessageEnvelope> envelopes;
   161     int count = mEngine->getEnvelopes(envelopes, 2);
   259     int count = 0;
   162     //TODO: needs error check for -1 ?
   260     if (mIsExpanded) {
       
   261         count = mEngine->getEnvelopes(envelopes, KMaxNumberOfMailsShown);
       
   262         }
       
   263 
   163     updateMailRowsList(count);
   264     updateMailRowsList(count);
   164     
   265     
   165     for(int i=0; i<envelopes.count(); i++)
   266     for(int i=0; i<envelopes.count(); i++)
   166         {
   267         {
   167         qDebug() << "env:" << QString::number(i) << "dispName: " << envelopes[i].sender().displayName();
       
   168         qDebug() << "env:" << QString::number(i) << "dispName: " << envelopes[i].sender().address();
       
   169         qDebug() << "env:" << QString::number(i) << "subject:" << envelopes[i].subject();
       
   170         qDebug() << "env:" << QString::number(i) << "isRead: " << envelopes[i].isRead();
       
   171         qDebug() << "env:" << QString::number(i) << "date: " << envelopes[i].sentTime();
       
   172         qDebug() << "env:" << QString::number(i) << "priority: " << envelopes[i].priority();
       
   173         qDebug() << "env:" << QString::number(i) << "attachments: " << envelopes[i].hasAttachments();
       
   174         mMailRows[i]->updateMailData( envelopes[i] );
   268         mMailRows[i]->updateMailData( envelopes[i] );
   175         }
   269         }
   176     qDebug() << "NmHsWidget::updateData OUT <<--"; 
   270     qDebug() << "NmHsWidget::updateData OUT <<--"; 
   177 }
   271 }
   178 
   272 
   179 /*!
   273 /*!
   180     Sets monitored account id from given string
   274     Sets monitored account id from given string
   181     Needed for home screen framework thich supports only QString type properties
   275     Needed for home screen framework which supports only QString type properties
   182 */
   276 */
   183 void NmHsWidget::setAccountId(const QString &text)
   277 void NmHsWidget::setAccountId(const QString &text)
   184 {
   278 {
   185     qDebug() << "NmHsWidget::setAccountId IN -->>"; 
   279     qDebug() << "NmHsWidget::setAccountId IN -->>"; 
   186     bool ok;
   280     bool ok;
   187     quint64 id = text.toULongLong(&ok);
   281     quint64 id = text.toULongLong(&ok);
   188     if (!ok)
   282     if (!ok)
   189         {
   283         {
   190         // TODO: assert here if conversion failed?
   284         qDebug() << "NmHsWidget::setAccountId: invalid account ID data, signal finished()!!!"; 
   191         qDebug() << "NmHsWidget::setAccountId: invalid account ID data!!!"; 
   285         //No valid account id so give up
   192         mAccountId.setId(0);
   286         emit finished();
   193         }
   287         }
   194     else
   288     else
   195         {
   289         {
   196         mAccountId.setId(id);
   290         mAccountId.setId(id);
   197         }
   291         }
   207     qDebug() << "NmHsWidget::accountId()"; 
   301     qDebug() << "NmHsWidget::accountId()"; 
   208     return QString::number(mAccountId.id());
   302     return QString::number(mAccountId.id());
   209 }
   303 }
   210 
   304 
   211 /*!
   305 /*!
   212     Updates list to include correct amount of mail row widgets
   306     Sets monitored account icon name from given string
   213 */
   307 */
   214 void NmHsWidget::updateMailRowsList(int mailCount)
   308 void NmHsWidget::setAccountIconName(const QString &text)
       
   309 {
       
   310     qDebug() << "NmHsWidget::setAccountIconName IN -->>"; 
       
   311     mAccountIconName = text;
       
   312     qDebug() << "NmHsWidget::setAccountIconName OUT <<--"; 
       
   313 }
       
   314 
       
   315 /*!
       
   316     Returns monitored account icon name
       
   317 */
       
   318 QString NmHsWidget::accountIconName() const
       
   319 {
       
   320     qDebug() << "NmHsWidget::accountIconName()"; 
       
   321     return mAccountIconName;
       
   322 }
       
   323 
       
   324 /*!
       
   325     Slot to handle expand/collapse trigger event
       
   326 */
       
   327 void NmHsWidget::handleExpandCollapseEvent()
       
   328 {
       
   329     qDebug() << "NmHsWidget::handleExpandCollapseEvent IN -->>";
       
   330     toggleExpansionState();
       
   331     qDebug() << "NmHsWidget::handleExpandCollapseEvent OUT <<--"; 
       
   332 }
       
   333 
       
   334 /*!
       
   335     Sets widget expand/collapse state
       
   336     /post widget expansion state is changed
       
   337 */
       
   338 void NmHsWidget::toggleExpansionState()
       
   339 {
       
   340     qDebug() << "NmHsWidget::setExpanded IN -->>"; 
       
   341 
       
   342     mIsExpanded = !mIsExpanded;
       
   343     
       
   344     //save new state to home screen
       
   345     QStringList propertiesList;
       
   346     propertiesList.append("widgetState");
       
   347     emit setPreferences(propertiesList);
       
   348     
       
   349     //handle state change drawing
       
   350     updateMailData();
       
   351     
       
   352     qDebug() << "NmHsWidget::setExpanded OUT <<--"; 
       
   353 }
       
   354 
       
   355 /*!
       
   356     Sets expand/collapse state from given string (needed by homescreen)
       
   357 */
       
   358 void NmHsWidget::setWidgetStateProperty(QString value)
       
   359 {
       
   360     qDebug() << "NmHsWidget::setWidgetStateProperty IN -->>"; 
       
   361     if (value == KNmHsWidgetStateCollapsed)
       
   362         {
       
   363         mIsExpanded = false;
       
   364         }
       
   365     else
       
   366         {
       
   367         mIsExpanded = true;
       
   368         }
       
   369     qDebug() << "NmHsWidget::setWidgetStateProperty OUT <<--"; 
       
   370 }
       
   371 
       
   372 /*!
       
   373     Returns widget expand/collapse state as string (needed by homescreen) 
       
   374 */
       
   375 QString NmHsWidget::widgetStateProperty()
       
   376 {
       
   377     qDebug() << "NmHsWidget::widgetStateProperty()";
       
   378     if (mIsExpanded)
       
   379         {
       
   380         return KNmHsWidgetStateExpanded;
       
   381         }
       
   382     else
       
   383         {
       
   384         return KNmHsWidgetStateCollapsed;
       
   385         }
       
   386 }
       
   387 
       
   388 /*!
       
   389     Updates mMailRows list to include correct amount of mail row widgets
       
   390     /param mailCount defines how many mail rows is needed
       
   391     /post mMailRows list includes NmHsWidgetEmailRow for each mail item 
       
   392 */
       
   393 void NmHsWidget::updateMailRowsList(const int mailCount)
   215 {
   394 {
   216     qDebug() << "NmHsWidget::updateMailRowsList IN -->>";
   395     qDebug() << "NmHsWidget::updateMailRowsList IN -->>";
   217     qDebug() << "NmHsWidget - mMailRows.count() == " <<  mMailRows.count();
   396     qDebug() << "NmHsWidget - mMailRows.count() == " <<  mMailRows.count();
   218     qDebug() << "NmHsWidget - ordered count == " <<  mailCount;
   397     qDebug() << "NmHsWidget - ordered count == " <<  mailCount;
   219     while (mMailRows.count() != mailCount)
   398     
       
   399     int neededRowsCount = mailCount;
       
   400     //force size when static and expanded
       
   401     if (mStaticWidget && mIsExpanded)
       
   402         {
       
   403         neededRowsCount = KMaxNumberOfMailsShown;
       
   404         }
       
   405     
       
   406     while (mMailRows.count() != neededRowsCount)
   220         {
   407         {
   221         //more mails to show than rows
   408         //more mails to show than rows
   222         if (mMailRows.count() < mailCount)
   409         if (mMailRows.count() < neededRowsCount)
   223             {
   410             {
   224             qDebug() << "NmHsWidget - add new mail row";
   411             qDebug() << "NmHsWidget - add new mail row";
   225             NmHsWidgetEmailRow *row = new NmHsWidgetEmailRow();
   412             NmHsWidgetEmailRow *row = new NmHsWidgetEmailRow();
       
   413             if( !row->loadDocML()){
       
   414                 qDebug() << "NmHsWidget::updateMailRowsList row->loadDocML() fails";
       
   415                 //if docml loading fails no point to proceed
       
   416                 //but memoryleak must be prevented
       
   417                 delete row;
       
   418                 row = NULL;
       
   419                 emit error();
       
   420                 return;
       
   421             }
       
   422             connect(row, SIGNAL(mailViewerLaunchTriggered(const NmId&))
       
   423                     ,mEngine, SLOT(launchMailAppMailViewer(const NmId&)));
       
   424             connect( mDateObserver, SIGNAL(dateTimeChanged())
       
   425                     ,row, SLOT(updateDateTime()) );
   226             mMailRows.append(row);
   426             mMailRows.append(row);
   227             mRowLayout->addItem(row);            
   427             mRowLayout->addItem(row);            
   228             }
   428             }
   229         //too many rows
   429         //too many rows
   230         else if (mMailRows.count() > mailCount)
   430         else if (mMailRows.count() > neededRowsCount)
   231             {
   431             {
   232             qDebug() << "NmHsWidget - remove mail row";
   432             qDebug() << "NmHsWidget - remove mail row";
   233             mRowLayout->removeItem(mMailRows.last());
   433             mRowLayout->removeItem(mMailRows.last());
   234             delete mMailRows.takeLast();
   434             delete mMailRows.takeLast();
   235             }
   435             }
   236         }
   436         }
   237     __ASSERT_ALWAYS( mMailRows.count() == mailCount, User::Panic(_L("Invalid"), 500) );
   437     __ASSERT_ALWAYS( mMailRows.count() == neededRowsCount, User::Panic(_L("Invalid"), 500) );
       
   438     
       
   439     //resize the widget to new layout size
       
   440     setPreferredSize( mRowLayout->preferredSize() );
       
   441     
       
   442     if (mStaticWidget)
       
   443         {
       
   444         this->updateMailRowsVisibility(mailCount);
       
   445         }
   238     qDebug() << "NmHsWidget::updateMailRowsList OUT <<--";
   446     qDebug() << "NmHsWidget::updateMailRowsList OUT <<--";
   239 }
   447 }
   240 
   448 
   241 /*!
   449 /*!
   242     mousePressEvent(QGraphicsSceneMouseEvent *event)
   450     Updates mail row visibilities in static widget
   243 */
   451     /param visibleCount defines how many items do have mail data
   244 void NmHsWidget::mousePressEvent(QGraphicsSceneMouseEvent *event)
   452     /post all row items having mail data are visible, other rows are hidden
   245 {
   453 */
   246     qDebug() << "NmHsWidget::mousePressEvent IN -->>";
   454 void NmHsWidget::updateMailRowsVisibility(const int visibleCount)
   247 
   455 {
   248     if (mTitleRow->rect().contains(event->pos()))
   456     qDebug() << "NmHsWidget::updateMailRowsVisibility IN -->>";
   249         {
   457   
   250         mEngine->launchMailAppInboxView();
   458     // set visible as many rows as requested by visibleCount param
   251         }
   459     bool isVisible;
   252     else
   460     for (int i=0; i < mMailRows.count(); i++) 
   253         {
   461         {
   254         for (int i=0; i < mMailRows.count(); i++)
   462         isVisible = false;
       
   463         if ((mIsExpanded) && (i < visibleCount)) 
   255             {
   464             {
   256             QRectF tmpRect = mMailRows.at(i)->geometry(); // rect();
   465             isVisible = true;
   257             if (tmpRect.contains(event->pos()))
       
   258                 {
       
   259                 mEngine->launchMailAppMailViewer(mMailRows.at(i)->messageId());
       
   260                 break;
       
   261                 }
       
   262             }
   466             }
   263         }
   467         mMailRows.at(i)->setVisible(isVisible);
   264     qDebug() << "NmHsWidget::mousePressEvent OUT <<--";
   468         }
   265 }
   469     
       
   470     qDebug() << "NmHsWidget::updateMailRowsVisibility OUT <<--";
       
   471 }
       
   472 
       
   473 /*!
       
   474     onEngineException (NmHsWidgetEmailEngineExceptionCode exc)
       
   475     signals widget to be finalized
       
   476     /param exc exception type
       
   477 */
       
   478 void NmHsWidget::onEngineException(const int& exc)
       
   479     {
       
   480     qDebug() << "NmHsWidget:onEngineException IN -->>";
       
   481     switch (exc)
       
   482         {
       
   483         case (NmEngineExcAccountDeleted):
       
   484              emit finished(); //succesful ending
       
   485              break;
       
   486         case (NmEngineExcFailure):
       
   487              emit error(); //failure
       
   488              break;
       
   489         default: 
       
   490             break; 
       
   491         }
       
   492     }