securitysettings/cpeapuiplugins/cpeapsimakaui/src/cpeapsimakaui.cpp
changeset 39 fe6b6762fccd
parent 33 938269283a16
child 52 c23bdf5a328a
equal deleted inserted replaced
38:7a0216d033ac 39:fe6b6762fccd
     1 /*
     1 /*
     2  * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
     2  * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3  * All rights reserved.
     3  * All rights reserved.
     4  * This component and the accompanying materials are made available
     4  * This component and the accompanying materials are made available
     5  * under the terms of the License "Eclipse Public License v1.0"
     5  * under the terms of "Eclipse Public License v1.0"
     6  * which accompanies this distribution, and is available
     6  * which accompanies this distribution, and is available
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     8  *
     8  *
     9  * Initial Contributors:
     9  * Initial Contributors:
    10  * Nokia Corporation - initial contribution.
    10  * Nokia Corporation - initial contribution.
    15  *   Control Panel QT UI for EAP-SIM and EAP-AKA method configuration
    15  *   Control Panel QT UI for EAP-SIM and EAP-AKA method configuration
    16  *
    16  *
    17  */
    17  */
    18 
    18 
    19 /*
    19 /*
    20  * %version:  16 %
    20  * %version:  18 %
    21  */
    21  */
    22 
    22 
    23 // System includes
    23 // System includes
    24 #include <HbDataForm>
    24 #include <HbDataForm>
    25 #include <HbDataFormModel>
    25 #include <HbDataFormModel>
    26 #include <HbDataFormViewItem>
    26 #include <HbDataFormViewItem>
       
    27 #include <HbParameterLengthLimiter>
    27 #include <HbMessageBox> 
    28 #include <HbMessageBox> 
    28 #include <HbAction>
    29 #include <HbAction>
    29 #include <HbLineEdit>
    30 #include <HbLineEdit>
    30 #include <cpsettingformitemdata.h>
    31 #include <cpsettingformitemdata.h>
    31 #include <cpitemdatahelper.h>
    32 #include <cpitemdatahelper.h>
    59 CpEapSimAkaUi::CpEapSimAkaUi(
    60 CpEapSimAkaUi::CpEapSimAkaUi(
    60     const EapQtConfigInterface::EapBearerType bearer,
    61     const EapQtConfigInterface::EapBearerType bearer,
    61     const int iapId,
    62     const int iapId,
    62     const EapQtPluginInfo &plugin,
    63     const EapQtPluginInfo &plugin,
    63     const EapQtPluginHandle& outerHandle) :
    64     const EapQtPluginHandle& outerHandle) :
    64         mConfigIf(new EapQtConfigInterface(bearer, iapId)),
    65         mConfigIf(NULL),
    65         mPluginInfo(plugin),
    66         mPluginInfo(plugin),
    66         mOuterHandle(outerHandle),
    67         mOuterHandle(outerHandle),
    67         mForm(NULL),
    68         mForm(NULL),
    68         mModel(NULL),
    69         mModel(NULL),
       
    70         mItemDataHelper(NULL),
       
    71         mGroupItem(NULL),
    69         mUsernameAutomatic(NULL),
    72         mUsernameAutomatic(NULL),
    70         mUsername(NULL),
    73         mUsername(NULL),
    71         mRealmAutomatic(NULL),
    74         mRealmAutomatic(NULL),
    72         mRealm(NULL),
    75         mRealm(NULL),
    73         mValidatorRealm(NULL),
    76         mValidatorRealm(NULL),
    80     if (iapId < 0) {
    83     if (iapId < 0) {
    81         QT_THROW(std::bad_alloc());
    84         QT_THROW(std::bad_alloc());
    82         // scoped pointer gets deleted automaticaly on exception
    85         // scoped pointer gets deleted automaticaly on exception
    83     }
    86     }
    84 
    87 
    85     initializeSimAkaUi();
    88     // Get EAP config interface
       
    89     mConfigIf.reset(new EapQtConfigInterface(bearer, iapId));
       
    90     
       
    91     createUi();
    86 }
    92 }
    87 
    93 
    88 /*!
    94 /*!
    89  * Destructor.
    95  * Destructor.
    90  */
    96  */
    95     // mValidatorRealm, mValidatorUsername
   101     // mValidatorRealm, mValidatorUsername
    96     // mConfigIf: scoped pointer deleted automatically
   102     // mConfigIf: scoped pointer deleted automatically
    97 }
   103 }
    98 
   104 
    99 /*!
   105 /*!
   100  * Initializes the sim-aka ui and initializes objects based on configuration
   106  * Creates EAP-SIM/AKA UI and initilizes settings read via
   101  * read from the database.
   107  * EapQtConfigInterface
   102  */
   108  */
   103 void CpEapSimAkaUi::initializeSimAkaUi()
   109 void CpEapSimAkaUi::createUi()
   104 {
   110 {
   105     qDebug("CpEapSimAkaUi::initializeSimAkaUi");
   111     qDebug("CpEapSimAkaUi::createUi");
   106 
   112 
   107     CpItemDataHelper itemDataHelper;
   113     // Read EAP Configurations
   108 
       
   109     // Read Configurations
       
   110     EapQtConfig eapConfig;
       
   111     bool configurationRead = mConfigIf->readConfiguration(mOuterHandle, mPluginInfo.pluginHandle(),
   114     bool configurationRead = mConfigIf->readConfiguration(mOuterHandle, mPluginInfo.pluginHandle(),
   112         eapConfig);
   115         mEapConfig);
   113     if (!configurationRead) {
   116     if (!configurationRead) {
   114         qDebug("CpEapSimAkaUi::initializeSimAkaUi - read configuration failed.");
   117         qDebug("CpEapSimAkaUi::initializeSimAkaUi - read configuration failed.");
   115     }
   118     }
   116     
   119     
   117     // Create UI objects and group 
   120     // Construct EAP-SIM/AKA settings UI 
   118     mForm = new HbDataForm();
   121     mForm = new HbDataForm();
   119     this->setWidget(mForm);
   122     this->setWidget(mForm);
       
   123     mModel = new HbDataFormModel(mForm);
       
   124 
       
   125     mGroupItem = new HbDataFormModelItem(HbDataFormModelItem::GroupItem,
       
   126         HbParameterLengthLimiter(
       
   127             hbTrId("txt_occ_subhead_eap_module_settings")).arg(
       
   128                 mPluginInfo.localizationId()));
       
   129     mModel->appendDataFormItem(mGroupItem);
       
   130 
       
   131     // The parameter given as 0 is a HbDataForm pointer, not parent
       
   132     mItemDataHelper = new CpItemDataHelper(0);
       
   133     mItemDataHelper->setParent(this);
       
   134 
       
   135     // Create UI components
       
   136     createUsername();
       
   137     createRealm();
   120     
   138     
   121     mModel = new HbDataFormModel(mForm);
   139     mItemDataHelper->bindToForm(mForm);
   122     HbDataFormModelItem *groupItem = new HbDataFormModelItem(HbDataFormModelItem::GroupItem,
   140     mForm->setModel(mModel);
   123         hbTrId("txt_occ_subhead_eap_module_settings").arg(mPluginInfo.localizationId()));
   141     
   124     mModel->appendDataFormItem(groupItem);
       
   125 
       
   126     // Connect signal to add validators when items get activated (visualization created).
   142     // Connect signal to add validators when items get activated (visualization created).
   127     bool connected = connect(mForm, SIGNAL( itemShown(const QModelIndex&) ), this,
   143     bool connected = connect(mForm, SIGNAL( itemShown(const QModelIndex&) ), this,
   128         SLOT( setValidator(const QModelIndex) ));
   144         SLOT( setValidator(const QModelIndex) ));
   129     Q_ASSERT(connected);
   145     Q_ASSERT(connected);
   130 
   146 
       
   147     // Expand EAP-SIM/AKA settings group
       
   148     mForm->setExpanded(mModel->indexFromItem(mGroupItem), true);
       
   149 }
       
   150 
       
   151 /*!
       
   152  * Creates Username group:
       
   153  * Generate automatically checkBox and username lineEdit
       
   154  */
       
   155 void CpEapSimAkaUi::createUsername()
       
   156 {
       
   157     qDebug("CpEapSimAkaUi::createUsername()");
   131     // UsernameAutomatic
   158     // UsernameAutomatic
   132     mUsernameAutomatic = new CpSettingFormItemData(HbDataFormModelItem::CheckBoxItem, hbTrId(
   159     mUsernameAutomatic = new CpSettingFormItemData(HbDataFormModelItem::CheckBoxItem, hbTrId(
   133         "txt_occ_setlabel_user_name"));
   160         "txt_occ_setlabel_user_name"));
   134     mUsernameAutomatic->setContentWidgetData("text", hbTrId(
   161     mUsernameAutomatic->setContentWidgetData("text", hbTrId(
   135         "txt_occ_setlabel_user_name_val_generate_automatica"));
   162         "txt_occ_setlabel_user_name_val_generate_automatica"));
   136     // Initialize the value from EapQtConfig
   163     // Initialize the value from EapQtConfig
   137     // Generate username automatically is selected by default
   164     // Generate username automatically is selected by default
   138     mUsernameAutomatic->setContentWidgetData("checkState", boolToCheckState(eapConfig.value(
   165     mUsernameAutomatic->setContentWidgetData("checkState", boolToCheckState(mEapConfig.value(
   139         EapQtConfig::UsernameAutomatic).toBool()));
   166         EapQtConfig::UsernameAutomatic).toBool()));
   140     // Connect signal to disable/enable username when usernameAutomatic changed   
   167     // Connect signal to disable/enable username when usernameAutomatic changed   
   141     mForm->addConnection(mUsernameAutomatic, SIGNAL(stateChanged(int)), this,
   168     mForm->addConnection(mUsernameAutomatic, SIGNAL(stateChanged(int)), this,
   142         SLOT(usernameAutomaticChanged(int)));
   169         SLOT(usernameAutomaticChanged(int)));
   143     groupItem->appendChild(mUsernameAutomatic);
   170     mGroupItem->appendChild(mUsernameAutomatic);
   144 
   171 
   145     //Username
   172     //Username
   146     mUsername = new CpSettingFormItemData(HbDataFormModelItem::TextItem, hbTrId(
   173     mUsername = new CpSettingFormItemData(HbDataFormModelItem::TextItem, hbTrId(
   147         "txt_occ_setlabel_user_name"));
   174         "txt_occ_setlabel_user_name"));
   148     mUsername->setContentWidgetData("text", eapConfig.value(EapQtConfig::Username));
   175     mUsername->setContentWidgetData("text", mEapConfig.value(EapQtConfig::Username));
   149     // Dimmed username if usernameAutomatic selected
   176     // Dim username if usernameAutomatic selected
   150     usernameAutomaticChanged(mUsernameAutomatic->contentWidgetData("checkState") == Qt::Checked);
   177     usernameAutomaticChanged(mUsernameAutomatic->contentWidgetData("checkState") == Qt::Checked);
   151     groupItem->appendChild(mUsername);
   178     mGroupItem->appendChild(mUsername);
   152 
   179 }
       
   180 
       
   181 /*!
       
   182  * Creates Realm group:
       
   183  * Generate automatically checkBox and realm lineEdit
       
   184  */
       
   185 void CpEapSimAkaUi::createRealm()
       
   186 {
       
   187     qDebug("CpEapSimAkaUi::createRealm()");
   153     // RealmAutomatic
   188     // RealmAutomatic
   154     mRealmAutomatic = new CpSettingFormItemData(HbDataFormModelItem::CheckBoxItem, hbTrId(
   189     mRealmAutomatic = new CpSettingFormItemData(HbDataFormModelItem::CheckBoxItem, hbTrId(
   155         "txt_occ_setlabel_realm"));
   190         "txt_occ_setlabel_realm"));
   156     mRealmAutomatic->setContentWidgetData("text", hbTrId(
   191     mRealmAutomatic->setContentWidgetData("text", hbTrId(
   157         "txt_occ_setlabel_realm_val_generate_automatically"));
   192         "txt_occ_setlabel_realm_val_generate_automatically"));
   158     // Initialize the value from EapQtConfig
   193     // Initialize the value from EapQtConfig
   159     // Generate realm automatically is selected by default
   194     // Generate realm automatically is selected by default
   160     mRealmAutomatic->setContentWidgetData("checkState", boolToCheckState(eapConfig.value(
   195     mRealmAutomatic->setContentWidgetData("checkState", boolToCheckState(mEapConfig.value(
   161         EapQtConfig::RealmAutomatic).toBool()));
   196         EapQtConfig::RealmAutomatic).toBool()));
   162     // connect signal to disable/enable realm when realmAutomatic changed 
   197     // connect signal to disable/enable realm when realmAutomatic changed 
   163     mForm->addConnection(mRealmAutomatic, SIGNAL(stateChanged(int)), this,
   198     mForm->addConnection(mRealmAutomatic, SIGNAL(stateChanged(int)), this,
   164         SLOT(realmAutomaticChanged(int)));
   199         SLOT(realmAutomaticChanged(int)));
   165     groupItem->appendChild(mRealmAutomatic);
   200     mGroupItem->appendChild(mRealmAutomatic);
   166 
   201 
   167     //Realm
   202     //Realm
   168     mRealm = new CpSettingFormItemData(HbDataFormModelItem::TextItem, hbTrId(
   203     mRealm = new CpSettingFormItemData(HbDataFormModelItem::TextItem, hbTrId(
   169         "txt_occ_setlabel_realm"));
   204         "txt_occ_setlabel_realm"));
   170     mRealm->setContentWidgetData("text", eapConfig.value(EapQtConfig::Realm));
   205     mRealm->setContentWidgetData("text", mEapConfig.value(EapQtConfig::Realm));
   171     // Dimmed realm if realmAutomatic selected
   206     // Dim realm if realmAutomatic selected
   172     realmAutomaticChanged(mRealmAutomatic->contentWidgetData("checkState") == Qt::Checked);
   207     realmAutomaticChanged(mRealmAutomatic->contentWidgetData("checkState") == Qt::Checked);
   173     groupItem->appendChild(mRealm);
   208     mGroupItem->appendChild(mRealm);
   174 
       
   175     // Set the model
       
   176     itemDataHelper.bindToForm(mForm);
       
   177     mForm->setModel(mModel);
       
   178 
       
   179     // Expand simakaui settings group
       
   180     mForm->setExpanded(mModel->indexFromItem(groupItem), TRUE);
       
   181 }
   209 }
   182 
   210 
   183 /*!
   211 /*!
   184  * Adds validators.
   212  * Adds validators.
   185  * 
   213  * 
   217  * 
   245  * 
   218  */
   246  */
   219 void CpEapSimAkaUi::close()
   247 void CpEapSimAkaUi::close()
   220 {
   248 {
   221     qDebug("CpEapSimAkaUi::close");
   249     qDebug("CpEapSimAkaUi::close");
       
   250 
       
   251     // Validate configuration
   222     if (validate()) {
   252     if (validate()) {
   223         qDebug("CpEapSimAkaUi::close - Store settings and exit");
   253         qDebug("CpEapSimAkaUi::close - Validation OK");
   224         storeSettings();
   254 
   225         CpBaseSettingView::close();
   255         // Store settings
       
   256         if (storeSettings()){
       
   257             qDebug("CpEapSimAkaUi::close - Settings stored, close view");
       
   258             // Close view
       
   259             CpBaseSettingView::close();   
       
   260         }
       
   261         else {
       
   262             qDebug("CpEapSimAkaUi::close - Store settings failed, prompt warning");
       
   263             // Store failed. Show error note to user
       
   264             QScopedPointer<HbMessageBox> infoBox;
       
   265             infoBox.reset(new HbMessageBox(
       
   266                 HbMessageBox::MessageTypeWarning));
       
   267             infoBox->setAttribute(Qt::WA_DeleteOnClose);
       
   268             infoBox->setText(hbTrId("txt_occ_info_unable_to_save_setting"));
       
   269             infoBox->clearActions();
       
   270             // Connect 'OK'-button to CpBaseSettingView 'aboutToClose'-signal
       
   271             HbAction *okAction = new HbAction(hbTrId("txt_common_button_ok"));
       
   272             infoBox->addAction(okAction);
       
   273             bool connected = connect(
       
   274                 okAction,
       
   275                 SIGNAL(triggered()),
       
   276                 this,
       
   277                 SIGNAL(aboutToClose()));
       
   278             Q_ASSERT(connected);
       
   279             infoBox->open();
       
   280             infoBox.take();
       
   281         }
   226     }
   282     }
   227     else {
   283     else {
   228         qDebug("CpEapSimAkaUi::close - validation failed. Prompt question.");
   284         qDebug("CpEapSimAkaUi::close - validation failed. Prompt question.");
   229         HbMessageBox *note = new HbMessageBox(HbMessageBox::MessageTypeQuestion);
   285         QScopedPointer<HbMessageBox> messageBox;
   230         note->setAttribute(Qt::WA_DeleteOnClose);
   286         messageBox.reset(new HbMessageBox(
   231         note->setText(hbTrId("txt_occ_info_incomplete_details_return_without_sa"));
   287             HbMessageBox::MessageTypeQuestion));
   232         note->clearActions();
   288         messageBox->setAttribute(Qt::WA_DeleteOnClose);
       
   289         messageBox->setText(hbTrId("txt_occ_info_incomplete_details_return_without_sa"));
       
   290         messageBox->clearActions();
   233         // Connect 'YES'-button to CpBaseSettingView 'aboutToClose'-signal
   291         // Connect 'YES'-button to CpBaseSettingView 'aboutToClose'-signal
   234         HbAction *okAction = new HbAction(hbTrId("txt_common_button_yes"));
   292         HbAction *okAction = new HbAction(hbTrId("txt_common_button_yes"));
   235         note->addAction(okAction);
   293         messageBox->addAction(okAction);
   236         bool connected = connect(
   294         bool connected = connect(
   237             okAction,
   295             okAction,
   238             SIGNAL(triggered()),
   296             SIGNAL(triggered()),
   239             this,
   297             this,
   240             SIGNAL(aboutToClose()));
   298             SIGNAL(aboutToClose()));
   241         Q_ASSERT(connected);
   299         Q_ASSERT(connected);
   242         // Clicking 'NO'-button does nothing
   300         // Clicking 'NO'-button does nothing
   243         HbAction *cancelAction = new HbAction(hbTrId("txt_common_button_no"));
   301         HbAction *cancelAction = new HbAction(hbTrId("txt_common_button_no"));
   244         note->addAction(cancelAction);
   302         messageBox->addAction(cancelAction);
   245         note->setTimeout(HbPopup::NoTimeout);
   303         messageBox->setTimeout(HbPopup::NoTimeout);
   246         note->open();
   304         messageBox->open();
       
   305         messageBox.take();
   247     }
   306     }
   248 }
   307 }
   249 
   308 
   250 /*!
   309 /*!
   251  * Dims the realm if generate realm automatically has been selected.
   310  * Dims the realm if generate realm automatically has been selected.
   330     return status;
   389     return status;
   331 }
   390 }
   332 
   391 
   333 /*!
   392 /*!
   334  * Stores settings given via SIM-AKA configuration UI
   393  * Stores settings given via SIM-AKA configuration UI
   335  */
   394  * 
   336 void CpEapSimAkaUi::storeSettings()
   395  * @return false if saving failed, true otherwise
       
   396  */
       
   397 bool CpEapSimAkaUi::storeSettings()
   337 {
   398 {
   338     qDebug("CpEapSimAkaUi::storeSettings");
   399     qDebug("CpEapSimAkaUi::storeSettings");
   339 
   400 
   340     EapQtConfig eapConfig;
   401     EapQtConfig eapConfig;
   341 
   402 
   345     eapConfig.setValue(EapQtConfig::Username, mUsername->contentWidgetData("text"));
   406     eapConfig.setValue(EapQtConfig::Username, mUsername->contentWidgetData("text"));
   346     eapConfig.setValue(EapQtConfig::RealmAutomatic, checkStateToBool(
   407     eapConfig.setValue(EapQtConfig::RealmAutomatic, checkStateToBool(
   347         mRealmAutomatic->contentWidgetData("checkState").toInt()));
   408         mRealmAutomatic->contentWidgetData("checkState").toInt()));
   348     eapConfig.setValue(EapQtConfig::Realm, mRealm->contentWidgetData("text"));
   409     eapConfig.setValue(EapQtConfig::Realm, mRealm->contentWidgetData("text"));
   349 
   410 
       
   411     // Save configuration
   350     if (!mConfigIf->saveConfiguration(mPluginInfo.pluginHandle(), eapConfig)) {
   412     if (!mConfigIf->saveConfiguration(mPluginInfo.pluginHandle(), eapConfig)) {
   351         qDebug("CpEapSimAkaUi::storeSettings - configuration saving failed.");
   413         qDebug("CpEapSimAkaUi::storeSettings - configuration saving failed.");
   352     }
   414         return false;
   353 }
   415     }
       
   416     return true;
       
   417 }