emailuis/nmailui/src/nmapplication.cpp
author hgs
Fri, 03 Sep 2010 14:07:42 +0300
changeset 66 084b5b1f02a7
parent 62 a8c646b56683
child 68 83cc6bae1de8
permissions -rw-r--r--
201035
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
/*
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
     2
 * Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies).
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
     3
 * All rights reserved.
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
     4
 * This component and the accompanying materials are made available
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
     5
 * under the terms of "Eclipse Public License v1.0"
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
     6
 * which accompanies this distribution, and is available
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
     7
 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
     8
 *
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
     9
 * Initial Contributors:
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
    10
 * Nokia Corporation - initial contribution.
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
    11
 *
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
    12
 * Contributors:
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
    13
 *
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
    14
 * Description:
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
    15
 *
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
    16
 */
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    17
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    18
#include "nmuiheaders.h"
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    19
#include <e32base.h>
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    20
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
    21
static const QString NmSendServiceName = "nmail.com.nokia.symbian.IFileShare";
56
hgs
parents: 51
diff changeset
    22
static const QString NmActivityName = "EmailInboxView";
66
hgs
parents: 62
diff changeset
    23
static const int NmErrorNoteDelay = 300000;
56
hgs
parents: 51
diff changeset
    24
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    25
/*!
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
    26
    \class NmApplication
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
    27
    \brief Application class, creates main window and handles view switching.
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    28
*/
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    29
57
hgs
parents: 56
diff changeset
    30
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    31
/*!
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
    32
    Constructor.
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    33
*/
66
hgs
parents: 62
diff changeset
    34
NmApplication::NmApplication(int &argc, char *argv[], Hb::ApplicationFlags flags)
hgs
parents: 62
diff changeset
    35
: HbApplication(argc,argv,flags),
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
    36
  mMainWindow(NULL),
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
    37
  mViewStack(NULL),
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
    38
  mActiveViewId(NmUiViewNone),
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
    39
  mUiEngine(NULL),
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
    40
  mBackAction(NULL),
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
    41
  mExtensionManager(NULL),
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
    42
  mMbListModel(NULL),
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
    43
  mServiceViewId(NmUiViewNone),
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
    44
  mForegroundService(false),
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
    45
  mEffects(NULL),
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
    46
  mAttaManager(NULL),
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
    47
  mSettingsViewLauncher(NULL),
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
    48
  mViewReady(false),
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
    49
  mQueryDialog(NULL),
62
hgs
parents: 57
diff changeset
    50
  mBackButtonPressed(false),
66
hgs
parents: 62
diff changeset
    51
  mApplicationHidden(false),
hgs
parents: 62
diff changeset
    52
  mErrorNoteTimer(NULL)
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    53
{
66
hgs
parents: 62
diff changeset
    54
    // Load the translation file.
hgs
parents: 62
diff changeset
    55
    QTranslator *translator = new QTranslator(this);
hgs
parents: 62
diff changeset
    56
    QString lang = QLocale::system().name();
hgs
parents: 62
diff changeset
    57
    QString appName = "mail_";
hgs
parents: 62
diff changeset
    58
    QString path = "Z:/resource/qt/translations/";
hgs
parents: 62
diff changeset
    59
    translator->load(appName + lang, path);
hgs
parents: 62
diff changeset
    60
    installTranslator(translator);
hgs
parents: 62
diff changeset
    61
    setApplicationName(hbTrId("txt_mail_title_mail"));
hgs
parents: 62
diff changeset
    62
    
hgs
parents: 62
diff changeset
    63
    quint64 accountId = 0;
hgs
parents: 62
diff changeset
    64
    QString activateId = this->activateId();
hgs
parents: 62
diff changeset
    65
    if (activateReason() == Hb::ActivationReasonActivity &&
hgs
parents: 62
diff changeset
    66
        activateId.startsWith(NmActivityName) ) {
hgs
parents: 62
diff changeset
    67
        QString accountIdString = activateId.mid(NmActivityName.length());
hgs
parents: 62
diff changeset
    68
        accountId = accountIdString.toULongLong();
hgs
parents: 62
diff changeset
    69
    }
hgs
parents: 62
diff changeset
    70
            
43
hgs
parents: 40
diff changeset
    71
    TRAP_IGNORE(mUiEngine = NmUiEngine::instance());
66
hgs
parents: 62
diff changeset
    72
        
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    73
    // Create network access manager and cache for application use.
43
hgs
parents: 40
diff changeset
    74
    mNetManager = new NmViewerViewNetManager(*mUiEngine);
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    75
    QNetworkDiskCache *cache = new QNetworkDiskCache();
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
    76
    cache->setCacheDirectory(
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
    77
        QDesktopServices::storageLocation(QDesktopServices::CacheLocation));
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    78
    mNetManager->setCache(cache);
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
    79
    
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    80
    createMainWindow();
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
    81
    
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
    82
    // Attachment manager can be shared between viewer and editor.
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
    83
    // The application class has the ownership.
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
    84
    mAttaManager = new NmAttachmentManager(*mUiEngine);
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
    85
    
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    86
    mSendServiceInterface =
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
    87
        new NmSendServiceInterface(NmSendServiceName, NULL, *mUiEngine, this);
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
    88
    mSendServiceInterface2 =
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
    89
        new NmSendServiceInterface(emailFullServiceNameSend, NULL, *mUiEngine, this);
43
hgs
parents: 40
diff changeset
    90
    mUriServiceInterface =
hgs
parents: 40
diff changeset
    91
        new NmUriServiceInterface(NULL, *mUiEngine, this);
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    92
    mMailboxServiceInterface =
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
    93
        new NmMailboxServiceInterface(NULL, *mUiEngine, this);
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    94
    mViewerServiceInterface =
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
    95
        new NmViewerServiceInterface(NULL, this, *mUiEngine);
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
    96
    
47
hgs
parents: 44
diff changeset
    97
    if(accountId != 0) {
hgs
parents: 44
diff changeset
    98
        QVariant mailbox;
57
hgs
parents: 56
diff changeset
    99
        mailbox.setValue(accountId);
47
hgs
parents: 44
diff changeset
   100
        mMailboxServiceInterface->displayInboxByMailboxId(mailbox);
hgs
parents: 44
diff changeset
   101
    }
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   102
    
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   103
    mEffects = new NmUiEffects(*mMainWindow);
57
hgs
parents: 56
diff changeset
   104
    
66
hgs
parents: 62
diff changeset
   105
    QObject::connect(this, SIGNAL(activate()), this, SLOT(activityActivated()));
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   106
}
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   107
57
hgs
parents: 56
diff changeset
   108
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   109
/*!
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   110
    Destructor.
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   111
*/
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   112
NmApplication::~NmApplication()
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   113
{
57
hgs
parents: 56
diff changeset
   114
    // Remove the event filter early since catching application activated/
hgs
parents: 56
diff changeset
   115
    // deactivated events now may cause a crash.
hgs
parents: 56
diff changeset
   116
    QCoreApplication::instance()->removeEventFilter(this);
hgs
parents: 56
diff changeset
   117
47
hgs
parents: 44
diff changeset
   118
    if (mQueryDialog) {
43
hgs
parents: 40
diff changeset
   119
        delete mQueryDialog;
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   120
        mQueryDialog = NULL;
43
hgs
parents: 40
diff changeset
   121
    }
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   122
    
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   123
    delete mSendServiceInterface;
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   124
    delete mSendServiceInterface2;
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   125
    delete mUriServiceInterface;
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   126
    delete mMailboxServiceInterface;
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   127
    delete mViewerServiceInterface;
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   128
    
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   129
    resetViewStack();
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   130
    delete mViewStack;
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   131
    
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   132
    NmIcons::freeIcons();
57
hgs
parents: 56
diff changeset
   133
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   134
    NmUiEngine::releaseInstance(mUiEngine);
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   135
    mUiEngine = NULL;
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   136
    
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   137
    delete mBackAction;
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   138
    
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   139
    // Workaround: the main window has to be closed (hidden) before deleting
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   140
    // the extension manager in order to prevent the main window's title bar
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   141
    // from showing when the application is closed.
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   142
    if (mMainWindow) {
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   143
        // Workaround: assert failure may happen if an open main window is
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   144
        // deleted.
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   145
        mMainWindow->close();
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   146
    }
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   147
    
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   148
    delete mExtensionManager;
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   149
    
47
hgs
parents: 44
diff changeset
   150
    if (mNetManager) {
hgs
parents: 44
diff changeset
   151
        if (mNetManager->cache()) {
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   152
            mNetManager->cache()->clear();
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   153
        }
57
hgs
parents: 56
diff changeset
   154
hgs
parents: 56
diff changeset
   155
        delete mNetManager;
hgs
parents: 56
diff changeset
   156
        mNetManager = NULL;
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   157
    }
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   158
    
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   159
    // Effects need to be deleted before MainWindow.
43
hgs
parents: 40
diff changeset
   160
    delete mEffects;
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   161
    delete mMainWindow;
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   162
    delete mAttaManager;
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   163
    delete mSettingsViewLauncher;
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   164
}
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   165
57
hgs
parents: 56
diff changeset
   166
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   167
/*!
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   168
    Main application window creation.
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   169
*/
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   170
void NmApplication::createMainWindow()
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   171
{
43
hgs
parents: 40
diff changeset
   172
    NM_FUNCTION;
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   173
    
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   174
    bool service = XQServiceUtil::isService();
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   175
    
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   176
    // Register custom widget files.
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   177
    HbStyleLoader::registerFilePath(":nmmessagelistviewitem.widgetml");
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   178
    HbStyleLoader::registerFilePath(":nmmessagelistviewitem.css");
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   179
    HbStyleLoader::registerFilePath(":nmviewerheader.widgetml");
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   180
    HbStyleLoader::registerFilePath(":nmviewerheader.css");
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   181
    
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   182
    // Create main window.
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   183
    mMainWindow = new HbMainWindow();
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   184
    
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   185
    // Connect to lazy loading signal.
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   186
    QObject::connect(mMainWindow, SIGNAL(viewReady ()),
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   187
                     this, SLOT(viewReady()));
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   188
    
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   189
    // Create extension manager.
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   190
    mExtensionManager = new NmUiExtensionManager();
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   191
    
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   192
    // Create view stack.
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   193
    mViewStack = new QStack<NmBaseView*>;
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   194
    
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   195
    // Create back action and connect it to prepareForPopView().
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   196
    if (mMainWindow) {
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   197
        mBackAction = new HbAction(Hb::BackNaviAction,this);
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   198
        connect(mBackAction,
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   199
                SIGNAL(triggered()),
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   200
                this,
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   201
                SLOT(prepareForPopView()));
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   202
        
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   203
        // Show mainwindow.
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   204
        // Services will active it when the view is ready.
40
hgs
parents: 23
diff changeset
   205
        if (!service) {
hgs
parents: 23
diff changeset
   206
            mMainWindow->show();
hgs
parents: 23
diff changeset
   207
        }
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   208
    }
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   209
    
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   210
    // Asynchronous operation completion related notifications.
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   211
    connect(mUiEngine,
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   212
            SIGNAL(operationCompleted(const NmOperationCompletionEvent &)),
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   213
            this,
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   214
            SLOT(handleOperationCompleted(const NmOperationCompletionEvent &)));
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   215
    
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   216
    mMbListModel = &mUiEngine->mailboxListModel();
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   217
    
62
hgs
parents: 57
diff changeset
   218
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   219
    // ----------------------------------------------------------------------
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   220
    
47
hgs
parents: 44
diff changeset
   221
    if (mMainWindow) {
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   222
        // Start to filter main window events to get "end key" event in all
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   223
        // possible situations. Using event()is not enough to catch the event
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   224
        // as it is only called if the view widget has the focus. Note: if
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   225
        // key capturing (xqkeycapture.h) is required it is probably best to
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   226
        // implement an own QMainWindow class and do the capturing there, not
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   227
        // in the views.
47
hgs
parents: 44
diff changeset
   228
        mMainWindow->installEventFilter(this);
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   229
        // Optimize the custom paint functions.
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   230
        // Currently effects to NmViewerHeader::paint() and
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   231
        // NmAttachmentListWidget::paint().
47
hgs
parents: 44
diff changeset
   232
        mMainWindow->setOptimizationFlag(QGraphicsView::DontSavePainterState);    
hgs
parents: 44
diff changeset
   233
    }
56
hgs
parents: 51
diff changeset
   234
    
57
hgs
parents: 56
diff changeset
   235
	// Install the event filter in order to receive ApplicationActivate/Deactivate
hgs
parents: 56
diff changeset
   236
    // events.
56
hgs
parents: 51
diff changeset
   237
    QCoreApplication::instance()->installEventFilter(this);
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   238
}
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   239
57
hgs
parents: 56
diff changeset
   240
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   241
/*!
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   242
    Slot. React to view ready signal and call current view method.
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   243
*/
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   244
void NmApplication::viewReady()
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   245
{
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   246
    mViewReady = true;
57
hgs
parents: 56
diff changeset
   247
47
hgs
parents: 44
diff changeset
   248
    if (mViewStack && !mViewStack->isEmpty()) {
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   249
    	NmBaseView *currentView = mViewStack->top();
57
hgs
parents: 56
diff changeset
   250
47
hgs
parents: 44
diff changeset
   251
        if (currentView) {
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   252
            currentView->viewReady();
51
hgs
parents: 49
diff changeset
   253
            emit applicationReady();
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   254
        }
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   255
    }
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   256
}
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   257
57
hgs
parents: 56
diff changeset
   258
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   259
/*!
57
hgs
parents: 56
diff changeset
   260
    Event filter. End key is filtered from the main window and either the view
hgs
parents: 56
diff changeset
   261
    takes case or the app is exited by default.
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   262
*/
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   263
bool NmApplication::eventFilter(QObject *obj, QEvent *event)
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   264
{
47
hgs
parents: 44
diff changeset
   265
    bool consumed(false);
57
hgs
parents: 56
diff changeset
   266
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   267
    if (obj && obj == mMainWindow && event && event->type() == QEvent::KeyPress) {
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   268
        QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   269
        if (keyEvent->key() == Qt::Key_No) {
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   270
            // End key, the "red" key.
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   271
            // Exit application if no pending operations are on-going.
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   272
        }
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   273
    }
57
hgs
parents: 56
diff changeset
   274
    else if (event && event->type() == QEvent::ApplicationActivate) {
56
hgs
parents: 51
diff changeset
   275
        NM_COMMENT("NmApplication::eventFilter ApplicationActivate");
62
hgs
parents: 57
diff changeset
   276
        mApplicationHidden = false;
57
hgs
parents: 56
diff changeset
   277
		// Update task switcher name & screenshot, we could have activated into some other mailbox
hgs
parents: 56
diff changeset
   278
        updateActivity();
56
hgs
parents: 51
diff changeset
   279
    }
57
hgs
parents: 56
diff changeset
   280
    else if (event && event->type() == QEvent::ApplicationDeactivate) {
56
hgs
parents: 51
diff changeset
   281
        NM_COMMENT("NmApplication::eventFilter ApplicationDeactivate");
57
hgs
parents: 56
diff changeset
   282
        // Update the screenshot in the taskswitcher to represent current state
62
hgs
parents: 57
diff changeset
   283
        if (!mApplicationHidden) {
hgs
parents: 57
diff changeset
   284
            updateActivity();
hgs
parents: 57
diff changeset
   285
        }
56
hgs
parents: 51
diff changeset
   286
        // hide the sync indicator when app goes to background
hgs
parents: 51
diff changeset
   287
        mUiEngine->enableSyncIndicator(false);
hgs
parents: 51
diff changeset
   288
    }
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   289
    
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   290
    if (!consumed) {
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   291
        consumed = QObject::eventFilter(obj, event);
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   292
    }
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   293
    
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   294
    return consumed;
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   295
}
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   296
57
hgs
parents: 56
diff changeset
   297
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   298
/*!
62
hgs
parents: 57
diff changeset
   299
    Pushes the given view into the view stack. The new view is also activated
hgs
parents: 57
diff changeset
   300
    and shown. If the view stack contains other views, the one on the top is
hgs
parents: 57
diff changeset
   301
    hidden.
hgs
parents: 57
diff changeset
   302
hgs
parents: 57
diff changeset
   303
    \param newView The view to push into the stack.
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   304
*/
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   305
void NmApplication::pushView(NmBaseView *newView)
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   306
{
47
hgs
parents: 44
diff changeset
   307
    if (newView && mViewStack) {
62
hgs
parents: 57
diff changeset
   308
        NM_COMMENT("NmApplication::pushView(): The given view is valid.");
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   309
        newView->setNavigationAction(mBackAction);
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   310
        
62
hgs
parents: 57
diff changeset
   311
        // Store the view to be hidden.
hgs
parents: 57
diff changeset
   312
        NmBaseView *viewToHide(NULL);
hgs
parents: 57
diff changeset
   313
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   314
        if (!mViewStack->isEmpty()) {
62
hgs
parents: 57
diff changeset
   315
            // The stack contains at least one other view.
hgs
parents: 57
diff changeset
   316
            viewToHide = mViewStack->top();
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   317
        }
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   318
		else {
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   319
			// viewReady should be informed immediately.
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   320
			if (mViewReady) {
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   321
				newView->viewReady();
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   322
			}
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   323
		}
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   324
        
62
hgs
parents: 57
diff changeset
   325
        // Activate the new view.
hgs
parents: 57
diff changeset
   326
    	NM_COMMENT("NmApplication::pushView(): Adding the view into the stack.");
hgs
parents: 57
diff changeset
   327
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   328
        mMainWindow->addView(newView);
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   329
        mViewStack->push(newView);
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   330
        mMainWindow->setCurrentView(newView);
62
hgs
parents: 57
diff changeset
   331
        mActiveViewId = newView->nmailViewId();
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   332
        
62
hgs
parents: 57
diff changeset
   333
        // Set the orientation of the toolbar.
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   334
        HbToolBar *tb = newView->toolBar();
62
hgs
parents: 57
diff changeset
   335
47
hgs
parents: 44
diff changeset
   336
        if (tb) {
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   337
            tb->setOrientation(Qt::Horizontal);
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   338
        }
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   339
        
62
hgs
parents: 57
diff changeset
   340
        // Hide the old view.
hgs
parents: 57
diff changeset
   341
        NM_COMMENT("NmApplication::pushView(): Removing the previous view.");
hgs
parents: 57
diff changeset
   342
hgs
parents: 57
diff changeset
   343
        if (viewToHide) {
hgs
parents: 57
diff changeset
   344
            mMainWindow->removeView(viewToHide);
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   345
        }
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   346
    }
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   347
}
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   348
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   349
/*!
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   350
    Ask from view that is it ok to pop view. This kind of 2-phase popView is
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   351
    needed because view may show query dialog for user response.
40
hgs
parents: 23
diff changeset
   352
 */
hgs
parents: 23
diff changeset
   353
void NmApplication::prepareForPopView()
hgs
parents: 23
diff changeset
   354
{
47
hgs
parents: 44
diff changeset
   355
    if (mViewStack && mViewStack->size() > 0) {
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   356
        // Get view pointer.
40
hgs
parents: 23
diff changeset
   357
        NmBaseView *view = mViewStack->top();
47
hgs
parents: 44
diff changeset
   358
        if (view){
hgs
parents: 44
diff changeset
   359
			NmUiViewId topViewId = view->nmailViewId();
hgs
parents: 44
diff changeset
   360
			
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   361
			// We must know in popView, are we coming with back button from
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   362
			// message view to prevent the send animation.
47
hgs
parents: 44
diff changeset
   363
			if (topViewId == NmUiViewMessageEditor) {
hgs
parents: 44
diff changeset
   364
				mBackButtonPressed = true;
hgs
parents: 44
diff changeset
   365
			}
hgs
parents: 44
diff changeset
   366
            
hgs
parents: 44
diff changeset
   367
            // View will call/signal popView if exitting is ok.
hgs
parents: 44
diff changeset
   368
            view->okToExitView();        
hgs
parents: 44
diff changeset
   369
        }
43
hgs
parents: 40
diff changeset
   370
    }
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   371
    // If the view stack is now empty quit the app. This happens also when
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   372
    // the app has been started as a service
47
hgs
parents: 44
diff changeset
   373
    else if (mViewStack && mViewStack->size() == 0) {
40
hgs
parents: 23
diff changeset
   374
        exitApplication();
hgs
parents: 23
diff changeset
   375
    }
hgs
parents: 23
diff changeset
   376
}
hgs
parents: 23
diff changeset
   377
57
hgs
parents: 56
diff changeset
   378
40
hgs
parents: 23
diff changeset
   379
/*!
51
hgs
parents: 49
diff changeset
   380
     Hide the application
hgs
parents: 49
diff changeset
   381
*/
hgs
parents: 49
diff changeset
   382
void NmApplication::hideApplication()
hgs
parents: 49
diff changeset
   383
{
62
hgs
parents: 57
diff changeset
   384
    mApplicationHidden = true;
hgs
parents: 57
diff changeset
   385
    
51
hgs
parents: 49
diff changeset
   386
    // Hide the application
hgs
parents: 49
diff changeset
   387
    XQServiceUtil::toBackground(true);
hgs
parents: 49
diff changeset
   388
hgs
parents: 49
diff changeset
   389
    // hide the sync indicator as well
hgs
parents: 49
diff changeset
   390
    mUiEngine->enableSyncIndicator(false);
56
hgs
parents: 51
diff changeset
   391
    
hgs
parents: 51
diff changeset
   392
    // Hide the mail from the task switcher 
hgs
parents: 51
diff changeset
   393
    TsTaskSettings taskSettings;
hgs
parents: 51
diff changeset
   394
    taskSettings.setVisibility(false);
hgs
parents: 51
diff changeset
   395
    
hgs
parents: 51
diff changeset
   396
    // Remove also the mailbox item from the task switcher
66
hgs
parents: 62
diff changeset
   397
    activityManager()->removeActivity(NmActivityName);
51
hgs
parents: 49
diff changeset
   398
}
hgs
parents: 49
diff changeset
   399
57
hgs
parents: 56
diff changeset
   400
51
hgs
parents: 49
diff changeset
   401
/*!
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   402
    Pop view from view stack. View object is deleted.
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   403
*/
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   404
void NmApplication::popView()
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   405
{
47
hgs
parents: 44
diff changeset
   406
    if (mViewStack && mViewStack->size() > 0) {
hgs
parents: 44
diff changeset
   407
        NmBaseView *view = mViewStack->top();    
hgs
parents: 44
diff changeset
   408
        if (view) {
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   409
            // Get top view id.
47
hgs
parents: 44
diff changeset
   410
            NmUiViewId topViewId = view->nmailViewId();
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   411
            
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   412
            // Prepare for send animation if returing from editor and message
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   413
            // has been sent.
47
hgs
parents: 44
diff changeset
   414
            if (topViewId == NmUiViewMessageEditor && mUiEngine->isSendingMessage()) {
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   415
				// If we are coming from message editor with back button.
47
hgs
parents: 44
diff changeset
   416
				// do not prepare the send animation.
hgs
parents: 44
diff changeset
   417
				if (!mBackButtonPressed) {
hgs
parents: 44
diff changeset
   418
					mEffects->prepareEffect(NmUiEffects::NmEditorSendMessageAnimation);
hgs
parents: 44
diff changeset
   419
				}
hgs
parents: 44
diff changeset
   420
	        }
hgs
parents: 44
diff changeset
   421
            mBackButtonPressed = false;
51
hgs
parents: 49
diff changeset
   422
hgs
parents: 49
diff changeset
   423
            // Move the application to background if closing the message list view
hgs
parents: 49
diff changeset
   424
            if (topViewId == NmUiViewMessageList && mViewStack->size() == 1) {
66
hgs
parents: 62
diff changeset
   425
                
hgs
parents: 62
diff changeset
   426
                // if the application has been started as embedded service,
hgs
parents: 62
diff changeset
   427
                // we must close it. Otherwise we cannot return back to the calling application.
hgs
parents: 62
diff changeset
   428
                if (!XQServiceUtil::isEmbedded()) {
hgs
parents: 62
diff changeset
   429
                    hideApplication();
hgs
parents: 62
diff changeset
   430
                    return;
hgs
parents: 62
diff changeset
   431
                }
51
hgs
parents: 49
diff changeset
   432
            }
hgs
parents: 49
diff changeset
   433
47
hgs
parents: 44
diff changeset
   434
            mViewStack->pop();
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   435
            // Call custom exit function.
47
hgs
parents: 44
diff changeset
   436
            view->aboutToExitView();
hgs
parents: 44
diff changeset
   437
            // Remove view from stack.
hgs
parents: 44
diff changeset
   438
            mMainWindow->removeView(view);
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   439
            
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   440
            // If we were in editor and sent a message, pop viewer from stack
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   441
            // first so we can go straight to mail list.
47
hgs
parents: 44
diff changeset
   442
            if (!mViewStack->isEmpty() && topViewId == NmUiViewMessageEditor &&
hgs
parents: 44
diff changeset
   443
                mUiEngine->isSendingMessage() &&
hgs
parents: 44
diff changeset
   444
                mViewStack->top()->nmailViewId() == NmUiViewMessageViewer) {
hgs
parents: 44
diff changeset
   445
                NmBaseView *tmpView = mViewStack->pop();
hgs
parents: 44
diff changeset
   446
                mMainWindow->removeView(tmpView);
hgs
parents: 44
diff changeset
   447
                delete tmpView;
hgs
parents: 44
diff changeset
   448
                tmpView = NULL;
hgs
parents: 44
diff changeset
   449
            }
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   450
            
47
hgs
parents: 44
diff changeset
   451
            if (!mViewStack->isEmpty()) {
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   452
                // Activate next view in stack.
47
hgs
parents: 44
diff changeset
   453
                NmBaseView *showView = mViewStack->top();
hgs
parents: 44
diff changeset
   454
                mMainWindow->addView(showView);
hgs
parents: 44
diff changeset
   455
                mMainWindow->setCurrentView(showView);
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   456
                // Store activated view id.
47
hgs
parents: 44
diff changeset
   457
                mActiveViewId=showView->nmailViewId();
hgs
parents: 44
diff changeset
   458
                // Perform send animation if requested.
hgs
parents: 44
diff changeset
   459
                mEffects->startEffect(NmUiEffects::NmEditorSendMessageAnimation);
hgs
parents: 44
diff changeset
   460
            }
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   461
            
47
hgs
parents: 44
diff changeset
   462
            delete view;
hgs
parents: 44
diff changeset
   463
            view = NULL;
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   464
            
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   465
            // If view was started as service, move the app now to the
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   466
            // background, unless it was started when the app was already in
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   467
            // foreground.
47
hgs
parents: 44
diff changeset
   468
            if (mServiceViewId == topViewId) {
hgs
parents: 44
diff changeset
   469
                mServiceViewId = NmUiViewNone;
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   470
                NM_COMMENT("NmApplication::popView() : returned from service view.");
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   471
                // If started as embedded or while the app was in foreground,
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   472
                // do not hide the app.
47
hgs
parents: 44
diff changeset
   473
                if (!XQServiceUtil::isEmbedded() &&
hgs
parents: 44
diff changeset
   474
                    !mForegroundService) {
hgs
parents: 44
diff changeset
   475
                    XQServiceUtil::toBackground(true);
hgs
parents: 44
diff changeset
   476
                }
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   477
            }
40
hgs
parents: 23
diff changeset
   478
        }
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   479
    }
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   480
    
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   481
    // If the view stack is now empty quit the app. This happens also when
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   482
    // the app has been started as a service.
47
hgs
parents: 44
diff changeset
   483
    if (mViewStack && mViewStack->size() == 0) {
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   484
        exitApplication();
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   485
    }
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   486
}
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   487
57
hgs
parents: 56
diff changeset
   488
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   489
/*!
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   490
    Reset view stack. Remove and destroy view objects.
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   491
*/
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   492
void NmApplication::resetViewStack()
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   493
{
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   494
    if (mViewStack && !mViewStack->isEmpty()) {
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   495
	    int viewCount = mViewStack->count();
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   496
        // Pop and destroy all views
47
hgs
parents: 44
diff changeset
   497
	    for (int i=0 ; i < viewCount ; i++) {
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   498
		    NmBaseView *view = mViewStack->pop();
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   499
            mMainWindow->removeView(view);
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   500
            delete view;
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   501
        }
47
hgs
parents: 44
diff changeset
   502
	    mActiveViewId = NmUiViewNone;
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   503
    }
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   504
}
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   505
57
hgs
parents: 56
diff changeset
   506
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   507
/*!
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   508
    Function activates view based on viewId parameter. If requested view is
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   509
    already open, it is requested to reload. Otherwise view object is created
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   510
    and pushed to view stack.
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   511
*/
47
hgs
parents: 44
diff changeset
   512
void NmApplication::enterNmUiView(NmUiStartParam *startParam)
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   513
{
43
hgs
parents: 40
diff changeset
   514
    NM_FUNCTION;
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   515
    
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   516
    // Check the validity of start parameter object.
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   517
    if (startParam) {
56
hgs
parents: 51
diff changeset
   518
    
hgs
parents: 51
diff changeset
   519
        mCurrentMailboxId = startParam->mailboxId();
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   520
        
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   521
        if (startParam->service() && mMainWindow) {
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   522
			// When the message list is started as a service previous views
62
hgs
parents: 57
diff changeset
   523
            // are removed from the stack. Open editors are closed. Also
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   524
            // if the view is same than the new one, keep it open (reload the
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   525
            // content).
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   526
            
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   527
		    // Reset the foreground service flag while popping the views.
44
hgs
parents: 43
diff changeset
   528
		    bool previousForegroundService = mForegroundService;
hgs
parents: 43
diff changeset
   529
		    mForegroundService = true;
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   530
		    
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   531
		    // At least one view must remain in the stack.
47
hgs
parents: 44
diff changeset
   532
			while (mViewStack->count( )> 1) {
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   533
			    NmUiViewId topId = mViewStack->top()->nmailViewId();
47
hgs
parents: 44
diff changeset
   534
			    if (topId != NmUiViewMessageEditor &&
hgs
parents: 44
diff changeset
   535
			        topId != NmUiViewMailboxList &&
hgs
parents: 44
diff changeset
   536
			        topId != startParam->viewId()) {
40
hgs
parents: 23
diff changeset
   537
			        prepareForPopView();
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   538
			    }
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   539
			    else {
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   540
			        // Editor or mailbox list in the top. Stop the loop.
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   541
			        break;
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   542
			    }
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   543
			}
44
hgs
parents: 43
diff changeset
   544
			mForegroundService = previousForegroundService;
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   545
        }
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   546
        
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   547
        // Check whether requested view is already active and if so, ask it
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   548
        // to reload contents with new start parameter data. Do not reuse the
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   549
        // view if started as service to editor view (ShareUI).
47
hgs
parents: 44
diff changeset
   550
        if (mActiveViewId == startParam->viewId() &&
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   551
        	(!startParam->service() || mActiveViewId!=NmUiViewMessageEditor)) {
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   552
            mViewStack->top()->reloadViewContents(startParam);
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   553
        }
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   554
        else {
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   555
            switch (startParam->viewId()) {
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   556
                case NmUiViewMailboxList:
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   557
                {
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   558
                    NmMailboxListView *mbListView = new NmMailboxListView(
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   559
                    		*this, startParam, *mUiEngine,
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   560
                    		*mMbListModel, new HbDocumentLoader(mMainWindow));
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   561
                    pushView(mbListView);
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   562
                }
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   563
                break;
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   564
                case NmUiViewMessageList:
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   565
                {
62
hgs
parents: 57
diff changeset
   566
                    // Check the topmost view. If it is an editor, save to draft and close it.
hgs
parents: 57
diff changeset
   567
                    if (startParam->service() && !mViewStack->isEmpty() && 
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   568
                        mViewStack->top()->nmailViewId()==NmUiViewMessageEditor) {
62
hgs
parents: 57
diff changeset
   569
                        QMetaObject::invokeMethod(mViewStack->top(),
hgs
parents: 57
diff changeset
   570
                            "safeToDraft", Qt::DirectConnection);
hgs
parents: 57
diff changeset
   571
                        popView();
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   572
                    }
62
hgs
parents: 57
diff changeset
   573
hgs
parents: 57
diff changeset
   574
                    NmMessageListModel *messageListModel =
hgs
parents: 57
diff changeset
   575
                        &mUiEngine->messageListModel(startParam->mailboxId(),
hgs
parents: 57
diff changeset
   576
                                                     startParam->folderId());
hgs
parents: 57
diff changeset
   577
                    NmMessageListView *msgList =
hgs
parents: 57
diff changeset
   578
                        new NmMessageListView(*this, startParam, *mUiEngine,
hgs
parents: 57
diff changeset
   579
                                              *mMbListModel, messageListModel,
hgs
parents: 57
diff changeset
   580
                                              new HbDocumentLoader(mMainWindow));
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   581
                    pushView(msgList);
62
hgs
parents: 57
diff changeset
   582
                    
hgs
parents: 57
diff changeset
   583
                    // Inform other processes about this event.
hgs
parents: 57
diff changeset
   584
                    NmUiEventsNotifier::notifyViewStateChanged(NmUiEventsNotifier::NmViewShownEvent,
hgs
parents: 57
diff changeset
   585
                                                               NmUiViewMessageList,
hgs
parents: 57
diff changeset
   586
                                                               startParam->mailboxId());
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   587
                }
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   588
                break;
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   589
                case NmUiViewMessageSearchList:
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   590
                {
62
hgs
parents: 57
diff changeset
   591
                    // Check the topmost view. If it is an editor, save to draft and close it.
hgs
parents: 57
diff changeset
   592
                    if (startParam->service() && !mViewStack->isEmpty() && 
hgs
parents: 57
diff changeset
   593
                        mViewStack->top()->nmailViewId()==NmUiViewMessageEditor) {
hgs
parents: 57
diff changeset
   594
                        QMetaObject::invokeMethod(mViewStack->top(),
hgs
parents: 57
diff changeset
   595
                            "safeToDraft", Qt::DirectConnection);
hgs
parents: 57
diff changeset
   596
                        popView();
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   597
                    }
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   598
                    
40
hgs
parents: 23
diff changeset
   599
                    NmMessageListModel &model =
hgs
parents: 23
diff changeset
   600
                        mUiEngine->messageListModelForSearch(startParam->mailboxId());
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   601
                    
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   602
                    NmMessageSearchListView *searchListView = new NmMessageSearchListView(
40
hgs
parents: 23
diff changeset
   603
                        *this, startParam, *mUiEngine, model,
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   604
                        new HbDocumentLoader(mMainWindow));
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   605
                    
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   606
                    pushView(searchListView);
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   607
                }
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   608
                break;
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   609
                case NmUiViewMessageViewer:
43
hgs
parents: 40
diff changeset
   610
                    pushView(new NmViewerView(*this, startParam, *mUiEngine,
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   611
                            mMainWindow, *mAttaManager));
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   612
                    break;
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   613
                case NmUiViewMessageEditor:
62
hgs
parents: 57
diff changeset
   614
                    // Check the topmost view. If it is an editor, save to draft and close it.
hgs
parents: 57
diff changeset
   615
                    if (startParam->service() && !mViewStack->isEmpty() && 
hgs
parents: 57
diff changeset
   616
                        mViewStack->top()->nmailViewId()==NmUiViewMessageEditor) {
hgs
parents: 57
diff changeset
   617
                        QMetaObject::invokeMethod(mViewStack->top(),
hgs
parents: 57
diff changeset
   618
                            "safeToDraft", Qt::DirectConnection);
hgs
parents: 57
diff changeset
   619
                        popView();
hgs
parents: 57
diff changeset
   620
                    }
43
hgs
parents: 40
diff changeset
   621
                    pushView(new NmEditorView(*this, startParam, *mUiEngine, *mAttaManager));
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   622
                    break;
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   623
                default:
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   624
                    // Reset view stack and exit application.
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   625
                    delete startParam;
47
hgs
parents: 44
diff changeset
   626
                    startParam = NULL;
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   627
                    resetViewStack();
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   628
                    break;
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   629
            }
44
hgs
parents: 43
diff changeset
   630
        }
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   631
        
44
hgs
parents: 43
diff changeset
   632
        if (startParam && startParam->service()) {
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   633
            // Store the view id that was launched as service.
44
hgs
parents: 43
diff changeset
   634
            mServiceViewId = mActiveViewId;
hgs
parents: 43
diff changeset
   635
		}
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   636
    }
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   637
}
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   638
57
hgs
parents: 56
diff changeset
   639
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   640
/*!
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   641
    Function can be used from views to exit the application. View stack is
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   642
    cleared. Views can connect exit menu selection to this slot.
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   643
*/
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   644
void NmApplication::exitApplication()
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   645
{
43
hgs
parents: 40
diff changeset
   646
    NM_FUNCTION;
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   647
    
66
hgs
parents: 62
diff changeset
   648
    activityManager()->removeActivity(NmActivityName);
56
hgs
parents: 51
diff changeset
   649
    
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   650
    delete mSendServiceInterface;
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   651
    mSendServiceInterface = NULL;
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   652
    delete mSendServiceInterface2;
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   653
    mSendServiceInterface2 = NULL;
43
hgs
parents: 40
diff changeset
   654
    delete mUriServiceInterface;
hgs
parents: 40
diff changeset
   655
    mUriServiceInterface = NULL;
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   656
    delete mMailboxServiceInterface;
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   657
    mMailboxServiceInterface = NULL;
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   658
    delete mViewerServiceInterface;
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   659
    mViewerServiceInterface = NULL;
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   660
    resetViewStack();
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   661
    qApp->quit();
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   662
}
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   663
57
hgs
parents: 56
diff changeset
   664
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   665
/*!
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   666
   Exit the application in the next event loop.
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   667
*/
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   668
void NmApplication::delayedExitApplication()
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   669
{
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   670
    // Exit the application in the next event loop.
47
hgs
parents: 44
diff changeset
   671
    QMetaObject::invokeMethod(this, "exitApplication", Qt::QueuedConnection);
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   672
}
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   673
57
hgs
parents: 56
diff changeset
   674
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   675
/*!
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   676
    Getter for main window instance.
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   677
*/
47
hgs
parents: 44
diff changeset
   678
HbMainWindow *NmApplication::mainWindow()
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   679
{
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   680
    return mMainWindow;
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   681
}
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   682
57
hgs
parents: 56
diff changeset
   683
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   684
/*!
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   685
    Getter for main UI extension manager.
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   686
*/
47
hgs
parents: 44
diff changeset
   687
NmUiExtensionManager &NmApplication::extManager()
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   688
{
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   689
    return *mExtensionManager;
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   690
}
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   691
57
hgs
parents: 56
diff changeset
   692
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   693
/*!
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   694
    Getter for network access manager.
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   695
*/
47
hgs
parents: 44
diff changeset
   696
NmViewerViewNetManager &NmApplication::networkAccessManager()
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   697
{
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   698
    return *mNetManager;
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   699
}
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   700
57
hgs
parents: 56
diff changeset
   701
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   702
/*!
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   703
    Get the screen size. Function returns curtent screen size.
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   704
*/
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   705
QSize NmApplication::screenSize()
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   706
{
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   707
    QSize ret(0,0);
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   708
    if (mMainWindow){
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   709
        HbDeviceProfile currentP = HbDeviceProfile::current();
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   710
        HbDeviceProfile altP(currentP.alternateProfileName());
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   711
        QSize curPSize = currentP.logicalSize();
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   712
        QSize altPSize = altP.logicalSize();
47
hgs
parents: 44
diff changeset
   713
        if (mMainWindow->orientation() == Qt::Horizontal) {
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   714
            // Get wide profile size in landscape.
47
hgs
parents: 44
diff changeset
   715
            if (curPSize.width() > altPSize.width()) {
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   716
                ret = curPSize;
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   717
            }
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   718
            else{
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   719
                ret = altPSize;
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   720
            }
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   721
        }
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   722
        else {
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   723
            // Get narrow profile size in portrait.
47
hgs
parents: 44
diff changeset
   724
            if (curPSize.width() < altPSize.width()) {
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   725
                ret = curPSize;
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   726
            }
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   727
            else{
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   728
                ret = altPSize;
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   729
            }
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   730
        }
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   731
    }
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   732
    return ret;
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   733
}
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   734
57
hgs
parents: 56
diff changeset
   735
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   736
/*!
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   737
    Handles all asynchronous operation's completions at UI level.
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   738
*/
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   739
void NmApplication::handleOperationCompleted(const NmOperationCompletionEvent &event)
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   740
{
47
hgs
parents: 44
diff changeset
   741
    if (event.mCompletionCode != NmNoError && event.mCompletionCode != NmCancelError) {
hgs
parents: 44
diff changeset
   742
        if (event.mOperationType == Synch && event.mCompletionCode == NmAuthenticationError) {
hgs
parents: 44
diff changeset
   743
            mLastOperationMailbox = event.mMailboxId;
hgs
parents: 44
diff changeset
   744
            if (mQueryDialog) {
43
hgs
parents: 40
diff changeset
   745
                delete mQueryDialog;
47
hgs
parents: 44
diff changeset
   746
                mQueryDialog = NULL;
43
hgs
parents: 40
diff changeset
   747
            }
hgs
parents: 40
diff changeset
   748
            mQueryDialog = NmUtilities::displayQuestionNote(hbTrId("txt_mail_dialog_address_or_password_incorrect"),
44
hgs
parents: 43
diff changeset
   749
                                                    this, SLOT(launchSettings(HbAction*)));
43
hgs
parents: 40
diff changeset
   750
        }
47
hgs
parents: 44
diff changeset
   751
        if (event.mOperationType == Synch && event.mCompletionCode == NmServerConnectionError) {
43
hgs
parents: 40
diff changeset
   752
            mLastOperationMailbox=event.mMailboxId;
47
hgs
parents: 44
diff changeset
   753
            if (mQueryDialog) {
43
hgs
parents: 40
diff changeset
   754
                delete mQueryDialog;
47
hgs
parents: 44
diff changeset
   755
                mQueryDialog = NULL;
43
hgs
parents: 40
diff changeset
   756
            }
hgs
parents: 40
diff changeset
   757
            mQueryDialog = NmUtilities::displayQuestionNote(hbTrId("txt_mail_dialog_server_settings_incorrect"),
44
hgs
parents: 43
diff changeset
   758
                                                    this, SLOT(launchSettings(HbAction*)));
43
hgs
parents: 40
diff changeset
   759
        }
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   760
        // Following applies to all operation/event types.
47
hgs
parents: 44
diff changeset
   761
        if (event.mCompletionCode == NmConnectionError) {
66
hgs
parents: 62
diff changeset
   762
            // Create error note delayer timer when used for the first time
hgs
parents: 62
diff changeset
   763
            if (!mErrorNoteTimer) {
hgs
parents: 62
diff changeset
   764
                mErrorNoteTimer = new QTimer(this);
hgs
parents: 62
diff changeset
   765
            }
hgs
parents: 62
diff changeset
   766
            // Check whether mailbox id has changed, stop
hgs
parents: 62
diff changeset
   767
            // timer in that case and note will be displayed even
hgs
parents: 62
diff changeset
   768
            // before 5min delay has passed
hgs
parents: 62
diff changeset
   769
            if (mLastErrorMailboxId != event.mMailboxId) {
hgs
parents: 62
diff changeset
   770
                mErrorNoteTimer->stop();
hgs
parents: 62
diff changeset
   771
            }
hgs
parents: 62
diff changeset
   772
            // Store mailbox id
hgs
parents: 62
diff changeset
   773
            mLastErrorMailboxId = event.mMailboxId;
hgs
parents: 62
diff changeset
   774
            // Show error note if timer is not active, e.g 5 minutes 
hgs
parents: 62
diff changeset
   775
            // have passed since last "mail connection error".
hgs
parents: 62
diff changeset
   776
            if (!mErrorNoteTimer->isActive()) {
hgs
parents: 62
diff changeset
   777
                NmUtilities::displayErrorNote(hbTrId("txt_mail_dialog_mail_connection_error"));            
hgs
parents: 62
diff changeset
   778
                // Start timer with 5 min timeout
hgs
parents: 62
diff changeset
   779
                mErrorNoteTimer->start(NmErrorNoteDelay);
hgs
parents: 62
diff changeset
   780
            }
43
hgs
parents: 40
diff changeset
   781
        }
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   782
    }
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   783
}
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   784
57
hgs
parents: 56
diff changeset
   785
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   786
/*!
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   787
    Launches settings view of the specified mailbox.
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   788
*/
43
hgs
parents: 40
diff changeset
   789
void NmApplication::launchSettings(HbAction* action)
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   790
{
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   791
    // Check whether yes button was pressed.
43
hgs
parents: 40
diff changeset
   792
    if (mQueryDialog&& action == mQueryDialog->actions().at(0)) {
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   793
        // Create settingslauncher if doesn't exist.
43
hgs
parents: 40
diff changeset
   794
        if(!mSettingsViewLauncher) {
hgs
parents: 40
diff changeset
   795
            mSettingsViewLauncher = new NmSettingsViewLauncher();
hgs
parents: 40
diff changeset
   796
            }
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   797
        // Mailboxname required.
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   798
        NmMailboxMetaData *mailboxMetaData = mUiEngine->mailboxById(mLastOperationMailbox); // No ownership.
47
hgs
parents: 44
diff changeset
   799
        if( mailboxMetaData ) {
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   800
            // Launch.
47
hgs
parents: 44
diff changeset
   801
            mSettingsViewLauncher->launchSettingsView(mLastOperationMailbox, mailboxMetaData->name());
44
hgs
parents: 43
diff changeset
   802
        }
hgs
parents: 43
diff changeset
   803
    }
43
hgs
parents: 40
diff changeset
   804
}
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   805
57
hgs
parents: 56
diff changeset
   806
43
hgs
parents: 40
diff changeset
   807
/*!
62
hgs
parents: 57
diff changeset
   808
   Check the foreground status of the application 
hgs
parents: 57
diff changeset
   809
   \return true if the application is in the foreground
hgs
parents: 57
diff changeset
   810
*/
hgs
parents: 57
diff changeset
   811
bool NmApplication::isForeground() const
hgs
parents: 57
diff changeset
   812
{
hgs
parents: 57
diff changeset
   813
    // At the moment there is no good way to check the foreground state.
hgs
parents: 57
diff changeset
   814
    QWindowSurface *surface = mMainWindow->windowSurface();
hgs
parents: 57
diff changeset
   815
    return (surface != 0);
hgs
parents: 57
diff changeset
   816
}
hgs
parents: 57
diff changeset
   817
hgs
parents: 57
diff changeset
   818
/*!
43
hgs
parents: 40
diff changeset
   819
	Stores the visibility state, e.g. when the service was launched.
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   820
	\return true if the app was visible.
43
hgs
parents: 40
diff changeset
   821
*/
hgs
parents: 40
diff changeset
   822
bool NmApplication::updateVisibilityState()
hgs
parents: 40
diff changeset
   823
{
62
hgs
parents: 57
diff changeset
   824
	mForegroundService = isForeground();
49
00c7ae862740 201025_2
hgs
parents: 47
diff changeset
   825
	NM_COMMENT(QString("NmApplication::updateVisibilityState() : mForegroundService == %1").arg(mForegroundService));
43
hgs
parents: 40
diff changeset
   826
	return mForegroundService;
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   827
}
56
hgs
parents: 51
diff changeset
   828
57
hgs
parents: 56
diff changeset
   829
56
hgs
parents: 51
diff changeset
   830
/*!
57
hgs
parents: 56
diff changeset
   831
    Update the thumbnail in the task switcher.
56
hgs
parents: 51
diff changeset
   832
*/
hgs
parents: 51
diff changeset
   833
void NmApplication::updateActivity()
hgs
parents: 51
diff changeset
   834
{
hgs
parents: 51
diff changeset
   835
    NmMailboxMetaData *meta = mUiEngine->mailboxById(mCurrentMailboxId);
66
hgs
parents: 62
diff changeset
   836
    
hgs
parents: 62
diff changeset
   837
    // This will ensure that when service is started as a embedded service and a mail 
hgs
parents: 62
diff changeset
   838
    // process already exists the task activity will show the embedded service inside the 
hgs
parents: 62
diff changeset
   839
    // calling processes activity and the already running mail process in its own activity.
hgs
parents: 62
diff changeset
   840
    if(!XQServiceUtil::isService() || !XQServiceUtil::isEmbedded()) {
hgs
parents: 62
diff changeset
   841
        if (meta) {
hgs
parents: 62
diff changeset
   842
            TsTaskSettings tasksettings;
hgs
parents: 62
diff changeset
   843
            tasksettings.setVisibility(false);
hgs
parents: 62
diff changeset
   844
            QVariantHash metadata;
hgs
parents: 62
diff changeset
   845
            metadata.insert(ActivityScreenshotKeyword, QPixmap::grabWidget(mainWindow(), mainWindow()->rect()));
hgs
parents: 62
diff changeset
   846
            metadata.insert(ActivityApplicationName, meta->name());
hgs
parents: 62
diff changeset
   847
            metadata.insert(ActivityVisibility, true);
hgs
parents: 62
diff changeset
   848
            activityManager()->removeActivity(NmActivityName);
hgs
parents: 62
diff changeset
   849
            activityManager()->addActivity(NmActivityName, QVariant(), metadata);
hgs
parents: 62
diff changeset
   850
        }
hgs
parents: 62
diff changeset
   851
        else {
hgs
parents: 62
diff changeset
   852
            activityManager()->removeActivity(NmActivityName);
hgs
parents: 62
diff changeset
   853
            TsTaskSettings tasksettings;
hgs
parents: 62
diff changeset
   854
            tasksettings.setVisibility(true);
56
hgs
parents: 51
diff changeset
   855
        }
hgs
parents: 51
diff changeset
   856
    }
hgs
parents: 51
diff changeset
   857
}
57
hgs
parents: 56
diff changeset
   858
hgs
parents: 56
diff changeset
   859
/*!
hgs
parents: 56
diff changeset
   860
	Switch to activated mailbox
hgs
parents: 56
diff changeset
   861
*/
hgs
parents: 56
diff changeset
   862
void NmApplication::activityActivated()
hgs
parents: 56
diff changeset
   863
{
66
hgs
parents: 62
diff changeset
   864
    quint64 accountId(0);
hgs
parents: 62
diff changeset
   865
    QString activateId = this->activateId();
hgs
parents: 62
diff changeset
   866
    if (activateReason() == Hb::ActivationReasonActivity &&
hgs
parents: 62
diff changeset
   867
            activateId.startsWith(NmActivityName) ) {
hgs
parents: 62
diff changeset
   868
        QString accountIdString = activateId.mid(NmActivityName.length());
hgs
parents: 62
diff changeset
   869
        accountId = accountIdString.toULongLong();
hgs
parents: 62
diff changeset
   870
        QVariant mailbox;
hgs
parents: 62
diff changeset
   871
        mailbox.setValue(accountId);
hgs
parents: 62
diff changeset
   872
        mMailboxServiceInterface->displayInboxByMailboxId(mailbox);
57
hgs
parents: 56
diff changeset
   873
    }
hgs
parents: 56
diff changeset
   874
}
hgs
parents: 56
diff changeset
   875