ipsservices/nmipssettings/src/nmipssettingsmanagerbase.cpp
changeset 68 83cc6bae1de8
parent 43 99bcbff212ad
equal deleted inserted replaced
67:459da34cdb45 68:83cc6bae1de8
    16 */
    16 */
    17 
    17 
    18 #include <QVariant>
    18 #include <QVariant>
    19 #include <smtpset.h>
    19 #include <smtpset.h>
    20 #include <iapprefs.h>
    20 #include <iapprefs.h>
    21 #include <xqconversions.h>
    21 #include <XqConversions>
    22 
    22 
    23 #include "nmipssettingsmanagerbase.h"
    23 #include "nmipssettingsmanagerbase.h"
    24 #include "nmipsextendedsettingsmanager.h"
    24 #include "nmipsextendedsettingsmanager.h"
    25 
    25 
    26 /*!
    26 /*!
    40     \param mailboxId Mailbox identifier.
    40     \param mailboxId Mailbox identifier.
    41     \param account CEmailAccounts created by the settings manager factory. Takes ownership after
    41     \param account CEmailAccounts created by the settings manager factory. Takes ownership after
    42     successful construction.
    42     successful construction.
    43     \param accountType AccountType identifier.
    43     \param accountType AccountType identifier.
    44 */
    44 */
    45 NmIpsSettingsManagerBase::NmIpsSettingsManagerBase(const NmId &mailboxId, CEmailAccounts *account, 
    45 NmIpsSettingsManagerBase::NmIpsSettingsManagerBase(const NmId &mailboxId, CEmailAccounts *account,
    46     IpsServices::TIpsSetAccountTypes accountType)
    46     IpsServices::TIpsSetAccountTypes accountType)
    47     : mAccountType(accountType),
    47     : mAccountType(accountType),
    48       mMailboxId(mailboxId.id())
    48       mMailboxId(mailboxId.id())
    49 {
    49 {
    50     QScopedPointer<NmIpsExtendedSettingsManager> extendedSettings(
    50     QScopedPointer<NmIpsExtendedSettingsManager> extendedSettings(
    65     delete mAccount;
    65     delete mAccount;
    66     delete mSmtpSettings;
    66     delete mSmtpSettings;
    67     delete mExtendedSettingsManager;
    67     delete mExtendedSettingsManager;
    68 }
    68 }
    69 
    69 
    70 /*!     
    70 /*!
    71     Finds and returns the SMTP specific setting or uses NmIpsExtendedSettingsManager to find
    71     Finds and returns the SMTP specific setting or uses NmIpsExtendedSettingsManager to find
    72     extended settings.
    72     extended settings.
    73     \param settingItem SettingItem enum of the setting to return 
    73     \param settingItem SettingItem enum of the setting to return
    74     \param QVariant SettingValue of the found setting value.
    74     \param QVariant SettingValue of the found setting value.
    75     \return bool <true> when the setting item was found otherwise <false>.
    75     \return bool <true> when the setting item was found otherwise <false>.
    76 */
    76 */
    77 bool NmIpsSettingsManagerBase::readSetting(IpsServices::SettingItem settingItem,
    77 bool NmIpsSettingsManagerBase::readSetting(IpsServices::SettingItem settingItem,
    78                                            QVariant &settingValue)
    78                                            QVariant &settingValue)
    79 {
    79 {
    80     bool found(false);
    80     bool found(false);
    81     
    81 
    82     switch (settingItem) {
    82     switch (settingItem) {
    83         case IpsServices::EmailAlias:
    83         case IpsServices::EmailAlias:
    84             settingValue = XQConversions::s60DescToQString(mSmtpSettings->EmailAlias());
    84             settingValue = XQConversions::s60DescToQString(mSmtpSettings->EmailAlias());
    85             found = true;
    85             found = true;
    86             break; 
    86             break;
    87         case IpsServices::EmailAddress:
    87         case IpsServices::EmailAddress:
    88             settingValue = XQConversions::s60DescToQString(mSmtpSettings->EmailAddress());
    88             settingValue = XQConversions::s60DescToQString(mSmtpSettings->EmailAddress());
    89             found = true;
    89             found = true;
    90             break; 
    90             break;
    91         case IpsServices::ReplyAddress:
    91         case IpsServices::ReplyAddress:
    92             settingValue = XQConversions::s60DescToQString(mSmtpSettings->ReplyToAddress());
    92             settingValue = XQConversions::s60DescToQString(mSmtpSettings->ReplyToAddress());
    93             found = true;
    93             found = true;
    94             break;
    94             break;
    95         case IpsServices::OutgoingMailServer:
    95         case IpsServices::OutgoingMailServer:
    96             settingValue = XQConversions::s60DescToQString(mSmtpSettings->ServerAddress());
    96             settingValue = XQConversions::s60DescToQString(mSmtpSettings->ServerAddress());
    97             found = true;
    97             found = true;
    98             break; 
    98             break;
    99         case IpsServices::OutgoingPort:
    99         case IpsServices::OutgoingPort:
   100             settingValue = mSmtpSettings->Port();
   100             settingValue = mSmtpSettings->Port();
   101             found = true;
   101             found = true;
   102             break;
   102             break;
   103         case IpsServices::OutgoingLoginName:
   103         case IpsServices::OutgoingLoginName:
   104             settingValue = XQConversions::s60Desc8ToQString(mSmtpSettings->LoginName());
   104             settingValue = XQConversions::s60Desc8ToQString(mSmtpSettings->LoginName());
   105             found = true;
   105             found = true;
   106             break; 
   106             break;
   107         case IpsServices::OutgoingPassword:
   107         case IpsServices::OutgoingPassword:
   108             settingValue = XQConversions::s60Desc8ToQString(mSmtpSettings->Password());
   108             settingValue = XQConversions::s60Desc8ToQString(mSmtpSettings->Password());
   109             found = true;
   109             found = true;
   110             break; 
   110             break;
   111         case IpsServices::SMTPAuthentication:
   111         case IpsServices::SMTPAuthentication:
   112             settingValue = mSmtpSettings->SMTPAuth();
   112             settingValue = mSmtpSettings->SMTPAuth();
   113             found = true;
   113             found = true;
   114             break; 
   114             break;
   115         case IpsServices::OutgoingSecureSockets:
   115         case IpsServices::OutgoingSecureSockets:
   116         	settingValue = mSmtpSettings->SecureSockets();
   116         	settingValue = mSmtpSettings->SecureSockets();
   117             found = true;
   117             found = true;
   118             break;  
   118             break;
   119         case IpsServices::OutgoingSSLWrapper:
   119         case IpsServices::OutgoingSSLWrapper:
   120         	settingValue = mSmtpSettings->SSLWrapper();
   120         	settingValue = mSmtpSettings->SSLWrapper();
   121             found = true;
   121             found = true;
   122             break;
   122             break;
   123         case IpsServices::Connection:
   123         case IpsServices::Connection:
   131             );
   131             );
   132             break;
   132             break;
   133         default:
   133         default:
   134             found = mExtendedSettingsManager->readSetting(settingItem, settingValue);
   134             found = mExtendedSettingsManager->readSetting(settingItem, settingValue);
   135             break;
   135             break;
   136     }   
   136     }
   137     return found;
   137     return found;
   138 }
   138 }
   139    
   139 
   140 /*!     
   140 /*!
   141     Writes SMTP settings or passes the extended settings to NmIpsExtendedSettingsManager.
   141     Writes SMTP settings or passes the extended settings to NmIpsExtendedSettingsManager.
   142     \param settingItem SettingItem enum of the setting to replace.
   142     \param settingItem SettingItem enum of the setting to replace.
   143     \param settingValue QVariant of the new setting value.
   143     \param settingValue QVariant of the new setting value.
   144     \return bool <true> when the setting item was succesfully written, otherwise <false>.
   144     \return bool <true> when the setting item was succesfully written, otherwise <false>.
   145 */
   145 */
   146 bool NmIpsSettingsManagerBase::writeSetting(IpsServices::SettingItem settingItem,
   146 bool NmIpsSettingsManagerBase::writeSetting(IpsServices::SettingItem settingItem,
   147                                             const QVariant &settingValue)
   147                                             const QVariant &settingValue)
   148 {
   148 {
   149     HBufC *tmp = 0;
   149     HBufC *tmp = NULL;
   150     HBufC8 *tmp8 = 0;
   150     HBufC8 *tmp8 = NULL;
   151     
   151 
   152     bool ret(false);
   152     bool ret(false);
   153     TInt err(KErrNone);
   153     TInt err(KErrNone);
   154 
   154 
   155     switch (settingItem) {
   155     switch (settingItem) {
   156         case IpsServices::EmailAlias:
   156         case IpsServices::EmailAlias:
   158             TRAP(err, mSmtpSettings->SetEmailAliasL(*tmp));
   158             TRAP(err, mSmtpSettings->SetEmailAliasL(*tmp));
   159             delete tmp;
   159             delete tmp;
   160             if (err==KErrNone) {
   160             if (err==KErrNone) {
   161                 ret = saveSettings();
   161                 ret = saveSettings();
   162             }
   162             }
   163             break; 
   163             break;
   164         case IpsServices::EmailAddress:
   164         case IpsServices::EmailAddress:
   165             tmp = XQConversions::qStringToS60Desc(settingValue.toString());
   165             tmp = XQConversions::qStringToS60Desc(settingValue.toString());
   166             TRAP(err, mSmtpSettings->SetEmailAddressL(*tmp));
   166             TRAP(err, mSmtpSettings->SetEmailAddressL(*tmp));
   167             delete tmp;
   167             delete tmp;
   168             if (err==KErrNone) {
   168             if (err==KErrNone) {
   169                 ret = saveSettings();
   169                 ret = saveSettings();
   170             }
   170             }
   171             break; 
   171             break;
   172         case IpsServices::ReplyAddress:
   172         case IpsServices::ReplyAddress:
   173             tmp = XQConversions::qStringToS60Desc(settingValue.toString());
   173             tmp = XQConversions::qStringToS60Desc(settingValue.toString());
   174             TRAP(err, mSmtpSettings->SetReplyToAddressL(*tmp));
   174             TRAP(err, mSmtpSettings->SetReplyToAddressL(*tmp));
   175             delete tmp;
   175             delete tmp;
   176             if (err==KErrNone) {
   176             if (err==KErrNone) {
   183             delete tmp;
   183             delete tmp;
   184             if (err==KErrNone) {
   184             if (err==KErrNone) {
   185                 ret = saveSettings();
   185                 ret = saveSettings();
   186             }
   186             }
   187             break;
   187             break;
   188         case IpsServices::OutgoingPort:            
   188         case IpsServices::OutgoingPort:
   189             mSmtpSettings->SetPort(settingValue.toInt());
   189             mSmtpSettings->SetPort(settingValue.toInt());
   190             ret = saveSettings();
   190             ret = saveSettings();
   191             break;
   191             break;
   192         case IpsServices::OutgoingLoginName:
   192         case IpsServices::OutgoingLoginName:
   193             tmp8 = XQConversions::qStringToS60Desc8(settingValue.toString());
   193             tmp8 = XQConversions::qStringToS60Desc8(settingValue.toString());
   203             delete tmp8;
   203             delete tmp8;
   204             if (err==KErrNone) {
   204             if (err==KErrNone) {
   205                 ret = saveSettings();
   205                 ret = saveSettings();
   206             }
   206             }
   207             break;
   207             break;
   208         case IpsServices::SMTPAuthentication:            
   208         case IpsServices::SMTPAuthentication:
   209             mSmtpSettings->SetSMTPAuth(settingValue.toBool());
   209             mSmtpSettings->SetSMTPAuth(settingValue.toBool());
   210             ret = saveSettings();
   210             ret = saveSettings();
   211             break;
   211             break;
   212         case IpsServices::OutgoingSecureSockets:
   212         case IpsServices::OutgoingSecureSockets:
   213             mSmtpSettings->SetSecureSockets(settingValue.toBool());
   213             mSmtpSettings->SetSecureSockets(settingValue.toBool());
   214             ret = saveSettings();
   214             ret = saveSettings();
   215             break;  
   215             break;
   216         case IpsServices::OutgoingSSLWrapper:
   216         case IpsServices::OutgoingSSLWrapper:
   217             mSmtpSettings->SetSSLWrapper(settingValue.toBool());
   217             mSmtpSettings->SetSSLWrapper(settingValue.toBool());
   218             ret = saveSettings();
   218             ret = saveSettings();
   219             break;
   219             break;
   220         case IpsServices::Connection:
   220         case IpsServices::Connection:
   221             ret = saveIAPSettings(settingValue.toUInt());
   221             ret = saveIAPSettings(settingValue.toUInt());
   222             break;
   222             break;
   223         default:
   223         default:
   224             ret = mExtendedSettingsManager->writeSetting(settingItem, settingValue);
   224             ret = mExtendedSettingsManager->writeSetting(settingItem, settingValue);
   225             break;    
   225             break;
   226     }
   226     }
   227     return ret;
   227     return ret;
   228 }
   228 }
   229 
   229 
   230 /*!     
   230 /*!
   231     Deletes the mailbox.
   231     Deletes the mailbox.
   232     \return Error code <code>0</code> if mailbox deletion was successful, otherwise error
   232     \return Error code <code>0</code> if mailbox deletion was successful, otherwise error
   233             code is returned.
   233             code is returned.
   234 */
   234 */
   235 int NmIpsSettingsManagerBase::deleteMailbox()
   235 int NmIpsSettingsManagerBase::deleteMailbox()
   239         mExtendedSettingsManager->deleteSettings();
   239         mExtendedSettingsManager->deleteSettings();
   240     );
   240     );
   241     return err;
   241     return err;
   242 }
   242 }
   243 
   243 
   244 /*!     
   244 /*!
   245     Returns the NmId of the mailbox.
   245     Returns the NmId of the mailbox.
   246     \return Mailbox id.
   246     \return Mailbox id.
   247 */
   247 */
   248 NmId NmIpsSettingsManagerBase::mailboxId() const
   248 NmId NmIpsSettingsManagerBase::mailboxId() const
   249 {
   249 {
   250     return mMailboxId;
   250     return mMailboxId;
   251 }
   251 }
   252 
   252 
   253 /*!     
   253 /*!
   254     Returns the mailbox account type.
   254     Returns the mailbox account type.
   255     \return Account type.
   255     \return Account type.
   256 */
   256 */
   257 IpsServices::TIpsSetAccountTypes NmIpsSettingsManagerBase::accountType() const
   257 IpsServices::TIpsSetAccountTypes NmIpsSettingsManagerBase::accountType() const
   258 {
   258 {
   266 int NmIpsSettingsManagerBase::determineDefaultOutgoingPort()
   266 int NmIpsSettingsManagerBase::determineDefaultOutgoingPort()
   267 {
   267 {
   268     int port(IpsServices::standardSmtpPort);
   268     int port(IpsServices::standardSmtpPort);
   269     if (mSmtpSettings->SSLWrapper()) {
   269     if (mSmtpSettings->SSLWrapper()) {
   270         port = IpsServices::secureSmtpPort;
   270         port = IpsServices::secureSmtpPort;
   271     }        
   271     }
   272     return port;
   272     return port;
   273 }
   273 }
   274 
   274 
   275 /*!
   275 /*!
   276     Returns reference to the Extended Settings Manager.
   276     Returns reference to the Extended Settings Manager.