securitysettings/eapqtdialogs/src/eapusernamepwddialog.cpp
branchRCL_3
changeset 46 c74b3d9f6b9e
parent 45 bad0cc58d154
child 55 9c2aa05919d9
equal deleted inserted replaced
45:bad0cc58d154 46:c74b3d9f6b9e
     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:   
       
    15 *   User authentication Dialog implementation
       
    16 *
       
    17 */
       
    18 
       
    19 /*
       
    20  * %version: 6 %
       
    21  */
       
    22 
       
    23 // System includes
       
    24 #include <eapqtvalidator.h>
       
    25 #include <eapqtexpandedeaptype.h>
       
    26 #include <eapqtconfiginterface.h>
       
    27 #include <eapqtconfig.h>
       
    28 #include <HbParameterLengthLimiter>
       
    29 #include <HbTranslator>
       
    30 #include <HbLineEdit>
       
    31 #include <HbAction>
       
    32 
       
    33 // User includes
       
    34 #include "eapusernamepwddialog.h"
       
    35 #include "OstTraceDefinitions.h"
       
    36 #ifdef OST_TRACE_COMPILER_IN_USE
       
    37 #include "eapusernamepwddialogTraces.h"
       
    38 #endif
       
    39 
       
    40 /*!
       
    41  * \class EapUsernamePwdDialog
       
    42  * \brief Implements Username Password Input Dialog. 
       
    43  */
       
    44 
       
    45 // External function prototypes
       
    46 
       
    47 // Local constants
       
    48  
       
    49 // ======== LOCAL FUNCTIONS ========
       
    50 
       
    51 // ======== MEMBER FUNCTIONS ========
       
    52 
       
    53 /*!
       
    54  * Constructor.
       
    55  * 
       
    56  * @param [in]  parameters Parameters for the Constructor.
       
    57  */
       
    58 EapUsernamePwdDialog::EapUsernamePwdDialog(const QVariantMap &parameters) 
       
    59  :mEdit1(NULL), 
       
    60  mEdit2(NULL), 
       
    61  mUnameValidator(NULL),
       
    62  mPwdValidator(NULL),
       
    63  mTranslator(new HbTranslator("eapprompts")),
       
    64  mClose(false),
       
    65  mOkActionPressed(false)
       
    66 {
       
    67     OstTraceFunctionEntry0( EAPUSERNAMEPWDDIALOG_EAPUSERNAMEPWDDIALOG_ENTRY );
       
    68     qDebug("EapUsernamePwdDialog::EapUsernamePwdDialog ENTER");
       
    69         
       
    70     createDialog(parameters);
       
    71         
       
    72     OstTraceFunctionExit0( EAPUSERNAMEPWDDIALOG_EAPUSERNAMEPWDDIALOG_EXIT );
       
    73     qDebug("EapUsernamePwdDialog::EapUsernamePwdDialog EXIT");
       
    74 }
       
    75     
       
    76 /*!
       
    77  * The construction of the dialog
       
    78  *
       
    79  * @param [in] parameters Parameters for the Construction of the dialog.
       
    80  */ 
       
    81 void EapUsernamePwdDialog::createDialog(const QVariantMap &parameters )
       
    82 {
       
    83     OstTraceFunctionEntry0( EAPUSERNAMEPWDDIALOG_CREATEDIALOG_ENTRY );
       
    84     qDebug("EapUsernamePwdDialog::createDialog ENTER");
       
    85      
       
    86     QString keyauthmethod("authmethod");    
       
    87     QString keyuname("username");
       
    88     QString keyeaptype("eaptype");
       
    89         
       
    90     QString unamestr;
       
    91     QString authMethodstr;
       
    92     
       
    93     //Get default username (if exists) and 
       
    94     //auth method strings from parameters   
       
    95     if ( parameters.empty() == false ) {
       
    96         if ( parameters.contains(keyuname) ) {
       
    97             QVariant variant = parameters.value(keyuname);
       
    98             unamestr = variant.toString();
       
    99             }
       
   100         if ( parameters.contains(keyauthmethod) ) {
       
   101             QVariant variant = parameters.value(keyauthmethod);
       
   102             authMethodstr = variant.toString();
       
   103             }    
       
   104         } 
       
   105     
       
   106     QString labelText1(HbParameterLengthLimiter(hbTrId("txt_occ_dialog_1_user_name")).arg(authMethodstr));
       
   107     QString labelText2(HbParameterLengthLimiter(hbTrId("txt_occ_dialog_password")));
       
   108     
       
   109     //Set the dialog to be on the screen until user reacts
       
   110     //by pressing any of the Action buttons
       
   111     this->setModal(true);
       
   112     this->setTimeout(HbPopup::NoTimeout);
       
   113     this->setDismissPolicy(HbPopup::NoDismiss);    
       
   114     this->setAdditionalRowVisible(true);
       
   115     
       
   116     //Set the first Line Edit (user name) to be on the screen
       
   117     this->setPromptText(labelText1, 0);   
       
   118     mEdit1 = this->lineEdit(0);
       
   119     //Set default user name string
       
   120     mEdit1->setText(unamestr);
       
   121     
       
   122     //Set the second Line Edit (password) to be on the screen also
       
   123     this->setPromptText(labelText2, 1);   
       
   124     mEdit2 = this->lineEdit(1);        
       
   125     
       
   126     //Get the EAP type for the Line Edits (Validator)
       
   127     QByteArray ba;
       
   128     if ( parameters.contains(keyeaptype) ) {
       
   129         QVariant variant = parameters.value(keyeaptype);
       
   130         ba = variant.toByteArray();
       
   131         } 
       
   132     Q_ASSERT( ba.isEmpty() == false );    
       
   133     EapQtExpandedEapType e_type(ba);
       
   134     EapQtConfigInterface eap_config_if;
       
   135     
       
   136     mUnameValidator.reset(eap_config_if.validatorEap(e_type,
       
   137                 EapQtConfig::Username));
       
   138     Q_ASSERT( mUnameValidator.isNull() == false );
       
   139    
       
   140     mUnameValidator->updateEditor(mEdit1);
       
   141         
       
   142     mPwdValidator.reset(eap_config_if.validatorEap(e_type,
       
   143                 EapQtConfig::Password));
       
   144     Q_ASSERT( mPwdValidator.isNull() == false );
       
   145         
       
   146     mPwdValidator->updateEditor(mEdit2);
       
   147     
       
   148     //Remove all default actions from the dialog 
       
   149     QList<QAction*> action_list = this->actions();    
       
   150     for ( int i = 0; i < action_list.count(); i++ ) {
       
   151         this->removeAction(action_list.at(i));
       
   152         } 
       
   153     
       
   154     //Add a new Ok button action 
       
   155     HbAction* actionOk = new HbAction(hbTrId("txt_common_button_ok"),this); 
       
   156     this->addAction(actionOk);
       
   157     //Add a new Cancel button action
       
   158     HbAction* actionCancel = new HbAction(hbTrId("txt_common_button_cancel"),this);
       
   159     this->addAction( actionCancel );    
       
   160     
       
   161     //Disconnect action Ok from the default SLOT and connect to 
       
   162     //a SLOT owned by this class 
       
   163     disconnect(actionOk, SIGNAL(triggered()),this, SLOT(close()));
       
   164     bool connected = connect(actionOk, SIGNAL(triggered()), this, SLOT(okPressed()));
       
   165     Q_ASSERT(connected == true);
       
   166     
       
   167     //Disconnect action Cancel from the default SLOT and connect to 
       
   168     //a SLOT owned by this class 
       
   169     disconnect(actionCancel, SIGNAL(triggered()),this, SLOT(close()));
       
   170     connected = connect(actionCancel, SIGNAL(triggered()), this, SLOT(cancelPressed()));
       
   171     Q_ASSERT(connected == true);
       
   172     
       
   173     // Connect the about to close and hide signals, so that we are able to inform 
       
   174     // the caller that the dialog was closed   
       
   175     connected = connect(this, SIGNAL(aboutToClose()), this, SLOT(closingDialog()));
       
   176     Q_ASSERT(connected == true);
       
   177     connected = connect(this, SIGNAL(aboutToHide()), this, SLOT(closingDialog()));
       
   178     Q_ASSERT(connected == true);
       
   179    
       
   180     OstTraceFunctionExit0( DUP1_EAPUSERNAMEPWDDIALOG_CREATEDIALOG_EXIT );
       
   181     qDebug("EapUsernamePwdDialog::createDialog EXIT");
       
   182 }
       
   183 
       
   184 /*!
       
   185  * Destructor
       
   186  */
       
   187 EapUsernamePwdDialog::~EapUsernamePwdDialog()
       
   188 {
       
   189     OstTraceFunctionEntry0( EAPUSERNAMEPWDDIALOG_DEAPUSERNAMEPWDDIALOG_ENTRY );
       
   190     qDebug("EapUsernamePwdDialog::~EapUsernamePwdDialog");
       
   191     
       
   192     //The dialog widgets are deleted as the dialog is deleted
       
   193     // mPwdValidator:   scoped pointer deleted automatically
       
   194     // mUnameValidator: scoped pointer deleted automatically
       
   195     
       
   196     OstTraceFunctionExit0( EAPUSERNAMEPWDDIALOG_DEAPUSERNAMEPWDDIALOG_EXIT );
       
   197 }
       
   198 
       
   199 /*!
       
   200  * Line edit validator
       
   201  *
       
   202  * @return true if content is valid.
       
   203  */
       
   204 bool EapUsernamePwdDialog::validate() const
       
   205 {
       
   206     qDebug("EapUsernamePwdDialog::validate ENTER");
       
   207     
       
   208     bool valid = false;
       
   209 
       
   210     if ( mUnameValidator->validate(mEdit1->text())== EapQtValidator::StatusOk   && 
       
   211          mPwdValidator->validate(mEdit2->text()) == EapQtValidator::StatusOk ) {
       
   212     
       
   213         qDebug("EapUsernamePwdDialog::validate(): returns TRUE");
       
   214         valid = true;
       
   215     }
       
   216 
       
   217     qDebug("EapUsernamePwdDialog::validate EXIT");
       
   218     return valid;
       
   219 }
       
   220 
       
   221 /*!
       
   222  * Function is called when the Ok Action button is pressed
       
   223  */
       
   224 void EapUsernamePwdDialog::okPressed()
       
   225 {
       
   226     OstTraceFunctionEntry0( EAPUSERNAMEPWDDIALOG_OKPRESSED_ENTRY );
       
   227     qDebug("EapUsernamePwdDialog::okPressed ENTER");
       
   228     
       
   229     if ( validate() == true && mOkActionPressed == false ) {
       
   230         
       
   231             mOkActionPressed = true;
       
   232             
       
   233             QVariantMap data;
       
   234      
       
   235             data["username"] = mEdit1->text();
       
   236             data["password"] = mEdit2->text();
       
   237       
       
   238             qDebug("EapUsernamePwdDialog::okPressed: emit deviceDialogData");
       
   239     
       
   240             emit deviceDialogData(data); 
       
   241             closeDeviceDialog(true);
       
   242     }
       
   243     OstTraceFunctionExit0( EAPUSERNAMEPWDDIALOG_OKPRESSED_EXIT );
       
   244     qDebug("EapUsernamePwdDialog::okPressed EXIT");
       
   245 }
       
   246 
       
   247 /*!
       
   248  * Function is called when the Cancel Action button is pressed
       
   249  */
       
   250 void EapUsernamePwdDialog::cancelPressed()
       
   251 {
       
   252     OstTraceFunctionEntry0( EAPUSERNAMEPWDDIALOG_CANCELPRESSED_ENTRY );
       
   253     qDebug("EapUsernamePwdDialog::cancelPressed ENTER");
       
   254     
       
   255     if (!mClose) {
       
   256         mClose = true;
       
   257         closeDeviceDialog(true);
       
   258     }   
       
   259     qDebug("EapUsernamePwdDialog::cancelPressed EXIT");
       
   260     OstTraceFunctionExit0( EAPUSERNAMEPWDDIALOG_CANCELPRESSED_EXIT );
       
   261 }
       
   262 
       
   263 /*!
       
   264  * Function is called when the dialog is about to close
       
   265  */
       
   266 void EapUsernamePwdDialog::closingDialog()
       
   267 {
       
   268     OstTraceFunctionEntry0( EAPUSERNAMEPWDDIALOG_CLOSINGDIALOG_ENTRY );
       
   269     qDebug("EapUsernamePwdDialog::closingDialog ENTER");
       
   270      
       
   271     qDebug("EapUsernamePwdDialog::closingDialog EXIT");
       
   272     OstTraceFunctionExit0( EAPUSERNAMEPWDDIALOG_CLOSINGDIALOG_EXIT );
       
   273 }
       
   274 
       
   275 /*!
       
   276  * Device dialog parameters to be set while dialog is displayed.
       
   277  * Not supported. 
       
   278  *
       
   279  * @param [in] parameters NOT USED
       
   280  * @return true always.
       
   281  */  
       
   282 bool EapUsernamePwdDialog::setDeviceDialogParameters
       
   283                 (const QVariantMap &parameters)
       
   284 {
       
   285     OstTraceFunctionEntry0( EAPUSERNAMEPWDDIALOG_SETDEVICEDIALOGPARAMETERS_ENTRY );
       
   286     
       
   287     Q_UNUSED(parameters)
       
   288     // changing the dialog after presenting it is not supported.
       
   289     
       
   290     OstTraceFunctionExit0( EAPUSERNAMEPWDDIALOG_SETDEVICEDIALOGPARAMETERS_EXIT );
       
   291     return true;
       
   292 }
       
   293 
       
   294 /*!
       
   295  * Not supported
       
   296  *
       
   297  * @return 0 always returned.
       
   298  */
       
   299 int EapUsernamePwdDialog::deviceDialogError() const
       
   300 {
       
   301     OstTraceFunctionEntry0( EAPUSERNAMEPWDDIALOG_DEVICEDIALOGERROR_ENTRY );
       
   302     OstTraceFunctionExit0( EAPUSERNAMEPWDDIALOG_DEVICEDIALOGERROR_EXIT);
       
   303     return 0;
       
   304 }
       
   305 
       
   306 /*!
       
   307  * Dialog is closed and the signal about closing is emitted
       
   308  *
       
   309  * @param [in] byClient indicates when the user closes the dialog
       
   310  */
       
   311 void EapUsernamePwdDialog::closeDeviceDialog(bool byClient)
       
   312 {   
       
   313     OstTraceFunctionEntry0( EAPUSERNAMEPWDDIALOG_CLOSEDEVICEDIALOG_ENTRY );
       
   314     qDebug("EapUsernamePwdDialog::closeDeviceDialog ENTER");
       
   315         
       
   316     //If the user closes the dialog, then the deviceDialogClosed is emitted
       
   317     if ( byClient == true )
       
   318         {
       
   319         qDebug("EapUsernamePwdDialog::closeDeviceDialog: emit deviceDialogClosed");
       
   320         emit deviceDialogClosed();
       
   321         }
       
   322     
       
   323     qDebug("EapUsernamePwdDialog::closeDeviceDialog EXIT");
       
   324     OstTraceFunctionExit0( EAPUSERNAMEPWDDIALOG_CLOSEDEVICEDIALOG_EXIT );
       
   325 }
       
   326 
       
   327 /*!
       
   328  * This dialog widget is returned to the caller
       
   329  *
       
   330  * @return this dialog widget
       
   331  */
       
   332 HbPopup *EapUsernamePwdDialog::deviceDialogWidget() const
       
   333 {
       
   334     OstTraceFunctionEntry0( EAPUSERNAMEPWDDIALOG_DEVICEDIALOGWIDGET_ENTRY );
       
   335     OstTraceFunctionExit0( EAPUSERNAMEPWDDIALOG_DEVICEDIALOGWIDGET_EXIT );
       
   336     
       
   337     return const_cast<EapUsernamePwdDialog*>(this);
       
   338 }
       
   339