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