ipsservices/nmipssettings/src/nmipspop3settingsmanager.cpp
branchRCL_3
changeset 63 d189ee25cf9d
equal deleted inserted replaced
61:dcf0eedfc1a3 63:d189ee25cf9d
       
     1 /*
       
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 #include <QVariant>
       
    19 #include <pop3set.h>
       
    20 #include <iapprefs.h>
       
    21 #include <cemailaccounts.h>
       
    22 #include <xqconversions.h>
       
    23 
       
    24 #include "nmipspop3settingsmanager.h"
       
    25 #include "nmipsextendedsettingsmanager.h"
       
    26 
       
    27 /*!
       
    28     \class NmIpsPop3SettingsManager
       
    29     \brief The class implements NmIpsPop3SettingsManager which is used for manipulating
       
    30     pop3 settings of a pop3 mailbox.
       
    31 */
       
    32 
       
    33 // ======== MEMBER FUNCTIONS ========
       
    34 
       
    35 /*!
       
    36     Constructor.
       
    37     Creates the CImPop4Settings instance for loading and saving the POP3 settings.
       
    38     Finds and loads the SMTP account and settings linked to the POP3 account.
       
    39     \param mailboxId Mailbox identifier.
       
    40     \param account CEmailAccounts created by the settings manager factory. Takes ownership.
       
    41     \param imapAccount TImapAccount of the mailbox.
       
    42 */
       
    43 NmIpsPop3SettingsManager::NmIpsPop3SettingsManager(const NmId &mailboxId,
       
    44     CEmailAccounts *account, TPopAccount popAccount)
       
    45 : NmIpsSettingsManagerBase(mailboxId, account, IpsServices::EMailPop),
       
    46   mPop3Account(popAccount)
       
    47 {
       
    48     QT_TRAP_THROWING(mPop3Settings = new(ELeave) CImPop3Settings());
       
    49 
       
    50     TRAP_IGNORE(mAccount->LoadPopSettingsL(mPop3Account, *mPop3Settings));
       
    51     TRAP_IGNORE(mAccount->GetSmtpAccountL(mPop3Account.iSmtpService, mSmtpAccount));
       
    52     TRAP_IGNORE(mAccount->LoadSmtpSettingsL(mSmtpAccount, *mSmtpSettings));
       
    53 }
       
    54 
       
    55 /*!
       
    56     Destructor.
       
    57 */
       
    58 NmIpsPop3SettingsManager::~NmIpsPop3SettingsManager()
       
    59 {
       
    60     delete mPop3Settings;
       
    61 }
       
    62 
       
    63 /*!
       
    64     Finds and returns settings for the account.
       
    65     \param settingItem SettingItem enum of the setting to return.
       
    66     \param QVariant SettingValue of the found setting value.
       
    67     \return <true> when the setting item was found otherwise <false>.
       
    68 */
       
    69 bool NmIpsPop3SettingsManager::readSetting(IpsServices::SettingItem settingItem,
       
    70                                            QVariant &settingValue)
       
    71 {
       
    72 	bool found(false);
       
    73 	switch (settingItem) {
       
    74         case IpsServices::IncomingLoginName:
       
    75             settingValue = XQConversions::s60Desc8ToQString(mPop3Settings->LoginName());
       
    76             found = true;
       
    77             break;
       
    78         case IpsServices::IncomingPassword:
       
    79             settingValue = XQConversions::s60Desc8ToQString(mPop3Settings->Password());
       
    80             found = true;
       
    81             break;
       
    82         case IpsServices::MailboxName:
       
    83             settingValue = XQConversions::s60DescToQString(mPop3Account.iPopAccountName);
       
    84             found = true;
       
    85             break;
       
    86         case IpsServices::IncomingMailServer:
       
    87             settingValue = XQConversions::s60DescToQString(mPop3Settings->ServerAddress());
       
    88             found = true;
       
    89             break;   
       
    90         case IpsServices::IncomingPort:
       
    91             settingValue = mPop3Settings->Port();
       
    92             found = true;
       
    93             break;  
       
    94         case IpsServices::IncomingSecureSockets:
       
    95             settingValue = mPop3Settings->SecureSockets();
       
    96             found = true;
       
    97             break;  
       
    98         case IpsServices::IncomingSSLWrapper:
       
    99             settingValue = mPop3Settings->SSLWrapper();
       
   100             found = true;
       
   101             break;
       
   102         default:
       
   103             found = NmIpsSettingsManagerBase::readSetting(settingItem, settingValue);
       
   104             break;
       
   105     }
       
   106 	return found;
       
   107 }
       
   108 
       
   109 /*!
       
   110     Writes POP3 specific settings or passes SMTP and extended settings to the base class.
       
   111     \param settingItem SettingItem enum of the setting to replace.
       
   112     \param settingValue QVariant of the new setting value.
       
   113 */
       
   114 bool NmIpsPop3SettingsManager::writeSetting(IpsServices::SettingItem settingItem,
       
   115                                             const QVariant &settingValue)
       
   116 {
       
   117     HBufC *tmp = 0;
       
   118     HBufC8 *tmp8 = 0;
       
   119 
       
   120     bool ret(false);
       
   121     TInt err(KErrNone);
       
   122 
       
   123     switch (settingItem) {
       
   124         case IpsServices::IncomingLoginName:
       
   125             tmp8 = XQConversions::qStringToS60Desc8(settingValue.toString());
       
   126             TRAP(err, mPop3Settings->SetLoginNameL(*tmp8));
       
   127             delete tmp8;
       
   128             if (err==KErrNone) {
       
   129                 ret = saveSettings();
       
   130             }
       
   131             break;
       
   132         case IpsServices::IncomingPassword:
       
   133             tmp8 = XQConversions::qStringToS60Desc8(settingValue.toString());
       
   134             TRAP(err, mPop3Settings->SetPasswordL(*tmp8));
       
   135             delete tmp8;
       
   136             if (err==KErrNone) {
       
   137                 ret = saveSettings();
       
   138             }
       
   139             break;
       
   140         case IpsServices::MailboxName:
       
   141             tmp = XQConversions::qStringToS60Desc(settingValue.toString());
       
   142             mPop3Account.iPopAccountName.Copy(*tmp);
       
   143             delete tmp;
       
   144             ret = saveSettings();
       
   145             break;
       
   146         case IpsServices::IncomingMailServer:
       
   147             tmp = XQConversions::qStringToS60Desc(settingValue.toString());
       
   148             TRAP(err, mPop3Settings->SetServerAddressL(*tmp));
       
   149             delete tmp;
       
   150             if (err==KErrNone) {
       
   151                 ret = saveSettings();
       
   152             }
       
   153             break;
       
   154         case IpsServices::IncomingPort:            
       
   155             mPop3Settings->SetPort(settingValue.toInt());
       
   156             ret = saveSettings();
       
   157             break;
       
   158         case IpsServices::IncomingSecureSockets:
       
   159             mPop3Settings->SetSecureSockets(settingValue.toBool());
       
   160             ret = saveSettings();
       
   161             break;  
       
   162         case IpsServices::IncomingSSLWrapper:
       
   163             mPop3Settings->SetSSLWrapper(settingValue.toBool());
       
   164             ret = saveSettings();
       
   165             break;
       
   166         case IpsServices::Connection:
       
   167             ret = saveIAPSettings(settingValue.toUInt());
       
   168             // Fallthrough so SMTP IAP settings are also updated accordingly.
       
   169         default:
       
   170             ret = NmIpsSettingsManagerBase::writeSetting(settingItem, settingValue);
       
   171             break;
       
   172     }
       
   173     return ret;
       
   174 }
       
   175 
       
   176 /*!
       
   177     Deletes the POP3 mailbox.
       
   178     \return Error code <code>0</code> if mailbox deletion was successful, otherwise error
       
   179             code is returned.
       
   180 */
       
   181 int NmIpsPop3SettingsManager::deleteMailbox()
       
   182 {
       
   183     TRAPD(error, mAccount->DeletePopAccountL(mPop3Account));
       
   184     if (!error) {
       
   185     	NmIpsSettingsManagerBase::deleteMailbox();
       
   186     }
       
   187 
       
   188     NMLOG(QString("NmIpsPop3SettingsManager::deleteMailbox status %1").arg(error));
       
   189     return error;
       
   190 }
       
   191 
       
   192 /*!
       
   193      Determines the default port for the incoming mail server based on the security settings.
       
   194      \return The port number to use.
       
   195  */
       
   196 int NmIpsPop3SettingsManager::determineDefaultIncomingPort()
       
   197 {
       
   198     int port(IpsServices::standardPop3Port);
       
   199     if (mPop3Settings->SSLWrapper()) {
       
   200         port = IpsServices::securePop3Port;
       
   201     }        
       
   202     return port;
       
   203 }
       
   204 
       
   205 /*!
       
   206     Stores the POP3 specific settings.
       
   207     \return bool <true> when the POP3 settings were succesfully written, otherwise <false>.
       
   208 */
       
   209 bool NmIpsPop3SettingsManager::saveSettings()
       
   210 {
       
   211     TRAPD(err, mAccount->SavePopSettingsL(mPop3Account, *mPop3Settings));
       
   212     NMLOG(QString("NmIpsPop3SettingsManager::saveSettings rval %1").arg(err));
       
   213     return (err==KErrNone);
       
   214 }
       
   215 
       
   216 /*!
       
   217     Stores the POP3 specific IAP settings.
       
   218     \return bool <true> when the POP3 IAP settings were succesfully written, otherwise <false>.
       
   219 */
       
   220 bool NmIpsPop3SettingsManager::saveIAPSettings(uint snapId)
       
   221 {
       
   222     TRAPD(err,
       
   223         CImIAPPreferences *prefs = CImIAPPreferences::NewLC();
       
   224         mAccount->LoadPopIapSettingsL(mPop3Account, *prefs);
       
   225         prefs->SetSNAPL(snapId);
       
   226         mAccount->SavePopIapSettingsL(mPop3Account, *prefs);
       
   227         CleanupStack::PopAndDestroy(prefs);
       
   228     );
       
   229     return (err==KErrNone);
       
   230 }