securitysettings/cpeapuiplugins/cpeapuserpasswordui/src/cpeapuserpasswordui.cpp
changeset 52 c23bdf5a328a
parent 39 fe6b6762fccd
equal deleted inserted replaced
51:e863583e6720 52:c23bdf5a328a
    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: 27 %
    20  * %version: 29 %
    21  */
    21  */
    22 
    22 
    23 // System includes
    23 // System includes
    24 #include <HbDataForm>
    24 #include <HbDataForm>
    25 #include <HbDataFormModel>
    25 #include <HbDataFormModel>
    90     // EapQtConfigInterface::IapIdUndefined)
    90     // EapQtConfigInterface::IapIdUndefined)
    91     if (iapId < 0) {
    91     if (iapId < 0) {
    92         QT_THROW(std::bad_alloc());
    92         QT_THROW(std::bad_alloc());
    93         // scoped pointer gets deleted automaticaly on exception
    93         // scoped pointer gets deleted automaticaly on exception
    94     }
    94     }
    95 
    95     setObjectName("CpEapUserPasswordUi");
       
    96     
    96     // Get EAP config interface
    97     // Get EAP config interface
    97     mConfigIf.reset(new EapQtConfigInterface(bearer, iapId));
    98     mConfigIf.reset(new EapQtConfigInterface(bearer, iapId));
    98     
    99     
    99     createUi();
   100     createUi();
   100 }
   101 }
   125         qDebug("CpEapUserPasswordUi::initializeUserPasswordUi - read configuration failed.");
   126         qDebug("CpEapUserPasswordUi::initializeUserPasswordUi - read configuration failed.");
   126     }
   127     }
   127 
   128 
   128     // Construct username-password UI
   129     // Construct username-password UI
   129     mForm = new HbDataForm();
   130     mForm = new HbDataForm();
       
   131     mForm->setObjectName("CpEapUserPasswordUiForm");
   130     this->setWidget(mForm);
   132     this->setWidget(mForm);
       
   133     
   131     mModel = new HbDataFormModel(mForm);
   134     mModel = new HbDataFormModel(mForm);
   132 
   135     mModel->setObjectName("CpEapUserPasswordUiModel");
       
   136     
   133     // Create settings group
   137     // Create settings group
   134     mGroupItem = new HbDataFormModelItem(HbDataFormModelItem::GroupItem,
   138     mGroupItem = new HbDataFormModelItem(
       
   139         HbDataFormModelItem::GroupItem,
   135         HbParameterLengthLimiter(
   140         HbParameterLengthLimiter(
   136             hbTrId("txt_occ_subhead_eap_module_settings")).arg(
   141             "txt_occ_subhead_eap_module_settings").arg(
   137                 mPluginInfo.localizationId()));
   142                 mPluginInfo.localizationId()));
       
   143     
       
   144     mGroupItem->setContentWidgetData("objectName", "CpEapUserPasswordUiGroup");
       
   145     
   138     mModel->appendDataFormItem(mGroupItem);
   146     mModel->appendDataFormItem(mGroupItem);
   139 
   147 
   140     // The parameter given as 0 is a HbDataForm pointer, not parent
   148     // The parameter given as 0 is a HbDataForm pointer, not parent
   141     mItemDataHelper = new CpItemDataHelper(0);
   149     mItemDataHelper = new CpItemDataHelper(0);
   142     mItemDataHelper->setParent(this);
   150     mItemDataHelper->setParent(this);
   147     
   155     
   148     mItemDataHelper->bindToForm(mForm);
   156     mItemDataHelper->bindToForm(mForm);
   149     mForm->setModel(mModel);
   157     mForm->setModel(mModel);
   150     
   158     
   151     // Connect signal to add validators when items get activated (visualization created).
   159     // Connect signal to add validators when items get activated (visualization created).
   152     bool connected = connect(mForm, SIGNAL( itemShown(const QModelIndex&) ), this,
   160     bool connected = connect(
       
   161         mForm, 
       
   162         SIGNAL( itemShown(const QModelIndex&) ), 
       
   163         this,
   153         SLOT( setValidator(const QModelIndex) ));
   164         SLOT( setValidator(const QModelIndex) ));
   154     Q_ASSERT(connected);
   165     Q_ASSERT(connected);
   155     
   166     
   156     // Expand username-password settings group
   167     // Expand username-password settings group
   157     mForm->setExpanded(mModel->indexFromItem(mGroupItem), true);
   168     mForm->setExpanded(mModel->indexFromItem(mGroupItem), true);
   162  */
   173  */
   163 void CpEapUserPasswordUi::createUsername()
   174 void CpEapUserPasswordUi::createUsername()
   164 {
   175 {
   165     qDebug("CpEapUserPasswordUi::createUsername()");
   176     qDebug("CpEapUserPasswordUi::createUsername()");
   166     // Username
   177     // Username
   167     mUsername = new CpSettingFormItemData(HbDataFormModelItem::TextItem, hbTrId(
   178     mUsername = new CpSettingFormItemData(
   168         "txt_occ_setlabel_user_name"));
   179         HbDataFormModelItem::TextItem, 
       
   180         hbTrId("txt_occ_setlabel_user_name"));
       
   181     
       
   182     mUsername->setContentWidgetData("objectName", "CpEapUserPasswordUiUsername");
       
   183     
   169     // Initialize the value from EapQtConfig
   184     // Initialize the value from EapQtConfig
   170     mUsername->setContentWidgetData("text", mEapConfig.value(EapQtConfig::Username));
   185     mUsername->setContentWidgetData("text", mEapConfig.value(EapQtConfig::Username));
   171     mGroupItem->appendChild(mUsername);
   186     mGroupItem->appendChild(mUsername);
   172 }
   187 }
   173 
   188 
   177  */
   192  */
   178 void CpEapUserPasswordUi::createPassword()
   193 void CpEapUserPasswordUi::createPassword()
   179 {
   194 {
   180     qDebug("CpEapUserPasswordUi::createPassword()");
   195     qDebug("CpEapUserPasswordUi::createPassword()");
   181     // Password prompting
   196     // Password prompting
   182     mPasswordPrompt = new CpSettingFormItemData(HbDataFormModelItem::CheckBoxItem, hbTrId(
   197     mPasswordPrompt = new CpSettingFormItemData(
   183         "txt_occ_setlabel_password"));
   198         HbDataFormModelItem::CheckBoxItem, 
   184     mPasswordPrompt->setContentWidgetData("text", hbTrId("txt_occ_setlabel_password_val_prompt"));
   199         hbTrId("txt_occ_setlabel_password"));
   185     mPasswordPrompt->setContentWidgetData("checkState", boolToCheckState(mEapConfig.value(
   200     
   186         EapQtConfig::PasswordPrompt).toBool()));
   201     mPasswordPrompt->setContentWidgetData(
       
   202         "objectName", 
       
   203         "CpEapUserPasswordUiPasswordPrompt");
       
   204     
       
   205     mPasswordPrompt->setContentWidgetData(
       
   206         "text", 
       
   207         hbTrId("txt_occ_setlabel_password_val_prompt"));
       
   208     
       
   209     mPasswordPrompt->setContentWidgetData(
       
   210         "checkState", 
       
   211         boolToCheckState(mEapConfig.value(EapQtConfig::PasswordPrompt).toBool()));
       
   212     
   187     // Connect signal to disable/enable password when passwordPrompt changed 
   213     // Connect signal to disable/enable password when passwordPrompt changed 
   188     mForm->addConnection(mPasswordPrompt, SIGNAL(stateChanged(int)), this,
   214     mForm->addConnection(
       
   215         mPasswordPrompt, 
       
   216         SIGNAL(stateChanged(int)), 
       
   217         this,
   189         SLOT(passwordPromptChanged(int)));
   218         SLOT(passwordPromptChanged(int)));
       
   219     
   190     mGroupItem->appendChild(mPasswordPrompt);
   220     mGroupItem->appendChild(mPasswordPrompt);
   191 
   221 
   192     // Password
   222     // Password
   193     mPassword = new CpSettingFormItemData(HbDataFormModelItem::TextItem, hbTrId(
   223     mPassword = new CpSettingFormItemData(
   194         "txt_occ_setlabel_password"));
   224         HbDataFormModelItem::TextItem, 
       
   225         hbTrId("txt_occ_setlabel_password"));
       
   226     
       
   227     mPassword->setContentWidgetData(
       
   228         "objectName", 
       
   229         "CpEapUserPasswordUiPassword");
       
   230 
   195     mPasswordStored = mEapConfig.value(EapQtConfig::PasswordStored).toBool();
   231     mPasswordStored = mEapConfig.value(EapQtConfig::PasswordStored).toBool();
       
   232     
   196     // If password has already been stored into the databse
   233     // If password has already been stored into the databse
   197     // fixed number of asterisks are shown in UI
   234     // fixed number of asterisks are shown in UI
   198     if (mPasswordStored) {
   235     if (mPasswordStored) {
   199         mPassword->setContentWidgetData("text", passwordExistString);
   236         mPassword->setContentWidgetData("text", passwordExistString);
   200     }
   237     }
   201     // Set password echo mode
   238     // Set password echo mode
   202     mPassword->setContentWidgetData("echoMode", HbLineEdit::Password);
   239     mPassword->setContentWidgetData("echoMode", HbLineEdit::Password);
       
   240     
   203     // Dim password if passwordPrompt is selected
   241     // Dim password if passwordPrompt is selected
   204     passwordPromptChanged(mPasswordPrompt->contentWidgetData("checkState") == Qt::Checked);
   242     passwordPromptChanged(mPasswordPrompt->contentWidgetData("checkState") == Qt::Checked);
       
   243     
   205     // Connect signal to get info that user has changed the password
   244     // Connect signal to get info that user has changed the password
   206     mForm->addConnection(mPassword, SIGNAL(editingFinished()), this, SLOT(passwordChanged()));
   245     mForm->addConnection(mPassword, SIGNAL(editingFinished()), this, SLOT(passwordChanged()));
   207     mGroupItem->appendChild(mPassword);
   246     mGroupItem->appendChild(mPassword);
   208 }
   247 }
   209 
   248 
   220         (mForm->itemByIndex(modelIndex));
   259         (mForm->itemByIndex(modelIndex));
   221     HbDataFormModelItem *modelItem = mModel->itemFromIndex(modelIndex);
   260     HbDataFormModelItem *modelItem = mModel->itemFromIndex(modelIndex);
   222     
   261     
   223     if (modelItem == mUsername) {
   262     if (modelItem == mUsername) {
   224         // When username lineEdit is activated (shown) first time, validator is added
   263         // When username lineEdit is activated (shown) first time, validator is added
   225         mValidatorUsername.reset(mConfigIf->validatorEap(mPluginInfo.pluginHandle().type(),
   264         mValidatorUsername.reset(
   226             EapQtConfig::Username));
   265             mConfigIf->validatorEap(
       
   266                 mPluginInfo.pluginHandle().type(),
       
   267                 EapQtConfig::Username));
       
   268         
   227         HbLineEdit *usernameEdit = qobject_cast<HbLineEdit *> (viewItem->dataItemContentWidget());
   269         HbLineEdit *usernameEdit = qobject_cast<HbLineEdit *> (viewItem->dataItemContentWidget());
   228         mValidatorUsername->updateEditor(usernameEdit);
   270         mValidatorUsername->updateEditor(usernameEdit);
   229     }
   271     }
   230     else if (modelItem == mPassword) {
   272     else if (modelItem == mPassword) {
   231         // When password lineEdit is activated (shown) first time, validator is added
   273         // When password lineEdit is activated (shown) first time, validator is added
   232         mValidatorPassword.reset(mConfigIf->validatorEap(mPluginInfo.pluginHandle().type(),
   274         mValidatorPassword.reset(
   233             EapQtConfig::Password));
   275             mConfigIf->validatorEap(
       
   276                 mPluginInfo.pluginHandle().type(),
       
   277                 EapQtConfig::Password));
       
   278         
   234         mPasswordEdit = qobject_cast<HbLineEdit *> (viewItem->dataItemContentWidget());
   279         mPasswordEdit = qobject_cast<HbLineEdit *> (viewItem->dataItemContentWidget());
   235         mValidatorPassword->updateEditor(mPasswordEdit);
   280         mValidatorPassword->updateEditor(mPasswordEdit);
   236         // Install event filter to clear dummy password, when password is started to edit.
   281         // Install event filter to clear dummy password, when password is started to edit.
   237         mPasswordEdit->installEventFilter(this);
   282         mPasswordEdit->installEventFilter(this);
   238     }
   283     }
   261         }
   306         }
   262         else {
   307         else {
   263             qDebug("CpEapUserPasswordUi::close - Store settings failed, prompt warning");
   308             qDebug("CpEapUserPasswordUi::close - Store settings failed, prompt warning");
   264             // Store failed. Show error note to user
   309             // Store failed. Show error note to user
   265             QScopedPointer<HbMessageBox> infoBox;
   310             QScopedPointer<HbMessageBox> infoBox;
   266             infoBox.reset(new HbMessageBox(
   311             infoBox.reset(new HbMessageBox(HbMessageBox::MessageTypeWarning));
   267                 HbMessageBox::MessageTypeWarning));
   312             infoBox->setObjectName("CpEapUserPasswordUiMessageBoxFailed");
   268             infoBox->setAttribute(Qt::WA_DeleteOnClose);
   313             infoBox->setAttribute(Qt::WA_DeleteOnClose);
   269             infoBox->setText(hbTrId("txt_occ_info_unable_to_save_setting"));
   314             infoBox->setText(hbTrId("txt_occ_info_unable_to_save_setting"));
   270             infoBox->clearActions();
   315             infoBox->clearActions();
       
   316             
   271             // Connect 'OK'-button to CpBaseSettingView 'aboutToClose'-signal
   317             // Connect 'OK'-button to CpBaseSettingView 'aboutToClose'-signal
   272             HbAction *okAction = new HbAction(hbTrId("txt_common_button_ok"));
   318             HbAction *okAction = new HbAction(hbTrId("txt_common_button_ok"));
   273             infoBox->addAction(okAction);
   319             infoBox->addAction(okAction);
   274             bool connected = connect(
   320             bool connected = connect(
   275                 okAction,
   321                 okAction,
   284     else {
   330     else {
   285         qDebug("CpEapUserPasswordUi::close - validation failed. Prompt question.");
   331         qDebug("CpEapUserPasswordUi::close - validation failed. Prompt question.");
   286 
   332 
   287         // Validate failed. Request user to exit anyway
   333         // Validate failed. Request user to exit anyway
   288         QScopedPointer<HbMessageBox> messageBox;
   334         QScopedPointer<HbMessageBox> messageBox;
   289         messageBox.reset(new HbMessageBox(
   335         messageBox.reset(new HbMessageBox(HbMessageBox::MessageTypeQuestion));
   290             HbMessageBox::MessageTypeQuestion));
   336         messageBox->setObjectName("CpEapUserPasswordUiMessageBoxValidationFailed");
   291         messageBox->setAttribute(Qt::WA_DeleteOnClose);
   337         messageBox->setAttribute(Qt::WA_DeleteOnClose);
   292         messageBox->setText(hbTrId("txt_occ_info_incomplete_details_return_without_sa"));
   338         messageBox->setText(hbTrId("txt_occ_info_incomplete_details_return_without_sa"));
   293         messageBox->clearActions();
   339         messageBox->clearActions();
       
   340         
   294         // Connect 'YES'-button to CpBaseSettingView 'aboutToClose'-signal
   341         // Connect 'YES'-button to CpBaseSettingView 'aboutToClose'-signal
   295         HbAction *okAction = new HbAction(hbTrId("txt_common_button_yes"));
   342         HbAction *okAction = new HbAction(hbTrId("txt_common_button_yes"));
   296         messageBox->addAction(okAction);
   343         messageBox->addAction(okAction);
   297         bool connected = connect(
   344         bool connected = connect(
   298             okAction,
   345             okAction,
   299             SIGNAL(triggered()),
   346             SIGNAL(triggered()),
   300             this,
   347             this,
   301             SIGNAL(aboutToClose()));
   348             SIGNAL(aboutToClose()));
   302         Q_ASSERT(connected);
   349         Q_ASSERT(connected);
       
   350         
   303         // Clicking 'NO'-button does nothing
   351         // Clicking 'NO'-button does nothing
   304         HbAction *cancelAction = new HbAction(hbTrId("txt_common_button_no"));
   352         HbAction *cancelAction = new HbAction(hbTrId("txt_common_button_no"));
   305         messageBox->addAction(cancelAction);
   353         messageBox->addAction(cancelAction);
   306         messageBox->setTimeout(HbPopup::NoTimeout);
   354         messageBox->setTimeout(HbPopup::NoTimeout);
   307         messageBox->open();
   355         messageBox->open();
   450     eapConfig.setValue(EapQtConfig::OuterType, qVariantFromValue(mOuterHandle));
   498     eapConfig.setValue(EapQtConfig::OuterType, qVariantFromValue(mOuterHandle));
   451     eapConfig.setValue(EapQtConfig::Username, mUsername->contentWidgetData("text"));
   499     eapConfig.setValue(EapQtConfig::Username, mUsername->contentWidgetData("text"));
   452     eapConfig.setValue(EapQtConfig::PasswordPrompt, checkStateToBool(
   500     eapConfig.setValue(EapQtConfig::PasswordPrompt, checkStateToBool(
   453         mPasswordPrompt->contentWidgetData("checkState").toInt()));
   501         mPasswordPrompt->contentWidgetData("checkState").toInt()));
   454     if (mPasswordPrompt->contentWidgetData("checkState") == Qt::Checked) {
   502     if (mPasswordPrompt->contentWidgetData("checkState") == Qt::Checked) {
   455         if(mPasswordStored) {
   503         if (mPasswordStored) {
   456             // Stored password is cleared if prompting has been enabled
   504             // Stored password is cleared if prompting has been enabled
   457             eapConfig.setValue(EapQtConfig::PasswordClear, true);
   505             eapConfig.setValue(EapQtConfig::PasswordClear, true);
   458             eapConfig.setValue(EapQtConfig::Password, "");
   506             eapConfig.setValue(EapQtConfig::Password, "");
   459         }
   507         }
   460         // else do nothing (password is not saved)
   508         // else do nothing (password is not saved)