securitysettings/eapqtdialogs/src/eapquerydialog.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: EAP Challenge query Dialog implementation
       
    15 *
       
    16 */
       
    17 
       
    18 /*
       
    19 * %version: 4 %
       
    20 */
       
    21 
       
    22 // System includes
       
    23 #include <HbLabel>
       
    24 #include <HbAction>
       
    25 #include <HbTranslator>
       
    26 #include <HbParameterLengthLimiter>
       
    27 
       
    28 // User includes
       
    29 #include "eapquerydialog.h"
       
    30 #include "OstTraceDefinitions.h"
       
    31 #ifdef OST_TRACE_COMPILER_IN_USE
       
    32 #include "eapquerydialogTraces.h"
       
    33 #endif
       
    34 
       
    35 /*!
       
    36  * \class EapQueryDialog
       
    37  * \brief Implements EAP Challenge query Dialog. 
       
    38  */
       
    39 
       
    40 // External function prototypes
       
    41 
       
    42 // Local constants
       
    43 
       
    44 //! The index numbers of the button of the dialog
       
    45 static const int okButtonIndex = 1;
       
    46  
       
    47 // ======== LOCAL FUNCTIONS ========
       
    48 
       
    49 // ======== MEMBER FUNCTIONS ========
       
    50 
       
    51 /*!
       
    52  * Constructor.
       
    53  * 
       
    54  * @param [in]  parameters Parameters for the Constructor.
       
    55  */
       
    56 EapQueryDialog::EapQueryDialog(const QVariantMap &parameters)
       
    57 :mTranslator(new HbTranslator("eapprompts")),
       
    58 mOkActionPressed(false)    
       
    59 {
       
    60     OstTraceFunctionEntry0( EAPQUERYDIALOG_EAPQUERYDIALOG_ENTRY );
       
    61     qDebug("EapQueryDialog::EapQueryDialog ENTER");
       
    62         
       
    63     createDialog( parameters );
       
    64     
       
    65     OstTraceFunctionExit0( EAPQUERYDIALOG_EAPQUERYDIALOG_EXIT );
       
    66     qDebug("EapQueryDialog::EapQueryDialog EXIT");
       
    67 }
       
    68 
       
    69 /*!
       
    70  * The construction of the dialog
       
    71  *
       
    72  * @param [in] parameters Parameters for the Construction of the dialog.
       
    73  */ 
       
    74 void EapQueryDialog::createDialog(const QVariantMap &parameters )
       
    75 {
       
    76     OstTraceFunctionEntry0( EAPQUERYDIALOG_CREATEDIALOG_ENTRY );
       
    77     qDebug("EapQueryDialog::createDialog ENTER");
       
    78      
       
    79     QString message;   
       
    80     QString authMethodstr; 
       
    81     QString keyauthmethod("authmethod");  
       
    82     QString keymessage("messagetxt");    
       
    83     QVariant tmpVariant;  
       
    84     
       
    85     //Get auth method and message string from parameters          
       
    86     if ( parameters.empty() == false ) {
       
    87       
       
    88         if ( parameters.contains(keyauthmethod) ) {
       
    89             tmpVariant = parameters.value(keyauthmethod);
       
    90             authMethodstr = tmpVariant.toString();
       
    91             }  
       
    92         if ( parameters.contains(keymessage) ) {
       
    93             tmpVariant = parameters.value(keymessage);
       
    94             message = tmpVariant.toString();
       
    95             }
       
    96         }    
       
    97     
       
    98     QString labelText1(HbParameterLengthLimiter(
       
    99         hbTrId("txt_occ_title_1_message").arg(authMethodstr)));
       
   100     QString labelText2 = message; 
       
   101     
       
   102     //Set the dialog to be on the screen until user reacts
       
   103     //by pressing the Action button
       
   104     this->setModal(true);
       
   105     this->setTimeout(HbPopup::NoTimeout);
       
   106     this->setDismissPolicy(HbPopup::NoDismiss);
       
   107                
       
   108     HbLabel* label1 = new HbLabel;
       
   109     Q_ASSERT(label1 != NULL);
       
   110     label1->setPlainText(labelText1);
       
   111     label1->setFontSpec(HbFontSpec(HbFontSpec::Primary));
       
   112     label1->setTextWrapping(Hb::TextWrapAnywhere);
       
   113     
       
   114     this->setHeadingWidget(label1);       
       
   115     this->setText(labelText2);    
       
   116     this->setIconVisible(false);
       
   117     
       
   118     //Remove all default actions from the dialog     
       
   119     QList<QAction*> action_list = this->actions();
       
   120     for ( int i = 0; i < action_list.count(); i++ ) {
       
   121         this->removeAction(action_list.at(i));
       
   122         }
       
   123         
       
   124     //Add a new Ok button action 
       
   125     HbAction* actionOk = new HbAction(hbTrId("txt_common_button_ok"),this); 
       
   126     this->addAction(actionOk);
       
   127     
       
   128     //Disconnect action Ok from the default SLOT and connect to 
       
   129     //a SLOT owned by this class 
       
   130     disconnect(actionOk, SIGNAL(triggered()),this, SLOT(close()));
       
   131     bool connected = connect(actionOk, SIGNAL(triggered()), this, SLOT(okPressed()));
       
   132     Q_ASSERT(connected == true);
       
   133         
       
   134     // Connect the about to close and hide signals, so that we are able to inform 
       
   135     // the caller that the dialog was closed    
       
   136     connected = connect(this, SIGNAL(aboutToClose()), this, SLOT(closingDialog()));
       
   137     Q_ASSERT(connected == true);
       
   138     connected = connect(this, SIGNAL(aboutToHide()), this, SLOT(closingDialog()));
       
   139     Q_ASSERT(connected == true);
       
   140    
       
   141     OstTraceFunctionExit0( DUP1_EAPQUERYDIALOG_CREATEDIALOG_EXIT );
       
   142     qDebug("EapQueryDialog::createDialog EXIT");
       
   143 }
       
   144 
       
   145 /*!
       
   146  * Destructor.
       
   147  */
       
   148 EapQueryDialog::~EapQueryDialog()
       
   149 {
       
   150     OstTraceFunctionEntry0( EAPQUERYDIALOG_DEAPQUERYDIALOG_ENTRY );
       
   151     
       
   152     // The dialog widgets are deleted as the dialog is deleted
       
   153     
       
   154     OstTraceFunctionExit0( EAPQUERYDIALOG_DEAPQUERYDIALOG_EXIT );
       
   155 }
       
   156 
       
   157 /*!
       
   158  * Function is called when the Ok Action button is pressed
       
   159  */
       
   160 void EapQueryDialog::okPressed()
       
   161 {
       
   162     OstTraceFunctionEntry0( EAPQUERYDIALOG_OKPRESSED_ENTRY );
       
   163     qDebug("EapQueryDialog::okPressed ENTER");
       
   164     
       
   165     if ( mOkActionPressed == false ) {
       
   166         
       
   167             mOkActionPressed = true;
       
   168             
       
   169             QVariantMap data;
       
   170             data["okbutton"] = okButtonIndex;
       
   171             
       
   172             // emit the data of the selected button and close the dialog
       
   173             qDebug("EapQueryDialog::okPressed: emit deviceDialogData");
       
   174             emit deviceDialogData(data);
       
   175     
       
   176             closeDeviceDialog(true);
       
   177     }
       
   178     OstTraceFunctionExit0( EAPQUERYDIALOG_OKPRESSED_EXIT );
       
   179     qDebug("EapQueryDialog::okPressed EXIT");
       
   180 }
       
   181 
       
   182 /*!
       
   183  * Function is called when the dialog is about to close
       
   184  */
       
   185 void EapQueryDialog::closingDialog()
       
   186 {
       
   187     OstTraceFunctionEntry0( EAPQUERYDIALOG_CLOSINGDIALOG_ENTRY );
       
   188     qDebug("EapQueryDialog::closingDialog ENTER");
       
   189  
       
   190     qDebug("EapQueryDialog::closingDialog EXIT");
       
   191     OstTraceFunctionExit0( EAPQUERYDIALOG_CLOSINGDIALOG_EXIT );
       
   192 }
       
   193 
       
   194 /*!
       
   195  * Device dialog parameters to be set while dialog is displayed.
       
   196  * Not supported. 
       
   197  *
       
   198  * @param [in] parameters NOT USED
       
   199  * @return true always.
       
   200  */  
       
   201 bool EapQueryDialog::setDeviceDialogParameters
       
   202                 (const QVariantMap &parameters)
       
   203 {
       
   204     OstTraceFunctionEntry0( EAPQUERYDIALOG_SETDEVICEDIALOGPARAMETERS_ENTRY );
       
   205     
       
   206     Q_UNUSED(parameters)
       
   207     // changing the dialog after presenting it is not supported.
       
   208     
       
   209     OstTraceFunctionExit0( EAPQUERYDIALOG_SETDEVICEDIALOGPARAMETERS_EXIT );
       
   210     return true;
       
   211 }
       
   212 
       
   213 /*!
       
   214  * Not supported
       
   215  *
       
   216  * @return 0 always returned.
       
   217  */
       
   218 int EapQueryDialog::deviceDialogError() const
       
   219 {
       
   220     OstTraceFunctionEntry0( EAPQUERYDIALOG_DEVICEDIALOGERROR_ENTRY );
       
   221     OstTraceFunctionExit0( EAPQUERYDIALOG_DEVICEDIALOGERROR_EXIT);
       
   222     return 0;
       
   223 }
       
   224 
       
   225 /*!
       
   226  * Dialog is closed and the signal about closing is emitted
       
   227  *
       
   228  * @param [in] byClient indicates when the user closes the dialog
       
   229  */
       
   230 void EapQueryDialog::closeDeviceDialog(bool byClient)
       
   231 {   
       
   232     OstTraceFunctionEntry0( EAPQUERYDIALOG_CLOSEDEVICEDIALOG_ENTRY );
       
   233     qDebug("EapQueryDialog::closeDeviceDialog ENTER");
       
   234         
       
   235     //If the user closes the dialog, then the deviceDialogClosed is emitted
       
   236     if ( byClient == true ) {
       
   237         emit deviceDialogClosed();
       
   238     }
       
   239     
       
   240     qDebug("EapQueryDialog::closeDeviceDialog EXIT");
       
   241     OstTraceFunctionExit0( EAPQUERYDIALOG_CLOSEDEVICEDIALOG_EXIT );
       
   242 }
       
   243 
       
   244 /*!
       
   245  * This dialog widget is returned to the caller
       
   246  *
       
   247  * @return this dialog widget
       
   248  */
       
   249 HbPopup *EapQueryDialog::deviceDialogWidget() const
       
   250 {
       
   251     OstTraceFunctionEntry0( EAPQUERYDIALOG_DEVICEDIALOGWIDGET_ENTRY );
       
   252     qDebug("EapQueryDialog::deviceDialogWidget ENTER");
       
   253     
       
   254     qDebug("EapQueryDialog::deviceDialogWidget EXIT");
       
   255     OstTraceFunctionExit0( EAPQUERYDIALOG_DEVICEDIALOGWIDGET_EXIT );
       
   256     
       
   257     return const_cast<EapQueryDialog*>(this);
       
   258 }
       
   259