securitysettings/cpeapuiplugins/cpeapuserpasswordui/src/cpeapuserpasswordui.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 username-password based EAP method configuration
    15  *   Control Panel QT UI for username-password based EAP method configuration
    16  *
    16  *
    17  */
    17  */
    18 
    18 
    19 /*
    19 /*
    20  * %version: 24 %
    20  * %version: 27 %
    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>
    65 CpEapUserPasswordUi::CpEapUserPasswordUi(
    66 CpEapUserPasswordUi::CpEapUserPasswordUi(
    66     const EapQtConfigInterface::EapBearerType bearer,
    67     const EapQtConfigInterface::EapBearerType bearer,
    67     const int iapId,
    68     const int iapId,
    68     const EapQtPluginInfo &plugin, 
    69     const EapQtPluginInfo &plugin, 
    69     const EapQtPluginHandle& outerHandle) :
    70     const EapQtPluginHandle& outerHandle) :
    70         mConfigIf(new EapQtConfigInterface(bearer, iapId)),
    71         mConfigIf(NULL),
    71         mPluginInfo(plugin), 
    72         mPluginInfo(plugin), 
    72         mOuterHandle(outerHandle), 
    73         mOuterHandle(outerHandle), 
    73         mForm(NULL),
    74         mForm(NULL),
    74         mModel(NULL), 
    75         mModel(NULL),
       
    76         mItemDataHelper(NULL),
       
    77         mGroupItem(NULL),
    75         mUsername(NULL), 
    78         mUsername(NULL), 
    76         mPasswordPrompt(NULL), 
    79         mPasswordPrompt(NULL), 
    77         mPassword(NULL), 
    80         mPassword(NULL), 
    78         mValidatorUsername(NULL),
    81         mValidatorUsername(NULL),
    79         mValidatorPassword(NULL), 
    82         mValidatorPassword(NULL), 
    88     if (iapId < 0) {
    91     if (iapId < 0) {
    89         QT_THROW(std::bad_alloc());
    92         QT_THROW(std::bad_alloc());
    90         // scoped pointer gets deleted automaticaly on exception
    93         // scoped pointer gets deleted automaticaly on exception
    91     }
    94     }
    92 
    95 
    93     initializeUserPasswordUi();
    96     // Get EAP config interface
       
    97     mConfigIf.reset(new EapQtConfigInterface(bearer, iapId));
       
    98     
       
    99     createUi();
    94 }
   100 }
    95 
   101 
    96 /*!
   102 /*!
    97  * Destructor.
   103  * Destructor.
    98  */
   104  */
   103     // mValidatorUsername, mValidatorPassword
   109     // mValidatorUsername, mValidatorPassword
   104     // mConfigIf: scoped pointer deleted automatically
   110     // mConfigIf: scoped pointer deleted automatically
   105 }
   111 }
   106 
   112 
   107 /*!
   113 /*!
   108  * Initializes the password-username ui and initializes objects based on configuration
   114  * Creates username-password UI and initilizes settings read via
   109  * read from the database.
   115  * EapQtConfigInterface
   110  */
   116  */
   111 void CpEapUserPasswordUi::initializeUserPasswordUi()
   117 void CpEapUserPasswordUi::createUi()
   112 {
   118 {
   113     qDebug("CpEapUserPasswordUi::initializeUserPasswordUi");
   119     qDebug("CpEapUserPasswordUi::createUi");
   114 
       
   115     CpItemDataHelper itemDataHelper;
       
   116 
   120 
   117     // Read Configurations
   121     // Read Configurations
   118     EapQtConfig eapConfig;
       
   119     bool configurationRead = mConfigIf->readConfiguration(mOuterHandle, mPluginInfo.pluginHandle(),
   122     bool configurationRead = mConfigIf->readConfiguration(mOuterHandle, mPluginInfo.pluginHandle(),
   120         eapConfig);
   123         mEapConfig);
   121     if (!configurationRead) {
   124     if (!configurationRead) {
   122         qDebug("CpEapUserPasswordUi::initializeUserPasswordUi - read configuration failed.");
   125         qDebug("CpEapUserPasswordUi::initializeUserPasswordUi - read configuration failed.");
   123     }
   126     }
   124 
   127 
   125     // Create UI objects and group 
   128     // Construct username-password UI
   126     mForm = new HbDataForm();
   129     mForm = new HbDataForm();
   127     this->setWidget(mForm);
   130     this->setWidget(mForm);
   128     
   131     mModel = new HbDataFormModel(mForm);
   129     mModel = new HbDataFormModel;
   132 
   130 
   133     // Create settings group
   131     HbDataFormModelItem *groupItem = new HbDataFormModelItem(HbDataFormModelItem::GroupItem,
   134     mGroupItem = new HbDataFormModelItem(HbDataFormModelItem::GroupItem,
   132         hbTrId("txt_occ_subhead_eap_module_settings").arg(mPluginInfo.localizationId()));
   135         HbParameterLengthLimiter(
   133     mModel->appendDataFormItem(groupItem);
   136             hbTrId("txt_occ_subhead_eap_module_settings")).arg(
   134 
   137                 mPluginInfo.localizationId()));
       
   138     mModel->appendDataFormItem(mGroupItem);
       
   139 
       
   140     // The parameter given as 0 is a HbDataForm pointer, not parent
       
   141     mItemDataHelper = new CpItemDataHelper(0);
       
   142     mItemDataHelper->setParent(this);
       
   143 
       
   144     // Create UI components
       
   145     createUsername();
       
   146     createPassword();
       
   147     
       
   148     mItemDataHelper->bindToForm(mForm);
       
   149     mForm->setModel(mModel);
       
   150     
   135     // Connect signal to add validators when items get activated (visualization created).
   151     // Connect signal to add validators when items get activated (visualization created).
   136     bool connected = connect(mForm, SIGNAL( itemShown(const QModelIndex&) ), this,
   152     bool connected = connect(mForm, SIGNAL( itemShown(const QModelIndex&) ), this,
   137         SLOT( setValidator(const QModelIndex) ));
   153         SLOT( setValidator(const QModelIndex) ));
   138     Q_ASSERT(connected);
   154     Q_ASSERT(connected);
   139     
   155     
       
   156     // Expand username-password settings group
       
   157     mForm->setExpanded(mModel->indexFromItem(mGroupItem), true);
       
   158 }
       
   159 
       
   160 /*!
       
   161  * Creates Username lineEdit
       
   162  */
       
   163 void CpEapUserPasswordUi::createUsername()
       
   164 {
       
   165     qDebug("CpEapUserPasswordUi::createUsername()");
   140     // Username
   166     // Username
   141     mUsername = new CpSettingFormItemData(HbDataFormModelItem::TextItem, hbTrId(
   167     mUsername = new CpSettingFormItemData(HbDataFormModelItem::TextItem, hbTrId(
   142         "txt_occ_setlabel_username"));
   168         "txt_occ_setlabel_user_name"));
   143     // Initialize the value from EapQtConfig
   169     // Initialize the value from EapQtConfig
   144     mUsername->setContentWidgetData("text", eapConfig.value(EapQtConfig::Username));
   170     mUsername->setContentWidgetData("text", mEapConfig.value(EapQtConfig::Username));
   145     groupItem->appendChild(mUsername);
   171     mGroupItem->appendChild(mUsername);
   146 
   172 }
       
   173 
       
   174 /*!
       
   175  * Creates Password group:
       
   176  * Prompt checkBox and password lineEdit
       
   177  */
       
   178 void CpEapUserPasswordUi::createPassword()
       
   179 {
       
   180     qDebug("CpEapUserPasswordUi::createPassword()");
   147     // Password prompting
   181     // Password prompting
   148     mPasswordPrompt = new CpSettingFormItemData(HbDataFormModelItem::CheckBoxItem, hbTrId(
   182     mPasswordPrompt = new CpSettingFormItemData(HbDataFormModelItem::CheckBoxItem, hbTrId(
   149         "txt_occ_setlabel_password"));
   183         "txt_occ_setlabel_password"));
   150     mPasswordPrompt->setContentWidgetData("text", hbTrId("txt_occ_setlabel_password_val_prompt"));
   184     mPasswordPrompt->setContentWidgetData("text", hbTrId("txt_occ_setlabel_password_val_prompt"));
   151     mPasswordPrompt->setContentWidgetData("checkState", boolToCheckState(eapConfig.value(
   185     mPasswordPrompt->setContentWidgetData("checkState", boolToCheckState(mEapConfig.value(
   152         EapQtConfig::PasswordPrompt).toBool()));
   186         EapQtConfig::PasswordPrompt).toBool()));
   153     // Connect signal to disable/enable password when passwordPrompt changed 
   187     // Connect signal to disable/enable password when passwordPrompt changed 
   154     mForm->addConnection(mPasswordPrompt, SIGNAL(stateChanged(int)), this,
   188     mForm->addConnection(mPasswordPrompt, SIGNAL(stateChanged(int)), this,
   155         SLOT(passwordPromptChanged(int)));
   189         SLOT(passwordPromptChanged(int)));
   156     groupItem->appendChild(mPasswordPrompt);
   190     mGroupItem->appendChild(mPasswordPrompt);
   157 
   191 
   158     // Password
   192     // Password
   159     mPassword = new CpSettingFormItemData(HbDataFormModelItem::TextItem, hbTrId(
   193     mPassword = new CpSettingFormItemData(HbDataFormModelItem::TextItem, hbTrId(
   160         "txt_occ_setlabel_password"));
   194         "txt_occ_setlabel_password"));
   161     mPasswordStored = eapConfig.value(EapQtConfig::PasswordStored).toBool();
   195     mPasswordStored = mEapConfig.value(EapQtConfig::PasswordStored).toBool();
   162     // If password has already been stored into the databse
   196     // If password has already been stored into the databse
   163     // fixed number of asterisks are shown in UI
   197     // fixed number of asterisks are shown in UI
   164     if (mPasswordStored) {
   198     if (mPasswordStored) {
   165         mPassword->setContentWidgetData("text", passwordExistString);
   199         mPassword->setContentWidgetData("text", passwordExistString);
   166     }
   200     }
   167     // Set password echo mode
   201     // Set password echo mode
   168     mPassword->setContentWidgetData("echoMode", HbLineEdit::Password);
   202     mPassword->setContentWidgetData("echoMode", HbLineEdit::Password);
   169     // Dimmed password if passwordPrompt is selected
   203     // Dim password if passwordPrompt is selected
   170     passwordPromptChanged(mPasswordPrompt->contentWidgetData("checkState") == Qt::Checked);
   204     passwordPromptChanged(mPasswordPrompt->contentWidgetData("checkState") == Qt::Checked);
   171     // Connect signal to get info that user has changed the password
   205     // Connect signal to get info that user has changed the password
   172     mForm->addConnection(mPassword, SIGNAL(editingFinished()), this, SLOT(passwordChanged()));
   206     mForm->addConnection(mPassword, SIGNAL(editingFinished()), this, SLOT(passwordChanged()));
   173     groupItem->appendChild(mPassword);
   207     mGroupItem->appendChild(mPassword);
   174 
       
   175     // Set the model
       
   176     mForm->setModel(mModel);
       
   177     itemDataHelper.bindToForm(mForm);
       
   178 
       
   179     // Expand userpasswordui settings group
       
   180     mForm->setExpanded(mModel->indexFromItem(groupItem), TRUE);
       
   181 }
   208 }
   182 
   209 
   183 /*!
   210 /*!
   184  * Adds validators and connects focusIn event to the Password.
   211  * Adds validators and connects focusIn event to the Password.
   185  * 
   212  * 
   219  * 
   246  * 
   220  */
   247  */
   221 void CpEapUserPasswordUi::close()
   248 void CpEapUserPasswordUi::close()
   222 {
   249 {
   223     qDebug("CpEapUserPasswordUi::close");
   250     qDebug("CpEapUserPasswordUi::close");
       
   251     
       
   252     // Validate configuration
   224     if (validate()) {
   253     if (validate()) {
   225         qDebug("CpEapUserPasswordUi::close - Store settings");
   254         qDebug("CpEapUserPasswordUi::close - Validation OK");
   226         storeSettings();
   255         
   227         qDebug("CpEapUserPasswordUi::close - Settings stored, exit");
   256         // Store settings
   228         CpBaseSettingView::close();
   257         if (storeSettings()){
       
   258             qDebug("CpEapUserPasswordUi::close - Settings stored, close view");
       
   259             // Close view
       
   260             CpBaseSettingView::close();   
       
   261         }
       
   262         else {
       
   263             qDebug("CpEapUserPasswordUi::close - Store settings failed, prompt warning");
       
   264             // Store failed. Show error note to user
       
   265             QScopedPointer<HbMessageBox> infoBox;
       
   266             infoBox.reset(new HbMessageBox(
       
   267                 HbMessageBox::MessageTypeWarning));
       
   268             infoBox->setAttribute(Qt::WA_DeleteOnClose);
       
   269             infoBox->setText(hbTrId("txt_occ_info_unable_to_save_setting"));
       
   270             infoBox->clearActions();
       
   271             // Connect 'OK'-button to CpBaseSettingView 'aboutToClose'-signal
       
   272             HbAction *okAction = new HbAction(hbTrId("txt_common_button_ok"));
       
   273             infoBox->addAction(okAction);
       
   274             bool connected = connect(
       
   275                 okAction,
       
   276                 SIGNAL(triggered()),
       
   277                 this,
       
   278                 SIGNAL(aboutToClose()));
       
   279             Q_ASSERT(connected);
       
   280             infoBox->open();
       
   281             infoBox.take();
       
   282         }
   229     }
   283     }
   230     else {
   284     else {
   231         qDebug("CpEapUserPasswordUi::close - validation failed. Prompt question.");
   285         qDebug("CpEapUserPasswordUi::close - validation failed. Prompt question.");
   232         HbMessageBox *note = new HbMessageBox(HbMessageBox::MessageTypeQuestion);
   286 
   233         note->setAttribute(Qt::WA_DeleteOnClose);
   287         // Validate failed. Request user to exit anyway
   234         note->setText(hbTrId("txt_occ_info_incomplete_details_return_without_sa"));
   288         QScopedPointer<HbMessageBox> messageBox;
   235         note->clearActions();
   289         messageBox.reset(new HbMessageBox(
       
   290             HbMessageBox::MessageTypeQuestion));
       
   291         messageBox->setAttribute(Qt::WA_DeleteOnClose);
       
   292         messageBox->setText(hbTrId("txt_occ_info_incomplete_details_return_without_sa"));
       
   293         messageBox->clearActions();
   236         // Connect 'YES'-button to CpBaseSettingView 'aboutToClose'-signal
   294         // Connect 'YES'-button to CpBaseSettingView 'aboutToClose'-signal
   237         HbAction *okAction = new HbAction(hbTrId("txt_common_button_yes"));
   295         HbAction *okAction = new HbAction(hbTrId("txt_common_button_yes"));
   238         note->addAction(okAction);
   296         messageBox->addAction(okAction);
   239         bool connected = connect(
   297         bool connected = connect(
   240             okAction,
   298             okAction,
   241             SIGNAL(triggered()),
   299             SIGNAL(triggered()),
   242             this,
   300             this,
   243             SIGNAL(aboutToClose()));
   301             SIGNAL(aboutToClose()));
   244         Q_ASSERT(connected);
   302         Q_ASSERT(connected);
   245         // Clicking 'NO'-button does nothing
   303         // Clicking 'NO'-button does nothing
   246         HbAction *cancelAction = new HbAction(hbTrId("txt_common_button_no"));
   304         HbAction *cancelAction = new HbAction(hbTrId("txt_common_button_no"));
   247         note->addAction(cancelAction);
   305         messageBox->addAction(cancelAction);
   248         note->setTimeout(HbPopup::NoTimeout);
   306         messageBox->setTimeout(HbPopup::NoTimeout);
   249         note->open();
   307         messageBox->open();
       
   308         messageBox.take();
   250     }
   309     }
   251 }
   310 }
   252 
   311 
   253 /*!
   312 /*!
   254  * Converts check box state to boolean.
   313  * Converts check box state to boolean.
   290  * Saves information that password has been changed and must be stored.
   349  * Saves information that password has been changed and must be stored.
   291  * If the new password is not given, the stored password is kept (if exists).
   350  * If the new password is not given, the stored password is kept (if exists).
   292  */
   351  */
   293 void CpEapUserPasswordUi::passwordChanged()
   352 void CpEapUserPasswordUi::passwordChanged()
   294 {
   353 {
   295     if (mPassword->contentWidgetData("text") != "") {
   354     if (mPassword->contentWidgetData("text").toString().length() > 0) {
   296         // Stored password is considered as changed only if user
   355         // Stored password is considered as changed only if user
   297         // gives new unempty password
   356         // gives new unempty password
   298         qDebug("CpEapUserPasswordUi::passwordChanged");
   357         qDebug("CpEapUserPasswordUi::passwordChanged");
   299         mPasswordChanged = true;
   358         mPasswordChanged = true;
   300     }
   359     }
   322 bool CpEapUserPasswordUi::validate()
   381 bool CpEapUserPasswordUi::validate()
   323 {
   382 {
   324     qDebug("CpEapUserPasswordUi::validate");
   383     qDebug("CpEapUserPasswordUi::validate");
   325     bool valid = false;
   384     bool valid = false;
   326 
   385 
   327     if ((EapQtValidator::StatusOk == mValidatorUsername->validate(mUsername->contentWidgetData(
   386     if (validateUsername()
   328         "text"))) && validatePasswordGroup()) {
   387         && validatePasswordGroup()) {
   329         qDebug("CpEapUserPasswordUi::validate - OK");
   388         qDebug("CpEapUserPasswordUi::validate - OK");
   330         valid = true;
   389         valid = true;
   331     }
   390     }
   332 
   391 
   333     return valid;
   392     return valid;
       
   393 }
       
   394 
       
   395 /*!
       
   396  * Validates username
       
   397  * 
       
   398  * @return true if OK, false otherwise
       
   399  */
       
   400 bool CpEapUserPasswordUi::validateUsername()
       
   401 {
       
   402     qDebug("CpEapUserPasswordUi::validateUsername");
       
   403     bool status = false;
       
   404     // true if (given username is valid) or 
       
   405     // (password prompt is on and username is empty)
       
   406     if ((EapQtValidator::StatusOk == mValidatorUsername->validate(
       
   407             mUsername->contentWidgetData("text"))) 
       
   408         || (mPasswordPrompt->contentWidgetData("checkState") == Qt::Checked
       
   409             && mUsername->contentWidgetData("text").toString().length() == 0)) {
       
   410         qDebug("CpEapUserPasswordUi::validateUsername - OK");
       
   411         status = true;
       
   412     }
       
   413     return status;       
   334 }
   414 }
   335 
   415 
   336 /*!
   416 /*!
   337  * Validates password and passwordPrompt.
   417  * Validates password and passwordPrompt.
   338  * 
   418  * 
   356     return status;
   436     return status;
   357 }
   437 }
   358 
   438 
   359 /*!
   439 /*!
   360  * Stores settings given via username-password configuration UI
   440  * Stores settings given via username-password configuration UI
   361  */
   441  * 
   362 void CpEapUserPasswordUi::storeSettings()
   442  * @return false if saving failed, true otherwisev
       
   443  */
       
   444 bool CpEapUserPasswordUi::storeSettings()
   363 {
   445 {
   364     qDebug("CpEapUserPasswordUi::storeSettings");
   446     qDebug("CpEapUserPasswordUi::storeSettings");
   365 
   447 
   366     EapQtConfig eapConfig;
   448     EapQtConfig eapConfig;
   367 
   449 
   387             // Store the new password
   469             // Store the new password
   388             eapConfig.setValue(EapQtConfig::Password, mPassword->contentWidgetData("text").toString());
   470             eapConfig.setValue(EapQtConfig::Password, mPassword->contentWidgetData("text").toString());
   389         }
   471         }
   390     }
   472     }
   391     
   473     
       
   474     // Save configuration
   392     if (!mConfigIf->saveConfiguration(mPluginInfo.pluginHandle(), eapConfig)) {
   475     if (!mConfigIf->saveConfiguration(mPluginInfo.pluginHandle(), eapConfig)) {
   393         qDebug("CpEapUserPasswordUi::storeSettings - configuration saving failed.");
   476         qDebug("CpEapUserPasswordUi::storeSettings - configuration saving failed.");
   394     }
   477         return false;
   395 }
   478     }
       
   479     return true;
       
   480 }