ipsservices/nmipssettings/src/nmipssettingshelper.cpp
changeset 18 578830873419
child 20 ecc8def7944a
equal deleted inserted replaced
4:e7aa27f58ae1 18:578830873419
       
     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 <HbAction>
       
    20 #include <HbGlobal>
       
    21 #include <HbMessageBox>
       
    22 #include <HbProgressDialog>
       
    23 #include <cpsettingformitemdata.h>
       
    24 
       
    25 #include "nmipssettingshelper.h"
       
    26 #include "nmipssettingsmanagerbase.h"
       
    27 
       
    28 /*!
       
    29     \class NmIpsSettingsHelper
       
    30     \brief Helper class to save data into database when user has made changes.
       
    31 
       
    32 */
       
    33 
       
    34 // ======== MEMBER FUNCTIONS ========
       
    35 
       
    36 /*!
       
    37     Constructor of NmIpsSettingsHelper.
       
    38     \param settingsManager Reference used by settingshelper to read and store values
       
    39 */
       
    40 NmIpsSettingsHelper::NmIpsSettingsHelper(NmIpsSettingsManagerBase &settingsManager)
       
    41 : mCurrentLineEditChanged(false),
       
    42   mSettingsManager(settingsManager)
       
    43 {
       
    44 }
       
    45 
       
    46 /*!
       
    47     Destructor of NmIpsSettingsHelper.
       
    48 */
       
    49 NmIpsSettingsHelper::~NmIpsSettingsHelper()
       
    50 {
       
    51     mContentItems.clear();
       
    52 }
       
    53 
       
    54 /*!
       
    55     Inserts content item pointers into map, which then can be used to access the widgets data.
       
    56     \param IpsServices::SettingItem. Key that can be used to access the value from map.
       
    57     \param  CpSettingFormItemData *. Pointer to the content item.
       
    58 */
       
    59 void NmIpsSettingsHelper::insertContentItem(IpsServices::SettingItem key,
       
    60                                             CpSettingFormItemData *value)
       
    61 {
       
    62     mContentItems.insert(key, value);
       
    63 }
       
    64 
       
    65 /*!
       
    66     Saves the My Name value into database if user has changed the value.
       
    67 */
       
    68 void NmIpsSettingsHelper::saveMyName()
       
    69 {
       
    70     if (mCurrentLineEditChanged) {
       
    71         CpSettingFormItemData *item = mContentItems.value(IpsServices::EmailAlias);
       
    72         QVariant data = item->contentWidgetData(QString("text"));
       
    73         mSettingsManager.writeSetting(IpsServices::EmailAlias, data);
       
    74     }
       
    75     mCurrentLineEditChanged = false;
       
    76 }
       
    77 
       
    78 /*!
       
    79     Sets the edit changed flag to indicate that user has edited the field
       
    80 
       
    81     \param text Reference to the text value in the line edit box.
       
    82 */
       
    83 void NmIpsSettingsHelper::myNameTextChange(const QString &text)
       
    84 {
       
    85     Q_UNUSED(text);
       
    86     mCurrentLineEditChanged = true;
       
    87 }
       
    88 
       
    89 /*!
       
    90     Saves the Mailbox name value into database if user has changed the value.
       
    91 */
       
    92 void NmIpsSettingsHelper::saveMailboxName()
       
    93 {
       
    94     if (mCurrentLineEditChanged) {
       
    95         CpSettingFormItemData *item = mContentItems.value(IpsServices::MailboxName);
       
    96         QVariant data = item->contentWidgetData(QString("text"));
       
    97         // Only save mailbox name if it's length is greater than zero. CEmailAccounts does not
       
    98         // allow zero-length mailbox names.
       
    99         if (data.toString().length() > 0) {
       
   100             mSettingsManager.writeSetting(IpsServices::MailboxName, data);
       
   101             QVariant property(NmSettings::MailboxName);
       
   102             emit mailboxPropertyChanged(mSettingsManager.mailboxId(), property, data);
       
   103         }
       
   104         else {
       
   105             if (mSettingsManager.readSetting(IpsServices::MailboxName, data)) {
       
   106                 item->setContentWidgetData(QString("text"), data);
       
   107             }
       
   108         }
       
   109 
       
   110     }
       
   111     mCurrentLineEditChanged = false;
       
   112 }
       
   113 
       
   114 /*!
       
   115     Sets the edit changed flag to indicate that user has edited the field
       
   116 
       
   117     \param text Reference to the text value in the line edit box.
       
   118 */
       
   119 void NmIpsSettingsHelper::mailboxNameTextChange(const QString &text)
       
   120 {
       
   121     Q_UNUSED(text);
       
   122     mCurrentLineEditChanged = true;
       
   123 }
       
   124 
       
   125 /*!
       
   126     Saves the Mail address value into database if user has changed the value.
       
   127 */
       
   128 void NmIpsSettingsHelper::saveMailAddress()
       
   129 {
       
   130     if (mCurrentLineEditChanged) {
       
   131         CpSettingFormItemData *item = mContentItems.value(IpsServices::EmailAddress);
       
   132         QVariant data = item->contentWidgetData(QString("text"));
       
   133         mSettingsManager.writeSetting(IpsServices::EmailAddress, data);
       
   134     }
       
   135     mCurrentLineEditChanged = false;
       
   136 }
       
   137 
       
   138 /*!
       
   139     Sets the edit changed flag to indicate that user has edited the field
       
   140 
       
   141     \param text Reference to the text value in the line edit box.
       
   142 */
       
   143 void NmIpsSettingsHelper::mailAddressTextChange(const QString &text)
       
   144 {
       
   145     Q_UNUSED(text);
       
   146     mCurrentLineEditChanged = true;
       
   147 }
       
   148 
       
   149 /*!
       
   150     Saves the Username value into database if user has changed the value.
       
   151 */
       
   152 void NmIpsSettingsHelper::saveUserName()
       
   153 {
       
   154     if (mCurrentLineEditChanged) {
       
   155         CpSettingFormItemData *item = mContentItems.value(IpsServices::LoginName);
       
   156         QVariant data = item->contentWidgetData(QString("text"));
       
   157         mSettingsManager.writeSetting(IpsServices::LoginName, data);
       
   158     }
       
   159     mCurrentLineEditChanged = false;
       
   160 }
       
   161 
       
   162 /*!
       
   163     Sets the edit changed flag to indicate that user has edited the field
       
   164 
       
   165     \param text Reference to the text value in the line edit box.
       
   166 */
       
   167 void NmIpsSettingsHelper::userNameTextChange(const QString &text)
       
   168 {
       
   169     Q_UNUSED(text);
       
   170     mCurrentLineEditChanged = true;
       
   171 }
       
   172 
       
   173 /*!
       
   174     Saves the Password value into database
       
   175 */
       
   176 void NmIpsSettingsHelper::savePassword()
       
   177 {
       
   178     CpSettingFormItemData *item = mContentItems.value(IpsServices::Password);
       
   179     QVariant data = item->contentWidgetData(QString("text"));
       
   180     mSettingsManager.writeSetting(IpsServices::Password, data);
       
   181 }
       
   182 
       
   183 /*!
       
   184     Saves the Reply to value into database if user has changed the value.
       
   185 */
       
   186 void NmIpsSettingsHelper::saveReplyTo()
       
   187 {
       
   188     if (mCurrentLineEditChanged) {
       
   189         CpSettingFormItemData *item = mContentItems.value(IpsServices::ReplyAddress);
       
   190         QVariant data = item->contentWidgetData(QString("text"));
       
   191         mSettingsManager.writeSetting(IpsServices::ReplyAddress, data);
       
   192     }
       
   193     mCurrentLineEditChanged = false;
       
   194 }
       
   195 
       
   196 /*!
       
   197     Sets the edit changed flag to indicate that user has edited the field
       
   198 
       
   199     \param text Reference to the text value in the line edit box.
       
   200 */
       
   201 void NmIpsSettingsHelper::replyToTextChange(const QString &text)
       
   202 {
       
   203     Q_UNUSED(text);
       
   204     mCurrentLineEditChanged = true;
       
   205 }
       
   206 
       
   207 /*!
       
   208     Deletes mailbox and displays the proper notes.
       
   209 */
       
   210 void NmIpsSettingsHelper::deleteButtonPress()
       
   211 {
       
   212     HbMessageBox confirmationDialog(HbMessageBox::MessageTypeQuestion);
       
   213     confirmationDialog.setText(hbTrId("txt_mail_dialog_do_you_want_to_delete_the_mailbox"));
       
   214     confirmationDialog.setModal(true);
       
   215     confirmationDialog.setTimeout(HbMessageBox::NoTimeout);
       
   216 
       
   217     HbAction *action = confirmationDialog.exec();
       
   218 
       
   219     if (action != confirmationDialog.primaryAction()) {
       
   220         // The user did not confirm the deletion.
       
   221         return;
       
   222     }
       
   223 
       
   224     QVariant mailboxName;
       
   225     mSettingsManager.readSetting(IpsServices::MailboxName, mailboxName);
       
   226 
       
   227     // Display the progress note. Before display the note, remove the cancel
       
   228     // button.
       
   229     HbProgressDialog progressNote(HbProgressDialog::WaitDialog);
       
   230     progressNote.setText(hbTrId("txt_mail_dpophead _1_deleted"));
       
   231     action = progressNote.primaryAction();
       
   232     progressNote.removeAction(action);
       
   233     progressNote.delayedShow();
       
   234 
       
   235     if (!mSettingsManager.deleteMailbox()) {
       
   236         // The mailbox was deleted successfully. Hide the progress note and
       
   237         // display the "mailbox deleted" dialog.
       
   238         progressNote.close();
       
   239 
       
   240         HbMessageBox infoDialog(HbMessageBox::MessageTypeInformation);
       
   241         infoDialog.setText(
       
   242             hbTrId("txt_mail_dialog_1_deleted").arg(mailboxName.toString()));
       
   243         infoDialog.setModal(true);
       
   244         HbAction *action = infoDialog.exec();
       
   245 
       
   246         // Emit the signal to update the UI.
       
   247         emit mailboxListChanged(mSettingsManager.mailboxId(),
       
   248                                 NmSettings::MailboxDeleted);
       
   249     } else {
       
   250         // Failed to delete the mailbox!
       
   251         // TODO: Should an error note be displayed?
       
   252         progressNote.close();
       
   253     }
       
   254 }
       
   255 
       
   256 /*!
       
   257     Saves the selected receiving schedule setting.
       
   258     \index Selected receiving schedule.
       
   259 */
       
   260 void NmIpsSettingsHelper::receivingScheduleChange(int index)
       
   261 {
       
   262     mSettingsManager.writeSetting(IpsServices::ReceptionActiveProfile, QVariant(index));
       
   263 }