wlanutilities/wlansniffer/src/wlansniffer.cpp
branchGCC_SURGE
changeset 47 b3d8f88532b7
parent 34 30a5f517c615
parent 46 2fbd1d709fe7
equal deleted inserted replaced
34:30a5f517c615 47:b3d8f88532b7
     1 /*
       
     2  * Copyright (c) 2009 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  * 
       
    16  */
       
    17 
       
    18 #include <QTranslator>
       
    19 #include <QLocale>
       
    20 
       
    21 #include "wlanqtutils.h"
       
    22 
       
    23 #include "wlansniffer.h"
       
    24 #include "wlansniffermainwindow.h"
       
    25 #include "OstTraceDefinitions.h"
       
    26 #ifdef OST_TRACE_COMPILER_IN_USE
       
    27 #include "wlansnifferTraces.h"
       
    28 #endif
       
    29 
       
    30 // Scan interval is 10 seconds
       
    31 const int scanTimerInterval = 10000;
       
    32 
       
    33 WlanSniffer::WlanSniffer(int argc, char* argv[]) :
       
    34     HbApplication(argc, argv),
       
    35     mWlanQtUtils(new WlanQtUtils())    
       
    36 {
       
    37     OstTraceFunctionEntry0( WLANSNIFFER_WLANSNIFFER_ENTRY );
       
    38     
       
    39     // Start the first scan immediately so that results are available as
       
    40     // soon as possible. Start also the timer for periodic scanning.
       
    41     mWlanQtUtils->scanWlans();
       
    42     mScanTimerId = startTimer(scanTimerInterval);
       
    43 
       
    44     // Install localization
       
    45     mTranslator = new QTranslator(this);
       
    46     QString lang = QLocale::system().name(); 
       
    47     QString path = "Z:/resource/qt/translations/"; 
       
    48     mTranslator->load("wlansniffer_" + lang, path); 
       
    49     qApp->installTranslator(mTranslator);
       
    50 
       
    51     mMainWindow = new WlanSnifferMainWindow(this);
       
    52     
       
    53     connect(
       
    54         mWlanQtUtils,
       
    55         SIGNAL(wlanScanReady()),
       
    56         mMainWindow,
       
    57         SLOT(updateListView()));
       
    58 
       
    59     connect(
       
    60         mWlanQtUtils,
       
    61         SIGNAL(wlanNetworkOpened(int)),
       
    62         mMainWindow,
       
    63         SLOT(updateListViewConnectionOpened(int)));
       
    64     
       
    65     connect(
       
    66         mWlanQtUtils,
       
    67         SIGNAL(wlanNetworkClosed(int)),
       
    68         mMainWindow,
       
    69         SLOT(updateListViewConnectionClosed(int)));
       
    70     
       
    71     connect(
       
    72         mMainWindow,
       
    73         SIGNAL(exitTriggered()),
       
    74         this,
       
    75         SLOT(exitApplication()));
       
    76 
       
    77     OstTraceFunctionExit0( WLANSNIFFER_WLANSNIFFER_EXIT );
       
    78 }
       
    79 
       
    80 WlanSniffer::~WlanSniffer()
       
    81 {
       
    82     OstTraceFunctionEntry0( WLANSNIFFER_WLANSNIFFERDESTR_ENTRY );
       
    83 
       
    84     killTimer(mScanTimerId);
       
    85     
       
    86     delete mMainWindow;
       
    87     delete mWlanQtUtils;
       
    88     
       
    89     OstTraceFunctionExit0( WLANSNIFFER_WLANSNIFFERDESTR_EXIT );
       
    90 }
       
    91 
       
    92 void WlanSniffer::timerEvent(QTimerEvent *event)
       
    93 {
       
    94     OstTraceFunctionEntry0( WLANSNIFFER_TIMEREVENT_ENTRY );
       
    95     
       
    96     Q_UNUSED(event);
       
    97     // Request a new scan. Timer events come periodically.
       
    98     mWlanQtUtils->scanWlans();
       
    99 
       
   100     OstTraceFunctionExit0( WLANSNIFFER_TIMEREVENT_EXIT );
       
   101 }
       
   102 
       
   103 WlanQtUtils *WlanSniffer::wlanQtUtils() const
       
   104 {
       
   105     OstTraceFunctionEntry0( WLANSNIFFER_WLANQTUTILS_ENTRY );
       
   106     OstTraceFunctionExit0( WLANSNIFFER_WLANQTUTILS_EXIT );
       
   107     return mWlanQtUtils;
       
   108 }
       
   109 
       
   110 void WlanSniffer::exitApplication()
       
   111 {
       
   112     OstTraceFunctionEntry0( WLANSNIFFER_EXITAPPLICATION_ENTRY );
       
   113     
       
   114     exit();
       
   115 
       
   116     OstTraceFunctionExit0( WLANSNIFFER_EXITAPPLICATION_EXIT );
       
   117 }