ipsservices/nmipssettings/src/nmipssettingsplugin.cpp
changeset 30 759dc5235cdb
parent 23 2dc6caa42ec3
child 44 c2d07d913565
equal deleted inserted replaced
27:9ba4404ef423 30:759dc5235cdb
    13 *
    13 *
    14 * Description:
    14 * Description:
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 #include <hbdataform.h>
       
    19 #include <hbdataformmodel.h>
       
    20 #include <hbdataformmodelitem.h>
       
    21 #include <hblineedit.h>
       
    22 #include <cpsettingformitemdata.h>
       
    23 #include <qplugin.h>
    18 #include <qplugin.h>
    24 #include <QCoreApplication>
    19 #include <QCoreApplication>
    25 #include <QTranslator>
    20 #include <QTranslator>
    26 #include <QScopedPointer>
    21 #include <QScopedPointer>
    27 #include <QLocale>
    22 #include <QLocale>
       
    23 
    28 #include <HbStringUtil>
    24 #include <HbStringUtil>
       
    25 #include <HbDataForm>
       
    26 #include <HbDataFormModel>
       
    27 #include <HbDataFormModelItem>
       
    28 #include <HbLineEdit>
       
    29 
       
    30 #include <cpsettingformitemdata.h>
    29 
    31 
    30 #include "nmipssettingsplugin.h"
    32 #include "nmipssettingsplugin.h"
    31 #include "nmipssettingshelper.h"
    33 #include "nmipssettingshelper.h"
    32 #include "nmipssettingsmanagerbase.h"
    34 #include "nmipssettingsmanagerbase.h"
    33 #include "nmipssettingsmanagerfactory.h"
    35 #include "nmipssettingsmanagerfactory.h"
    39 #include "nmipssettingslabeledcombobox.h"
    41 #include "nmipssettingslabeledcombobox.h"
    40 
    42 
    41 const QString NmIpsSettingsComboItems("comboItems");
    43 const QString NmIpsSettingsComboItems("comboItems");
    42 const QString NmIpsSettingsLabelTexts("labelTexts");
    44 const QString NmIpsSettingsLabelTexts("labelTexts");
    43 const QString NmIpsSettingsItems("items");
    45 const QString NmIpsSettingsItems("items");
       
    46 const int NmIpsSettingsReceptionUserDefinedProfileEnabled(1);
    44 
    47 
    45 /*!
    48 /*!
    46     \class NmIpsSettingsPlugin
    49     \class NmIpsSettingsPlugin
    47     \brief The class implements NmSettingsPluginInterface which is an interface
    50     \brief The class implements NmSettingsPluginInterface which is an interface
    48            for NMail settings plug-ins.
    51            for NMail settings plug-ins.
    61     QString lang = QLocale::system().name();
    64     QString lang = QLocale::system().name();
    62     QString path = "Z:/resource/qt/translations/";
    65     QString path = "Z:/resource/qt/translations/";
    63     QString appName = "mailips_";
    66     QString appName = "mailips_";
    64     QString commonName = "common_";
    67     QString commonName = "common_";
    65     
    68     
    66 
       
    67     // Load common strings
    69     // Load common strings
    68 	QScopedPointer<QTranslator> commonTranslator(new QTranslator(this));
    70 	QScopedPointer<QTranslator> commonTranslator(new QTranslator(this));
    69     commonTranslator->load(commonName + lang, path);
    71     commonTranslator->load(commonName + lang, path);
    70     QCoreApplication::installTranslator(commonTranslator.data());
    72     QCoreApplication::installTranslator(commonTranslator.data());
    71     (void)commonTranslator.take();  
    73     (void)commonTranslator.take();  
    94     \return <code>true</code> if plug-in contains certain mailbox otherwise <code>false</code>
    96     \return <code>true</code> if plug-in contains certain mailbox otherwise <code>false</code>
    95 */
    97 */
    96 bool NmIpsSettingsPlugin::populateModel(HbDataFormModel &model,
    98 bool NmIpsSettingsPlugin::populateModel(HbDataFormModel &model,
    97     HbDataForm &form, const NmId &mailboxId)
    99     HbDataForm &form, const NmId &mailboxId)
    98 {
   100 {
       
   101     // Turns AlwaysOnline OFF
       
   102     setAlwaysOnlineState(EServerAPIEmailTurnOff, mailboxId);
       
   103     
    99     // Store model and form pointers.
   104     // Store model and form pointers.
   100     mModel = &model;
   105     mModel = &model;
   101     mForm = &form;
   106     mForm = &form;
   102 
   107 
   103     // populateModel is called each time when a new settings view is created and this
   108     // populateModel is called each time when a new settings view is created and this
   131 
   136 
   132         // Add items to the model.
   137         // Add items to the model.
   133         initGroupItems();
   138         initGroupItems();
   134         result = true;
   139         result = true;
   135     }
   140     }
   136     
       
   137     return result;
   141     return result;
   138 }
   142 }
   139 
   143 
   140 /*!
   144 /*!
   141     This slot can be used in cases when plugin needs to handle stuff before settingsview is closed.
   145     This slot can be used in cases when plugin needs to handle stuff before settingsview is closed.
   142 */
   146 */
   143 void NmIpsSettingsPlugin::aboutToClose()
   147 void NmIpsSettingsPlugin::aboutToClose()
   144 {
   148 {
   145     QVariant profileIndex;
   149     QVariant profileIndex;
       
   150     const NmId mailboxId = mSettingsManager->mailboxId();
       
   151     
   146 	mSettingsManager->readSetting(IpsServices::ReceptionActiveProfile, profileIndex);
   152 	mSettingsManager->readSetting(IpsServices::ReceptionActiveProfile, profileIndex);
   147 	if ((mSettingsHelper->isOffline()) && (profileIndex.toInt() != IpsServices::EmailSyncProfileManualFetch)) {
   153 	if ((mSettingsHelper->isOffline()) && (profileIndex.toInt() != IpsServices::EmailSyncProfileManualFetch)) {
   148 		emit goOnline(mSettingsManager->mailboxId());
   154 		emit goOnline(mailboxId);
   149 	}
   155 	}
       
   156 	
       
   157 	// Turns AlwaysOnline ON
       
   158 	setAlwaysOnlineState(EServerAPIEmailTurnOn, mailboxId);
   150 }
   159 }
   151 
   160 
   152 /*!
   161 /*!
   153     Appends the group items to the model.
   162     Appends the group items to the model.
   154 */
   163 */
   201     Appends the preferences items to the group item.
   210     Appends the preferences items to the group item.
   202     \param item Reference to the parent group item.
   211     \param item Reference to the parent group item.
   203 */
   212 */
   204 void NmIpsSettingsPlugin::initPreferenceItems(HbDataFormModelItem &item) const
   213 void NmIpsSettingsPlugin::initPreferenceItems(HbDataFormModelItem &item) const
   205 {
   214 {
   206     // 1. My Name
   215 
       
   216     // 1. Connection
       
   217     QVariant destId;
       
   218 
       
   219     mSettingsManager->readSetting(IpsServices::Connection, destId);
       
   220     QString destName(mSettingsHelper->destinationNameFromIdentifier(destId.toUInt()));
       
   221     HbDataFormModelItem::DataItemType buttonItem =
       
   222         static_cast<HbDataFormModelItem::DataItemType>(
       
   223             HbDataFormModelItem::CustomItemBase + 2);
       
   224     CpSettingFormItemData *connectionButtonItem = new CpSettingFormItemData(buttonItem,
       
   225         hbTrId("txt_mailips_setlabel_connection"));
       
   226     connectionButtonItem->setContentWidgetData(QString("text"), destName);
       
   227     mSettingsHelper->insertContentItem(IpsServices::Connection, connectionButtonItem);
       
   228     mForm->addConnection(connectionButtonItem, SIGNAL(clicked()),
       
   229                          mSettingsHelper, SLOT(connectionButtonPress()));
       
   230     item.appendChild(connectionButtonItem);
       
   231 
       
   232     // 2. My Name
   207     QVariant myName;
   233     QVariant myName;
   208     mSettingsManager->readSetting(IpsServices::EmailAlias, myName);
   234     mSettingsManager->readSetting(IpsServices::EmailAlias, myName);
   209     CpSettingFormItemData *myNameItem = new CpSettingFormItemData(
   235     CpSettingFormItemData *myNameItem = new CpSettingFormItemData(
   210         HbDataFormModelItem::TextItem, hbTrId("txt_mailips_setlabel_my_name"));
   236         HbDataFormModelItem::TextItem, hbTrId("txt_mailips_setlabel_my_name"));
   211     mSettingsHelper->insertContentItem(IpsServices::EmailAlias, myNameItem);
   237     mSettingsHelper->insertContentItem(IpsServices::EmailAlias, myNameItem);
   214                          mSettingsHelper, SLOT(saveMyName()));
   240                          mSettingsHelper, SLOT(saveMyName()));
   215     mForm->addConnection(myNameItem, SIGNAL(textChanged(QString)),
   241     mForm->addConnection(myNameItem, SIGNAL(textChanged(QString)),
   216                          mSettingsHelper, SLOT(myNameTextChange(QString)));
   242                          mSettingsHelper, SLOT(myNameTextChange(QString)));
   217     item.appendChild(myNameItem);
   243     item.appendChild(myNameItem);
   218 
   244 
   219     // 2. Mailbox Name
   245     // 3. Mailbox Name
   220     QVariant mailboxName;
   246     QVariant mailboxName;
   221     mSettingsManager->readSetting(IpsServices::MailboxName, mailboxName);
   247     mSettingsManager->readSetting(IpsServices::MailboxName, mailboxName);
   222     CpSettingFormItemData *mailboxNameItem = new CpSettingFormItemData(
   248     CpSettingFormItemData *mailboxNameItem = new CpSettingFormItemData(
   223         HbDataFormModelItem::TextItem, hbTrId("txt_mailips_setlabel_mailbox_name"));
   249         HbDataFormModelItem::TextItem, hbTrId("txt_mailips_setlabel_mailbox_name"));
   224     mSettingsHelper->insertContentItem(IpsServices::MailboxName, mailboxNameItem);
   250     mSettingsHelper->insertContentItem(IpsServices::MailboxName, mailboxNameItem);
   290         new CpSettingFormItemData(HbDataFormModelItem::RadioButtonListItem, hbTrId(
   316         new CpSettingFormItemData(HbDataFormModelItem::RadioButtonListItem, hbTrId(
   291             "txt_mailips_setlabel_show_mail_in_inbox"));
   317             "txt_mailips_setlabel_show_mail_in_inbox"));
   292 
   318 
   293     mSettingsHelper->insertContentItem(IpsServices::ReceptionInboxSyncWindow, showMailInInboxItem);
   319     mSettingsHelper->insertContentItem(IpsServices::ReceptionInboxSyncWindow, showMailInInboxItem);
   294 
   320 
       
   321     // If changes are made to showMailItems, conversion table in
       
   322     // showMailInInboxModified method needs to be updated also.
   295     QStringList showMailItems;
   323     QStringList showMailItems;
   296     showMailItems << HbStringUtil::convertDigits("50")
   324     showMailItems << HbStringUtil::convertDigits("50")
   297                   << HbStringUtil::convertDigits("100")
   325                   << HbStringUtil::convertDigits("100")
   298                   << HbStringUtil::convertDigits("500")
   326                   << HbStringUtil::convertDigits("500")
   299                   << hbTrId("txt_mailips_setlabel_val_all");
   327                   << hbTrId("txt_mailips_setlabel_val_all");
   300     
   328     
   301 
       
   302     QList<QVariant> showMailItemValues;
       
   303     showMailItemValues << 50
       
   304                        << 100
       
   305                        << 500
       
   306                        << 0;
       
   307     
       
   308     QVariant value(showMailItemValues);
       
   309     showMailInInboxItem->setData(HbDataFormModelItem::DescriptionRole + 1, value);
       
   310     showMailInInboxItem->setContentWidgetData(NmIpsSettingsItems, showMailItems);
   329     showMailInInboxItem->setContentWidgetData(NmIpsSettingsItems, showMailItems);
   311     showMailInInboxItem->setEnabled(true);
   330     showMailInInboxItem->setEnabled(true);
   312     item.appendChild(showMailInInboxItem);
   331     item.appendChild(showMailInInboxItem);
   313 
   332 
   314     // Active sync profile connection
   333     // Active sync profile connection
   315     mForm->addConnection(infoItem, SIGNAL(currentIndexChanged(int)),
   334     mForm->addConnection(infoItem, SIGNAL(currentIndexChanged(int)),
   316         mSettingsHelper, SLOT(receivingScheduleChange(int)));
   335         mSettingsHelper, SLOT(receivingScheduleChange(int)));
   317 
   336 
   318     mForm->addConnection(showMailInInboxItem, SIGNAL(itemSelected(int)),
   337     mForm->addConnection(showMailInInboxItem, SIGNAL(valueChanged(QPersistentModelIndex, QVariant)),
   319         this, SLOT(showMailInInboxModified(int)));
   338         this, SLOT(showMailInInboxModified(QPersistentModelIndex, QVariant)));
   320 
   339 
   321     // Must be called manually here, because the signal->slot connection set above using
   340     // Must be called manually here, because the signal->slot connection set above using
   322     // HbDataForm::addConnection() is actually established AFTER the properties have first been
   341     // HbDataForm::addConnection() is actually established AFTER the properties have first been
   323     // set to the widget, causing the first currentIndexChanged signal not to reach
   342     // set to the widget, causing the first currentIndexChanged signal not to reach
   324     // NmIpsSettingsHelper::receivingScheduleChange().
   343     // NmIpsSettingsHelper::receivingScheduleChange().
   552         item.appendChild(folderPathItem);
   571         item.appendChild(folderPathItem);
   553     }
   572     }
   554 }
   573 }
   555 
   574 
   556 /*!
   575 /*!
       
   576     Sets the state of the AlwaysOnline.
       
   577     \param command Command for the state of the AlwaysOnline.
       
   578     \param mailboxId Mailbox id.
       
   579 */
       
   580 void NmIpsSettingsPlugin::setAlwaysOnlineState(TAlwaysOnlineServerAPICommands command,
       
   581                                                NmId mailboxId) const
       
   582 {
       
   583     RAlwaysOnlineClientSession aosession;
       
   584     TInt err(aosession.Connect());
       
   585     
       
   586     if (err == KErrNone) {
       
   587         TPckgBuf<TMsvId> mboxBuf(mailboxId.id32());
       
   588         
       
   589         TRAP_IGNORE(aosession.RelayCommandL(command, mboxBuf));
       
   590     }
       
   591     
       
   592     aosession.Close();
       
   593 }
       
   594 
       
   595 /*!
   557     Creates user defined mode if not already exist.
   596     Creates user defined mode if not already exist.
   558 */
   597 */
   559 void NmIpsSettingsPlugin::createUserDefinedMode()
   598 void NmIpsSettingsPlugin::createUserDefinedMode()
   560 {
   599 {
   561     QVariant userDefineMode;
   600     QVariant userDefineMode;
   586 
   625 
   587         // Reconnect signal, so that helper is aware of data modifications.
   626         // Reconnect signal, so that helper is aware of data modifications.
   588         mForm->addConnection(syncProfile, SIGNAL(currentIndexChanged(int)),
   627         mForm->addConnection(syncProfile, SIGNAL(currentIndexChanged(int)),
   589             mSettingsHelper, SLOT(receivingScheduleChange(int)));
   628             mSettingsHelper, SLOT(receivingScheduleChange(int)));
   590 
   629 
   591         // Mark that user defined mode exists.
   630         // Set reception user defined profile enabled.
   592         userDefineMode.setValue(1);
   631         userDefineMode.setValue(NmIpsSettingsReceptionUserDefinedProfileEnabled);
   593         mSettingsManager->writeSetting(IpsServices::ReceptionUserDefinedProfile, userDefineMode);
   632         mSettingsManager->writeSetting(IpsServices::ReceptionUserDefinedProfile, userDefineMode);
   594     }
   633     }
   595 }
   634 }
   596 
   635 
   597 /*!
   636 /*!
   598     Handles mail in inbox modifications.
   637     Handles mail in inbox modifications.
   599 
   638 
   600     \param index Selected value index.
   639     \param value Selected value as a text.
   601 */
   640 */
   602 void NmIpsSettingsPlugin::showMailInInboxModified(int index)
   641 void NmIpsSettingsPlugin::showMailInInboxModified(QPersistentModelIndex, QVariant value)
   603 {
   642 {
   604     HbDataFormModelItem* item = mSettingsHelper->contentItem(IpsServices::ReceptionInboxSyncWindow);
   643     QMap<QString, int> conversionTable;
   605     QVariant itemData = item->data(HbDataFormModelItem::HbDataFormModelItem::DescriptionRole + 1);
   644     conversionTable[HbStringUtil::convertDigits("50")] = 50;
   606     int selectedValue = itemData.value< QList< QVariant > >().at(index).toInt();
   645     conversionTable[HbStringUtil::convertDigits("100")] = 100;
   607     mSettingsHelper->handleReceivingScheduleSettingChange(
   646     conversionTable[HbStringUtil::convertDigits("500")] = 500;
   608         IpsServices::ReceptionInboxSyncWindow, selectedValue);
   647     conversionTable[hbTrId("txt_mailips_setlabel_val_all")] = 0;
       
   648 
       
   649     int selectedValue(conversionTable.value(value.toString()));
       
   650     QVariant previouslySelectedValue;
       
   651     mSettingsManager->readSetting(IpsServices::ReceptionInboxSyncWindow, previouslySelectedValue);
       
   652     if (previouslySelectedValue.toInt() != selectedValue) {
       
   653         mSettingsHelper->handleReceivingScheduleSettingChange(
       
   654             IpsServices::ReceptionInboxSyncWindow, selectedValue);
       
   655     }
   609 }
   656 }
   610 
   657 
   611 Q_EXPORT_PLUGIN2(nmipssettings, NmIpsSettingsPlugin);
   658 Q_EXPORT_PLUGIN2(nmipssettings, NmIpsSettingsPlugin);