emailservices/nmailagent/src/nmmailagent.cpp
author hgs
Fri, 23 Jul 2010 19:09:50 +0300
changeset 56 15bc1d5d6267
parent 51 d845db10c0d4
child 62 a8c646b56683
permissions -rw-r--r--
201029
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
/*
51
hgs
parents: 48
diff changeset
     2
 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
hgs
parents: 48
diff changeset
     3
 * All rights reserved.
hgs
parents: 48
diff changeset
     4
 * This component and the accompanying materials are made available
hgs
parents: 48
diff changeset
     5
 * under the terms of "Eclipse Public License v1.0"
hgs
parents: 48
diff changeset
     6
 * which accompanies this distribution, and is available
hgs
parents: 48
diff changeset
     7
 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
hgs
parents: 48
diff changeset
     8
 *
hgs
parents: 48
diff changeset
     9
 * Initial Contributors:
hgs
parents: 48
diff changeset
    10
 * Nokia Corporation - initial contribution.
hgs
parents: 48
diff changeset
    11
 *
hgs
parents: 48
diff changeset
    12
 * Contributors:
hgs
parents: 48
diff changeset
    13
 *
hgs
parents: 48
diff changeset
    14
 * Description: Mail agent is responsible of monitoring mail accounts. It activates
hgs
parents: 48
diff changeset
    15
 *              and deactivates indicator depending on received events. Mail agent is
hgs
parents: 48
diff changeset
    16
 *              also responsible of monitoring silence mode, playing alert tone and vibrating
hgs
parents: 48
diff changeset
    17
 *              phone when new mail is received.
hgs
parents: 48
diff changeset
    18
 *
hgs
parents: 48
diff changeset
    19
 */
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    20
43
hgs
parents: 40
diff changeset
    21
#include "emailtrace.h"
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    22
#include "nmmailagentheaders.h"
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    23
#include "nmmailagent.h"
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    24
44
hgs
parents: 43
diff changeset
    25
#include <xqaiwdeclplat.h>
hgs
parents: 43
diff changeset
    26
#include <xqapplicationmanager.h>
hgs
parents: 43
diff changeset
    27
#include <xqaiwrequest.h>
hgs
parents: 43
diff changeset
    28
hgs
parents: 43
diff changeset
    29
#include <xqsettingsmanager.h>
hgs
parents: 43
diff changeset
    30
#include <xqcentralrepositoryutils.h>
43
hgs
parents: 40
diff changeset
    31
#include <xqsystemtoneservice.h>
48
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
    32
#include <xqsettingskey.h>
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
    33
#include <ProfileEngineInternalCRKeys.h>
43
hgs
parents: 40
diff changeset
    34
51
hgs
parents: 48
diff changeset
    35
// CONSTANTS
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
    36
const int NmAgentIndicatorNotSet = -1;
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
    37
const int NmAgentAlertToneTimer = 60000; // 60s
44
hgs
parents: 43
diff changeset
    38
const int NmAgentDefaultVibraDuration = 1000; // 1 second
47
hgs
parents: 44
diff changeset
    39
static const quint32 NmRepositoryId = 0x2002C326;
43
hgs
parents: 40
diff changeset
    40
static const QString NmMailboxIndicatorType = "com.nokia.nmail.indicatorplugin_%1/1.0";
hgs
parents: 40
diff changeset
    41
static const QString NmSendIndicatorName = "com.nokia.nmail.indicatorplugin.send/1.0";
hgs
parents: 40
diff changeset
    42
static const QString NmUnreadIndicatorName = "com.nokia.nmail.indicatorplugin.unread/1.0";
48
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
    43
const XQCentralRepositorySettingsKey NmSilenceModeKey(KCRUidProfileEngine.iUid, KProEngSilenceMode);
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
    44
const int NmSilenceModeOn = 1;
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
    45
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
    46
/*!
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
    47
    Helper method for finding out if XQSettingsKey and XQCentralRepositorySettingsKey points to
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
    48
    same key.
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
    49
51
hgs
parents: 48
diff changeset
    50
    \param settingKey XQSettingsKey
hgs
parents: 48
diff changeset
    51
    \param cenrepSettingKey XQCentralRepositorySettingsKey
hgs
parents: 48
diff changeset
    52
    \return <code>true</code> if target, uid and key matches otherwise returns <code>false</code>
hgs
parents: 48
diff changeset
    53
 */
48
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
    54
bool keysEqual(const XQSettingsKey& settingKey, const XQCentralRepositorySettingsKey& cenrepSettingKey)
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
    55
{
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
    56
    return ((settingKey.target() == cenrepSettingKey.target()) &&
51
hgs
parents: 48
diff changeset
    57
        (settingKey.uid() == cenrepSettingKey.uid()) &&
hgs
parents: 48
diff changeset
    58
        (settingKey.key() == cenrepSettingKey.key()));
48
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
    59
}
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    60
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    61
51
hgs
parents: 48
diff changeset
    62
hgs
parents: 48
diff changeset
    63
/*!
hgs
parents: 48
diff changeset
    64
    \class NmMailboxInfo
hgs
parents: 48
diff changeset
    65
hgs
parents: 48
diff changeset
    66
    \brief Main class for storing mailbox data.
hgs
parents: 48
diff changeset
    67
 */
hgs
parents: 48
diff changeset
    68
NmMailboxInfo::NmMailboxInfo()
hgs
parents: 48
diff changeset
    69
: mId(0),
hgs
parents: 48
diff changeset
    70
  mIndicatorIndex(NmAgentIndicatorNotSet),
hgs
parents: 48
diff changeset
    71
  mInboxFolderId(0),
hgs
parents: 48
diff changeset
    72
  mOutboxFolderId(0),
hgs
parents: 48
diff changeset
    73
  mSyncState(SyncComplete),
hgs
parents: 48
diff changeset
    74
  mConnectState(Disconnected),
hgs
parents: 48
diff changeset
    75
  mInboxCreatedMessages(0),
hgs
parents: 48
diff changeset
    76
  mInboxChangedMessages(0),
hgs
parents: 48
diff changeset
    77
  mInboxDeletedMessages(0),
hgs
parents: 48
diff changeset
    78
  mOutboxMails(0),
hgs
parents: 48
diff changeset
    79
  mActive(false),
hgs
parents: 48
diff changeset
    80
  mInboxActive(false)
hgs
parents: 48
diff changeset
    81
  {
56
hgs
parents: 51
diff changeset
    82
      NM_FUNCTION;
51
hgs
parents: 48
diff changeset
    83
  }
hgs
parents: 48
diff changeset
    84
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    85
/*!
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    86
    \class NmMailAgent
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    87
51
hgs
parents: 48
diff changeset
    88
    \brief Main class for receiving email events. Activates and deactivates indicator.
hgs
parents: 48
diff changeset
    89
 */
hgs
parents: 48
diff changeset
    90
NmMailAgent::NmMailAgent() :
hgs
parents: 48
diff changeset
    91
     mIndicator(NULL),
hgs
parents: 48
diff changeset
    92
     mSystemTone(NULL),
hgs
parents: 48
diff changeset
    93
     mPluginFactory(NULL),
hgs
parents: 48
diff changeset
    94
     mVibra(NULL),
hgs
parents: 48
diff changeset
    95
     mAlertToneAllowed(true),
hgs
parents: 48
diff changeset
    96
     mLastOutboxCount(0),
hgs
parents: 48
diff changeset
    97
     mUnreadIndicatorActive(false),
hgs
parents: 48
diff changeset
    98
     mSettingManager(NULL),
hgs
parents: 48
diff changeset
    99
     mSilenceMode(NmSilenceModeOn)  // by default silent mode is on
hgs
parents: 48
diff changeset
   100
     {
56
hgs
parents: 51
diff changeset
   101
     NM_FUNCTION;
51
hgs
parents: 48
diff changeset
   102
     }
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   103
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   104
/*!
51
hgs
parents: 48
diff changeset
   105
    Delayed start.
hgs
parents: 48
diff changeset
   106
 */
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   107
void NmMailAgent::delayedStart()
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   108
{
43
hgs
parents: 40
diff changeset
   109
    NM_FUNCTION;
hgs
parents: 40
diff changeset
   110
51
hgs
parents: 48
diff changeset
   111
    if (!init()) {
hgs
parents: 48
diff changeset
   112
        // Initialisation failed. Quit the agent.
hgs
parents: 48
diff changeset
   113
        QCoreApplication::exit(1);
hgs
parents: 48
diff changeset
   114
    }
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   115
}
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   116
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   117
/*!
51
hgs
parents: 48
diff changeset
   118
    Initialise the agent.
hgs
parents: 48
diff changeset
   119
hgs
parents: 48
diff changeset
   120
    \return true if succesfully started.
hgs
parents: 48
diff changeset
   121
 */
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   122
bool NmMailAgent::init()
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   123
{
43
hgs
parents: 40
diff changeset
   124
    NM_FUNCTION;
hgs
parents: 40
diff changeset
   125
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   126
    mPluginFactory = NmDataPluginFactory::instance();
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   127
    if (!mPluginFactory) {
43
hgs
parents: 40
diff changeset
   128
        NM_ERROR(1,"NmMailAgent::init(): PluginFactory not created");
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   129
        return false;
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   130
    }
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   131
48
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   132
    // Check status of silent mode.
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   133
    delete mSettingManager;
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   134
    mSettingManager = NULL;
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   135
    mSettingManager = new XQSettingsManager();
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   136
    QVariant silenceMode = mSettingManager->readItemValue(NmSilenceModeKey,
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   137
        XQSettingsManager::TypeInt);
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   138
    mSilenceMode = silenceMode.toInt();
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   139
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   140
    // Start monitoring silence mode key.
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   141
    bool monitoring(mSettingManager->startMonitoring(NmSilenceModeKey, XQSettingsManager::TypeInt));
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   142
    monitoring &= connect(mSettingManager,
51
hgs
parents: 48
diff changeset
   143
                          SIGNAL(valueChanged(const XQSettingsKey &, const QVariant &)),
48
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   144
                          this,
51
hgs
parents: 48
diff changeset
   145
                          SLOT(valueChanged(const XQSettingsKey &, const QVariant &)),
48
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   146
                          Qt::UniqueConnection);
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   147
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   148
    // If silence mode monitoring can't be started, then change silence mode on to be sure
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   149
    // that no tone is played if silence mode is turned on at somepoint.
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   150
    if (!monitoring) {
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   151
        mSilenceMode = NmSilenceModeOn;
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   152
    }
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   153
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   154
    delete mSystemTone;
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   155
    mSystemTone = NULL;
47
hgs
parents: 44
diff changeset
   156
    mSystemTone = new XQSystemToneService();
hgs
parents: 44
diff changeset
   157
48
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   158
    delete mIndicator;
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   159
    mIndicator = NULL;
43
hgs
parents: 40
diff changeset
   160
    mIndicator = new HbIndicator();
51
hgs
parents: 48
diff changeset
   161
    connect(mIndicator,SIGNAL(userActivated(const QString &, const QVariantMap &)),
hgs
parents: 48
diff changeset
   162
        this, SLOT(indicatorActivated(const QString &, const QVariantMap &)));
43
hgs
parents: 40
diff changeset
   163
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   164
    QList<QObject*> *plugins = mPluginFactory->pluginInstances();
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   165
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   166
    foreach (QObject *plugin, *plugins) {
51
hgs
parents: 48
diff changeset
   167
        if (plugin) {
hgs
parents: 48
diff changeset
   168
            // Start listening events
hgs
parents: 48
diff changeset
   169
            connect(plugin, SIGNAL(mailboxEvent(NmMailboxEvent, const QList<NmId> &)),
hgs
parents: 48
diff changeset
   170
                    this, SLOT(handleMailboxEvent(NmMailboxEvent, const QList<NmId> &)),
hgs
parents: 48
diff changeset
   171
                    Qt::UniqueConnection);
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   172
51
hgs
parents: 48
diff changeset
   173
            connect(plugin, SIGNAL(messageEvent(
hgs
parents: 48
diff changeset
   174
                        NmMessageEvent, const NmId &, const QList<NmId> &, const NmId &)),
hgs
parents: 48
diff changeset
   175
                    this, SLOT(handleMessageEvent(
hgs
parents: 48
diff changeset
   176
                        NmMessageEvent, const NmId &, const QList<NmId> &, const NmId &)),
hgs
parents: 48
diff changeset
   177
                    Qt::UniqueConnection);
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   178
51
hgs
parents: 48
diff changeset
   179
            connect(plugin, SIGNAL(syncStateEvent(NmSyncState, const NmOperationCompletionEvent &)),
hgs
parents: 48
diff changeset
   180
                    this, SLOT(handleSyncStateEvent(NmSyncState, const NmOperationCompletionEvent &)),
hgs
parents: 48
diff changeset
   181
                Qt::UniqueConnection);
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   182
51
hgs
parents: 48
diff changeset
   183
            connect(plugin, SIGNAL(connectionEvent(NmConnectState, const NmId, int)),
hgs
parents: 48
diff changeset
   184
                    this, SLOT(handleConnectionEvent(NmConnectState, const NmId, int)),
hgs
parents: 48
diff changeset
   185
                    Qt::UniqueConnection);
hgs
parents: 48
diff changeset
   186
        }
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   187
    }
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   188
44
hgs
parents: 43
diff changeset
   189
    // Construct the vibra interface instance.
48
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   190
    delete mVibra;
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   191
    mVibra = NULL;
44
hgs
parents: 43
diff changeset
   192
    TRAP_IGNORE(mVibra = CHWRMVibra::NewL());
hgs
parents: 43
diff changeset
   193
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   194
    // load all current mailboxes
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   195
    initMailboxStatus();
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   196
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   197
    return true;
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   198
}
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   199
51
hgs
parents: 48
diff changeset
   200
/*!
hgs
parents: 48
diff changeset
   201
    Destructor of NmMailAgent.
hgs
parents: 48
diff changeset
   202
 */
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   203
NmMailAgent::~NmMailAgent()
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   204
{
43
hgs
parents: 40
diff changeset
   205
    NM_FUNCTION;
hgs
parents: 40
diff changeset
   206
51
hgs
parents: 48
diff changeset
   207
    delete mIndicator;
44
hgs
parents: 43
diff changeset
   208
    delete mVibra;
47
hgs
parents: 44
diff changeset
   209
    delete mSystemTone;
48
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   210
    if (mSettingManager) {
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   211
        mSettingManager->stopMonitoring(NmSilenceModeKey);
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   212
        delete mSettingManager;
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   213
    }
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   214
    qDeleteAll(mMailboxes);
44
hgs
parents: 43
diff changeset
   215
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   216
    NmDataPluginFactory::releaseInstance(mPluginFactory);
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   217
}
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   218
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   219
/*!
51
hgs
parents: 48
diff changeset
   220
    Initialize the mailbox list with the current state.
hgs
parents: 48
diff changeset
   221
 */
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   222
void NmMailAgent::initMailboxStatus()
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   223
{
43
hgs
parents: 40
diff changeset
   224
    NM_FUNCTION;
hgs
parents: 40
diff changeset
   225
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   226
    QList<NmMailbox*> mailboxes;
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   227
    QList<QObject*> *plugins = mPluginFactory->pluginInstances();
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   228
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   229
    foreach(QObject* pluginObject, *plugins) {
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   230
        NmDataPluginInterface *plugin =
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   231
            mPluginFactory->interfaceInstance(pluginObject);
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   232
        if (plugin) {
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   233
            plugin->listMailboxes(mailboxes);
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   234
        }
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   235
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   236
        // Add the indicators
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   237
        // Must be made in reverse order to show them properly in
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   238
        // HbIndicator menu
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   239
        QListIterator<NmMailbox *> i(mailboxes);
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   240
        i.toBack();
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   241
        while (i.hasPrevious()) {
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   242
            const NmMailbox *mailbox = i.previous();
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   243
            if (mailbox) {
51
hgs
parents: 48
diff changeset
   244
                NmMailboxInfo *mailboxInfo = createMailboxInfo(*mailbox, plugin);
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   245
                if (mailboxInfo) {
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   246
                    bool activate = updateUnreadCount(mailbox->id(), *mailboxInfo);
44
hgs
parents: 43
diff changeset
   247
                    bool wasActive = isMailboxActive(mailbox->id());
hgs
parents: 43
diff changeset
   248
                    if (activate) {
51
hgs
parents: 48
diff changeset
   249
                        if (!wasActive) {
44
hgs
parents: 43
diff changeset
   250
                            // do not activate the mailbox if it was left as hidden last time
hgs
parents: 43
diff changeset
   251
                            activate = false;
hgs
parents: 43
diff changeset
   252
                        }
hgs
parents: 43
diff changeset
   253
                        else {
hgs
parents: 43
diff changeset
   254
                            // otherwise, activate the mailbox and show inbox state
hgs
parents: 43
diff changeset
   255
                            mailboxInfo->mInboxActive = true;
hgs
parents: 43
diff changeset
   256
                        }
hgs
parents: 43
diff changeset
   257
                    }
hgs
parents: 43
diff changeset
   258
51
hgs
parents: 48
diff changeset
   259
                    mailboxInfo->mOutboxMails = getOutboxCount(mailbox->id(),
hgs
parents: 48
diff changeset
   260
                        mailboxInfo->mOutboxFolderId);
44
hgs
parents: 43
diff changeset
   261
                    if (mailboxInfo->mOutboxMails > 0 && wasActive) {
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   262
                        activate = true;
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   263
                    }
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   264
51
hgs
parents: 48
diff changeset
   265
                    // Create indicator for visible mailboxes
hgs
parents: 48
diff changeset
   266
                    updateMailboxState(mailbox->id(), activate, false);
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   267
                }
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   268
            }
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   269
        }
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   270
        qDeleteAll(mailboxes);
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   271
    }
44
hgs
parents: 43
diff changeset
   272
    updateUnreadIndicator();
43
hgs
parents: 40
diff changeset
   273
    updateSendIndicator();
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   274
}
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   275
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   276
/*!
51
hgs
parents: 48
diff changeset
   277
    Get mailbox unread count in inbox folder.
hgs
parents: 48
diff changeset
   278
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   279
    \param mailboxId id of the mailbox
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   280
    \param mailboxInfo contains the list of unread messages
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   281
    \return true if new unread mails was found
51
hgs
parents: 48
diff changeset
   282
 */
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   283
bool NmMailAgent::updateUnreadCount(const NmId &mailboxId, NmMailboxInfo &mailboxInfo)
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   284
{
43
hgs
parents: 40
diff changeset
   285
    NM_FUNCTION;
hgs
parents: 40
diff changeset
   286
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   287
    int newUnreadMessages(0);
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   288
    NmDataPluginInterface *plugin = mPluginFactory->interfaceInstance(mailboxId);
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   289
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   290
    if (plugin) {
51
hgs
parents: 48
diff changeset
   291
        NmId inboxId = mailboxInfo.mInboxFolderId.id();
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   292
51
hgs
parents: 48
diff changeset
   293
        // Inbox folder ID may be still unknown
hgs
parents: 48
diff changeset
   294
        if (inboxId == 0) {
hgs
parents: 48
diff changeset
   295
            mailboxInfo.mInboxFolderId = plugin->getStandardFolderId(mailboxId, NmFolderInbox);
hgs
parents: 48
diff changeset
   296
            inboxId = mailboxInfo.mInboxFolderId.id();
hgs
parents: 48
diff changeset
   297
        }
hgs
parents: 48
diff changeset
   298
hgs
parents: 48
diff changeset
   299
        // get list of messages in inbox
hgs
parents: 48
diff changeset
   300
        QList<NmMessageEnvelope*> messageList;
hgs
parents: 48
diff changeset
   301
        plugin->listMessages(mailboxId, inboxId, messageList);
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   302
51
hgs
parents: 48
diff changeset
   303
        QList<NmId> newUnreadMessageIdList;
hgs
parents: 48
diff changeset
   304
        foreach (const NmMessageEnvelope* envelope, messageList) {
hgs
parents: 48
diff changeset
   305
            // if the message is not read, it is "unread"
hgs
parents: 48
diff changeset
   306
            if (!envelope->isRead()) {
hgs
parents: 48
diff changeset
   307
                quint64 messageId = envelope->messageId().id();
hgs
parents: 48
diff changeset
   308
                newUnreadMessageIdList.append(envelope->messageId());
hgs
parents: 48
diff changeset
   309
                bool found(false);
hgs
parents: 48
diff changeset
   310
                // Iterate through all known ids. If the id can't be found the mail is new.
hgs
parents: 48
diff changeset
   311
                foreach (const NmId id, mailboxInfo.mUnreadMailIdList) {
hgs
parents: 48
diff changeset
   312
                    if (id.id() == messageId) {
hgs
parents: 48
diff changeset
   313
                        found = true;
hgs
parents: 48
diff changeset
   314
                        break;
hgs
parents: 48
diff changeset
   315
                    }
hgs
parents: 48
diff changeset
   316
                }
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   317
51
hgs
parents: 48
diff changeset
   318
                if (!found) {
hgs
parents: 48
diff changeset
   319
                    newUnreadMessages++;
hgs
parents: 48
diff changeset
   320
                }
hgs
parents: 48
diff changeset
   321
            }
hgs
parents: 48
diff changeset
   322
        }
hgs
parents: 48
diff changeset
   323
        qDeleteAll(messageList);
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   324
51
hgs
parents: 48
diff changeset
   325
        // Save updated list of unread message IDs
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   326
        mailboxInfo.mUnreadMailIdList = newUnreadMessageIdList;
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   327
    }
43
hgs
parents: 40
diff changeset
   328
    NM_COMMENT(QString("NmMailAgent::getUnreadCount(): count=%1, new=%2").
hgs
parents: 40
diff changeset
   329
        arg(mailboxInfo.mUnreadMailIdList.count()).arg(newUnreadMessages));
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   330
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   331
    return (newUnreadMessages > 0);
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   332
}
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   333
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   334
/*!
51
hgs
parents: 48
diff changeset
   335
    Get mailbox count in outbox folder.
hgs
parents: 48
diff changeset
   336
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   337
    \param mailboxId id of the mailbox
51
hgs
parents: 48
diff changeset
   338
    \param outboxId Outbox folder Id
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   339
    \return number of mails in the outbox
51
hgs
parents: 48
diff changeset
   340
 */
hgs
parents: 48
diff changeset
   341
int NmMailAgent::getOutboxCount(const NmId &mailboxId, const NmId &outboxId)
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   342
{
43
hgs
parents: 40
diff changeset
   343
    NM_FUNCTION;
hgs
parents: 40
diff changeset
   344
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   345
    int count(0);
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   346
    NmDataPluginInterface *plugin = mPluginFactory->interfaceInstance(mailboxId);
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   347
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   348
    if (plugin) {
51
hgs
parents: 48
diff changeset
   349
        // get list of messages in outbox
hgs
parents: 48
diff changeset
   350
        QList<NmMessageEnvelope*> messageList;
hgs
parents: 48
diff changeset
   351
        plugin->listMessages(mailboxId, outboxId, messageList);
hgs
parents: 48
diff changeset
   352
        count = messageList.count();
hgs
parents: 48
diff changeset
   353
        qDeleteAll(messageList);
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   354
    }
43
hgs
parents: 40
diff changeset
   355
    NM_COMMENT(QString("NmMailAgent::getOutboxCount(): count=%1").arg(count));
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   356
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   357
    return count;
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   358
}
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   359
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   360
/*!
51
hgs
parents: 48
diff changeset
   361
    Get list of unread counts in active mailboxes.
hgs
parents: 48
diff changeset
   362
43
hgs
parents: 40
diff changeset
   363
	\returns total number of unread mails
51
hgs
parents: 48
diff changeset
   364
 */
43
hgs
parents: 40
diff changeset
   365
int NmMailAgent::getTotalUnreadCount() const
hgs
parents: 40
diff changeset
   366
{
48
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   367
    NM_FUNCTION;
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   368
43
hgs
parents: 40
diff changeset
   369
    int unreads = 0;
hgs
parents: 40
diff changeset
   370
    foreach (const NmMailboxInfo *mailbox, mMailboxes) {
44
hgs
parents: 43
diff changeset
   371
        if (mailbox->mActive && mailbox->mInboxActive) {
43
hgs
parents: 40
diff changeset
   372
            unreads += mailbox->mUnreadMailIdList.count();
hgs
parents: 40
diff changeset
   373
        }
hgs
parents: 40
diff changeset
   374
    }
hgs
parents: 40
diff changeset
   375
    return unreads;
hgs
parents: 40
diff changeset
   376
}
hgs
parents: 40
diff changeset
   377
hgs
parents: 40
diff changeset
   378
/*!
51
hgs
parents: 48
diff changeset
   379
    Update the "@" indicator state according to unread state.
hgs
parents: 48
diff changeset
   380
43
hgs
parents: 40
diff changeset
   381
    \return true if the indicator was activated
51
hgs
parents: 48
diff changeset
   382
 */
43
hgs
parents: 40
diff changeset
   383
bool NmMailAgent::updateUnreadIndicator()
hgs
parents: 40
diff changeset
   384
{
48
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   385
    NM_FUNCTION;
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   386
43
hgs
parents: 40
diff changeset
   387
    int unreads = getTotalUnreadCount();
hgs
parents: 40
diff changeset
   388
    return updateUnreadIndicator(unreads>0);
hgs
parents: 40
diff changeset
   389
}
hgs
parents: 40
diff changeset
   390
hgs
parents: 40
diff changeset
   391
/*!
51
hgs
parents: 48
diff changeset
   392
    Update the mailbox visibility and status.
hgs
parents: 48
diff changeset
   393
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   394
    \param mailboxId id of the mailbox
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   395
    \param active visibility state of the mailbox
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   396
    \param refreshAlways true when the indicator should be always updated
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   397
    \return true if the mailbox state was changed
51
hgs
parents: 48
diff changeset
   398
 */
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   399
bool NmMailAgent::updateMailboxState(const NmId &mailboxId,
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   400
    bool active, bool refreshAlways)
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   401
{
43
hgs
parents: 40
diff changeset
   402
    NM_FUNCTION;
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   403
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   404
    NmMailboxInfo *mailboxInfo = getMailboxInfo(mailboxId);
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   405
    bool changed = false;
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   406
    if (mailboxInfo->mActive != active ||
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   407
        refreshAlways) {
47
hgs
parents: 44
diff changeset
   408
51
hgs
parents: 48
diff changeset
   409
        // store the new state to permanent storage
44
hgs
parents: 43
diff changeset
   410
        storeMailboxActive(mailboxId, active);
47
hgs
parents: 44
diff changeset
   411
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   412
        mailboxInfo->mActive = active;
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   413
        changed = true;
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   414
        if (active) {
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   415
            // Mailbox is not yet assigned to any indicator
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   416
            if (mailboxInfo->mIndicatorIndex < 0) {
43
hgs
parents: 40
diff changeset
   417
                mailboxInfo->mIndicatorIndex = getFreeIndicatorIndex();
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   418
            }
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   419
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   420
            updateIndicator(true,*mailboxInfo);
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   421
        }
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   422
        else {
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   423
            // Indicator not anymore active. Release it.
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   424
            if (mailboxInfo->mIndicatorIndex>=0) {
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   425
                updateIndicator(false,*mailboxInfo);
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   426
                mailboxInfo->mIndicatorIndex = NmAgentIndicatorNotSet;
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   427
            }
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   428
        }
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   429
    }
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   430
    return changed;
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   431
}
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   432
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   433
/*!
51
hgs
parents: 48
diff changeset
   434
    Updates indicator status.
hgs
parents: 48
diff changeset
   435
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   436
    \param mailboxIndex index of the item shown in indicator menu
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   437
    \param active indicator visibility state
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   438
    \param mailboxInfo information of the mailbox
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   439
    \return true if indicator was updated with no errors
51
hgs
parents: 48
diff changeset
   440
 */
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   441
bool NmMailAgent::updateIndicator(bool active,
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   442
    const NmMailboxInfo& mailboxInfo)
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   443
{
43
hgs
parents: 40
diff changeset
   444
    NM_FUNCTION;
hgs
parents: 40
diff changeset
   445
    NM_COMMENT(QString("NmMailAgent::updateIndicator(): index=%1, active=%2").
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   446
        arg(mailboxInfo.mIndicatorIndex).arg(active));
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   447
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   448
    bool ok = false;
43
hgs
parents: 40
diff changeset
   449
    QString name = QString(NmMailboxIndicatorType).
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   450
        arg(mailboxInfo.mIndicatorIndex);
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   451
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   452
    QList<QVariant> list;
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   453
    list.append(mailboxInfo.mId.id());
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   454
    list.append(mailboxInfo.mName);
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   455
    list.append(mailboxInfo.mUnreadMailIdList.count());
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   456
    list.append(mailboxInfo.mSyncState);
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   457
    list.append(mailboxInfo.mConnectState);
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   458
    list.append(mailboxInfo.mOutboxMails);
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   459
    list.append(mailboxInfo.mIconName);
43
hgs
parents: 40
diff changeset
   460
    list.append(mLastOutboxCount);
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   461
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   462
    if (active) {
43
hgs
parents: 40
diff changeset
   463
        ok = mIndicator->activate(name,list);
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   464
    }
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   465
    else {
43
hgs
parents: 40
diff changeset
   466
        ok = mIndicator->deactivate(name,list);
hgs
parents: 40
diff changeset
   467
    }
hgs
parents: 40
diff changeset
   468
hgs
parents: 40
diff changeset
   469
    updateUnreadIndicator();
hgs
parents: 40
diff changeset
   470
hgs
parents: 40
diff changeset
   471
    return ok;
hgs
parents: 40
diff changeset
   472
}
hgs
parents: 40
diff changeset
   473
hgs
parents: 40
diff changeset
   474
/*!
51
hgs
parents: 48
diff changeset
   475
    Update the unread indicator state.
hgs
parents: 48
diff changeset
   476
hgs
parents: 48
diff changeset
   477
    \param active if true unread indicator is activated otherwise deactivated
43
hgs
parents: 40
diff changeset
   478
    \return true if the indicator was activated
51
hgs
parents: 48
diff changeset
   479
 */
43
hgs
parents: 40
diff changeset
   480
bool NmMailAgent::updateUnreadIndicator(bool active)
hgs
parents: 40
diff changeset
   481
{
hgs
parents: 40
diff changeset
   482
    NM_FUNCTION;
48
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   483
43
hgs
parents: 40
diff changeset
   484
    bool activated = false;
44
hgs
parents: 43
diff changeset
   485
    if (active != mUnreadIndicatorActive) {
hgs
parents: 43
diff changeset
   486
        if (active) {
hgs
parents: 43
diff changeset
   487
            mIndicator->activate(NmUnreadIndicatorName);
43
hgs
parents: 40
diff changeset
   488
            activated = true;
hgs
parents: 40
diff changeset
   489
        }
44
hgs
parents: 43
diff changeset
   490
        else {
hgs
parents: 43
diff changeset
   491
            mIndicator->deactivate(NmUnreadIndicatorName);
hgs
parents: 43
diff changeset
   492
        }
hgs
parents: 43
diff changeset
   493
        mUnreadIndicatorActive = active;
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   494
    }
44
hgs
parents: 43
diff changeset
   495
43
hgs
parents: 40
diff changeset
   496
    return activated;
hgs
parents: 40
diff changeset
   497
}
hgs
parents: 40
diff changeset
   498
hgs
parents: 40
diff changeset
   499
/*!
51
hgs
parents: 48
diff changeset
   500
    Opens inbox view to specific mailbox.
hgs
parents: 48
diff changeset
   501
hgs
parents: 48
diff changeset
   502
    \param mailboxId Id of mailbox
43
hgs
parents: 40
diff changeset
   503
    \return true if inbox is succesfully opened
51
hgs
parents: 48
diff changeset
   504
 */
43
hgs
parents: 40
diff changeset
   505
bool NmMailAgent::launchMailbox(quint64 mailboxId)
hgs
parents: 40
diff changeset
   506
{
hgs
parents: 40
diff changeset
   507
    NM_FUNCTION;
hgs
parents: 40
diff changeset
   508
47
hgs
parents: 44
diff changeset
   509
    bool ok(false);
44
hgs
parents: 43
diff changeset
   510
    XQApplicationManager appManager;
hgs
parents: 43
diff changeset
   511
    XQAiwRequest *request = appManager.create(
hgs
parents: 43
diff changeset
   512
        XQI_EMAIL_INBOX_VIEW, XQOP_EMAIL_INBOX_VIEW, false);
47
hgs
parents: 44
diff changeset
   513
    // Instance might be NULL if the service is not available.
hgs
parents: 44
diff changeset
   514
    if (request) {
hgs
parents: 44
diff changeset
   515
        QList<QVariant> list;
hgs
parents: 44
diff changeset
   516
        list.append(QVariant(mailboxId));
hgs
parents: 44
diff changeset
   517
        request->setArguments(list);
hgs
parents: 44
diff changeset
   518
        ok = request->send();
hgs
parents: 44
diff changeset
   519
        NM_COMMENT(QString("Launch ok=%1 error=%2").arg(ok).arg(request->lastError()));
hgs
parents: 44
diff changeset
   520
        delete request;
hgs
parents: 44
diff changeset
   521
    }
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   522
    return ok;
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   523
}
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   524
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   525
/*!
51
hgs
parents: 48
diff changeset
   526
    Handles message created event.
hgs
parents: 48
diff changeset
   527
hgs
parents: 48
diff changeset
   528
    \param folderId Id of the folder that includes the message
hgs
parents: 48
diff changeset
   529
    \param messageIds Message ids that are checked
hgs
parents: 48
diff changeset
   530
    \param mailboxId Id of the mailbox that includes the message
hgs
parents: 48
diff changeset
   531
    \param updateNeeded Set to <code>true</code> if update needed otherwise not touched
hgs
parents: 48
diff changeset
   532
    \param activate Set to <code>true</code> if activation needed otherwise not touched
hgs
parents: 48
diff changeset
   533
 */
hgs
parents: 48
diff changeset
   534
void NmMailAgent::handleMessageCreatedEvent(const NmId &folderId, const QList<NmId> &messageIds,
hgs
parents: 48
diff changeset
   535
    const NmId &mailboxId, bool &updateNeeded, bool &activate)
hgs
parents: 48
diff changeset
   536
{
hgs
parents: 48
diff changeset
   537
    NM_FUNCTION;
hgs
parents: 48
diff changeset
   538
hgs
parents: 48
diff changeset
   539
    // Check the new messages to make the indicator appear earlier
hgs
parents: 48
diff changeset
   540
    NmMailboxInfo *mailboxInfo = getMailboxInfo(mailboxId);
hgs
parents: 48
diff changeset
   541
hgs
parents: 48
diff changeset
   542
    // Inbox folder ID may be still unknown
hgs
parents: 48
diff changeset
   543
    if (mailboxInfo->mInboxFolderId.id() == 0) {
hgs
parents: 48
diff changeset
   544
        NmDataPluginInterface *plugin =
hgs
parents: 48
diff changeset
   545
            mPluginFactory->interfaceInstance(mailboxId);
hgs
parents: 48
diff changeset
   546
hgs
parents: 48
diff changeset
   547
        if (plugin) {
hgs
parents: 48
diff changeset
   548
            mailboxInfo->mInboxFolderId =
hgs
parents: 48
diff changeset
   549
                plugin->getStandardFolderId(mailboxId, NmFolderInbox);
hgs
parents: 48
diff changeset
   550
        }
hgs
parents: 48
diff changeset
   551
    }
hgs
parents: 48
diff changeset
   552
hgs
parents: 48
diff changeset
   553
    if (folderId == mailboxInfo->mInboxFolderId) {
hgs
parents: 48
diff changeset
   554
        foreach (NmId messageId, messageIds) {
hgs
parents: 48
diff changeset
   555
            bool messageUnread = false;
hgs
parents: 48
diff changeset
   556
hgs
parents: 48
diff changeset
   557
            // Check the message if we can either play a tone or if the "@" is
hgs
parents: 48
diff changeset
   558
            // not visible at the moment
hgs
parents: 48
diff changeset
   559
            if (mAlertToneAllowed || !mUnreadIndicatorActive) {
hgs
parents: 48
diff changeset
   560
                if (getMessageUnreadInfo(folderId, messageId, mailboxId, messageUnread)) {
hgs
parents: 48
diff changeset
   561
                    if (messageUnread) {
hgs
parents: 48
diff changeset
   562
                        mailboxInfo->mUnreadMailIdList.append(messageId);
hgs
parents: 48
diff changeset
   563
                        mailboxInfo->mInboxActive = true;
hgs
parents: 48
diff changeset
   564
                        updateMailboxState(mailboxId, true, false);
hgs
parents: 48
diff changeset
   565
hgs
parents: 48
diff changeset
   566
                        // make the "@" appear immediatelly
hgs
parents: 48
diff changeset
   567
                        updateUnreadIndicator(true);
hgs
parents: 48
diff changeset
   568
hgs
parents: 48
diff changeset
   569
                        // Play the tone as well
hgs
parents: 48
diff changeset
   570
                        playAlertTone();
hgs
parents: 48
diff changeset
   571
                    }
hgs
parents: 48
diff changeset
   572
                }
hgs
parents: 48
diff changeset
   573
            }
hgs
parents: 48
diff changeset
   574
        }
hgs
parents: 48
diff changeset
   575
    }
hgs
parents: 48
diff changeset
   576
hgs
parents: 48
diff changeset
   577
    if (folderId==mailboxInfo->mInboxFolderId) {
hgs
parents: 48
diff changeset
   578
        mailboxInfo->mInboxCreatedMessages += messageIds.count();
hgs
parents: 48
diff changeset
   579
    }
hgs
parents: 48
diff changeset
   580
hgs
parents: 48
diff changeset
   581
    // When created a new mail in the outbox, we are in sending state
hgs
parents: 48
diff changeset
   582
    if (mailboxInfo->mOutboxFolderId == folderId) {
hgs
parents: 48
diff changeset
   583
        // The first mail created in the outbox
hgs
parents: 48
diff changeset
   584
        if (mailboxInfo->mOutboxMails <= 0) {
hgs
parents: 48
diff changeset
   585
            NM_COMMENT("NmMailAgent: first mail in outbox");
hgs
parents: 48
diff changeset
   586
        }
hgs
parents: 48
diff changeset
   587
        // Always activate the indicator
hgs
parents: 48
diff changeset
   588
        activate = true;
hgs
parents: 48
diff changeset
   589
        updateNeeded = true;
hgs
parents: 48
diff changeset
   590
hgs
parents: 48
diff changeset
   591
        mailboxInfo->mOutboxMails += messageIds.count();
hgs
parents: 48
diff changeset
   592
        updateSendIndicator();
hgs
parents: 48
diff changeset
   593
    }
hgs
parents: 48
diff changeset
   594
}
hgs
parents: 48
diff changeset
   595
hgs
parents: 48
diff changeset
   596
hgs
parents: 48
diff changeset
   597
/*!
hgs
parents: 48
diff changeset
   598
    Handles message changed event.
hgs
parents: 48
diff changeset
   599
    \sa updateUnreadCount
hgs
parents: 48
diff changeset
   600
hgs
parents: 48
diff changeset
   601
    \param folderId Id of the folder that includes the message
56
hgs
parents: 51
diff changeset
   602
    \param messageIds Message ids that are checked
51
hgs
parents: 48
diff changeset
   603
    \param mailboxId Id of the mailbox that includes the message
hgs
parents: 48
diff changeset
   604
    \param updateNeeded Set to <code>true</code> if update needed otherwise not touched
hgs
parents: 48
diff changeset
   605
    \param activate Set result value of updateUnreadCount method
hgs
parents: 48
diff changeset
   606
 */
56
hgs
parents: 51
diff changeset
   607
void NmMailAgent::handleMessageChangedEvent(const NmId &folderId, 
hgs
parents: 51
diff changeset
   608
    const QList<NmId> &messageIds,
hgs
parents: 51
diff changeset
   609
    const NmId &mailboxId,
51
hgs
parents: 48
diff changeset
   610
    bool &updateNeeded, bool &activate)
hgs
parents: 48
diff changeset
   611
{
hgs
parents: 48
diff changeset
   612
    NmMailboxInfo *mailboxInfo = getMailboxInfo(mailboxId);
hgs
parents: 48
diff changeset
   613
56
hgs
parents: 51
diff changeset
   614
    // we are interested only about changes in the inbox
51
hgs
parents: 48
diff changeset
   615
    if (folderId == mailboxInfo->mInboxFolderId) {
hgs
parents: 48
diff changeset
   616
        mailboxInfo->mInboxChangedMessages++;
hgs
parents: 48
diff changeset
   617
56
hgs
parents: 51
diff changeset
   618
        // If not currently syncronizing the mailbox, this may mean
hgs
parents: 51
diff changeset
   619
        // that a message was read/unread
hgs
parents: 51
diff changeset
   620
        if (mailboxInfo && mailboxInfo->mSyncState == SyncComplete) {
hgs
parents: 51
diff changeset
   621
            // If there was no unread mails in the list, do nothing
hgs
parents: 51
diff changeset
   622
            int oldCount(mailboxInfo->mUnreadMailIdList.count());
hgs
parents: 51
diff changeset
   623
            if (oldCount>0) {
hgs
parents: 51
diff changeset
   624
                // Check how many messages were unread earlier
hgs
parents: 51
diff changeset
   625
                int unreadMessages = 0;
hgs
parents: 51
diff changeset
   626
                foreach (NmId messageId, messageIds) {
hgs
parents: 51
diff changeset
   627
                    if (mailboxInfo->mUnreadMailIdList.indexOf(messageId)>=0) {
hgs
parents: 51
diff changeset
   628
                        unreadMessages++;
hgs
parents: 51
diff changeset
   629
                    }
hgs
parents: 51
diff changeset
   630
                }
51
hgs
parents: 48
diff changeset
   631
56
hgs
parents: 51
diff changeset
   632
                // Could lead the count drop to 0 => mailbox will be hidden
hgs
parents: 51
diff changeset
   633
                if (unreadMessages > 0) {
hgs
parents: 51
diff changeset
   634
                    // check the unread status again
hgs
parents: 51
diff changeset
   635
                    activate = updateUnreadCount(mailboxId, *mailboxInfo);
hgs
parents: 51
diff changeset
   636
hgs
parents: 51
diff changeset
   637
                    // no more unread mails in the inbox
hgs
parents: 51
diff changeset
   638
                    if (mailboxInfo->mUnreadMailIdList.count()==0) {
hgs
parents: 51
diff changeset
   639
                        NM_COMMENT("NmMailAgent:handleMessageChangedEvent - no more unread msgs");
hgs
parents: 51
diff changeset
   640
                        updateNeeded = true;
hgs
parents: 51
diff changeset
   641
                    }
hgs
parents: 51
diff changeset
   642
                }
hgs
parents: 51
diff changeset
   643
            }
51
hgs
parents: 48
diff changeset
   644
        }
hgs
parents: 48
diff changeset
   645
    }
hgs
parents: 48
diff changeset
   646
}
hgs
parents: 48
diff changeset
   647
hgs
parents: 48
diff changeset
   648
/*!
hgs
parents: 48
diff changeset
   649
    Handles message deleted event.
hgs
parents: 48
diff changeset
   650
hgs
parents: 48
diff changeset
   651
    \param folderId Id of the folder that includes the message
hgs
parents: 48
diff changeset
   652
    \param messageIds Message ids that are checked
hgs
parents: 48
diff changeset
   653
    \param mailboxId Id of the mailbox that includes the message
hgs
parents: 48
diff changeset
   654
    \param updateNeeded Set to <code>true</code> if update needed otherwise not touched
hgs
parents: 48
diff changeset
   655
    \param activate Set to <code>true</code> if activation needed otherwise not touched
hgs
parents: 48
diff changeset
   656
 */
hgs
parents: 48
diff changeset
   657
void NmMailAgent::handleMessageDeletedEvent(const NmId &folderId, const QList<NmId> &messageIds,
hgs
parents: 48
diff changeset
   658
    const NmId &mailboxId, bool &updateNeeded, bool &activate)
hgs
parents: 48
diff changeset
   659
{
hgs
parents: 48
diff changeset
   660
    NmMailboxInfo *mailboxInfo = getMailboxInfo(mailboxId);
hgs
parents: 48
diff changeset
   661
hgs
parents: 48
diff changeset
   662
    if (folderId == mailboxInfo->mInboxFolderId) {
hgs
parents: 48
diff changeset
   663
        mailboxInfo->mInboxDeletedMessages++;
hgs
parents: 48
diff changeset
   664
    }
hgs
parents: 48
diff changeset
   665
hgs
parents: 48
diff changeset
   666
    // Deleted mails from the outbox
hgs
parents: 48
diff changeset
   667
    if (mailboxInfo->mOutboxFolderId == folderId) {
hgs
parents: 48
diff changeset
   668
        mailboxInfo->mOutboxMails -= messageIds.count();
hgs
parents: 48
diff changeset
   669
hgs
parents: 48
diff changeset
   670
        // Sanity check for the outbox count
hgs
parents: 48
diff changeset
   671
        if (mailboxInfo->mOutboxMails < 0) {
hgs
parents: 48
diff changeset
   672
            mailboxInfo->mOutboxMails = 0;
hgs
parents: 48
diff changeset
   673
        }
hgs
parents: 48
diff changeset
   674
hgs
parents: 48
diff changeset
   675
        // The last mail was now deleted
hgs
parents: 48
diff changeset
   676
        if (mailboxInfo->mOutboxMails == 0) {
hgs
parents: 48
diff changeset
   677
            NM_COMMENT("NmMailAgent: last mail deleted from outbox");
hgs
parents: 48
diff changeset
   678
            updateNeeded = true;
hgs
parents: 48
diff changeset
   679
hgs
parents: 48
diff changeset
   680
            // Keep it active if there is unread mails and inbox is still active
hgs
parents: 48
diff changeset
   681
            if (mailboxInfo->mInboxActive &&
hgs
parents: 48
diff changeset
   682
                mailboxInfo->mUnreadMailIdList.count() > 0) {
hgs
parents: 48
diff changeset
   683
                activate = true;
hgs
parents: 48
diff changeset
   684
            }
hgs
parents: 48
diff changeset
   685
        }
hgs
parents: 48
diff changeset
   686
        else {
hgs
parents: 48
diff changeset
   687
            // Also update the indicator status if it is already shown
hgs
parents: 48
diff changeset
   688
            if (mailboxInfo->mActive) {
hgs
parents: 48
diff changeset
   689
                activate = true;
hgs
parents: 48
diff changeset
   690
                updateNeeded = true;
hgs
parents: 48
diff changeset
   691
            }
hgs
parents: 48
diff changeset
   692
        }
hgs
parents: 48
diff changeset
   693
        updateSendIndicator();
hgs
parents: 48
diff changeset
   694
    }
hgs
parents: 48
diff changeset
   695
}
hgs
parents: 48
diff changeset
   696
hgs
parents: 48
diff changeset
   697
/*!
hgs
parents: 48
diff changeset
   698
    Get next free indicator index, starting from 0.
hgs
parents: 48
diff changeset
   699
hgs
parents: 48
diff changeset
   700
    \return index of the indicator that is available
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   701
 */
43
hgs
parents: 40
diff changeset
   702
int NmMailAgent::getFreeIndicatorIndex()
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   703
{
43
hgs
parents: 40
diff changeset
   704
    NM_FUNCTION;
hgs
parents: 40
diff changeset
   705
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   706
    int index = 0;
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   707
    bool found(false);
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   708
    do {
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   709
        found = false;
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   710
        foreach (NmMailboxInfo *mailbox, mMailboxes) {
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   711
            if (mailbox->mIndicatorIndex == index &&
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   712
                mailbox->mActive) {
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   713
                found = true;
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   714
                index++;
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   715
            }
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   716
        }
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   717
    }
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   718
    while( found );
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   719
    return index;
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   720
}
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   721
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   722
/*!
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   723
    Received from NmFrameworkAdapter mailboxEvent signal
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   724
    \sa NmFrameworkAdapter
51
hgs
parents: 48
diff changeset
   725
hgs
parents: 48
diff changeset
   726
    \param event Mailbox event type
hgs
parents: 48
diff changeset
   727
    \param mailboxIds Mailbox ids that are checked
hgs
parents: 48
diff changeset
   728
 */
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   729
void NmMailAgent::handleMailboxEvent(NmMailboxEvent event, const QList<NmId> &mailboxIds)
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   730
{
43
hgs
parents: 40
diff changeset
   731
    NM_FUNCTION;
hgs
parents: 40
diff changeset
   732
    NM_COMMENT(QString("NmMailAgent::handleMailboxEvent(): event=%1").arg(event));
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   733
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   734
    switch(event) {
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   735
        case NmMailboxCreated:
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   736
            foreach (NmId mailboxId, mailboxIds) {
51
hgs
parents: 48
diff changeset
   737
                NmMailboxInfo *mailboxInfo = getMailboxInfo(mailboxId); // create a new mailbox if needed
hgs
parents: 48
diff changeset
   738
                if (!mailboxInfo) {
hgs
parents: 48
diff changeset
   739
                    // Unable to initialise the mailbox. Try again later.
hgs
parents: 48
diff changeset
   740
                    NM_COMMENT("Cannot initialise mailbox");
56
hgs
parents: 51
diff changeset
   741
51
hgs
parents: 48
diff changeset
   742
                    qRegisterMetaType<NmId>("NmId");
hgs
parents: 48
diff changeset
   743
                    QMetaObject::invokeMethod(this, "delayedMailboxCreated",
hgs
parents: 48
diff changeset
   744
                        Qt::QueuedConnection, Q_ARG(NmId,mailboxId));
hgs
parents: 48
diff changeset
   745
                }
47
hgs
parents: 44
diff changeset
   746
44
hgs
parents: 43
diff changeset
   747
                // make sure the mailbox activity data is reseted
hgs
parents: 43
diff changeset
   748
                deleteStoredMailboxActivity(mailboxId);
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   749
            }
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   750
            break;
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   751
        case NmMailboxChanged:
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   752
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   753
            // Mailbox name may have been changed
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   754
            foreach (NmId mailboxId, mailboxIds) {
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   755
                NmMailboxInfo *mailboxInfo = getMailboxInfo(mailboxId);
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   756
                NmMailbox *mailbox(NULL);
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   757
                NmDataPluginInterface *plugin = mPluginFactory->interfaceInstance(mailboxId);
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   758
                if (plugin) {
51
hgs
parents: 48
diff changeset
   759
                    plugin->getMailboxById(mailboxId,mailbox);
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   760
                }
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   761
                if (mailbox && mailboxInfo) {
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   762
                    if(mailbox->name() != mailboxInfo->mName) {
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   763
                        mailboxInfo->mName = mailbox->name();
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   764
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   765
                        if (mailboxInfo->mActive) {
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   766
                            // Update the status of the mailbox
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   767
                            updateMailboxState(mailboxId, true, true);
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   768
                        }
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   769
                    }
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   770
                }
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   771
                delete mailbox;
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   772
            }
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   773
            break;
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   774
        case NmMailboxDeleted:
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   775
            foreach (NmId mailboxId, mailboxIds) {
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   776
                // Will hide also the indicator
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   777
                removeMailboxInfo(mailboxId);
47
hgs
parents: 44
diff changeset
   778
44
hgs
parents: 43
diff changeset
   779
                // make sure the mailbox activity data is deleted
hgs
parents: 43
diff changeset
   780
                deleteStoredMailboxActivity(mailboxId);
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   781
            }
43
hgs
parents: 40
diff changeset
   782
            updateUnreadIndicator();
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   783
            break;
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   784
        default:
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   785
            break;
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   786
    }
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   787
}
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   788
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   789
/*!
56
hgs
parents: 51
diff changeset
   790
    Called when mailbox is initialised with a delay. This may happen at least when
51
hgs
parents: 48
diff changeset
   791
    NmMailboxCreated event is received.
56
hgs
parents: 51
diff changeset
   792
51
hgs
parents: 48
diff changeset
   793
    \param mailboxId id of the mailbox
43
hgs
parents: 40
diff changeset
   794
*/
51
hgs
parents: 48
diff changeset
   795
void NmMailAgent::delayedMailboxCreated(const NmId mailboxId)
hgs
parents: 48
diff changeset
   796
{
hgs
parents: 48
diff changeset
   797
    NM_FUNCTION;
hgs
parents: 48
diff changeset
   798
hgs
parents: 48
diff changeset
   799
    // create and subscribe to the mailbox, if not done earlier
hgs
parents: 48
diff changeset
   800
    getMailboxInfo(mailboxId);
hgs
parents: 48
diff changeset
   801
}
hgs
parents: 48
diff changeset
   802
hgs
parents: 48
diff changeset
   803
/*!
hgs
parents: 48
diff changeset
   804
   Map the type name to mailbox info.
hgs
parents: 48
diff changeset
   805
hgs
parents: 48
diff changeset
   806
   \param type Indicator type name
hgs
parents: 48
diff changeset
   807
   \return NULL if no mailbox match the type
hgs
parents: 48
diff changeset
   808
 */
43
hgs
parents: 40
diff changeset
   809
NmMailboxInfo *NmMailAgent::getMailboxByType(const QString &type)
hgs
parents: 40
diff changeset
   810
{
48
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   811
    NM_FUNCTION;
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   812
51
hgs
parents: 48
diff changeset
   813
    NmMailboxInfo *foundMailbox = NULL;
43
hgs
parents: 40
diff changeset
   814
    foreach (NmMailboxInfo *mailbox, mMailboxes) {
hgs
parents: 40
diff changeset
   815
        // mailbox is shown in indicators
hgs
parents: 40
diff changeset
   816
        if (mailbox->mIndicatorIndex >= 0 && mailbox->mActive) {
hgs
parents: 40
diff changeset
   817
            QString typeName = QString(NmMailboxIndicatorType).arg(mailbox->mIndicatorIndex);
hgs
parents: 40
diff changeset
   818
hgs
parents: 40
diff changeset
   819
            // type names match(!)
51
hgs
parents: 48
diff changeset
   820
            if (type == typeName) {
hgs
parents: 48
diff changeset
   821
                foundMailbox = mailbox;
hgs
parents: 48
diff changeset
   822
                break;
43
hgs
parents: 40
diff changeset
   823
            }
hgs
parents: 40
diff changeset
   824
        }
hgs
parents: 40
diff changeset
   825
    }
51
hgs
parents: 48
diff changeset
   826
    return foundMailbox;
43
hgs
parents: 40
diff changeset
   827
}
hgs
parents: 40
diff changeset
   828
hgs
parents: 40
diff changeset
   829
/*!
hgs
parents: 40
diff changeset
   830
    Called when indicator is clicked from the indicator menu
hgs
parents: 40
diff changeset
   831
    - indicator will be hide from the menu
hgs
parents: 40
diff changeset
   832
    - mailbox will be launched
51
hgs
parents: 48
diff changeset
   833
hgs
parents: 48
diff changeset
   834
    \param type Indicator type name
hgs
parents: 48
diff changeset
   835
    \param data Data sent by indicator
hgs
parents: 48
diff changeset
   836
 */
43
hgs
parents: 40
diff changeset
   837
void NmMailAgent::indicatorActivated(const QString &type, const QVariantMap &data)
hgs
parents: 40
diff changeset
   838
{
hgs
parents: 40
diff changeset
   839
    NM_FUNCTION;
hgs
parents: 40
diff changeset
   840
    Q_UNUSED(data);
47
hgs
parents: 44
diff changeset
   841
43
hgs
parents: 40
diff changeset
   842
    // map the indicator type to mailbox
hgs
parents: 40
diff changeset
   843
    NmMailboxInfo *info = getMailboxByType(type);
hgs
parents: 40
diff changeset
   844
    if (info) {
hgs
parents: 40
diff changeset
   845
        info->mActive = false; // indicator is no longer active
44
hgs
parents: 43
diff changeset
   846
        info->mInboxActive = false; // also inbox does not activate the indicator
hgs
parents: 43
diff changeset
   847
        storeMailboxActive(info->mId, false);
43
hgs
parents: 40
diff changeset
   848
        updateUnreadIndicator();
hgs
parents: 40
diff changeset
   849
hgs
parents: 40
diff changeset
   850
        launchMailbox(info->mId.id());
hgs
parents: 40
diff changeset
   851
    }
hgs
parents: 40
diff changeset
   852
}
hgs
parents: 40
diff changeset
   853
hgs
parents: 40
diff changeset
   854
/*!
48
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   855
    Called when cenrep key value has been changed.
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   856
    - only silence mode key handled
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   857
51
hgs
parents: 48
diff changeset
   858
    \param key changed key
hgs
parents: 48
diff changeset
   859
    \param value value for a key
hgs
parents: 48
diff changeset
   860
 */
hgs
parents: 48
diff changeset
   861
void NmMailAgent::valueChanged(const XQSettingsKey &key, const QVariant &value)
48
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   862
{
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   863
    NM_FUNCTION;
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   864
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   865
    if(keysEqual(key, NmSilenceModeKey)) {
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   866
        mSilenceMode = value.toInt();
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   867
    }
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   868
}
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   869
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
   870
/*!
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   871
    Received from NmFrameworkAdapter messageEvent signal
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   872
    \sa NmFrameworkAdapter
51
hgs
parents: 48
diff changeset
   873
hgs
parents: 48
diff changeset
   874
    \param event Message event
hgs
parents: 48
diff changeset
   875
    \param folderId Folder Id
hgs
parents: 48
diff changeset
   876
    \param messageIds List of message Ids
hgs
parents: 48
diff changeset
   877
    \param mailboxId Id of the mailbox
hgs
parents: 48
diff changeset
   878
 */
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   879
void NmMailAgent::handleMessageEvent(
51
hgs
parents: 48
diff changeset
   880
    NmMessageEvent event,
hgs
parents: 48
diff changeset
   881
    const NmId &folderId,
hgs
parents: 48
diff changeset
   882
    const QList<NmId> &messageIds,
hgs
parents: 48
diff changeset
   883
    const NmId &mailboxId)
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   884
{
43
hgs
parents: 40
diff changeset
   885
    NM_FUNCTION;
hgs
parents: 40
diff changeset
   886
    NM_COMMENT(QString("NmMailAgent::handleMessageEvent(): event=%1, id=%2").
hgs
parents: 40
diff changeset
   887
        arg(event).arg(mailboxId.id()));
hgs
parents: 40
diff changeset
   888
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   889
    bool updateNeeded = false;
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   890
    bool activate = false;
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   891
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   892
    switch (event) {
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   893
        case NmMessageCreated: {
51
hgs
parents: 48
diff changeset
   894
            handleMessageCreatedEvent(folderId, messageIds, mailboxId, updateNeeded, activate);
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   895
            break;
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   896
        }
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   897
        case NmMessageChanged: {
56
hgs
parents: 51
diff changeset
   898
            handleMessageChangedEvent(folderId, messageIds, mailboxId, updateNeeded, activate);
51
hgs
parents: 48
diff changeset
   899
            break;
hgs
parents: 48
diff changeset
   900
        }
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   901
        case NmMessageDeleted: {
51
hgs
parents: 48
diff changeset
   902
            handleMessageDeletedEvent(folderId, messageIds, mailboxId, updateNeeded, activate);
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   903
            break;
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   904
        }
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   905
        default:
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   906
            break;
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   907
    }
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   908
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   909
    if (updateNeeded) {
43
hgs
parents: 40
diff changeset
   910
        updateUnreadIndicator();
hgs
parents: 40
diff changeset
   911
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   912
        NmMailboxInfo *mailboxInfo = getMailboxInfo(mailboxId);
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   913
        updateMailboxState(mailboxId,
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   914
            activate, true /* force refresh */);
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   915
    }
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   916
}
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   917
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   918
/*!
51
hgs
parents: 48
diff changeset
   919
    Received from NmFrameworkAdapter syncStateEvent signal.
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   920
    \sa NmFrameworkAdapter
51
hgs
parents: 48
diff changeset
   921
hgs
parents: 48
diff changeset
   922
    \param state state of synchronization
hgs
parents: 48
diff changeset
   923
    \param event Information related to asynchronous operation
hgs
parents: 48
diff changeset
   924
hgs
parents: 48
diff changeset
   925
 */
hgs
parents: 48
diff changeset
   926
void NmMailAgent::handleSyncStateEvent(NmSyncState state, const NmOperationCompletionEvent &event)
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   927
{
43
hgs
parents: 40
diff changeset
   928
    NM_FUNCTION;
hgs
parents: 40
diff changeset
   929
    NM_COMMENT(QString("NmMailAgent::handleSyncStateEvent(): state=%1, id=%2").
hgs
parents: 40
diff changeset
   930
        arg(state).arg(event.mMailboxId.id()));
hgs
parents: 40
diff changeset
   931
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   932
    NmMailboxInfo *info = getMailboxInfo(event.mMailboxId);
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   933
    if (info) {
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   934
        info->mSyncState = state;
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   935
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   936
        if (state==Synchronizing) {
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   937
            // Reset counters when sync is started
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   938
            info->mInboxCreatedMessages = 0;
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   939
            info->mInboxChangedMessages = 0;
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   940
            info->mInboxDeletedMessages = 0;
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   941
        }
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   942
        else if (state==SyncComplete) {
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   943
            // Check the unread status here again
51
hgs
parents: 48
diff changeset
   944
            bool updateMailbox = updateUnreadCount(event.mMailboxId, *info);
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   945
            int oldOutboxCount = info->mOutboxMails;
51
hgs
parents: 48
diff changeset
   946
            info->mOutboxMails = getOutboxCount(event.mMailboxId, info->mOutboxFolderId);
hgs
parents: 48
diff changeset
   947
            int unreadMailCount(info->mUnreadMailIdList.count());
hgs
parents: 48
diff changeset
   948
            if (info->mOutboxMails > oldOutboxCount || unreadMailCount == 0) {
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   949
                // new mails in outbox
51
hgs
parents: 48
diff changeset
   950
                updateMailbox = true;
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   951
            }
51
hgs
parents: 48
diff changeset
   952
            bool active = unreadMailCount || info->mOutboxMails;
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   953
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   954
            // Refresh the indicator if messages created or changed
43
hgs
parents: 40
diff changeset
   955
            NM_COMMENT(QString("NmMailAgent::handleSyncStateEvent(): "
hgs
parents: 40
diff changeset
   956
                "created=%1, changed=%2, deleted=%3").
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   957
                arg(info->mInboxCreatedMessages).
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   958
                arg(info->mInboxChangedMessages).
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   959
                arg(info->mInboxDeletedMessages));
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   960
            bool refresh = (info->mInboxCreatedMessages > 0) || (info->mInboxChangedMessages > 0);
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   961
43
hgs
parents: 40
diff changeset
   962
            updateUnreadIndicator();
hgs
parents: 40
diff changeset
   963
51
hgs
parents: 48
diff changeset
   964
            if (updateMailbox) {
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   965
                updateMailboxState(event.mMailboxId, active, refresh);
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
   966
            }
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   967
        }
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   968
    }
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   969
}
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   970
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   971
/*!
51
hgs
parents: 48
diff changeset
   972
    Received from NmFrameworkAdapter connectionState signal.
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   973
    \sa NmFrameworkAdapter
51
hgs
parents: 48
diff changeset
   974
hgs
parents: 48
diff changeset
   975
    \param state Connection state
hgs
parents: 48
diff changeset
   976
    \param mailboxId Id of the mailbox
hgs
parents: 48
diff changeset
   977
    \parma errorcode Error code
hgs
parents: 48
diff changeset
   978
 */
40
hgs
parents: 23
diff changeset
   979
void NmMailAgent::handleConnectionEvent(NmConnectState state, const NmId mailboxId, int errorcode)
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   980
{
43
hgs
parents: 40
diff changeset
   981
    NM_FUNCTION;
hgs
parents: 40
diff changeset
   982
    NM_COMMENT(QString("NmMailAgent::handleConnectionEvent(): state=%1, id=%2").
hgs
parents: 40
diff changeset
   983
        arg(state).arg(mailboxId.id()));
hgs
parents: 40
diff changeset
   984
    Q_UNUSED(errorcode);
hgs
parents: 40
diff changeset
   985
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   986
    NmMailboxInfo *mailboxInfo = getMailboxInfo(mailboxId);
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   987
    if (mailboxInfo) {
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   988
        // Connecting, Connected, Disconnecting, Disconnected
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   989
        mailboxInfo->mConnectState = state;
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   990
    }
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   991
}
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   992
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   993
/*!
51
hgs
parents: 48
diff changeset
   994
    Remove a mailbox info entry.
hgs
parents: 48
diff changeset
   995
hgs
parents: 48
diff changeset
   996
    \param id Id of the mailbox
hgs
parents: 48
diff changeset
   997
    \return true if mailbox info was found.
hgs
parents: 48
diff changeset
   998
 */
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   999
bool NmMailAgent::removeMailboxInfo(const NmId &id)
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
  1000
{
43
hgs
parents: 40
diff changeset
  1001
    NM_FUNCTION;
hgs
parents: 40
diff changeset
  1002
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
  1003
    bool found = false;
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
  1004
    foreach (NmMailboxInfo *mailbox, mMailboxes) {
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
  1005
        if (mailbox->mId == id) {
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1006
            // Hide the indicator too
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1007
            if(mailbox->mIndicatorIndex>=0) {
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1008
                updateIndicator(false,*mailbox);
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1009
            }
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1010
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
  1011
            found = true;
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
  1012
            mMailboxes.removeAll(mailbox);
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
  1013
        }
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
  1014
    }
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
  1015
    return found;
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
  1016
}
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
  1017
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
  1018
/*!
51
hgs
parents: 48
diff changeset
  1019
    Create a new mailbox info entry.
hgs
parents: 48
diff changeset
  1020
hgs
parents: 48
diff changeset
  1021
    \param id Id of the mailbox
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
  1022
    \return new mailbox info object
51
hgs
parents: 48
diff changeset
  1023
 */
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
  1024
NmMailboxInfo *NmMailAgent::createMailboxInfo(const NmId &id)
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
  1025
{
43
hgs
parents: 40
diff changeset
  1026
    NM_FUNCTION;
hgs
parents: 40
diff changeset
  1027
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
  1028
    // get information of the mailbox
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
  1029
    NmMailbox *mailbox = NULL;
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1030
    NmMailboxInfo *info = NULL;
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1031
    NmDataPluginInterface *plugin = mPluginFactory->interfaceInstance(id);
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1032
    if (plugin) {
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1033
        plugin->getMailboxById(id, mailbox);
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1034
        if (mailbox) {
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1035
            info = createMailboxInfo(*mailbox,plugin);
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1036
        }
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
  1037
    }
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1038
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1039
    return info;
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
  1040
}
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
  1041
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
  1042
/*!
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
  1043
    Create a new mailbox info with given parameters
51
hgs
parents: 48
diff changeset
  1044
hgs
parents: 48
diff changeset
  1045
    \param mailbox Mailbox which mailbox info will be created
hgs
parents: 48
diff changeset
  1046
    \param plugin Interface to access email data
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
  1047
    \return new mailbox info object
51
hgs
parents: 48
diff changeset
  1048
 */
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
  1049
NmMailboxInfo *NmMailAgent::createMailboxInfo(const NmMailbox &mailbox, NmDataPluginInterface *plugin)
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
  1050
{
43
hgs
parents: 40
diff changeset
  1051
    NM_FUNCTION;
hgs
parents: 40
diff changeset
  1052
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
  1053
    NmMailboxInfo *mailboxInfo = new NmMailboxInfo();
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
  1054
    mailboxInfo->mId = mailbox.id();
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
  1055
    mailboxInfo->mName = mailbox.name();
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
  1056
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
  1057
    mMailboxes.append(mailboxInfo);
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
  1058
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
  1059
    // Subscribe to get all mailbox events
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1060
    plugin->subscribeMailboxEvents(mailboxInfo->mId);
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1061
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
  1062
    // get inbox folder ID. It might be still unknown (=0).
20
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1063
    mailboxInfo->mInboxFolderId = plugin->getStandardFolderId(
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1064
        mailbox.id(), NmFolderInbox );
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1065
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1066
    // get outbox folder ID
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1067
    mailboxInfo->mOutboxFolderId = plugin->getStandardFolderId(
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1068
        mailbox.id(), NmFolderOutbox );
ecc8def7944a Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1069
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
  1070
    // Get branded mailbox icon
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
  1071
    NmMailbox mailbox2( mailbox );
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
  1072
    QString domainName = mailbox2.address().address();
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
  1073
    EmailMailboxInfo emailMailboxInfo;
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
  1074
    mailboxInfo->mIconName =
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
  1075
        emailMailboxInfo.mailboxIcon(domainName);
40
hgs
parents: 23
diff changeset
  1076
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
  1077
    return mailboxInfo;
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
  1078
}
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
  1079
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
  1080
/*!
51
hgs
parents: 48
diff changeset
  1081
    Return mailbox info class with mailbox id. If no class is found,
hgs
parents: 48
diff changeset
  1082
    create a new instance with given id.
hgs
parents: 48
diff changeset
  1083
hgs
parents: 48
diff changeset
  1084
    \param id Id of the mailbox
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
  1085
    \return mailbox info object
51
hgs
parents: 48
diff changeset
  1086
 */
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
  1087
NmMailboxInfo *NmMailAgent::getMailboxInfo(const NmId &id)
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
  1088
{
43
hgs
parents: 40
diff changeset
  1089
    NM_FUNCTION;
hgs
parents: 40
diff changeset
  1090
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
  1091
    foreach (NmMailboxInfo *mailbox, mMailboxes) {
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
  1092
        if (mailbox->mId == id) {
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
  1093
            return mailbox;
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
  1094
        }
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
  1095
    }
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
  1096
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
  1097
    // Not found. Create a new mailbox info.
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
  1098
    return createMailboxInfo(id);
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
  1099
}
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
  1100
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
  1101
/*!
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
  1102
    Finds out if the message is unread.
51
hgs
parents: 48
diff changeset
  1103
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
  1104
    \param folderId the id of the folder that includes the message
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
  1105
    \param messageIds the message ids that are checked
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
  1106
    \param mailboxId the id of the mailbox that includes the message
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
  1107
    \param unreadMessage true if there was unread messages
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
  1108
    \return true if info fetching was successful
51
hgs
parents: 48
diff changeset
  1109
 */
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
  1110
bool NmMailAgent::getMessageUnreadInfo(const NmId &folderId,
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
  1111
    const NmId &messageId, const NmId &mailboxId, bool &unreadMessage)
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
  1112
{
43
hgs
parents: 40
diff changeset
  1113
    NM_FUNCTION;
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
  1114
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
  1115
    NmDataPluginInterface *plugin = mPluginFactory->interfaceInstance(mailboxId);
51
hgs
parents: 48
diff changeset
  1116
    bool ok(false);
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
  1117
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
  1118
    if (plugin) {
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
  1119
        NmMessage *message=NULL;
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
  1120
        plugin->getMessageById(mailboxId, folderId, messageId, message);
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
  1121
        if (message) {
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
  1122
            ok = true;
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
  1123
            NmMessageEnvelope envelope = message->envelope();
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
  1124
            if (!envelope.isRead()) {
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
  1125
                unreadMessage = true;
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
  1126
            }
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
  1127
            delete message;
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
  1128
        }
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
  1129
    }
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
  1130
    return ok;
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
  1131
}
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
  1132
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
  1133
/*!
51
hgs
parents: 48
diff changeset
  1134
    Plays email alert tone when new messages arrive.
hgs
parents: 48
diff changeset
  1135
43
hgs
parents: 40
diff changeset
  1136
	\returns true if the tone was played
51
hgs
parents: 48
diff changeset
  1137
 */
43
hgs
parents: 40
diff changeset
  1138
bool NmMailAgent::playAlertTone()
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
  1139
{
43
hgs
parents: 40
diff changeset
  1140
    NM_FUNCTION;
51
hgs
parents: 48
diff changeset
  1141
    bool played(false);
43
hgs
parents: 40
diff changeset
  1142
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
  1143
    if (mAlertToneAllowed) {
48
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
  1144
        // Play tone only if system tone service is available and
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
  1145
        // phone is not in silence mode.
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
  1146
        if (mSystemTone && !mSilenceMode) {
47
hgs
parents: 44
diff changeset
  1147
            mSystemTone->playTone(XQSystemToneService::EmailAlertTone);
hgs
parents: 44
diff changeset
  1148
        }
hgs
parents: 44
diff changeset
  1149
44
hgs
parents: 43
diff changeset
  1150
        // Execute the vibra effect.
hgs
parents: 43
diff changeset
  1151
        if (mVibra) {
hgs
parents: 43
diff changeset
  1152
            TRAP_IGNORE(mVibra->StartVibraL(NmAgentDefaultVibraDuration));
hgs
parents: 43
diff changeset
  1153
        }
47
hgs
parents: 44
diff changeset
  1154
43
hgs
parents: 40
diff changeset
  1155
        // play alert only once per minute
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
  1156
        mAlertToneAllowed = false;
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
  1157
        QTimer::singleShot(NmAgentAlertToneTimer, this, SLOT(enableAlertTone()));
51
hgs
parents: 48
diff changeset
  1158
        played = true;
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
  1159
    }
44
hgs
parents: 43
diff changeset
  1160
51
hgs
parents: 48
diff changeset
  1161
    return played;
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
  1162
}
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
  1163
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
  1164
/*!
51
hgs
parents: 48
diff changeset
  1165
    Allows alert tune to be played again.
hgs
parents: 48
diff changeset
  1166
 */
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
  1167
void NmMailAgent::enableAlertTone()
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
  1168
{
43
hgs
parents: 40
diff changeset
  1169
    NM_FUNCTION;
hgs
parents: 40
diff changeset
  1170
23
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
  1171
    mAlertToneAllowed = true;
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
  1172
}
2dc6caa42ec3 Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 20
diff changeset
  1173
43
hgs
parents: 40
diff changeset
  1174
/*!
51
hgs
parents: 48
diff changeset
  1175
    Update send indicator according to outbox state.
hgs
parents: 48
diff changeset
  1176
 */
43
hgs
parents: 40
diff changeset
  1177
void NmMailAgent::updateSendIndicator()
hgs
parents: 40
diff changeset
  1178
{
48
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
  1179
    NM_FUNCTION;
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
  1180
43
hgs
parents: 40
diff changeset
  1181
    // Get number of mails in outboxes
51
hgs
parents: 48
diff changeset
  1182
    int outboxMails(0);
43
hgs
parents: 40
diff changeset
  1183
    foreach (NmMailboxInfo *mailboxInfo, mMailboxes) {
hgs
parents: 40
diff changeset
  1184
        outboxMails += mailboxInfo->mOutboxMails;
hgs
parents: 40
diff changeset
  1185
    }
hgs
parents: 40
diff changeset
  1186
hgs
parents: 40
diff changeset
  1187
    if( outboxMails == 0 ) {
hgs
parents: 40
diff changeset
  1188
        mIndicator->deactivate(NmSendIndicatorName);
hgs
parents: 40
diff changeset
  1189
    }
hgs
parents: 40
diff changeset
  1190
    else if (outboxMails > mLastOutboxCount) {
hgs
parents: 40
diff changeset
  1191
        // New mails detected in outbox
hgs
parents: 40
diff changeset
  1192
51
hgs
parents: 48
diff changeset
  1193
        // indicator will disappear automatically after a delay
43
hgs
parents: 40
diff changeset
  1194
        mIndicator->activate(NmSendIndicatorName);
51
hgs
parents: 48
diff changeset
  1195
    }
43
hgs
parents: 40
diff changeset
  1196
51
hgs
parents: 48
diff changeset
  1197
    mLastOutboxCount = outboxMails;
43
hgs
parents: 40
diff changeset
  1198
}
hgs
parents: 40
diff changeset
  1199
44
hgs
parents: 43
diff changeset
  1200
/*!
51
hgs
parents: 48
diff changeset
  1201
    Store the mailbox active information to permanent storage.
hgs
parents: 48
diff changeset
  1202
hgs
parents: 48
diff changeset
  1203
    \param mailboxId Id of the mailbox
44
hgs
parents: 43
diff changeset
  1204
    \param active true if the mailbox is active
51
hgs
parents: 48
diff changeset
  1205
 */
44
hgs
parents: 43
diff changeset
  1206
void NmMailAgent::storeMailboxActive(const NmId &mailboxId, bool active)
hgs
parents: 43
diff changeset
  1207
{
48
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
  1208
    NM_FUNCTION;
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
  1209
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
  1210
    if (mSettingManager) {
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
  1211
        XQCentralRepositorySettingsKey key(NmRepositoryId, mailboxId.id());
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
  1212
        XQCentralRepositoryUtils utils(*mSettingManager);
47
hgs
parents: 44
diff changeset
  1213
48
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
  1214
        if (active) {
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
  1215
            // when mailbox is active, key can be deleted
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
  1216
            utils.deleteKey(key);
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
  1217
        }
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
  1218
        else {
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
  1219
            utils.createKey(key,(int)active);
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
  1220
        }
44
hgs
parents: 43
diff changeset
  1221
    }
hgs
parents: 43
diff changeset
  1222
}
hgs
parents: 43
diff changeset
  1223
hgs
parents: 43
diff changeset
  1224
/*!
47
hgs
parents: 44
diff changeset
  1225
    Get the mailbox activity state.
51
hgs
parents: 48
diff changeset
  1226
44
hgs
parents: 43
diff changeset
  1227
    \param mailboxId id of the mailbox
hgs
parents: 43
diff changeset
  1228
    \return true if the mailbox is active or no information was stored earlier
51
hgs
parents: 48
diff changeset
  1229
 */
44
hgs
parents: 43
diff changeset
  1230
bool NmMailAgent::isMailboxActive(const NmId &mailboxId)
hgs
parents: 43
diff changeset
  1231
{
48
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
  1232
    NM_FUNCTION;
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
  1233
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
  1234
    bool mailboxActive(true);
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
  1235
    if (mSettingManager) {
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
  1236
        XQCentralRepositorySettingsKey key(NmRepositoryId, mailboxId.id());
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
  1237
        QVariant value = mSettingManager->readItemValue(key, XQSettingsManager::TypeInt);
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
  1238
        if (value.isValid()) {
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
  1239
            NM_COMMENT(QString("NmMailAgent::isMailboxActive - value=%1").arg(value.toInt()));
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
  1240
            mailboxActive = value.toInt();
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
  1241
        }
44
hgs
parents: 43
diff changeset
  1242
    }
48
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
  1243
    return mailboxActive;
44
hgs
parents: 43
diff changeset
  1244
}
hgs
parents: 43
diff changeset
  1245
hgs
parents: 43
diff changeset
  1246
/*!
51
hgs
parents: 48
diff changeset
  1247
    Delete all stored activity information for the mailbox id.
hgs
parents: 48
diff changeset
  1248
44
hgs
parents: 43
diff changeset
  1249
    \param mailboxId id of the mailbox
51
hgs
parents: 48
diff changeset
  1250
 */
44
hgs
parents: 43
diff changeset
  1251
void NmMailAgent::deleteStoredMailboxActivity(const NmId &mailboxId)
hgs
parents: 43
diff changeset
  1252
{
48
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
  1253
    NM_FUNCTION;
10eaf342f539 201025_1
hgs
parents: 47
diff changeset
  1254
44
hgs
parents: 43
diff changeset
  1255
    // deactivation delete the key too
51
hgs
parents: 48
diff changeset
  1256
    storeMailboxActive(mailboxId, false);
44
hgs
parents: 43
diff changeset
  1257
}
hgs
parents: 43
diff changeset
  1258
18
578830873419 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
  1259
// End of file