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