connectionutilities/confirmqueries/src/cellularpromptdialog.cpp
changeset 18 fcbbe021d614
child 41 bbb64eb3bdee
equal deleted inserted replaced
4:77415202bfc8 18:fcbbe021d614
       
     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 #include <QTranslator>
       
    19 #include <QLocale>
       
    20 #include <QList>
       
    21 #include <HbLabel>
       
    22 #include <HbDialog>
       
    23 #include <HbDocumentLoader>
       
    24 #include <HbPushButton>
       
    25 #include <HbView>
       
    26 #include <HbApplication>
       
    27 #include "cellularpromptdialog.h"
       
    28 #include "OstTraceDefinitions.h"
       
    29 #ifdef OST_TRACE_COMPILER_IN_USE
       
    30 #include "cellularpromptdialogTraces.h"
       
    31 #endif
       
    32 
       
    33 
       
    34 
       
    35 // The index numbers of the buttons of the dialog
       
    36 const int firstButtonIndex = 1;
       
    37 const int middleButtonIndex = 2;
       
    38 const int cancelButtonIndex = 3;
       
    39 
       
    40 /**
       
    41  * The constructor
       
    42  */
       
    43 CellularPromptDialog::CellularPromptDialog(const QVariantMap &parameters)
       
    44 {
       
    45     OstTraceFunctionEntry0( CELLULARPROMPTDIALOG_CELLULARPROMPTDIALOG_ENTRY );
       
    46 
       
    47     // Install localization
       
    48     QTranslator *translator = new QTranslator(this);
       
    49     QString lang = QLocale::system().name(); 
       
    50     QString path = "Z:/resource/qt/translations/"; 
       
    51     translator->load("cellularpromptdialog_" + lang, path);
       
    52     qApp->installTranslator(translator);
       
    53     
       
    54     createDialog(parameters);
       
    55     mClose = false;
       
    56     
       
    57     OstTraceFunctionExit0( CELLULARPROMPTDIALOG_CELLULARPROMPTDIALOG_EXIT );
       
    58 }
       
    59 
       
    60 
       
    61 /**
       
    62  * The construction of the dialog
       
    63  */ 
       
    64 void CellularPromptDialog::createDialog(const QVariantMap &parameters)
       
    65 {
       
    66     OstTraceFunctionEntry0( CELLULARPROMPTDIALOG_CREATEDIALOG_ENTRY );
       
    67     
       
    68     // Set the button and label texts according to the network (home or abroad)
       
    69     QString labelText;
       
    70     QString button1Text;
       
    71     QString button2Text;
       
    72     QString button3Text(hbTrId("txt_occ_button_cellular_cancel"));
       
    73     
       
    74     // There is only one value in the QVariantMap that we are interested in,
       
    75     // whether we are in home network or not
       
    76     QList<QVariant> list = parameters.values();
       
    77     bool homeNetwork = true;
       
    78     
       
    79     if (list.count() > 0) {
       
    80         homeNetwork = list[0].toBool();
       
    81     }
       
    82     
       
    83     if (homeNetwork) {
       
    84         labelText = QString(hbTrId("txt_occ_title_connect_to_internet_using_cellular_d"));
       
    85         button1Text = QString(hbTrId("txt_occ_button_connect_automatically"));
       
    86         button2Text = QString(hbTrId("txt_occ_button_connect_this_time"));
       
    87     } else {
       
    88         labelText = QString(hbTrId("txt_occ_title_connect_to_internet_in_this_country"));
       
    89         button1Text = QString(hbTrId("txt_occ_button_connect_this_time"));
       
    90     }
       
    91     
       
    92     HbDocumentLoader loader;
       
    93     bool ok = true;
       
    94 
       
    95     if (homeNetwork) {
       
    96         loader.load(":/xml/prompt_home.docml", &ok);
       
    97     } else {
       
    98         loader.load(":/xml/prompt_abroad.docml", &ok);
       
    99     }
       
   100 
       
   101     if ( !ok ) {
       
   102         // send information about cancelling to the observer, the xml loading failed
       
   103         cancelPressed();
       
   104         OstTraceFunctionExit0( CELLULARPROMPTDIALOG_CREATEDIALOG_EXIT );
       
   105         return;
       
   106     }
       
   107     
       
   108     // store the pointer to the dialog in order to be able to delete
       
   109     // it in the destructor
       
   110     mDialog = qobject_cast<HbDialog*>( loader.findWidget ("dialog"));
       
   111     Q_ASSERT(mDialog != NULL);
       
   112     
       
   113     // fetch the needed widgets, update their texts and connect the
       
   114     // clicked signals of the buttons to correct slots.
       
   115     HbWidget *container = qobject_cast<HbWidget*>( loader.findWidget ("container"));
       
   116     this->setContentWidget(container);
       
   117     
       
   118     // Set the dialog to be on the screen for 30 seconds, unless
       
   119     // the user reacts earlier
       
   120     this->setModal(true);
       
   121     this->setTimeout(30000);
       
   122     this->setDismissPolicy(HbPopup::NoDismiss);
       
   123     
       
   124     HbLabel* label = qobject_cast<HbLabel*>( loader.findWidget("label") );
       
   125     Q_ASSERT(label != NULL);
       
   126     label->setPlainText(labelText);
       
   127     label->setTextWrapping(Hb::TextWordWrap);
       
   128 
       
   129     HbPushButton* firstButton = qobject_cast<HbPushButton*>( loader.findWidget("topButton") );
       
   130     Q_ASSERT(firstButton != NULL);
       
   131     firstButton->setText(button1Text);
       
   132     
       
   133     HbPushButton* middleButton = NULL;
       
   134     if ( homeNetwork ) {
       
   135     middleButton = qobject_cast<HbPushButton*>( loader.findWidget("middleButton") );
       
   136     Q_ASSERT(middleButton != NULL); 
       
   137     middleButton->setText(button2Text);
       
   138     } 
       
   139     
       
   140     HbPushButton* cancelButton = qobject_cast<HbPushButton*>( loader.findWidget("cancelButton") );
       
   141     Q_ASSERT(cancelButton != NULL);
       
   142     cancelButton->setText(button3Text);
       
   143       
       
   144     // Connect the button clicks to slots, assert if connecting fails
       
   145     bool connected = connect( firstButton, SIGNAL(clicked()), this, SLOT( firstButtonPressed() ));
       
   146     Q_ASSERT(connected == true);
       
   147     
       
   148     if ( homeNetwork ) {
       
   149     connected = connect( middleButton, SIGNAL(clicked()), this, SLOT( middleButtonPressed() ));
       
   150     Q_ASSERT(connected == true);
       
   151     }
       
   152     
       
   153     connected = connect( cancelButton, SIGNAL(clicked()), this, SLOT( cancelPressed() ));
       
   154     Q_ASSERT(connected == true);
       
   155     // Connect the about to close and hide signals, so that we are able to inform 
       
   156     // the caller that the dialog was closed, for example due to timeout
       
   157     connected = connect(this, SIGNAL(aboutToClose()), this, SLOT(closingDialog()));
       
   158     Q_ASSERT(connected == true);
       
   159     connected = connect(this, SIGNAL(aboutToHide()), this, SLOT(closingDialog()));
       
   160     Q_ASSERT(connected == true);
       
   161    
       
   162     OstTraceFunctionExit0( DUP1_CELLULARPROMPTDIALOG_CREATEDIALOG_EXIT );
       
   163 }
       
   164 
       
   165 /**
       
   166  * Destructor
       
   167  */
       
   168 CellularPromptDialog::~CellularPromptDialog()
       
   169 {
       
   170     OstTraceFunctionEntry0( CELLULARPROMPTDIALOG_DCELLULARPROMPTDIALOG_ENTRY );
       
   171     
       
   172     // The dialog widgets are deleted as the dialog is deleted
       
   173     if (mDialog != NULL) {
       
   174         delete mDialog;
       
   175     }
       
   176     mDialog = NULL;
       
   177     
       
   178     OstTraceFunctionExit0( CELLULARPROMPTDIALOG_DCELLULARPROMPTDIALOG_EXIT );
       
   179 }
       
   180 
       
   181 /**
       
   182  * Function is called when the first button is pressed and the 
       
   183  * index of the button is emitted
       
   184  */
       
   185 void CellularPromptDialog::firstButtonPressed()
       
   186 {
       
   187     OstTraceFunctionEntry0( CELLULARPROMPTDIALOG_FIRSTBUTTONPRESSED_ENTRY );
       
   188     
       
   189     QVariantMap data;
       
   190     QVariant variant(firstButtonIndex);
       
   191     data.insert("button", variant);
       
   192     // emit the data of the selected button and close the dialog
       
   193     emit deviceDialogData(data);
       
   194     close();
       
   195 
       
   196     OstTraceFunctionExit0( CELLULARPROMPTDIALOG_FIRSTBUTTONPRESSED_EXIT );
       
   197 }
       
   198 
       
   199 /**
       
   200  * Function is called when the second button is pressed and the 
       
   201  * index of the button is emitted
       
   202  */
       
   203 void CellularPromptDialog::middleButtonPressed()
       
   204 {
       
   205     OstTraceFunctionEntry0( CELLULARPROMPTDIALOG_MIDDLEBUTTONPRESSED_ENTRY );
       
   206     
       
   207     QVariantMap data;
       
   208     QVariant variant(middleButtonIndex);
       
   209     data.insert("button", variant);
       
   210     // emit the data of the selected button and close the dialog
       
   211     emit deviceDialogData(data);
       
   212     close();
       
   213     
       
   214     OstTraceFunctionExit0( CELLULARPROMPTDIALOG_MIDDLEBUTTONPRESSED_EXIT );
       
   215 }
       
   216 
       
   217 /**
       
   218  * Function is called when the third button is pressed and the 
       
   219  * index of the button is emitted
       
   220  */
       
   221 void CellularPromptDialog::cancelPressed()
       
   222 {
       
   223     OstTraceFunctionEntry0( CELLULARPROMPTDIALOG_CANCELPRESSED_ENTRY );
       
   224     
       
   225     QVariantMap data;
       
   226     QVariant variant(cancelButtonIndex);
       
   227     data.insert("button", variant);
       
   228     // emit the data of the selected button and close the dialog
       
   229     emit deviceDialogData(data);
       
   230     close();
       
   231     
       
   232     OstTraceFunctionExit0( CELLULARPROMPTDIALOG_CANCELPRESSED_EXIT );
       
   233 }
       
   234 
       
   235 /**
       
   236  * Function is called when the dialog is about to close
       
   237  */
       
   238 void CellularPromptDialog::closingDialog()
       
   239 {
       
   240     OstTraceFunctionEntry0( CELLULARPROMPTDIALOG_CLOSINGDIALOG_ENTRY );
       
   241     
       
   242     if (!mClose) {
       
   243         mClose = true;
       
   244         closeDeviceDialog(false);
       
   245     }
       
   246     OstTraceFunctionExit0( CELLULARPROMPTDIALOG_CLOSINGDIALOG_EXIT );
       
   247 }
       
   248 
       
   249 
       
   250 /**
       
   251  * Updating the dialog during its showing is not allowed.
       
   252  */ 
       
   253 bool CellularPromptDialog::setDeviceDialogParameters
       
   254                 (const QVariantMap &parameters)
       
   255 {
       
   256     OstTraceFunctionEntry0( CELLULARPROMPTDIALOG_SETDEVICEDIALOGPARAMETERS_ENTRY );
       
   257     
       
   258     Q_UNUSED(parameters)
       
   259     // changing the dialog after presenting it is not supported.
       
   260     
       
   261     OstTraceFunctionExit0( CELLULARPROMPTDIALOG_SETDEVICEDIALOGPARAMETERS_EXIT );
       
   262     return true;
       
   263 }
       
   264 
       
   265 /**
       
   266  * Not supported, 0 always returned
       
   267  */
       
   268 int CellularPromptDialog::deviceDialogError() const
       
   269 {
       
   270     OstTraceFunctionEntry0( CELLULARPROMPTDIALOG_DEVICEDIALOGERROR_ENTRY );
       
   271     OstTraceFunctionExit0( CELLULARPROMPTDIALOG_DEVICEDIALOGERROR_EXIT);
       
   272     return 0;
       
   273 }
       
   274 
       
   275 /**
       
   276  * Dialog is closed and the signal about closing is emitted
       
   277  */
       
   278 void CellularPromptDialog::closeDeviceDialog(bool byClient)
       
   279 {   
       
   280     OstTraceFunctionEntry0( CELLULARPROMPTDIALOG_CLOSEDEVICEDIALOG_ENTRY );
       
   281     
       
   282     Q_UNUSED(byClient)
       
   283     close();
       
   284     // If the user closes the dialog, then the deviceDialogClosed is emitted
       
   285     emit deviceDialogClosed();
       
   286     
       
   287     OstTraceFunctionExit0( CELLULARPROMPTDIALOG_CLOSEDEVICEDIALOG_EXIT );
       
   288 }
       
   289 
       
   290 /**
       
   291  * This dialog widget is returned to the caller
       
   292  */
       
   293 HbPopup *CellularPromptDialog::deviceDialogWidget() const
       
   294 {
       
   295     OstTraceFunctionEntry0( CELLULARPROMPTDIALOG_DEVICEDIALOGWIDGET_ENTRY );
       
   296     OstTraceFunctionExit0( CELLULARPROMPTDIALOG_DEVICEDIALOGWIDGET_EXIT );
       
   297     
       
   298     return const_cast<CellularPromptDialog*>(this);
       
   299 }
       
   300