securitysettings/eapqtdialogs/src/eappasswordquerydialog.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: Prompt Dialog implementation
       
    15 *
       
    16 */
       
    17 
       
    18 #include <eapqtvalidator.h>
       
    19 #include <eapqtexpandedeaptype.h>
       
    20 #include <eapqtconfiginterface.h>
       
    21 #include <eapqtconfig.h>
       
    22 #include "eappasswordquerydialog.h"
       
    23 #include "OstTraceDefinitions.h"
       
    24 #ifdef OST_TRACE_COMPILER_IN_USE
       
    25 #endif
       
    26 
       
    27 
       
    28 /**
       
    29  * The constructor
       
    30  */
       
    31 EapPasswordQueryDialog::EapPasswordQueryDialog(const QVariantMap &parameters) 
       
    32  :mEdit(NULL), 
       
    33  mPwdValidator(NULL),
       
    34  mActionOk(NULL)
       
    35 {
       
    36     OstTraceFunctionEntry0( EAPPASSWORDQUERYDIALOG_EAPPASSWORDQUERYDIALOG_ENTRY );
       
    37     qDebug("EapPasswordQueryDialog::EapPasswordQueryDialog ENTER");
       
    38 
       
    39     createDialog(parameters);
       
    40     
       
    41     mClose = false;
       
    42     mOkActionPressed = false;
       
    43     
       
    44     OstTraceFunctionExit0( EAPPASSWORDQUERYDIALOG_EAPPASSWORDQUERYDIALOG_EXIT );
       
    45     qDebug("EapPasswordQueryDialog::EapPasswordQueryDialog EXIT");
       
    46 }
       
    47     
       
    48 /**
       
    49  * The construction of the dialog
       
    50  */ 
       
    51 void EapPasswordQueryDialog::createDialog(const QVariantMap &parameters )
       
    52 {
       
    53     OstTraceFunctionEntry0( EAPPASSWORDQUERYDIALOG_CREATEDIALOG_ENTRY );
       
    54     qDebug("EapPasswordQueryDialog::createDialog ENTER");
       
    55          
       
    56     QString keyeaptype = QString("eaptype"); 
       
    57     QString keyauthmethod = QString("authmethod");    
       
    58     QString authMethodstr = QString("FOO");
       
    59        
       
    60     if ( parameters.empty() == false ) {
       
    61         if ( parameters.contains(keyauthmethod) ) {
       
    62             QVariant variant = parameters.value(keyauthmethod);
       
    63             authMethodstr = variant.toString();
       
    64             }    
       
    65         } 
       
    66     QString labelText = QString(hbTrId("txt_occ_dialog_1_password").arg(authMethodstr));
       
    67     
       
    68     //Set the dialog to be on the screen until user reacts
       
    69     //by pressing any of the Action buttons
       
    70     this->setModal(true);
       
    71     this->setTimeout(HbPopup::NoTimeout);
       
    72     this->setDismissPolicy(HbPopup::NoDismiss);
       
    73     this->setPromptText(labelText, 0);   
       
    74     mEdit = this->lineEdit(0);
       
    75     mEdit->setEchoMode(HbLineEdit::Password);
       
    76     
       
    77     QByteArray ba;
       
    78     
       
    79     if ( parameters.contains(keyeaptype) ) {
       
    80         QVariant variant3 = parameters.value(keyeaptype);
       
    81         ba = variant3.toByteArray();
       
    82         } 
       
    83     Q_ASSERT( ba.isEmpty() == false );
       
    84     
       
    85     EapQtExpandedEapType e_type(ba);
       
    86     EapQtConfigInterface eap_config_if;
       
    87          
       
    88     mPwdValidator = eap_config_if.validatorEap(e_type,
       
    89                 EapQtConfig::Password); 
       
    90     
       
    91     mPwdValidator->updateEditor(mEdit);
       
    92                 
       
    93     QList<QAction*> action_list = this->actions();
       
    94         
       
    95     for ( int i = 0; i < action_list.count(); i++ ) {
       
    96         this->removeAction(action_list.at(i));
       
    97         } 
       
    98     
       
    99     mActionOk = new HbAction(hbTrId("txt_common_button_ok"),this); 
       
   100     this->addAction(mActionOk);
       
   101     
       
   102     HbAction* actionCancel = new HbAction(hbTrId("txt_common_button_cancel"),this);
       
   103     this->addAction(actionCancel);    
       
   104      
       
   105     disconnect(mActionOk, SIGNAL(triggered()),this, SLOT(close()));
       
   106     bool connected = connect(mActionOk, SIGNAL(triggered()), this, SLOT(okPressed()));
       
   107     Q_ASSERT(connected == true);
       
   108     
       
   109     disconnect(actionCancel, SIGNAL(triggered()),this, SLOT(close()));
       
   110     connected = connect(actionCancel, SIGNAL(triggered()), this, SLOT(cancelPressed()));
       
   111     Q_ASSERT(connected == true);
       
   112     
       
   113     // Connect the about to close and hide signals, so that we are able to inform 
       
   114     // the caller that the dialog was closed   
       
   115     connected = connect(this, SIGNAL(aboutToClose()), this, SLOT(closingDialog()));
       
   116     Q_ASSERT(connected == true);
       
   117     connected = connect(this, SIGNAL(aboutToHide()), this, SLOT(closingDialog()));
       
   118     Q_ASSERT(connected == true);
       
   119    
       
   120     OstTraceFunctionExit0( DUP1_EAPPASSWORDQUERYDIALOG_CREATEDIALOG_EXIT );
       
   121     qDebug("EapPasswordQueryDialog::createDialog EXIT");
       
   122 }
       
   123 
       
   124 /**
       
   125  * Destructor
       
   126  */
       
   127 EapPasswordQueryDialog::~EapPasswordQueryDialog()
       
   128 {
       
   129     OstTraceFunctionEntry0( EAPPASSWORDQUERYDIALOG_DEAPPASSWORDQUERYDIALOG_ENTRY );
       
   130     
       
   131     // The dialog widgets are deleted as the dialog is deleted        
       
   132     delete mPwdValidator;
       
   133     
       
   134     OstTraceFunctionExit0( EAPPASSWORDQUERYDIALOG_DEAPPASSWORDQUERYDIALOG_EXIT );
       
   135 }
       
   136 
       
   137 /**
       
   138  * Line edit validator
       
   139  */
       
   140 bool EapPasswordQueryDialog::validate() const
       
   141 {
       
   142     qDebug("EapPasswordQueryDialog::validate ENTER");
       
   143     
       
   144     bool valid = false;
       
   145 
       
   146     if ( mPwdValidator->validate(mEdit->text())== EapQtValidator::StatusOk ) {
       
   147         
       
   148         qDebug("EapPasswordQueryDialog::validate(): returns TRUE");
       
   149         valid = true;
       
   150     }
       
   151     
       
   152     qDebug("EapPasswordQueryDialog::validate EXIT");
       
   153     return valid;
       
   154 }
       
   155 
       
   156 
       
   157 /**
       
   158  * Function is called when the Ok Action button is pressed
       
   159  */
       
   160 void EapPasswordQueryDialog::okPressed()
       
   161 {
       
   162     OstTraceFunctionEntry0( EAPPASSWORDQUERYDIALOG_OKPRESSED_ENTRY );
       
   163     qDebug("EapPasswordQueryDialog::okPressed ENTER");
       
   164     
       
   165     if ( validate() == true && mOkActionPressed == false ) {
       
   166         
       
   167             mOkActionPressed = true;
       
   168             
       
   169             QVariantMap data;
       
   170     
       
   171             QString editStr = mEdit->text();
       
   172             
       
   173             QVariant variant(editStr);
       
   174     
       
   175             data["password"] = variant;
       
   176       
       
   177             qDebug("EapPasswordQueryDialog::okPressed: emit deviceDialogData");
       
   178     
       
   179             emit deviceDialogData(data); 
       
   180             closeDeviceDialog(true);
       
   181     }
       
   182     OstTraceFunctionExit0( EAPPASSWORDQUERYDIALOG_OKPRESSED_EXIT );
       
   183     qDebug("EapPasswordQueryDialog::okPressed EXIT");
       
   184 }
       
   185 
       
   186 /**
       
   187  * Function is called when the Cancel Action button is pressed
       
   188  */
       
   189 void EapPasswordQueryDialog::cancelPressed()
       
   190 {
       
   191     OstTraceFunctionEntry0( EAPPASSWORDQUERYDIALOG_CANCELPRESSED_ENTRY );
       
   192     qDebug("EapPasswordQueryDialog::cancelPressed ENTER");
       
   193     
       
   194     if (!mClose) {
       
   195         mClose = true;
       
   196         closeDeviceDialog(true);
       
   197     }   
       
   198     qDebug("EapPasswordQueryDialog::cancelPressed EXIT");
       
   199     OstTraceFunctionExit0( EAPPASSWORDQUERYDIALOG_CANCELPRESSED_EXIT );
       
   200 }
       
   201 
       
   202 /**
       
   203  * Function is called when the dialog is about to close
       
   204  * 
       
   205  */
       
   206 void EapPasswordQueryDialog::closingDialog()
       
   207 {
       
   208     OstTraceFunctionEntry0( EAPPASSWORDQUERYDIALOG_CLOSINGDIALOG_ENTRY );
       
   209     qDebug("EapPasswordQueryDialog::closingDialog ENTER");
       
   210  
       
   211     closeDeviceDialog(false);
       
   212     
       
   213     qDebug("EapPasswordQueryDialog::closingDialog EXIT");
       
   214     OstTraceFunctionExit0( EAPPASSWORDQUERYDIALOG_CLOSINGDIALOG_EXIT );
       
   215 }
       
   216 
       
   217 /**
       
   218  * Updating the dialog during its showing is not allowed.
       
   219  */ 
       
   220 bool EapPasswordQueryDialog::setDeviceDialogParameters
       
   221                 (const QVariantMap &parameters)
       
   222 {
       
   223     OstTraceFunctionEntry0( EAPPASSWORDQUERYDIALOG_SETDEVICEDIALOGPARAMETERS_ENTRY );
       
   224     
       
   225     Q_UNUSED(parameters)
       
   226     // changing the dialog after presenting it is not supported.
       
   227     
       
   228     OstTraceFunctionExit0( EAPPASSWORDQUERYDIALOG_SETDEVICEDIALOGPARAMETERS_EXIT );
       
   229     return true;
       
   230 }
       
   231 
       
   232 /**
       
   233  * Not supported, 0 always returned
       
   234  */
       
   235 int EapPasswordQueryDialog::deviceDialogError() const
       
   236 {
       
   237     OstTraceFunctionEntry0( EAPPASSWORDQUERYDIALOG_DEVICEDIALOGERROR_ENTRY );
       
   238     OstTraceFunctionExit0( EAPPASSWORDQUERYDIALOG_DEVICEDIALOGERROR_EXIT);
       
   239     return 0;
       
   240 }
       
   241 
       
   242 /**
       
   243  * Dialog is closed and the signal about closing is emitted
       
   244  */
       
   245 void EapPasswordQueryDialog::closeDeviceDialog(bool byClient)
       
   246 {   
       
   247     OstTraceFunctionEntry0( EAPPASSWORDQUERYDIALOG_CLOSEDEVICEDIALOG_ENTRY );
       
   248     qDebug("EapPasswordQueryDialog::closeDeviceDialog ENTER");
       
   249         
       
   250     //If the user closes the dialog, then the deviceDialogClosed is emitted
       
   251     if ( byClient == true )
       
   252         {
       
   253         qDebug("EapUsernamePwdDialog::closeDeviceDialog: emit deviceDialogClosed");
       
   254         emit deviceDialogClosed();
       
   255         }
       
   256     
       
   257     qDebug("EapPasswordQueryDialog::closeDeviceDialog EXIT");
       
   258     OstTraceFunctionExit0( EAPPASSWORDQUERYDIALOG_CLOSEDEVICEDIALOG_EXIT );
       
   259 }
       
   260 
       
   261 /**
       
   262  * This dialog widget is returned to the caller
       
   263  */
       
   264 HbPopup *EapPasswordQueryDialog::deviceDialogWidget() const
       
   265 {
       
   266     OstTraceFunctionEntry0( EAPPASSWORDQUERYDIALOG_DEVICEDIALOGWIDGET_ENTRY );
       
   267     OstTraceFunctionExit0( EAPPASSWORDQUERYDIALOG_DEVICEDIALOGWIDGET_EXIT );
       
   268     
       
   269     return const_cast<EapPasswordQueryDialog*>(this);
       
   270 }
       
   271