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