wlanutilities/wlanlogin/wlanloginapp/src/wlanloginview.cpp
changeset 39 7b3e49e4608a
child 53 bdc64aa9b954
equal deleted inserted replaced
36:682dd021f9be 39:7b3e49e4608a
       
     1 /*
       
     2 * Copyright (c) 2010 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 * Main view for the WLAN Login application
       
    16 * 
       
    17 */
       
    18 
       
    19 
       
    20 #include <QGraphicsLinearLayout>
       
    21 #include <QWebFrame>
       
    22 
       
    23 // System includes
       
    24 #include <HbDocumentLoader>
       
    25 #include <HbToolbar>
       
    26 #include <HbAction>
       
    27 #include <HbProgressBar>
       
    28 #include <HbScrollBar>
       
    29 #include <HbScrollArea>
       
    30 #include <HbWidget>
       
    31 
       
    32 // User includes
       
    33 #include "wlanloginview.h"
       
    34 #include "wlanloginwebview.h"
       
    35 #include "wlanloginwebpage.h"
       
    36 #include "wlanloginmainwindow.h"
       
    37 #include "wlanloginengine.h"
       
    38 #include "ictsqtwrapper.h"
       
    39 
       
    40 #include "OstTraceDefinitions.h"
       
    41 #ifdef OST_TRACE_COMPILER_IN_USE
       
    42 #include "wlanloginviewTraces.h"
       
    43 #endif
       
    44 
       
    45 /*!
       
    46     \class WlanLoginView
       
    47     \brief Main view for the WLAN Login application
       
    48 */
       
    49 
       
    50 // External function prototypes
       
    51 
       
    52 // Local constants
       
    53 
       
    54 // ======== LOCAL FUNCTIONS ========
       
    55 
       
    56 // ======== MEMBER FUNCTIONS ========
       
    57 
       
    58 /*!
       
    59     Constructor       
       
    60  */
       
    61 WlanLoginView::WlanLoginView(WlanLoginApplication* appRef):
       
    62     mAppRef(appRef),
       
    63     mMainLayout(NULL),
       
    64     mContentLayout(NULL),
       
    65     mProgressBar(NULL),
       
    66     mScrollArea(NULL),
       
    67     mScrollAreaContent(NULL),
       
    68     mWebView(NULL),
       
    69     mToolBar(NULL),
       
    70     mCancelAction(NULL),
       
    71     mNextAction(NULL),
       
    72     mContinueAction(NULL)
       
    73 {   
       
    74     OstTraceFunctionEntry0(WLANLOGINVIEW_WLANLOGINVIEW_ENTRY);
       
    75     
       
    76     setTitleBarVisible(false);
       
    77     setStatusBarVisible(false);
       
    78     
       
    79     mMainLayout = new QGraphicsLinearLayout(Qt::Vertical);
       
    80     mMainLayout->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
       
    81     mMainLayout->setContentsMargins(0,0,0,0);
       
    82     setLayout(mMainLayout);
       
    83       
       
    84     mScrollArea = new HbScrollArea();
       
    85     mScrollArea->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
       
    86     mScrollArea->setVerticalScrollBarPolicy(HbScrollArea::ScrollBarAlwaysOff);
       
    87     mScrollArea->setHorizontalScrollBarPolicy(HbScrollArea::ScrollBarAlwaysOff);  
       
    88     mScrollArea->setScrollDirections(Qt::Vertical | Qt::Horizontal);
       
    89     mScrollArea->setClampingStyle( HbScrollArea::StrictClamping );
       
    90     mScrollArea->setScrollingStyle( HbScrollArea::PanWithFollowOn );
       
    91     mMainLayout->addItem(mScrollArea);
       
    92    
       
    93     mScrollAreaContent = new HbWidget();
       
    94     mScrollAreaContent->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);    
       
    95     mContentLayout = new QGraphicsLinearLayout(Qt::Vertical);
       
    96     mContentLayout->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
       
    97     mContentLayout->setContentsMargins(0,0,0,0);
       
    98     mScrollAreaContent->setLayout(mContentLayout);
       
    99     mScrollArea->setContentWidget(mScrollAreaContent);
       
   100     
       
   101     // Set white background to content widget
       
   102     QPixmap pixmap(10,10);
       
   103     pixmap.fill(Qt::white);
       
   104     QGraphicsPixmapItem *pixmapItem = new QGraphicsPixmapItem(pixmap);
       
   105     mScrollAreaContent->setBackgroundItem(pixmapItem);
       
   106     
       
   107     //Note: Progress bar is added to layout when loadStarted signal is handled and
       
   108     //removed when loadFinished signal is handled
       
   109     mProgressBar = new HbProgressBar();  
       
   110     mProgressBar->setRange( 0,100);
       
   111     mProgressBar->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
       
   112     mProgressBar->setVisible(false);
       
   113     
       
   114     mWebView = new WlanLoginWebView();
       
   115     mContentLayout->addItem(mWebView);
       
   116     mWebView->page()->setNetworkAccessManager(appRef->engine()->networkAccessManager());
       
   117     
       
   118     //Create tool bar
       
   119     mToolBar = new HbToolBar();   
       
   120     mCancelAction = mToolBar->addAction(HbIcon("qtg_mono_exit"),"");
       
   121     mNextAction = mToolBar->addAction(HbIcon("qtg_mono_arrow_right"),"");
       
   122     mContinueAction = mToolBar->addAction(HbIcon("qtg_mono_tick"),"");
       
   123     
       
   124     setToolBar(mToolBar);
       
   125     setActiveToolBarAction(Cancel);
       
   126 
       
   127     mToolBar->show();
       
   128     mWebView->show();
       
   129     mScrollArea->show();
       
   130     
       
   131     bool connectStatus = connect(
       
   132         mWebView,
       
   133         SIGNAL(loadStarted()),
       
   134         this,
       
   135         SLOT(handleLoadStarted())); 
       
   136     Q_ASSERT(connectStatus == true);
       
   137     
       
   138     connectStatus = connect(
       
   139         mWebView,
       
   140         SIGNAL(loadProgress(int)),
       
   141         this,
       
   142         SLOT(handleLoadProgress(int))); 
       
   143     Q_ASSERT(connectStatus == true);
       
   144     
       
   145     connectStatus = connect(
       
   146         mWebView,
       
   147         SIGNAL(loadFinished(bool)),
       
   148         this,
       
   149         SLOT(handleLoadFinished(bool)));
       
   150     Q_ASSERT(connectStatus == true);
       
   151     
       
   152     connectStatus = connect(
       
   153     mWebView,
       
   154     SIGNAL(urlChanged(const QUrl&)),
       
   155     this,
       
   156     SLOT(handleUrlChanged(const QUrl&)));
       
   157     Q_ASSERT(connectStatus == true);
       
   158     
       
   159     connectStatus = connect(
       
   160         mWebView->page(),
       
   161         SIGNAL(formSubmitted()),
       
   162         this,
       
   163         SLOT(handleFormSubmitted()));
       
   164     Q_ASSERT(connectStatus == true);
       
   165     
       
   166     connectStatus = connect(
       
   167         mCancelAction,
       
   168         SIGNAL(triggered()),
       
   169         this,
       
   170         SLOT(handleCancelAction()));
       
   171     Q_ASSERT(connectStatus == true);
       
   172     
       
   173     connectStatus = connect(
       
   174         mNextAction,
       
   175         SIGNAL(triggered()),
       
   176         this,
       
   177         SLOT(handleNextAction()));
       
   178     Q_ASSERT(connectStatus == true);
       
   179     
       
   180     connectStatus = connect(
       
   181         mContinueAction,
       
   182         SIGNAL(triggered()),
       
   183         this,
       
   184         SLOT(handleContinueAction()));
       
   185     Q_ASSERT(connectStatus == true);
       
   186     
       
   187     show();
       
   188     
       
   189     OstTraceFunctionExit0(WLANLOGINVIEW_WLANLOGINVIEW_EXIT);
       
   190 }
       
   191 
       
   192 
       
   193 /*!
       
   194     Destructor       
       
   195  */
       
   196 WlanLoginView::~WlanLoginView()
       
   197 {
       
   198     OstTraceFunctionEntry0(WLANLOGINVIEW_DESTRUCTOR_ENTRY);
       
   199     
       
   200     //delete progress bar here as it is not on the layout all the time and
       
   201     //thus may not have a parent at all.
       
   202     if (mProgressBar) {
       
   203         delete mProgressBar;
       
   204     }
       
   205     
       
   206     OstTraceFunctionExit0(WLANLOGINVIEW_DESTRUCTOR_EXIT);
       
   207 }
       
   208 
       
   209 
       
   210 /*!
       
   211     This function handles connectionReady signal from engine and starts loading of
       
   212     provided web page
       
   213     
       
   214     @param [in] url URL to be loaded
       
   215  */
       
   216 void WlanLoginView::handleConnectionReady(QUrl url)
       
   217 {
       
   218     OstTraceFunctionEntry0(WLANLOGINVIEW_HANDLECONNECTIONREADY_ENTRY);
       
   219     
       
   220     mWebView->load(url);
       
   221     
       
   222     OstTraceFunctionExit0(WLANLOGINVIEW_HANDLECONNECTIONREADY_EXIT);
       
   223 }
       
   224 
       
   225 
       
   226 /*!
       
   227     This function handles orientationChanged signal
       
   228     
       
   229     @param [in] orientation New Orientation of the screen
       
   230  */
       
   231 void WlanLoginView::handleOrientationChanged(Qt::Orientation orientation)
       
   232 {
       
   233     Q_UNUSED(orientation);
       
   234     OstTraceFunctionEntry0( WLANLOGINVIEW_ORIENTATIONCHANGED_ENTRY );
       
   235     
       
   236     adjustViewSize();
       
   237     
       
   238     OstTraceFunctionEntry0( WLANLOGINVIEW_ORIENTATIONCHANGED_EXIT );
       
   239 }
       
   240 
       
   241 void WlanLoginView::adjustViewSize()
       
   242 {
       
   243     OstTraceFunctionEntry0( WLANLOGINVIEW_ADJUSTVIEWSIZE_ENTRY );
       
   244     
       
   245     //Store current screen size
       
   246     QSizeF screenSize = mAppRef->mainWindow()->layoutRect().size();
       
   247     
       
   248     //Store current content size
       
   249     QSize contentSize = mWebView->page()->mainFrame()->contentsSize();
       
   250     
       
   251     //Set viewPortSize to biggest values of content size or current screen size 
       
   252     QSize newViewPortSize;
       
   253     if (screenSize.toSize().width() > contentSize.width()) {
       
   254         newViewPortSize.setWidth(screenSize.toSize().width());
       
   255     } else {    
       
   256         newViewPortSize.setWidth(contentSize.width());
       
   257     }
       
   258     
       
   259     if (screenSize.toSize().height() > contentSize.height()) {
       
   260         newViewPortSize.setHeight(screenSize.toSize().height());
       
   261     } else {    
       
   262         newViewPortSize.setHeight(contentSize.height());
       
   263     }
       
   264     mWebView->page()->setViewportSize(newViewPortSize);
       
   265     
       
   266     
       
   267     //Set Web View size to same size as viewport
       
   268     mWebView->setMinimumWidth((qreal)newViewPortSize.width());
       
   269     mWebView->setMaximumWidth((qreal)newViewPortSize.width());
       
   270     mWebView->setPreferredWidth((qreal)newViewPortSize.width());
       
   271     
       
   272     mWebView->setMinimumHeight((qreal)newViewPortSize.height());
       
   273     mWebView->setMaximumHeight((qreal)newViewPortSize.height());
       
   274     mWebView->setPreferredHeight((qreal)newViewPortSize.height());
       
   275     
       
   276     
       
   277     //Set preferred content size to current screen size
       
   278     mWebView->page()->setPreferredContentsSize(mAppRef->mainWindow()->layoutRect().size().toSize());
       
   279       
       
   280     OstTraceFunctionEntry0( WLANLOGINVIEW_ADJUSTVIEWSIZE_EXIT );
       
   281 }
       
   282 
       
   283 
       
   284 /*!
       
   285     This function handles urlChanged signal from QGraphicsWebView
       
   286     
       
   287     @param [in] newUrl New URL
       
   288  */
       
   289 void WlanLoginView::handleUrlChanged(const QUrl& newUrl )
       
   290 {
       
   291     OstTraceFunctionEntry0(WLANLOGINVIEW_HANDLEURLCHANGED_ENTRY);
       
   292  
       
   293 #ifdef OST_TRACE_COMPILER_IN_USE
       
   294     QString url = newUrl.toString();
       
   295     TPtrC tmp(url.utf16(),url.length() );
       
   296     
       
   297     OstTraceExt1(
       
   298         TRACE_NORMAL,
       
   299         WLANLOGINVIEW_HANDLEURLCHANGED_URL_TRACE, 
       
   300         "WlanLoginEngine::handleUrlChanged;newUrl=%S",
       
   301         tmp);
       
   302 #endif
       
   303 
       
   304     OstTraceFunctionExit0(WLANLOGINVIEW_HANDLEURLCHANGED_EXIT);
       
   305 }
       
   306 
       
   307 
       
   308 /*!
       
   309     This function handles loadStarted signal from QGraphicsWebView
       
   310  */
       
   311 void WlanLoginView::handleLoadStarted()
       
   312 {
       
   313    OstTraceFunctionEntry0(WLANLOGINVIEW_HANDLELOADSTARTED_ENTRY);
       
   314    
       
   315    mContentLayout->insertItem(0, mProgressBar);
       
   316     mProgressBar->setVisible(true);
       
   317     
       
   318     OstTraceFunctionExit0(WLANLOGINVIEW_HANDLELOADSTARTED_EXIT);
       
   319 }
       
   320 
       
   321 
       
   322 /*!
       
   323     This function handles loadProgress signal from QGraphicsWebView
       
   324 
       
   325     @param [in] progressValue Indicates page loading progress: 0..100
       
   326  */
       
   327 void WlanLoginView::handleLoadProgress(int progressValue)
       
   328 {
       
   329     OstTraceFunctionEntry0(WLANLOGINVIEW_HANDLELOADPROGRESS_ENTRY);
       
   330     
       
   331     mProgressBar->setProgressValue(progressValue);
       
   332     
       
   333     OstTraceFunctionExit0(WLANLOGINVIEW_HANDLELOADPROGRESS_EXIT);
       
   334 }
       
   335 
       
   336 
       
   337 /*!
       
   338     This function handles loadfinished signal from QGraphicsWebView
       
   339 
       
   340     @param [in] status Success status
       
   341  */
       
   342 void WlanLoginView::handleLoadFinished(bool status)
       
   343 {
       
   344    OstTraceFunctionEntry0(WLANLOGINVIEW_HANDLELOADFINISHED_ENTRY);
       
   345    
       
   346     if(status)
       
   347     {   
       
   348         adjustViewSize();
       
   349     }
       
   350    
       
   351     mProgressBar->setVisible(false);
       
   352     mContentLayout->removeItem(mProgressBar);
       
   353   
       
   354     OstTraceFunctionExit0(WLANLOGINVIEW_HANDLELOADFINISHED_EXIT);
       
   355 }
       
   356 
       
   357 
       
   358 /*!
       
   359     This function handles formSumitted signal from WlanLoginWebPage
       
   360 
       
   361  */
       
   362 void WlanLoginView::handleFormSubmitted()
       
   363 {
       
   364     OstTraceFunctionEntry0(WLANLOGINVIEW_HANDLEFORMSUBMITTED_ENTRY);
       
   365                
       
   366     //TODO: Check why QWebPage sends this signal to times in a row when user pushes submit button in a web page
       
   367     
       
   368     //User has submitted credentials, let's start internet connectivity test
       
   369     emit startIcts();       
       
   370     
       
   371     OstTraceFunctionExit0(WLANLOGINVIEW_HANDLEFORMSUBMITTED_EXIT);
       
   372 }
       
   373 
       
   374 
       
   375 /*!
       
   376     This function handles triggered signal from "cancel" button
       
   377 
       
   378  */
       
   379 void WlanLoginView::handleCancelAction()
       
   380 {
       
   381     OstTraceFunctionEntry0(WLANLOGINVIEW_HANDLECANCELACTION_ENTRY);
       
   382 
       
   383     emit cancelTriggered();
       
   384                
       
   385     OstTraceFunctionExit0(WLANLOGINVIEW_HANDLECANCELACTION_EXIT);
       
   386 }
       
   387 
       
   388 
       
   389 /*!
       
   390     This function handles triggered signal from "next" button
       
   391 
       
   392  */
       
   393 void WlanLoginView::handleNextAction()
       
   394 {
       
   395     OstTraceFunctionEntry0(WLANLOGINVIEW_HANDLENEXTACTION_ENTRY);
       
   396 
       
   397     emit nextTriggered();
       
   398     
       
   399     //Change toolabr action to "Continue" as we are going to background 
       
   400     setActiveToolBarAction(Continue);
       
   401         
       
   402     OstTraceFunctionExit0(WLANLOGINVIEW_HANDLENEXTACTION_EXIT);
       
   403 }
       
   404 
       
   405 
       
   406 /*!
       
   407     This function handles triggered signal from "continue" button
       
   408 
       
   409  */
       
   410 void WlanLoginView::handleContinueAction()
       
   411 {
       
   412     OstTraceFunctionEntry0(WLANLOGINVIEW_HANDLECONTINUEACTION_ENTRY);
       
   413 
       
   414     emit continueTriggered();
       
   415     
       
   416     OstTraceFunctionExit0(WLANLOGINVIEW_HANDLECONTINUEACTION_EXIT);
       
   417 }
       
   418 
       
   419 
       
   420 /*!
       
   421     This function handles ictsOk signal from engine
       
   422 
       
   423  */
       
   424 void WlanLoginView::handleIctsOk()
       
   425 {
       
   426     OstTraceFunctionEntry0(WLANLOGINVIEW_HANDLEICTSRESULT_ENTRY);
       
   427             
       
   428     setActiveToolBarAction(Next);
       
   429     
       
   430     OstTraceFunctionExit0(WLANLOGINVIEW_HANDLEICTSRESULT_EXIT);
       
   431 }
       
   432 
       
   433 /*!
       
   434     This function sets active action to the toolbar and hides other actions
       
   435 
       
   436      @param [in] newAction Action to be set to toolbar
       
   437  */
       
   438 void WlanLoginView::setActiveToolBarAction(ActionType newAction)
       
   439 {
       
   440     OstTraceFunctionEntry0( WLANLOGINVIEW_SETACTIVETOOLBARACTION_ENTRY );
       
   441     
       
   442     switch (newAction) {
       
   443     case Cancel:
       
   444         mNextAction->setEnabled(false);
       
   445         mNextAction->setVisible(false);
       
   446         
       
   447         mContinueAction->setEnabled(false);
       
   448         mContinueAction->setVisible(false);
       
   449         
       
   450         mCancelAction->setVisible(true);
       
   451         mCancelAction->setEnabled(true);
       
   452         break;
       
   453             
       
   454     case Next:
       
   455         mCancelAction->setEnabled(false);
       
   456         mCancelAction->setVisible(false);
       
   457         
       
   458         mContinueAction->setEnabled(false);
       
   459         mContinueAction->setVisible(false);
       
   460         
       
   461         mNextAction->setVisible(true);
       
   462         mNextAction->setEnabled(true);
       
   463         break;
       
   464             
       
   465     case Continue:
       
   466         mCancelAction->setEnabled(false);
       
   467         mCancelAction->setVisible(false);
       
   468         
       
   469         mNextAction->setEnabled(false);
       
   470         mNextAction->setVisible(false);
       
   471         
       
   472         mContinueAction->setVisible(true);
       
   473         mContinueAction->setEnabled(true);
       
   474         break;
       
   475             
       
   476     default:
       
   477         break;
       
   478             
       
   479     }
       
   480     
       
   481     OstTraceFunctionExit0( WLANLOGINVIEW_SETACTIVETOOLBARACTION_EXIT );
       
   482 }