ipsservices/nmipssettings/src/nmipssettingsmanagerbase.cpp
changeset 43 99bcbff212ad
parent 23 2dc6caa42ec3
child 68 83cc6bae1de8
equal deleted inserted replaced
42:139d4b7b2938 43:99bcbff212ad
    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(new NmIpsExtendedSettingsManager(mailboxId));
    50     QScopedPointer<NmIpsExtendedSettingsManager> extendedSettings(
       
    51         new NmIpsExtendedSettingsManager(mailboxId));
    51 
    52 
    52     QT_TRAP_THROWING(mSmtpSettings = new(ELeave) CImSmtpSettings());
    53     QT_TRAP_THROWING(mSmtpSettings = new(ELeave) CImSmtpSettings());
    53 
    54 
    54     mExtendedSettingsManager = extendedSettings.take();
    55     mExtendedSettingsManager = extendedSettings.take();
    55 
    56 
    56     mAccount = account; // Takes ownership.
    57     mAccount = account; // Takes ownership.
    57 }
    58 }
    58 
    59 
    59 /*!
    60 /*!
    60     Destructor
    61     Destructor.
    61 */
    62 */
    62 NmIpsSettingsManagerBase::~NmIpsSettingsManagerBase()
    63 NmIpsSettingsManagerBase::~NmIpsSettingsManagerBase()
    63 {
    64 {
    64     delete mAccount;
    65     delete mAccount;
    65     delete mSmtpSettings;
    66     delete mSmtpSettings;
    71     extended settings.
    72     extended settings.
    72     \param settingItem SettingItem enum of the setting to return 
    73     \param settingItem SettingItem enum of the setting to return 
    73     \param QVariant SettingValue of the found setting value.
    74     \param QVariant SettingValue of the found setting value.
    74     \return bool <true> when the setting item was found otherwise <false>.
    75     \return bool <true> when the setting item was found otherwise <false>.
    75 */
    76 */
    76 bool NmIpsSettingsManagerBase::readSetting(IpsServices::SettingItem settingItem, QVariant &settingValue)
    77 bool NmIpsSettingsManagerBase::readSetting(IpsServices::SettingItem settingItem,
       
    78                                            QVariant &settingValue)
    77 {
    79 {
    78     bool found(false);
    80     bool found(false);
    79     
    81     
    80     switch (settingItem) {
    82     switch (settingItem) {
    81         case IpsServices::EmailAlias:
    83         case IpsServices::EmailAlias:
   115             found = true;
   117             found = true;
   116             break;  
   118             break;  
   117         case IpsServices::OutgoingSSLWrapper:
   119         case IpsServices::OutgoingSSLWrapper:
   118         	settingValue = mSmtpSettings->SSLWrapper();
   120         	settingValue = mSmtpSettings->SSLWrapper();
   119             found = true;
   121             found = true;
   120             break;  
   122             break;
       
   123         case IpsServices::Connection:
       
   124             settingValue = 0;
       
   125             TRAP_IGNORE(
       
   126                 CImIAPPreferences *prefs = CImIAPPreferences::NewLC();
       
   127                 mAccount->LoadSmtpIapSettingsL(mSmtpAccount, *prefs);
       
   128                 settingValue = (uint)prefs->SNAPPreference();
       
   129                 CleanupStack::PopAndDestroy(prefs);
       
   130                 found = true;
       
   131             );
       
   132             break;
   121         default:
   133         default:
   122             found = mExtendedSettingsManager->readSetting(settingItem, settingValue);
   134             found = mExtendedSettingsManager->readSetting(settingItem, settingValue);
   123             break;
   135             break;
   124     }   
   136     }   
   125     return found;
   137     return found;
   129     Writes SMTP settings or passes the extended settings to NmIpsExtendedSettingsManager.
   141     Writes SMTP settings or passes the extended settings to NmIpsExtendedSettingsManager.
   130     \param settingItem SettingItem enum of the setting to replace.
   142     \param settingItem SettingItem enum of the setting to replace.
   131     \param settingValue QVariant of the new setting value.
   143     \param settingValue QVariant of the new setting value.
   132     \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>.
   133 */
   145 */
   134 bool NmIpsSettingsManagerBase::writeSetting(IpsServices::SettingItem settingItem, const QVariant &settingValue)
   146 bool NmIpsSettingsManagerBase::writeSetting(IpsServices::SettingItem settingItem,
       
   147                                             const QVariant &settingValue)
   135 {
   148 {
   136     HBufC *tmp = 0;
   149     HBufC *tmp = 0;
   137     HBufC8 *tmp8 = 0;
   150     HBufC8 *tmp8 = 0;
   138     
   151     
   139     bool ret(false);
   152     bool ret(false);
   201             ret = saveSettings();
   214             ret = saveSettings();
   202             break;  
   215             break;  
   203         case IpsServices::OutgoingSSLWrapper:
   216         case IpsServices::OutgoingSSLWrapper:
   204             mSmtpSettings->SetSSLWrapper(settingValue.toBool());
   217             mSmtpSettings->SetSSLWrapper(settingValue.toBool());
   205             ret = saveSettings();
   218             ret = saveSettings();
   206             break;  
   219             break;
       
   220         case IpsServices::Connection:
       
   221             ret = saveIAPSettings(settingValue.toUInt());
       
   222             break;
   207         default:
   223         default:
   208             ret = mExtendedSettingsManager->writeSetting(settingItem, settingValue);
   224             ret = mExtendedSettingsManager->writeSetting(settingItem, settingValue);
   209             break;    
   225             break;    
   210     }
   226     }
   211     return ret;
   227     return ret;
   212 }
   228 }
   213 
   229 
   214 /*!     
   230 /*!     
   215     Delete mailbox.
   231     Deletes the mailbox.
   216 
       
   217     \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
   218             code is returned.
   233             code is returned.
   219 */
   234 */
   220 int NmIpsSettingsManagerBase::deleteMailbox()
   235 int NmIpsSettingsManagerBase::deleteMailbox()
   221 {
   236 {
   225     );
   240     );
   226     return err;
   241     return err;
   227 }
   242 }
   228 
   243 
   229 /*!     
   244 /*!     
       
   245     Returns the NmId of the mailbox.
       
   246     \return Mailbox id.
       
   247 */
       
   248 NmId NmIpsSettingsManagerBase::mailboxId() const
       
   249 {
       
   250     return mMailboxId;
       
   251 }
       
   252 
       
   253 /*!     
       
   254     Returns the mailbox account type.
       
   255     \return Account type.
       
   256 */
       
   257 IpsServices::TIpsSetAccountTypes NmIpsSettingsManagerBase::accountType() const
       
   258 {
       
   259     return mAccountType;
       
   260 }
       
   261 
       
   262 /*!
       
   263      Determines the default port for the outgoing mail server based on the security settings.
       
   264      \return The port number to use.
       
   265  */
       
   266 int NmIpsSettingsManagerBase::determineDefaultOutgoingPort()
       
   267 {
       
   268     int port(IpsServices::standardSmtpPort);
       
   269     if (mSmtpSettings->SSLWrapper()) {
       
   270         port = IpsServices::secureSmtpPort;
       
   271     }        
       
   272     return port;
       
   273 }
       
   274 
       
   275 /*!
       
   276     Returns reference to the Extended Settings Manager.
       
   277     \return Extended Settings Manager reference.
       
   278 */
       
   279 NmIpsExtendedSettingsManager &NmIpsSettingsManagerBase::extendedSettingsManager() const
       
   280 {
       
   281     return *mExtendedSettingsManager;
       
   282 }
       
   283 
       
   284 /*!
   230     Stores the SMTP specific settings.
   285     Stores the SMTP specific settings.
   231     \return bool <true> when the SMTP settings were succesfully written, otherwise <false>.
   286     \return bool <true> when the SMTP settings were succesfully written, otherwise <false>.
   232 */
   287 */
   233 bool NmIpsSettingsManagerBase::saveSettings()
   288 bool NmIpsSettingsManagerBase::saveSettings()
   234 {
   289 {
   235     TRAPD(err, mAccount->SaveSmtpSettingsL(mSmtpAccount, *mSmtpSettings));
   290     TRAPD(err, mAccount->SaveSmtpSettingsL(mSmtpAccount, *mSmtpSettings));
   236     return (err == KErrNone);
   291     return (err == KErrNone);
   237 }
   292 }
   238 
   293 
   239 /*!     
   294 /*!
   240     NmId for the mailbox. 
   295     Stores the SMTP specific IAP settings.
   241 */
   296     \return bool <true> when the SMTP IAP settings were succesfully written, otherwise <false>.
   242 NmId NmIpsSettingsManagerBase::mailboxId() const
   297 */
   243 {
   298 bool NmIpsSettingsManagerBase::saveIAPSettings(uint snapId)
   244     return mMailboxId;
   299 {
   245 }
   300     TRAPD(err,
   246 
   301         CImIAPPreferences *prefs = CImIAPPreferences::NewLC();
   247 /*!     
   302         mAccount->LoadSmtpIapSettingsL(mSmtpAccount, *prefs);
   248     Mailbox account type. 
   303         prefs->SetSNAPL(snapId);
   249 */
   304         mAccount->SaveSmtpIapSettingsL(mSmtpAccount, *prefs);
   250 IpsServices::TIpsSetAccountTypes NmIpsSettingsManagerBase::accountType() const
   305         CleanupStack::PopAndDestroy(prefs);
   251 {
   306     );
   252     return mAccountType;
   307     return (err == KErrNone);
   253 }
   308 }
   254 
       
   255 /*!
       
   256      Determine the default port for the outgoing mail server based on the security settings
       
   257      
       
   258      \return int the port number to use
       
   259  */
       
   260 int NmIpsSettingsManagerBase::determineDefaultOutgoingPort()
       
   261 {
       
   262     int port = 0;    
       
   263     bool sslTls = mSmtpSettings->SSLWrapper();    
       
   264     if (sslTls) {
       
   265         port = IpsServices::secureSmtpPort;
       
   266     } else {
       
   267         port = IpsServices::standardSmtpPort;
       
   268     }        
       
   269     return port;
       
   270 }
       
   271 
       
   272 /*!
       
   273 
       
   274 */
       
   275 NmIpsExtendedSettingsManager &NmIpsSettingsManagerBase::extendedSettingsManager() const
       
   276 {
       
   277     return *mExtendedSettingsManager;
       
   278 }
       
   279