emailuis/nmhswidget/src/nmhswidget.cpp
author hgs
Mon, 23 Aug 2010 23:32:31 +0300
changeset 62 a8c646b56683
parent 49 00c7ae862740
child 68 83cc6bae1de8
permissions -rw-r--r--
201033
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     1
/*
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
     2
 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     3
 * All rights reserved.
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     4
 * This component and the accompanying materials are made available
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     5
 * under the terms of "Eclipse Public License v1.0"
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     6
 * which accompanies this distribution, and is available
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     7
 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     8
 *
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     9
 * Initial Contributors:
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    10
 * Nokia Corporation - initial contribution.
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    11
 *
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    12
 * Contributors:
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    13
 *
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    14
 * Description: 
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    15
 *
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    16
 */
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    17
#include <QtGui>
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    18
#include <QGraphicsLinearLayout>
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    19
#include <hbcolorscheme.h>
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
    20
#include <hbdocumentloader.h>
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
    21
#include <QTranslator>
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
    22
#include <hbframedrawer.h>
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
    23
#include <hbframeitem.h>
47
hgs
parents: 43
diff changeset
    24
#include <hblabel.h>
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
    25
#include "nmcommon.h"
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    26
#include "nmhswidget.h"
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    27
#include "nmhswidgetemailengine.h"
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    28
#include "nmmessageenvelope.h"
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    29
#include "nmhswidgettitlerow.h"
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    30
#include "nmhswidgetemailrow.h"
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    31
#include "nmhswidgetconsts.h"
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
    32
#include "nmhswidgetdatetimeobserver.h"
43
hgs
parents: 23
diff changeset
    33
#include "emailtrace.h"
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    34
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    35
NmHsWidget::NmHsWidget(QGraphicsItem *parent, Qt::WindowFlags flags)
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    36
    : HbWidget(parent, flags), 
62
hgs
parents: 49
diff changeset
    37
      mMainContainer(0),
hgs
parents: 49
diff changeset
    38
      mEmptySpaceContainer(0),
hgs
parents: 49
diff changeset
    39
      mWidgetContainer(0),
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
    40
      mTitleRow(0),
62
hgs
parents: 49
diff changeset
    41
      mContentContainer(0),
hgs
parents: 49
diff changeset
    42
      mNoMailsLabel(0),
hgs
parents: 49
diff changeset
    43
      mContentLayout(0),              
hgs
parents: 49
diff changeset
    44
      mBackgroundFrameDrawer(0),
hgs
parents: 49
diff changeset
    45
      mTranslator(0),
hgs
parents: 49
diff changeset
    46
      mEngine(0),      
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
    47
      mAccountId(0),
43
hgs
parents: 23
diff changeset
    48
      mAccountIconName(),
47
hgs
parents: 43
diff changeset
    49
      mDateObserver(0),
62
hgs
parents: 49
diff changeset
    50
      mIsExpanded(false)
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    51
{
43
hgs
parents: 23
diff changeset
    52
    NM_FUNCTION;
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    53
}
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    54
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    55
/*!
47
hgs
parents: 43
diff changeset
    56
 Destructor
hgs
parents: 43
diff changeset
    57
 */
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    58
NmHsWidget::~NmHsWidget()
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    59
{
43
hgs
parents: 23
diff changeset
    60
    NM_FUNCTION;
hgs
parents: 23
diff changeset
    61
hgs
parents: 23
diff changeset
    62
    delete mTranslator;
hgs
parents: 23
diff changeset
    63
    mTranslator = NULL;
hgs
parents: 23
diff changeset
    64
hgs
parents: 23
diff changeset
    65
    delete mEngine;
hgs
parents: 23
diff changeset
    66
    mEngine = NULL;
hgs
parents: 23
diff changeset
    67
hgs
parents: 23
diff changeset
    68
    delete mBackgroundFrameDrawer;
hgs
parents: 23
diff changeset
    69
    mBackgroundFrameDrawer = NULL;
hgs
parents: 23
diff changeset
    70
hgs
parents: 23
diff changeset
    71
    delete mDateObserver;
hgs
parents: 23
diff changeset
    72
    mDateObserver = NULL;
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    73
}
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    74
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    75
/*!
47
hgs
parents: 43
diff changeset
    76
 \fn QPainterPath NmHsWidget::shape()
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
    77
47
hgs
parents: 43
diff changeset
    78
 Called by home screen fw to check widget boundaries, needed to draw
hgs
parents: 43
diff changeset
    79
 outside widget boundingRect.
hgs
parents: 43
diff changeset
    80
 /return QPainterPath path describing actual boundaries of widget 
hgs
parents: 43
diff changeset
    81
  including child items
hgs
parents: 43
diff changeset
    82
 */
hgs
parents: 43
diff changeset
    83
QPainterPath NmHsWidget::shape() const
hgs
parents: 43
diff changeset
    84
{
hgs
parents: 43
diff changeset
    85
    NM_FUNCTION;
hgs
parents: 43
diff changeset
    86
    
hgs
parents: 43
diff changeset
    87
    QPainterPath path;
hgs
parents: 43
diff changeset
    88
    path.setFillRule(Qt::WindingFill);
62
hgs
parents: 49
diff changeset
    89
    if (mWidgetContainer){
hgs
parents: 49
diff changeset
    90
        //add mWidgetContainer using geometry to get
hgs
parents: 49
diff changeset
    91
        //correct point for top-left-corner
hgs
parents: 49
diff changeset
    92
        QRectF widgetRect = mWidgetContainer->geometry();
hgs
parents: 49
diff changeset
    93
        path.addRect(widgetRect); 
hgs
parents: 49
diff changeset
    94
        
hgs
parents: 49
diff changeset
    95
        //then fetch shape from title row 
hgs
parents: 49
diff changeset
    96
        QPainterPath titlepath;
hgs
parents: 49
diff changeset
    97
        titlepath.addPath(mTitleRow->shape());
hgs
parents: 49
diff changeset
    98
        //translate it's location to be inside mWidgetContainer
hgs
parents: 49
diff changeset
    99
        titlepath.translate(widgetRect.topLeft());
hgs
parents: 49
diff changeset
   100
        //and finally add it to path
hgs
parents: 49
diff changeset
   101
        path.addPath(titlepath);    
47
hgs
parents: 43
diff changeset
   102
    }
62
hgs
parents: 49
diff changeset
   103
    //simplified path, i.e. only outlines
47
hgs
parents: 43
diff changeset
   104
    return path.simplified();
hgs
parents: 43
diff changeset
   105
}
hgs
parents: 43
diff changeset
   106
hgs
parents: 43
diff changeset
   107
/*!
hgs
parents: 43
diff changeset
   108
 \fn void NmHsWidget::onShow()
hgs
parents: 43
diff changeset
   109
hgs
parents: 43
diff changeset
   110
 called by home screen fw when widget gets visible
hgs
parents: 43
diff changeset
   111
 */
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   112
void NmHsWidget::onShow()
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   113
{
43
hgs
parents: 23
diff changeset
   114
    NM_FUNCTION;
47
hgs
parents: 43
diff changeset
   115
    if (mEngine) {
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   116
        mEngine->activate();
47
hgs
parents: 43
diff changeset
   117
    }
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   118
}
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   119
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   120
/*!
47
hgs
parents: 43
diff changeset
   121
 \fn void NmHsWidget::onHide()
hgs
parents: 43
diff changeset
   122
hgs
parents: 43
diff changeset
   123
 called by home screen fw when widget gets hidden
hgs
parents: 43
diff changeset
   124
 */
hgs
parents: 43
diff changeset
   125
void NmHsWidget::onHide()
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   126
{
43
hgs
parents: 23
diff changeset
   127
    NM_FUNCTION;
47
hgs
parents: 43
diff changeset
   128
    if (mEngine) {
hgs
parents: 43
diff changeset
   129
        mEngine->suspend();
hgs
parents: 43
diff changeset
   130
    }
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   131
}
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   132
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   133
/*!
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   134
 \fn bool NmHsWidget::loadDocML(HbDocumentLoader &loader)
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   135
 
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   136
 loads layout data and child items from docml file. Must be called after constructor.
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   137
 /return true if loading succeeded, otherwise false. False indicates that object is unusable
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   138
 */
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   139
bool NmHsWidget::loadDocML(HbDocumentLoader &loader)
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   140
{
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   141
    NM_FUNCTION;
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   142
    
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   143
    bool ok(false);
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   144
    loader.load(KNmHsWidgetDocML, &ok);
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   145
    
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   146
    if(ok) {
62
hgs
parents: 49
diff changeset
   147
        mMainContainer = static_cast<HbWidget*> (loader.findWidget(KNmHsWidgetMainContainer));  
hgs
parents: 49
diff changeset
   148
        mWidgetContainer = static_cast<HbWidget*> (loader.findWidget(KNmHsWidgetContainer));
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   149
        mContentContainer = static_cast<HbWidget*> (loader.findWidget(KNmHsWidgetContentContainer));
62
hgs
parents: 49
diff changeset
   150
        mEmptySpaceContainer = static_cast<HbWidget*> (loader.findWidget(KNmHsWidgetEmptySpaceContainer));
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   151
        mNoMailsLabel = static_cast<HbLabel*> (loader.findWidget(KNmHsWidgetNoMailsLabel));
62
hgs
parents: 49
diff changeset
   152
        if (!mMainContainer || !mWidgetContainer || !mContentContainer 
hgs
parents: 49
diff changeset
   153
                || !mEmptySpaceContainer || !mNoMailsLabel ) {
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   154
            //something failed in documentloader, no point to continue
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   155
            NM_ERROR(1,"NmHsWidget::loadDocML fail @ containers or label");
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   156
            ok = false;
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   157
        }
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   158
    }
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   159
    return ok;
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   160
}
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   161
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   162
/*!
47
hgs
parents: 43
diff changeset
   163
 Initializes Localization.
hgs
parents: 43
diff changeset
   164
 /post mTranslator constructed & localization file loaded
hgs
parents: 43
diff changeset
   165
 */
hgs
parents: 43
diff changeset
   166
void NmHsWidget::setupLocalization()
hgs
parents: 43
diff changeset
   167
{
hgs
parents: 43
diff changeset
   168
    NM_FUNCTION;
hgs
parents: 43
diff changeset
   169
hgs
parents: 43
diff changeset
   170
    //Use correct localisation
hgs
parents: 43
diff changeset
   171
    mTranslator = new QTranslator();
hgs
parents: 43
diff changeset
   172
    QString lang = QLocale::system().name();
hgs
parents: 43
diff changeset
   173
    mTranslator->load(KNmHsWidgetLocFileName + lang, KNmHsWidgetLocLocation);
hgs
parents: 43
diff changeset
   174
    QCoreApplication::installTranslator(mTranslator);
hgs
parents: 43
diff changeset
   175
}
hgs
parents: 43
diff changeset
   176
hgs
parents: 43
diff changeset
   177
/*!
hgs
parents: 43
diff changeset
   178
 Initializes UI. Everything that is not done in docml files should be here.
hgs
parents: 43
diff changeset
   179
 return true if ok, in error false.
hgs
parents: 43
diff changeset
   180
 */
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   181
void NmHsWidget::setupUi()
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   182
{
43
hgs
parents: 23
diff changeset
   183
    NM_FUNCTION;
47
hgs
parents: 43
diff changeset
   184
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   185
    //main level layout needed to control docml objects
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   186
    QGraphicsLinearLayout *widgetLayout = new QGraphicsLinearLayout(Qt::Vertical);
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   187
    widgetLayout->setContentsMargins(KNmHsWidgetContentsMargin, KNmHsWidgetContentsMargin,
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   188
            KNmHsWidgetContentsMargin, KNmHsWidgetContentsMargin);
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   189
    widgetLayout->setSpacing(KNmHsWidgetContentsMargin);
62
hgs
parents: 49
diff changeset
   190
    widgetLayout->addItem(mMainContainer);
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   191
    this->setLayout(widgetLayout);
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   192
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   193
    //fetch pointer to content container layout
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   194
    //to be able to add/remove email rows and no mails label
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   195
    mContentLayout = (QGraphicsLinearLayout*) mContentContainer->layout();
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   196
    
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   197
    //set noMailsLabel properties not supported by doc loader 
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   198
    QColor newFontColor;
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   199
    newFontColor = HbColorScheme::color("qtc_hs_list_item_content_normal");
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   200
    mNoMailsLabel->setTextColor(newFontColor);
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   201
    mNoMailsLabel->setVisible(true);   
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   202
    
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   203
    mContentLayout->removeItem(mNoMailsLabel);
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   204
    
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   205
    //widget background
47
hgs
parents: 43
diff changeset
   206
    mBackgroundFrameDrawer = new HbFrameDrawer(KNmHsWidgetBackgroundImage,
hgs
parents: 43
diff changeset
   207
        HbFrameDrawer::NinePieces);
hgs
parents: 43
diff changeset
   208
    HbFrameItem* backgroundLayoutItem = new HbFrameItem(mBackgroundFrameDrawer);
hgs
parents: 43
diff changeset
   209
    //set to NULL to indicate that ownership transferred
hgs
parents: 43
diff changeset
   210
    mBackgroundFrameDrawer = NULL;
62
hgs
parents: 49
diff changeset
   211
    mWidgetContainer->setBackgroundItem(backgroundLayoutItem);
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   212
}
47
hgs
parents: 43
diff changeset
   213
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   214
/*!
47
hgs
parents: 43
diff changeset
   215
 Initializes the widget.
hgs
parents: 43
diff changeset
   216
 
hgs
parents: 43
diff changeset
   217
 called by home screen fw when widget is added to home screen
hgs
parents: 43
diff changeset
   218
 */
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   219
void NmHsWidget::onInitialize()
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   220
{
43
hgs
parents: 23
diff changeset
   221
    NM_FUNCTION;
62
hgs
parents: 49
diff changeset
   222
    
47
hgs
parents: 43
diff changeset
   223
    QT_TRY {
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   224
	    // Use document loader to load the contents
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   225
	    HbDocumentLoader loader;
62
hgs
parents: 49
diff changeset
   226
		//setup localization before docml loading
hgs
parents: 49
diff changeset
   227
	    setupLocalization();
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   228
		
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   229
	    //load containers and mNoMailsLabel
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   230
        if (!loadDocML(loader)) {
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   231
            NM_ERROR(1,"NmHsWidget::onInitialize Fail @ loader");
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   232
            emit error(); //failure, no point to continue
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   233
            return;
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   234
        }
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   235
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   236
        //construct title row
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   237
        mTitleRow = new NmHsWidgetTitleRow(this);
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   238
        if (!mTitleRow->setupUI(loader)) {
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   239
            //title row creation failed
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   240
            NM_ERROR(1,"NmHsWidget::onInitialize fail @ titlerow");
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   241
            emit error(); //failure, no point to continue
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   242
            return;            
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   243
        }
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   244
				
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   245
        setupUi();
47
hgs
parents: 43
diff changeset
   246
hgs
parents: 43
diff changeset
   247
        //Engine construction is 2 phased. 
hgs
parents: 43
diff changeset
   248
        mEngine = new NmHsWidgetEmailEngine(mAccountId);
hgs
parents: 43
diff changeset
   249
        //Client must connect to exception signals before calling the initialize function
hgs
parents: 43
diff changeset
   250
        //because we don't want to miss any signals.
hgs
parents: 43
diff changeset
   251
        connect(mEngine, SIGNAL( exceptionOccured(const int&) ), this,
hgs
parents: 43
diff changeset
   252
            SLOT( onEngineException(const int&) ));
hgs
parents: 43
diff changeset
   253
        if (!mEngine->initialize()) {
hgs
parents: 43
diff changeset
   254
            //engine construction failed. Give up.
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   255
            NM_ERROR(1,"NmHsWidget::onInitialize fail @ engine");
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   256
            emit error();
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   257
            return;
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   258
        }
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   259
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   260
        mTitleRow->updateAccountName(mEngine->accountName());
47
hgs
parents: 43
diff changeset
   261
hgs
parents: 43
diff changeset
   262
        //create observer for date/time change events
hgs
parents: 43
diff changeset
   263
        mDateObserver = new NmHsWidgetDateTimeObserver();
hgs
parents: 43
diff changeset
   264
hgs
parents: 43
diff changeset
   265
        //Crete MailRows and associated connections
hgs
parents: 43
diff changeset
   266
        createMailRowsList();
hgs
parents: 43
diff changeset
   267
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   268
        updateMailData();
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   269
        mTitleRow->updateUnreadCount(mEngine->unreadCount());
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   270
        mTitleRow->setAccountIcon(mAccountIconName);
43
hgs
parents: 23
diff changeset
   271
        mTitleRow->setExpandCollapseIcon(mIsExpanded);
47
hgs
parents: 43
diff changeset
   272
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   273
        //Get signals about changes in mail data
47
hgs
parents: 43
diff changeset
   274
        connect(mEngine, SIGNAL( mailDataChanged() ), this, SLOT( updateMailData() ));
hgs
parents: 43
diff changeset
   275
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   276
        //Get Signals about changes in unread count
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   277
        connect(mEngine, SIGNAL( unreadCountChanged(const int&) )
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   278
                ,mTitleRow, SLOT( updateUnreadCount(const int&) ) );
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   279
        
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   280
        //Get signals about account name changes
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   281
        connect(mEngine, SIGNAL( accountNameChanged(const QString&) )
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   282
                ,mTitleRow, SLOT( updateAccountName(const QString&) ) );
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   283
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   284
	    //Get signals about user actions
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   285
	    connect(mTitleRow, SIGNAL( mailboxLaunchTriggered() )
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   286
	            ,mEngine, SLOT( launchMailAppInboxView() ) );
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   287
	    connect(mTitleRow, SIGNAL( expandCollapseButtonPressed() )
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   288
	            ,this, SLOT( handleExpandCollapseEvent() ) );
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   289
	    
62
hgs
parents: 49
diff changeset
   290
	    setMinimumSize(mTitleRow->minimumWidth(), 
hgs
parents: 49
diff changeset
   291
	            mEmptySpaceContainer->minimumHeight() + mTitleRow->minimumHeight());
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   292
    }
47
hgs
parents: 43
diff changeset
   293
    QT_CATCH(...) {
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   294
        NM_ERROR(1,"NmHsWidget::onInitialize fail @ catch");
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   295
        emit error();
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   296
    }
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   297
}
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   298
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   299
/*!
47
hgs
parents: 43
diff changeset
   300
 updateMailData slot
hgs
parents: 43
diff changeset
   301
 */
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   302
void NmHsWidget::updateMailData()
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   303
{
43
hgs
parents: 23
diff changeset
   304
    NM_FUNCTION;
47
hgs
parents: 43
diff changeset
   305
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   306
    QList<NmMessageEnvelope> envelopes;
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   307
    int count = 0;
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   308
    if (mIsExpanded) {
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   309
        count = mEngine->getEnvelopes(envelopes, KMaxNumberOfMailsShown);
47
hgs
parents: 43
diff changeset
   310
    }
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   311
47
hgs
parents: 43
diff changeset
   312
    updateLayout(count);
hgs
parents: 43
diff changeset
   313
    //count is safe for envelopes and mMailRows
hgs
parents: 43
diff changeset
   314
    for (int i = 0; i < count; i++) {
hgs
parents: 43
diff changeset
   315
        mMailRows.at(i)->updateMailData(envelopes.at(i));
hgs
parents: 43
diff changeset
   316
    }
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   317
}
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   318
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   319
/*!
47
hgs
parents: 43
diff changeset
   320
 Sets monitored account id from given string
hgs
parents: 43
diff changeset
   321
 Needed for home screen framework which supports only QString type properties
hgs
parents: 43
diff changeset
   322
 */
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   323
void NmHsWidget::setAccountId(const QString &text)
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   324
{
43
hgs
parents: 23
diff changeset
   325
    NM_FUNCTION;
47
hgs
parents: 43
diff changeset
   326
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   327
    bool ok;
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   328
    quint64 id = text.toULongLong(&ok);
47
hgs
parents: 43
diff changeset
   329
    if (!ok) {
hgs
parents: 43
diff changeset
   330
        NM_ERROR(1, "NmHsWidget::setAccountId: invalid account ID data, signal finished()!!!");
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   331
        //No valid account id so give up
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   332
        emit finished();
47
hgs
parents: 43
diff changeset
   333
        return;
hgs
parents: 43
diff changeset
   334
    }
hgs
parents: 43
diff changeset
   335
hgs
parents: 43
diff changeset
   336
    mAccountId.setId(id);
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   337
}
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   338
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   339
/*!
47
hgs
parents: 43
diff changeset
   340
 Returns monitored account id as a string
hgs
parents: 43
diff changeset
   341
 Needed for home screen framework which supports only QString type properties
hgs
parents: 43
diff changeset
   342
 */
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   343
QString NmHsWidget::accountId() const
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   344
{
43
hgs
parents: 23
diff changeset
   345
    NM_FUNCTION;
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   346
    return QString::number(mAccountId.id());
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   347
}
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   348
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   349
/*!
47
hgs
parents: 43
diff changeset
   350
 Sets monitored account icon name from given string
hgs
parents: 43
diff changeset
   351
 */
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   352
void NmHsWidget::setAccountIconName(const QString &text)
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   353
{
43
hgs
parents: 23
diff changeset
   354
    NM_FUNCTION;
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   355
    mAccountIconName = text;
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   356
}
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   357
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   358
/*!
47
hgs
parents: 43
diff changeset
   359
 Returns monitored account icon name
hgs
parents: 43
diff changeset
   360
 */
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   361
QString NmHsWidget::accountIconName() const
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   362
{
43
hgs
parents: 23
diff changeset
   363
    NM_FUNCTION;
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   364
    return mAccountIconName;
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   365
}
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   366
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   367
/*!
47
hgs
parents: 43
diff changeset
   368
 Slot to handle expand/collapse trigger event
hgs
parents: 43
diff changeset
   369
 */
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   370
void NmHsWidget::handleExpandCollapseEvent()
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   371
{
43
hgs
parents: 23
diff changeset
   372
    NM_FUNCTION;
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   373
    toggleExpansionState();
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   374
}
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   375
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   376
/*!
47
hgs
parents: 43
diff changeset
   377
 Sets widget expand/collapse state
hgs
parents: 43
diff changeset
   378
 /post widget expansion state is changed
hgs
parents: 43
diff changeset
   379
 */
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   380
void NmHsWidget::toggleExpansionState()
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   381
{
43
hgs
parents: 23
diff changeset
   382
    NM_FUNCTION;
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   383
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   384
    mIsExpanded = !mIsExpanded;
47
hgs
parents: 43
diff changeset
   385
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   386
    //save new state to home screen
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   387
    QStringList propertiesList;
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   388
    propertiesList.append("widgetState");
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   389
    emit setPreferences(propertiesList);
47
hgs
parents: 43
diff changeset
   390
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   391
    //handle state change drawing
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   392
    updateMailData();
47
hgs
parents: 43
diff changeset
   393
43
hgs
parents: 23
diff changeset
   394
    mTitleRow->setExpandCollapseIcon(mIsExpanded);
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   395
}
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   396
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   397
/*!
47
hgs
parents: 43
diff changeset
   398
 Sets expand/collapse state from given string (needed by homescreen)
hgs
parents: 43
diff changeset
   399
 */
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   400
void NmHsWidget::setWidgetStateProperty(QString value)
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   401
{
43
hgs
parents: 23
diff changeset
   402
    NM_FUNCTION;
47
hgs
parents: 43
diff changeset
   403
    if (value == KNmHsWidgetStateCollapsed) {
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   404
        mIsExpanded = false;
47
hgs
parents: 43
diff changeset
   405
    }
hgs
parents: 43
diff changeset
   406
    else {
hgs
parents: 43
diff changeset
   407
        mIsExpanded = true;
hgs
parents: 43
diff changeset
   408
    }
hgs
parents: 43
diff changeset
   409
}
hgs
parents: 43
diff changeset
   410
hgs
parents: 43
diff changeset
   411
/*!
hgs
parents: 43
diff changeset
   412
 Returns widget expand/collapse state as string (needed by homescreen) 
hgs
parents: 43
diff changeset
   413
 */
hgs
parents: 43
diff changeset
   414
QString NmHsWidget::widgetStateProperty()
hgs
parents: 43
diff changeset
   415
{
hgs
parents: 43
diff changeset
   416
    NM_FUNCTION;
hgs
parents: 43
diff changeset
   417
    if (mIsExpanded) {
hgs
parents: 43
diff changeset
   418
        return KNmHsWidgetStateExpanded;
hgs
parents: 43
diff changeset
   419
    }
hgs
parents: 43
diff changeset
   420
    else {
hgs
parents: 43
diff changeset
   421
        return KNmHsWidgetStateCollapsed;
hgs
parents: 43
diff changeset
   422
    }
hgs
parents: 43
diff changeset
   423
}
hgs
parents: 43
diff changeset
   424
hgs
parents: 43
diff changeset
   425
/*!
hgs
parents: 43
diff changeset
   426
 Updates mMailRows list to include KMaxNumberOfMailsShown mail row widgets
hgs
parents: 43
diff changeset
   427
 /post mMailRows contains KMaxNumberOfMailsShown mailRows 
hgs
parents: 43
diff changeset
   428
 */
hgs
parents: 43
diff changeset
   429
void NmHsWidget::createMailRowsList()
hgs
parents: 43
diff changeset
   430
{
hgs
parents: 43
diff changeset
   431
    NM_FUNCTION;
hgs
parents: 43
diff changeset
   432
hgs
parents: 43
diff changeset
   433
    //make sure that there are as many email rows as needed
hgs
parents: 43
diff changeset
   434
    while (mMailRows.count() < KMaxNumberOfMailsShown) {
hgs
parents: 43
diff changeset
   435
        NmHsWidgetEmailRow *row = new NmHsWidgetEmailRow(this);
hgs
parents: 43
diff changeset
   436
        if (!row->setupUI()) {
hgs
parents: 43
diff changeset
   437
            NM_ERROR(1, "NmHsWidget::createMailRowsList row->setUpUI() fails");
hgs
parents: 43
diff changeset
   438
            //if setupUI fails no point to proceed
hgs
parents: 43
diff changeset
   439
            emit error();
hgs
parents: 43
diff changeset
   440
            return;
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   441
        }
47
hgs
parents: 43
diff changeset
   442
        connect(row, SIGNAL(mailViewerLaunchTriggered(const NmId&)), mEngine,
hgs
parents: 43
diff changeset
   443
            SLOT(launchMailAppMailViewer(const NmId&)));
hgs
parents: 43
diff changeset
   444
        connect(mDateObserver, SIGNAL(dateTimeChanged()), row, SLOT(updateDateTime()));
hgs
parents: 43
diff changeset
   445
        mMailRows.append(row);
hgs
parents: 43
diff changeset
   446
    }
hgs
parents: 43
diff changeset
   447
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   448
}
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   449
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   450
/*!
47
hgs
parents: 43
diff changeset
   451
 Updates the Layout to contain the right items
hgs
parents: 43
diff changeset
   452
 /param mailCount defines how many emails is to be shown
hgs
parents: 43
diff changeset
   453
 /post If widget is collapsed, the layout contains only titleRow widget.
hgs
parents: 43
diff changeset
   454
 If widget is expanded and mailCount is 0 layout will contain
hgs
parents: 43
diff changeset
   455
 titlerow & noMailsLabel. 
hgs
parents: 43
diff changeset
   456
 If widget is expanded and mailCount is greter
hgs
parents: 43
diff changeset
   457
 than zero, layout will contain titlerow and KMaxNumberOfMailsShown times
hgs
parents: 43
diff changeset
   458
 emailrow(s)
hgs
parents: 43
diff changeset
   459
 */
hgs
parents: 43
diff changeset
   460
void NmHsWidget::updateLayout(const int mailCount)
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   461
{
43
hgs
parents: 23
diff changeset
   462
    NM_FUNCTION;
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   463
47
hgs
parents: 43
diff changeset
   464
    if (mIsExpanded) {
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   465
        //set container height to content height 
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   466
        qreal contentHeight = KMaxNumberOfMailsShown
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   467
                * mMailRows.first()->maximumHeight();
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   468
        mContentContainer->setMaximumHeight(contentHeight);
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   469
        mContentContainer->setVisible(true);
47
hgs
parents: 43
diff changeset
   470
        if (mailCount == 0) {
hgs
parents: 43
diff changeset
   471
            addNoMailsLabelToLayout();
hgs
parents: 43
diff changeset
   472
            removeEmailRowsFromLayout();
hgs
parents: 43
diff changeset
   473
        }
hgs
parents: 43
diff changeset
   474
        else {
hgs
parents: 43
diff changeset
   475
            removeNoMailsLabelFromLayout();
hgs
parents: 43
diff changeset
   476
            addEmailRowsToLayout();
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   477
        }
47
hgs
parents: 43
diff changeset
   478
    }
hgs
parents: 43
diff changeset
   479
    else {
hgs
parents: 43
diff changeset
   480
        removeNoMailsLabelFromLayout();
hgs
parents: 43
diff changeset
   481
        removeEmailRowsFromLayout();
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   482
        mContentContainer->setVisible(false);
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   483
        mContentContainer->setMaximumHeight(0);        
47
hgs
parents: 43
diff changeset
   484
    }
hgs
parents: 43
diff changeset
   485
hgs
parents: 43
diff changeset
   486
    //resize the widget to new layout size
62
hgs
parents: 49
diff changeset
   487
    qreal totalHeight = mEmptySpaceContainer->preferredHeight() + mTitleRow->containerHeight() + mContentContainer->maximumHeight();
hgs
parents: 49
diff changeset
   488
    //set maximum sizes, otherwise widget will stay huge also when collapsed
hgs
parents: 49
diff changeset
   489
    setMaximumHeight(totalHeight);
hgs
parents: 49
diff changeset
   490
    mMainContainer->setMaximumHeight(totalHeight);
hgs
parents: 49
diff changeset
   491
    mWidgetContainer->setMaximumHeight(totalHeight - mEmptySpaceContainer->preferredHeight());
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   492
    //resize here or widget cannot draw mail rows when expanding
62
hgs
parents: 49
diff changeset
   493
    resize(mTitleRow->maximumWidth(), totalHeight);
hgs
parents: 49
diff changeset
   494
    mMainContainer->resize(mTitleRow->maximumWidth(), totalHeight);
hgs
parents: 49
diff changeset
   495
    mWidgetContainer->resize(mTitleRow->maximumWidth(), totalHeight - mEmptySpaceContainer->preferredHeight());
47
hgs
parents: 43
diff changeset
   496
hgs
parents: 43
diff changeset
   497
    updateMailRowsVisibility(mailCount);
hgs
parents: 43
diff changeset
   498
}
hgs
parents: 43
diff changeset
   499
hgs
parents: 43
diff changeset
   500
/*!
hgs
parents: 43
diff changeset
   501
 Updates mNoMailsLabel visibility based on widget state
hgs
parents: 43
diff changeset
   502
 /param mailCount defines how many mail rows is needed
hgs
parents: 43
diff changeset
   503
 /post if mail count is 0 and mIsExpanded equals true, then
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   504
 the mNoMailLabel is added to the mContentLayout. 
47
hgs
parents: 43
diff changeset
   505
 */
hgs
parents: 43
diff changeset
   506
void NmHsWidget::addNoMailsLabelToLayout()
hgs
parents: 43
diff changeset
   507
{
hgs
parents: 43
diff changeset
   508
    NM_FUNCTION;
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   509
47
hgs
parents: 43
diff changeset
   510
    if (mNoMailsLabel->isVisible() || mMailRows.isEmpty()) {
hgs
parents: 43
diff changeset
   511
        return;
hgs
parents: 43
diff changeset
   512
    }
hgs
parents: 43
diff changeset
   513
    //Add mNoMailsLabel to layout if not yet there and show it
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   514
    mContentLayout->addItem(mNoMailsLabel);
47
hgs
parents: 43
diff changeset
   515
    //resize the widget to new layout size
hgs
parents: 43
diff changeset
   516
    mNoMailsLabel->show();
hgs
parents: 43
diff changeset
   517
}
hgs
parents: 43
diff changeset
   518
hgs
parents: 43
diff changeset
   519
/*!
hgs
parents: 43
diff changeset
   520
 removeNoMailsLabelFromLayout removes mNoMailsLabel from the layout
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   521
 /post mNoMailsLabel is not in mContentLayout
47
hgs
parents: 43
diff changeset
   522
 */
hgs
parents: 43
diff changeset
   523
void NmHsWidget::removeNoMailsLabelFromLayout()
hgs
parents: 43
diff changeset
   524
{
hgs
parents: 43
diff changeset
   525
    NM_FUNCTION;
hgs
parents: 43
diff changeset
   526
    //remove mNoMailsLabel from Layout and hide it
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   527
    mContentLayout->removeItem(mNoMailsLabel);
47
hgs
parents: 43
diff changeset
   528
    mNoMailsLabel->hide();
hgs
parents: 43
diff changeset
   529
}
hgs
parents: 43
diff changeset
   530
hgs
parents: 43
diff changeset
   531
/*!
hgs
parents: 43
diff changeset
   532
 addEmailRowsToLayout adds every emailrow to the layout
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   533
 /post all elements in mMailRows are added to mContentLayout
47
hgs
parents: 43
diff changeset
   534
 */
hgs
parents: 43
diff changeset
   535
void NmHsWidget::addEmailRowsToLayout()
hgs
parents: 43
diff changeset
   536
{
hgs
parents: 43
diff changeset
   537
    NM_FUNCTION;
hgs
parents: 43
diff changeset
   538
    foreach(NmHsWidgetEmailRow *row, mMailRows)
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   539
        {
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   540
            mContentLayout->addItem(row);
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   541
        }
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   542
}
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   543
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   544
/*!
47
hgs
parents: 43
diff changeset
   545
 removeEmailRowsFromLayout removes every emailrow from the layout
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   546
 /post none of the elements in mMailRows are in mContentLayout
47
hgs
parents: 43
diff changeset
   547
 */
hgs
parents: 43
diff changeset
   548
void NmHsWidget::removeEmailRowsFromLayout()
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   549
{
43
hgs
parents: 23
diff changeset
   550
    NM_FUNCTION;
47
hgs
parents: 43
diff changeset
   551
    foreach(NmHsWidgetEmailRow *row, mMailRows)
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   552
        {
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   553
            mContentLayout->removeItem(row);
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   554
        }
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   555
}
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   556
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   557
/*!
47
hgs
parents: 43
diff changeset
   558
 Updates mail row visibilities in static widget
hgs
parents: 43
diff changeset
   559
 /param visibleCount defines how many items do have mail data
hgs
parents: 43
diff changeset
   560
 /post all row items having mail data are visible, other rows are hidden
hgs
parents: 43
diff changeset
   561
 */
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   562
void NmHsWidget::updateMailRowsVisibility(const int visibleCount)
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   563
{
43
hgs
parents: 23
diff changeset
   564
    NM_FUNCTION;
47
hgs
parents: 43
diff changeset
   565
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   566
    // set visible as many rows as requested by visibleCount param
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   567
    bool isVisible;
47
hgs
parents: 43
diff changeset
   568
hgs
parents: 43
diff changeset
   569
    for (int i = 0; i < mMailRows.count(); i++) {
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   570
        isVisible = false;
47
hgs
parents: 43
diff changeset
   571
        if ((mIsExpanded) && (i < visibleCount)) {
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   572
            isVisible = true;
47
hgs
parents: 43
diff changeset
   573
        }
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   574
        mMailRows.at(i)->setVisible(isVisible);
47
hgs
parents: 43
diff changeset
   575
    }
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   576
}
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   577
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   578
/*!
47
hgs
parents: 43
diff changeset
   579
 onEngineException (NmHsWidgetEmailEngineExceptionCode exc)
hgs
parents: 43
diff changeset
   580
 signals widget to be finalized
hgs
parents: 43
diff changeset
   581
 /param exc exception type
hgs
parents: 43
diff changeset
   582
 */
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   583
void NmHsWidget::onEngineException(const int& exc)
47
hgs
parents: 43
diff changeset
   584
{
43
hgs
parents: 23
diff changeset
   585
    NM_FUNCTION;
47
hgs
parents: 43
diff changeset
   586
    switch (exc) {
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   587
        case (NmEngineExcAccountDeleted):
47
hgs
parents: 43
diff changeset
   588
            emit finished(); //succesful ending
hgs
parents: 43
diff changeset
   589
            break;
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   590
        case (NmEngineExcFailure):
47
hgs
parents: 43
diff changeset
   591
            emit error(); //failure
hgs
parents: 43
diff changeset
   592
            break;
hgs
parents: 43
diff changeset
   593
        default:
hgs
parents: 43
diff changeset
   594
            break;
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   595
    }
47
hgs
parents: 43
diff changeset
   596
}