securitysettings/eapqtdialogs/src/eapmschapv2newpwddialog.cpp
changeset 26 9abfd4f00d37
equal deleted inserted replaced
25:e03a3db4489e 26:9abfd4f00d37
       
     1 /*
       
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: Dialog implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <HbMessageBox>
       
    20 #include <eapqtvalidator.h>
       
    21 #include <eapqtexpandedeaptype.h>
       
    22 #include <eapqtconfiginterface.h>
       
    23 #include <eapqtconfig.h>
       
    24 #include "eapmschapv2newpwddialog.h"
       
    25 #include "OstTraceDefinitions.h"
       
    26 #ifdef OST_TRACE_COMPILER_IN_USE
       
    27 #endif
       
    28 
       
    29 
       
    30 /**
       
    31  * The constructor
       
    32  */
       
    33 EapMschapv2NewPwdDialog::EapMschapv2NewPwdDialog(const QVariantMap &parameters) 
       
    34  :mEdit1(NULL), 
       
    35  mEdit2(NULL), 
       
    36  mPwdValidator(NULL),
       
    37  mActionOk(NULL),
       
    38  mTranslator(new HbTranslator("eapprompts"))
       
    39 {
       
    40     OstTraceFunctionEntry0( EAPMSCHAPV2NEWPWDDIALOG_EAPMSCHAPV2NEWPWDDIALOG_ENTRY );
       
    41     qDebug("EapMschapv2NewPwdDialog::EapMschapv2NewPwdDialog ENTER");
       
    42 
       
    43     createDialog(parameters);
       
    44     
       
    45     mClose = false;
       
    46     
       
    47     OstTraceFunctionExit0( EAPMSCHAPV2NEWPWDDIALOG_EAPMSCHAPV2NEWPWDDIALOG_EXIT );
       
    48     qDebug("EapMschapv2NewPwdDialog::EapMschapv2NewPwdDialog EXIT");
       
    49 }
       
    50     
       
    51 /**
       
    52  * The construction of the dialog
       
    53  */ 
       
    54 void EapMschapv2NewPwdDialog::createDialog(const QVariantMap &parameters )
       
    55 {
       
    56     OstTraceFunctionEntry0( EAPMSCHAPV2NEWPWDDIALOG_CREATEDIALOG_ENTRY );
       
    57     qDebug("EapMschapv2NewPwdDialog::createDialog ENTER");
       
    58     
       
    59     Q_UNUSED(parameters)
       
    60     
       
    61     QString labelText1 = QString(hbTrId("txt_occ_dialog_new_eapmschapv2_password"));
       
    62     QString labelText2 = QString(hbTrId("txt_occ_dialog_verify_password"));
       
    63         
       
    64     //Set the dialog to be on the screen until user reacts
       
    65     //by pressing any of the Action buttons
       
    66     this->setModal(true);
       
    67     this->setTimeout(HbPopup::NoTimeout);
       
    68     this->setDismissPolicy(HbPopup::NoDismiss);    
       
    69     this->setAdditionalRowVisible(true);
       
    70     
       
    71     this->setPromptText(labelText1, 0);   
       
    72     mEdit1 = this->lineEdit(0);
       
    73     mEdit1->setEchoMode(HbLineEdit::Password);
       
    74     
       
    75     this->setPromptText(labelText2, 1);   
       
    76     mEdit2 = this->lineEdit(1);        
       
    77     mEdit2->setEchoMode(HbLineEdit::Password);
       
    78     
       
    79     EapQtConfigInterface eap_config_if;
       
    80     
       
    81     mPwdValidator = eap_config_if.validatorEap(EapQtExpandedEapType::TypeEapMschapv2,
       
    82                 EapQtConfig::Password );  
       
    83     mPwdValidator->updateEditor(mEdit1);
       
    84     
       
    85     QList<QAction*> action_list = this->actions();
       
    86         
       
    87     for ( int i = 0; i < action_list.count(); i++ ) {
       
    88         this->removeAction(action_list.at(i));
       
    89         } 
       
    90     
       
    91     mActionOk = new HbAction(hbTrId("txt_common_button_ok"),this); 
       
    92     this->addAction(mActionOk);
       
    93     
       
    94     HbAction* actionCancel = new HbAction(hbTrId("txt_common_button_cancel"),this);
       
    95     this->addAction(actionCancel);    
       
    96      
       
    97     disconnect(mActionOk, SIGNAL(triggered()),this, SLOT(close()));
       
    98     bool connected = connect(mActionOk, SIGNAL(triggered()), this, SLOT(okPressed()));
       
    99     Q_ASSERT(connected == true);
       
   100     
       
   101     disconnect(actionCancel, SIGNAL(triggered()),this, SLOT(close()));
       
   102     connected = connect(actionCancel, SIGNAL(triggered()), this, SLOT(cancelPressed()));
       
   103     Q_ASSERT(connected == true);
       
   104     
       
   105     // Connect the about to close and hide signals, so that we are able to inform 
       
   106     // the caller that the dialog was closed   
       
   107     connected = connect(this, SIGNAL(aboutToClose()), this, SLOT(closingDialog()));
       
   108     Q_ASSERT(connected == true);
       
   109     connected = connect(this, SIGNAL(aboutToHide()), this, SLOT(closingDialog()));
       
   110     Q_ASSERT(connected == true);
       
   111    
       
   112     OstTraceFunctionExit0( DUP1_EAPMSCHAPV2NEWPWDDIALOG_CREATEDIALOG_EXIT );
       
   113     qDebug("EapMschapv2NewPwdDialog::createDialog EXIT");
       
   114 }
       
   115 
       
   116 /**
       
   117  * Destructor
       
   118  */
       
   119 EapMschapv2NewPwdDialog::~EapMschapv2NewPwdDialog()
       
   120 {
       
   121     OstTraceFunctionEntry0( EAPMSCHAPV2NEWPWDDIALOG_DEAPMSCHAPV2NEWPWDDIALOG_ENTRY );
       
   122     qDebug("EapMschapv2NewPwdDialog::~EapMschapv2NewPwdDialog");
       
   123     
       
   124     //The dialog widgets are deleted as the dialog is deleted
       
   125     delete mPwdValidator;
       
   126     
       
   127     OstTraceFunctionExit0( EAPMSCHAPV2NEWPWDDIALOG_DEAPMSCHAPV2NEWPWDDIALOG_EXIT );
       
   128 }
       
   129 
       
   130 /**
       
   131  * Line edit validator
       
   132  */
       
   133 bool EapMschapv2NewPwdDialog::validate() const
       
   134 {
       
   135     qDebug("EapMschapv2NewPwdDialog::validate");
       
   136     
       
   137     bool valid = false;
       
   138     
       
   139     EapQtValidator::Status test_status = mPwdValidator->validate(mEdit1->text());
       
   140     
       
   141     if ( mPwdValidator->validate(mEdit1->text())== EapQtValidator::StatusOk &&
       
   142         mEdit1->text() == mEdit2->text()) {
       
   143         qDebug("EapMschapv2NewPwdDialog::validate: ret val: TRUE");
       
   144         valid = true;
       
   145     }
       
   146     return valid;
       
   147 }
       
   148 
       
   149 /**
       
   150  * Function is called when the Ok Action button is pressed
       
   151  */
       
   152 void EapMschapv2NewPwdDialog::okPressed()
       
   153 {
       
   154     OstTraceFunctionEntry0( EAPMSCHAPV2NEWPWDDIALOG_FIRSTBUTTONPRESSED_ENTRY );
       
   155     qDebug("EapMschapv2NewPwdDialog::okPressed ENTER");
       
   156     
       
   157     if ( validate() == true ) {
       
   158          
       
   159         QVariantMap data;
       
   160     
       
   161         QString editStr = mEdit1->text();
       
   162          
       
   163         QVariant variant(editStr);
       
   164    
       
   165         data["password"] = variant;
       
   166       
       
   167         qDebug("EapMschapv2NewPwdDialog::okPressed: emit deviceDialogData");
       
   168     
       
   169         emit deviceDialogData(data); 
       
   170         closeDeviceDialog(true);
       
   171         }
       
   172     else {
       
   173         HbMessageBox *box = 
       
   174             new HbMessageBox(hbTrId("txt_occ_info_passwords_do_not_match_try_again"),
       
   175             HbMessageBox::MessageTypeInformation);
       
   176         
       
   177         box->setAttribute(Qt::WA_DeleteOnClose);
       
   178         box->open();       
       
   179         }
       
   180     OstTraceFunctionExit0( EAPMSCHAPV2NEWPWDDIALOG_FIRSTBUTTONPRESSED_EXIT );
       
   181     qDebug("EapMschapv2NewPwdDialog::okPressed EXIT");
       
   182 }
       
   183 
       
   184 /**
       
   185  * Function is called when the Cancel Action button is pressed
       
   186  */
       
   187 void EapMschapv2NewPwdDialog::cancelPressed()
       
   188 {
       
   189     OstTraceFunctionEntry0( EAPMSCHAPV2NEWPWDDIALOG_CANCELPRESSED_ENTRY );
       
   190     qDebug("EapMschapv2NewPwdDialog::cancelPressed ENTER");
       
   191     
       
   192     if (!mClose) {
       
   193         mClose = true;
       
   194         closeDeviceDialog(true);
       
   195     }   
       
   196     qDebug("EapMschapv2NewPwdDialog::cancelPressed EXIT");
       
   197     OstTraceFunctionExit0( EAPMSCHAPV2NEWPWDDIALOG_CANCELPRESSED_EXIT );
       
   198 }
       
   199 
       
   200 /**
       
   201  * Function is called when the dialog is about to close
       
   202  * 
       
   203  */
       
   204 void EapMschapv2NewPwdDialog::closingDialog()
       
   205 {
       
   206     OstTraceFunctionEntry0( EAPMSCHAPV2NEWPWDDIALOG_CLOSINGDIALOG_ENTRY );
       
   207     qDebug("EapMschapv2NewPwdDialog::closingDialog ENTER");
       
   208  
       
   209     closeDeviceDialog(false);
       
   210     
       
   211     qDebug("EapMschapv2NewPwdDialog::closingDialog EXIT");
       
   212     OstTraceFunctionExit0( EAPMSCHAPV2NEWPWDDIALOG_CLOSINGDIALOG_EXIT );
       
   213 }
       
   214 
       
   215 /**
       
   216  * Updating the dialog during its showing is not allowed.
       
   217  */ 
       
   218 bool EapMschapv2NewPwdDialog::setDeviceDialogParameters
       
   219                 (const QVariantMap &parameters)
       
   220 {
       
   221     OstTraceFunctionEntry0( EAPMSCHAPV2NEWPWDDIALOG_SETDEVICEDIALOGPARAMETERS_ENTRY );
       
   222     
       
   223     Q_UNUSED(parameters)
       
   224     // changing the dialog after presenting it is not supported.
       
   225     
       
   226     OstTraceFunctionExit0( EAPMSCHAPV2NEWPWDDIALOG_SETDEVICEDIALOGPARAMETERS_EXIT );
       
   227     return true;
       
   228 }
       
   229 
       
   230 /**
       
   231  * Not supported, 0 always returned
       
   232  */
       
   233 int EapMschapv2NewPwdDialog::deviceDialogError() const
       
   234 {
       
   235     OstTraceFunctionEntry0( EAPMSCHAPV2NEWPWDDIALOG_DEVICEDIALOGERROR_ENTRY );
       
   236     OstTraceFunctionExit0( EAPMSCHAPV2NEWPWDDIALOG_DEVICEDIALOGERROR_EXIT);
       
   237     return 0;
       
   238 }
       
   239 
       
   240 /**
       
   241  * Dialog is closed and the signal about closing is emitted
       
   242  */
       
   243 void EapMschapv2NewPwdDialog::closeDeviceDialog(bool byClient)
       
   244 {   
       
   245     OstTraceFunctionEntry0( EAPMSCHAPV2NEWPWDDIALOG_CLOSEDEVICEDIALOG_ENTRY );
       
   246     qDebug("EapMschapv2NewPwdDialog::closeDeviceDialog ENTER");
       
   247             
       
   248     //If the user closes the dialog, then the deviceDialogClosed is emitted
       
   249     if( byClient == true ) {
       
   250         qDebug("EapMschapv2NewPwdDialog::closeDeviceDialog: emit deviceDialogClosed");
       
   251         emit deviceDialogClosed();
       
   252         }
       
   253     
       
   254     qDebug("EapMschapv2NewPwdDialog::closeDeviceDialog EXIT");
       
   255     OstTraceFunctionExit0( EAPMSCHAPV2NEWPWDDIALOG_CLOSEDEVICEDIALOG_EXIT );
       
   256 }
       
   257 
       
   258 /**
       
   259  * This dialog widget is returned to the caller
       
   260  */
       
   261 HbPopup *EapMschapv2NewPwdDialog::deviceDialogWidget() const
       
   262 {
       
   263     OstTraceFunctionEntry0( EAPMSCHAPV2NEWPWDDIALOG_DEVICEDIALOGWIDGET_ENTRY );
       
   264     OstTraceFunctionExit0( EAPMSCHAPV2NEWPWDDIALOG_DEVICEDIALOGWIDGET_EXIT );
       
   265     
       
   266     return const_cast<EapMschapv2NewPwdDialog*>(this);
       
   267 }
       
   268