securitysettings/eapqtdialogs/src/eapfastcreatemasterkeyquerydialog.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: Fast Create Master Key Query Dialog implementation
       
    15 *
       
    16 */
       
    17 
       
    18 /*
       
    19 * %version: 4 %
       
    20 */
       
    21 
       
    22 #include <HbLineEdit>
       
    23 #include <HbAction>
       
    24 #include <HbMessageBox>
       
    25 #include <HbTranslator>
       
    26 #include <eapqtvalidator.h>
       
    27 #include <eapqtexpandedeaptype.h>
       
    28 #include <eapqtconfiginterface.h>
       
    29 #include <eapqtconfig.h>
       
    30 #include "eapfastcreatemasterkeyquerydialog.h"
       
    31 #include "OstTraceDefinitions.h"
       
    32 #ifdef OST_TRACE_COMPILER_IN_USE
       
    33 #endif
       
    34 
       
    35 
       
    36 /**
       
    37  * The constructor
       
    38  */
       
    39 EapFastCreateMasterKeyQueryDialog::EapFastCreateMasterKeyQueryDialog(const QVariantMap &parameters) 
       
    40  :mEdit1(NULL), 
       
    41   mEdit2(NULL), 
       
    42   mPwdValidator(NULL),
       
    43   mTranslator(new HbTranslator("eapprompts")),
       
    44   mErrMsgTranslator(new HbTranslator("cpdestinationplugin")),
       
    45   mClose(false),
       
    46   mOkActionPressed(false)
       
    47 {
       
    48     OstTraceFunctionEntry0( EAPFASTCREATEMASTERKEYQUERYDIALOG_EAPFASTCREATEMASTERKEYQUERYDIALOG_ENTRY );
       
    49     qDebug("EapFastCreateMasterKeyQueryDialog::EapFastCreateMasterKeyQueryDialog ENTER");
       
    50        
       
    51     createDialog(parameters);
       
    52         
       
    53     OstTraceFunctionExit0( EAPFASTCREATEMASTERKEYQUERYDIALOG_EAPFASTCREATEMASTERKEYQUERYDIALOG_EXIT );
       
    54     qDebug("EapFastCreateMasterKeyQueryDialog::EapFastCreateMasterKeyQueryDialog EXIT");
       
    55 }
       
    56     
       
    57 /**
       
    58  * The construction of the dialog
       
    59  */ 
       
    60 void EapFastCreateMasterKeyQueryDialog::createDialog(const QVariantMap &parameters )
       
    61 {
       
    62     OstTraceFunctionEntry0( EAPFASTCREATEMASTERKEYQUERYDIALOG_CREATEDIALOG_ENTRY );
       
    63     qDebug("EapFastCreateMasterKeyQueryDialog::createDialog ENTER");
       
    64     
       
    65     Q_UNUSED(parameters)
       
    66     
       
    67     QString labelText1(hbTrId("txt_occ_dialog_create_password_for_encrypted_pac_s"));
       
    68     QString labelText2(hbTrId("txt_occ_dialog_verify_password"));
       
    69         
       
    70     //Set the dialog to be on the screen until user reacts
       
    71     //by pressing any of the Action buttons
       
    72     this->setModal(true);
       
    73     this->setTimeout(HbPopup::NoTimeout);
       
    74     this->setDismissPolicy(HbPopup::NoDismiss);    
       
    75     this->setAdditionalRowVisible(true);
       
    76     
       
    77     this->setPromptText(labelText1, 0);   
       
    78     mEdit1 = this->lineEdit(0);
       
    79     mEdit1->setEchoMode(HbLineEdit::Password);
       
    80     
       
    81     this->setPromptText(labelText2, 1);   
       
    82     mEdit2 = this->lineEdit(1);        
       
    83     mEdit2->setEchoMode(HbLineEdit::Password);
       
    84     
       
    85     EapQtConfigInterface eap_config_if;
       
    86     
       
    87     mPwdValidator.reset( eap_config_if.validatorPacStore(
       
    88                 EapQtPacStoreConfig::PacStorePassword) ); 
       
    89     Q_ASSERT( mPwdValidator.isNull() == false );                
       
    90                      
       
    91     mPwdValidator->updateEditor(mEdit1);
       
    92     
       
    93    
       
    94     //Remove all default actions from the dialog  
       
    95     QList<QAction*> action_list = this->actions();        
       
    96     for ( int i = 0; i < action_list.count(); i++ ) {
       
    97         this->removeAction(action_list.at(i));
       
    98         } 
       
    99     
       
   100     //Add a new Ok button action 
       
   101     HbAction* actionOk = new HbAction(hbTrId("txt_common_button_ok"),this); 
       
   102     this->addAction(actionOk);
       
   103     
       
   104     //Add a new Cancel button action 
       
   105     HbAction* actionCancel = new HbAction(hbTrId("txt_common_button_cancel"),this);
       
   106     this->addAction(actionCancel);    
       
   107     
       
   108     //Disconnect action Ok from the default SLOT and connect to 
       
   109     //a SLOT owned by this class    
       
   110     disconnect(actionOk, SIGNAL(triggered()),this, SLOT(close()));
       
   111     bool connected = connect(actionOk, SIGNAL(triggered()), this, SLOT(okPressed()));
       
   112     Q_ASSERT(connected == true);
       
   113     
       
   114     //Disconnect action Cancel from the default SLOT and connect to 
       
   115     //a SLOT owned by this class  
       
   116     disconnect(actionCancel, SIGNAL(triggered()),this, SLOT(close()));
       
   117     connected = connect(actionCancel, SIGNAL(triggered()), this, SLOT(cancelPressed()));
       
   118     Q_ASSERT(connected == true);
       
   119     
       
   120     // Connect the about to close and hide signals, so that we are able to inform 
       
   121     // the caller that the dialog was closed   
       
   122     connected = connect(this, SIGNAL(aboutToClose()), this, SLOT(closingDialog()));
       
   123     Q_ASSERT(connected == true);
       
   124     connected = connect(this, SIGNAL(aboutToHide()), this, SLOT(closingDialog()));
       
   125     Q_ASSERT(connected == true);
       
   126    
       
   127     OstTraceFunctionExit0( DUP1_EAPFASTCREATEMASTERKEYQUERYDIALOG_CREATEDIALOG_EXIT );
       
   128     qDebug("EapFastCreateMasterKeyQueryDialog::createDialog EXIT");
       
   129 }
       
   130 
       
   131 /**
       
   132  * Destructor
       
   133  */
       
   134 EapFastCreateMasterKeyQueryDialog::~EapFastCreateMasterKeyQueryDialog()
       
   135 {
       
   136     OstTraceFunctionEntry0( EAPFASTCREATEMASTERKEYQUERYDIALOG_DEAPFASTCREATEMASTERKEYQUERYDIALOG_ENTRY );
       
   137     qDebug("EapFastCreateMasterKeyQueryDialog::~EapFastCreateMasterKeyQueryDialog");
       
   138     
       
   139     //The dialog widgets are deleted as the dialog is deleted
       
   140     // mPwdValidator:   scoped pointer deleted automatically
       
   141     
       
   142     OstTraceFunctionExit0( EAPFASTCREATEMASTERKEYQUERYDIALOG_DEAPFASTCREATEMASTERKEYQUERYDIALOG_EXIT );
       
   143 }
       
   144 
       
   145 /**
       
   146  * Line edit validator
       
   147  */
       
   148 bool EapFastCreateMasterKeyQueryDialog::validate() const
       
   149 {
       
   150     qDebug("EapFastCreateMasterKeyQueryDialog::validate");
       
   151     
       
   152     bool valid = false;
       
   153     
       
   154     EapQtValidator::Status test_status = mPwdValidator->validate(mEdit1->text());
       
   155     
       
   156     if ( mPwdValidator->validate(mEdit1->text())== EapQtValidator::StatusOk &&
       
   157         mEdit1->text() == mEdit2->text()) {
       
   158         qDebug("EapFastCreateMasterKeyQueryDialog::validate: ret val: TRUE");
       
   159         valid = true;
       
   160     }
       
   161     return valid;
       
   162 }
       
   163 
       
   164 /**
       
   165  * Function is called when the Ok Action button is pressed
       
   166  */
       
   167 void EapFastCreateMasterKeyQueryDialog::okPressed()
       
   168 {
       
   169     OstTraceFunctionEntry0( EAPFASTCREATEMASTERKEYQUERYDIALOG_FIRSTBUTTONPRESSED_ENTRY );
       
   170     qDebug("EapFastCreateMasterKeyQueryDialog::okPressed ENTER");
       
   171     
       
   172     if ( validate() == true ) {
       
   173          
       
   174             QVariantMap data;
       
   175        
       
   176             data["password"] = mEdit1->text();
       
   177       
       
   178             qDebug("EapFastCreateMasterKeyQueryDialog::okPressed: emit deviceDialogData");
       
   179     
       
   180             emit deviceDialogData(data); 
       
   181             closeDeviceDialog(true);
       
   182         }
       
   183     else {
       
   184         HbMessageBox *box = 
       
   185             new HbMessageBox(hbTrId("txt_occ_info_passwords_do_not_match_try_again"),
       
   186             HbMessageBox::MessageTypeInformation);
       
   187         box->setAttribute(Qt::WA_DeleteOnClose);
       
   188         box->open();       
       
   189         }
       
   190     OstTraceFunctionExit0( EAPFASTCREATEMASTERKEYQUERYDIALOG_FIRSTBUTTONPRESSED_EXIT );
       
   191     qDebug("EapFastCreateMasterKeyQueryDialog::okPressed EXIT");
       
   192 }
       
   193 
       
   194 /**
       
   195  * Function is called when the Cancel Action button is pressed
       
   196  */
       
   197 void EapFastCreateMasterKeyQueryDialog::cancelPressed()
       
   198 {
       
   199     OstTraceFunctionEntry0( EAPFASTCREATEMASTERKEYQUERYDIALOG_CANCELPRESSED_ENTRY );
       
   200     qDebug("EapFastCreateMasterKeyQueryDialog::cancelPressed ENTER");
       
   201     
       
   202     if (!mClose) {
       
   203         mClose = true;
       
   204         closeDeviceDialog(true);
       
   205     }   
       
   206     qDebug("EapFastCreateMasterKeyQueryDialog::cancelPressed EXIT");
       
   207     OstTraceFunctionExit0( EAPFASTCREATEMASTERKEYQUERYDIALOG_CANCELPRESSED_EXIT );
       
   208 }
       
   209 
       
   210 /**
       
   211  * Function is called when the dialog is about to close
       
   212  * 
       
   213  */
       
   214 void EapFastCreateMasterKeyQueryDialog::closingDialog()
       
   215 {
       
   216     OstTraceFunctionEntry0( EAPFASTCREATEMASTERKEYQUERYDIALOG_CLOSINGDIALOG_ENTRY );
       
   217     qDebug("EapFastCreateMasterKeyQueryDialog::closingDialog ENTER");
       
   218  
       
   219     qDebug("EapFastCreateMasterKeyQueryDialog::closingDialog EXIT");
       
   220     OstTraceFunctionExit0( EAPFASTCREATEMASTERKEYQUERYDIALOG_CLOSINGDIALOG_EXIT );
       
   221 }
       
   222 
       
   223 /**
       
   224  * Updating the dialog during its showing is not allowed.
       
   225  */ 
       
   226 bool EapFastCreateMasterKeyQueryDialog::setDeviceDialogParameters
       
   227                 (const QVariantMap &parameters)
       
   228 {
       
   229     OstTraceFunctionEntry0( EAPFASTCREATEMASTERKEYQUERYDIALOG_SETDEVICEDIALOGPARAMETERS_ENTRY );
       
   230     
       
   231     Q_UNUSED(parameters)
       
   232     // changing the dialog after presenting it is not supported.
       
   233     
       
   234     OstTraceFunctionExit0( EAPFASTCREATEMASTERKEYQUERYDIALOG_SETDEVICEDIALOGPARAMETERS_EXIT );
       
   235     return true;
       
   236 }
       
   237 
       
   238 /**
       
   239  * Not supported, 0 always returned
       
   240  */
       
   241 int EapFastCreateMasterKeyQueryDialog::deviceDialogError() const
       
   242 {
       
   243     OstTraceFunctionEntry0( EAPFASTCREATEMASTERKEYQUERYDIALOG_DEVICEDIALOGERROR_ENTRY );
       
   244     OstTraceFunctionExit0( EAPFASTCREATEMASTERKEYQUERYDIALOG_DEVICEDIALOGERROR_EXIT);
       
   245     return 0;
       
   246 }
       
   247 
       
   248 /**
       
   249  * Dialog is closed and the signal about closing is emitted
       
   250  */
       
   251 void EapFastCreateMasterKeyQueryDialog::closeDeviceDialog(bool byClient)
       
   252 {   
       
   253     OstTraceFunctionEntry0( EAPFASTCREATEMASTERKEYQUERYDIALOG_CLOSEDEVICEDIALOG_ENTRY );
       
   254     qDebug("EapFastCreateMasterKeyQueryDialog::closeDeviceDialog ENTER");
       
   255         
       
   256     //If the user closes the dialog, then the deviceDialogClosed is emitted
       
   257     if ( byClient == true )
       
   258         {
       
   259         qDebug("EapFastCreateMasterKeyQueryDialog::closeDeviceDialog: emit deviceDialogClosed");
       
   260         emit deviceDialogClosed();
       
   261         }
       
   262     
       
   263     qDebug("EapFastCreateMasterKeyQueryDialog::closeDeviceDialog EXIT");
       
   264     OstTraceFunctionExit0( EAPFASTCREATEMASTERKEYQUERYDIALOG_CLOSEDEVICEDIALOG_EXIT );
       
   265 }
       
   266 
       
   267 /**
       
   268  * This dialog widget is returned to the caller
       
   269  */
       
   270 HbPopup *EapFastCreateMasterKeyQueryDialog::deviceDialogWidget() const
       
   271 {
       
   272     OstTraceFunctionEntry0( EAPFASTCREATEMASTERKEYQUERYDIALOG_DEVICEDIALOGWIDGET_ENTRY );
       
   273     OstTraceFunctionExit0( EAPFASTCREATEMASTERKEYQUERYDIALOG_DEVICEDIALOGWIDGET_EXIT );
       
   274     
       
   275     return const_cast<EapFastCreateMasterKeyQueryDialog*>(this);
       
   276 }
       
   277