wlanutilities/wlanlogin/wlanloginapp/src/wlanloginview.cpp
changeset 56 de27cc8389dd
parent 46 2fbd1d709fe7
equal deleted inserted replaced
50:d4198dcb9983 56:de27cc8389dd
    19 
    19 
    20 #include <QGraphicsLinearLayout>
    20 #include <QGraphicsLinearLayout>
    21 #include <QWebFrame>
    21 #include <QWebFrame>
    22 
    22 
    23 // System includes
    23 // System includes
    24 #include <HbDocumentLoader>
       
    25 #include <HbToolbar>
    24 #include <HbToolbar>
    26 #include <HbAction>
    25 #include <HbAction>
    27 #include <HbProgressBar>
    26 #include <HbProgressBar>
    28 #include <HbScrollBar>
    27 #include <HbScrollBar>
    29 #include <HbScrollArea>
    28 #include <HbScrollArea>
    30 #include <HbWidget>
    29 #include <HbWidget>
       
    30 #include <HbMainWindow>
    31 
    31 
    32 // User includes
    32 // User includes
       
    33 #include "wlanlogindocumentloader.h"
    33 #include "wlanloginview.h"
    34 #include "wlanloginview.h"
    34 #include "wlanloginwebview.h"
    35 #include "wlanloginwebview.h"
    35 #include "wlanloginwebpage.h"
    36 #include "wlanloginwebpage.h"
    36 #include "wlanloginmainwindow.h"
    37 #include "wlanloginmainwindow.h"
    37 #include "wlanloginengine.h"
    38 #include "wlanloginengine.h"
    48 */
    49 */
    49 
    50 
    50 // External function prototypes
    51 // External function prototypes
    51 
    52 
    52 // Local constants
    53 // Local constants
       
    54 //! WLAN Login view docml file
       
    55 static const QString wlanLoginViewDocml(":/docml/wlanloginview.docml");
    53 
    56 
    54 // ======== LOCAL FUNCTIONS ========
    57 // ======== LOCAL FUNCTIONS ========
    55 
    58 
    56 // ======== MEMBER FUNCTIONS ========
    59 // ======== MEMBER FUNCTIONS ========
    57 
    60 
    58 /*!
    61 /*!
    59     Constructor       
    62     Constructor       
    60  */
    63  */
    61 WlanLoginView::WlanLoginView(WlanLoginApplication* appRef):
    64 WlanLoginView::WlanLoginView(WlanLoginMainWindow* mainWindow):
    62     mAppRef(appRef),
    65     mMainWindow(mainWindow),
    63     mMainLayout(NULL),
    66     mDocLoader(new WlanLoginDocumentLoader(mainWindow)),
    64     mContentLayout(NULL),
       
    65     mProgressBar(NULL),
    67     mProgressBar(NULL),
    66     mScrollArea(NULL),
       
    67     mScrollAreaContent(NULL),
    68     mScrollAreaContent(NULL),
    68     mWebView(NULL),
    69     mWebView(NULL),
    69     mToolBar(NULL),
       
    70     mCancelAction(NULL),
       
    71     mNextAction(NULL),
    70     mNextAction(NULL),
    72     mContinueAction(NULL)
    71     mFirstIctsOkResult(true)
    73 {   
    72 {   
    74     OstTraceFunctionEntry0(WLANLOGINVIEW_WLANLOGINVIEW_ENTRY);
    73     OstTraceFunctionEntry0(WLANLOGINVIEW_WLANLOGINVIEW_ENTRY);
    75     
    74     
       
    75     loadDocml();
       
    76     
    76     setTitleBarVisible(false);
    77     setTitleBarVisible(false);
    77     setStatusBarVisible(false);
    78     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     
    79     
   101     // Set white background to content widget
    80     // Set white background to content widget
   102     QPixmap pixmap(10,10);
    81     QPixmap pixmap(10,10);
   103     pixmap.fill(Qt::white);
    82     pixmap.fill(Qt::white);
   104     QGraphicsPixmapItem *pixmapItem = new QGraphicsPixmapItem(pixmap);
    83     QGraphicsPixmapItem *pixmapItem = new QGraphicsPixmapItem(pixmap);
   105     mScrollAreaContent->setBackgroundItem(pixmapItem);
    84     mScrollAreaContent->setBackgroundItem(pixmapItem);
   106     
    85     
   107     //Note: Progress bar is added to layout when loadStarted signal is handled and
    86     mWebView->page()->setNetworkAccessManager(mMainWindow->application()->engine()->networkAccessManager());
   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     
    87     
   131     bool connectStatus = connect(
    88     bool connectStatus = connect(
   132         mWebView,
    89         mWebView,
   133         SIGNAL(loadStarted()),
    90         SIGNAL(loadStarted()),
   134         this,
    91         this,
   175         SIGNAL(triggered()),
   132         SIGNAL(triggered()),
   176         this,
   133         this,
   177         SLOT(handleNextAction()));
   134         SLOT(handleNextAction()));
   178     Q_ASSERT(connectStatus == true);
   135     Q_ASSERT(connectStatus == true);
   179     
   136     
   180     connectStatus = connect(
       
   181         mContinueAction,
       
   182         SIGNAL(triggered()),
       
   183         this,
       
   184         SLOT(handleContinueAction()));
       
   185     Q_ASSERT(connectStatus == true);
       
   186     
       
   187     show();
   137     show();
   188     
   138     
   189     OstTraceFunctionExit0(WLANLOGINVIEW_WLANLOGINVIEW_EXIT);
   139     OstTraceFunctionExit0(WLANLOGINVIEW_WLANLOGINVIEW_EXIT);
   190 }
   140 }
   191 
   141 
       
   142 /*!
       
   143    Loads widgets and objects from the docml file. 
       
   144  */
       
   145 void WlanLoginView::loadDocml()
       
   146 {
       
   147     OstTraceFunctionEntry0( WLANLOGINVIEW_LOADDOCML_ENTRY );
       
   148 
       
   149     setObjectName(QString("wlanLoginView"));
       
   150     QObjectList objectList;
       
   151     objectList.append(this);
       
   152     mDocLoader->setObjectTree(objectList);
       
   153 
       
   154     bool ok = false;
       
   155     
       
   156     mDocLoader->load(wlanLoginViewDocml, &ok);
       
   157     Q_ASSERT(ok);
       
   158      
       
   159     //Fetch pointer for progress bar
       
   160     mProgressBar = reinterpret_cast<HbProgressBar *>(
       
   161         mDocLoader->findObject("progressBar"));
       
   162     Q_ASSERT(mProgressBar);
       
   163     
       
   164     //Fetch pointer for scroll area content
       
   165     mScrollAreaContent = reinterpret_cast<HbWidget *>(
       
   166         mDocLoader->findObject("scrollAreaContent"));
       
   167     Q_ASSERT(mScrollAreaContent);
       
   168     
       
   169     //Fetch pointer for Web View
       
   170     mWebView = reinterpret_cast<WlanLoginWebView *>(
       
   171         mDocLoader->findObject("webView"));
       
   172     Q_ASSERT(mWebView);
       
   173     
       
   174 	//Fetch pointer for cancel action
       
   175     mCancelAction = qobject_cast<HbAction*> (
       
   176         mDocLoader->findObject("cancelAction"));
       
   177     Q_ASSERT(mCancelAction != NULL);
       
   178  
       
   179 	//Fetch pointer for next action
       
   180     mNextAction = qobject_cast<HbAction*> (
       
   181         mDocLoader->findObject("nextAction"));
       
   182     Q_ASSERT(mNextAction != NULL);
       
   183     
       
   184     OstTraceFunctionExit0( WLANLOGINVIEW_LOADDOCML_EXIT );
       
   185 }
   192 
   186 
   193 /*!
   187 /*!
   194     Destructor       
   188     Destructor       
   195  */
   189  */
   196 WlanLoginView::~WlanLoginView()
   190 WlanLoginView::~WlanLoginView()
   197 {
   191 {
   198     OstTraceFunctionEntry0(WLANLOGINVIEW_DESTRUCTOR_ENTRY);
   192     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     
   193     
   206     OstTraceFunctionExit0(WLANLOGINVIEW_DESTRUCTOR_EXIT);
   194     OstTraceFunctionExit0(WLANLOGINVIEW_DESTRUCTOR_EXIT);
   207 }
   195 }
   208 
   196 
   209 
   197 
   241 void WlanLoginView::adjustViewSize()
   229 void WlanLoginView::adjustViewSize()
   242 {
   230 {
   243     OstTraceFunctionEntry0( WLANLOGINVIEW_ADJUSTVIEWSIZE_ENTRY );
   231     OstTraceFunctionEntry0( WLANLOGINVIEW_ADJUSTVIEWSIZE_ENTRY );
   244     
   232     
   245     //Store current screen size
   233     //Store current screen size
   246     QSizeF screenSize = mAppRef->mainWindow()->layoutRect().size();
   234     QSizeF screenSize = mMainWindow->layoutRect().size();
   247     
   235     
   248     //Store current content size
   236     //Store current content size
   249     QSize contentSize = mWebView->page()->mainFrame()->contentsSize();
   237     QSize contentSize = mWebView->page()->mainFrame()->contentsSize();
   250     
   238     
   251     //Set viewPortSize to biggest values of content size or current screen size 
   239     //Set viewPortSize to biggest values of content size or current screen size 
   273     mWebView->setMaximumHeight((qreal)newViewPortSize.height());
   261     mWebView->setMaximumHeight((qreal)newViewPortSize.height());
   274     mWebView->setPreferredHeight((qreal)newViewPortSize.height());
   262     mWebView->setPreferredHeight((qreal)newViewPortSize.height());
   275     
   263     
   276     
   264     
   277     //Set preferred content size to current screen size
   265     //Set preferred content size to current screen size
   278     mWebView->page()->setPreferredContentsSize(mAppRef->mainWindow()->layoutRect().size().toSize());
   266     mWebView->page()->setPreferredContentsSize(mMainWindow->layoutRect().size().toSize());
   279       
   267       
   280     OstTraceFunctionEntry0( WLANLOGINVIEW_ADJUSTVIEWSIZE_EXIT );
   268     OstTraceFunctionEntry0( WLANLOGINVIEW_ADJUSTVIEWSIZE_EXIT );
   281 }
   269 }
   282 
   270 
   283 
   271 
   310  */
   298  */
   311 void WlanLoginView::handleLoadStarted()
   299 void WlanLoginView::handleLoadStarted()
   312 {
   300 {
   313    OstTraceFunctionEntry0(WLANLOGINVIEW_HANDLELOADSTARTED_ENTRY);
   301    OstTraceFunctionEntry0(WLANLOGINVIEW_HANDLELOADSTARTED_ENTRY);
   314    
   302    
   315    mContentLayout->insertItem(0, mProgressBar);
       
   316     mProgressBar->setVisible(true);
   303     mProgressBar->setVisible(true);
   317     
   304     
   318     OstTraceFunctionExit0(WLANLOGINVIEW_HANDLELOADSTARTED_EXIT);
   305     OstTraceFunctionExit0(WLANLOGINVIEW_HANDLELOADSTARTED_EXIT);
   319 }
   306 }
   320 
   307 
   347     {   
   334     {   
   348         adjustViewSize();
   335         adjustViewSize();
   349     }
   336     }
   350    
   337    
   351     mProgressBar->setVisible(false);
   338     mProgressBar->setVisible(false);
   352     mContentLayout->removeItem(mProgressBar);
       
   353   
   339   
   354     OstTraceFunctionExit0(WLANLOGINVIEW_HANDLELOADFINISHED_EXIT);
   340     OstTraceFunctionExit0(WLANLOGINVIEW_HANDLELOADFINISHED_EXIT);
   355 }
   341 }
   356 
   342 
   357 
   343 
   360 
   346 
   361  */
   347  */
   362 void WlanLoginView::handleFormSubmitted()
   348 void WlanLoginView::handleFormSubmitted()
   363 {
   349 {
   364     OstTraceFunctionEntry0(WLANLOGINVIEW_HANDLEFORMSUBMITTED_ENTRY);
   350     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     
   351     
   368     //User has submitted credentials, let's start internet connectivity test
   352     //User has submitted credentials, let's start internet connectivity test
   369     emit startIcts();       
   353     emit startIcts();       
   370     
   354     
   371     OstTraceFunctionExit0(WLANLOGINVIEW_HANDLEFORMSUBMITTED_EXIT);
   355     OstTraceFunctionExit0(WLANLOGINVIEW_HANDLEFORMSUBMITTED_EXIT);
   378  */
   362  */
   379 void WlanLoginView::handleCancelAction()
   363 void WlanLoginView::handleCancelAction()
   380 {
   364 {
   381     OstTraceFunctionEntry0(WLANLOGINVIEW_HANDLECANCELACTION_ENTRY);
   365     OstTraceFunctionEntry0(WLANLOGINVIEW_HANDLECANCELACTION_ENTRY);
   382 
   366 
       
   367     mWebView->stop();
   383     emit cancelTriggered();
   368     emit cancelTriggered();
   384                
   369                
   385     OstTraceFunctionExit0(WLANLOGINVIEW_HANDLECANCELACTION_EXIT);
   370     OstTraceFunctionExit0(WLANLOGINVIEW_HANDLECANCELACTION_EXIT);
   386 }
   371 }
   387 
   372 
   393 void WlanLoginView::handleNextAction()
   378 void WlanLoginView::handleNextAction()
   394 {
   379 {
   395     OstTraceFunctionEntry0(WLANLOGINVIEW_HANDLENEXTACTION_ENTRY);
   380     OstTraceFunctionEntry0(WLANLOGINVIEW_HANDLENEXTACTION_ENTRY);
   396 
   381 
   397     emit nextTriggered();
   382     emit nextTriggered();
   398     
       
   399     //Change toolabr action to "Continue" as we are going to background 
       
   400     setActiveToolBarAction(Continue);
       
   401         
   383         
   402     OstTraceFunctionExit0(WLANLOGINVIEW_HANDLENEXTACTION_EXIT);
   384     OstTraceFunctionExit0(WLANLOGINVIEW_HANDLENEXTACTION_EXIT);
   403 }
   385 }
   404 
   386 
   405 
   387 
   406 /*!
   388 /*!
   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
   389     This function handles ictsOk signal from engine
   422 
   390 
   423  */
   391  */
   424 void WlanLoginView::handleIctsOk()
   392 void WlanLoginView::handleIctsOk()
   425 {
   393 {
   426     OstTraceFunctionEntry0(WLANLOGINVIEW_HANDLEICTSRESULT_ENTRY);
   394     OstTraceFunctionEntry0(WLANLOGINVIEW_HANDLEICTSRESULT_ENTRY);
   427             
   395             
   428     setActiveToolBarAction(Next);
   396     mNextAction->setEnabled(true);
       
   397     
       
   398     //Send application to background automatically only in first successfull login
       
   399     //as in other cases WLAN Wizard won't exist in the underneath
       
   400     if (mFirstIctsOkResult) {
       
   401         mFirstIctsOkResult = false;
       
   402         emit nextTriggered();
       
   403     }
   429     
   404     
   430     OstTraceFunctionExit0(WLANLOGINVIEW_HANDLEICTSRESULT_EXIT);
   405     OstTraceFunctionExit0(WLANLOGINVIEW_HANDLEICTSRESULT_EXIT);
   431 }
   406 }
   432 
   407 
   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 }