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