securitysettings/cpeapuiplugins/cpeapsimakaui/src/cpeapsimakaui.cpp
changeset 52 c23bdf5a328a
parent 39 fe6b6762fccd
equal deleted inserted replaced
51:e863583e6720 52:c23bdf5a328a
    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:  18 %
    20  * %version:  20 %
    21  */
    21  */
    22 
    22 
    23 // System includes
    23 // System includes
    24 #include <HbDataForm>
    24 #include <HbDataForm>
    25 #include <HbDataFormModel>
    25 #include <HbDataFormModel>
    76         mValidatorRealm(NULL),
    76         mValidatorRealm(NULL),
    77         mValidatorUsername(NULL)
    77         mValidatorUsername(NULL)
    78 {
    78 {
    79     qDebug("CpEapSimAkaUi::CpEapSimAkaUi");
    79     qDebug("CpEapSimAkaUi::CpEapSimAkaUi");
    80 
    80 
       
    81     setObjectName("CpEapSimAkaUi");
    81     // IAP must be valid in construction (check includes
    82     // IAP must be valid in construction (check includes
    82     // EapQtConfigInterface::IapIdUndefined)
    83     // EapQtConfigInterface::IapIdUndefined)
    83     if (iapId < 0) {
    84     if (iapId < 0) {
    84         QT_THROW(std::bad_alloc());
    85         QT_THROW(std::bad_alloc());
    85         // scoped pointer gets deleted automaticaly on exception
    86         // scoped pointer gets deleted automaticaly on exception
   117         qDebug("CpEapSimAkaUi::initializeSimAkaUi - read configuration failed.");
   118         qDebug("CpEapSimAkaUi::initializeSimAkaUi - read configuration failed.");
   118     }
   119     }
   119     
   120     
   120     // Construct EAP-SIM/AKA settings UI 
   121     // Construct EAP-SIM/AKA settings UI 
   121     mForm = new HbDataForm();
   122     mForm = new HbDataForm();
       
   123     mForm->setObjectName("CpEapSimAkaUiForm");
   122     this->setWidget(mForm);
   124     this->setWidget(mForm);
       
   125     
   123     mModel = new HbDataFormModel(mForm);
   126     mModel = new HbDataFormModel(mForm);
   124 
   127     mModel->setObjectName("CpEapSimAkaUiModel");
   125     mGroupItem = new HbDataFormModelItem(HbDataFormModelItem::GroupItem,
   128     
       
   129     mGroupItem = new HbDataFormModelItem(
       
   130         HbDataFormModelItem::GroupItem,
   126         HbParameterLengthLimiter(
   131         HbParameterLengthLimiter(
   127             hbTrId("txt_occ_subhead_eap_module_settings")).arg(
   132             "txt_occ_subhead_eap_module_settings").arg(
   128                 mPluginInfo.localizationId()));
   133                 mPluginInfo.localizationId()));
       
   134     
       
   135     mGroupItem->setContentWidgetData("objectName", "CpEapSimAkaUiGroupItem");
       
   136     
   129     mModel->appendDataFormItem(mGroupItem);
   137     mModel->appendDataFormItem(mGroupItem);
   130 
   138 
   131     // The parameter given as 0 is a HbDataForm pointer, not parent
   139     // The parameter given as 0 is a HbDataForm pointer, not parent
   132     mItemDataHelper = new CpItemDataHelper(0);
   140     mItemDataHelper = new CpItemDataHelper(0);
   133     mItemDataHelper->setParent(this);
   141     mItemDataHelper->setParent(this);
   138     
   146     
   139     mItemDataHelper->bindToForm(mForm);
   147     mItemDataHelper->bindToForm(mForm);
   140     mForm->setModel(mModel);
   148     mForm->setModel(mModel);
   141     
   149     
   142     // Connect signal to add validators when items get activated (visualization created).
   150     // Connect signal to add validators when items get activated (visualization created).
   143     bool connected = connect(mForm, SIGNAL( itemShown(const QModelIndex&) ), this,
   151     bool connected = connect(
       
   152         mForm, 
       
   153         SIGNAL( itemShown(const QModelIndex&) ), 
       
   154         this,
   144         SLOT( setValidator(const QModelIndex) ));
   155         SLOT( setValidator(const QModelIndex) ));
   145     Q_ASSERT(connected);
   156     Q_ASSERT(connected);
   146 
   157 
   147     // Expand EAP-SIM/AKA settings group
   158     // Expand EAP-SIM/AKA settings group
   148     mForm->setExpanded(mModel->indexFromItem(mGroupItem), true);
   159     mForm->setExpanded(mModel->indexFromItem(mGroupItem), true);
   154  */
   165  */
   155 void CpEapSimAkaUi::createUsername()
   166 void CpEapSimAkaUi::createUsername()
   156 {
   167 {
   157     qDebug("CpEapSimAkaUi::createUsername()");
   168     qDebug("CpEapSimAkaUi::createUsername()");
   158     // UsernameAutomatic
   169     // UsernameAutomatic
   159     mUsernameAutomatic = new CpSettingFormItemData(HbDataFormModelItem::CheckBoxItem, hbTrId(
   170     mUsernameAutomatic = new CpSettingFormItemData(
   160         "txt_occ_setlabel_user_name"));
   171         HbDataFormModelItem::CheckBoxItem, 
   161     mUsernameAutomatic->setContentWidgetData("text", hbTrId(
   172         hbTrId("txt_occ_setlabel_user_name"));
   162         "txt_occ_setlabel_user_name_val_generate_automatica"));
   173     
       
   174     mUsernameAutomatic->setContentWidgetData("objectName", "CpEapSimAkaUiUsernameAutomatic");
       
   175     mUsernameAutomatic->setContentWidgetData(
       
   176         "text", 
       
   177         hbTrId("txt_occ_setlabel_user_name_val_generate_automatica"));
       
   178     
   163     // Initialize the value from EapQtConfig
   179     // Initialize the value from EapQtConfig
   164     // Generate username automatically is selected by default
   180     // Generate username automatically is selected by default
   165     mUsernameAutomatic->setContentWidgetData("checkState", boolToCheckState(mEapConfig.value(
   181     mUsernameAutomatic->setContentWidgetData(
   166         EapQtConfig::UsernameAutomatic).toBool()));
   182         "checkState", 
       
   183         boolToCheckState(mEapConfig.value(EapQtConfig::UsernameAutomatic).toBool()));
       
   184     
   167     // Connect signal to disable/enable username when usernameAutomatic changed   
   185     // Connect signal to disable/enable username when usernameAutomatic changed   
   168     mForm->addConnection(mUsernameAutomatic, SIGNAL(stateChanged(int)), this,
   186     mForm->addConnection(
   169         SLOT(usernameAutomaticChanged(int)));
   187         mUsernameAutomatic, SIGNAL(stateChanged(int)), 
       
   188         this, SLOT(usernameAutomaticChanged(int)));
       
   189     
   170     mGroupItem->appendChild(mUsernameAutomatic);
   190     mGroupItem->appendChild(mUsernameAutomatic);
   171 
   191 
   172     //Username
   192     //Username
   173     mUsername = new CpSettingFormItemData(HbDataFormModelItem::TextItem, hbTrId(
   193     mUsername = new CpSettingFormItemData(
   174         "txt_occ_setlabel_user_name"));
   194         HbDataFormModelItem::TextItem, 
       
   195         hbTrId("txt_occ_setlabel_user_name"));
       
   196     
       
   197     mUsername->setContentWidgetData("objectName", "CpEapSimAkaUiUsername");
   175     mUsername->setContentWidgetData("text", mEapConfig.value(EapQtConfig::Username));
   198     mUsername->setContentWidgetData("text", mEapConfig.value(EapQtConfig::Username));
       
   199     
   176     // Dim username if usernameAutomatic selected
   200     // Dim username if usernameAutomatic selected
   177     usernameAutomaticChanged(mUsernameAutomatic->contentWidgetData("checkState") == Qt::Checked);
   201     usernameAutomaticChanged(mUsernameAutomatic->contentWidgetData("checkState") == Qt::Checked);
   178     mGroupItem->appendChild(mUsername);
   202     mGroupItem->appendChild(mUsername);
   179 }
   203 }
   180 
   204 
   184  */
   208  */
   185 void CpEapSimAkaUi::createRealm()
   209 void CpEapSimAkaUi::createRealm()
   186 {
   210 {
   187     qDebug("CpEapSimAkaUi::createRealm()");
   211     qDebug("CpEapSimAkaUi::createRealm()");
   188     // RealmAutomatic
   212     // RealmAutomatic
   189     mRealmAutomatic = new CpSettingFormItemData(HbDataFormModelItem::CheckBoxItem, hbTrId(
   213     mRealmAutomatic = new CpSettingFormItemData(
   190         "txt_occ_setlabel_realm"));
   214         HbDataFormModelItem::CheckBoxItem, 
   191     mRealmAutomatic->setContentWidgetData("text", hbTrId(
   215         hbTrId("txt_occ_setlabel_realm"));
   192         "txt_occ_setlabel_realm_val_generate_automatically"));
   216     
       
   217     mRealmAutomatic->setContentWidgetData("objectName", "CpEapSimAkaUiRealmAutomatic");
       
   218     mRealmAutomatic->setContentWidgetData(
       
   219         "text", 
       
   220         hbTrId("txt_occ_setlabel_realm_val_generate_automatically"));
       
   221     
   193     // Initialize the value from EapQtConfig
   222     // Initialize the value from EapQtConfig
   194     // Generate realm automatically is selected by default
   223     // Generate realm automatically is selected by default
   195     mRealmAutomatic->setContentWidgetData("checkState", boolToCheckState(mEapConfig.value(
   224     mRealmAutomatic->setContentWidgetData(
   196         EapQtConfig::RealmAutomatic).toBool()));
   225         "checkState", 
       
   226         boolToCheckState(mEapConfig.value(EapQtConfig::RealmAutomatic).toBool()));
       
   227     
   197     // connect signal to disable/enable realm when realmAutomatic changed 
   228     // connect signal to disable/enable realm when realmAutomatic changed 
   198     mForm->addConnection(mRealmAutomatic, SIGNAL(stateChanged(int)), this,
   229     mForm->addConnection(
       
   230         mRealmAutomatic, 
       
   231         SIGNAL(stateChanged(int)), 
       
   232         this, 
   199         SLOT(realmAutomaticChanged(int)));
   233         SLOT(realmAutomaticChanged(int)));
       
   234     
   200     mGroupItem->appendChild(mRealmAutomatic);
   235     mGroupItem->appendChild(mRealmAutomatic);
   201 
   236 
   202     //Realm
   237     //Realm
   203     mRealm = new CpSettingFormItemData(HbDataFormModelItem::TextItem, hbTrId(
   238     mRealm = new CpSettingFormItemData(
   204         "txt_occ_setlabel_realm"));
   239         HbDataFormModelItem::TextItem, 
       
   240         hbTrId("txt_occ_setlabel_realm"));
       
   241     
       
   242     mRealm->setContentWidgetData("objectName", "CpEapSimAkaUiRealm");
   205     mRealm->setContentWidgetData("text", mEapConfig.value(EapQtConfig::Realm));
   243     mRealm->setContentWidgetData("text", mEapConfig.value(EapQtConfig::Realm));
       
   244     
   206     // Dim realm if realmAutomatic selected
   245     // Dim realm if realmAutomatic selected
   207     realmAutomaticChanged(mRealmAutomatic->contentWidgetData("checkState") == Qt::Checked);
   246     realmAutomaticChanged(mRealmAutomatic->contentWidgetData("checkState") == Qt::Checked);
   208     mGroupItem->appendChild(mRealm);
   247     mGroupItem->appendChild(mRealm);
   209 }
   248 }
   210 
   249 
   221         (mForm->itemByIndex(modelIndex));
   260         (mForm->itemByIndex(modelIndex));
   222     HbDataFormModelItem *modelItem = mModel->itemFromIndex(modelIndex);
   261     HbDataFormModelItem *modelItem = mModel->itemFromIndex(modelIndex);
   223     
   262     
   224     if (modelItem == mUsername) {
   263     if (modelItem == mUsername) {
   225         // When username lineEdit is activated (shown) first time, validator is added
   264         // When username lineEdit is activated (shown) first time, validator is added
   226         mValidatorUsername.reset(mConfigIf->validatorEap(mPluginInfo.pluginHandle().type(),
   265         mValidatorUsername.reset(
   227             EapQtConfig::Username));
   266             mConfigIf->validatorEap(
       
   267                 mPluginInfo.pluginHandle().type(),
       
   268                 EapQtConfig::Username));
       
   269         
   228         HbLineEdit *edit = qobject_cast<HbLineEdit *> (viewItem->dataItemContentWidget());
   270         HbLineEdit *edit = qobject_cast<HbLineEdit *> (viewItem->dataItemContentWidget());
   229         mValidatorUsername->updateEditor(edit);
   271         mValidatorUsername->updateEditor(edit);
   230     }
   272     }
   231     else if (modelItem == mRealm) {
   273     else if (modelItem == mRealm) {
   232         // When realm lineEdit is activated (shown) first time, validator is added
   274         // When realm lineEdit is activated (shown) first time, validator is added
   233         mValidatorRealm.reset(mConfigIf->validatorEap(mPluginInfo.pluginHandle().type(),
   275         mValidatorRealm.reset(
       
   276             mConfigIf->validatorEap(
       
   277                 mPluginInfo.pluginHandle().type(),
   234                 EapQtConfig::Realm));
   278                 EapQtConfig::Realm));
       
   279         
   235         HbLineEdit *edit = qobject_cast<HbLineEdit *> (viewItem->dataItemContentWidget());
   280         HbLineEdit *edit = qobject_cast<HbLineEdit *> (viewItem->dataItemContentWidget());
   236         mValidatorRealm->updateEditor(edit);
   281         mValidatorRealm->updateEditor(edit);
   237     }
   282     }
   238 }
   283 }
   239 
   284 
   260         }
   305         }
   261         else {
   306         else {
   262             qDebug("CpEapSimAkaUi::close - Store settings failed, prompt warning");
   307             qDebug("CpEapSimAkaUi::close - Store settings failed, prompt warning");
   263             // Store failed. Show error note to user
   308             // Store failed. Show error note to user
   264             QScopedPointer<HbMessageBox> infoBox;
   309             QScopedPointer<HbMessageBox> infoBox;
   265             infoBox.reset(new HbMessageBox(
   310             infoBox.reset(new HbMessageBox(HbMessageBox::MessageTypeWarning));
   266                 HbMessageBox::MessageTypeWarning));
   311             infoBox->setObjectName("CpEapSimAkaUiMessageBoxFailed");
   267             infoBox->setAttribute(Qt::WA_DeleteOnClose);
   312             infoBox->setAttribute(Qt::WA_DeleteOnClose);
   268             infoBox->setText(hbTrId("txt_occ_info_unable_to_save_setting"));
   313             infoBox->setText(hbTrId("txt_occ_info_unable_to_save_setting"));
   269             infoBox->clearActions();
   314             infoBox->clearActions();
       
   315             
   270             // Connect 'OK'-button to CpBaseSettingView 'aboutToClose'-signal
   316             // Connect 'OK'-button to CpBaseSettingView 'aboutToClose'-signal
   271             HbAction *okAction = new HbAction(hbTrId("txt_common_button_ok"));
   317             HbAction *okAction = new HbAction(hbTrId("txt_common_button_ok"));
   272             infoBox->addAction(okAction);
   318             infoBox->addAction(okAction);
       
   319             
   273             bool connected = connect(
   320             bool connected = connect(
   274                 okAction,
   321                 okAction,
   275                 SIGNAL(triggered()),
   322                 SIGNAL(triggered()),
   276                 this,
   323                 this,
   277                 SIGNAL(aboutToClose()));
   324                 SIGNAL(aboutToClose()));
   278             Q_ASSERT(connected);
   325             Q_ASSERT(connected);
       
   326             
   279             infoBox->open();
   327             infoBox->open();
   280             infoBox.take();
   328             infoBox.take();
   281         }
   329         }
   282     }
   330     }
   283     else {
   331     else {
   284         qDebug("CpEapSimAkaUi::close - validation failed. Prompt question.");
   332         qDebug("CpEapSimAkaUi::close - validation failed. Prompt question.");
   285         QScopedPointer<HbMessageBox> messageBox;
   333         QScopedPointer<HbMessageBox> messageBox;
   286         messageBox.reset(new HbMessageBox(
   334         messageBox.reset(new HbMessageBox(HbMessageBox::MessageTypeQuestion));
   287             HbMessageBox::MessageTypeQuestion));
   335         messageBox->setObjectName("CpEapSimAkaUiMessageBoxValidationFailed");
   288         messageBox->setAttribute(Qt::WA_DeleteOnClose);
   336         messageBox->setAttribute(Qt::WA_DeleteOnClose);
   289         messageBox->setText(hbTrId("txt_occ_info_incomplete_details_return_without_sa"));
   337         messageBox->setText(hbTrId("txt_occ_info_incomplete_details_return_without_sa"));
   290         messageBox->clearActions();
   338         messageBox->clearActions();
       
   339         
   291         // Connect 'YES'-button to CpBaseSettingView 'aboutToClose'-signal
   340         // Connect 'YES'-button to CpBaseSettingView 'aboutToClose'-signal
   292         HbAction *okAction = new HbAction(hbTrId("txt_common_button_yes"));
   341         HbAction *okAction = new HbAction(hbTrId("txt_common_button_yes"));
   293         messageBox->addAction(okAction);
   342         messageBox->addAction(okAction);
       
   343         
   294         bool connected = connect(
   344         bool connected = connect(
   295             okAction,
   345             okAction,
   296             SIGNAL(triggered()),
   346             SIGNAL(triggered()),
   297             this,
   347             this,
   298             SIGNAL(aboutToClose()));
   348             SIGNAL(aboutToClose()));
   299         Q_ASSERT(connected);
   349         Q_ASSERT(connected);
       
   350         
   300         // Clicking 'NO'-button does nothing
   351         // Clicking 'NO'-button does nothing
   301         HbAction *cancelAction = new HbAction(hbTrId("txt_common_button_no"));
   352         HbAction *cancelAction = new HbAction(hbTrId("txt_common_button_no"));
   302         messageBox->addAction(cancelAction);
   353         messageBox->addAction(cancelAction);
   303         messageBox->setTimeout(HbPopup::NoTimeout);
   354         messageBox->setTimeout(HbPopup::NoTimeout);
   304         messageBox->open();
   355         messageBox->open();
   398 {
   449 {
   399     qDebug("CpEapSimAkaUi::storeSettings");
   450     qDebug("CpEapSimAkaUi::storeSettings");
   400 
   451 
   401     EapQtConfig eapConfig;
   452     EapQtConfig eapConfig;
   402 
   453 
   403     eapConfig.setValue(EapQtConfig::OuterType, qVariantFromValue(mOuterHandle));
   454     eapConfig.setValue(
   404     eapConfig.setValue(EapQtConfig::UsernameAutomatic, checkStateToBool(
   455         EapQtConfig::OuterType, 
   405         mUsernameAutomatic->contentWidgetData("checkState").toInt()));
   456         qVariantFromValue(mOuterHandle));
   406     eapConfig.setValue(EapQtConfig::Username, mUsername->contentWidgetData("text"));
   457     
   407     eapConfig.setValue(EapQtConfig::RealmAutomatic, checkStateToBool(
   458     eapConfig.setValue(
   408         mRealmAutomatic->contentWidgetData("checkState").toInt()));
   459         EapQtConfig::UsernameAutomatic, 
   409     eapConfig.setValue(EapQtConfig::Realm, mRealm->contentWidgetData("text"));
   460         checkStateToBool(mUsernameAutomatic->contentWidgetData("checkState").toInt()));
       
   461     
       
   462     eapConfig.setValue(
       
   463         EapQtConfig::Username, 
       
   464         mUsername->contentWidgetData("text"));
       
   465     
       
   466     eapConfig.setValue(
       
   467         EapQtConfig::RealmAutomatic, 
       
   468         checkStateToBool(mRealmAutomatic->contentWidgetData("checkState").toInt()));
       
   469     
       
   470     eapConfig.setValue(
       
   471         EapQtConfig::Realm, 
       
   472         mRealm->contentWidgetData("text"));
   410 
   473 
   411     // Save configuration
   474     // Save configuration
   412     if (!mConfigIf->saveConfiguration(mPluginInfo.pluginHandle(), eapConfig)) {
   475     if (!mConfigIf->saveConfiguration(mPluginInfo.pluginHandle(), eapConfig)) {
   413         qDebug("CpEapSimAkaUi::storeSettings - configuration saving failed.");
   476         qDebug("CpEapSimAkaUi::storeSettings - configuration saving failed.");
   414         return false;
   477         return false;