wlanutilities/wlansniffer/wlansnifferapplication/src/wlansniffermainwindow.cpp
author hgs
Fri, 03 Sep 2010 09:37:37 +0300
changeset 60 822a45792fdd
parent 53 bdc64aa9b954
child 61 e1d68407ed06
permissions -rw-r--r--
201035
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
31
hgs
parents:
diff changeset
     1
/*
hgs
parents:
diff changeset
     2
* Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies).
hgs
parents:
diff changeset
     3
* All rights reserved.
hgs
parents:
diff changeset
     4
* This component and the accompanying materials are made available
hgs
parents:
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
hgs
parents:
diff changeset
     6
* which accompanies this distribution, and is available
hgs
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
hgs
parents:
diff changeset
     8
*
hgs
parents:
diff changeset
     9
* Initial Contributors:
hgs
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
hgs
parents:
diff changeset
    11
*
hgs
parents:
diff changeset
    12
* Contributors:
hgs
parents:
diff changeset
    13
*
hgs
parents:
diff changeset
    14
* Description:
hgs
parents:
diff changeset
    15
* WLAN Sniffer main window. 
hgs
parents:
diff changeset
    16
*/
hgs
parents:
diff changeset
    17
hgs
parents:
diff changeset
    18
// System includes
hgs
parents:
diff changeset
    19
hgs
parents:
diff changeset
    20
// User includes
hgs
parents:
diff changeset
    21
hgs
parents:
diff changeset
    22
#include "wlanqtutils.h"
hgs
parents:
diff changeset
    23
#include "wlanqtutilsap.h"
hgs
parents:
diff changeset
    24
hgs
parents:
diff changeset
    25
#include "wlanwizard.h"
hgs
parents:
diff changeset
    26
hgs
parents:
diff changeset
    27
#include "wlansnifferengine.h"
hgs
parents:
diff changeset
    28
#include "wlansnifferlistview.h"
hgs
parents:
diff changeset
    29
#include "wlansniffermainwindow.h"
hgs
parents:
diff changeset
    30
hgs
parents:
diff changeset
    31
#include "OstTraceDefinitions.h"
hgs
parents:
diff changeset
    32
#ifdef OST_TRACE_COMPILER_IN_USE
hgs
parents:
diff changeset
    33
#include "wlansniffermainwindowTraces.h"
hgs
parents:
diff changeset
    34
#endif
hgs
parents:
diff changeset
    35
hgs
parents:
diff changeset
    36
/*!
hgs
parents:
diff changeset
    37
    \class WlanSnifferMainWindow
hgs
parents:
diff changeset
    38
    \brief WLAN Sniffer main window. 
hgs
parents:
diff changeset
    39
*/
hgs
parents:
diff changeset
    40
hgs
parents:
diff changeset
    41
// External function prototypes
hgs
parents:
diff changeset
    42
hgs
parents:
diff changeset
    43
// Local constants
hgs
parents:
diff changeset
    44
hgs
parents:
diff changeset
    45
// ======== LOCAL FUNCTIONS ========
hgs
parents:
diff changeset
    46
hgs
parents:
diff changeset
    47
// ======== MEMBER FUNCTIONS ========
hgs
parents:
diff changeset
    48
hgs
parents:
diff changeset
    49
/*!
hgs
parents:
diff changeset
    50
    Constructor.
hgs
parents:
diff changeset
    51
    
hgs
parents:
diff changeset
    52
    @param [in] engine WLAN Sniffer application engine.
hgs
parents:
diff changeset
    53
 */
hgs
parents:
diff changeset
    54
hgs
parents:
diff changeset
    55
WlanSnifferMainWindow::WlanSnifferMainWindow(WlanSnifferEngine *engine) :
hgs
parents:
diff changeset
    56
    mWizard(0),
hgs
parents:
diff changeset
    57
    mListView(0),
hgs
parents:
diff changeset
    58
    mEngine(engine)
hgs
parents:
diff changeset
    59
{
hgs
parents:
diff changeset
    60
    OstTraceFunctionEntry0(WLANSNIFFERMAINWINDOW_WLANSNIFFERMAINWINDOW_ENTRY);
hgs
parents:
diff changeset
    61
hgs
parents:
diff changeset
    62
    // Add the list view to the main window
hgs
parents:
diff changeset
    63
    addListView();
hgs
parents:
diff changeset
    64
    bool connectStatus = connect(
hgs
parents:
diff changeset
    65
        mEngine,
hgs
parents:
diff changeset
    66
        SIGNAL(toListView(QString)),
hgs
parents:
diff changeset
    67
        this,
hgs
parents:
diff changeset
    68
        SLOT(toListView(QString)));
hgs
parents:
diff changeset
    69
    Q_ASSERT(connectStatus == true);
hgs
parents:
diff changeset
    70
    
hgs
parents:
diff changeset
    71
    // When using WLAN Sniffer service, the view show is called after the service
hgs
parents:
diff changeset
    72
    // request arrives.
hgs
parents:
diff changeset
    73
    if (!mEngine->isEmbedded()) {
hgs
parents:
diff changeset
    74
        // Show the list view
hgs
parents:
diff changeset
    75
        toListView(hbTrId("txt_occ_title_wireless_lan"));
hgs
parents:
diff changeset
    76
    }
hgs
parents:
diff changeset
    77
hgs
parents:
diff changeset
    78
    OstTraceFunctionExit0(WLANSNIFFERMAINWINDOW_WLANSNIFFERMAINWINDOW_EXIT);
hgs
parents:
diff changeset
    79
}
hgs
parents:
diff changeset
    80
hgs
parents:
diff changeset
    81
/*!
hgs
parents:
diff changeset
    82
    Destructor.
hgs
parents:
diff changeset
    83
 */
hgs
parents:
diff changeset
    84
hgs
parents:
diff changeset
    85
WlanSnifferMainWindow::~WlanSnifferMainWindow()
hgs
parents:
diff changeset
    86
{
hgs
parents:
diff changeset
    87
    OstTraceFunctionEntry0(WLANSNIFFERMAINWINDOW_WLANSNIFFERMAINWINDOWDESTR_ENTRY);
hgs
parents:
diff changeset
    88
    OstTraceFunctionExit0(WLANSNIFFERMAINWINDOW_WLANSNIFFERMAINWINDOWDESTR_EXIT);
hgs
parents:
diff changeset
    89
}
hgs
parents:
diff changeset
    90
hgs
parents:
diff changeset
    91
/*!
hgs
parents:
diff changeset
    92
    Shows the WLAN Sniffer list view.
hgs
parents:
diff changeset
    93
    
hgs
parents:
diff changeset
    94
    @param [in] title View title.
hgs
parents:
diff changeset
    95
 */
hgs
parents:
diff changeset
    96
hgs
parents:
diff changeset
    97
void WlanSnifferMainWindow::toListView(const QString &title)
hgs
parents:
diff changeset
    98
{
hgs
parents:
diff changeset
    99
    OstTraceFunctionEntry0(WLANSNIFFERMAINWINDOW_TOLISTVIEW_ENTRY);
hgs
parents:
diff changeset
   100
    
hgs
parents:
diff changeset
   101
    // Show the list view
hgs
parents:
diff changeset
   102
    mListView->setTitle(title);
hgs
parents:
diff changeset
   103
    setCurrentView(mListView);
hgs
parents:
diff changeset
   104
    show();
hgs
parents:
diff changeset
   105
hgs
parents:
diff changeset
   106
    OstTraceFunctionExit0(WLANSNIFFERMAINWINDOW_TOLISTVIEW_EXIT);
hgs
parents:
diff changeset
   107
}
hgs
parents:
diff changeset
   108
hgs
parents:
diff changeset
   109
/*!
hgs
parents:
diff changeset
   110
    Creates and adds the WLAN List View to main window.
hgs
parents:
diff changeset
   111
 */
hgs
parents:
diff changeset
   112
hgs
parents:
diff changeset
   113
void WlanSnifferMainWindow::addListView()
hgs
parents:
diff changeset
   114
{
hgs
parents:
diff changeset
   115
    OstTraceFunctionEntry0(WLANSNIFFERMAINWINDOW_ADDLISTVIEW_ENTRY);
hgs
parents:
diff changeset
   116
    
hgs
parents:
diff changeset
   117
    mListView = new WlanSnifferListView(mEngine, this);
hgs
parents:
diff changeset
   118
    addView(mListView);
hgs
parents:
diff changeset
   119
hgs
parents:
diff changeset
   120
    bool connectStatus = connect(
hgs
parents:
diff changeset
   121
        mListView,
hgs
parents:
diff changeset
   122
        SIGNAL(wizardTriggered(const WlanQtUtilsAp *)),
hgs
parents:
diff changeset
   123
        this,
hgs
parents:
diff changeset
   124
        SLOT(startWlanWizard(const WlanQtUtilsAp *)));
hgs
parents:
diff changeset
   125
    
hgs
parents:
diff changeset
   126
    OstTraceFunctionExit0(WLANSNIFFERMAINWINDOW_ADDLISTVIEW_EXIT);
hgs
parents:
diff changeset
   127
}
hgs
parents:
diff changeset
   128
hgs
parents:
diff changeset
   129
/*!
hgs
parents:
diff changeset
   130
    Starts WLAN Wizard for new WLAN IAP creation.
hgs
parents:
diff changeset
   131
    
39
hgs
parents: 31
diff changeset
   132
    @param [in] ap WLAN Access Point to create, or NULL for adding WLAN manually.
31
hgs
parents:
diff changeset
   133
 */
hgs
parents:
diff changeset
   134
hgs
parents:
diff changeset
   135
void WlanSnifferMainWindow::startWlanWizard(const WlanQtUtilsAp *ap)
hgs
parents:
diff changeset
   136
{
hgs
parents:
diff changeset
   137
    OstTraceFunctionEntry0(WLANSNIFFERMAINWINDOW_STARTWLANWIZARD_ENTRY);
hgs
parents:
diff changeset
   138
    
hgs
parents:
diff changeset
   139
    Q_ASSERT(mWizard == NULL);
hgs
parents:
diff changeset
   140
hgs
parents:
diff changeset
   141
    // Stop WLAN scanning for the duration of WLAN Wizard
hgs
parents:
diff changeset
   142
    mEngine->stopWlanScanning();
hgs
parents:
diff changeset
   143
    
39
hgs
parents: 31
diff changeset
   144
    mWizard = QSharedPointer<WlanWizard>(new WlanWizard(this));
31
hgs
parents:
diff changeset
   145
    bool connectStatus = connect(
39
hgs
parents: 31
diff changeset
   146
        mWizard.data(),
31
hgs
parents:
diff changeset
   147
        SIGNAL(finished(int,bool)),
hgs
parents:
diff changeset
   148
        this,
39
hgs
parents: 31
diff changeset
   149
        SLOT(handleWlanWizardComplete(int,bool)),
hgs
parents: 31
diff changeset
   150
        Qt::QueuedConnection);
31
hgs
parents:
diff changeset
   151
    Q_ASSERT(connectStatus == true);
hgs
parents:
diff changeset
   152
    
hgs
parents:
diff changeset
   153
    connectStatus = connect(
39
hgs
parents: 31
diff changeset
   154
        mWizard.data(),
31
hgs
parents:
diff changeset
   155
        SIGNAL(cancelled()),
hgs
parents:
diff changeset
   156
        this,
39
hgs
parents: 31
diff changeset
   157
        SLOT(handleWlanWizardCancelled()),
hgs
parents: 31
diff changeset
   158
        Qt::QueuedConnection);
31
hgs
parents:
diff changeset
   159
    Q_ASSERT(connectStatus == true);
hgs
parents:
diff changeset
   160
    
39
hgs
parents: 31
diff changeset
   161
    // Create an IAP for a specific AP
hgs
parents: 31
diff changeset
   162
    if (ap) {
hgs
parents: 31
diff changeset
   163
        mWizard->setParameters(
60
hgs
parents: 53
diff changeset
   164
            ap->value(WlanQtUtilsAp::ConfIdName).toString(),
hgs
parents: 53
diff changeset
   165
            ap->value(WlanQtUtilsAp::ConfIdSsid).toByteArray(),
39
hgs
parents: 31
diff changeset
   166
            ap->value(WlanQtUtilsAp::ConfIdConnectionMode).toInt(),
hgs
parents: 31
diff changeset
   167
            ap->value(WlanQtUtilsAp::ConfIdSecurityMode).toInt(),
hgs
parents: 31
diff changeset
   168
            ap->value(WlanQtUtilsAp::ConfIdWpaPskUse).toInt(),
hgs
parents: 31
diff changeset
   169
            ap->value(WlanQtUtilsAp::ConfIdWpsSupported).toBool());
hgs
parents: 31
diff changeset
   170
    }
hgs
parents: 31
diff changeset
   171
    // else: Add WLAN IAP manually
31
hgs
parents:
diff changeset
   172
    
hgs
parents:
diff changeset
   173
    mWizard->show();
hgs
parents:
diff changeset
   174
hgs
parents:
diff changeset
   175
    OstTraceFunctionExit0(WLANSNIFFERMAINWINDOW_STARTWLANWIZARD_EXIT);
hgs
parents:
diff changeset
   176
}
hgs
parents:
diff changeset
   177
hgs
parents:
diff changeset
   178
/*!
hgs
parents:
diff changeset
   179
    WLAN Wizard successful completion handler.
hgs
parents:
diff changeset
   180
    
hgs
parents:
diff changeset
   181
    @param [in] iapId IAP ID of the new WLAN IAP.
hgs
parents:
diff changeset
   182
    @param [in] connected TRUE if connected.  
hgs
parents:
diff changeset
   183
 */
hgs
parents:
diff changeset
   184
hgs
parents:
diff changeset
   185
void WlanSnifferMainWindow::handleWlanWizardComplete(
hgs
parents:
diff changeset
   186
    int iapId,
hgs
parents:
diff changeset
   187
    bool connected)
hgs
parents:
diff changeset
   188
{
hgs
parents:
diff changeset
   189
    OstTraceFunctionEntry0(WLANSNIFFERMAINWINDOW_HANDLEWLANWIZARDCOMPLETE_ENTRY);
hgs
parents:
diff changeset
   190
hgs
parents:
diff changeset
   191
    // The wizard must exist
hgs
parents:
diff changeset
   192
    Q_ASSERT(mWizard);
hgs
parents:
diff changeset
   193
    
39
hgs
parents: 31
diff changeset
   194
    // Enable scanning again
hgs
parents: 31
diff changeset
   195
    mEngine->startWlanScanning();
hgs
parents: 31
diff changeset
   196
hgs
parents: 31
diff changeset
   197
    if (connected) {
hgs
parents: 31
diff changeset
   198
        // The IAP ID must be valid
hgs
parents: 31
diff changeset
   199
        Q_ASSERT(iapId != WlanQtUtils::IapIdNone);
hgs
parents: 31
diff changeset
   200
        
hgs
parents: 31
diff changeset
   201
        // Connect (share) the new IAP in order to keep the connection open when
hgs
parents: 31
diff changeset
   202
        // deleting Wizard.
hgs
parents: 31
diff changeset
   203
        mEngine->wlanQtUtils()->connectIap(iapId, false);
hgs
parents: 31
diff changeset
   204
    }
hgs
parents: 31
diff changeset
   205
    // else: created IAP not connected at all, or already dropped
hgs
parents: 31
diff changeset
   206
    // (probably due to being out of coverage) so don't try to share it
hgs
parents: 31
diff changeset
   207
    
hgs
parents: 31
diff changeset
   208
    // Delete the Wizard instance. This is OK since the connect is Qt::QueuedConnection.
hgs
parents: 31
diff changeset
   209
    mWizard.clear();
31
hgs
parents:
diff changeset
   210
    
hgs
parents:
diff changeset
   211
    OstTraceFunctionExit0(WLANSNIFFERMAINWINDOW_HANDLEWLANWIZARDCOMPLETE_EXIT);
hgs
parents:
diff changeset
   212
}
hgs
parents:
diff changeset
   213
hgs
parents:
diff changeset
   214
/*!
hgs
parents:
diff changeset
   215
    WLAN Wizard cancellation handler.
hgs
parents:
diff changeset
   216
 */
hgs
parents:
diff changeset
   217
hgs
parents:
diff changeset
   218
void WlanSnifferMainWindow::handleWlanWizardCancelled()
hgs
parents:
diff changeset
   219
{
hgs
parents:
diff changeset
   220
    OstTraceFunctionEntry0(WLANSNIFFERMAINWINDOW_HANDLEWLANWIZARDCANCELLED_ENTRY);
hgs
parents:
diff changeset
   221
hgs
parents:
diff changeset
   222
    // The wizard must exist
hgs
parents:
diff changeset
   223
    Q_ASSERT(mWizard);
hgs
parents:
diff changeset
   224
    
39
hgs
parents: 31
diff changeset
   225
    // Enable scanning again
hgs
parents: 31
diff changeset
   226
    mEngine->startWlanScanning();
hgs
parents: 31
diff changeset
   227
    
hgs
parents: 31
diff changeset
   228
    // Delete the Wizard instance. This is OK since the connect is Qt::QueuedConnection.
hgs
parents: 31
diff changeset
   229
    mWizard.clear();
31
hgs
parents:
diff changeset
   230
    
hgs
parents:
diff changeset
   231
    OstTraceFunctionExit0(WLANSNIFFERMAINWINDOW_HANDLEWLANWIZARDCANCELLED_EXIT);
hgs
parents:
diff changeset
   232
}