cmmanager/cmapplsettingsui/tsrc/tst_applsettingsui/src/applsettester.cpp
branchRCL_3
changeset 58 83ca720e2b9a
parent 57 05bc53fe583b
child 62 bb1f80fb7db2
equal deleted inserted replaced
57:05bc53fe583b 58:83ca720e2b9a
     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:
       
    15 * Dialog implementaton for test application 
       
    16 * for testing CM Manager Application Settings Ui.
       
    17 */
       
    18 
       
    19 #include <QGraphicsWidget>
       
    20 #include <QString>
       
    21 
       
    22 #include <HbDialog>
       
    23 #include <HbApplication>
       
    24 #include <HbMainWindow>
       
    25 #include <HbView>
       
    26 #include <HbDocumentLoader>
       
    27 #include <HbInstance>
       
    28 #include <HbAction>
       
    29 #include <HbCheckBox>
       
    30 #include <HbLabel>
       
    31 #include <HbLineEdit>
       
    32 #include <HbComboBox>
       
    33 
       
    34 
       
    35 #include "cmapplsettingsui.h"
       
    36 #include "cmmanagerdefines_shim.h"
       
    37 
       
    38 #include "applsettester.h"
       
    39 
       
    40 #define TEST_DOCML ":/docml/tst_applsettingsui.docml"
       
    41 
       
    42 ApplSettTester::ApplSettTester(QWidget *parent) : HbMainWindow(parent)
       
    43 {
       
    44     applSett = new CmApplSettingsUi(this);
       
    45 
       
    46     // Clear initial selection
       
    47     mSelection.result = CmApplSettingsUi::SelectionTypeDestination;
       
    48     mSelection.id = 0;
       
    49     
       
    50     bool status = connect(
       
    51         this,
       
    52         SIGNAL(orientationChanged(Qt::Orientation)),
       
    53         this,
       
    54         SLOT(orientationChange(Qt::Orientation)));
       
    55     Q_ASSERT(status);
       
    56     
       
    57     docLoader = new HbDocumentLoader();
       
    58     docmlLoad(this->orientation()); 
       
    59 }
       
    60 
       
    61 ApplSettTester::~ApplSettTester()
       
    62 {
       
    63     delete docLoader;
       
    64 }
       
    65 
       
    66 void ApplSettTester::docmlLoad(Qt::Orientation orientation)
       
    67 {
       
    68     bool ok = true;
       
    69     
       
    70     docLoader->reset();
       
    71     // First load the common section
       
    72     docLoader->load(TEST_DOCML, &ok);
       
    73 
       
    74     if (ok) {    
       
    75         // Then load the orientation specific section
       
    76         orientationChange(orientation);
       
    77         
       
    78         QGraphicsWidget *widget = docLoader->findWidget(QString("testApplView"));
       
    79         if (widget) {
       
    80             view = qobject_cast<HbView*>(widget);
       
    81             this->addView(view);
       
    82             this->setCurrentView(view);
       
    83 
       
    84             checkboxDest = qobject_cast<HbCheckBox*>(docLoader->findWidget("checkbox_dest"));
       
    85             Q_ASSERT(checkboxDest);
       
    86             checkboxCM = qobject_cast<HbCheckBox*>(docLoader->findWidget("checkbox_cm"));
       
    87             Q_ASSERT(checkboxCM);
       
    88             
       
    89             checkboxWlan = qobject_cast<HbCheckBox*>(docLoader->findWidget("checkbox_wlan"));
       
    90             Q_ASSERT(checkboxWlan);
       
    91             checkboxGprs = qobject_cast<HbCheckBox*>(docLoader->findWidget("checkbox_gprs"));
       
    92             Q_ASSERT(checkboxGprs);
       
    93            
       
    94             selectionMode = qobject_cast<HbComboBox*>(docLoader->findWidget("mode"));
       
    95             Q_ASSERT(selectionMode);
       
    96             selectionId = qobject_cast<HbLineEdit*>(docLoader->findWidget("id"));
       
    97             Q_ASSERT(selectionId);
       
    98            
       
    99             labelResult = qobject_cast<HbLabel*>(docLoader->findWidget("result"));
       
   100             Q_ASSERT(labelResult);
       
   101             
       
   102             action = qobject_cast<HbAction *>(docLoader->findObject("testAction"));
       
   103             Q_ASSERT(action);
       
   104             
       
   105             bool status = connect(action, SIGNAL(triggered()), this, SLOT(runTest()));
       
   106             Q_ASSERT(status);
       
   107         }
       
   108     }
       
   109 }
       
   110 
       
   111 void ApplSettTester::orientationChange(Qt::Orientation orientation)
       
   112 {
       
   113     bool ok = true;
       
   114     if (orientation == Qt::Vertical) {
       
   115         // reading "portrait" section
       
   116         docLoader->load(TEST_DOCML, "portrait", &ok);
       
   117     } else {
       
   118         // reading "landscape" section
       
   119         docLoader->load(TEST_DOCML, "landscape", &ok);
       
   120     }   
       
   121 }
       
   122 
       
   123 void ApplSettTester::runTest()
       
   124 {
       
   125     QFlags<CmApplSettingsUi::SelectionDialogItems> listItems;
       
   126     QSet<CmApplSettingsUi::BearerTypeFilter> filter;
       
   127     
       
   128     // Dialog type selection
       
   129     if (checkboxDest->checkState()) {
       
   130         listItems |= CmApplSettingsUi::ShowDestinations;
       
   131     }
       
   132     if (checkboxCM->checkState()) {
       
   133         listItems |= CmApplSettingsUi::ShowConnectionMethods;
       
   134     }
       
   135 
       
   136     // Bearer filtering
       
   137     if (checkboxWlan->checkState()) {
       
   138         filter |= CMManagerShim::BearerTypeWlan;
       
   139     }
       
   140     if (checkboxGprs->checkState()) {
       
   141         filter |= CMManagerShim::BearerTypePacketData;
       
   142     }
       
   143     
       
   144     // Setting selection value
       
   145     mSelection.result = 
       
   146         (CmApplSettingsUi::SelectionType)selectionMode->currentIndex();
       
   147     mSelection.id = selectionId->text().toUInt();;
       
   148 
       
   149     applSett->setOptions(listItems, filter);
       
   150     applSett->setSelection(mSelection);
       
   151     
       
   152     // Connect finished(uint) signal and handle result via it
       
   153     connect(applSett, SIGNAL(finished(uint)), this, SLOT(showResult(uint)));
       
   154     
       
   155     // Start CmApplSettingsUi
       
   156     applSett->open();
       
   157 }
       
   158 
       
   159 void ApplSettTester::showResult(uint retval)
       
   160 {
       
   161     if (retval == CmApplSettingsUi::ApplSettingsErrorNone) {
       
   162         mSelection = applSett->selection();
       
   163         selectionMode->setCurrentIndex(mSelection.result);    
       
   164         selectionId->setText(QString::number(mSelection.id));
       
   165     }
       
   166     labelResult->setNumber(int(retval));
       
   167 }