emailservices/nmclientapi/src/nmapisettingsmanager_p.cpp
author hgs
Fri, 23 Jul 2010 19:09:50 +0300
changeset 56 15bc1d5d6267
child 74 6c59112cfd31
permissions -rw-r--r--
201029
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
56
hgs
parents:
diff changeset
     1
/*
hgs
parents:
diff changeset
     2
 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
hgs
parents:
diff changeset
     3
 * All rights reserved.
hgs
parents:
diff changeset
     4
 * This component and the accompanying materials are made available
hgs
parents:
diff changeset
     5
 * under the terms of "Eclipse Public License v1.0"
hgs
parents:
diff changeset
     6
 * which accompanies this distribution, and is available
hgs
parents:
diff changeset
     7
 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
hgs
parents:
diff changeset
     8
 *
hgs
parents:
diff changeset
     9
 * Initial Contributors:
hgs
parents:
diff changeset
    10
 * Nokia Corporation - initial contribution.
hgs
parents:
diff changeset
    11
 *
hgs
parents:
diff changeset
    12
 * Contributors:
hgs
parents:
diff changeset
    13
 *
hgs
parents:
diff changeset
    14
 * Description:
hgs
parents:
diff changeset
    15
 *
hgs
parents:
diff changeset
    16
 */
hgs
parents:
diff changeset
    17
hgs
parents:
diff changeset
    18
#include <QVariant>
hgs
parents:
diff changeset
    19
#include <QList>
hgs
parents:
diff changeset
    20
hgs
parents:
diff changeset
    21
#include <xqconversions.h>
hgs
parents:
diff changeset
    22
#include <xqsettingsmanager.h>
hgs
parents:
diff changeset
    23
#include <xqcentralrepositoryutils.h>
hgs
parents:
diff changeset
    24
#include <xqcentralrepositorysearchcriteria.h>
hgs
parents:
diff changeset
    25
hgs
parents:
diff changeset
    26
#include <pop3set.h>
hgs
parents:
diff changeset
    27
#include <imapset.h>
hgs
parents:
diff changeset
    28
#include <smtpset.h>
hgs
parents:
diff changeset
    29
#include <iapprefs.h>
hgs
parents:
diff changeset
    30
hgs
parents:
diff changeset
    31
#include "ipssettingkeys.h"
hgs
parents:
diff changeset
    32
#include "nmapiheaders.h"
hgs
parents:
diff changeset
    33
#include <nmapisettingsmanager.h>
hgs
parents:
diff changeset
    34
#include "nmapisettingsmanager_p.h"
hgs
parents:
diff changeset
    35
hgs
parents:
diff changeset
    36
namespace EmailClientApi
hgs
parents:
diff changeset
    37
{
hgs
parents:
diff changeset
    38
hgs
parents:
diff changeset
    39
NmApiSettingsManagerPrivate::NmApiSettingsManagerPrivate(const quint64 mailboxId)
hgs
parents:
diff changeset
    40
    : mAccount(0),
hgs
parents:
diff changeset
    41
    mPop3Settings(0),
hgs
parents:
diff changeset
    42
    mImap4Settings(0),
hgs
parents:
diff changeset
    43
    mSmtpSettings(0),
hgs
parents:
diff changeset
    44
    mMailboxOffset(-1),
hgs
parents:
diff changeset
    45
    mMailboxId(0)
hgs
parents:
diff changeset
    46
{
hgs
parents:
diff changeset
    47
    QT_TRAP_THROWING(mAccount = CEmailAccounts::NewL());
hgs
parents:
diff changeset
    48
    mMailboxId = (quint32)mailboxId;
hgs
parents:
diff changeset
    49
hgs
parents:
diff changeset
    50
    mQSettingsManager = new XQSettingsManager();
hgs
parents:
diff changeset
    51
    Q_CHECK_PTR(mQSettingsManager);
hgs
parents:
diff changeset
    52
hgs
parents:
diff changeset
    53
    checkAccountType();
hgs
parents:
diff changeset
    54
    QT_TRAP_THROWING(initAccountL());
hgs
parents:
diff changeset
    55
    calculateMailboxOffset();
hgs
parents:
diff changeset
    56
hgs
parents:
diff changeset
    57
}
hgs
parents:
diff changeset
    58
hgs
parents:
diff changeset
    59
NmApiSettingsManagerPrivate::~NmApiSettingsManagerPrivate()
hgs
parents:
diff changeset
    60
{
hgs
parents:
diff changeset
    61
    delete mPop3Settings;
hgs
parents:
diff changeset
    62
    delete mImap4Settings;
hgs
parents:
diff changeset
    63
    delete mSmtpSettings;
hgs
parents:
diff changeset
    64
    delete mQSettingsManager;
hgs
parents:
diff changeset
    65
    delete mAccount;
hgs
parents:
diff changeset
    66
}
hgs
parents:
diff changeset
    67
hgs
parents:
diff changeset
    68
/*!
hgs
parents:
diff changeset
    69
 Loads QMail specific settings.
hgs
parents:
diff changeset
    70
 \param mailboxId which settings are returned
hgs
parents:
diff changeset
    71
 \param data consists of keys and values of settings.
hgs
parents:
diff changeset
    72
 \return bool <true> when the setting items were found otherwise <false>.
hgs
parents:
diff changeset
    73
 */
hgs
parents:
diff changeset
    74
bool NmApiSettingsManagerPrivate::load(quint64 mailboxId, NmApiMailboxSettingsData &data)
hgs
parents:
diff changeset
    75
{
hgs
parents:
diff changeset
    76
	mMailboxId = mailboxId;
hgs
parents:
diff changeset
    77
    return (readSetting(data) && readCenRepSetting(data));
hgs
parents:
diff changeset
    78
}
hgs
parents:
diff changeset
    79
hgs
parents:
diff changeset
    80
/*!
hgs
parents:
diff changeset
    81
 Saves QMail specific settings.
hgs
parents:
diff changeset
    82
 \param data consists of keys and values of settings.
hgs
parents:
diff changeset
    83
 \return bool <true> when the setting items were successfully saved otherwise <false>.
hgs
parents:
diff changeset
    84
 */
hgs
parents:
diff changeset
    85
bool NmApiSettingsManagerPrivate::save(const NmApiMailboxSettingsData &data)
hgs
parents:
diff changeset
    86
{
hgs
parents:
diff changeset
    87
    TInt err(KErrNone);
hgs
parents:
diff changeset
    88
    TRAP(err, writeSettingL(data));
hgs
parents:
diff changeset
    89
    return (!err && writeSettingToCenRep(data));
hgs
parents:
diff changeset
    90
}
hgs
parents:
diff changeset
    91
hgs
parents:
diff changeset
    92
/*!
hgs
parents:
diff changeset
    93
 Finds and returns the SMTP specific setting.
hgs
parents:
diff changeset
    94
 \param settingItem SettingItem enum of the setting to return
hgs
parents:
diff changeset
    95
 \param QVariant SettingValue of the found setting value.
hgs
parents:
diff changeset
    96
 \return bool <true> when the setting item was found otherwise <false>.
hgs
parents:
diff changeset
    97
 */
hgs
parents:
diff changeset
    98
bool NmApiSettingsManagerPrivate::readSetting(NmApiMailboxSettingsData &data)
hgs
parents:
diff changeset
    99
{
hgs
parents:
diff changeset
   100
    if (mMailboxType == NmApiMailboxTypePop) {
hgs
parents:
diff changeset
   101
        data.setValue(IncomingLoginName, XQConversions::s60Desc8ToQString(mPop3Settings->LoginName()));
hgs
parents:
diff changeset
   102
        data.setValue(IncomingPassword, XQConversions::s60Desc8ToQString(mPop3Settings->Password()));
hgs
parents:
diff changeset
   103
        data.setValue(MailboxName, XQConversions::s60DescToQString(mPop3Account.iPopAccountName));
hgs
parents:
diff changeset
   104
        data.setValue(IncomingMailServer, XQConversions::s60DescToQString(mPop3Settings->ServerAddress()));
hgs
parents:
diff changeset
   105
#if (defined SYMBIAN_EMAIL_CAPABILITY_SUPPORT)
hgs
parents:
diff changeset
   106
        data.setValue(IncomingMailUsesAuthentication, mPop3Settings->POP3Auth());
hgs
parents:
diff changeset
   107
#endif
hgs
parents:
diff changeset
   108
        data.setValue(IncomingPort, mPop3Settings->Port());
hgs
parents:
diff changeset
   109
    }
hgs
parents:
diff changeset
   110
    else if (mMailboxType  == NmApiMailboxTypeImap) {
hgs
parents:
diff changeset
   111
        data.setValue(IncomingLoginName, XQConversions::s60Desc8ToQString(mImap4Settings->LoginName()));
hgs
parents:
diff changeset
   112
        data.setValue(IncomingPassword, XQConversions::s60Desc8ToQString(mImap4Settings->Password()));
hgs
parents:
diff changeset
   113
        data.setValue(MailboxName, XQConversions::s60DescToQString(
hgs
parents:
diff changeset
   114
                mImap4Account.iImapAccountName));
hgs
parents:
diff changeset
   115
        data.setValue(IncomingMailServer, XQConversions::s60DescToQString(
hgs
parents:
diff changeset
   116
                mImap4Settings->ServerAddress()));
hgs
parents:
diff changeset
   117
#if (defined SYMBIAN_EMAIL_CAPABILITY_SUPPORT)
hgs
parents:
diff changeset
   118
        data.setValue(IncomingMailUsesAuthentication, mImap4Settings->IAMP4Auth());
hgs
parents:
diff changeset
   119
#endif
hgs
parents:
diff changeset
   120
        data.setValue(IncomingPort, mImap4Settings->Port());
hgs
parents:
diff changeset
   121
        data.setValue(FolderPath, XQConversions::s60Desc8ToQString(mImap4Settings->FolderPath()));
hgs
parents:
diff changeset
   122
    }
hgs
parents:
diff changeset
   123
hgs
parents:
diff changeset
   124
    data.setValue(IncomingMailSecurityType, security());
hgs
parents:
diff changeset
   125
    data.setValue(MyName, XQConversions::s60DescToQString(mSmtpSettings->EmailAlias()));
hgs
parents:
diff changeset
   126
    data.setValue(EmailAlias, XQConversions::s60DescToQString(mSmtpSettings->EmailAlias()));
hgs
parents:
diff changeset
   127
    data.setValue(EmailAddress, XQConversions::s60DescToQString(mSmtpSettings->EmailAddress()));
hgs
parents:
diff changeset
   128
    data.setValue(ReplyAddress, XQConversions::s60DescToQString(mSmtpSettings->ReplyToAddress()));
hgs
parents:
diff changeset
   129
    data.setValue(OutgoingMailServer, XQConversions::s60DescToQString(mSmtpSettings->ServerAddress()));
hgs
parents:
diff changeset
   130
    data.setValue(OutgoingPort, mSmtpSettings->Port());
hgs
parents:
diff changeset
   131
    data.setValue(OutgoingLoginName, XQConversions::s60Desc8ToQString(mSmtpSettings->LoginName()));
hgs
parents:
diff changeset
   132
    data.setValue(OutgoingPassword, XQConversions::s60Desc8ToQString(mSmtpSettings->Password()));
hgs
parents:
diff changeset
   133
    data.setValue(UseOutgoingAuthentication, mSmtpSettings->SMTPAuth());
hgs
parents:
diff changeset
   134
    data.setValue(OutgoingMailUsesAuthentication, mSmtpSettings->SMTPAuth());
hgs
parents:
diff changeset
   135
    data.setValue(OutgoingSecureSockets, mSmtpSettings->SecureSockets());
hgs
parents:
diff changeset
   136
    data.setValue(OutgoingSSLWrapper, mSmtpSettings->SSLWrapper());
hgs
parents:
diff changeset
   137
    data.setValue(OutgoingMailSecurityType, XQConversions::s60Desc8ToQString(mSmtpSettings->TlsSslDomain()));
hgs
parents:
diff changeset
   138
    return true;
hgs
parents:
diff changeset
   139
}
hgs
parents:
diff changeset
   140
hgs
parents:
diff changeset
   141
bool NmApiSettingsManagerPrivate::readCenRepSetting(NmApiMailboxSettingsData &data)
hgs
parents:
diff changeset
   142
{
hgs
parents:
diff changeset
   143
    bool ret = true;
hgs
parents:
diff changeset
   144
    QVariant tmp;
hgs
parents:
diff changeset
   145
    data.setValue(DownloadPictures, readFromCenRep(IpsServices::EmailKeyPreferenceDownloadPictures));
hgs
parents:
diff changeset
   146
    data.setValue(MessageDivider, readFromCenRep(IpsServices::EmailKeyPreferenceMessageDivider));
hgs
parents:
diff changeset
   147
hgs
parents:
diff changeset
   148
    tmp = readFromCenRep(IpsServices::EmailKeyReceptionActiveProfile);
hgs
parents:
diff changeset
   149
    switch(tmp.toInt()){
hgs
parents:
diff changeset
   150
        case 0:
hgs
parents:
diff changeset
   151
            data.setValue(ReceptionActiveProfile, EmailClientApi::EmailProfileOffsetKUTD);
hgs
parents:
diff changeset
   152
            break;
hgs
parents:
diff changeset
   153
        case 1:
hgs
parents:
diff changeset
   154
            data.setValue(ReceptionActiveProfile, EmailClientApi::EmailProfileOffsetSE);
hgs
parents:
diff changeset
   155
            break;
hgs
parents:
diff changeset
   156
        case 2:
hgs
parents:
diff changeset
   157
            data.setValue(ReceptionActiveProfile, EmailClientApi::EmailProfileOffsetMF);
hgs
parents:
diff changeset
   158
            break;
hgs
parents:
diff changeset
   159
        case 3:
hgs
parents:
diff changeset
   160
            data.setValue(ReceptionActiveProfile, EmailClientApi::EmailProfileOffsetUD);
hgs
parents:
diff changeset
   161
            break;
hgs
parents:
diff changeset
   162
        default:
hgs
parents:
diff changeset
   163
            data.setValue(ReceptionActiveProfile, EmailClientApi::EmailProfileOffsetKUTD);
hgs
parents:
diff changeset
   164
            break;
hgs
parents:
diff changeset
   165
    };
hgs
parents:
diff changeset
   166
hgs
parents:
diff changeset
   167
    data.setValue(ReceptionUserDefinedProfile, readFromCenRep(IpsServices::EmailKeyReceptionUserDefinedProfile));
hgs
parents:
diff changeset
   168
    data.setValue(ReceptionInboxSyncWindow, readFromCenRep(mActiveProfileOffset
hgs
parents:
diff changeset
   169
                        + IpsServices::EmailKeyReceptionInboxSyncWindow));
hgs
parents:
diff changeset
   170
    data.setValue(ReceptionGenericSyncWindowInMessages, readFromCenRep(mActiveProfileOffset
hgs
parents:
diff changeset
   171
                        + IpsServices::EmailKeyReceptionGenericSyncWindowInMessages));
hgs
parents:
diff changeset
   172
    data.setValue(ReceptionWeekDays, readFromCenRep(mActiveProfileOffset
hgs
parents:
diff changeset
   173
                        + IpsServices::EmailKeyReceptionWeekDays));
hgs
parents:
diff changeset
   174
    data.setValue(ReceptionDayStartTime, readFromCenRep(mActiveProfileOffset
hgs
parents:
diff changeset
   175
                        + IpsServices::EmailKeyReceptionDayStartTime));
hgs
parents:
diff changeset
   176
    data.setValue(ReceptionDayEndTime, readFromCenRep(mActiveProfileOffset
hgs
parents:
diff changeset
   177
                        + IpsServices::EmailKeyReceptionDayEndTime));
hgs
parents:
diff changeset
   178
    data.setValue(ReceptionRefreshPeriodDayTime, readFromCenRep(mActiveProfileOffset
hgs
parents:
diff changeset
   179
                        + IpsServices::EmailKeyReceptionRefreshPeriodDayTime));
hgs
parents:
diff changeset
   180
    data.setValue(ReceptionRefreshPeriodOther, readFromCenRep(mActiveProfileOffset
hgs
parents:
diff changeset
   181
                        + IpsServices::EmailKeyReceptionRefreshPeriodOther));
hgs
parents:
diff changeset
   182
    data.setValue(UserNameHidden, readFromCenRep(IpsServices::EmailKeyUserNameHidden));
hgs
parents:
diff changeset
   183
    data.setValue(EmailNotificationState, readFromCenRep(IpsServices::EmailKeyEMNState));
hgs
parents:
diff changeset
   184
    data.setValue(FirstEmnReceived, readFromCenRep(IpsServices::EmailKeyFirstEmnReceived));
hgs
parents:
diff changeset
   185
    data.setValue(EmnReceivedNotSynced, readFromCenRep(IpsServices::EmailKeyEmnReceivedNotSynced));
hgs
parents:
diff changeset
   186
hgs
parents:
diff changeset
   187
    QString aolState = alwaysOnlineState();
hgs
parents:
diff changeset
   188
    if(aolState.length()>0)
hgs
parents:
diff changeset
   189
        data.setValue(AlwaysOnlineState, aolState);
hgs
parents:
diff changeset
   190
hgs
parents:
diff changeset
   191
    data.setValue(AoLastSuccessfulUpdate, readFromCenRep(IpsServices::EmailKeyAoLastSuccessfulUpdateL));
hgs
parents:
diff changeset
   192
    data.setValue(AoLastUpdateFailed, readFromCenRep(IpsServices::EmailKeyAoLastUpdateFailed));
hgs
parents:
diff changeset
   193
    data.setValue(AoUpdateSuccessfulWithCurSettings, readFromCenRep(IpsServices::EmailKeyAoUpdateSuccessfulWithCurSettings));
hgs
parents:
diff changeset
   194
    return ret;
hgs
parents:
diff changeset
   195
}
hgs
parents:
diff changeset
   196
hgs
parents:
diff changeset
   197
/*!
hgs
parents:
diff changeset
   198
 Writes POP3/IMAP4 specific settings.
hgs
parents:
diff changeset
   199
 \param data consists of keys and values of settings.
hgs
parents:
diff changeset
   200
 */
hgs
parents:
diff changeset
   201
bool NmApiSettingsManagerPrivate::writeSettingL(const NmApiMailboxSettingsData &data)
hgs
parents:
diff changeset
   202
{
hgs
parents:
diff changeset
   203
    HBufC *tmp = 0;
hgs
parents:
diff changeset
   204
    HBufC8 *tmp8 = 0;
hgs
parents:
diff changeset
   205
    bool ret(false);
hgs
parents:
diff changeset
   206
    int key;
hgs
parents:
diff changeset
   207
    QVariant settingValue;
hgs
parents:
diff changeset
   208
    QList<int> keylist;
hgs
parents:
diff changeset
   209
    bool aliasSet = false;
hgs
parents:
diff changeset
   210
hgs
parents:
diff changeset
   211
    keylist = data.listSettings();
hgs
parents:
diff changeset
   212
    for (int i = 0; i < keylist.size(); i++) {
hgs
parents:
diff changeset
   213
        key = keylist[i];
hgs
parents:
diff changeset
   214
        data.getValue(key, settingValue);
hgs
parents:
diff changeset
   215
        switch (key) {
hgs
parents:
diff changeset
   216
            case IncomingLoginName: {
hgs
parents:
diff changeset
   217
                tmp8 = XQConversions::qStringToS60Desc8(settingValue.toString());
hgs
parents:
diff changeset
   218
                if (mMailboxType == NmApiMailboxTypePop) {
hgs
parents:
diff changeset
   219
                    mPop3Settings->SetLoginNameL(*tmp8);
hgs
parents:
diff changeset
   220
                }
hgs
parents:
diff changeset
   221
                else if (mMailboxType == NmApiMailboxTypeImap) {
hgs
parents:
diff changeset
   222
                    mImap4Settings->SetLoginNameL(*tmp8);
hgs
parents:
diff changeset
   223
                    }
hgs
parents:
diff changeset
   224
                delete tmp8;
hgs
parents:
diff changeset
   225
                break;
hgs
parents:
diff changeset
   226
            }
hgs
parents:
diff changeset
   227
            case IncomingPassword: {
hgs
parents:
diff changeset
   228
                tmp8 = XQConversions::qStringToS60Desc8(settingValue.toString());
hgs
parents:
diff changeset
   229
                if (mMailboxType == NmApiMailboxTypePop) {
hgs
parents:
diff changeset
   230
                    mPop3Settings->SetPasswordL(*tmp8);
hgs
parents:
diff changeset
   231
                }
hgs
parents:
diff changeset
   232
                else if (mMailboxType == NmApiMailboxTypeImap) {
hgs
parents:
diff changeset
   233
                    mImap4Settings->SetPasswordL(*tmp8);
hgs
parents:
diff changeset
   234
                    }
hgs
parents:
diff changeset
   235
                delete tmp8;
hgs
parents:
diff changeset
   236
                break;
hgs
parents:
diff changeset
   237
            }
hgs
parents:
diff changeset
   238
            case MailboxName: {
hgs
parents:
diff changeset
   239
                tmp = XQConversions::qStringToS60Desc(settingValue.toString());
hgs
parents:
diff changeset
   240
                if (mMailboxType == NmApiMailboxTypePop) {
hgs
parents:
diff changeset
   241
                    mPop3Account.iPopAccountName.Copy(*tmp);
hgs
parents:
diff changeset
   242
                }
hgs
parents:
diff changeset
   243
                else if (mMailboxType == NmApiMailboxTypeImap) {
hgs
parents:
diff changeset
   244
                    mImap4Account.iImapAccountName.Copy(*tmp);
hgs
parents:
diff changeset
   245
                    }
hgs
parents:
diff changeset
   246
                delete tmp;
hgs
parents:
diff changeset
   247
                break;
hgs
parents:
diff changeset
   248
            }
hgs
parents:
diff changeset
   249
            case IncomingMailServer: {
hgs
parents:
diff changeset
   250
                tmp = XQConversions::qStringToS60Desc(settingValue.toString());
hgs
parents:
diff changeset
   251
hgs
parents:
diff changeset
   252
                if (mMailboxType == NmApiMailboxTypePop) {
hgs
parents:
diff changeset
   253
                    mPop3Settings->SetServerAddressL(*tmp);
hgs
parents:
diff changeset
   254
                }
hgs
parents:
diff changeset
   255
                else if (mMailboxType == NmApiMailboxTypeImap) {
hgs
parents:
diff changeset
   256
                    mImap4Settings->SetServerAddressL(*tmp);
hgs
parents:
diff changeset
   257
                    }
hgs
parents:
diff changeset
   258
                delete tmp;
hgs
parents:
diff changeset
   259
                break;
hgs
parents:
diff changeset
   260
            }
hgs
parents:
diff changeset
   261
            case IncomingMailUsesAuthentication: {
hgs
parents:
diff changeset
   262
#if (defined SYMBIAN_EMAIL_CAPABILITY_SUPPORT)
hgs
parents:
diff changeset
   263
hgs
parents:
diff changeset
   264
                if (mMailboxType == NmApiMailboxTypePop) {
hgs
parents:
diff changeset
   265
                    mPop3Settings->SetPOP3Auth(settingValue.toBool());
hgs
parents:
diff changeset
   266
                }
hgs
parents:
diff changeset
   267
                else if (mMailboxType == NmApiMailboxTypeImap) {
hgs
parents:
diff changeset
   268
                    mImap4Settings->SetIAMP4Auth(settingValue.toBool());
hgs
parents:
diff changeset
   269
                }
hgs
parents:
diff changeset
   270
#endif
hgs
parents:
diff changeset
   271
                break;
hgs
parents:
diff changeset
   272
            }
hgs
parents:
diff changeset
   273
            case IncomingMailSecurityType: {
hgs
parents:
diff changeset
   274
                setSecurity(settingValue.toString());
hgs
parents:
diff changeset
   275
                break;
hgs
parents:
diff changeset
   276
            }
hgs
parents:
diff changeset
   277
            case IncomingPort: {
hgs
parents:
diff changeset
   278
                if (mMailboxType == NmApiMailboxTypePop) {
hgs
parents:
diff changeset
   279
                mPop3Settings->SetPort(settingValue.toInt());
hgs
parents:
diff changeset
   280
                }
hgs
parents:
diff changeset
   281
                else if (mMailboxType == NmApiMailboxTypeImap) {
hgs
parents:
diff changeset
   282
                    mImap4Settings->SetPort(settingValue.toInt());
hgs
parents:
diff changeset
   283
                }
hgs
parents:
diff changeset
   284
                break;
hgs
parents:
diff changeset
   285
            }
hgs
parents:
diff changeset
   286
            case OutgoingPort: {
hgs
parents:
diff changeset
   287
                mSmtpSettings->SetPort(settingValue.toInt());
hgs
parents:
diff changeset
   288
                break;
hgs
parents:
diff changeset
   289
            }
hgs
parents:
diff changeset
   290
            case IncomingSecureSockets: {
hgs
parents:
diff changeset
   291
                if (mMailboxType == NmApiMailboxTypePop) {
hgs
parents:
diff changeset
   292
                    mPop3Settings->SetSecureSockets(settingValue.toBool());
hgs
parents:
diff changeset
   293
                 }
hgs
parents:
diff changeset
   294
                 else if (mMailboxType == NmApiMailboxTypeImap) {
hgs
parents:
diff changeset
   295
                    mImap4Settings->SetSecureSockets(settingValue.toBool());
hgs
parents:
diff changeset
   296
                     }
hgs
parents:
diff changeset
   297
                break;
hgs
parents:
diff changeset
   298
            }
hgs
parents:
diff changeset
   299
            case IncomingSSLWrapper: {
hgs
parents:
diff changeset
   300
                if (mMailboxType == NmApiMailboxTypePop) {
hgs
parents:
diff changeset
   301
                    mPop3Settings->SetSSLWrapper(settingValue.toBool());
hgs
parents:
diff changeset
   302
                }
hgs
parents:
diff changeset
   303
                else if (mMailboxType == NmApiMailboxTypeImap) {
hgs
parents:
diff changeset
   304
                    mImap4Settings->SetSSLWrapper(settingValue.toBool());
hgs
parents:
diff changeset
   305
                    }
hgs
parents:
diff changeset
   306
                break;
hgs
parents:
diff changeset
   307
            }
hgs
parents:
diff changeset
   308
            case EmailAddress: {
hgs
parents:
diff changeset
   309
                tmp = XQConversions::qStringToS60Desc(settingValue.toString());
hgs
parents:
diff changeset
   310
                mSmtpSettings->SetEmailAddressL(*tmp);
hgs
parents:
diff changeset
   311
                break;
hgs
parents:
diff changeset
   312
            }
hgs
parents:
diff changeset
   313
            case ReplyAddress: {
hgs
parents:
diff changeset
   314
                tmp = XQConversions::qStringToS60Desc(settingValue.toString());
hgs
parents:
diff changeset
   315
                mSmtpSettings->SetReplyToAddressL(*tmp);
hgs
parents:
diff changeset
   316
                break;
hgs
parents:
diff changeset
   317
            }
hgs
parents:
diff changeset
   318
            case EmailAlias: {
hgs
parents:
diff changeset
   319
                QVariant tmpName;
hgs
parents:
diff changeset
   320
                if(data.getValue(MyName,tmpName)) {
hgs
parents:
diff changeset
   321
                    if(tmpName.toString()
hgs
parents:
diff changeset
   322
                        ==XQConversions::s60DescToQString(mSmtpSettings->EmailAlias())) {
hgs
parents:
diff changeset
   323
                        aliasSet = true;
hgs
parents:
diff changeset
   324
                    }
hgs
parents:
diff changeset
   325
                }
hgs
parents:
diff changeset
   326
                tmp = XQConversions::qStringToS60Desc(settingValue.toString());
hgs
parents:
diff changeset
   327
                mSmtpSettings->SetEmailAliasL(*tmp);
hgs
parents:
diff changeset
   328
                break;
hgs
parents:
diff changeset
   329
            }
hgs
parents:
diff changeset
   330
            case MyName: {
hgs
parents:
diff changeset
   331
                if(!aliasSet) {
hgs
parents:
diff changeset
   332
                tmp = XQConversions::qStringToS60Desc(settingValue.toString());
hgs
parents:
diff changeset
   333
                mSmtpSettings->SetEmailAliasL(*tmp);
hgs
parents:
diff changeset
   334
                }
hgs
parents:
diff changeset
   335
                break;
hgs
parents:
diff changeset
   336
            }
hgs
parents:
diff changeset
   337
            case OutgoingMailServer: {
hgs
parents:
diff changeset
   338
                tmp = XQConversions::qStringToS60Desc(settingValue.toString());
hgs
parents:
diff changeset
   339
                mSmtpSettings->SetServerAddressL(*tmp);
hgs
parents:
diff changeset
   340
                break;
hgs
parents:
diff changeset
   341
            }
hgs
parents:
diff changeset
   342
            case OutgoingLoginName: {
hgs
parents:
diff changeset
   343
                tmp8 = XQConversions::qStringToS60Desc8(settingValue.toString());
hgs
parents:
diff changeset
   344
                mSmtpSettings->SetLoginNameL(*tmp8);
hgs
parents:
diff changeset
   345
                break;
hgs
parents:
diff changeset
   346
            }
hgs
parents:
diff changeset
   347
            case OutgoingPassword: {
hgs
parents:
diff changeset
   348
                tmp8 = XQConversions::qStringToS60Desc8(settingValue.toString());
hgs
parents:
diff changeset
   349
                mSmtpSettings->SetPasswordL(*tmp8);
hgs
parents:
diff changeset
   350
                break;
hgs
parents:
diff changeset
   351
            }
hgs
parents:
diff changeset
   352
            case UseOutgoingAuthentication:
hgs
parents:
diff changeset
   353
            case OutgoingMailUsesAuthentication: {
hgs
parents:
diff changeset
   354
                mSmtpSettings->SetSMTPAuth(settingValue.toBool());
hgs
parents:
diff changeset
   355
                break;
hgs
parents:
diff changeset
   356
            }
hgs
parents:
diff changeset
   357
            case OutgoingSecureSockets: {
hgs
parents:
diff changeset
   358
                mSmtpSettings->SetSecureSockets(settingValue.toBool());
hgs
parents:
diff changeset
   359
                break;
hgs
parents:
diff changeset
   360
            }
hgs
parents:
diff changeset
   361
            case OutgoingSSLWrapper: {
hgs
parents:
diff changeset
   362
                mSmtpSettings->SetSSLWrapper(settingValue.toBool());
hgs
parents:
diff changeset
   363
                break;
hgs
parents:
diff changeset
   364
            }
hgs
parents:
diff changeset
   365
            case OutgoingMailSecurityType: {
hgs
parents:
diff changeset
   366
                tmp8 = XQConversions::qStringToS60Desc8(settingValue.toString());
hgs
parents:
diff changeset
   367
                mSmtpSettings->SetTlsSslDomainL(*tmp8);
hgs
parents:
diff changeset
   368
                break;
hgs
parents:
diff changeset
   369
            }
hgs
parents:
diff changeset
   370
            case FolderPath: {
hgs
parents:
diff changeset
   371
                tmp8 = XQConversions::qStringToS60Desc8(settingValue.toString());
hgs
parents:
diff changeset
   372
                mImap4Settings->SetFolderPathL(*tmp8);
hgs
parents:
diff changeset
   373
                break;
hgs
parents:
diff changeset
   374
            }
hgs
parents:
diff changeset
   375
            default: {
hgs
parents:
diff changeset
   376
				break;
hgs
parents:
diff changeset
   377
            }
hgs
parents:
diff changeset
   378
        };
hgs
parents:
diff changeset
   379
    }
hgs
parents:
diff changeset
   380
    ret = saveSettings();
hgs
parents:
diff changeset
   381
    return ret;
hgs
parents:
diff changeset
   382
}
hgs
parents:
diff changeset
   383
hgs
parents:
diff changeset
   384
/*!
hgs
parents:
diff changeset
   385
Writes settings to central repository.
hgs
parents:
diff changeset
   386
\param data consists of keys and values of settings.
hgs
parents:
diff changeset
   387
 */
hgs
parents:
diff changeset
   388
bool NmApiSettingsManagerPrivate::writeSettingToCenRep(
hgs
parents:
diff changeset
   389
    const NmApiMailboxSettingsData &data)
hgs
parents:
diff changeset
   390
{
hgs
parents:
diff changeset
   391
    int key;
hgs
parents:
diff changeset
   392
    QVariant settingValue;
hgs
parents:
diff changeset
   393
    QList<int> keylist;
hgs
parents:
diff changeset
   394
hgs
parents:
diff changeset
   395
    keylist = data.listSettings();
hgs
parents:
diff changeset
   396
    bool ret = false;
hgs
parents:
diff changeset
   397
    if(keylist.contains(ReceptionActiveProfile)) {
hgs
parents:
diff changeset
   398
        data.getValue(ReceptionActiveProfile,settingValue);
hgs
parents:
diff changeset
   399
        QVariant profileOffset = 0;
hgs
parents:
diff changeset
   400
        if(settingValue.toString() == EmailClientApi::EmailProfileOffsetKUTD) {
hgs
parents:
diff changeset
   401
            profileOffset=0;
hgs
parents:
diff changeset
   402
        } else if(settingValue.toString() == EmailClientApi::EmailProfileOffsetSE){
hgs
parents:
diff changeset
   403
            profileOffset = 1;
hgs
parents:
diff changeset
   404
        } else if (settingValue.toString() == EmailClientApi::EmailProfileOffsetMF){
hgs
parents:
diff changeset
   405
                    profileOffset = 2;
hgs
parents:
diff changeset
   406
        } else if (settingValue.toString() == EmailClientApi::EmailProfileOffsetUD) {
hgs
parents:
diff changeset
   407
            profileOffset = 3;
hgs
parents:
diff changeset
   408
        }
hgs
parents:
diff changeset
   409
        ret = writeToCenRep(IpsServices::EmailKeyReceptionActiveProfile, profileOffset);
hgs
parents:
diff changeset
   410
        if(ret) {
hgs
parents:
diff changeset
   411
            calculateActiveProfileOffset();
hgs
parents:
diff changeset
   412
        }
hgs
parents:
diff changeset
   413
    }
hgs
parents:
diff changeset
   414
    if (ret) {
hgs
parents:
diff changeset
   415
        for (int i = 0; i < keylist.size(); i++) {
hgs
parents:
diff changeset
   416
            key = keylist[i];
hgs
parents:
diff changeset
   417
            data.getValue(key, settingValue);
hgs
parents:
diff changeset
   418
            switch (key) {
hgs
parents:
diff changeset
   419
                case DownloadPictures: {
hgs
parents:
diff changeset
   420
                    ret = writeToCenRep(IpsServices::EmailKeyPreferenceDownloadPictures,
hgs
parents:
diff changeset
   421
                        settingValue);
hgs
parents:
diff changeset
   422
                    break;
hgs
parents:
diff changeset
   423
                }
hgs
parents:
diff changeset
   424
                case MessageDivider: {
hgs
parents:
diff changeset
   425
                    ret = writeToCenRep(IpsServices::EmailKeyPreferenceMessageDivider, settingValue);
hgs
parents:
diff changeset
   426
                    break;
hgs
parents:
diff changeset
   427
                }
hgs
parents:
diff changeset
   428
                case ReceptionUserDefinedProfile: {
hgs
parents:
diff changeset
   429
                    ret = writeToCenRep(IpsServices::EmailKeyReceptionUserDefinedProfile,
hgs
parents:
diff changeset
   430
                        settingValue);
hgs
parents:
diff changeset
   431
                    break;
hgs
parents:
diff changeset
   432
                }
hgs
parents:
diff changeset
   433
                case ReceptionInboxSyncWindow: {
hgs
parents:
diff changeset
   434
                    ret = writeToCenRep(mActiveProfileOffset
hgs
parents:
diff changeset
   435
                        + IpsServices::EmailKeyReceptionInboxSyncWindow, settingValue);
hgs
parents:
diff changeset
   436
                    break;
hgs
parents:
diff changeset
   437
                }
hgs
parents:
diff changeset
   438
                case ReceptionGenericSyncWindowInMessages: {
hgs
parents:
diff changeset
   439
                    ret = writeToCenRep(mActiveProfileOffset
hgs
parents:
diff changeset
   440
                        + IpsServices::EmailKeyReceptionGenericSyncWindowInMessages, settingValue);
hgs
parents:
diff changeset
   441
                    break;
hgs
parents:
diff changeset
   442
                }
hgs
parents:
diff changeset
   443
                case ReceptionWeekDays: {
hgs
parents:
diff changeset
   444
                    ret = writeToCenRep(mActiveProfileOffset + IpsServices::EmailKeyReceptionWeekDays,
hgs
parents:
diff changeset
   445
                        settingValue);
hgs
parents:
diff changeset
   446
                    break;
hgs
parents:
diff changeset
   447
                }
hgs
parents:
diff changeset
   448
                case ReceptionDayStartTime: {
hgs
parents:
diff changeset
   449
                    ret = writeToCenRep(mActiveProfileOffset + IpsServices::EmailKeyReceptionDayStartTime,
hgs
parents:
diff changeset
   450
                        settingValue);
hgs
parents:
diff changeset
   451
                    break;
hgs
parents:
diff changeset
   452
                }
hgs
parents:
diff changeset
   453
                case ReceptionDayEndTime: {
hgs
parents:
diff changeset
   454
                    ret = writeToCenRep(mActiveProfileOffset + IpsServices::EmailKeyReceptionDayEndTime,
hgs
parents:
diff changeset
   455
                        settingValue);
hgs
parents:
diff changeset
   456
                    break;
hgs
parents:
diff changeset
   457
                }
hgs
parents:
diff changeset
   458
                case ReceptionRefreshPeriodDayTime: {
hgs
parents:
diff changeset
   459
                    ret = writeToCenRep(mActiveProfileOffset
hgs
parents:
diff changeset
   460
                        + IpsServices::EmailKeyReceptionRefreshPeriodDayTime, settingValue);
hgs
parents:
diff changeset
   461
                    break;
hgs
parents:
diff changeset
   462
                }
hgs
parents:
diff changeset
   463
                case ReceptionRefreshPeriodOther: {
hgs
parents:
diff changeset
   464
                    ret = writeToCenRep(mActiveProfileOffset
hgs
parents:
diff changeset
   465
                        + IpsServices::EmailKeyReceptionRefreshPeriodOther, settingValue);
hgs
parents:
diff changeset
   466
                    break;
hgs
parents:
diff changeset
   467
                }
hgs
parents:
diff changeset
   468
                case UserNameHidden: {
hgs
parents:
diff changeset
   469
                    ret = writeToCenRep(IpsServices::EmailKeyUserNameHidden, settingValue);
hgs
parents:
diff changeset
   470
                    break;
hgs
parents:
diff changeset
   471
                }
hgs
parents:
diff changeset
   472
                case EmailNotificationState: {
hgs
parents:
diff changeset
   473
                    ret = writeToCenRep(IpsServices::EmailKeyEMNState, settingValue);
hgs
parents:
diff changeset
   474
                    break;
hgs
parents:
diff changeset
   475
                }
hgs
parents:
diff changeset
   476
                case FirstEmnReceived: {
hgs
parents:
diff changeset
   477
                    ret = writeToCenRep(IpsServices::EmailKeyFirstEmnReceived, settingValue);
hgs
parents:
diff changeset
   478
                    break;
hgs
parents:
diff changeset
   479
                }
hgs
parents:
diff changeset
   480
                case EmnReceivedNotSynced: {
hgs
parents:
diff changeset
   481
                    ret = writeToCenRep(IpsServices::EmailKeyEmnReceivedNotSynced, settingValue);
hgs
parents:
diff changeset
   482
                    break;
hgs
parents:
diff changeset
   483
                }
hgs
parents:
diff changeset
   484
                case AlwaysOnlineState: {
hgs
parents:
diff changeset
   485
                    setAlwaysOnlineState(settingValue);
hgs
parents:
diff changeset
   486
                    break;
hgs
parents:
diff changeset
   487
                }
hgs
parents:
diff changeset
   488
                case AoLastSuccessfulUpdate: {
hgs
parents:
diff changeset
   489
                    ret = writeToCenRep(IpsServices::EmailKeyAoLastSuccessfulUpdateL, settingValue);
hgs
parents:
diff changeset
   490
                    break;
hgs
parents:
diff changeset
   491
                }
hgs
parents:
diff changeset
   492
                case AoLastUpdateFailed: {
hgs
parents:
diff changeset
   493
                    ret = writeToCenRep(IpsServices::EmailKeyAoLastUpdateFailed, settingValue);
hgs
parents:
diff changeset
   494
                    break;
hgs
parents:
diff changeset
   495
                }
hgs
parents:
diff changeset
   496
                case AoUpdateSuccessfulWithCurSettings: {
hgs
parents:
diff changeset
   497
                    ret = writeToCenRep(IpsServices::EmailKeyAoUpdateSuccessfulWithCurSettings,
hgs
parents:
diff changeset
   498
                        settingValue);
hgs
parents:
diff changeset
   499
                    break;
hgs
parents:
diff changeset
   500
                }
hgs
parents:
diff changeset
   501
                case ReceptionActiveProfile:
hgs
parents:
diff changeset
   502
                default: {
hgs
parents:
diff changeset
   503
                    break;
hgs
parents:
diff changeset
   504
                }
hgs
parents:
diff changeset
   505
            };
hgs
parents:
diff changeset
   506
        }
hgs
parents:
diff changeset
   507
    }
hgs
parents:
diff changeset
   508
    return ret;
hgs
parents:
diff changeset
   509
}
hgs
parents:
diff changeset
   510
/*!
hgs
parents:
diff changeset
   511
 Stores the POP3/IMAP4 specific settings.
hgs
parents:
diff changeset
   512
 \return bool <true> when the settings were succesfully written, otherwise <false>.
hgs
parents:
diff changeset
   513
 */
hgs
parents:
diff changeset
   514
bool NmApiSettingsManagerPrivate::saveSettings()
hgs
parents:
diff changeset
   515
{
hgs
parents:
diff changeset
   516
    bool ret(false);
hgs
parents:
diff changeset
   517
    if (mMailboxType == NmApiMailboxTypePop) {
hgs
parents:
diff changeset
   518
        TRAPD(err, mAccount->SavePopSettingsL(mPop3Account, *mPop3Settings));
hgs
parents:
diff changeset
   519
        if (err == KErrNone) {
hgs
parents:
diff changeset
   520
            ret = true;
hgs
parents:
diff changeset
   521
        }
hgs
parents:
diff changeset
   522
    }
hgs
parents:
diff changeset
   523
    else if (mMailboxType == NmApiMailboxTypeImap) {
hgs
parents:
diff changeset
   524
        TRAPD(err, mAccount->SaveImapSettingsL(mImap4Account, *mImap4Settings));
hgs
parents:
diff changeset
   525
        if (err == KErrNone) {
hgs
parents:
diff changeset
   526
            ret = true;
hgs
parents:
diff changeset
   527
        }
hgs
parents:
diff changeset
   528
    }
hgs
parents:
diff changeset
   529
    return ret;
hgs
parents:
diff changeset
   530
}
hgs
parents:
diff changeset
   531
hgs
parents:
diff changeset
   532
/*!
hgs
parents:
diff changeset
   533
 Reads a key value from the Central Repository.
hgs
parents:
diff changeset
   534
 \param key Key identifier.
hgs
parents:
diff changeset
   535
 \return the settings value for the given key.
hgs
parents:
diff changeset
   536
 */
hgs
parents:
diff changeset
   537
QVariant NmApiSettingsManagerPrivate::readFromCenRep(quint32 key) const
hgs
parents:
diff changeset
   538
{
hgs
parents:
diff changeset
   539
    XQCentralRepositorySettingsKey settingKey(IpsServices::EmailMailboxSettingRepository,
hgs
parents:
diff changeset
   540
        mMailboxOffset + key);
hgs
parents:
diff changeset
   541
    return mQSettingsManager->readItemValue(settingKey);
hgs
parents:
diff changeset
   542
}
hgs
parents:
diff changeset
   543
hgs
parents:
diff changeset
   544
/*!
hgs
parents:
diff changeset
   545
 Writes a key value to the Central Repository.
hgs
parents:
diff changeset
   546
 \param key Key identifier.
hgs
parents:
diff changeset
   547
 \param value The settings value for the given key.
hgs
parents:
diff changeset
   548
 \return Returns <true> if the value was succesfully written, <false> if not.
hgs
parents:
diff changeset
   549
 */
hgs
parents:
diff changeset
   550
bool NmApiSettingsManagerPrivate::writeToCenRep(quint32 key, const QVariant &value) const
hgs
parents:
diff changeset
   551
{
hgs
parents:
diff changeset
   552
    XQCentralRepositorySettingsKey settingKey(IpsServices::EmailMailboxSettingRepository,
hgs
parents:
diff changeset
   553
        mMailboxOffset + key);
hgs
parents:
diff changeset
   554
    return mQSettingsManager->writeItemValue(settingKey, value);
hgs
parents:
diff changeset
   555
}
hgs
parents:
diff changeset
   556
hgs
parents:
diff changeset
   557
void NmApiSettingsManagerPrivate::setSecurity(QString securityType)
hgs
parents:
diff changeset
   558
{
hgs
parents:
diff changeset
   559
    if (securityType == NmApiStartTls) {
hgs
parents:
diff changeset
   560
        if (mMailboxType == NmApiMailboxTypePop) {
hgs
parents:
diff changeset
   561
            mPop3Settings->SetSecureSockets(ETrue);
hgs
parents:
diff changeset
   562
            mPop3Settings->SetSSLWrapper(EFalse);
hgs
parents:
diff changeset
   563
        }
hgs
parents:
diff changeset
   564
        else {
hgs
parents:
diff changeset
   565
            mImap4Settings->SetSecureSockets(ETrue);
hgs
parents:
diff changeset
   566
            mImap4Settings->SetSSLWrapper(EFalse);
hgs
parents:
diff changeset
   567
        }
hgs
parents:
diff changeset
   568
    }
hgs
parents:
diff changeset
   569
    else if (securityType == NmApiSSLTls) {
hgs
parents:
diff changeset
   570
        if (mMailboxType == NmApiMailboxTypePop) {
hgs
parents:
diff changeset
   571
            mPop3Settings->SetSecureSockets(EFalse);
hgs
parents:
diff changeset
   572
            mPop3Settings->SetSSLWrapper(ETrue);
hgs
parents:
diff changeset
   573
        }
hgs
parents:
diff changeset
   574
        else {
hgs
parents:
diff changeset
   575
            mImap4Settings->SetSecureSockets(EFalse);
hgs
parents:
diff changeset
   576
            mImap4Settings->SetSSLWrapper(ETrue);
hgs
parents:
diff changeset
   577
        }
hgs
parents:
diff changeset
   578
    }
hgs
parents:
diff changeset
   579
    else {
hgs
parents:
diff changeset
   580
        if (mMailboxType == NmApiMailboxTypePop) {
hgs
parents:
diff changeset
   581
            mPop3Settings->SetSecureSockets(EFalse);
hgs
parents:
diff changeset
   582
            mPop3Settings->SetSSLWrapper(EFalse);
hgs
parents:
diff changeset
   583
        }
hgs
parents:
diff changeset
   584
        else {
hgs
parents:
diff changeset
   585
            mImap4Settings->SetSecureSockets(EFalse);
hgs
parents:
diff changeset
   586
            mImap4Settings->SetSSLWrapper(EFalse);
hgs
parents:
diff changeset
   587
        }
hgs
parents:
diff changeset
   588
    }
hgs
parents:
diff changeset
   589
}
hgs
parents:
diff changeset
   590
hgs
parents:
diff changeset
   591
QString NmApiSettingsManagerPrivate::security() const
hgs
parents:
diff changeset
   592
{
hgs
parents:
diff changeset
   593
    bool ss(false);
hgs
parents:
diff changeset
   594
    bool sslw(false);
hgs
parents:
diff changeset
   595
    QString securityType("");
hgs
parents:
diff changeset
   596
hgs
parents:
diff changeset
   597
    if (mMailboxType == NmApiMailboxTypePop) {
hgs
parents:
diff changeset
   598
        ss = mPop3Settings->SecureSockets();
hgs
parents:
diff changeset
   599
        sslw = mPop3Settings->SSLWrapper();
hgs
parents:
diff changeset
   600
    }
hgs
parents:
diff changeset
   601
    else {
hgs
parents:
diff changeset
   602
        ss = mImap4Settings->SecureSockets();
hgs
parents:
diff changeset
   603
        sslw = mImap4Settings->SSLWrapper();
hgs
parents:
diff changeset
   604
    }
hgs
parents:
diff changeset
   605
hgs
parents:
diff changeset
   606
    if (ss == true && sslw == false) {
hgs
parents:
diff changeset
   607
        securityType = NmApiStartTls;
hgs
parents:
diff changeset
   608
    }
hgs
parents:
diff changeset
   609
    else if (ss == false && sslw == true) {
hgs
parents:
diff changeset
   610
        securityType = NmApiSSLTls;
hgs
parents:
diff changeset
   611
    }
hgs
parents:
diff changeset
   612
    else {
hgs
parents:
diff changeset
   613
        securityType = NmApiSecurityOff;
hgs
parents:
diff changeset
   614
    }
hgs
parents:
diff changeset
   615
    return securityType;
hgs
parents:
diff changeset
   616
}
hgs
parents:
diff changeset
   617
hgs
parents:
diff changeset
   618
/*!
hgs
parents:
diff changeset
   619
hgs
parents:
diff changeset
   620
 */
hgs
parents:
diff changeset
   621
QString NmApiSettingsManagerPrivate::alwaysOnlineState() const
hgs
parents:
diff changeset
   622
{
hgs
parents:
diff changeset
   623
    TInt profile = IpsServices::EmailSyncProfileManualFetch;
hgs
parents:
diff changeset
   624
    QString ret = NmApiOff;
hgs
parents:
diff changeset
   625
hgs
parents:
diff changeset
   626
    QVariant state;
hgs
parents:
diff changeset
   627
    TInt settingValue = -1;
hgs
parents:
diff changeset
   628
    state = readFromCenRep(IpsServices::EmailKeyReceptionActiveProfile);
hgs
parents:
diff changeset
   629
    settingValue = state.toInt();
hgs
parents:
diff changeset
   630
hgs
parents:
diff changeset
   631
    if (settingValue >= 0) {
hgs
parents:
diff changeset
   632
        profile = settingValue;
hgs
parents:
diff changeset
   633
        if (profile != IpsServices::EmailSyncProfileManualFetch) {
hgs
parents:
diff changeset
   634
            ret = NmApiAlways;
hgs
parents:
diff changeset
   635
        }
hgs
parents:
diff changeset
   636
    }
hgs
parents:
diff changeset
   637
    return ret;
hgs
parents:
diff changeset
   638
}
hgs
parents:
diff changeset
   639
hgs
parents:
diff changeset
   640
/*!
hgs
parents:
diff changeset
   641
hgs
parents:
diff changeset
   642
 */
hgs
parents:
diff changeset
   643
void NmApiSettingsManagerPrivate::setAlwaysOnlineState(const QVariant state)
hgs
parents:
diff changeset
   644
{
hgs
parents:
diff changeset
   645
    //only allowed to switch state off, not on.
hgs
parents:
diff changeset
   646
    if (state.toString() == NmApiOff) {
hgs
parents:
diff changeset
   647
        writeToCenRep(IpsServices::EmailKeyReceptionActiveProfile,
hgs
parents:
diff changeset
   648
            IpsServices::EmailSyncProfileManualFetch);
hgs
parents:
diff changeset
   649
    }
hgs
parents:
diff changeset
   650
}
hgs
parents:
diff changeset
   651
hgs
parents:
diff changeset
   652
void NmApiSettingsManagerPrivate::calculateMailboxOffset()
hgs
parents:
diff changeset
   653
{
hgs
parents:
diff changeset
   654
    // Find all the keys that match the criteria 0xZZZZZ000, where Z=don't care.
hgs
parents:
diff changeset
   655
    // This will give us all the keys that hold the mailbox ids, e.g. 0x00001000, 0x00002000, etc.
hgs
parents:
diff changeset
   656
    quint32 partialKey(0x00000000);
hgs
parents:
diff changeset
   657
    quint32 bitMask(0x00000FFF);
hgs
parents:
diff changeset
   658
    XQCentralRepositorySearchCriteria criteria(IpsServices::EmailMailboxSettingRepository,
hgs
parents:
diff changeset
   659
        partialKey, bitMask);
hgs
parents:
diff changeset
   660
    // Set the mailbox id is value criteria for the search.
hgs
parents:
diff changeset
   661
    criteria.setValueCriteria((int) mMailboxId);
hgs
parents:
diff changeset
   662
hgs
parents:
diff changeset
   663
    // Find the keys.
hgs
parents:
diff changeset
   664
    XQCentralRepositoryUtils utils(*mQSettingsManager);
hgs
parents:
diff changeset
   665
    QList<XQCentralRepositorySettingsKey> foundKeys = utils.findKeys(criteria);
hgs
parents:
diff changeset
   666
hgs
parents:
diff changeset
   667
    // We should only get one key as a result.
hgs
parents:
diff changeset
   668
    if (foundKeys.count() == 1) {
hgs
parents:
diff changeset
   669
        mMailboxOffset = foundKeys[0].key();
hgs
parents:
diff changeset
   670
        calculateActiveProfileOffset();
hgs
parents:
diff changeset
   671
    }
hgs
parents:
diff changeset
   672
    else {
hgs
parents:
diff changeset
   673
        mActiveProfileOffset = -1;
hgs
parents:
diff changeset
   674
        mMailboxOffset = -1;
hgs
parents:
diff changeset
   675
    }
hgs
parents:
diff changeset
   676
}
hgs
parents:
diff changeset
   677
hgs
parents:
diff changeset
   678
/*!
hgs
parents:
diff changeset
   679
 Calculates the active reception schedule profile offset.
hgs
parents:
diff changeset
   680
 */
hgs
parents:
diff changeset
   681
void NmApiSettingsManagerPrivate::calculateActiveProfileOffset()
hgs
parents:
diff changeset
   682
{
hgs
parents:
diff changeset
   683
    QVariant activeProfile = readFromCenRep(IpsServices::EmailKeyReceptionActiveProfile);
hgs
parents:
diff changeset
   684
    mActiveProfileOffset = convertToProfileOffset(activeProfile.toInt());
hgs
parents:
diff changeset
   685
}
hgs
parents:
diff changeset
   686
hgs
parents:
diff changeset
   687
/*!
hgs
parents:
diff changeset
   688
hgs
parents:
diff changeset
   689
 */
hgs
parents:
diff changeset
   690
qint32 NmApiSettingsManagerPrivate::convertToProfileOffset(int profile) const
hgs
parents:
diff changeset
   691
{
hgs
parents:
diff changeset
   692
    quint32 profileOffset(0);
hgs
parents:
diff changeset
   693
    // Possible values are defined in ipssettingkeys.h
hgs
parents:
diff changeset
   694
    switch (profile) {
hgs
parents:
diff changeset
   695
        case 0: {
hgs
parents:
diff changeset
   696
            profileOffset = IpsServices::EmailProfileOffsetKUTD;
hgs
parents:
diff changeset
   697
            break;
hgs
parents:
diff changeset
   698
        }
hgs
parents:
diff changeset
   699
        case 1: {
hgs
parents:
diff changeset
   700
            profileOffset = IpsServices::EmailProfileOffsetSE;
hgs
parents:
diff changeset
   701
            break;
hgs
parents:
diff changeset
   702
        }
hgs
parents:
diff changeset
   703
        case 2: {
hgs
parents:
diff changeset
   704
            profileOffset = IpsServices::EmailProfileOffsetMF;
hgs
parents:
diff changeset
   705
            break;
hgs
parents:
diff changeset
   706
        }
hgs
parents:
diff changeset
   707
        case 3: {
hgs
parents:
diff changeset
   708
            profileOffset = IpsServices::EmailProfileOffsetUD;
hgs
parents:
diff changeset
   709
            break;
hgs
parents:
diff changeset
   710
        }
hgs
parents:
diff changeset
   711
        default: {
hgs
parents:
diff changeset
   712
            break;
hgs
parents:
diff changeset
   713
        }
hgs
parents:
diff changeset
   714
    };
hgs
parents:
diff changeset
   715
hgs
parents:
diff changeset
   716
    return profileOffset;
hgs
parents:
diff changeset
   717
}
hgs
parents:
diff changeset
   718
hgs
parents:
diff changeset
   719
bool NmApiSettingsManagerPrivate::checkAccountType()
hgs
parents:
diff changeset
   720
{
hgs
parents:
diff changeset
   721
    bool identified = false;
hgs
parents:
diff changeset
   722
hgs
parents:
diff changeset
   723
    RArray<TImapAccount> imapAccounts;
hgs
parents:
diff changeset
   724
    CleanupClosePushL(imapAccounts);
hgs
parents:
diff changeset
   725
    TRAPD(err, mAccount->GetImapAccountsL(imapAccounts));
hgs
parents:
diff changeset
   726
    if (err == KErrNone) {
hgs
parents:
diff changeset
   727
        for (int i=0; i < imapAccounts.Count(); ++i) {
hgs
parents:
diff changeset
   728
            TImapAccount account = imapAccounts[i];
hgs
parents:
diff changeset
   729
            if (account.iImapService == mMailboxId) {
hgs
parents:
diff changeset
   730
                mImap4Account = account;
hgs
parents:
diff changeset
   731
                mMailboxType = NmApiMailboxTypeImap;
hgs
parents:
diff changeset
   732
                identified = true;
hgs
parents:
diff changeset
   733
                break;
hgs
parents:
diff changeset
   734
            }
hgs
parents:
diff changeset
   735
        }
hgs
parents:
diff changeset
   736
    }
hgs
parents:
diff changeset
   737
    CleanupStack::PopAndDestroy(&imapAccounts);
hgs
parents:
diff changeset
   738
hgs
parents:
diff changeset
   739
    if (!identified) {
hgs
parents:
diff changeset
   740
        RArray<TPopAccount> popAccounts;
hgs
parents:
diff changeset
   741
        CleanupClosePushL(popAccounts);
hgs
parents:
diff changeset
   742
        TRAPD(err, mAccount->GetPopAccountsL(popAccounts));
hgs
parents:
diff changeset
   743
        if (err == KErrNone) {
hgs
parents:
diff changeset
   744
            for (int i = 0; i < popAccounts.Count(); ++i) {
hgs
parents:
diff changeset
   745
                TPopAccount account = popAccounts[i];
hgs
parents:
diff changeset
   746
                if (popAccounts[i].iPopService == mMailboxId) {
hgs
parents:
diff changeset
   747
                    mPop3Account = account;
hgs
parents:
diff changeset
   748
                    mMailboxType = NmApiMailboxTypePop;
hgs
parents:
diff changeset
   749
                    identified = true;
hgs
parents:
diff changeset
   750
                    break;
hgs
parents:
diff changeset
   751
                }
hgs
parents:
diff changeset
   752
            }
hgs
parents:
diff changeset
   753
        }
hgs
parents:
diff changeset
   754
        CleanupStack::PopAndDestroy(&popAccounts);
hgs
parents:
diff changeset
   755
    }
hgs
parents:
diff changeset
   756
hgs
parents:
diff changeset
   757
    return identified;
hgs
parents:
diff changeset
   758
}
hgs
parents:
diff changeset
   759
hgs
parents:
diff changeset
   760
void NmApiSettingsManagerPrivate::initAccountL()
hgs
parents:
diff changeset
   761
{
hgs
parents:
diff changeset
   762
    if (mMailboxType == NmApiMailboxTypePop) {
hgs
parents:
diff changeset
   763
        mPop3Settings = new(ELeave) CImPop3Settings();
hgs
parents:
diff changeset
   764
        mAccount->LoadPopSettingsL(mPop3Account, *mPop3Settings);
hgs
parents:
diff changeset
   765
    }
hgs
parents:
diff changeset
   766
    else if (mMailboxType == NmApiMailboxTypeImap) {
hgs
parents:
diff changeset
   767
        mImap4Settings = new(ELeave) CImImap4Settings();
hgs
parents:
diff changeset
   768
        mAccount->LoadImapSettingsL(mImap4Account, *mImap4Settings);
hgs
parents:
diff changeset
   769
    }
hgs
parents:
diff changeset
   770
hgs
parents:
diff changeset
   771
    mSmtpSettings = new(ELeave) CImSmtpSettings();
hgs
parents:
diff changeset
   772
hgs
parents:
diff changeset
   773
    if (mMailboxType == NmApiMailboxTypePop) {
hgs
parents:
diff changeset
   774
        mAccount->GetSmtpAccountL(mPop3Account.iSmtpService, mSmtpAccount);
hgs
parents:
diff changeset
   775
    }
hgs
parents:
diff changeset
   776
    else if (mMailboxType == NmApiMailboxTypeImap) {
hgs
parents:
diff changeset
   777
        mAccount->GetSmtpAccountL(mImap4Account.iSmtpService, mSmtpAccount);
hgs
parents:
diff changeset
   778
    }
hgs
parents:
diff changeset
   779
    mAccount->LoadSmtpSettingsL(mSmtpAccount, *mSmtpSettings);
hgs
parents:
diff changeset
   780
}
hgs
parents:
diff changeset
   781
hgs
parents:
diff changeset
   782
} // end namespace