ipsservices/nmipssettings/src/nmipssettingshelper.cpp
changeset 43 99bcbff212ad
parent 40 2c62ef3caffd
child 44 c2d07d913565
equal deleted inserted replaced
42:139d4b7b2938 43:99bcbff212ad
    14 * Description:
    14 * Description:
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 #include <QVariant>
    18 #include <QVariant>
       
    19 #include <QIntValidator>
       
    20 #include <QStringList>
       
    21 
    19 #include <HbAction>
    22 #include <HbAction>
    20 #include <HbGlobal>
    23 #include <HbGlobal>
    21 #include <HbMessageBox>
    24 #include <HbMessageBox>
    22 #include <HbProgressDialog>
    25 #include <HbProgressDialog>
    23 #include <HbInputDialog>
    26 #include <HbInputDialog>
    24 #include <cpsettingformitemdata.h>
    27 #include <HbDataFormModel>
    25 #include <hbdataformmodel.h>
    28 #include <HbExtendedLocale>
    26 #include <qstringlist.h>
    29 #include <HbLineEdit>
    27 #include <hbextendedlocale.h>
       
    28 #include <hblineedit.h>
       
    29 #include <HbValidator>
    30 #include <HbValidator>
    30 #include <QIntValidator>
       
    31 #include <HbStringUtil>
    31 #include <HbStringUtil>
    32 #include <HbDataForm>
    32 #include <HbDataForm>
       
    33 
       
    34 #include <cpsettingformitemdata.h>
       
    35 
       
    36 #include <cmapplsettingsui.h>
       
    37 #include <cmmanagerdefines_shim.h>
       
    38 #include <qnetworkconfigmanager.h>
       
    39 #include <qnetworkconfiguration.h>
       
    40 
    33 
    41 
    34 #include "nmipssettingshelper.h"
    42 #include "nmipssettingshelper.h"
    35 #include "nmipssettingsmanagerbase.h"
    43 #include "nmipssettingsmanagerbase.h"
    36 #include "nmipssettingscustomitem.h"
    44 #include "nmipssettingscustomitem.h"
    37 #include "nmipsextendedsettingsmanager.h"
    45 #include "nmipsextendedsettingsmanager.h"
    38 
    46 
    39 // CONSTANTS
    47 // CONSTANTS
    40 
    48 
    41 // Dynamic receiving schedule group items
    49 // Dynamic receiving schedule group items.
    42 const IpsServices::SettingItem NmIpsSettingsReceivingSchedule[] = {
    50 const IpsServices::SettingItem NmIpsSettingsReceivingSchedule[] = {
    43         IpsServices::ReceptionInboxSyncWindow,
    51         IpsServices::ReceptionInboxSyncWindow,
    44         IpsServices::ReceptionWeekDays,
    52         IpsServices::ReceptionWeekDays,
    45         IpsServices::ReceptionDayStartTime,
    53         IpsServices::ReceptionDayStartTime,
    46         IpsServices::ReceptionDayEndTime,
    54         IpsServices::ReceptionDayEndTime,
    47         IpsServices::ReceptionRefreshPeriodDayTime};
    55         IpsServices::ReceptionRefreshPeriodDayTime};
       
    56 
       
    57 QTM_USE_NAMESPACE
       
    58 
    48 
    59 
    49 /*!
    60 /*!
    50     \class NmIpsSettingsHelper
    61     \class NmIpsSettingsHelper
    51     \brief Helper class to save data into database when user has made changes.
    62     \brief Helper class to save data into database when user has made changes.
    52 
    63 
    70   mIncomingPortInputDialog(0),
    81   mIncomingPortInputDialog(0),
    71   mIncomingPortInputValidator(0),
    82   mIncomingPortInputValidator(0),
    72   mFolderPathInputDialog(0),
    83   mFolderPathInputDialog(0),
    73   mOutgoingPortInputDialog(0),
    84   mOutgoingPortInputDialog(0),
    74   mOutgoingPortInputValidator(0),
    85   mOutgoingPortInputValidator(0),
       
    86   mDestinationDialog(0),
    75   mServerInfoDynamicItemsVisible(false),
    87   mServerInfoDynamicItemsVisible(false),
    76   mRadioButtonPreviousIndex(0)
    88   mRadioButtonPreviousIndex(0)
       
    89 
    77 {
    90 {
    78 }
    91 }
    79 
    92 
    80 /*!
    93 /*!
    81     Destructor of NmIpsSettingsHelper.
    94     Destructor of NmIpsSettingsHelper.
   271                         HbDataFormModelItem::RadioButtonListItem,
   284                         HbDataFormModelItem::RadioButtonListItem,
   272                             hbTrId("txt_mailips_setlabel_refresh_mail"));
   285                             hbTrId("txt_mailips_setlabel_refresh_mail"));
   273 
   286 
   274                     mReceivingScheduleGroupItem->appendChild(formItemData);
   287                     mReceivingScheduleGroupItem->appendChild(formItemData);
   275                     insertContentItem(IpsServices::ReceptionRefreshPeriodDayTime, formItemData);
   288                     insertContentItem(IpsServices::ReceptionRefreshPeriodDayTime, formItemData);
       
   289 
       
   290                     // If changes are made to refreshMailItems, conversion table in
       
   291                     // refreshPeriodModified method needs to be updated also.
   276                     QStringList refreshMailItems;
   292                     QStringList refreshMailItems;
   277                     refreshMailItems << hbTrId("txt_mailips_setlabel_val_keep_uptodate")
   293                     refreshMailItems << hbTrId("txt_mailips_setlabel_val_keep_uptodate")
   278                                      << hbTrId("txt_mailips_setlabel_val_every_15_minutes")
   294                                      << hbTrId("txt_mailips_setlabel_val_every_15_minutes")
   279                                      << hbTrId("txt_mailips_setlabel_val_every_1_hour")
   295                                      << hbTrId("txt_mailips_setlabel_val_every_1_hour")
   280                                      << hbTrId("txt_mailips_setlabel_val_every_4_hours");
   296                                      << hbTrId("txt_mailips_setlabel_val_every_4_hours");
   281                     formItemData->setContentWidgetData(QString("items"), refreshMailItems);
   297                     formItemData->setContentWidgetData(QString("items"), refreshMailItems);
   282 
   298                     mDataForm.addConnection(
   283                     QList<QVariant> refreshMailItemValues;
   299                         formItemData, SIGNAL(valueChanged(QPersistentModelIndex, QVariant)),
   284                     refreshMailItemValues << 5
   300                         this, SLOT(refreshPeriodModified(QPersistentModelIndex, QVariant)));
   285                                           << 15
       
   286                                           << 60
       
   287                                           << 240;
       
   288                     QVariant value(refreshMailItemValues);
       
   289                     formItemData->setData(HbDataFormModelItem::DescriptionRole + 1, value);
       
   290 
       
   291                     mDataForm.addConnection(formItemData, SIGNAL(itemSelected(int)),
       
   292                         this, SLOT(refreshPeriodModified(int)));
       
   293                 }
   301                 }
   294 
   302 
   295                 // Update data
   303                 // Update data
   296                 QVariant interval;
   304                 QVariant interval;
   297                 mSettingsManager.readSetting(item, interval);
   305                 mSettingsManager.readSetting(item, interval);
   362     mCurrentLineEditChanged = false;
   370     mCurrentLineEditChanged = false;
   363 }
   371 }
   364 
   372 
   365 /*!
   373 /*!
   366     Sets the edit changed flag to indicate that user has edited the field
   374     Sets the edit changed flag to indicate that user has edited the field
   367 
       
   368     \param text Reference to the text value in the line edit box.
   375     \param text Reference to the text value in the line edit box.
   369 */
   376 */
   370 void NmIpsSettingsHelper::myNameTextChange(const QString &text)
   377 void NmIpsSettingsHelper::myNameTextChange(const QString &text)
   371 {
   378 {
   372     Q_UNUSED(text);
   379     Q_UNUSED(text);
   401         else {
   408         else {
   402             if (mSettingsManager.readSetting(IpsServices::MailboxName, data)) {
   409             if (mSettingsManager.readSetting(IpsServices::MailboxName, data)) {
   403                 item->setContentWidgetData(QString("text"), data);
   410                 item->setContentWidgetData(QString("text"), data);
   404             }
   411             }
   405         }
   412         }
   406 
       
   407     }
   413     }
   408     mCurrentLineEditChanged = false;
   414     mCurrentLineEditChanged = false;
   409 }
   415 }
   410 
   416 
   411 /*!
   417 /*!
   412     Sets the edit changed flag to indicate that user has edited the field
   418     Sets the edit changed flag to indicate that user has edited the field
   413 
       
   414     \param text Reference to the text value in the line edit box.
   419     \param text Reference to the text value in the line edit box.
   415 */
   420 */
   416 void NmIpsSettingsHelper::mailboxNameTextChange(const QString &text)
   421 void NmIpsSettingsHelper::mailboxNameTextChange(const QString &text)
   417 {
   422 {
   418     Q_UNUSED(text);
   423     Q_UNUSED(text);
   428 		emit goOffline(mSettingsManager.mailboxId());
   433 		emit goOffline(mSettingsManager.mailboxId());
   429 		mEmitOnline = true;
   434 		mEmitOnline = true;
   430 		HbDataFormModelItem *item = mContentItems.value(IpsServices::EmailAddress);
   435 		HbDataFormModelItem *item = mContentItems.value(IpsServices::EmailAddress);
   431         QVariant data = item->contentWidgetData(QString("text"));
   436         QVariant data = item->contentWidgetData(QString("text"));
   432         mSettingsManager.writeSetting(IpsServices::EmailAddress, data);
   437         mSettingsManager.writeSetting(IpsServices::EmailAddress, data);
       
   438         QVariant property(NmSettings::MailboxName);
       
   439         emit mailboxPropertyChanged(mSettingsManager.mailboxId(), property, data);
   433     }
   440     }
   434     mCurrentLineEditChanged = false;
   441     mCurrentLineEditChanged = false;
   435 }
   442 }
   436 
   443 
   437 /*!
   444 /*!
   546     mCurrentLineEditChanged = false;
   553     mCurrentLineEditChanged = false;
   547 }
   554 }
   548 
   555 
   549 /*!
   556 /*!
   550     Sets the edit changed flag to indicate that user has edited the field
   557     Sets the edit changed flag to indicate that user has edited the field
   551 
       
   552     \param text Reference to the text value in the line edit box.
   558     \param text Reference to the text value in the line edit box.
   553 */
   559 */
   554 void NmIpsSettingsHelper::replyToTextChange(const QString &text)
   560 void NmIpsSettingsHelper::replyToTextChange(const QString &text)
   555 {
   561 {
   556     Q_UNUSED(text);
   562     Q_UNUSED(text);
   575 /*!
   581 /*!
   576     Deletes mailbox and displays the proper notes.
   582     Deletes mailbox and displays the proper notes.
   577 */
   583 */
   578 void NmIpsSettingsHelper::handleMailboxDelete(HbAction *action)
   584 void NmIpsSettingsHelper::handleMailboxDelete(HbAction *action)
   579 {
   585 {
   580     if (action == mDeleteConfirmationDialog->primaryAction()) {
   586     if (action == mDeleteConfirmationDialog->actions().at(0)) {        
   581         
       
   582         emit goOffline(mSettingsManager.mailboxId());
   587         emit goOffline(mSettingsManager.mailboxId());
   583         mEmitOnline = false;
   588         mEmitOnline = false;
   584     
   589     
   585         QVariant mailboxName;
   590         QVariant mailboxName;
   586         mSettingsManager.readSetting(IpsServices::MailboxName, mailboxName);
   591         mSettingsManager.readSetting(IpsServices::MailboxName, mailboxName);
   587     
   592     
   588         // Display the progress note. Before display the note, remove the cancel
   593         // Display the progress note. Before display the note, remove the cancel
   589         // button.
   594         // button.
   590         HbProgressDialog progressNote(HbProgressDialog::WaitDialog);
   595         HbProgressDialog progressNote(HbProgressDialog::WaitDialog);
   591         progressNote.setText(hbTrId("txt_common_info_deleting"));
   596         progressNote.setText(hbTrId("txt_common_info_deleting"));
   592         action = progressNote.primaryAction();
   597         progressNote.removeAction(progressNote.actions().at(0));
   593         progressNote.removeAction(action);
       
   594         progressNote.delayedShow();
   598         progressNote.delayedShow();
   595     
   599     
   596         if (!mSettingsManager.deleteMailbox()) {
   600         if (!mSettingsManager.deleteMailbox()) {
   597             // The mailbox was deleted successfully. Hide the progress note and
   601             // The mailbox was deleted successfully. Hide the progress note and
   598             // display the "mailbox deleted" dialog.
   602             // display the "mailbox deleted" dialog.
   613         }
   617         }
   614     }
   618     }
   615 }
   619 }
   616 
   620 
   617 /*!
   621 /*!
   618     Handels the event after the mailbox delete information dialog has been dismissed.
   622     Handles the event after the mailbox delete information dialog has been dismissed.
   619 */
   623 */
   620 void NmIpsSettingsHelper::handleMailboxDeleteUpdate(HbAction *action)
   624 void NmIpsSettingsHelper::handleMailboxDeleteUpdate(HbAction *action)
   621 {
   625 {
   622     Q_UNUSED(action);
   626     Q_UNUSED(action);
   623     // Emit the signal to update the UI.
   627     // Emit the signal to update the UI.
   748     mCurrentLineEditChanged = false;
   752     mCurrentLineEditChanged = false;
   749 }
   753 }
   750 
   754 
   751 /*!
   755 /*!
   752     Sets the edit changed flag to indicate that user has edited the field
   756     Sets the edit changed flag to indicate that user has edited the field
   753 
       
   754     \param text Reference to the text value in the line edit box.
   757     \param text Reference to the text value in the line edit box.
   755 */
   758 */
   756 void NmIpsSettingsHelper::incomingMailServerTextChange(const QString &text)
   759 void NmIpsSettingsHelper::incomingMailServerTextChange(const QString &text)
   757 {
   760 {
   758     Q_UNUSED(text);
   761     Q_UNUSED(text);
   773     mCurrentLineEditChanged = false;
   776     mCurrentLineEditChanged = false;
   774 }
   777 }
   775 
   778 
   776 /*!
   779 /*!
   777     Sets the edit changed flag to indicate that user has edited the field
   780     Sets the edit changed flag to indicate that user has edited the field
   778 
       
   779     \param text Reference to the text value in the line edit box.
   781     \param text Reference to the text value in the line edit box.
   780 */
   782 */
   781 void NmIpsSettingsHelper::outgoingMailServerTextChange(const QString &text)
   783 void NmIpsSettingsHelper::outgoingMailServerTextChange(const QString &text)
   782 {
   784 {
   783     Q_UNUSED(text);
   785     Q_UNUSED(text);
   785 }
   787 }
   786 
   788 
   787 /*!
   789 /*!
   788     Saves the incoming port value into database if user has changed the value. If the user wish to
   790     Saves the incoming port value into database if user has changed the value. If the user wish to
   789     define the port, a input dialog is shown.
   791     define the port, a input dialog is shown.
   790     
       
   791     \param index Used to determine if the default value or a user defined value should be written
   792     \param index Used to determine if the default value or a user defined value should be written
   792 */
   793 */
   793 void NmIpsSettingsHelper::incomingPortChange(int index)
   794 void NmIpsSettingsHelper::incomingPortChange(int index)
   794 {
   795 {
   795     if (mRadioButtonPreviousIndex != index && index == IpsServices::NmIpsSettingsDefault) {
   796     if (mRadioButtonPreviousIndex != index && index == IpsServices::NmIpsSettingsDefault) {
   801         showIncomingPortInputDialog();
   802         showIncomingPortInputDialog();
   802     }
   803     }
   803 }
   804 }
   804 
   805 
   805 /*!
   806 /*!
   806     Show a input dialog for allowing the user to specify a incoming port.
   807     Shows an input dialog for allowing the user to specify a incoming port.
   807 */
   808 */
   808 void NmIpsSettingsHelper::showIncomingPortInputDialog()
   809 void NmIpsSettingsHelper::showIncomingPortInputDialog()
   809 {    
   810 {    
   810     // User can open the dialog multiple times, so delete the old ones first.
   811     // User can open the dialog multiple times, so delete the old ones first.
   811     delete mIncomingPortInputDialog;
   812     delete mIncomingPortInputDialog;
   826     
   827     
   827     mIncomingPortInputDialog->open(this, SLOT(handleUserDefinedIncomingPortInput(HbAction *)));
   828     mIncomingPortInputDialog->open(this, SLOT(handleUserDefinedIncomingPortInput(HbAction *)));
   828 }
   829 }
   829 
   830 
   830 /*!
   831 /*!
   831    Handels the saving of the port new value.
   832    Handles the saving of the port new value.
   832 */
   833 */
   833 void NmIpsSettingsHelper::handleUserDefinedIncomingPortInput(HbAction *action)
   834 void NmIpsSettingsHelper::handleUserDefinedIncomingPortInput(HbAction *action)
   834 {
   835 {
   835     if (action == mIncomingPortInputDialog->primaryAction()) {
   836     if (action == mIncomingPortInputDialog->actions().at(0)) {
   836         QVariant newPort = mIncomingPortInputDialog->value();
   837         QVariant newPort = mIncomingPortInputDialog->value();
   837         emit goOffline(mSettingsManager.mailboxId());
   838         emit goOffline(mSettingsManager.mailboxId());
   838         mEmitOnline = true;
   839         mEmitOnline = true;
   839         mSettingsManager.writeSetting(IpsServices::IncomingPort, newPort);
   840         mSettingsManager.writeSetting(IpsServices::IncomingPort, newPort);
   840     } else {
   841     } else {
   844     }
   845     }
   845 }
   846 }
   846 
   847 
   847 /*!
   848 /*!
   848     Used for getting the index to display in the port radio button list 
   849     Used for getting the index to display in the port radio button list 
   849     
       
   850     \return index Used to set the selected value
   850     \return index Used to set the selected value
   851 */
   851 */
   852 int NmIpsSettingsHelper::getCorrectPortRadioButtonIndex(int currentPort)
   852 int NmIpsSettingsHelper::getCorrectPortRadioButtonIndex(int currentPort)
   853 {
   853 {
   854     int index = 0;
   854     int index = 0;
   861     return index;
   861     return index;
   862 }
   862 }
   863 
   863 
   864 /*!
   864 /*!
   865     Sets the previous index value to indicate that user has edited the field
   865     Sets the previous index value to indicate that user has edited the field
   866 
       
   867     \param text Reference to the item in the radio button list.
   866     \param text Reference to the item in the radio button list.
   868 */
   867 */
   869 void NmIpsSettingsHelper::incomingPortPress(const QModelIndex &index)
   868 void NmIpsSettingsHelper::incomingPortPress(const QModelIndex &index)
   870 {
   869 {
   871     Q_UNUSED(index);
   870     Q_UNUSED(index);
   911         }
   910         }
   912     }
   911     }
   913 }
   912 }
   914 
   913 
   915 /*!
   914 /*!
   916     Sets the previous index value to indicate that user has edited the field
   915     Sets the previous index value to indicate that user has edited the field.
   917 
       
   918     \param text Reference to the item in the radio button list.
   916     \param text Reference to the item in the radio button list.
   919 */
   917 */
   920 void NmIpsSettingsHelper::incomingSecureConnectionPress(const QModelIndex &index)
   918 void NmIpsSettingsHelper::incomingSecureConnectionPress(const QModelIndex &index)
   921 {
   919 {
   922 	Q_UNUSED(index);
   920 	Q_UNUSED(index);
   924     QVariant data = item->contentWidgetData(QString("selected"));
   922     QVariant data = item->contentWidgetData(QString("selected"));
   925     mRadioButtonPreviousIndex = data.toInt();
   923     mRadioButtonPreviousIndex = data.toInt();
   926 }
   924 }
   927 
   925 
   928 /*!
   926 /*!
   929     Used for getting the index to display in the secure connection radio button list 
   927     Used for getting the index to display in the secure connection radio button list.
   930     
       
   931     \return index Used to set the selected value
   928     \return index Used to set the selected value
   932 */
   929 */
   933 int NmIpsSettingsHelper::getCorrectSecureRadioButtonIndex(QVariant secureSockets, 
   930 int NmIpsSettingsHelper::getCorrectSecureRadioButtonIndex(QVariant secureSockets, 
   934                                                           QVariant secureSSLWrapper)
   931                                                           QVariant secureSSLWrapper)
   935 {
   932 {
   987 */
   984 */
   988 void NmIpsSettingsHelper::handleUserDefinedFolderPathInput(HbAction *action)
   985 void NmIpsSettingsHelper::handleUserDefinedFolderPathInput(HbAction *action)
   989 {
   986 {
   990     HbDataFormModelItem *item = mContentItems.value(IpsServices::FolderPath);
   987     HbDataFormModelItem *item = mContentItems.value(IpsServices::FolderPath);
   991     
   988     
   992     if (action == mFolderPathInputDialog->primaryAction()) { 
   989     if (action == mFolderPathInputDialog->actions().at(0)) { 
   993         QVariant newFolderPath = mFolderPathInputDialog->value();
   990         QVariant newFolderPath = mFolderPathInputDialog->value();
   994         mSettingsManager.writeSetting(IpsServices::FolderPath, newFolderPath);
   991         mSettingsManager.writeSetting(IpsServices::FolderPath, newFolderPath);
   995         //set selected index to default if user inputed empty string.
   992         //set selected index to default if user inputed empty string.
   996         if (newFolderPath.toString().isEmpty()) {
   993         if (newFolderPath.toString().isEmpty()) {
   997             item->setContentWidgetData(QString("selected"), IpsServices::NmIpsSettingsDefault);
   994             item->setContentWidgetData(QString("selected"), IpsServices::NmIpsSettingsDefault);
  1029     int days(0);
  1026     int days(0);
  1030     foreach (QVariant selectedIndex, selectedIndexes) {
  1027     foreach (QVariant selectedIndex, selectedIndexes) {
  1031         days |= itemValues.at(selectedIndex.toInt()).toInt();
  1028         days |= itemValues.at(selectedIndex.toInt()).toInt();
  1032     }
  1029     }
  1033 
  1030 
  1034     handleReceivingScheduleSettingChange(IpsServices::ReceptionWeekDays, days);
  1031     QVariant previouslySelectedValue;
  1035 
  1032     mSettingsManager.readSetting(IpsServices::ReceptionWeekDays, previouslySelectedValue);
       
  1033     if (days != previouslySelectedValue.toInt()) {
       
  1034         handleReceivingScheduleSettingChange(IpsServices::ReceptionWeekDays, days);
       
  1035     }
       
  1036 
       
  1037     // Although the mode might not be changed we need to still update the button text.
  1036     // Every weekday selected.
  1038     // Every weekday selected.
  1037     if (days == 0x7f) {
  1039     if (days == 0x7f) {
  1038         item->setContentWidgetData(QString("text"),
  1040         item->setContentWidgetData(QString("text"),
  1039             hbTrId("txt_mailips_setlabel_download_images_val_every_day"));
  1041             hbTrId("txt_mailips_setlabel_download_images_val_every_day"));
  1040     }
  1042     }
  1041 }
  1043 }
  1042 
  1044 
  1043 /*!
  1045 /*!
  1044     Handles start time modifications.
  1046     Handles start time modifications.
  1045 	
       
  1046     \param time Modified start time.
  1047     \param time Modified start time.
  1047 */
  1048 */
  1048 void NmIpsSettingsHelper::startTimeModified(QTime time)
  1049 void NmIpsSettingsHelper::startTimeModified(QTime time)
  1049 {
  1050 {
  1050     int startTime(time.hour()*60 + time.minute());
  1051     int startTime(time.hour()*60 + time.minute());
  1051     handleReceivingScheduleSettingChange(IpsServices::ReceptionDayStartTime, startTime);
  1052     QVariant previouslySelectedStartTime;
       
  1053     mSettingsManager.readSetting(IpsServices::ReceptionDayStartTime, previouslySelectedStartTime);
       
  1054     if (startTime != previouslySelectedStartTime.toInt()) {
       
  1055         handleReceivingScheduleSettingChange(IpsServices::ReceptionDayStartTime, startTime);
       
  1056     }
  1052 }
  1057 }
  1053 
  1058 
  1054 /*!
  1059 /*!
  1055     Handles refresh period modifications.
  1060     Handles refresh period modifications.
  1056 
  1061     \param value Selected value as a text.
  1057     \param index selected item index.
  1062 */
  1058 */
  1063 void NmIpsSettingsHelper::refreshPeriodModified(QPersistentModelIndex, QVariant value)
  1059 void NmIpsSettingsHelper::refreshPeriodModified(int index)
  1064 {
  1060 {
  1065     QMap<QString, int> conversionTable;
  1061     HbDataFormModelItem* item = mContentItems.value(IpsServices::ReceptionRefreshPeriodDayTime);
  1066     conversionTable[hbTrId("txt_mailips_setlabel_val_keep_uptodate")] = 5;
  1062     QVariant itemData = item->data(HbDataFormModelItem::DescriptionRole + 1);
  1067     conversionTable[hbTrId("txt_mailips_setlabel_val_every_15_minutes")] = 15;
  1063     int selectedValue = itemData.value< QList< QVariant > >().at(index).toInt();
  1068     conversionTable[hbTrId("txt_mailips_setlabel_val_every_1_hour")] = 60;
  1064     handleReceivingScheduleSettingChange(IpsServices::ReceptionRefreshPeriodDayTime, selectedValue);
  1069     conversionTable[hbTrId("txt_mailips_setlabel_val_every_4_hours")] = 240;
       
  1070 
       
  1071     int selectedValue(conversionTable.value(value.toString()));
       
  1072     QVariant previouslySelectedValue;
       
  1073     mSettingsManager.readSetting(IpsServices::ReceptionRefreshPeriodDayTime,
       
  1074         previouslySelectedValue);
       
  1075     if (selectedValue != previouslySelectedValue.toInt()) {
       
  1076         handleReceivingScheduleSettingChange(IpsServices::ReceptionRefreshPeriodDayTime,
       
  1077             selectedValue);
       
  1078     }
  1065 }
  1079 }
  1066 
  1080 
  1067 /*!
  1081 /*!
  1068     Handles end time modifications.
  1082     Handles end time modifications.
  1069 
       
  1070     \param time Modified start time.
  1083     \param time Modified start time.
  1071 */
  1084 */
  1072 void NmIpsSettingsHelper::endTimeModified(QTime time)
  1085 void NmIpsSettingsHelper::endTimeModified(QTime time)
  1073 {
  1086 {
  1074     int endTime(time.hour()*60 + time.minute());
  1087     int endTime(time.hour()*60 + time.minute());
  1075     handleReceivingScheduleSettingChange(IpsServices::ReceptionDayEndTime, endTime);
  1088     QVariant previouslySelectedEndTime;
       
  1089     mSettingsManager.readSetting(IpsServices::ReceptionDayEndTime, previouslySelectedEndTime);
       
  1090     if (endTime != previouslySelectedEndTime) {
       
  1091         handleReceivingScheduleSettingChange(IpsServices::ReceptionDayEndTime, endTime);
       
  1092     }
  1076 }
  1093 }
  1077 
  1094 
  1078 /*!
  1095 /*!
  1079     Used for getting the index to display in the inbox path radio button list 
  1096     Used for getting the index to display in the inbox path radio button list 
  1080     
       
  1081     \return index Used to set the selected value
  1097     \return index Used to set the selected value
  1082 */
  1098 */
  1083 int NmIpsSettingsHelper::getCorrectInboxPathRadioButtonIndex(QVariant folderPath)
  1099 int NmIpsSettingsHelper::getCorrectInboxPathRadioButtonIndex(QVariant folderPath)
  1084 {
  1100 {
  1085     int index(0);
  1101     int index(0);
  1093 
  1109 
  1094 /*!
  1110 /*!
  1095     Handles receiving schedule item value modifications.
  1111     Handles receiving schedule item value modifications.
  1096     Takes care of creating 'user defined' mode, coping values from active profile to
  1112     Takes care of creating 'user defined' mode, coping values from active profile to
  1097     user defined mode, storing changed value and selecting 'user defined' mode.
  1113     user defined mode, storing changed value and selecting 'user defined' mode.
  1098 
       
  1099     \param settingItem Changed setting item.
  1114     \param settingItem Changed setting item.
  1100     \param settingValue Setting item's value.
  1115     \param settingValue Setting item's value.
  1101 */
  1116 */
  1102 void NmIpsSettingsHelper::handleReceivingScheduleSettingChange(
  1117 void NmIpsSettingsHelper::handleReceivingScheduleSettingChange(
  1103     IpsServices::SettingItem settingItem, const QVariant &settingValue)
  1118     IpsServices::SettingItem settingItem, const QVariant &settingValue)
  1126     HbDataFormModelItem *syncProfile = contentItem(IpsServices::ReceptionActiveProfile);
  1141     HbDataFormModelItem *syncProfile = contentItem(IpsServices::ReceptionActiveProfile);
  1127     syncProfile->setContentWidgetData(QString("currentIndex"), 3);
  1142     syncProfile->setContentWidgetData(QString("currentIndex"), 3);
  1128 }
  1143 }
  1129 
  1144 
  1130 /*!
  1145 /*!
       
  1146      Return the localized name for network destination with id of \a identifier.
       
  1147      \param identifier Network destination identifier.
       
  1148      \return Name of the network destination.
       
  1149  */
       
  1150 QString NmIpsSettingsHelper::destinationNameFromIdentifier(uint identifier)
       
  1151 {
       
  1152     const QString snapPrefix("S_");
       
  1153 
       
  1154     QNetworkConfigurationManager netMan;
       
  1155     QNetworkConfiguration conf = netMan.configurationFromIdentifier( snapPrefix +
       
  1156                                                                      QString::number(identifier));
       
  1157     return conf.name();
       
  1158 }
       
  1159 
       
  1160 /*!
  1131     Copies receiving schedule settings from currently active profile to given profile.
  1161     Copies receiving schedule settings from currently active profile to given profile.
  1132 
       
  1133     \param profileMode Mode where receiving schedule settings from active profile are copied to.
  1162     \param profileMode Mode where receiving schedule settings from active profile are copied to.
  1134 */
  1163 */
  1135 void NmIpsSettingsHelper::copyReceivingScheduleSettingsFromActiveProfile(int profileMode)
  1164 void NmIpsSettingsHelper::copyReceivingScheduleSettingsFromActiveProfile(int profileMode)
  1136 {
  1165 {
  1137     // Read receiving schedule dynamic group item values and
  1166     // Read receiving schedule dynamic group item values and
  1153     }
  1182     }
  1154 }
  1183 }
  1155 /*!
  1184 /*!
  1156     Saves the outgoing port value into database if user has changed the value. If the user wish to
  1185     Saves the outgoing port value into database if user has changed the value. If the user wish to
  1157     define the port, a input dialog is shown.
  1186     define the port, a input dialog is shown.
  1158 
       
  1159     \param index Used to determine if the default value or a user defined value should be written
  1187     \param index Used to determine if the default value or a user defined value should be written
  1160 */
  1188 */
  1161 void NmIpsSettingsHelper::outgoingPortChange(int index)
  1189 void NmIpsSettingsHelper::outgoingPortChange(int index)
  1162 {
  1190 {
  1163     if (mRadioButtonPreviousIndex != index && index == IpsServices::NmIpsSettingsDefault) {
  1191     if (mRadioButtonPreviousIndex != index && index == IpsServices::NmIpsSettingsDefault) {
  1169         showOutgoingPortInputDialog();
  1197         showOutgoingPortInputDialog();
  1170     }
  1198     }
  1171 }
  1199 }
  1172 
  1200 
  1173 /*!
  1201 /*!
  1174     Show a input dialog for allowing the user to specify a outgoing port.
  1202     Shows an input dialog for allowing the user to specify a outgoing port.
  1175 
       
  1176 */
  1203 */
  1177 void NmIpsSettingsHelper::showOutgoingPortInputDialog()
  1204 void NmIpsSettingsHelper::showOutgoingPortInputDialog()
  1178 {
  1205 {
  1179     // User can open the dialog multiple times, so delete the old ones first.
  1206     // User can open the dialog multiple times, so delete the old ones first.
  1180     delete mOutgoingPortInputDialog;
  1207     delete mOutgoingPortInputDialog;
  1195     
  1222     
  1196     mOutgoingPortInputDialog->open(this, SLOT(handleUserDefinedOutgoingPortInput(HbAction *)));
  1223     mOutgoingPortInputDialog->open(this, SLOT(handleUserDefinedOutgoingPortInput(HbAction *)));
  1197 }
  1224 }
  1198 
  1225 
  1199 /*!
  1226 /*!
  1200     Handels the saving of the port new value.
  1227     Handles the saving of the port new value.
       
  1228     \action Selected action.
  1201 */
  1229 */
  1202 void NmIpsSettingsHelper::handleUserDefinedOutgoingPortInput(HbAction *action)
  1230 void NmIpsSettingsHelper::handleUserDefinedOutgoingPortInput(HbAction *action)
  1203 {
  1231 {
  1204     if (action == mOutgoingPortInputDialog->primaryAction()) {
  1232     if (action == mOutgoingPortInputDialog->actions().at(0)) {
  1205         QVariant newPort = mOutgoingPortInputDialog->value();
  1233         QVariant newPort = mOutgoingPortInputDialog->value();
  1206         emit goOffline(mSettingsManager.mailboxId());
  1234         emit goOffline(mSettingsManager.mailboxId());
  1207         mEmitOnline = true;
  1235         mEmitOnline = true;
  1208         mSettingsManager.writeSetting(IpsServices::OutgoingPort, newPort);
  1236         mSettingsManager.writeSetting(IpsServices::OutgoingPort, newPort);
  1209     } else {
  1237     } else {
  1212         item->setContentWidgetData(QString("selected"), mRadioButtonPreviousIndex);
  1240         item->setContentWidgetData(QString("selected"), mRadioButtonPreviousIndex);
  1213     }
  1241     }
  1214 }
  1242 }
  1215 
  1243 
  1216 /*!
  1244 /*!
  1217     Sets the previous index value to indicate that user has edited the field
  1245     Handles the saving of the selected network connection.
  1218 
  1246     \param status Dialog exit status \sa CmApplSettingsUi::ApplSettingsError.
       
  1247 */
       
  1248 void NmIpsSettingsHelper::handleConnectionSelected(uint status)
       
  1249 {
       
  1250     if (status == CmApplSettingsUi::ApplSettingsErrorNone) {
       
  1251         CmApplSettingsUi::SettingSelection selection = mDestinationDialog->selection();
       
  1252         uint destId(selection.id);
       
  1253         if (mSettingsManager.writeSetting(IpsServices::Connection, QVariant(destId))) {
       
  1254             QString destName(destinationNameFromIdentifier(destId));
       
  1255             HbDataFormModelItem *item = mContentItems.value(IpsServices::Connection);
       
  1256             item->setContentWidgetData(QString("text"), destName);
       
  1257         }
       
  1258     }
       
  1259 }
       
  1260 
       
  1261 /*!
       
  1262     Sets the previous index value to indicate that user has edited the field.
  1219     \param index Reference to the item in the radio button list.
  1263     \param index Reference to the item in the radio button list.
  1220 */
  1264 */
  1221 void NmIpsSettingsHelper::outgoingPortPress(const QModelIndex &index)
  1265 void NmIpsSettingsHelper::outgoingPortPress(const QModelIndex &index)
  1222 {
  1266 {
  1223     Q_UNUSED(index);
  1267     Q_UNUSED(index);
  1225     QVariant data = item->contentWidgetData(QString("selected"));
  1269     QVariant data = item->contentWidgetData(QString("selected"));
  1226     mRadioButtonPreviousIndex = data.toInt();
  1270     mRadioButtonPreviousIndex = data.toInt();
  1227 }
  1271 }
  1228 
  1272 
  1229 /*!
  1273 /*!
  1230     Used for getting the index to display in the outgoing port radio button list
  1274     Used for getting the index to display in the outgoing port radio button list.
  1231 
  1275     \return index Used to set the selected value.
  1232     \return index Used to set the selected value
       
  1233 */
  1276 */
  1234 int NmIpsSettingsHelper::getCorrectOutgoingPortRadioButtonIndex(int currentPort)
  1277 int NmIpsSettingsHelper::getCorrectOutgoingPortRadioButtonIndex(int currentPort)
  1235 {
  1278 {
  1236     int index = 0;
  1279     int index = 0;
  1237     int port = mSettingsManager.determineDefaultOutgoingPort();
  1280     int port = mSettingsManager.determineDefaultOutgoingPort();
  1242     }
  1285     }
  1243     return index;
  1286     return index;
  1244 }
  1287 }
  1245 
  1288 
  1246 /*!
  1289 /*!
  1247     Used for getting the index to display in the outgoing authentication radio button list 
  1290     Used for getting the index to display in the outgoing authentication radio button list.
  1248     
  1291     \return index Used to set the selected value.
  1249     \return index Used to set the selected value
       
  1250 */
  1292 */
  1251 int NmIpsSettingsHelper::getCorrectOutgoingAuthenticationRadioButtonIndex()
  1293 int NmIpsSettingsHelper::getCorrectOutgoingAuthenticationRadioButtonIndex()
  1252 {
  1294 {
  1253     int index(IpsServices::EMailAuthNone);
  1295     int index(IpsServices::EMailAuthNone);
  1254     QVariant temp;
  1296     QVariant temp;
  1278     return index;
  1320     return index;
  1279 }
  1321 }
  1280 
  1322 
  1281 /*!
  1323 /*!
  1282     Saves the outgoing secure connection value into database if user has changed the value.
  1324     Saves the outgoing secure connection value into database if user has changed the value.
       
  1325     \param index Selected radio button index.
  1283 */
  1326 */
  1284 void NmIpsSettingsHelper::outgoingSecureConnectionItemChange(int index)
  1327 void NmIpsSettingsHelper::outgoingSecureConnectionItemChange(int index)
  1285 {
  1328 {
  1286     if (mRadioButtonPreviousIndex != index) {
  1329     if (mRadioButtonPreviousIndex != index) {
  1287         emit goOffline(mSettingsManager.mailboxId());
  1330         emit goOffline(mSettingsManager.mailboxId());
  1315         }
  1358         }
  1316     }
  1359     }
  1317 }
  1360 }
  1318 
  1361 
  1319 /*!
  1362 /*!
  1320     Sets the previous index value to indicate that user has edited the field
  1363     Sets the previous index value to indicate that user has edited the field.
  1321 
  1364     \param index Reference to the item in the radio button list.
  1322     \param text Reference to the item in the radio button list.
       
  1323 */
  1365 */
  1324 void NmIpsSettingsHelper::outgoingSecureConnectionPress(const QModelIndex &index)
  1366 void NmIpsSettingsHelper::outgoingSecureConnectionPress(const QModelIndex &index)
  1325 {
  1367 {
  1326 	Q_UNUSED(index);
  1368 	Q_UNUSED(index);
  1327 	HbDataFormModelItem *item = mContentItems.value(IpsServices::OutgoingSecureSockets);
  1369 	HbDataFormModelItem *item = mContentItems.value(IpsServices::OutgoingSecureSockets);
  1330 }
  1372 }
  1331 
  1373 
  1332 /*!
  1374 /*!
  1333     Saves the outgoing authetication value into database if user has changed the value and
  1375     Saves the outgoing authetication value into database if user has changed the value and
  1334     updates dynamic group items.
  1376     updates dynamic group items.
       
  1377     \param index Selected radio button index.
  1335 */
  1378 */
  1336 void NmIpsSettingsHelper::outgoingAuthenticationChange(int index)
  1379 void NmIpsSettingsHelper::outgoingAuthenticationChange(int index)
  1337 {
  1380 {
  1338     if (mRadioButtonPreviousIndex != index) {
  1381     if (mRadioButtonPreviousIndex != index) {
  1339         QVariant loginName;
  1382         QVariant loginName;
  1367         }
  1410         }
  1368     }
  1411     }
  1369 }
  1412 }
  1370 
  1413 
  1371 /*!
  1414 /*!
  1372     Sets the previous index value to indicate that user has edited the field
  1415     Sets the previous index value to indicate that user has edited the field.
  1373 
  1416     \param index Reference to the item in the radio button list.
  1374     \param text Reference to the item in the radio button list.
       
  1375 */
  1417 */
  1376 void NmIpsSettingsHelper::outgoingAuthenticationPress(const QModelIndex &index)
  1418 void NmIpsSettingsHelper::outgoingAuthenticationPress(const QModelIndex &index)
  1377 {
  1419 {
  1378     Q_UNUSED(index);
  1420     Q_UNUSED(index);
  1379     HbDataFormModelItem *item = mContentItems.value(IpsServices::SMTPAuthentication);
  1421     HbDataFormModelItem *item = mContentItems.value(IpsServices::SMTPAuthentication);
  1380     QVariant data = item->contentWidgetData(QString("selected"));
  1422     QVariant data = item->contentWidgetData(QString("selected"));
  1381     mRadioButtonPreviousIndex = data.toInt();
  1423     mRadioButtonPreviousIndex = data.toInt();
  1382 }
  1424 }
  1383 
  1425 
       
  1426 /*!
       
  1427     Launches the connection selection dialog.
       
  1428 */
       
  1429 void NmIpsSettingsHelper::connectionButtonPress()
       
  1430 {
       
  1431     if (!mDestinationDialog) {
       
  1432         // Create the dialog and configure it.
       
  1433         mDestinationDialog = new CmApplSettingsUi(this);
       
  1434 
       
  1435         mDestinationDialog->setOptions(
       
  1436             QFlags<CmApplSettingsUi::SelectionDialogItems>(CmApplSettingsUi::ShowDestinations),
       
  1437             QSet<CmApplSettingsUi::BearerTypeFilter>());
       
  1438         connect(mDestinationDialog, SIGNAL(finished(uint)),
       
  1439                 this, SLOT(handleConnectionSelected(uint)));
       
  1440     }
       
  1441 
       
  1442     // Set currently active destination as selected.
       
  1443     QVariant destId;
       
  1444     if (mSettingsManager.readSetting(IpsServices::Connection, destId)) {
       
  1445         CmApplSettingsUi::SettingSelection selection;
       
  1446         selection.result = CmApplSettingsUi::SelectionTypeDestination;
       
  1447         selection.id = destId.toUInt();
       
  1448         mDestinationDialog->setSelection(selection);
       
  1449     }
       
  1450 
       
  1451     // Open the dialog.
       
  1452     mDestinationDialog->open();
       
  1453 }