securitysettings/eapqtdialogs/src/eappasswordquerydialog.cpp
author hgs
Thu, 24 Jun 2010 11:23:08 +0300
changeset 34 ad1f037f1ac2
child 36 c98682f98478
permissions -rw-r--r--
201025
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
34
hgs
parents:
diff changeset
     1
/*
hgs
parents:
diff changeset
     2
* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). 
hgs
parents:
diff changeset
     3
* All rights reserved.
hgs
parents:
diff changeset
     4
* This component and the accompanying materials are made available
hgs
parents:
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
hgs
parents:
diff changeset
     6
* which accompanies this distribution, and is available
hgs
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
hgs
parents:
diff changeset
     8
*
hgs
parents:
diff changeset
     9
* Initial Contributors:
hgs
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
hgs
parents:
diff changeset
    11
*
hgs
parents:
diff changeset
    12
* Contributors:
hgs
parents:
diff changeset
    13
*
hgs
parents:
diff changeset
    14
* Description: EAP Password Query Dialog implementation
hgs
parents:
diff changeset
    15
*
hgs
parents:
diff changeset
    16
*/
hgs
parents:
diff changeset
    17
hgs
parents:
diff changeset
    18
/*
hgs
parents:
diff changeset
    19
* %version: 4 %
hgs
parents:
diff changeset
    20
*/
hgs
parents:
diff changeset
    21
hgs
parents:
diff changeset
    22
#include <HbTranslator>
hgs
parents:
diff changeset
    23
#include <HbLineEdit>
hgs
parents:
diff changeset
    24
#include <HbAction>
hgs
parents:
diff changeset
    25
#include <HbTranslator>
hgs
parents:
diff changeset
    26
#include <HbParameterLengthLimiter>
hgs
parents:
diff changeset
    27
#include <eapqtvalidator.h>
hgs
parents:
diff changeset
    28
#include <eapqtexpandedeaptype.h>
hgs
parents:
diff changeset
    29
#include <eapqtconfiginterface.h>
hgs
parents:
diff changeset
    30
#include <eapqtconfig.h>
hgs
parents:
diff changeset
    31
#include "eappasswordquerydialog.h"
hgs
parents:
diff changeset
    32
#include "OstTraceDefinitions.h"
hgs
parents:
diff changeset
    33
#ifdef OST_TRACE_COMPILER_IN_USE
hgs
parents:
diff changeset
    34
#endif
hgs
parents:
diff changeset
    35
hgs
parents:
diff changeset
    36
hgs
parents:
diff changeset
    37
/**
hgs
parents:
diff changeset
    38
 * The constructor
hgs
parents:
diff changeset
    39
 */
hgs
parents:
diff changeset
    40
EapPasswordQueryDialog::EapPasswordQueryDialog(const QVariantMap &parameters) 
hgs
parents:
diff changeset
    41
 :mEdit(NULL), 
hgs
parents:
diff changeset
    42
 mPwdValidator(NULL),
hgs
parents:
diff changeset
    43
 mTranslator(new HbTranslator("eapprompts")),
hgs
parents:
diff changeset
    44
 mClose(false),
hgs
parents:
diff changeset
    45
 mOkActionPressed(false)
hgs
parents:
diff changeset
    46
{
hgs
parents:
diff changeset
    47
    OstTraceFunctionEntry0( EAPPASSWORDQUERYDIALOG_EAPPASSWORDQUERYDIALOG_ENTRY );
hgs
parents:
diff changeset
    48
    qDebug("EapPasswordQueryDialog::EapPasswordQueryDialog ENTER");
hgs
parents:
diff changeset
    49
hgs
parents:
diff changeset
    50
    createDialog(parameters);
hgs
parents:
diff changeset
    51
        
hgs
parents:
diff changeset
    52
    OstTraceFunctionExit0( EAPPASSWORDQUERYDIALOG_EAPPASSWORDQUERYDIALOG_EXIT );
hgs
parents:
diff changeset
    53
    qDebug("EapPasswordQueryDialog::EapPasswordQueryDialog EXIT");
hgs
parents:
diff changeset
    54
}
hgs
parents:
diff changeset
    55
    
hgs
parents:
diff changeset
    56
/**
hgs
parents:
diff changeset
    57
 * The construction of the dialog
hgs
parents:
diff changeset
    58
 */ 
hgs
parents:
diff changeset
    59
void EapPasswordQueryDialog::createDialog(const QVariantMap &parameters )
hgs
parents:
diff changeset
    60
{
hgs
parents:
diff changeset
    61
    OstTraceFunctionEntry0( EAPPASSWORDQUERYDIALOG_CREATEDIALOG_ENTRY );
hgs
parents:
diff changeset
    62
    qDebug("EapPasswordQueryDialog::createDialog ENTER");
hgs
parents:
diff changeset
    63
          
hgs
parents:
diff changeset
    64
    QString keyeaptype("eaptype"); 
hgs
parents:
diff changeset
    65
    QString keyauthmethod("authmethod");    
hgs
parents:
diff changeset
    66
    QString authMethodstr;
hgs
parents:
diff changeset
    67
    
hgs
parents:
diff changeset
    68
    //Get auth method string from parameters   
hgs
parents:
diff changeset
    69
    if ( parameters.empty() == false ) {
hgs
parents:
diff changeset
    70
        if ( parameters.contains(keyauthmethod) ) {
hgs
parents:
diff changeset
    71
            QVariant variant = parameters.value(keyauthmethod);
hgs
parents:
diff changeset
    72
            authMethodstr = variant.toString();
hgs
parents:
diff changeset
    73
            }    
hgs
parents:
diff changeset
    74
        } 
hgs
parents:
diff changeset
    75
    QString labelText(HbParameterLengthLimiter(
hgs
parents:
diff changeset
    76
        hbTrId("txt_occ_dialog_1_password").arg(authMethodstr)));
hgs
parents:
diff changeset
    77
    
hgs
parents:
diff changeset
    78
    //Set the dialog to be on the screen until user reacts
hgs
parents:
diff changeset
    79
    //by pressing any of the Action buttons
hgs
parents:
diff changeset
    80
    this->setModal(true);
hgs
parents:
diff changeset
    81
    this->setTimeout(HbPopup::NoTimeout);
hgs
parents:
diff changeset
    82
    this->setDismissPolicy(HbPopup::NoDismiss);
hgs
parents:
diff changeset
    83
    this->setPromptText(labelText, 0);   
hgs
parents:
diff changeset
    84
    mEdit = this->lineEdit(0);
hgs
parents:
diff changeset
    85
    mEdit->setEchoMode(HbLineEdit::Password);
hgs
parents:
diff changeset
    86
    
hgs
parents:
diff changeset
    87
    //Get the EAP type from parameters (for the Validator)
hgs
parents:
diff changeset
    88
    QByteArray ba;    
hgs
parents:
diff changeset
    89
    if ( parameters.contains(keyeaptype) ) {
hgs
parents:
diff changeset
    90
        QVariant variant3 = parameters.value(keyeaptype);
hgs
parents:
diff changeset
    91
        ba = variant3.toByteArray();
hgs
parents:
diff changeset
    92
        } 
hgs
parents:
diff changeset
    93
    Q_ASSERT( ba.isEmpty() == false );
hgs
parents:
diff changeset
    94
    
hgs
parents:
diff changeset
    95
    EapQtExpandedEapType e_type(ba);
hgs
parents:
diff changeset
    96
    EapQtConfigInterface eap_config_if;
hgs
parents:
diff changeset
    97
         
hgs
parents:
diff changeset
    98
    mPwdValidator.reset(eap_config_if.validatorEap(e_type,
hgs
parents:
diff changeset
    99
                EapQtConfig::Password)); 
hgs
parents:
diff changeset
   100
    Q_ASSERT( mPwdValidator.isNull() == false );
hgs
parents:
diff changeset
   101
    
hgs
parents:
diff changeset
   102
    mPwdValidator->updateEditor(mEdit);
hgs
parents:
diff changeset
   103
    
hgs
parents:
diff changeset
   104
    //Remove all default actions from the dialog                 
hgs
parents:
diff changeset
   105
    QList<QAction*> action_list = this->actions();
hgs
parents:
diff changeset
   106
    for ( int i = 0; i < action_list.count(); i++ ) {
hgs
parents:
diff changeset
   107
        this->removeAction(action_list.at(i));
hgs
parents:
diff changeset
   108
        } 
hgs
parents:
diff changeset
   109
    
hgs
parents:
diff changeset
   110
    //Add a new Ok button action 
hgs
parents:
diff changeset
   111
    HbAction* actionOk = new HbAction(hbTrId("txt_common_button_ok"),this); 
hgs
parents:
diff changeset
   112
    this->addAction(actionOk);
hgs
parents:
diff changeset
   113
    
hgs
parents:
diff changeset
   114
    //Add a new Cancel button action 
hgs
parents:
diff changeset
   115
    HbAction* actionCancel = new HbAction(hbTrId("txt_common_button_cancel"),this);
hgs
parents:
diff changeset
   116
    this->addAction(actionCancel);    
hgs
parents:
diff changeset
   117
    
hgs
parents:
diff changeset
   118
    //Disconnect action Ok from the default SLOT and connect to 
hgs
parents:
diff changeset
   119
    //a SLOT owned by this class  
hgs
parents:
diff changeset
   120
    disconnect(actionOk, SIGNAL(triggered()),this, SLOT(close()));
hgs
parents:
diff changeset
   121
    bool connected = connect(actionOk, SIGNAL(triggered()), this, SLOT(okPressed()));
hgs
parents:
diff changeset
   122
    Q_ASSERT(connected == true);
hgs
parents:
diff changeset
   123
    
hgs
parents:
diff changeset
   124
    //Disconnect action Cancel from the default SLOT and connect to 
hgs
parents:
diff changeset
   125
    //a SLOT owned by this class  
hgs
parents:
diff changeset
   126
    disconnect(actionCancel, SIGNAL(triggered()),this, SLOT(close()));
hgs
parents:
diff changeset
   127
    connected = connect(actionCancel, SIGNAL(triggered()), this, SLOT(cancelPressed()));
hgs
parents:
diff changeset
   128
    Q_ASSERT(connected == true);
hgs
parents:
diff changeset
   129
    
hgs
parents:
diff changeset
   130
    // Connect the about to close and hide signals, so that we are able to inform 
hgs
parents:
diff changeset
   131
    // the caller that the dialog was closed   
hgs
parents:
diff changeset
   132
    connected = connect(this, SIGNAL(aboutToClose()), this, SLOT(closingDialog()));
hgs
parents:
diff changeset
   133
    Q_ASSERT(connected == true);
hgs
parents:
diff changeset
   134
    connected = connect(this, SIGNAL(aboutToHide()), this, SLOT(closingDialog()));
hgs
parents:
diff changeset
   135
    Q_ASSERT(connected == true);
hgs
parents:
diff changeset
   136
   
hgs
parents:
diff changeset
   137
    OstTraceFunctionExit0( DUP1_EAPPASSWORDQUERYDIALOG_CREATEDIALOG_EXIT );
hgs
parents:
diff changeset
   138
    qDebug("EapPasswordQueryDialog::createDialog EXIT");
hgs
parents:
diff changeset
   139
}
hgs
parents:
diff changeset
   140
hgs
parents:
diff changeset
   141
/**
hgs
parents:
diff changeset
   142
 * Destructor
hgs
parents:
diff changeset
   143
 */
hgs
parents:
diff changeset
   144
EapPasswordQueryDialog::~EapPasswordQueryDialog()
hgs
parents:
diff changeset
   145
{
hgs
parents:
diff changeset
   146
    OstTraceFunctionEntry0( EAPPASSWORDQUERYDIALOG_DEAPPASSWORDQUERYDIALOG_ENTRY );
hgs
parents:
diff changeset
   147
    
hgs
parents:
diff changeset
   148
    // The dialog widgets are deleted as the dialog is deleted        
hgs
parents:
diff changeset
   149
    // mPwdValidator:   scoped pointer deleted automatically
hgs
parents:
diff changeset
   150
    
hgs
parents:
diff changeset
   151
    OstTraceFunctionExit0( EAPPASSWORDQUERYDIALOG_DEAPPASSWORDQUERYDIALOG_EXIT );
hgs
parents:
diff changeset
   152
}
hgs
parents:
diff changeset
   153
hgs
parents:
diff changeset
   154
/**
hgs
parents:
diff changeset
   155
 * Line edit validator
hgs
parents:
diff changeset
   156
 */
hgs
parents:
diff changeset
   157
bool EapPasswordQueryDialog::validate() const
hgs
parents:
diff changeset
   158
{
hgs
parents:
diff changeset
   159
    qDebug("EapPasswordQueryDialog::validate ENTER");
hgs
parents:
diff changeset
   160
    
hgs
parents:
diff changeset
   161
    bool valid = false;
hgs
parents:
diff changeset
   162
hgs
parents:
diff changeset
   163
    if ( mPwdValidator->validate(mEdit->text())== EapQtValidator::StatusOk ) {
hgs
parents:
diff changeset
   164
        
hgs
parents:
diff changeset
   165
        qDebug("EapPasswordQueryDialog::validate(): returns TRUE");
hgs
parents:
diff changeset
   166
        valid = true;
hgs
parents:
diff changeset
   167
    }
hgs
parents:
diff changeset
   168
    
hgs
parents:
diff changeset
   169
    qDebug("EapPasswordQueryDialog::validate EXIT");
hgs
parents:
diff changeset
   170
    return valid;
hgs
parents:
diff changeset
   171
}
hgs
parents:
diff changeset
   172
hgs
parents:
diff changeset
   173
/**
hgs
parents:
diff changeset
   174
 * Function is called when the Ok Action button is pressed
hgs
parents:
diff changeset
   175
 */
hgs
parents:
diff changeset
   176
void EapPasswordQueryDialog::okPressed()
hgs
parents:
diff changeset
   177
{
hgs
parents:
diff changeset
   178
    OstTraceFunctionEntry0( EAPPASSWORDQUERYDIALOG_OKPRESSED_ENTRY );
hgs
parents:
diff changeset
   179
    qDebug("EapPasswordQueryDialog::okPressed ENTER");
hgs
parents:
diff changeset
   180
    
hgs
parents:
diff changeset
   181
    if ( validate() == true && mOkActionPressed == false ) {
hgs
parents:
diff changeset
   182
        
hgs
parents:
diff changeset
   183
            mOkActionPressed = true;
hgs
parents:
diff changeset
   184
            
hgs
parents:
diff changeset
   185
            QVariantMap data;
hgs
parents:
diff changeset
   186
        
hgs
parents:
diff changeset
   187
            data["password"] = mEdit->text();
hgs
parents:
diff changeset
   188
      
hgs
parents:
diff changeset
   189
            qDebug("EapPasswordQueryDialog::okPressed: emit deviceDialogData");
hgs
parents:
diff changeset
   190
    
hgs
parents:
diff changeset
   191
            emit deviceDialogData(data); 
hgs
parents:
diff changeset
   192
            closeDeviceDialog(true);
hgs
parents:
diff changeset
   193
    }
hgs
parents:
diff changeset
   194
    OstTraceFunctionExit0( EAPPASSWORDQUERYDIALOG_OKPRESSED_EXIT );
hgs
parents:
diff changeset
   195
    qDebug("EapPasswordQueryDialog::okPressed EXIT");
hgs
parents:
diff changeset
   196
}
hgs
parents:
diff changeset
   197
hgs
parents:
diff changeset
   198
/**
hgs
parents:
diff changeset
   199
 * Function is called when the Cancel Action button is pressed
hgs
parents:
diff changeset
   200
 */
hgs
parents:
diff changeset
   201
void EapPasswordQueryDialog::cancelPressed()
hgs
parents:
diff changeset
   202
{
hgs
parents:
diff changeset
   203
    OstTraceFunctionEntry0( EAPPASSWORDQUERYDIALOG_CANCELPRESSED_ENTRY );
hgs
parents:
diff changeset
   204
    qDebug("EapPasswordQueryDialog::cancelPressed ENTER");
hgs
parents:
diff changeset
   205
    
hgs
parents:
diff changeset
   206
    if (!mClose) {
hgs
parents:
diff changeset
   207
        mClose = true;
hgs
parents:
diff changeset
   208
        closeDeviceDialog(true);
hgs
parents:
diff changeset
   209
    }   
hgs
parents:
diff changeset
   210
    qDebug("EapPasswordQueryDialog::cancelPressed EXIT");
hgs
parents:
diff changeset
   211
    OstTraceFunctionExit0( EAPPASSWORDQUERYDIALOG_CANCELPRESSED_EXIT );
hgs
parents:
diff changeset
   212
}
hgs
parents:
diff changeset
   213
hgs
parents:
diff changeset
   214
/**
hgs
parents:
diff changeset
   215
 * Function is called when the dialog is about to close
hgs
parents:
diff changeset
   216
 * 
hgs
parents:
diff changeset
   217
 */
hgs
parents:
diff changeset
   218
void EapPasswordQueryDialog::closingDialog()
hgs
parents:
diff changeset
   219
{
hgs
parents:
diff changeset
   220
    OstTraceFunctionEntry0( EAPPASSWORDQUERYDIALOG_CLOSINGDIALOG_ENTRY );
hgs
parents:
diff changeset
   221
    qDebug("EapPasswordQueryDialog::closingDialog ENTER");
hgs
parents:
diff changeset
   222
 
hgs
parents:
diff changeset
   223
    
hgs
parents:
diff changeset
   224
    qDebug("EapPasswordQueryDialog::closingDialog EXIT");
hgs
parents:
diff changeset
   225
    OstTraceFunctionExit0( EAPPASSWORDQUERYDIALOG_CLOSINGDIALOG_EXIT );
hgs
parents:
diff changeset
   226
}
hgs
parents:
diff changeset
   227
hgs
parents:
diff changeset
   228
/**
hgs
parents:
diff changeset
   229
 * Updating the dialog during its showing is not allowed.
hgs
parents:
diff changeset
   230
 */ 
hgs
parents:
diff changeset
   231
bool EapPasswordQueryDialog::setDeviceDialogParameters
hgs
parents:
diff changeset
   232
                (const QVariantMap &parameters)
hgs
parents:
diff changeset
   233
{
hgs
parents:
diff changeset
   234
    OstTraceFunctionEntry0( EAPPASSWORDQUERYDIALOG_SETDEVICEDIALOGPARAMETERS_ENTRY );
hgs
parents:
diff changeset
   235
    
hgs
parents:
diff changeset
   236
    Q_UNUSED(parameters)
hgs
parents:
diff changeset
   237
    // changing the dialog after presenting it is not supported.
hgs
parents:
diff changeset
   238
    
hgs
parents:
diff changeset
   239
    OstTraceFunctionExit0( EAPPASSWORDQUERYDIALOG_SETDEVICEDIALOGPARAMETERS_EXIT );
hgs
parents:
diff changeset
   240
    return true;
hgs
parents:
diff changeset
   241
}
hgs
parents:
diff changeset
   242
hgs
parents:
diff changeset
   243
/**
hgs
parents:
diff changeset
   244
 * Not supported, 0 always returned
hgs
parents:
diff changeset
   245
 */
hgs
parents:
diff changeset
   246
int EapPasswordQueryDialog::deviceDialogError() const
hgs
parents:
diff changeset
   247
{
hgs
parents:
diff changeset
   248
    OstTraceFunctionEntry0( EAPPASSWORDQUERYDIALOG_DEVICEDIALOGERROR_ENTRY );
hgs
parents:
diff changeset
   249
    OstTraceFunctionExit0( EAPPASSWORDQUERYDIALOG_DEVICEDIALOGERROR_EXIT);
hgs
parents:
diff changeset
   250
    return 0;
hgs
parents:
diff changeset
   251
}
hgs
parents:
diff changeset
   252
hgs
parents:
diff changeset
   253
/**
hgs
parents:
diff changeset
   254
 * Dialog is closed and the signal about closing is emitted
hgs
parents:
diff changeset
   255
 */
hgs
parents:
diff changeset
   256
void EapPasswordQueryDialog::closeDeviceDialog(bool byClient)
hgs
parents:
diff changeset
   257
{   
hgs
parents:
diff changeset
   258
    OstTraceFunctionEntry0( EAPPASSWORDQUERYDIALOG_CLOSEDEVICEDIALOG_ENTRY );
hgs
parents:
diff changeset
   259
    qDebug("EapPasswordQueryDialog::closeDeviceDialog ENTER");
hgs
parents:
diff changeset
   260
        
hgs
parents:
diff changeset
   261
    //If the user closes the dialog, then the deviceDialogClosed is emitted
hgs
parents:
diff changeset
   262
    if ( byClient == true )
hgs
parents:
diff changeset
   263
        {
hgs
parents:
diff changeset
   264
        qDebug("EapUsernamePwdDialog::closeDeviceDialog: emit deviceDialogClosed");
hgs
parents:
diff changeset
   265
        emit deviceDialogClosed();
hgs
parents:
diff changeset
   266
        }
hgs
parents:
diff changeset
   267
    
hgs
parents:
diff changeset
   268
    qDebug("EapPasswordQueryDialog::closeDeviceDialog EXIT");
hgs
parents:
diff changeset
   269
    OstTraceFunctionExit0( EAPPASSWORDQUERYDIALOG_CLOSEDEVICEDIALOG_EXIT );
hgs
parents:
diff changeset
   270
}
hgs
parents:
diff changeset
   271
hgs
parents:
diff changeset
   272
/**
hgs
parents:
diff changeset
   273
 * This dialog widget is returned to the caller
hgs
parents:
diff changeset
   274
 */
hgs
parents:
diff changeset
   275
HbPopup *EapPasswordQueryDialog::deviceDialogWidget() const
hgs
parents:
diff changeset
   276
{
hgs
parents:
diff changeset
   277
    OstTraceFunctionEntry0( EAPPASSWORDQUERYDIALOG_DEVICEDIALOGWIDGET_ENTRY );
hgs
parents:
diff changeset
   278
    OstTraceFunctionExit0( EAPPASSWORDQUERYDIALOG_DEVICEDIALOGWIDGET_EXIT );
hgs
parents:
diff changeset
   279
    
hgs
parents:
diff changeset
   280
    return const_cast<EapPasswordQueryDialog*>(this);
hgs
parents:
diff changeset
   281
}
hgs
parents:
diff changeset
   282