securitysettings/eapqtdialogs/src/eapmschapv2oldpwddialog.cpp
changeset 39 fe6b6762fccd
child 36 c98682f98478
equal deleted inserted replaced
38:7a0216d033ac 39:fe6b6762fccd
       
     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: EAP-MSCHAPv2 Old Password Input Dialog implementation
       
    15 *
       
    16 */
       
    17 
       
    18 #include <HbAction>
       
    19 #include <HbTranslator>
       
    20 #include <eapqtvalidator.h>
       
    21 #include <eapqtexpandedeaptype.h>
       
    22 #include <eapqtconfiginterface.h>
       
    23 #include <eapqtconfig.h>
       
    24 #include "eapmschapv2oldpwddialog.h"
       
    25 #include "OstTraceDefinitions.h"
       
    26 #ifdef OST_TRACE_COMPILER_IN_USE
       
    27 #endif
       
    28 
       
    29 /**
       
    30  * The constructor
       
    31  */
       
    32 EapMschapv2OldPwdDialog::EapMschapv2OldPwdDialog(const QVariantMap &parameters) 
       
    33  :mEdit(NULL), 
       
    34  mPwdValidator(NULL),
       
    35  mTranslator(new HbTranslator("eapprompts")),
       
    36  mOkActionPressed(false),
       
    37  mClose(false)
       
    38 {
       
    39     OstTraceFunctionEntry0( EAPMSCHAPV2OLDPWDDIALOG_EAPMSCHAPV2OLDPWDDIALOG_ENTRY );
       
    40     qDebug("EapMschapv2OldPwdDialog::EapMschapv2OldPwdDialog ENTER");
       
    41         
       
    42     createDialog(parameters);
       
    43     
       
    44     OstTraceFunctionExit0( EAPMSCHAPV2OLDPWDDIALOG_EAPMSCHAPV2OLDPWDDIALOG_EXIT );
       
    45     qDebug("EapMschapv2OldPwdDialog::EapMschapv2OldPwdDialog EXIT");
       
    46 }
       
    47     
       
    48 /**
       
    49  * The construction of the dialog
       
    50  */ 
       
    51 void EapMschapv2OldPwdDialog::createDialog(const QVariantMap &parameters )
       
    52 {
       
    53     OstTraceFunctionEntry0( EAPMSCHAPV2OLDPWDDIALOG_CREATEDIALOG_ENTRY );
       
    54     qDebug("EapMschapv2OldPwdDialog::createDialog ENTER");
       
    55 
       
    56     QString labelText1(hbTrId("txt_occ_dialog_old_eapmschapv2_password"));
       
    57     
       
    58     Q_UNUSED(parameters)
       
    59     
       
    60     //Set the dialog to be on the screen until user reacts
       
    61     //by pressing any of the Action buttons
       
    62     this->setModal(true);
       
    63     this->setTimeout(HbPopup::NoTimeout);
       
    64     this->setDismissPolicy(HbPopup::NoDismiss);    
       
    65     this->setPromptText(labelText1, 0);      
       
    66     mEdit = this->lineEdit(0);
       
    67     mEdit->setEchoMode(HbLineEdit::Password);
       
    68       
       
    69     EapQtConfigInterface eap_config_if;
       
    70     
       
    71     mPwdValidator.reset(eap_config_if.validatorEap(EapQtExpandedEapType::TypeEapMschapv2, 
       
    72                EapQtConfig::Password )); 
       
    73     Q_ASSERT( mPwdValidator.isNull() == false );
       
    74          
       
    75     mPwdValidator->updateEditor(mEdit);
       
    76     
       
    77     //Remove all default actions from the dialog                 
       
    78     QList<QAction*> action_list = this->actions();
       
    79     for ( int i = 0; i < action_list.count(); i++ ) {
       
    80         this->removeAction(action_list.at(i));
       
    81         } 
       
    82     
       
    83     //Add a new Ok button action 
       
    84     HbAction* actionOk = new HbAction(hbTrId("txt_common_button_ok"),this); 
       
    85     this->addAction(actionOk);
       
    86     
       
    87     //Add a new Cancel button action 
       
    88     HbAction* actionCancel = new HbAction(hbTrId("txt_common_button_cancel"),this);
       
    89     this->addAction(actionCancel);    
       
    90     
       
    91     //Disconnect action Ok from the default SLOT and connect to 
       
    92     //a SLOT owned by this class   
       
    93     disconnect(actionOk, SIGNAL(triggered()),this, SLOT(close()));
       
    94     bool connected = connect(actionOk, SIGNAL(triggered()), this, SLOT(okPressed()));
       
    95     Q_ASSERT(connected == true);
       
    96     
       
    97     //Disconnect action Cancel from the default SLOT and connect to 
       
    98     //a SLOT owned by this class  
       
    99     disconnect(actionCancel, SIGNAL(triggered()),this, SLOT(close()));
       
   100     connected = connect(actionCancel, SIGNAL(triggered()), this, SLOT(cancelPressed()));
       
   101     Q_ASSERT(connected == true);
       
   102     
       
   103     // Connect the about to close and hide signals, so that we are able to inform 
       
   104     // the caller that the dialog was closed   
       
   105     connected = connect(this, SIGNAL(aboutToClose()), this, SLOT(closingDialog()));
       
   106     Q_ASSERT(connected == true);
       
   107     connected = connect(this, SIGNAL(aboutToHide()), this, SLOT(closingDialog()));
       
   108     Q_ASSERT(connected == true);
       
   109    
       
   110     OstTraceFunctionExit0( DUP1_EAPMSCHAPV2OLDPWDDIALOG_CREATEDIALOG_EXIT );
       
   111     qDebug("EapMschapv2OldPwdDialog::createDialog EXIT");
       
   112 }
       
   113 
       
   114 /**
       
   115  * Destructor
       
   116  */
       
   117 EapMschapv2OldPwdDialog::~EapMschapv2OldPwdDialog()
       
   118 {
       
   119     OstTraceFunctionEntry0( EAPMSCHAPV2OLDPWDDIALOG_DEAPMSCHAPV2OLDPWDDIALOG_ENTRY );
       
   120     
       
   121     // The dialog widgets are deleted as the dialog is deleted
       
   122     // mPwdValidator:   scoped pointer deleted automatically
       
   123     
       
   124     OstTraceFunctionExit0( EAPMSCHAPV2OLDPWDDIALOG_DEAPMSCHAPV2OLDPWDDIALOG_EXIT );
       
   125 }
       
   126 
       
   127 /**
       
   128  * Line edit validator
       
   129  */
       
   130 bool EapMschapv2OldPwdDialog::validate() const
       
   131 {
       
   132     qDebug("EapMschapv2OldPwdDialog::validate ENTER");
       
   133     
       
   134     bool valid = false;
       
   135 
       
   136     if ( mPwdValidator->validate(mEdit->text())== EapQtValidator::StatusOk ) {
       
   137         qDebug("EapMschapv2OldPwdDialog::validate: returns TRUE");
       
   138         valid = true;
       
   139     }
       
   140     
       
   141     qDebug("EapMschapv2OldPwdDialog::validate EXIT");
       
   142     return valid;
       
   143 }
       
   144 
       
   145 /**
       
   146  * Function is called when the Ok Action button is pressed
       
   147  */
       
   148 void EapMschapv2OldPwdDialog::okPressed()
       
   149 {
       
   150     OstTraceFunctionEntry0( EAPMSCHAPV2OLDPWDDIALOG_FIRSTBUTTONPRESSED_ENTRY );
       
   151     qDebug("EapMschapv2OldPwdDialog::okPressed ENTER");
       
   152     
       
   153     if ( validate() == true  && mOkActionPressed == false ) {
       
   154         
       
   155         mOkActionPressed = true;
       
   156             
       
   157         QVariantMap data;
       
   158     
       
   159         data["password"] = mEdit->text();
       
   160       
       
   161         qDebug("EapMschapv2OldPwdDialog::okPressed: emit deviceDialogData");
       
   162     
       
   163         emit deviceDialogData(data); 
       
   164         closeDeviceDialog(true);
       
   165         }
       
   166 
       
   167     OstTraceFunctionExit0( EAPMSCHAPV2OLDPWDDIALOG_FIRSTBUTTONPRESSED_EXIT );
       
   168     qDebug("EapMschapv2OldPwdDialog::okPressed EXIT");
       
   169 }
       
   170 
       
   171 /**
       
   172  * Function is called when the Cancel Action button is pressed
       
   173  */
       
   174 void EapMschapv2OldPwdDialog::cancelPressed()
       
   175 {
       
   176     OstTraceFunctionEntry0( EAPMSCHAPV2OLDPWDDIALOG_CANCELPRESSED_ENTRY );
       
   177     qDebug("EapMschapv2OldPwdDialog::cancelPressed ENTER");
       
   178     
       
   179     if (!mClose) {
       
   180         mClose = true;
       
   181         closeDeviceDialog(true);
       
   182     }   
       
   183     qDebug("EapMschapv2OldPwdDialog::cancelPressed EXIT");
       
   184     OstTraceFunctionExit0( EAPMSCHAPV2OLDPWDDIALOG_CANCELPRESSED_EXIT );
       
   185 }
       
   186 
       
   187 /**
       
   188  * Function is called when the dialog is about to close
       
   189  * 
       
   190  */
       
   191 void EapMschapv2OldPwdDialog::closingDialog()
       
   192 {
       
   193     OstTraceFunctionEntry0( EAPMSCHAPV2OLDPWDDIALOG_CLOSINGDIALOG_ENTRY );
       
   194     qDebug("EapMschapv2OldPwdDialog::closingDialog ENTER");
       
   195  
       
   196     
       
   197     qDebug("EapMschapv2OldPwdDialog::closingDialog EXIT");
       
   198     OstTraceFunctionExit0( EAPMSCHAPV2OLDPWDDIALOG_CLOSINGDIALOG_EXIT );
       
   199 }
       
   200 
       
   201 /**
       
   202  * Updating the dialog during its showing is not allowed.
       
   203  */ 
       
   204 bool EapMschapv2OldPwdDialog::setDeviceDialogParameters
       
   205                 (const QVariantMap &parameters)
       
   206 {
       
   207     OstTraceFunctionEntry0( EAPMSCHAPV2OLDPWDDIALOG_SETDEVICEDIALOGPARAMETERS_ENTRY );
       
   208     
       
   209     Q_UNUSED(parameters)
       
   210     // changing the dialog after presenting it is not supported.
       
   211     
       
   212     OstTraceFunctionExit0( EAPMSCHAPV2OLDPWDDIALOG_SETDEVICEDIALOGPARAMETERS_EXIT );
       
   213     return true;
       
   214 }
       
   215 
       
   216 /**
       
   217  * Not supported, 0 always returned
       
   218  */
       
   219 int EapMschapv2OldPwdDialog::deviceDialogError() const
       
   220 {
       
   221     OstTraceFunctionEntry0( EAPMSCHAPV2OLDPWDDIALOG_DEVICEDIALOGERROR_ENTRY );
       
   222     OstTraceFunctionExit0( EAPMSCHAPV2OLDPWDDIALOG_DEVICEDIALOGERROR_EXIT);
       
   223     return 0;
       
   224 }
       
   225 
       
   226 /**
       
   227  * Dialog is closed and the signal about closing is emitted
       
   228  */
       
   229 void EapMschapv2OldPwdDialog::closeDeviceDialog(bool byClient)
       
   230 {   
       
   231     OstTraceFunctionEntry0( EAPMSCHAPV2OLDPWDDIALOG_CLOSEDEVICEDIALOG_ENTRY );
       
   232     qDebug("EapMschapv2OldPwdDialog::closeDeviceDialog ENTER");
       
   233             
       
   234     //If the user closes the dialog, then the deviceDialogClosed is emitted
       
   235     if ( byClient == true ) {  
       
   236         qDebug("EapMschapv2OldPwdDialog::closeDeviceDialog: emit deviceDialogClosed");  
       
   237         emit deviceDialogClosed(); 
       
   238         }
       
   239     
       
   240     qDebug("EapMschapv2OldPwdDialog::closeDeviceDialog EXIT");
       
   241     OstTraceFunctionExit0( EAPMSCHAPV2OLDPWDDIALOG_CLOSEDEVICEDIALOG_EXIT );
       
   242 }
       
   243 
       
   244 /**
       
   245  * This dialog widget is returned to the caller
       
   246  */
       
   247 HbPopup *EapMschapv2OldPwdDialog::deviceDialogWidget() const
       
   248 {
       
   249     OstTraceFunctionEntry0( EAPMSCHAPV2OLDPWDDIALOG_DEVICEDIALOGWIDGET_ENTRY );
       
   250     OstTraceFunctionExit0( EAPMSCHAPV2OLDPWDDIALOG_DEVICEDIALOGWIDGET_EXIT );
       
   251     
       
   252     return const_cast<EapMschapv2OldPwdDialog*>(this);
       
   253 }
       
   254