wlanutilities/wlanlogin/wlanloginapp/src/wlanloginview.cpp
changeset 56 de27cc8389dd
parent 46 2fbd1d709fe7
--- a/wlanutilities/wlanlogin/wlanloginapp/src/wlanloginview.cpp	Wed Aug 18 10:52:46 2010 +0300
+++ b/wlanutilities/wlanlogin/wlanloginapp/src/wlanloginview.cpp	Thu Sep 02 21:36:44 2010 +0300
@@ -21,15 +21,16 @@
 #include <QWebFrame>
 
 // System includes
-#include <HbDocumentLoader>
 #include <HbToolbar>
 #include <HbAction>
 #include <HbProgressBar>
 #include <HbScrollBar>
 #include <HbScrollArea>
 #include <HbWidget>
+#include <HbMainWindow>
 
 // User includes
+#include "wlanlogindocumentloader.h"
 #include "wlanloginview.h"
 #include "wlanloginwebview.h"
 #include "wlanloginwebpage.h"
@@ -50,6 +51,8 @@
 // External function prototypes
 
 // Local constants
+//! WLAN Login view docml file
+static const QString wlanLoginViewDocml(":/docml/wlanloginview.docml");
 
 // ======== LOCAL FUNCTIONS ========
 
@@ -58,75 +61,29 @@
 /*!
     Constructor       
  */
-WlanLoginView::WlanLoginView(WlanLoginApplication* appRef):
-    mAppRef(appRef),
-    mMainLayout(NULL),
-    mContentLayout(NULL),
+WlanLoginView::WlanLoginView(WlanLoginMainWindow* mainWindow):
+    mMainWindow(mainWindow),
+    mDocLoader(new WlanLoginDocumentLoader(mainWindow)),
     mProgressBar(NULL),
-    mScrollArea(NULL),
     mScrollAreaContent(NULL),
     mWebView(NULL),
-    mToolBar(NULL),
-    mCancelAction(NULL),
     mNextAction(NULL),
-    mContinueAction(NULL)
+    mFirstIctsOkResult(true)
 {   
     OstTraceFunctionEntry0(WLANLOGINVIEW_WLANLOGINVIEW_ENTRY);
     
+    loadDocml();
+    
     setTitleBarVisible(false);
     setStatusBarVisible(false);
     
-    mMainLayout = new QGraphicsLinearLayout(Qt::Vertical);
-    mMainLayout->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
-    mMainLayout->setContentsMargins(0,0,0,0);
-    setLayout(mMainLayout);
-      
-    mScrollArea = new HbScrollArea();
-    mScrollArea->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
-    mScrollArea->setVerticalScrollBarPolicy(HbScrollArea::ScrollBarAlwaysOff);
-    mScrollArea->setHorizontalScrollBarPolicy(HbScrollArea::ScrollBarAlwaysOff);  
-    mScrollArea->setScrollDirections(Qt::Vertical | Qt::Horizontal);
-    mScrollArea->setClampingStyle( HbScrollArea::StrictClamping );
-    mScrollArea->setScrollingStyle( HbScrollArea::PanWithFollowOn );
-    mMainLayout->addItem(mScrollArea);
-   
-    mScrollAreaContent = new HbWidget();
-    mScrollAreaContent->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);    
-    mContentLayout = new QGraphicsLinearLayout(Qt::Vertical);
-    mContentLayout->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
-    mContentLayout->setContentsMargins(0,0,0,0);
-    mScrollAreaContent->setLayout(mContentLayout);
-    mScrollArea->setContentWidget(mScrollAreaContent);
-    
     // Set white background to content widget
     QPixmap pixmap(10,10);
     pixmap.fill(Qt::white);
     QGraphicsPixmapItem *pixmapItem = new QGraphicsPixmapItem(pixmap);
     mScrollAreaContent->setBackgroundItem(pixmapItem);
     
-    //Note: Progress bar is added to layout when loadStarted signal is handled and
-    //removed when loadFinished signal is handled
-    mProgressBar = new HbProgressBar();  
-    mProgressBar->setRange( 0,100);
-    mProgressBar->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
-    mProgressBar->setVisible(false);
-    
-    mWebView = new WlanLoginWebView();
-    mContentLayout->addItem(mWebView);
-    mWebView->page()->setNetworkAccessManager(appRef->engine()->networkAccessManager());
-    
-    //Create tool bar
-    mToolBar = new HbToolBar();   
-    mCancelAction = mToolBar->addAction(HbIcon("qtg_mono_exit"),"");
-    mNextAction = mToolBar->addAction(HbIcon("qtg_mono_arrow_right"),"");
-    mContinueAction = mToolBar->addAction(HbIcon("qtg_mono_tick"),"");
-    
-    setToolBar(mToolBar);
-    setActiveToolBarAction(Cancel);
-
-    mToolBar->show();
-    mWebView->show();
-    mScrollArea->show();
+    mWebView->page()->setNetworkAccessManager(mMainWindow->application()->engine()->networkAccessManager());
     
     bool connectStatus = connect(
         mWebView,
@@ -177,18 +134,55 @@
         SLOT(handleNextAction()));
     Q_ASSERT(connectStatus == true);
     
-    connectStatus = connect(
-        mContinueAction,
-        SIGNAL(triggered()),
-        this,
-        SLOT(handleContinueAction()));
-    Q_ASSERT(connectStatus == true);
-    
     show();
     
     OstTraceFunctionExit0(WLANLOGINVIEW_WLANLOGINVIEW_EXIT);
 }
 
+/*!
+   Loads widgets and objects from the docml file. 
+ */
+void WlanLoginView::loadDocml()
+{
+    OstTraceFunctionEntry0( WLANLOGINVIEW_LOADDOCML_ENTRY );
+
+    setObjectName(QString("wlanLoginView"));
+    QObjectList objectList;
+    objectList.append(this);
+    mDocLoader->setObjectTree(objectList);
+
+    bool ok = false;
+    
+    mDocLoader->load(wlanLoginViewDocml, &ok);
+    Q_ASSERT(ok);
+     
+    //Fetch pointer for progress bar
+    mProgressBar = reinterpret_cast<HbProgressBar *>(
+        mDocLoader->findObject("progressBar"));
+    Q_ASSERT(mProgressBar);
+    
+    //Fetch pointer for scroll area content
+    mScrollAreaContent = reinterpret_cast<HbWidget *>(
+        mDocLoader->findObject("scrollAreaContent"));
+    Q_ASSERT(mScrollAreaContent);
+    
+    //Fetch pointer for Web View
+    mWebView = reinterpret_cast<WlanLoginWebView *>(
+        mDocLoader->findObject("webView"));
+    Q_ASSERT(mWebView);
+    
+	//Fetch pointer for cancel action
+    mCancelAction = qobject_cast<HbAction*> (
+        mDocLoader->findObject("cancelAction"));
+    Q_ASSERT(mCancelAction != NULL);
+ 
+	//Fetch pointer for next action
+    mNextAction = qobject_cast<HbAction*> (
+        mDocLoader->findObject("nextAction"));
+    Q_ASSERT(mNextAction != NULL);
+    
+    OstTraceFunctionExit0( WLANLOGINVIEW_LOADDOCML_EXIT );
+}
 
 /*!
     Destructor       
@@ -197,12 +191,6 @@
 {
     OstTraceFunctionEntry0(WLANLOGINVIEW_DESTRUCTOR_ENTRY);
     
-    //delete progress bar here as it is not on the layout all the time and
-    //thus may not have a parent at all.
-    if (mProgressBar) {
-        delete mProgressBar;
-    }
-    
     OstTraceFunctionExit0(WLANLOGINVIEW_DESTRUCTOR_EXIT);
 }
 
@@ -243,7 +231,7 @@
     OstTraceFunctionEntry0( WLANLOGINVIEW_ADJUSTVIEWSIZE_ENTRY );
     
     //Store current screen size
-    QSizeF screenSize = mAppRef->mainWindow()->layoutRect().size();
+    QSizeF screenSize = mMainWindow->layoutRect().size();
     
     //Store current content size
     QSize contentSize = mWebView->page()->mainFrame()->contentsSize();
@@ -275,7 +263,7 @@
     
     
     //Set preferred content size to current screen size
-    mWebView->page()->setPreferredContentsSize(mAppRef->mainWindow()->layoutRect().size().toSize());
+    mWebView->page()->setPreferredContentsSize(mMainWindow->layoutRect().size().toSize());
       
     OstTraceFunctionEntry0( WLANLOGINVIEW_ADJUSTVIEWSIZE_EXIT );
 }
@@ -312,7 +300,6 @@
 {
    OstTraceFunctionEntry0(WLANLOGINVIEW_HANDLELOADSTARTED_ENTRY);
    
-   mContentLayout->insertItem(0, mProgressBar);
     mProgressBar->setVisible(true);
     
     OstTraceFunctionExit0(WLANLOGINVIEW_HANDLELOADSTARTED_EXIT);
@@ -349,7 +336,6 @@
     }
    
     mProgressBar->setVisible(false);
-    mContentLayout->removeItem(mProgressBar);
   
     OstTraceFunctionExit0(WLANLOGINVIEW_HANDLELOADFINISHED_EXIT);
 }
@@ -362,8 +348,6 @@
 void WlanLoginView::handleFormSubmitted()
 {
     OstTraceFunctionEntry0(WLANLOGINVIEW_HANDLEFORMSUBMITTED_ENTRY);
-               
-    //TODO: Check why QWebPage sends this signal to times in a row when user pushes submit button in a web page
     
     //User has submitted credentials, let's start internet connectivity test
     emit startIcts();       
@@ -380,6 +364,7 @@
 {
     OstTraceFunctionEntry0(WLANLOGINVIEW_HANDLECANCELACTION_ENTRY);
 
+    mWebView->stop();
     emit cancelTriggered();
                
     OstTraceFunctionExit0(WLANLOGINVIEW_HANDLECANCELACTION_EXIT);
@@ -395,29 +380,12 @@
     OstTraceFunctionEntry0(WLANLOGINVIEW_HANDLENEXTACTION_ENTRY);
 
     emit nextTriggered();
-    
-    //Change toolabr action to "Continue" as we are going to background 
-    setActiveToolBarAction(Continue);
         
     OstTraceFunctionExit0(WLANLOGINVIEW_HANDLENEXTACTION_EXIT);
 }
 
 
 /*!
-    This function handles triggered signal from "continue" button
-
- */
-void WlanLoginView::handleContinueAction()
-{
-    OstTraceFunctionEntry0(WLANLOGINVIEW_HANDLECONTINUEACTION_ENTRY);
-
-    emit continueTriggered();
-    
-    OstTraceFunctionExit0(WLANLOGINVIEW_HANDLECONTINUEACTION_EXIT);
-}
-
-
-/*!
     This function handles ictsOk signal from engine
 
  */
@@ -425,58 +393,15 @@
 {
     OstTraceFunctionEntry0(WLANLOGINVIEW_HANDLEICTSRESULT_ENTRY);
             
-    setActiveToolBarAction(Next);
+    mNextAction->setEnabled(true);
+    
+    //Send application to background automatically only in first successfull login
+    //as in other cases WLAN Wizard won't exist in the underneath
+    if (mFirstIctsOkResult) {
+        mFirstIctsOkResult = false;
+        emit nextTriggered();
+    }
     
     OstTraceFunctionExit0(WLANLOGINVIEW_HANDLEICTSRESULT_EXIT);
 }
 
-/*!
-    This function sets active action to the toolbar and hides other actions
-
-     @param [in] newAction Action to be set to toolbar
- */
-void WlanLoginView::setActiveToolBarAction(ActionType newAction)
-{
-    OstTraceFunctionEntry0( WLANLOGINVIEW_SETACTIVETOOLBARACTION_ENTRY );
-    
-    switch (newAction) {
-    case Cancel:
-        mNextAction->setEnabled(false);
-        mNextAction->setVisible(false);
-        
-        mContinueAction->setEnabled(false);
-        mContinueAction->setVisible(false);
-        
-        mCancelAction->setVisible(true);
-        mCancelAction->setEnabled(true);
-        break;
-            
-    case Next:
-        mCancelAction->setEnabled(false);
-        mCancelAction->setVisible(false);
-        
-        mContinueAction->setEnabled(false);
-        mContinueAction->setVisible(false);
-        
-        mNextAction->setVisible(true);
-        mNextAction->setEnabled(true);
-        break;
-            
-    case Continue:
-        mCancelAction->setEnabled(false);
-        mCancelAction->setVisible(false);
-        
-        mNextAction->setEnabled(false);
-        mNextAction->setVisible(false);
-        
-        mContinueAction->setVisible(true);
-        mContinueAction->setEnabled(true);
-        break;
-            
-    default:
-        break;
-            
-    }
-    
-    OstTraceFunctionExit0( WLANLOGINVIEW_SETACTIVETOOLBARACTION_EXIT );
-}