emailservices/nmclientapi/src/nmapisettingsmanager_p.cpp
author hgs
Thu, 30 Sep 2010 11:43:07 +0300
changeset 74 6c59112cfd31
parent 56 15bc1d5d6267
child 76 38bf5461e270
permissions -rw-r--r--
201039
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
 */
74
hgs
parents: 56
diff changeset
    17
#include <nmapiheaders.h>
56
hgs
parents:
diff changeset
    18
74
hgs
parents: 56
diff changeset
    19
// Helpers
hgs
parents: 56
diff changeset
    20
HBufC8* StringToS60HBufC8LC(const QString &string)
hgs
parents: 56
diff changeset
    21
{
hgs
parents: 56
diff changeset
    22
    HBufC8* tmp = XQConversions::qStringToS60Desc8(string);
hgs
parents: 56
diff changeset
    23
    User::LeaveIfNull(tmp);
hgs
parents: 56
diff changeset
    24
    CleanupStack::PushL(tmp);
hgs
parents: 56
diff changeset
    25
    return tmp;
hgs
parents: 56
diff changeset
    26
}
56
hgs
parents:
diff changeset
    27
74
hgs
parents: 56
diff changeset
    28
const TPtrC StringToS60TPtrC(const QString &string)
hgs
parents: 56
diff changeset
    29
{
hgs
parents: 56
diff changeset
    30
    return TPtrC(reinterpret_cast<const TUint16*>(string.utf16()));
hgs
parents: 56
diff changeset
    31
}
hgs
parents: 56
diff changeset
    32
56
hgs
parents:
diff changeset
    33
hgs
parents:
diff changeset
    34
namespace EmailClientApi
hgs
parents:
diff changeset
    35
{
74
hgs
parents: 56
diff changeset
    36
const int KUndefinedOffset = -1;
56
hgs
parents:
diff changeset
    37
74
hgs
parents: 56
diff changeset
    38
NmApiSettingsManagerPrivate::NmApiSettingsManagerPrivate()
hgs
parents: 56
diff changeset
    39
    : mAccount(NULL),
hgs
parents: 56
diff changeset
    40
    mPop3Settings(NULL),
hgs
parents: 56
diff changeset
    41
    mImap4Settings(NULL),
hgs
parents: 56
diff changeset
    42
    mSmtpSettings(NULL),
hgs
parents: 56
diff changeset
    43
    mQSettingsManager(NULL),
hgs
parents: 56
diff changeset
    44
    mMailboxOffset(KUndefinedOffset),
hgs
parents: 56
diff changeset
    45
    mActiveProfileOffset(KUndefinedOffset),
56
hgs
parents:
diff changeset
    46
    mMailboxId(0)
hgs
parents:
diff changeset
    47
{
hgs
parents:
diff changeset
    48
}
hgs
parents:
diff changeset
    49
hgs
parents:
diff changeset
    50
NmApiSettingsManagerPrivate::~NmApiSettingsManagerPrivate()
hgs
parents:
diff changeset
    51
{
hgs
parents:
diff changeset
    52
    delete mPop3Settings;
hgs
parents:
diff changeset
    53
    delete mImap4Settings;
hgs
parents:
diff changeset
    54
    delete mSmtpSettings;
hgs
parents:
diff changeset
    55
    delete mQSettingsManager;
hgs
parents:
diff changeset
    56
    delete mAccount;
hgs
parents:
diff changeset
    57
}
hgs
parents:
diff changeset
    58
hgs
parents:
diff changeset
    59
/*!
74
hgs
parents: 56
diff changeset
    60
 Loads email account settings.
56
hgs
parents:
diff changeset
    61
 \param mailboxId which settings are returned
hgs
parents:
diff changeset
    62
 \param data consists of keys and values of settings.
hgs
parents:
diff changeset
    63
 \return bool <true> when the setting items were found otherwise <false>.
hgs
parents:
diff changeset
    64
 */
hgs
parents:
diff changeset
    65
bool NmApiSettingsManagerPrivate::load(quint64 mailboxId, NmApiMailboxSettingsData &data)
hgs
parents:
diff changeset
    66
{
74
hgs
parents: 56
diff changeset
    67
    AccountDataCleanUpItem(mAccount, mPop3Settings,
hgs
parents: 56
diff changeset
    68
            mImap4Settings, mSmtpSettings, mQSettingsManager);
hgs
parents: 56
diff changeset
    69
    mMailboxId = mailboxId; // Last 32 bits are used as mailbox id
hgs
parents: 56
diff changeset
    70
    data.setMailboxId(mailboxId);
hgs
parents: 56
diff changeset
    71
    bool retVal = false;
hgs
parents: 56
diff changeset
    72
    TRAPD(err, initAccountL());
hgs
parents: 56
diff changeset
    73
    if (!err) {
hgs
parents: 56
diff changeset
    74
        readSettings(data);
hgs
parents: 56
diff changeset
    75
        retVal = readCenRepSettings(data);
hgs
parents: 56
diff changeset
    76
    }
hgs
parents: 56
diff changeset
    77
    return retVal;
56
hgs
parents:
diff changeset
    78
}
hgs
parents:
diff changeset
    79
hgs
parents:
diff changeset
    80
/*!
74
hgs
parents: 56
diff changeset
    81
 Saves mailbox settings.
hgs
parents: 56
diff changeset
    82
 \param mailboxId which settings are saved
56
hgs
parents:
diff changeset
    83
 \param data consists of keys and values of settings.
hgs
parents:
diff changeset
    84
 \return bool <true> when the setting items were successfully saved otherwise <false>.
hgs
parents:
diff changeset
    85
 */
74
hgs
parents: 56
diff changeset
    86
bool NmApiSettingsManagerPrivate::save(quint64 mailboxId, const NmApiMailboxSettingsData &data)
56
hgs
parents:
diff changeset
    87
{
74
hgs
parents: 56
diff changeset
    88
    AccountDataCleanUpItem(mAccount, mPop3Settings,
hgs
parents: 56
diff changeset
    89
           mImap4Settings, mSmtpSettings, mQSettingsManager);
hgs
parents: 56
diff changeset
    90
    mMailboxId = mailboxId; // Last 32 bits are used as mailbox id
hgs
parents: 56
diff changeset
    91
    bool retVal = false;
hgs
parents: 56
diff changeset
    92
    TRAPD(err, initAccountL());
hgs
parents: 56
diff changeset
    93
    if (!err) {
hgs
parents: 56
diff changeset
    94
        TRAP(err, writeSettingL(data));
hgs
parents: 56
diff changeset
    95
        if(!err) {
hgs
parents: 56
diff changeset
    96
            retVal = writeSettingToCenRep(data);
hgs
parents: 56
diff changeset
    97
        }
hgs
parents: 56
diff changeset
    98
    }
hgs
parents: 56
diff changeset
    99
    return (!err && retVal);
56
hgs
parents:
diff changeset
   100
}
hgs
parents:
diff changeset
   101
hgs
parents:
diff changeset
   102
/*!
74
hgs
parents: 56
diff changeset
   103
 Reads the mailbox account specific settings.
hgs
parents: 56
diff changeset
   104
 \param data consists of keys and values of settings.
56
hgs
parents:
diff changeset
   105
 */
74
hgs
parents: 56
diff changeset
   106
void NmApiSettingsManagerPrivate::readSettings(NmApiMailboxSettingsData &data)
56
hgs
parents:
diff changeset
   107
{
hgs
parents:
diff changeset
   108
    if (mMailboxType == NmApiMailboxTypePop) {
hgs
parents:
diff changeset
   109
        data.setValue(IncomingLoginName, XQConversions::s60Desc8ToQString(mPop3Settings->LoginName()));
hgs
parents:
diff changeset
   110
        data.setValue(IncomingPassword, XQConversions::s60Desc8ToQString(mPop3Settings->Password()));
hgs
parents:
diff changeset
   111
        data.setValue(MailboxName, XQConversions::s60DescToQString(mPop3Account.iPopAccountName));
hgs
parents:
diff changeset
   112
        data.setValue(IncomingMailServer, XQConversions::s60DescToQString(mPop3Settings->ServerAddress()));
hgs
parents:
diff changeset
   113
#if (defined SYMBIAN_EMAIL_CAPABILITY_SUPPORT)
hgs
parents:
diff changeset
   114
        data.setValue(IncomingMailUsesAuthentication, mPop3Settings->POP3Auth());
hgs
parents:
diff changeset
   115
#endif
hgs
parents:
diff changeset
   116
        data.setValue(IncomingPort, mPop3Settings->Port());
74
hgs
parents: 56
diff changeset
   117
        data.setValue(IncomingMailSecurityType, security(*mPop3Settings));
56
hgs
parents:
diff changeset
   118
    }
hgs
parents:
diff changeset
   119
    else if (mMailboxType  == NmApiMailboxTypeImap) {
hgs
parents:
diff changeset
   120
        data.setValue(IncomingLoginName, XQConversions::s60Desc8ToQString(mImap4Settings->LoginName()));
hgs
parents:
diff changeset
   121
        data.setValue(IncomingPassword, XQConversions::s60Desc8ToQString(mImap4Settings->Password()));
hgs
parents:
diff changeset
   122
        data.setValue(MailboxName, XQConversions::s60DescToQString(
hgs
parents:
diff changeset
   123
                mImap4Account.iImapAccountName));
hgs
parents:
diff changeset
   124
        data.setValue(IncomingMailServer, XQConversions::s60DescToQString(
hgs
parents:
diff changeset
   125
                mImap4Settings->ServerAddress()));
hgs
parents:
diff changeset
   126
#if (defined SYMBIAN_EMAIL_CAPABILITY_SUPPORT)
hgs
parents:
diff changeset
   127
        data.setValue(IncomingMailUsesAuthentication, mImap4Settings->IAMP4Auth());
hgs
parents:
diff changeset
   128
#endif
hgs
parents:
diff changeset
   129
        data.setValue(IncomingPort, mImap4Settings->Port());
hgs
parents:
diff changeset
   130
        data.setValue(FolderPath, XQConversions::s60Desc8ToQString(mImap4Settings->FolderPath()));
74
hgs
parents: 56
diff changeset
   131
        data.setValue(IncomingMailSecurityType, security(*mImap4Settings));
56
hgs
parents:
diff changeset
   132
    }
hgs
parents:
diff changeset
   133
hgs
parents:
diff changeset
   134
    data.setValue(MyName, XQConversions::s60DescToQString(mSmtpSettings->EmailAlias()));
hgs
parents:
diff changeset
   135
    data.setValue(EmailAlias, XQConversions::s60DescToQString(mSmtpSettings->EmailAlias()));
hgs
parents:
diff changeset
   136
    data.setValue(EmailAddress, XQConversions::s60DescToQString(mSmtpSettings->EmailAddress()));
hgs
parents:
diff changeset
   137
    data.setValue(ReplyAddress, XQConversions::s60DescToQString(mSmtpSettings->ReplyToAddress()));
hgs
parents:
diff changeset
   138
    data.setValue(OutgoingMailServer, XQConversions::s60DescToQString(mSmtpSettings->ServerAddress()));
hgs
parents:
diff changeset
   139
    data.setValue(OutgoingPort, mSmtpSettings->Port());
hgs
parents:
diff changeset
   140
    data.setValue(OutgoingLoginName, XQConversions::s60Desc8ToQString(mSmtpSettings->LoginName()));
hgs
parents:
diff changeset
   141
    data.setValue(OutgoingPassword, XQConversions::s60Desc8ToQString(mSmtpSettings->Password()));
hgs
parents:
diff changeset
   142
    data.setValue(UseOutgoingAuthentication, mSmtpSettings->SMTPAuth());
hgs
parents:
diff changeset
   143
    data.setValue(OutgoingMailUsesAuthentication, mSmtpSettings->SMTPAuth());
hgs
parents:
diff changeset
   144
    data.setValue(OutgoingSecureSockets, mSmtpSettings->SecureSockets());
hgs
parents:
diff changeset
   145
    data.setValue(OutgoingSSLWrapper, mSmtpSettings->SSLWrapper());
74
hgs
parents: 56
diff changeset
   146
    data.setValue(OutgoingMailSecurityType, security(*mSmtpSettings));
hgs
parents: 56
diff changeset
   147
}
hgs
parents: 56
diff changeset
   148
hgs
parents: 56
diff changeset
   149
/*!
hgs
parents: 56
diff changeset
   150
 Returns the Central Repository setting. Sets given boolen parameter to <false>
hgs
parents: 56
diff changeset
   151
 if error happens. If no error happens boolean status is not changed.
hgs
parents: 56
diff changeset
   152
 \param cenRepKey Central repository key
hgs
parents: 56
diff changeset
   153
 \param success  Boolean which is set to <false> if some other error than 
hgs
parents: 56
diff changeset
   154
                 XQSettingsManager::NotFoundError occurs.
hgs
parents: 56
diff changeset
   155
                 Note! Variable is never set to <true>.
hgs
parents: 56
diff changeset
   156
 \return QVariant The settings value for the given key.
hgs
parents: 56
diff changeset
   157
 */
hgs
parents: 56
diff changeset
   158
QVariant NmApiSettingsManagerPrivate::readFromCenRep(quint32 key,
hgs
parents: 56
diff changeset
   159
        bool &success) const
hgs
parents: 56
diff changeset
   160
    {
hgs
parents: 56
diff changeset
   161
    QVariant setting = readFromCenRep(key);
hgs
parents: 56
diff changeset
   162
hgs
parents: 56
diff changeset
   163
    /*
hgs
parents: 56
diff changeset
   164
     XQSettingsManager::NotFoundError occurs if some setting is not found from the cenrep.
hgs
parents: 56
diff changeset
   165
     This is a valid case since all accounts doesn't neccessarily have all possible settings.
hgs
parents: 56
diff changeset
   166
     All other errors are "real" errors and those are indicated to the API user.
hgs
parents: 56
diff changeset
   167
     */
hgs
parents: 56
diff changeset
   168
    if (setting.isNull() 
hgs
parents: 56
diff changeset
   169
        && mQSettingsManager->error() != XQSettingsManager::NotFoundError) {
hgs
parents: 56
diff changeset
   170
        success = false;
hgs
parents: 56
diff changeset
   171
    }
hgs
parents: 56
diff changeset
   172
hgs
parents: 56
diff changeset
   173
    return setting;
hgs
parents: 56
diff changeset
   174
    }
hgs
parents: 56
diff changeset
   175
hgs
parents: 56
diff changeset
   176
bool NmApiSettingsManagerPrivate::readCenRepSettings(NmApiMailboxSettingsData &data)
hgs
parents: 56
diff changeset
   177
{
hgs
parents: 56
diff changeset
   178
    bool retVal = true;
hgs
parents: 56
diff changeset
   179
    
hgs
parents: 56
diff changeset
   180
    data.setValue(DownloadPictures, 
hgs
parents: 56
diff changeset
   181
        readFromCenRep(IpsServices::EmailKeyPreferenceDownloadPictures, retVal));
hgs
parents: 56
diff changeset
   182
    data.setValue(MessageDivider, 
hgs
parents: 56
diff changeset
   183
        readFromCenRep(IpsServices::EmailKeyPreferenceMessageDivider, retVal));
hgs
parents: 56
diff changeset
   184
hgs
parents: 56
diff changeset
   185
    QVariant activeProfileSetting = readFromCenRep(IpsServices::EmailKeyReceptionActiveProfile, retVal);
hgs
parents: 56
diff changeset
   186
    
hgs
parents: 56
diff changeset
   187
    if (!activeProfileSetting.isNull()) {
hgs
parents: 56
diff changeset
   188
        switch (activeProfileSetting.toInt()) {
hgs
parents: 56
diff changeset
   189
            case IpsServices::EmailSyncProfileKeepUpToDate:
hgs
parents: 56
diff changeset
   190
                data.setValue(ReceptionActiveProfile, EmailClientApi::EmailProfileOffsetKUTD);
hgs
parents: 56
diff changeset
   191
                break;
hgs
parents: 56
diff changeset
   192
            case IpsServices::EmailSyncProfileSaveEnergy:
hgs
parents: 56
diff changeset
   193
                data.setValue(ReceptionActiveProfile, EmailClientApi::EmailProfileOffsetSE);
hgs
parents: 56
diff changeset
   194
                break;
hgs
parents: 56
diff changeset
   195
            case IpsServices::EmailSyncProfileManualFetch:
hgs
parents: 56
diff changeset
   196
                data.setValue(ReceptionActiveProfile, EmailClientApi::EmailProfileOffsetMF);
hgs
parents: 56
diff changeset
   197
                break;
hgs
parents: 56
diff changeset
   198
            case IpsServices::EmailSyncProfileUserDefined:
hgs
parents: 56
diff changeset
   199
                data.setValue(ReceptionActiveProfile, EmailClientApi::EmailProfileOffsetUD);
hgs
parents: 56
diff changeset
   200
                break;
hgs
parents: 56
diff changeset
   201
            default:
hgs
parents: 56
diff changeset
   202
                data.setValue(ReceptionActiveProfile, EmailClientApi::EmailProfileOffsetKUTD);
hgs
parents: 56
diff changeset
   203
                break;
hgs
parents: 56
diff changeset
   204
        }
hgs
parents: 56
diff changeset
   205
    }
hgs
parents: 56
diff changeset
   206
hgs
parents: 56
diff changeset
   207
    data.setValue(ReceptionUserDefinedProfile, readFromCenRep(
hgs
parents: 56
diff changeset
   208
            IpsServices::EmailKeyReceptionUserDefinedProfile, retVal));
hgs
parents: 56
diff changeset
   209
    data.setValue(ReceptionInboxSyncWindow, readFromCenRep(mActiveProfileOffset
hgs
parents: 56
diff changeset
   210
                        + IpsServices::EmailKeyReceptionInboxSyncWindow, retVal));
hgs
parents: 56
diff changeset
   211
    data.setValue(ReceptionGenericSyncWindowInMessages, readFromCenRep(mActiveProfileOffset
hgs
parents: 56
diff changeset
   212
                        + IpsServices::EmailKeyReceptionGenericSyncWindowInMessages, retVal));
hgs
parents: 56
diff changeset
   213
    data.setValue(ReceptionWeekDays, readFromCenRep(mActiveProfileOffset
hgs
parents: 56
diff changeset
   214
                        + IpsServices::EmailKeyReceptionWeekDays, retVal));
hgs
parents: 56
diff changeset
   215
    data.setValue(ReceptionDayStartTime, readFromCenRep(mActiveProfileOffset
hgs
parents: 56
diff changeset
   216
                        + IpsServices::EmailKeyReceptionDayStartTime, retVal));
hgs
parents: 56
diff changeset
   217
    data.setValue(ReceptionDayEndTime, readFromCenRep(mActiveProfileOffset
hgs
parents: 56
diff changeset
   218
                        + IpsServices::EmailKeyReceptionDayEndTime, retVal));
hgs
parents: 56
diff changeset
   219
    data.setValue(ReceptionRefreshPeriodDayTime, readFromCenRep(mActiveProfileOffset
hgs
parents: 56
diff changeset
   220
                        + IpsServices::EmailKeyReceptionRefreshPeriodDayTime, retVal));
hgs
parents: 56
diff changeset
   221
    data.setValue(ReceptionRefreshPeriodOther, readFromCenRep(mActiveProfileOffset
hgs
parents: 56
diff changeset
   222
                        + IpsServices::EmailKeyReceptionRefreshPeriodOther, retVal));
hgs
parents: 56
diff changeset
   223
    data.setValue(UserNameHidden, readFromCenRep(IpsServices::EmailKeyUserNameHidden, retVal));
hgs
parents: 56
diff changeset
   224
    data.setValue(EmailNotificationState, readFromCenRep(IpsServices::EmailKeyEMNState, retVal));
hgs
parents: 56
diff changeset
   225
    data.setValue(FirstEmnReceived, readFromCenRep(IpsServices::EmailKeyFirstEmnReceived, retVal));
hgs
parents: 56
diff changeset
   226
    data.setValue(EmnReceivedNotSynced, readFromCenRep(
hgs
parents: 56
diff changeset
   227
        IpsServices::EmailKeyEmnReceivedNotSynced, retVal));
hgs
parents: 56
diff changeset
   228
    data.setValue(AlwaysOnlineState, alwaysOnlineState(retVal));
hgs
parents: 56
diff changeset
   229
hgs
parents: 56
diff changeset
   230
    data.setValue(AoLastSuccessfulUpdate, readFromCenRep(
hgs
parents: 56
diff changeset
   231
        IpsServices::EmailKeyAoLastSuccessfulUpdateL, retVal));
hgs
parents: 56
diff changeset
   232
    data.setValue(AoLastUpdateFailed, readFromCenRep(
hgs
parents: 56
diff changeset
   233
        IpsServices::EmailKeyAoLastUpdateFailed, retVal));
hgs
parents: 56
diff changeset
   234
    data.setValue(AoUpdateSuccessfulWithCurSettings, readFromCenRep(
hgs
parents: 56
diff changeset
   235
            IpsServices::EmailKeyAoUpdateSuccessfulWithCurSettings, retVal));
hgs
parents: 56
diff changeset
   236
    return retVal;
56
hgs
parents:
diff changeset
   237
}
hgs
parents:
diff changeset
   238
74
hgs
parents: 56
diff changeset
   239
void NmApiSettingsManagerPrivate::fillImapSettingDataL(const NmApiMailboxSettingsData &data)
56
hgs
parents:
diff changeset
   240
{
74
hgs
parents: 56
diff changeset
   241
    int key = -1;
hgs
parents: 56
diff changeset
   242
    QVariant settingValue;
hgs
parents: 56
diff changeset
   243
    QList<int> keylist = data.listSettings();
hgs
parents: 56
diff changeset
   244
    
hgs
parents: 56
diff changeset
   245
    for (int i = 0; i < keylist.size(); i++) {
hgs
parents: 56
diff changeset
   246
        key = keylist[i];
hgs
parents: 56
diff changeset
   247
        if (data.getValue(key, settingValue) && !settingValue.isNull()) {
hgs
parents: 56
diff changeset
   248
            switch (key) {
hgs
parents: 56
diff changeset
   249
                case IncomingLoginName:
hgs
parents: 56
diff changeset
   250
                    mImap4Settings->SetLoginNameL(*StringToS60HBufC8LC(settingValue.toString()));
hgs
parents: 56
diff changeset
   251
                    CleanupStack::PopAndDestroy();
hgs
parents: 56
diff changeset
   252
                    break;
hgs
parents: 56
diff changeset
   253
                case IncomingPassword:
hgs
parents: 56
diff changeset
   254
                    mImap4Settings->SetPasswordL(*StringToS60HBufC8LC(settingValue.toString()));
hgs
parents: 56
diff changeset
   255
                    CleanupStack::PopAndDestroy();
hgs
parents: 56
diff changeset
   256
                    break;
hgs
parents: 56
diff changeset
   257
                case MailboxName:
hgs
parents: 56
diff changeset
   258
                    mImap4Account.iImapAccountName.Copy(StringToS60TPtrC(settingValue.toString()));
hgs
parents: 56
diff changeset
   259
                    break;
hgs
parents: 56
diff changeset
   260
                case IncomingMailServer:
hgs
parents: 56
diff changeset
   261
                    mImap4Settings->SetServerAddressL(StringToS60TPtrC(settingValue.toString()));
hgs
parents: 56
diff changeset
   262
                    break;
hgs
parents: 56
diff changeset
   263
                case IncomingMailUsesAuthentication:
hgs
parents: 56
diff changeset
   264
#if (defined SYMBIAN_EMAIL_CAPABILITY_SUPPORT)
hgs
parents: 56
diff changeset
   265
                   mImap4Settings->SetIAMP4Auth(settingValue.toBool());             
hgs
parents: 56
diff changeset
   266
#endif
hgs
parents: 56
diff changeset
   267
                   break;
hgs
parents: 56
diff changeset
   268
                case FolderPath:
hgs
parents: 56
diff changeset
   269
                   mImap4Settings->SetFolderPathL(*StringToS60HBufC8LC(settingValue.toString()));
hgs
parents: 56
diff changeset
   270
                   CleanupStack::PopAndDestroy();
hgs
parents: 56
diff changeset
   271
                   break;
hgs
parents: 56
diff changeset
   272
                case IncomingMailSecurityType:
hgs
parents: 56
diff changeset
   273
                    setSecurity(*mImap4Settings, settingValue.toString());
hgs
parents: 56
diff changeset
   274
                    break;
hgs
parents: 56
diff changeset
   275
                case IncomingPort:
hgs
parents: 56
diff changeset
   276
                    mImap4Settings->SetPort(settingValue.toInt());
hgs
parents: 56
diff changeset
   277
                    break;
hgs
parents: 56
diff changeset
   278
                case IncomingSecureSockets:
hgs
parents: 56
diff changeset
   279
                    mImap4Settings->SetSecureSockets(settingValue.toBool());
hgs
parents: 56
diff changeset
   280
                    break;
hgs
parents: 56
diff changeset
   281
                case IncomingSSLWrapper:
hgs
parents: 56
diff changeset
   282
                    mImap4Settings->SetSSLWrapper(settingValue.toBool());
hgs
parents: 56
diff changeset
   283
                    break;
hgs
parents: 56
diff changeset
   284
                default:
hgs
parents: 56
diff changeset
   285
                    fillSmtpSettingDataL(data, settingValue, key);
hgs
parents: 56
diff changeset
   286
                    break;
hgs
parents: 56
diff changeset
   287
            }
hgs
parents: 56
diff changeset
   288
        }
hgs
parents: 56
diff changeset
   289
    }
hgs
parents: 56
diff changeset
   290
}
56
hgs
parents:
diff changeset
   291
74
hgs
parents: 56
diff changeset
   292
void NmApiSettingsManagerPrivate::fillPopSettingDataL(const NmApiMailboxSettingsData &data)
hgs
parents: 56
diff changeset
   293
{
hgs
parents: 56
diff changeset
   294
    int key = -1;
hgs
parents: 56
diff changeset
   295
    QVariant settingValue;
hgs
parents: 56
diff changeset
   296
    QList<int> keylist = data.listSettings();
hgs
parents: 56
diff changeset
   297
    
hgs
parents: 56
diff changeset
   298
    for (int i = 0; i < keylist.size(); i++) {
hgs
parents: 56
diff changeset
   299
       key = keylist[i];
hgs
parents: 56
diff changeset
   300
       if (data.getValue(key, settingValue) && !settingValue.isNull()) {
hgs
parents: 56
diff changeset
   301
           switch (key) {
hgs
parents: 56
diff changeset
   302
               case IncomingLoginName:
hgs
parents: 56
diff changeset
   303
                   mPop3Settings->SetLoginNameL(*StringToS60HBufC8LC(settingValue.toString()));
hgs
parents: 56
diff changeset
   304
                   CleanupStack::PopAndDestroy();
hgs
parents: 56
diff changeset
   305
                   break;
hgs
parents: 56
diff changeset
   306
               case IncomingPassword:
hgs
parents: 56
diff changeset
   307
                   mPop3Settings->SetPasswordL(*StringToS60HBufC8LC(settingValue.toString()));
hgs
parents: 56
diff changeset
   308
                   CleanupStack::PopAndDestroy();
hgs
parents: 56
diff changeset
   309
                   break;
hgs
parents: 56
diff changeset
   310
               case MailboxName:
hgs
parents: 56
diff changeset
   311
                   mPop3Account.iPopAccountName.Copy(StringToS60TPtrC(settingValue.toString()));
hgs
parents: 56
diff changeset
   312
                   break;
hgs
parents: 56
diff changeset
   313
               case IncomingMailServer:
hgs
parents: 56
diff changeset
   314
                   mPop3Settings->SetServerAddressL(StringToS60TPtrC(settingValue.toString()));
hgs
parents: 56
diff changeset
   315
                   break;
hgs
parents: 56
diff changeset
   316
               case IncomingMailUsesAuthentication:
hgs
parents: 56
diff changeset
   317
#if (defined SYMBIAN_EMAIL_CAPABILITY_SUPPORT)
hgs
parents: 56
diff changeset
   318
                   mPop3Settings->SetPOP3Auth(settingValue.toBool());
hgs
parents: 56
diff changeset
   319
#endif
hgs
parents: 56
diff changeset
   320
                   break;
hgs
parents: 56
diff changeset
   321
               case IncomingMailSecurityType:
hgs
parents: 56
diff changeset
   322
                   setSecurity(*mPop3Settings, settingValue.toString());
hgs
parents: 56
diff changeset
   323
                   break;
hgs
parents: 56
diff changeset
   324
               case IncomingPort:
hgs
parents: 56
diff changeset
   325
                   mPop3Settings->SetPort(settingValue.toInt());
hgs
parents: 56
diff changeset
   326
                   break;
hgs
parents: 56
diff changeset
   327
               case IncomingSecureSockets:
hgs
parents: 56
diff changeset
   328
                   mPop3Settings->SetSecureSockets(settingValue.toBool());
hgs
parents: 56
diff changeset
   329
                   break;
hgs
parents: 56
diff changeset
   330
               case IncomingSSLWrapper:
hgs
parents: 56
diff changeset
   331
                   mPop3Settings->SetSSLWrapper(settingValue.toBool());
hgs
parents: 56
diff changeset
   332
                   break;
hgs
parents: 56
diff changeset
   333
               default:
hgs
parents: 56
diff changeset
   334
                   fillSmtpSettingDataL(data, settingValue, key);
hgs
parents: 56
diff changeset
   335
                   break;
hgs
parents: 56
diff changeset
   336
           }
hgs
parents: 56
diff changeset
   337
       }
hgs
parents: 56
diff changeset
   338
    }
hgs
parents: 56
diff changeset
   339
}
56
hgs
parents:
diff changeset
   340
74
hgs
parents: 56
diff changeset
   341
void NmApiSettingsManagerPrivate::fillSmtpSettingDataL(const NmApiMailboxSettingsData &data, 
hgs
parents: 56
diff changeset
   342
        const QVariant settingValue, const int key)
hgs
parents: 56
diff changeset
   343
{    
hgs
parents: 56
diff changeset
   344
    switch (key) {
hgs
parents: 56
diff changeset
   345
       case EmailAddress:
hgs
parents: 56
diff changeset
   346
           mSmtpSettings->SetEmailAddressL(StringToS60TPtrC(settingValue.toString()));
hgs
parents: 56
diff changeset
   347
           break;
hgs
parents: 56
diff changeset
   348
       case ReplyAddress:  
hgs
parents: 56
diff changeset
   349
           mSmtpSettings->SetReplyToAddressL(StringToS60TPtrC(settingValue.toString()));
hgs
parents: 56
diff changeset
   350
           break;
hgs
parents: 56
diff changeset
   351
       case EmailAlias:
hgs
parents: 56
diff changeset
   352
           mSmtpSettings->SetEmailAliasL(StringToS60TPtrC(settingValue.toString()));
hgs
parents: 56
diff changeset
   353
           break;
hgs
parents: 56
diff changeset
   354
       case MyName:
hgs
parents: 56
diff changeset
   355
           // If EmailAlias is not set already
hgs
parents: 56
diff changeset
   356
           if(mSmtpSettings->EmailAlias().Length() == 0) {
hgs
parents: 56
diff changeset
   357
               mSmtpSettings->SetEmailAliasL(StringToS60TPtrC(settingValue.toString()));
hgs
parents: 56
diff changeset
   358
           }
hgs
parents: 56
diff changeset
   359
           break;
hgs
parents: 56
diff changeset
   360
       case OutgoingMailServer:
hgs
parents: 56
diff changeset
   361
           mSmtpSettings->SetServerAddressL(StringToS60TPtrC(settingValue.toString()));
hgs
parents: 56
diff changeset
   362
           break;
hgs
parents: 56
diff changeset
   363
       case OutgoingLoginName:
hgs
parents: 56
diff changeset
   364
           mSmtpSettings->SetLoginNameL(*StringToS60HBufC8LC(settingValue.toString()));
hgs
parents: 56
diff changeset
   365
           CleanupStack::PopAndDestroy();
hgs
parents: 56
diff changeset
   366
           break;
hgs
parents: 56
diff changeset
   367
       case OutgoingPassword:
hgs
parents: 56
diff changeset
   368
           mSmtpSettings->SetPasswordL(*StringToS60HBufC8LC(settingValue.toString()));
hgs
parents: 56
diff changeset
   369
           CleanupStack::PopAndDestroy();
hgs
parents: 56
diff changeset
   370
           break;
hgs
parents: 56
diff changeset
   371
       case UseOutgoingAuthentication:
hgs
parents: 56
diff changeset
   372
           // fall through
hgs
parents: 56
diff changeset
   373
       case OutgoingMailUsesAuthentication:
hgs
parents: 56
diff changeset
   374
           mSmtpSettings->SetSMTPAuth(settingValue.toBool());
hgs
parents: 56
diff changeset
   375
           break;
hgs
parents: 56
diff changeset
   376
       case OutgoingSecureSockets:
hgs
parents: 56
diff changeset
   377
           mSmtpSettings->SetSecureSockets(settingValue.toBool());
hgs
parents: 56
diff changeset
   378
           break;
hgs
parents: 56
diff changeset
   379
       case OutgoingSSLWrapper:
hgs
parents: 56
diff changeset
   380
           mSmtpSettings->SetSSLWrapper(settingValue.toBool());
hgs
parents: 56
diff changeset
   381
           break;
hgs
parents: 56
diff changeset
   382
       case OutgoingMailSecurityType:
hgs
parents: 56
diff changeset
   383
           setSecurity(*mSmtpSettings, settingValue.toString());
hgs
parents: 56
diff changeset
   384
           break;
hgs
parents: 56
diff changeset
   385
       case OutgoingPort:
hgs
parents: 56
diff changeset
   386
           mSmtpSettings->SetPort(settingValue.toInt());
hgs
parents: 56
diff changeset
   387
           break;
hgs
parents: 56
diff changeset
   388
       default:
hgs
parents: 56
diff changeset
   389
           break;
hgs
parents: 56
diff changeset
   390
   }
56
hgs
parents:
diff changeset
   391
}
hgs
parents:
diff changeset
   392
hgs
parents:
diff changeset
   393
/*!
hgs
parents:
diff changeset
   394
 Writes POP3/IMAP4 specific settings.
hgs
parents:
diff changeset
   395
 \param data consists of keys and values of settings.
hgs
parents:
diff changeset
   396
 */
74
hgs
parents: 56
diff changeset
   397
void NmApiSettingsManagerPrivate::writeSettingL(const NmApiMailboxSettingsData &data)
hgs
parents: 56
diff changeset
   398
{     
hgs
parents: 56
diff changeset
   399
    if (mMailboxType == NmApiMailboxTypePop) {
hgs
parents: 56
diff changeset
   400
        fillPopSettingDataL(data);
hgs
parents: 56
diff changeset
   401
        mAccount->SavePopSettingsL(mPop3Account, *mPop3Settings);
56
hgs
parents:
diff changeset
   402
    }
74
hgs
parents: 56
diff changeset
   403
    else if (mMailboxType == NmApiMailboxTypeImap) {
hgs
parents: 56
diff changeset
   404
        fillImapSettingDataL(data);
hgs
parents: 56
diff changeset
   405
        mAccount->SaveImapSettingsL(mImap4Account, *mImap4Settings);
hgs
parents: 56
diff changeset
   406
    }   
hgs
parents: 56
diff changeset
   407
    mAccount->SaveSmtpSettingsL(mSmtpAccount, *mSmtpSettings);
56
hgs
parents:
diff changeset
   408
}
hgs
parents:
diff changeset
   409
hgs
parents:
diff changeset
   410
/*!
74
hgs
parents: 56
diff changeset
   411
 Writes settings to central repository.
hgs
parents: 56
diff changeset
   412
 \param data consists of keys and values of settings.
56
hgs
parents:
diff changeset
   413
 */
hgs
parents:
diff changeset
   414
bool NmApiSettingsManagerPrivate::writeSettingToCenRep(
hgs
parents:
diff changeset
   415
    const NmApiMailboxSettingsData &data)
hgs
parents:
diff changeset
   416
{
74
hgs
parents: 56
diff changeset
   417
    int key = -1;
56
hgs
parents:
diff changeset
   418
    QVariant settingValue;
74
hgs
parents: 56
diff changeset
   419
    QList<int> keylist = data.listSettings();
56
hgs
parents:
diff changeset
   420
    bool ret = false;
74
hgs
parents: 56
diff changeset
   421
    
hgs
parents: 56
diff changeset
   422
    if (data.getValue(ReceptionActiveProfile, settingValue) && !settingValue.isNull()) {
56
hgs
parents:
diff changeset
   423
        QVariant profileOffset = 0;
hgs
parents:
diff changeset
   424
        if(settingValue.toString() == EmailClientApi::EmailProfileOffsetKUTD) {
74
hgs
parents: 56
diff changeset
   425
            profileOffset = 0;
56
hgs
parents:
diff changeset
   426
        } else if(settingValue.toString() == EmailClientApi::EmailProfileOffsetSE){
hgs
parents:
diff changeset
   427
            profileOffset = 1;
hgs
parents:
diff changeset
   428
        } else if (settingValue.toString() == EmailClientApi::EmailProfileOffsetMF){
74
hgs
parents: 56
diff changeset
   429
            profileOffset = 2;
56
hgs
parents:
diff changeset
   430
        } else if (settingValue.toString() == EmailClientApi::EmailProfileOffsetUD) {
hgs
parents:
diff changeset
   431
            profileOffset = 3;
hgs
parents:
diff changeset
   432
        }
hgs
parents:
diff changeset
   433
        ret = writeToCenRep(IpsServices::EmailKeyReceptionActiveProfile, profileOffset);
hgs
parents:
diff changeset
   434
        if(ret) {
74
hgs
parents: 56
diff changeset
   435
            ret = calculateActiveProfileOffset();
56
hgs
parents:
diff changeset
   436
        }
hgs
parents:
diff changeset
   437
    }
hgs
parents:
diff changeset
   438
    if (ret) {
74
hgs
parents: 56
diff changeset
   439
        bool cenRepSuccess = true;
56
hgs
parents:
diff changeset
   440
        for (int i = 0; i < keylist.size(); i++) {
hgs
parents:
diff changeset
   441
            key = keylist[i];
74
hgs
parents: 56
diff changeset
   442
            if (data.getValue(key, settingValue) && !settingValue.isNull()) {
hgs
parents: 56
diff changeset
   443
                switch (key) {
hgs
parents: 56
diff changeset
   444
                    case DownloadPictures:
hgs
parents: 56
diff changeset
   445
                        cenRepSuccess = writeToCenRep(IpsServices::EmailKeyPreferenceDownloadPictures,
hgs
parents: 56
diff changeset
   446
                            settingValue);
hgs
parents: 56
diff changeset
   447
                        break;
hgs
parents: 56
diff changeset
   448
                    case MessageDivider:
hgs
parents: 56
diff changeset
   449
                        cenRepSuccess = writeToCenRep(IpsServices::EmailKeyPreferenceMessageDivider, 
hgs
parents: 56
diff changeset
   450
                            settingValue);
hgs
parents: 56
diff changeset
   451
                        break;
hgs
parents: 56
diff changeset
   452
                    case ReceptionUserDefinedProfile:
hgs
parents: 56
diff changeset
   453
                        cenRepSuccess = writeToCenRep(IpsServices::EmailKeyReceptionUserDefinedProfile,
hgs
parents: 56
diff changeset
   454
                            settingValue);
hgs
parents: 56
diff changeset
   455
                        break;
hgs
parents: 56
diff changeset
   456
                    case ReceptionInboxSyncWindow:
hgs
parents: 56
diff changeset
   457
                        cenRepSuccess = writeToCenRep(mActiveProfileOffset
hgs
parents: 56
diff changeset
   458
                            + IpsServices::EmailKeyReceptionInboxSyncWindow, settingValue);
hgs
parents: 56
diff changeset
   459
                        break;
hgs
parents: 56
diff changeset
   460
                    case ReceptionGenericSyncWindowInMessages:
hgs
parents: 56
diff changeset
   461
                        cenRepSuccess = writeToCenRep(mActiveProfileOffset
hgs
parents: 56
diff changeset
   462
                            + IpsServices::EmailKeyReceptionGenericSyncWindowInMessages, 
hgs
parents: 56
diff changeset
   463
                            settingValue);
hgs
parents: 56
diff changeset
   464
                        break;
hgs
parents: 56
diff changeset
   465
                    case ReceptionWeekDays:
hgs
parents: 56
diff changeset
   466
                        cenRepSuccess = writeToCenRep(mActiveProfileOffset 
hgs
parents: 56
diff changeset
   467
                            + IpsServices::EmailKeyReceptionWeekDays, settingValue);
hgs
parents: 56
diff changeset
   468
                        break;
hgs
parents: 56
diff changeset
   469
                    case ReceptionDayStartTime:
hgs
parents: 56
diff changeset
   470
                        cenRepSuccess = writeToCenRep(mActiveProfileOffset 
hgs
parents: 56
diff changeset
   471
                            + IpsServices::EmailKeyReceptionDayStartTime, settingValue);
hgs
parents: 56
diff changeset
   472
                        break;
hgs
parents: 56
diff changeset
   473
                    case ReceptionDayEndTime:
hgs
parents: 56
diff changeset
   474
                        cenRepSuccess = writeToCenRep(mActiveProfileOffset
hgs
parents: 56
diff changeset
   475
                            + IpsServices::EmailKeyReceptionDayEndTime, settingValue);
hgs
parents: 56
diff changeset
   476
                        break;
hgs
parents: 56
diff changeset
   477
                    case ReceptionRefreshPeriodDayTime:
hgs
parents: 56
diff changeset
   478
                        cenRepSuccess = writeToCenRep(mActiveProfileOffset
hgs
parents: 56
diff changeset
   479
                            + IpsServices::EmailKeyReceptionRefreshPeriodDayTime, settingValue);
hgs
parents: 56
diff changeset
   480
                        break;
hgs
parents: 56
diff changeset
   481
                    case ReceptionRefreshPeriodOther:
hgs
parents: 56
diff changeset
   482
                        cenRepSuccess = writeToCenRep(mActiveProfileOffset
hgs
parents: 56
diff changeset
   483
                            + IpsServices::EmailKeyReceptionRefreshPeriodOther, settingValue);
hgs
parents: 56
diff changeset
   484
                        break;
hgs
parents: 56
diff changeset
   485
                    case UserNameHidden:
hgs
parents: 56
diff changeset
   486
                        cenRepSuccess = writeToCenRep(IpsServices::EmailKeyUserNameHidden, 
hgs
parents: 56
diff changeset
   487
                            settingValue);
hgs
parents: 56
diff changeset
   488
                        break;
hgs
parents: 56
diff changeset
   489
                    case EmailNotificationState:
hgs
parents: 56
diff changeset
   490
                        cenRepSuccess = writeToCenRep(IpsServices::EmailKeyEMNState, 
hgs
parents: 56
diff changeset
   491
                            settingValue);
hgs
parents: 56
diff changeset
   492
                        break;
hgs
parents: 56
diff changeset
   493
                    case FirstEmnReceived:
hgs
parents: 56
diff changeset
   494
                        cenRepSuccess = writeToCenRep(IpsServices::EmailKeyFirstEmnReceived, 
hgs
parents: 56
diff changeset
   495
                            settingValue);
hgs
parents: 56
diff changeset
   496
                        break;
hgs
parents: 56
diff changeset
   497
                    case EmnReceivedNotSynced:
hgs
parents: 56
diff changeset
   498
                        cenRepSuccess = writeToCenRep(IpsServices::EmailKeyEmnReceivedNotSynced, 
hgs
parents: 56
diff changeset
   499
                            settingValue);
hgs
parents: 56
diff changeset
   500
                        break;
hgs
parents: 56
diff changeset
   501
                    case AlwaysOnlineState:
hgs
parents: 56
diff changeset
   502
                        cenRepSuccess = setAlwaysOnlineState(settingValue);
hgs
parents: 56
diff changeset
   503
                        break;
hgs
parents: 56
diff changeset
   504
                    case AoLastSuccessfulUpdate:
hgs
parents: 56
diff changeset
   505
                        cenRepSuccess = writeToCenRep(IpsServices::EmailKeyAoLastSuccessfulUpdateL, 
hgs
parents: 56
diff changeset
   506
                            settingValue);
hgs
parents: 56
diff changeset
   507
                        break;
hgs
parents: 56
diff changeset
   508
                    case AoLastUpdateFailed:
hgs
parents: 56
diff changeset
   509
                        cenRepSuccess = writeToCenRep(IpsServices::EmailKeyAoLastUpdateFailed, 
hgs
parents: 56
diff changeset
   510
                            settingValue);
hgs
parents: 56
diff changeset
   511
                        break;
hgs
parents: 56
diff changeset
   512
                    case AoUpdateSuccessfulWithCurSettings:
hgs
parents: 56
diff changeset
   513
                        cenRepSuccess = writeToCenRep(
hgs
parents: 56
diff changeset
   514
                            IpsServices::EmailKeyAoUpdateSuccessfulWithCurSettings,
hgs
parents: 56
diff changeset
   515
                            settingValue);
hgs
parents: 56
diff changeset
   516
                        break;
hgs
parents: 56
diff changeset
   517
                    case ReceptionActiveProfile:
hgs
parents: 56
diff changeset
   518
                        // fall through
hgs
parents: 56
diff changeset
   519
                    default:
hgs
parents: 56
diff changeset
   520
                        break;
56
hgs
parents:
diff changeset
   521
                }
74
hgs
parents: 56
diff changeset
   522
                
hgs
parents: 56
diff changeset
   523
                if (!cenRepSuccess) {
hgs
parents: 56
diff changeset
   524
                    ret = false; // ret is false if even one of the cenrep operations fails
56
hgs
parents:
diff changeset
   525
                }
74
hgs
parents: 56
diff changeset
   526
            }
56
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.
74
hgs
parents: 56
diff changeset
   535
 \return QVariant The settings value for the given key.
56
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.
74
hgs
parents: 56
diff changeset
   548
 \return bool Returns <true> if the value was succesfully written, <false> if not.
56
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
74
hgs
parents: 56
diff changeset
   557
void NmApiSettingsManagerPrivate::setSecurity(CImBaseEmailSettings &settings, 
hgs
parents: 56
diff changeset
   558
    QString securityType)
56
hgs
parents:
diff changeset
   559
{
74
hgs
parents: 56
diff changeset
   560
    settings.SetSecureSockets(securityType == NmApiStartTls ? ETrue : EFalse );
hgs
parents: 56
diff changeset
   561
    settings.SetSSLWrapper(securityType == NmApiSSLTls ? ETrue : EFalse );
56
hgs
parents:
diff changeset
   562
}
hgs
parents:
diff changeset
   563
74
hgs
parents: 56
diff changeset
   564
QString NmApiSettingsManagerPrivate::security(CImBaseEmailSettings &settings) const
56
hgs
parents:
diff changeset
   565
{
74
hgs
parents: 56
diff changeset
   566
    bool ss(settings.SecureSockets());
hgs
parents: 56
diff changeset
   567
    bool sslWrapper(settings.SSLWrapper());
hgs
parents: 56
diff changeset
   568
    QString securityType(NmApiSecurityOff);
56
hgs
parents:
diff changeset
   569
74
hgs
parents: 56
diff changeset
   570
    if (ss == true && sslWrapper == false) {
hgs
parents: 56
diff changeset
   571
        securityType = NmApiStartTls;
56
hgs
parents:
diff changeset
   572
    }
74
hgs
parents: 56
diff changeset
   573
    else if (ss == false && sslWrapper == true) {
hgs
parents: 56
diff changeset
   574
        securityType = NmApiSSLTls;
56
hgs
parents:
diff changeset
   575
    }
hgs
parents:
diff changeset
   576
hgs
parents:
diff changeset
   577
    return securityType;
hgs
parents:
diff changeset
   578
}
hgs
parents:
diff changeset
   579
hgs
parents:
diff changeset
   580
/*!
74
hgs
parents: 56
diff changeset
   581
 Function for getting online state.
hgs
parents: 56
diff changeset
   582
 \param success Boolean variable for informing if operation fails. 
hgs
parents: 56
diff changeset
   583
 Note! If success is already <false> it is not set to <true>.
hgs
parents: 56
diff changeset
   584
 \return QString Online state.
56
hgs
parents:
diff changeset
   585
 */
74
hgs
parents: 56
diff changeset
   586
QString NmApiSettingsManagerPrivate::alwaysOnlineState(bool &success) const
56
hgs
parents:
diff changeset
   587
{
74
hgs
parents: 56
diff changeset
   588
    QString ret = NmApiOff;  
hgs
parents: 56
diff changeset
   589
    int settingValue = -1;
hgs
parents: 56
diff changeset
   590
    bool cenRepSuccess = true;
hgs
parents: 56
diff changeset
   591
    QVariant state = readFromCenRep(IpsServices::EmailKeyReceptionActiveProfile,
hgs
parents: 56
diff changeset
   592
        cenRepSuccess);
56
hgs
parents:
diff changeset
   593
74
hgs
parents: 56
diff changeset
   594
    if (cenRepSuccess) {
hgs
parents: 56
diff changeset
   595
        settingValue = state.toInt();
hgs
parents: 56
diff changeset
   596
        if (settingValue != IpsServices::EmailSyncProfileManualFetch) {
56
hgs
parents:
diff changeset
   597
            ret = NmApiAlways;
hgs
parents:
diff changeset
   598
        }
hgs
parents:
diff changeset
   599
    }
74
hgs
parents: 56
diff changeset
   600
    else { // If cenrep read fails it is informed via parameter
hgs
parents: 56
diff changeset
   601
        success = cenRepSuccess;
hgs
parents: 56
diff changeset
   602
    }
hgs
parents: 56
diff changeset
   603
    
56
hgs
parents:
diff changeset
   604
    return ret;
hgs
parents:
diff changeset
   605
}
hgs
parents:
diff changeset
   606
hgs
parents:
diff changeset
   607
/*!
74
hgs
parents: 56
diff changeset
   608
 Function for setting online state off. It is not allowed to change it on.
hgs
parents: 56
diff changeset
   609
 \return bool Return <true> if operation was successful otherwise <false>.
56
hgs
parents:
diff changeset
   610
 */
74
hgs
parents: 56
diff changeset
   611
bool NmApiSettingsManagerPrivate::setAlwaysOnlineState(const QVariant &state)
56
hgs
parents:
diff changeset
   612
{
74
hgs
parents: 56
diff changeset
   613
    bool retVal = true;
56
hgs
parents:
diff changeset
   614
    if (state.toString() == NmApiOff) {
74
hgs
parents: 56
diff changeset
   615
        retVal = writeToCenRep(IpsServices::EmailKeyReceptionActiveProfile,
56
hgs
parents:
diff changeset
   616
            IpsServices::EmailSyncProfileManualFetch);
hgs
parents:
diff changeset
   617
    }
74
hgs
parents: 56
diff changeset
   618
    return retVal;
56
hgs
parents:
diff changeset
   619
}
hgs
parents:
diff changeset
   620
74
hgs
parents: 56
diff changeset
   621
/*!
hgs
parents: 56
diff changeset
   622
 Function for calculating mailbox offset.
hgs
parents: 56
diff changeset
   623
 \return bool Returns <true> if operation was successfull otherwise returns <false>.
hgs
parents: 56
diff changeset
   624
 */
hgs
parents: 56
diff changeset
   625
bool NmApiSettingsManagerPrivate::calculateMailboxOffset()
56
hgs
parents:
diff changeset
   626
{
hgs
parents:
diff changeset
   627
    // Find all the keys that match the criteria 0xZZZZZ000, where Z=don't care.
hgs
parents:
diff changeset
   628
    // This will give us all the keys that hold the mailbox ids, e.g. 0x00001000, 0x00002000, etc.
hgs
parents:
diff changeset
   629
    quint32 partialKey(0x00000000);
hgs
parents:
diff changeset
   630
    quint32 bitMask(0x00000FFF);
hgs
parents:
diff changeset
   631
    XQCentralRepositorySearchCriteria criteria(IpsServices::EmailMailboxSettingRepository,
hgs
parents:
diff changeset
   632
        partialKey, bitMask);
hgs
parents:
diff changeset
   633
    // Set the mailbox id is value criteria for the search.
74
hgs
parents: 56
diff changeset
   634
    criteria.setValueCriteria((static_cast<int>(mMailboxId)));
56
hgs
parents:
diff changeset
   635
hgs
parents:
diff changeset
   636
    // Find the keys.
hgs
parents:
diff changeset
   637
    XQCentralRepositoryUtils utils(*mQSettingsManager);
hgs
parents:
diff changeset
   638
    QList<XQCentralRepositorySettingsKey> foundKeys = utils.findKeys(criteria);
hgs
parents:
diff changeset
   639
74
hgs
parents: 56
diff changeset
   640
    bool retVal = true;
56
hgs
parents:
diff changeset
   641
    // We should only get one key as a result.
hgs
parents:
diff changeset
   642
    if (foundKeys.count() == 1) {
hgs
parents:
diff changeset
   643
        mMailboxOffset = foundKeys[0].key();
74
hgs
parents: 56
diff changeset
   644
        retVal = calculateActiveProfileOffset();
56
hgs
parents:
diff changeset
   645
    }
hgs
parents:
diff changeset
   646
    else {
74
hgs
parents: 56
diff changeset
   647
        mActiveProfileOffset = KUndefinedOffset;
hgs
parents: 56
diff changeset
   648
        mMailboxOffset = KUndefinedOffset;
hgs
parents: 56
diff changeset
   649
        retVal = false;
56
hgs
parents:
diff changeset
   650
    }
74
hgs
parents: 56
diff changeset
   651
    return retVal;
56
hgs
parents:
diff changeset
   652
}
hgs
parents:
diff changeset
   653
hgs
parents:
diff changeset
   654
/*!
74
hgs
parents: 56
diff changeset
   655
 Calculates the Active profile offset.
hgs
parents: 56
diff changeset
   656
  \return bool Returns <true> if operation was successfull otherwise <false>.
56
hgs
parents:
diff changeset
   657
 */
74
hgs
parents: 56
diff changeset
   658
bool NmApiSettingsManagerPrivate::calculateActiveProfileOffset()
56
hgs
parents:
diff changeset
   659
{
74
hgs
parents: 56
diff changeset
   660
    bool retVal = true;
hgs
parents: 56
diff changeset
   661
    QVariant activeProfile = readFromCenRep(
hgs
parents: 56
diff changeset
   662
        IpsServices::EmailKeyReceptionActiveProfile, retVal);
hgs
parents: 56
diff changeset
   663
    if (retVal) {
hgs
parents: 56
diff changeset
   664
        switch (activeProfile.toInt()) {
hgs
parents: 56
diff changeset
   665
            case 0:
hgs
parents: 56
diff changeset
   666
                mActiveProfileOffset = IpsServices::EmailProfileOffsetKUTD;
hgs
parents: 56
diff changeset
   667
                break;
hgs
parents: 56
diff changeset
   668
            case 1:
hgs
parents: 56
diff changeset
   669
                mActiveProfileOffset = IpsServices::EmailProfileOffsetSE;
hgs
parents: 56
diff changeset
   670
                break;
hgs
parents: 56
diff changeset
   671
            case 2:
hgs
parents: 56
diff changeset
   672
                mActiveProfileOffset = IpsServices::EmailProfileOffsetMF;
hgs
parents: 56
diff changeset
   673
                break;
hgs
parents: 56
diff changeset
   674
            case 3:
hgs
parents: 56
diff changeset
   675
                mActiveProfileOffset = IpsServices::EmailProfileOffsetUD;
hgs
parents: 56
diff changeset
   676
                break;
hgs
parents: 56
diff changeset
   677
            default:
hgs
parents: 56
diff changeset
   678
                mActiveProfileOffset = IpsServices::EmailProfileOffsetKUTD;
hgs
parents: 56
diff changeset
   679
                break;
56
hgs
parents:
diff changeset
   680
        }
74
hgs
parents: 56
diff changeset
   681
    }
hgs
parents: 56
diff changeset
   682
    return retVal;
56
hgs
parents:
diff changeset
   683
}
hgs
parents:
diff changeset
   684
74
hgs
parents: 56
diff changeset
   685
/*!
hgs
parents: 56
diff changeset
   686
 Function for checking account type. 
hgs
parents: 56
diff changeset
   687
 \return bool Returns <true> If account type was identified. <false> if not.  
hgs
parents: 56
diff changeset
   688
 */
hgs
parents: 56
diff changeset
   689
bool NmApiSettingsManagerPrivate::checkAccountTypeL()
56
hgs
parents:
diff changeset
   690
{
hgs
parents:
diff changeset
   691
    bool identified = false;
hgs
parents:
diff changeset
   692
    RArray<TImapAccount> imapAccounts;
hgs
parents:
diff changeset
   693
    CleanupClosePushL(imapAccounts);
74
hgs
parents: 56
diff changeset
   694
    
hgs
parents: 56
diff changeset
   695
    mAccount->GetImapAccountsL(imapAccounts);
hgs
parents: 56
diff changeset
   696
    for (int i=0; i < imapAccounts.Count(); ++i) {
hgs
parents: 56
diff changeset
   697
        TImapAccount account = imapAccounts[i];
hgs
parents: 56
diff changeset
   698
        if (account.iImapService == mMailboxId) {
hgs
parents: 56
diff changeset
   699
            mImap4Account = account;
hgs
parents: 56
diff changeset
   700
            mMailboxType = NmApiMailboxTypeImap;
hgs
parents: 56
diff changeset
   701
            identified = true;
hgs
parents: 56
diff changeset
   702
            break;
56
hgs
parents:
diff changeset
   703
        }
hgs
parents:
diff changeset
   704
    }
hgs
parents:
diff changeset
   705
    CleanupStack::PopAndDestroy(&imapAccounts);
hgs
parents:
diff changeset
   706
hgs
parents:
diff changeset
   707
    if (!identified) {
hgs
parents:
diff changeset
   708
        RArray<TPopAccount> popAccounts;
hgs
parents:
diff changeset
   709
        CleanupClosePushL(popAccounts);
74
hgs
parents: 56
diff changeset
   710
        mAccount->GetPopAccountsL(popAccounts);
hgs
parents: 56
diff changeset
   711
        for (int i = 0; i < popAccounts.Count(); ++i) {
hgs
parents: 56
diff changeset
   712
            TPopAccount account = popAccounts[i];
hgs
parents: 56
diff changeset
   713
            if (popAccounts[i].iPopService == mMailboxId) {
hgs
parents: 56
diff changeset
   714
                mPop3Account = account;
hgs
parents: 56
diff changeset
   715
                mMailboxType = NmApiMailboxTypePop;
hgs
parents: 56
diff changeset
   716
                identified = true;
hgs
parents: 56
diff changeset
   717
                break;
56
hgs
parents:
diff changeset
   718
            }
hgs
parents:
diff changeset
   719
        }
hgs
parents:
diff changeset
   720
        CleanupStack::PopAndDestroy(&popAccounts);
hgs
parents:
diff changeset
   721
    }
hgs
parents:
diff changeset
   722
    return identified;
hgs
parents:
diff changeset
   723
}
hgs
parents:
diff changeset
   724
74
hgs
parents: 56
diff changeset
   725
/*!
hgs
parents: 56
diff changeset
   726
 Function for initializing account information.
hgs
parents: 56
diff changeset
   727
 */
56
hgs
parents:
diff changeset
   728
void NmApiSettingsManagerPrivate::initAccountL()
hgs
parents:
diff changeset
   729
{
74
hgs
parents: 56
diff changeset
   730
    mAccount = CEmailAccounts::NewL();
hgs
parents: 56
diff changeset
   731
   
hgs
parents: 56
diff changeset
   732
    if (!checkAccountTypeL()) {
hgs
parents: 56
diff changeset
   733
        User::Leave(KErrNotSupported); // Account type was not identified
hgs
parents: 56
diff changeset
   734
    }
hgs
parents: 56
diff changeset
   735
    
hgs
parents: 56
diff changeset
   736
    if (mMailboxType == NmApiMailboxTypePop) {      
56
hgs
parents:
diff changeset
   737
        mPop3Settings = new(ELeave) CImPop3Settings();
hgs
parents:
diff changeset
   738
        mAccount->LoadPopSettingsL(mPop3Account, *mPop3Settings);
74
hgs
parents: 56
diff changeset
   739
        mAccount->GetSmtpAccountL(mPop3Account.iSmtpService, mSmtpAccount);
56
hgs
parents:
diff changeset
   740
    }
74
hgs
parents: 56
diff changeset
   741
    else if (mMailboxType == NmApiMailboxTypeImap) {   
56
hgs
parents:
diff changeset
   742
        mImap4Settings = new(ELeave) CImImap4Settings();
hgs
parents:
diff changeset
   743
        mAccount->LoadImapSettingsL(mImap4Account, *mImap4Settings);
74
hgs
parents: 56
diff changeset
   744
        mAccount->GetSmtpAccountL(mImap4Account.iSmtpService, mSmtpAccount);
hgs
parents: 56
diff changeset
   745
    }
hgs
parents: 56
diff changeset
   746
    else {
hgs
parents: 56
diff changeset
   747
        User::Leave(KErrNotSupported);
56
hgs
parents:
diff changeset
   748
    }
hgs
parents:
diff changeset
   749
hgs
parents:
diff changeset
   750
    mSmtpSettings = new(ELeave) CImSmtpSettings();
hgs
parents:
diff changeset
   751
    mAccount->LoadSmtpSettingsL(mSmtpAccount, *mSmtpSettings);
74
hgs
parents: 56
diff changeset
   752
    
hgs
parents: 56
diff changeset
   753
    QT_TRYCATCH_LEAVING(mQSettingsManager = new XQSettingsManager());
hgs
parents: 56
diff changeset
   754
    calculateMailboxOffset();
56
hgs
parents:
diff changeset
   755
}
hgs
parents:
diff changeset
   756
hgs
parents:
diff changeset
   757
} // end namespace