wlanutilities/wlansniffer/wlansnifferapplication/src/wlansniffermainwindow.cpp
author hgs
Thu, 16 Sep 2010 12:52:33 +0300
changeset 61 e1d68407ed06
parent 60 822a45792fdd
permissions -rw-r--r--
201037
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
    
61
hgs
parents: 60
diff changeset
   139
    if (mWizard == NULL) {
hgs
parents: 60
diff changeset
   140
        // Stop WLAN scanning for the duration of WLAN Wizard
hgs
parents: 60
diff changeset
   141
        mEngine->stopWlanScanning();
hgs
parents: 60
diff changeset
   142
        
hgs
parents: 60
diff changeset
   143
        mWizard = QSharedPointer<WlanWizard>(new WlanWizard(this));
hgs
parents: 60
diff changeset
   144
        bool connectStatus = connect(
hgs
parents: 60
diff changeset
   145
            mWizard.data(),
hgs
parents: 60
diff changeset
   146
            SIGNAL(finished(int,bool)),
hgs
parents: 60
diff changeset
   147
            this,
hgs
parents: 60
diff changeset
   148
            SLOT(handleWlanWizardComplete(int,bool)),
hgs
parents: 60
diff changeset
   149
            Qt::QueuedConnection);
hgs
parents: 60
diff changeset
   150
        Q_ASSERT(connectStatus == true);
hgs
parents: 60
diff changeset
   151
        
hgs
parents: 60
diff changeset
   152
        connectStatus = connect(
hgs
parents: 60
diff changeset
   153
            mWizard.data(),
hgs
parents: 60
diff changeset
   154
            SIGNAL(cancelled()),
hgs
parents: 60
diff changeset
   155
            this,
hgs
parents: 60
diff changeset
   156
            SLOT(handleWlanWizardCancelled()),
hgs
parents: 60
diff changeset
   157
            Qt::QueuedConnection);
hgs
parents: 60
diff changeset
   158
        Q_ASSERT(connectStatus == true);
hgs
parents: 60
diff changeset
   159
        
hgs
parents: 60
diff changeset
   160
        // Create an IAP for a specific AP
hgs
parents: 60
diff changeset
   161
        if (ap) {
hgs
parents: 60
diff changeset
   162
            mWizard->setParameters(
hgs
parents: 60
diff changeset
   163
                ap->value(WlanQtUtilsAp::ConfIdName).toString(),
hgs
parents: 60
diff changeset
   164
                ap->value(WlanQtUtilsAp::ConfIdSsid).toByteArray(),
hgs
parents: 60
diff changeset
   165
                ap->value(WlanQtUtilsAp::ConfIdConnectionMode).toInt(),
hgs
parents: 60
diff changeset
   166
                ap->value(WlanQtUtilsAp::ConfIdSecurityMode).toInt(),
hgs
parents: 60
diff changeset
   167
                ap->value(WlanQtUtilsAp::ConfIdWpaPskUse).toInt(),
hgs
parents: 60
diff changeset
   168
                ap->value(WlanQtUtilsAp::ConfIdWpsSupported).toBool());
hgs
parents: 60
diff changeset
   169
        }
hgs
parents: 60
diff changeset
   170
        // else: Add WLAN IAP manually
hgs
parents: 60
diff changeset
   171
        
hgs
parents: 60
diff changeset
   172
        mWizard->show();
hgs
parents: 60
diff changeset
   173
    }
hgs
parents: 60
diff changeset
   174
    // else: already running Wizard, ignore this call
31
hgs
parents:
diff changeset
   175
    
hgs
parents:
diff changeset
   176
    OstTraceFunctionExit0(WLANSNIFFERMAINWINDOW_STARTWLANWIZARD_EXIT);
hgs
parents:
diff changeset
   177
}
hgs
parents:
diff changeset
   178
hgs
parents:
diff changeset
   179
/*!
hgs
parents:
diff changeset
   180
    WLAN Wizard successful completion handler.
hgs
parents:
diff changeset
   181
    
hgs
parents:
diff changeset
   182
    @param [in] iapId IAP ID of the new WLAN IAP.
hgs
parents:
diff changeset
   183
    @param [in] connected TRUE if connected.  
hgs
parents:
diff changeset
   184
 */
hgs
parents:
diff changeset
   185
hgs
parents:
diff changeset
   186
void WlanSnifferMainWindow::handleWlanWizardComplete(
hgs
parents:
diff changeset
   187
    int iapId,
hgs
parents:
diff changeset
   188
    bool connected)
hgs
parents:
diff changeset
   189
{
hgs
parents:
diff changeset
   190
    OstTraceFunctionEntry0(WLANSNIFFERMAINWINDOW_HANDLEWLANWIZARDCOMPLETE_ENTRY);
hgs
parents:
diff changeset
   191
hgs
parents:
diff changeset
   192
    // The wizard must exist
hgs
parents:
diff changeset
   193
    Q_ASSERT(mWizard);
hgs
parents:
diff changeset
   194
    
39
hgs
parents: 31
diff changeset
   195
    // Enable scanning again
hgs
parents: 31
diff changeset
   196
    mEngine->startWlanScanning();
hgs
parents: 31
diff changeset
   197
hgs
parents: 31
diff changeset
   198
    if (connected) {
hgs
parents: 31
diff changeset
   199
        // The IAP ID must be valid
hgs
parents: 31
diff changeset
   200
        Q_ASSERT(iapId != WlanQtUtils::IapIdNone);
hgs
parents: 31
diff changeset
   201
        
hgs
parents: 31
diff changeset
   202
        // Connect (share) the new IAP in order to keep the connection open when
hgs
parents: 31
diff changeset
   203
        // deleting Wizard.
hgs
parents: 31
diff changeset
   204
        mEngine->wlanQtUtils()->connectIap(iapId, false);
hgs
parents: 31
diff changeset
   205
    }
hgs
parents: 31
diff changeset
   206
    // else: created IAP not connected at all, or already dropped
hgs
parents: 31
diff changeset
   207
    // (probably due to being out of coverage) so don't try to share it
hgs
parents: 31
diff changeset
   208
    
hgs
parents: 31
diff changeset
   209
    // Delete the Wizard instance. This is OK since the connect is Qt::QueuedConnection.
hgs
parents: 31
diff changeset
   210
    mWizard.clear();
31
hgs
parents:
diff changeset
   211
    
hgs
parents:
diff changeset
   212
    OstTraceFunctionExit0(WLANSNIFFERMAINWINDOW_HANDLEWLANWIZARDCOMPLETE_EXIT);
hgs
parents:
diff changeset
   213
}
hgs
parents:
diff changeset
   214
hgs
parents:
diff changeset
   215
/*!
hgs
parents:
diff changeset
   216
    WLAN Wizard cancellation handler.
hgs
parents:
diff changeset
   217
 */
hgs
parents:
diff changeset
   218
hgs
parents:
diff changeset
   219
void WlanSnifferMainWindow::handleWlanWizardCancelled()
hgs
parents:
diff changeset
   220
{
hgs
parents:
diff changeset
   221
    OstTraceFunctionEntry0(WLANSNIFFERMAINWINDOW_HANDLEWLANWIZARDCANCELLED_ENTRY);
hgs
parents:
diff changeset
   222
hgs
parents:
diff changeset
   223
    // The wizard must exist
hgs
parents:
diff changeset
   224
    Q_ASSERT(mWizard);
hgs
parents:
diff changeset
   225
    
39
hgs
parents: 31
diff changeset
   226
    // Enable scanning again
hgs
parents: 31
diff changeset
   227
    mEngine->startWlanScanning();
hgs
parents: 31
diff changeset
   228
    
hgs
parents: 31
diff changeset
   229
    // Delete the Wizard instance. This is OK since the connect is Qt::QueuedConnection.
hgs
parents: 31
diff changeset
   230
    mWizard.clear();
31
hgs
parents:
diff changeset
   231
    
hgs
parents:
diff changeset
   232
    OstTraceFunctionExit0(WLANSNIFFERMAINWINDOW_HANDLEWLANWIZARDCANCELLED_EXIT);
hgs
parents:
diff changeset
   233
}