wlanutilities/wlanlogin/wlanloginapp/src/wlanloginengine.cpp
author hgs
Fri, 09 Jul 2010 10:38:19 +0300
changeset 43 72ebcbb64834
parent 39 7b3e49e4608a
child 53 bdc64aa9b954
permissions -rw-r--r--
201027
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
39
hgs
parents:
diff changeset
     1
/*
hgs
parents:
diff changeset
     2
* Copyright (c) 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 Login engine class implementation
hgs
parents:
diff changeset
    16
* 
hgs
parents:
diff changeset
    17
*/
hgs
parents:
diff changeset
    18
hgs
parents:
diff changeset
    19
// System includes
hgs
parents:
diff changeset
    20
#include <QObject>
hgs
parents:
diff changeset
    21
#include <QString>
hgs
parents:
diff changeset
    22
#include <QUrl>
hgs
parents:
diff changeset
    23
#include <HbMessagebox>
hgs
parents:
diff changeset
    24
#include <HbAction>
hgs
parents:
diff changeset
    25
#include <qnetworkconfigmanager.h>
hgs
parents:
diff changeset
    26
#include <qnetworkconfiguration.h>
hgs
parents:
diff changeset
    27
#include <qnetworksession.h>
hgs
parents:
diff changeset
    28
hgs
parents:
diff changeset
    29
//User includes
hgs
parents:
diff changeset
    30
#include "wlanloginengine.h"
hgs
parents:
diff changeset
    31
#include "wlanloginapplication.h"
hgs
parents:
diff changeset
    32
#include "wlanloginmainwindow.h"
hgs
parents:
diff changeset
    33
#include "ictsqtwrapper.h"
hgs
parents:
diff changeset
    34
#include "wlanloginnetworkaccessmanager.h"
hgs
parents:
diff changeset
    35
hgs
parents:
diff changeset
    36
#include "OstTraceDefinitions.h"
hgs
parents:
diff changeset
    37
#ifdef OST_TRACE_COMPILER_IN_USE
hgs
parents:
diff changeset
    38
#include "wlanloginengineTraces.h"
hgs
parents:
diff changeset
    39
#endif
hgs
parents:
diff changeset
    40
hgs
parents:
diff changeset
    41
/*!
hgs
parents:
diff changeset
    42
    \class WlanLoginEngine
hgs
parents:
diff changeset
    43
    \brief WLAN Login engine class implementation.
hgs
parents:
diff changeset
    44
*/
hgs
parents:
diff changeset
    45
hgs
parents:
diff changeset
    46
// External function prototypes
hgs
parents:
diff changeset
    47
hgs
parents:
diff changeset
    48
// Local constants
43
hgs
parents: 39
diff changeset
    49
const QString iapIdentifierPrefix = "I_";
39
hgs
parents:
diff changeset
    50
hgs
parents:
diff changeset
    51
// ======== LOCAL FUNCTIONS ========
hgs
parents:
diff changeset
    52
hgs
parents:
diff changeset
    53
// ======== MEMBER FUNCTIONS ========
hgs
parents:
diff changeset
    54
hgs
parents:
diff changeset
    55
/*!
hgs
parents:
diff changeset
    56
    Constructor.
hgs
parents:
diff changeset
    57
 */
hgs
parents:
diff changeset
    58
WlanLoginEngine::WlanLoginEngine(QObject *parent): 
hgs
parents:
diff changeset
    59
    QObject(parent),
hgs
parents:
diff changeset
    60
    mEngineState(WaitingForStart),
hgs
parents:
diff changeset
    61
    mServiceRequestCompleted(false),
hgs
parents:
diff changeset
    62
    mNetConfigurationManager(new QNetworkConfigurationManager(this)),
hgs
parents:
diff changeset
    63
    mNetworkAccessManager(new WlanLoginNetworkAccessManager(this)),
hgs
parents:
diff changeset
    64
    mNetworkSession(NULL),
hgs
parents:
diff changeset
    65
    mIctsWrapper(NULL),
hgs
parents:
diff changeset
    66
    mIctsFirstRun(true),
hgs
parents:
diff changeset
    67
    mIap(0),
hgs
parents:
diff changeset
    68
    mNetId(0),
hgs
parents:
diff changeset
    69
    mRedirectionUrl(QUrl(""))            
hgs
parents:
diff changeset
    70
{
hgs
parents:
diff changeset
    71
    OstTraceFunctionEntry0(WLANLOGINENGINE_WLANLOGINENGINE_ENTRY);
hgs
parents:
diff changeset
    72
    
hgs
parents:
diff changeset
    73
    bool connectStatus = connect(
hgs
parents:
diff changeset
    74
        mNetConfigurationManager,
hgs
parents:
diff changeset
    75
        SIGNAL(updateCompleted()),
hgs
parents:
diff changeset
    76
        this, 
hgs
parents:
diff changeset
    77
        SLOT(handleUpdateCompleted()));  
hgs
parents:
diff changeset
    78
    Q_ASSERT(connectStatus == true);
hgs
parents:
diff changeset
    79
            
hgs
parents:
diff changeset
    80
    OstTraceFunctionExit0(WLANLOGINENGINE_WLANLOGINENGINE_EXIT);
hgs
parents:
diff changeset
    81
}
hgs
parents:
diff changeset
    82
hgs
parents:
diff changeset
    83
hgs
parents:
diff changeset
    84
/*!
hgs
parents:
diff changeset
    85
    Destructor.
hgs
parents:
diff changeset
    86
 */
hgs
parents:
diff changeset
    87
WlanLoginEngine::~WlanLoginEngine()
hgs
parents:
diff changeset
    88
{
hgs
parents:
diff changeset
    89
    OstTraceFunctionEntry0(WLANLOGINENGINE_DESTRUCTOR_ENTRY);
43
hgs
parents: 39
diff changeset
    90
hgs
parents: 39
diff changeset
    91
    if (mNetworkSession) {
hgs
parents: 39
diff changeset
    92
        mNetworkSession->close();
hgs
parents: 39
diff changeset
    93
    }
39
hgs
parents:
diff changeset
    94
    
hgs
parents:
diff changeset
    95
    OstTraceFunctionExit0(WLANLOGINENGINE_DESTRUCTOR_EXIT);
hgs
parents:
diff changeset
    96
}
hgs
parents:
diff changeset
    97
hgs
parents:
diff changeset
    98
hgs
parents:
diff changeset
    99
/*!
hgs
parents:
diff changeset
   100
    Function that returns pointer to network access manager.
hgs
parents:
diff changeset
   101
    
hgs
parents:
diff changeset
   102
    @return Pointer to WlanLoginNetworkAccessManager
hgs
parents:
diff changeset
   103
 */
hgs
parents:
diff changeset
   104
WlanLoginNetworkAccessManager* WlanLoginEngine::networkAccessManager() const
hgs
parents:
diff changeset
   105
{
hgs
parents:
diff changeset
   106
    return mNetworkAccessManager;
hgs
parents:
diff changeset
   107
}
hgs
parents:
diff changeset
   108
hgs
parents:
diff changeset
   109
hgs
parents:
diff changeset
   110
/*!
hgs
parents:
diff changeset
   111
    Function that returns current state of the engine.
hgs
parents:
diff changeset
   112
    
hgs
parents:
diff changeset
   113
    @return engine state
hgs
parents:
diff changeset
   114
 */
hgs
parents:
diff changeset
   115
WlanLoginEngine::EngineState WlanLoginEngine::engineState()
hgs
parents:
diff changeset
   116
{
hgs
parents:
diff changeset
   117
    return mEngineState;    
hgs
parents:
diff changeset
   118
}
hgs
parents:
diff changeset
   119
hgs
parents:
diff changeset
   120
hgs
parents:
diff changeset
   121
/*!
hgs
parents:
diff changeset
   122
    Function that sets the current state of the engine.
hgs
parents:
diff changeset
   123
    
hgs
parents:
diff changeset
   124
    @param [in] newState New state of the engine to be set
hgs
parents:
diff changeset
   125
 */
hgs
parents:
diff changeset
   126
void WlanLoginEngine::setEngineState(WlanLoginEngine::EngineState newState)
hgs
parents:
diff changeset
   127
{
hgs
parents:
diff changeset
   128
    mEngineState = newState;
hgs
parents:
diff changeset
   129
}
hgs
parents:
diff changeset
   130
hgs
parents:
diff changeset
   131
hgs
parents:
diff changeset
   132
/*!
hgs
parents:
diff changeset
   133
    This slot handles startLogin signal from Qt Highway service provider
hgs
parents:
diff changeset
   134
    
hgs
parents:
diff changeset
   135
    @param [in] iapId Internet access point ID for a connection that we should attach to'
hgs
parents:
diff changeset
   136
    @param [in] netId Network Id for the connection to be used
hgs
parents:
diff changeset
   137
    @param [in] redirectionUrl The URL that we were redirected to by the first internet connectivity test
hgs
parents:
diff changeset
   138
    
hgs
parents:
diff changeset
   139
 */
hgs
parents:
diff changeset
   140
void WlanLoginEngine::handleStartLogin(int iapId, int netId, QUrl redirectionUrl)
hgs
parents:
diff changeset
   141
{
hgs
parents:
diff changeset
   142
    OstTraceFunctionEntry0(WLANLOGINENGINE_HANDLESTARTLOGIN_ENTRY);
hgs
parents:
diff changeset
   143
   
hgs
parents:
diff changeset
   144
    mIap = iapId; 
hgs
parents:
diff changeset
   145
    OstTrace1(
hgs
parents:
diff changeset
   146
        TRACE_NORMAL,
hgs
parents:
diff changeset
   147
        WLANLOGINENGINE_HANDLESTARTLOGIN_IAP_TRACE,
hgs
parents:
diff changeset
   148
        "WlanLoginEngine::handleStartLogin;mIap=%d",
hgs
parents:
diff changeset
   149
        mIap);
hgs
parents:
diff changeset
   150
  
hgs
parents:
diff changeset
   151
    mNetId = netId;
hgs
parents:
diff changeset
   152
    OstTrace1(
hgs
parents:
diff changeset
   153
        TRACE_NORMAL,
hgs
parents:
diff changeset
   154
        WLANLOGINENGINE_HANDLESTARTLOGIN_NETID_TRACE,
hgs
parents:
diff changeset
   155
        "WlanLoginEngine::handleStartLogin;mNetId=%d",
hgs
parents:
diff changeset
   156
        mNetId);
hgs
parents:
diff changeset
   157
       
hgs
parents:
diff changeset
   158
    mRedirectionUrl = redirectionUrl;
hgs
parents:
diff changeset
   159
    
hgs
parents:
diff changeset
   160
#ifdef OST_TRACE_COMPILER_IN_USE
hgs
parents:
diff changeset
   161
    QString url = mRedirectionUrl.toString();
hgs
parents:
diff changeset
   162
    TPtrC tmp(url.utf16(),url.length() );
hgs
parents:
diff changeset
   163
    
hgs
parents:
diff changeset
   164
    OstTraceExt1(
hgs
parents:
diff changeset
   165
        TRACE_NORMAL,
hgs
parents:
diff changeset
   166
        WLANLOGINENGINE_HANDLESTARTLOGIN_URL_TRACE, 
hgs
parents:
diff changeset
   167
        "WlanLoginEngine::handleStartLogin;mRedirectionUrl=%S",
hgs
parents:
diff changeset
   168
        tmp);
hgs
parents:
diff changeset
   169
#endif
hgs
parents:
diff changeset
   170
        
hgs
parents:
diff changeset
   171
    //Create ICTS instance as we know needed parameters now
hgs
parents:
diff changeset
   172
    mIctsWrapper = new IctsWrapper(mIap, mNetId, this);
hgs
parents:
diff changeset
   173
    
hgs
parents:
diff changeset
   174
    bool connectStatus = connect(
hgs
parents:
diff changeset
   175
        mIctsWrapper,
hgs
parents:
diff changeset
   176
        SIGNAL(connectivityTestResult(IctsWrapper::ConnectivityTestResult, QUrl)), 
hgs
parents:
diff changeset
   177
        this,
hgs
parents:
diff changeset
   178
        SLOT(handleConnectivityTestResult(IctsWrapper::ConnectivityTestResult, QUrl)));  
hgs
parents:
diff changeset
   179
    Q_ASSERT(connectStatus == true);
hgs
parents:
diff changeset
   180
    
hgs
parents:
diff changeset
   181
    //Update network configurations as only states of the cellular IAP's are reliable 
hgs
parents:
diff changeset
   182
    //after creating network configuration manager
hgs
parents:
diff changeset
   183
    
hgs
parents:
diff changeset
   184
    setEngineState(UpdatingNetworkConfigurations);
hgs
parents:
diff changeset
   185
    mNetConfigurationManager->updateConfigurations();
hgs
parents:
diff changeset
   186
    
hgs
parents:
diff changeset
   187
    OstTraceFunctionExit0(WLANLOGINENGINE_HANDLESTARTLOGIN_EXIT);
hgs
parents:
diff changeset
   188
}
hgs
parents:
diff changeset
   189
hgs
parents:
diff changeset
   190
/*!
hgs
parents:
diff changeset
   191
    This slot handles stopLogin signal from Qt Highway service provider
hgs
parents:
diff changeset
   192
        
hgs
parents:
diff changeset
   193
 */
hgs
parents:
diff changeset
   194
void WlanLoginEngine::handleStopLogin()
hgs
parents:
diff changeset
   195
{
hgs
parents:
diff changeset
   196
    OstTraceFunctionEntry0(WLANLOGINENGINE_HANDLESTOPLOGIN_ENTRY);
hgs
parents:
diff changeset
   197
hgs
parents:
diff changeset
   198
    // Exit application
hgs
parents:
diff changeset
   199
    qApp->quit();
hgs
parents:
diff changeset
   200
hgs
parents:
diff changeset
   201
    OstTraceFunctionExit0(WLANLOGINENGINE_HANDLESTOPLOGIN_EXIT);
hgs
parents:
diff changeset
   202
}
hgs
parents:
diff changeset
   203
hgs
parents:
diff changeset
   204
hgs
parents:
diff changeset
   205
/*!
hgs
parents:
diff changeset
   206
    This slot handles updateCompleted signal from QNetworkConfigManager
hgs
parents:
diff changeset
   207
        
hgs
parents:
diff changeset
   208
 */
hgs
parents:
diff changeset
   209
void WlanLoginEngine::handleUpdateCompleted()
hgs
parents:
diff changeset
   210
{
hgs
parents:
diff changeset
   211
   OstTraceFunctionEntry0(WLANLOGINENGINE_HANDLEUPDATECOMPLETED_ENTRY);
hgs
parents:
diff changeset
   212
   
hgs
parents:
diff changeset
   213
   //States of the available configurations are now updated and
hgs
parents:
diff changeset
   214
   //we can open the network session to provided IAP
hgs
parents:
diff changeset
   215
   
hgs
parents:
diff changeset
   216
   openSession();
hgs
parents:
diff changeset
   217
hgs
parents:
diff changeset
   218
   OstTraceFunctionExit0(WLANLOGINENGINE_HANDLEUPDATECOMPLETED_EXIT);
hgs
parents:
diff changeset
   219
}
hgs
parents:
diff changeset
   220
hgs
parents:
diff changeset
   221
/*!
hgs
parents:
diff changeset
   222
    This function handles opening of the network session to the specified IAP.
hgs
parents:
diff changeset
   223
    If IAP is not already in connected state, function completes service request
hgs
parents:
diff changeset
   224
    with connection dropped status and show a message box to user.
hgs
parents:
diff changeset
   225
        
hgs
parents:
diff changeset
   226
 */
hgs
parents:
diff changeset
   227
void WlanLoginEngine::openSession()
hgs
parents:
diff changeset
   228
{
hgs
parents:
diff changeset
   229
    OstTraceFunctionEntry0(WLANLOGINENGINE_OPENSESSION_ENTRY);
hgs
parents:
diff changeset
   230
hgs
parents:
diff changeset
   231
    setEngineState(WlanLoginEngine::OpeningNetworkSession);
hgs
parents:
diff changeset
   232
    
hgs
parents:
diff changeset
   233
    //Get configuration that matches the provided IAP
43
hgs
parents: 39
diff changeset
   234
	//Note that identifier must be given in format I_ + IAP ID
hgs
parents: 39
diff changeset
   235
    QNetworkConfiguration netConfiguration = mNetConfigurationManager->configurationFromIdentifier(iapIdentifierPrefix + QString::number(mIap));    
39
hgs
parents:
diff changeset
   236
    
hgs
parents:
diff changeset
   237
    OstTrace1(
hgs
parents:
diff changeset
   238
        TRACE_NORMAL,
hgs
parents:
diff changeset
   239
        WLANLOGINENGINE_OPENSESSION_CONFIGURATION_IDENTIFIER_TRACE,
hgs
parents:
diff changeset
   240
        "WlanLoginEngine::openSession;netConfiguration identifier=%d",
hgs
parents:
diff changeset
   241
        netConfiguration.identifier().toInt());
hgs
parents:
diff changeset
   242
    
hgs
parents:
diff changeset
   243
    OstTrace1(TRACE_NORMAL,
hgs
parents:
diff changeset
   244
        WLANLOGINENGINE_OPENSESSION_CONFIGURATION_STATE_TRACE,
hgs
parents:
diff changeset
   245
        "WlanLoginEngine::openSession;netConfiguration state=%d",
hgs
parents:
diff changeset
   246
        netConfiguration.state());
hgs
parents:
diff changeset
   247
    
hgs
parents:
diff changeset
   248
#ifdef OST_TRACE_COMPILER_IN_USE
hgs
parents:
diff changeset
   249
    QString string = netConfiguration.name();
hgs
parents:
diff changeset
   250
    TPtrC tmp(string.utf16(),string.length() );
hgs
parents:
diff changeset
   251
    
hgs
parents:
diff changeset
   252
    OstTraceExt1(
hgs
parents:
diff changeset
   253
        TRACE_NORMAL,
hgs
parents:
diff changeset
   254
        WLANLOGINENGINE_OPENSESSION_CONFIGURATION_NAME_TRACE, 
hgs
parents:
diff changeset
   255
        "WlanLoginEngine::openSession;netConfiguration name=%S",
hgs
parents:
diff changeset
   256
        tmp );
hgs
parents:
diff changeset
   257
       
hgs
parents:
diff changeset
   258
    string = netConfiguration.bearerName();
hgs
parents:
diff changeset
   259
    tmp.Set(string.utf16(),string.length());
hgs
parents:
diff changeset
   260
    
hgs
parents:
diff changeset
   261
    OstTraceExt1(
hgs
parents:
diff changeset
   262
        TRACE_NORMAL,
hgs
parents:
diff changeset
   263
        WLANLOGINENGINE_OPENSESSION_CONFIGURATION_BEARER_NAME_TRACE, 
hgs
parents:
diff changeset
   264
        "WlanLoginEngine::openSession;netConfiguration bearerName=%S",
hgs
parents:
diff changeset
   265
        tmp );
hgs
parents:
diff changeset
   266
#endif
hgs
parents:
diff changeset
   267
    
hgs
parents:
diff changeset
   268
    //Check that configuration state is active before opening session
hgs
parents:
diff changeset
   269
    //Otherwise show disconnected message box
hgs
parents:
diff changeset
   270
    
hgs
parents:
diff changeset
   271
    if (netConfiguration.state() == QNetworkConfiguration::Active)
hgs
parents:
diff changeset
   272
        {
hgs
parents:
diff changeset
   273
        //Create network session to IAP that was provided in startup
hgs
parents:
diff changeset
   274
        mNetworkSession = new QNetworkSession(netConfiguration, this);
hgs
parents:
diff changeset
   275
        
hgs
parents:
diff changeset
   276
        bool connectStatus = connect(
hgs
parents:
diff changeset
   277
            mNetworkSession,
hgs
parents:
diff changeset
   278
            SIGNAL(opened()),
hgs
parents:
diff changeset
   279
            this, 
hgs
parents:
diff changeset
   280
            SLOT(handleSessionOpened()));
hgs
parents:
diff changeset
   281
        Q_ASSERT(connectStatus == true);
hgs
parents:
diff changeset
   282
        
hgs
parents:
diff changeset
   283
        connectStatus = connect(
hgs
parents:
diff changeset
   284
            mNetworkSession,
hgs
parents:
diff changeset
   285
            SIGNAL(stateChanged(QNetworkSession::State)), 
hgs
parents:
diff changeset
   286
            this,
hgs
parents:
diff changeset
   287
            SLOT(handleSessionStateChanged(QNetworkSession::State)));       
hgs
parents:
diff changeset
   288
        Q_ASSERT(connectStatus == true);
hgs
parents:
diff changeset
   289
        
hgs
parents:
diff changeset
   290
        connectStatus = connect(
hgs
parents:
diff changeset
   291
            mNetworkSession,
hgs
parents:
diff changeset
   292
            SIGNAL(error(QNetworkSession::SessionError)), 
hgs
parents:
diff changeset
   293
            this,
hgs
parents:
diff changeset
   294
            SLOT(handleSessionError(QNetworkSession::SessionError)));   
hgs
parents:
diff changeset
   295
        Q_ASSERT(connectStatus == true);
hgs
parents:
diff changeset
   296
        
hgs
parents:
diff changeset
   297
        mNetworkSession->open();
hgs
parents:
diff changeset
   298
        } else {
hgs
parents:
diff changeset
   299
            showConnectionDroppedMessageBox();
hgs
parents:
diff changeset
   300
        }
hgs
parents:
diff changeset
   301
    
hgs
parents:
diff changeset
   302
    OstTraceFunctionExit0(WLANLOGINENGINE_OPENSESSION_EXIT);
hgs
parents:
diff changeset
   303
}
hgs
parents:
diff changeset
   304
hgs
parents:
diff changeset
   305
hgs
parents:
diff changeset
   306
/*!
hgs
parents:
diff changeset
   307
    This function handles sessionOpened signal from QNetworkSession. It informs view that
hgs
parents:
diff changeset
   308
    connection is ready to be used.
hgs
parents:
diff changeset
   309
        
hgs
parents:
diff changeset
   310
 */
hgs
parents:
diff changeset
   311
void WlanLoginEngine::handleSessionOpened()
hgs
parents:
diff changeset
   312
{
hgs
parents:
diff changeset
   313
    OstTraceFunctionEntry0(WLANLOGINENGINE_HANDLESESSIONOPENED_ENTRY);
hgs
parents:
diff changeset
   314
hgs
parents:
diff changeset
   315
    setEngineState(NetworkSessionOpened);
hgs
parents:
diff changeset
   316
    //Send indication to view that connection is ready
hgs
parents:
diff changeset
   317
    emit connectionReady(mRedirectionUrl);
hgs
parents:
diff changeset
   318
hgs
parents:
diff changeset
   319
    OstTraceFunctionExit0(WLANLOGINENGINE_HANDLESESSIONOPENED_EXIT);
hgs
parents:
diff changeset
   320
}
hgs
parents:
diff changeset
   321
hgs
parents:
diff changeset
   322
hgs
parents:
diff changeset
   323
/*!
hgs
parents:
diff changeset
   324
    This function handles sessionStateChanged signal from QNetworkSession.
hgs
parents:
diff changeset
   325
    @param [in] newState New state of the session  
hgs
parents:
diff changeset
   326
 */
hgs
parents:
diff changeset
   327
void WlanLoginEngine::handleSessionStateChanged(QNetworkSession::State newState)
hgs
parents:
diff changeset
   328
{
hgs
parents:
diff changeset
   329
    OstTraceFunctionEntry0(WLANLOGINENGINE_HANDLESESSIONSTATECHANGED_ENTRY);
hgs
parents:
diff changeset
   330
hgs
parents:
diff changeset
   331
    OstTrace1(
hgs
parents:
diff changeset
   332
        TRACE_NORMAL,
hgs
parents:
diff changeset
   333
        WLANLOGINENGINE_HANDLESESSIONSTATECHANGED_STATE_TRACE,
hgs
parents:
diff changeset
   334
        "WlanLoginEngine::handleSessionStateChanged;newState=%d",
hgs
parents:
diff changeset
   335
        newState );
hgs
parents:
diff changeset
   336
    
hgs
parents:
diff changeset
   337
    OstTraceFunctionExit0(WLANLOGINENGINE_HANDLESESSIONSTATECHANGED_EXIT);
hgs
parents:
diff changeset
   338
}
hgs
parents:
diff changeset
   339
hgs
parents:
diff changeset
   340
hgs
parents:
diff changeset
   341
/*!
hgs
parents:
diff changeset
   342
    This function handles sessionError signal from QNetworkSession
hgs
parents:
diff changeset
   343
    @param [in] error session error     
hgs
parents:
diff changeset
   344
 */
hgs
parents:
diff changeset
   345
void WlanLoginEngine::handleSessionError(QNetworkSession::SessionError error)
hgs
parents:
diff changeset
   346
{
hgs
parents:
diff changeset
   347
    OstTraceFunctionEntry0(WLANLOGINENGINE_HANDLESESSIONERROR_ENTRY);
hgs
parents:
diff changeset
   348
        
hgs
parents:
diff changeset
   349
    OstTrace1(
hgs
parents:
diff changeset
   350
        TRACE_NORMAL,
hgs
parents:
diff changeset
   351
        WLANLOGINENGINE_SESSION_ERROR_TRACE,
hgs
parents:
diff changeset
   352
        "WlanLoginEngine::handleSessionError;error=%d",
hgs
parents:
diff changeset
   353
        error);
hgs
parents:
diff changeset
   354
    
hgs
parents:
diff changeset
   355
    switch (engineState()) {    
hgs
parents:
diff changeset
   356
    case OpeningNetworkSession:
hgs
parents:
diff changeset
   357
        showConnectionDroppedMessageBox();
hgs
parents:
diff changeset
   358
        break;
hgs
parents:
diff changeset
   359
        
hgs
parents:
diff changeset
   360
    case NetworkSessionOpened:
hgs
parents:
diff changeset
   361
    case IctsRan:
hgs
parents:
diff changeset
   362
        if (error == QNetworkSession::SessionAbortedError ) {
hgs
parents:
diff changeset
   363
            showConnectionDroppedMessageBox();
hgs
parents:
diff changeset
   364
        }
hgs
parents:
diff changeset
   365
        break;
hgs
parents:
diff changeset
   366
        
hgs
parents:
diff changeset
   367
    case RunningIcts:
hgs
parents:
diff changeset
   368
        if (error == QNetworkSession::SessionAbortedError ) {
hgs
parents:
diff changeset
   369
            stopIcts();
hgs
parents:
diff changeset
   370
            showConnectionDroppedMessageBox();
hgs
parents:
diff changeset
   371
        }
hgs
parents:
diff changeset
   372
        break;
hgs
parents:
diff changeset
   373
        
hgs
parents:
diff changeset
   374
    default:
hgs
parents:
diff changeset
   375
        break;
hgs
parents:
diff changeset
   376
    }
hgs
parents:
diff changeset
   377
        
hgs
parents:
diff changeset
   378
    OstTraceFunctionExit0(WLANLOGINENGINE_HANDLESESSIONERROR_EXIT);
hgs
parents:
diff changeset
   379
}
hgs
parents:
diff changeset
   380
hgs
parents:
diff changeset
   381
/*!
hgs
parents:
diff changeset
   382
    This function handles startIcts signal and starts connectivity test in polling mode
hgs
parents:
diff changeset
   383
        
hgs
parents:
diff changeset
   384
 */
hgs
parents:
diff changeset
   385
void WlanLoginEngine::handleStartIcts()
hgs
parents:
diff changeset
   386
{
hgs
parents:
diff changeset
   387
    OstTraceFunctionEntry0(WLANLOGINENGINE_HANDLESTARTICTS_ENTRY);
hgs
parents:
diff changeset
   388
    
hgs
parents:
diff changeset
   389
    if (!mIctsWrapper->isPolling()) {
hgs
parents:
diff changeset
   390
        setEngineState(RunningIcts);
hgs
parents:
diff changeset
   391
        mIctsWrapper->startPolling(totalPollingTime, pollingInterval);
hgs
parents:
diff changeset
   392
    }
hgs
parents:
diff changeset
   393
hgs
parents:
diff changeset
   394
    OstTraceFunctionExit0(WLANLOGINENGINE_HANDLESTARTICTS_EXIT);
hgs
parents:
diff changeset
   395
}
hgs
parents:
diff changeset
   396
hgs
parents:
diff changeset
   397
/*!
hgs
parents:
diff changeset
   398
    This function stops internet connectivity test
hgs
parents:
diff changeset
   399
        
hgs
parents:
diff changeset
   400
 */
hgs
parents:
diff changeset
   401
void WlanLoginEngine::stopIcts()
hgs
parents:
diff changeset
   402
{
hgs
parents:
diff changeset
   403
    OstTraceFunctionEntry0(WLANLOGINENGINE_STOPICTS_ENTRY);
hgs
parents:
diff changeset
   404
hgs
parents:
diff changeset
   405
    if (mIctsWrapper->isPolling()) {
hgs
parents:
diff changeset
   406
        mIctsWrapper->stopPolling();
hgs
parents:
diff changeset
   407
    }
hgs
parents:
diff changeset
   408
hgs
parents:
diff changeset
   409
    OstTraceFunctionExit0(WLANLOGINENGINE_STOPICTS_EXIT);
hgs
parents:
diff changeset
   410
}
hgs
parents:
diff changeset
   411
hgs
parents:
diff changeset
   412
/*!
hgs
parents:
diff changeset
   413
    This slot handles connectivityTestResult signal from ICTS wrapper
hgs
parents:
diff changeset
   414
    @param [in] result Result of the internet connectivity test
hgs
parents:
diff changeset
   415
    @param [in] redirectionUrl The URL that we are being redirected, valid only if result is HttpAuthenticationNeeded
hgs
parents:
diff changeset
   416
 */
hgs
parents:
diff changeset
   417
hgs
parents:
diff changeset
   418
void WlanLoginEngine::handleConnectivityTestResult(IctsWrapper::ConnectivityTestResult result, QUrl redirectUrl)
hgs
parents:
diff changeset
   419
{
hgs
parents:
diff changeset
   420
    OstTraceFunctionEntry0(WLANLOGINENGINE_HANDLECONNECTIVITYTESTRESULT_ENTRY);
hgs
parents:
diff changeset
   421
hgs
parents:
diff changeset
   422
    Q_UNUSED(redirectUrl);
hgs
parents:
diff changeset
   423
    
hgs
parents:
diff changeset
   424
    setEngineState(IctsRan);
hgs
parents:
diff changeset
   425
    mIctsFirstRun = false;
hgs
parents:
diff changeset
   426
    
hgs
parents:
diff changeset
   427
    if (result == IctsWrapper::ConnectionOk){
hgs
parents:
diff changeset
   428
        emit ictsOk();
hgs
parents:
diff changeset
   429
    }
hgs
parents:
diff changeset
   430
    
hgs
parents:
diff changeset
   431
    OstTraceFunctionExit0(WLANLOGINENGINE_HANDLECONNECTIVITYTESTRESULT_EXIT);
hgs
parents:
diff changeset
   432
}
hgs
parents:
diff changeset
   433
hgs
parents:
diff changeset
   434
/*!
hgs
parents:
diff changeset
   435
    This slot handles cancelTriggered signal from the view
hgs
parents:
diff changeset
   436
        
hgs
parents:
diff changeset
   437
 */
hgs
parents:
diff changeset
   438
void WlanLoginEngine::handleCancelTriggered()
hgs
parents:
diff changeset
   439
{
hgs
parents:
diff changeset
   440
    OstTraceFunctionEntry0(WLANLOGINENGINE_HANDLECANCELTRIGGERED_ENTRY);
hgs
parents:
diff changeset
   441
    
hgs
parents:
diff changeset
   442
    //Stop ICTS if it is running:
hgs
parents:
diff changeset
   443
    if (engineState() == RunningIcts) {
hgs
parents:
diff changeset
   444
        stopIcts();
hgs
parents:
diff changeset
   445
        if (mIctsFirstRun) {
hgs
parents:
diff changeset
   446
            emitCompleteServiceRequest(WlanLoginService::WlanLoginStatusCancel);
hgs
parents:
diff changeset
   447
        } else {
hgs
parents:
diff changeset
   448
            //Previous ICTS must have failed as cancel action can't be selected from UI if
hgs
parents:
diff changeset
   449
            //it has passed
hgs
parents:
diff changeset
   450
            emitCompleteServiceRequest(WlanLoginService::WlanLoginStatusFailed);
hgs
parents:
diff changeset
   451
        }         
hgs
parents:
diff changeset
   452
    } else if (engineState() == IctsRan) {
hgs
parents:
diff changeset
   453
        //ICTS must have failed as cancel action can't be selected from UI if
hgs
parents:
diff changeset
   454
        //it has passed
hgs
parents:
diff changeset
   455
        emitCompleteServiceRequest(WlanLoginService::WlanLoginStatusFailed);
hgs
parents:
diff changeset
   456
    } else {
hgs
parents:
diff changeset
   457
        //ICTS not run yet
hgs
parents:
diff changeset
   458
        emitCompleteServiceRequest(WlanLoginService::WlanLoginStatusCancel); 
hgs
parents:
diff changeset
   459
    }
hgs
parents:
diff changeset
   460
hgs
parents:
diff changeset
   461
    OstTraceFunctionExit0(WLANLOGINENGINE_HANDLECANCELTRIGGERED_EXIT);
hgs
parents:
diff changeset
   462
}
hgs
parents:
diff changeset
   463
hgs
parents:
diff changeset
   464
/*!
hgs
parents:
diff changeset
   465
    This slot handles nextTriggered signal from the view
hgs
parents:
diff changeset
   466
        
hgs
parents:
diff changeset
   467
 */
hgs
parents:
diff changeset
   468
void WlanLoginEngine::handleNextTriggered()
hgs
parents:
diff changeset
   469
{
hgs
parents:
diff changeset
   470
    OstTraceFunctionEntry0(WLANLOGINENGINE_HANDLENEXTTRIGGERED_ENTRY);
hgs
parents:
diff changeset
   471
        
hgs
parents:
diff changeset
   472
    emitCompleteServiceRequest(WlanLoginService::WlanLoginStatusNext);
hgs
parents:
diff changeset
   473
    
hgs
parents:
diff changeset
   474
    //put application to background:
hgs
parents:
diff changeset
   475
    WlanLoginApplication* app = static_cast<WlanLoginApplication *>(this->parent());    
hgs
parents:
diff changeset
   476
    app->mainWindow()->lower();
hgs
parents:
diff changeset
   477
    
hgs
parents:
diff changeset
   478
    OstTraceFunctionExit0(WLANLOGINENGINE_HANDLENEXTTRIGGERED_EXIT);
hgs
parents:
diff changeset
   479
}
hgs
parents:
diff changeset
   480
hgs
parents:
diff changeset
   481
/*!
hgs
parents:
diff changeset
   482
    This slot handles continueTriggered signal from the view
hgs
parents:
diff changeset
   483
        
hgs
parents:
diff changeset
   484
 */
hgs
parents:
diff changeset
   485
void WlanLoginEngine::handleContinueTriggered()
hgs
parents:
diff changeset
   486
{
hgs
parents:
diff changeset
   487
    OstTraceFunctionEntry0(WLANLOGINENGINE_HANDLECONTINUETRIGGERED_ENTRY);
hgs
parents:
diff changeset
   488
    
hgs
parents:
diff changeset
   489
    //put application to background:
hgs
parents:
diff changeset
   490
    WlanLoginApplication* app = static_cast<WlanLoginApplication *>(this->parent());
hgs
parents:
diff changeset
   491
    app->mainWindow()->lower();
hgs
parents:
diff changeset
   492
    
hgs
parents:
diff changeset
   493
    OstTraceFunctionExit0(WLANLOGINENGINE_HANDLECONTINUETRIGGERED_EXIT);
hgs
parents:
diff changeset
   494
}
hgs
parents:
diff changeset
   495
hgs
parents:
diff changeset
   496
/*!
hgs
parents:
diff changeset
   497
    This function shows connection dropped message box to the user
hgs
parents:
diff changeset
   498
        
hgs
parents:
diff changeset
   499
 */
hgs
parents:
diff changeset
   500
void WlanLoginEngine::showConnectionDroppedMessageBox()
hgs
parents:
diff changeset
   501
{
hgs
parents:
diff changeset
   502
    OstTraceFunctionEntry0(WLANLOGINENGINE_SHOWCONNECTIONDROPPEDMESSAGEBOX_ENTRY);
hgs
parents:
diff changeset
   503
    
hgs
parents:
diff changeset
   504
    HbMessageBox *messageBox = new HbMessageBox(hbTrId("txt_occ_info_wlan_connection_closed_login_applica"));
hgs
parents:
diff changeset
   505
    messageBox->setAttribute(Qt::WA_DeleteOnClose);
hgs
parents:
diff changeset
   506
    messageBox->setTimeout(messageBoxTimeout);
hgs
parents:
diff changeset
   507
    messageBox->open(this,SLOT(connectionDroppedMessageBoxClosed(HbAction*)));
hgs
parents:
diff changeset
   508
    
hgs
parents:
diff changeset
   509
    OstTraceFunctionExit0(WLANLOGINENGINE_SHOWCONNECTIONDROPPEDMESSAGEBOX_EXIT);
hgs
parents:
diff changeset
   510
}
hgs
parents:
diff changeset
   511
hgs
parents:
diff changeset
   512
void WlanLoginEngine::connectionDroppedMessageBoxClosed(HbAction* action)
hgs
parents:
diff changeset
   513
{
hgs
parents:
diff changeset
   514
    OstTraceFunctionEntry0(WLANLOGINENGINE_HANDLEMESSAGEBOXCLOSED_ENTRY);
hgs
parents:
diff changeset
   515
    
hgs
parents:
diff changeset
   516
    Q_UNUSED(action);
hgs
parents:
diff changeset
   517
        
hgs
parents:
diff changeset
   518
    if (mServiceRequestCompleted == false ) {
hgs
parents:
diff changeset
   519
        emitCompleteServiceRequest(WlanLoginService::WlanLoginStatusConnectionDropped);
hgs
parents:
diff changeset
   520
                
hgs
parents:
diff changeset
   521
    } else {
hgs
parents:
diff changeset
   522
        //If Qt Highway service request is already completed when connection drops, we have to make exit by our own
hgs
parents:
diff changeset
   523
        qApp->exit();
hgs
parents:
diff changeset
   524
    }               
hgs
parents:
diff changeset
   525
      
hgs
parents:
diff changeset
   526
    OstTraceFunctionEntry0(WLANLOGINENGINE_HANDLEMESSAGEBOXCLOSED_EXIT);    
hgs
parents:
diff changeset
   527
}
hgs
parents:
diff changeset
   528
hgs
parents:
diff changeset
   529
/*!
hgs
parents:
diff changeset
   530
    This function completes Qt Highway service request
hgs
parents:
diff changeset
   531
    @param [in] status completeing status of the service request   
hgs
parents:
diff changeset
   532
 */
hgs
parents:
diff changeset
   533
void WlanLoginEngine::emitCompleteServiceRequest(WlanLoginService::WlanLoginStatus status )
hgs
parents:
diff changeset
   534
{
hgs
parents:
diff changeset
   535
    OstTraceFunctionEntry0(WLANLOGINENGINE_EMITCOMPLETESERVICEREQUEST_ENTRY);
hgs
parents:
diff changeset
   536
        
hgs
parents:
diff changeset
   537
    mServiceRequestCompleted = true;
hgs
parents:
diff changeset
   538
    OstTrace1(
hgs
parents:
diff changeset
   539
        TRACE_BORDER,
hgs
parents:
diff changeset
   540
        WLANLOGINENGINE_EMITCOMPLETESERVICEREQUEST_EMIT_TRACE,
hgs
parents:
diff changeset
   541
        "WlanLoginEngine::emitCompleteServiceRequest with status:;status=%d",
hgs
parents:
diff changeset
   542
        status);
hgs
parents:
diff changeset
   543
    emit completeServiceRequest(status);
hgs
parents:
diff changeset
   544
hgs
parents:
diff changeset
   545
    OstTraceFunctionExit0(WLANLOGINENGINE_EMITCOMPLETESERVICEREQUEST_EXIT);
hgs
parents:
diff changeset
   546
}