ginebra/viewstack.cpp
changeset 5 0f2326c2a325
parent 1 b0dd75e285d2
child 6 1c3b8676e58c
equal deleted inserted replaced
1:b0dd75e285d2 5:0f2326c2a325
     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 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "utilities.h"
       
    20 #include <QtCore/QUrl>
       
    21 #include "viewstack.h"
       
    22 #include "viewcontroller.h"
       
    23 #include "chromeview.h"
       
    24 #include "chromewidget.h"
       
    25 #include "chromesnippet.h"
       
    26 #include "webpagecontroller.h"
       
    27 #include "HistoryFlowView.h"
       
    28 #include "WindowFlowView.h"
       
    29 
       
    30 
       
    31 ViewStack* ViewStack::getSingleton()
       
    32 {
       
    33     static ViewStack* singleton = 0;
       
    34     if(!singleton)
       
    35     {
       
    36         singleton = new ViewStack;
       
    37         singleton->setObjectName("viewStack");
       
    38     } // if(! singleton)
       
    39 
       
    40     assert(singleton);
       
    41     return singleton;
       
    42 }
       
    43 
       
    44 void ViewStack::fromWindowView(const QString &to)
       
    45 {
       
    46     emit (deActivateWindowView());
       
    47 
       
    48     m_chromeView->setViewofCurrentPage();
       
    49 
       
    50     WRT::WindowFlowView* windowView = static_cast<WRT::WindowFlowView *>(m_viewController->getView("WindowView"));
       
    51 
       
    52     disconnect(windowView, SIGNAL(ok(WrtBrowserContainer*)), this, SLOT(goBackFromWindowView()));
       
    53     disconnect(windowView, SIGNAL(addPageComplete()), this, SLOT(goBackFromWindowView()));
       
    54     disconnect(windowView, SIGNAL(centerIndexChanged(int)), this, SIGNAL(pageChanged(int)));
       
    55 
       
    56     m_viewController->showContent(to);
       
    57 }
       
    58 
       
    59 void ViewStack::fromGoAnywhereView(const QString &to)
       
    60 {
       
    61     WRT::HistoryFlowView* historyView = static_cast<WRT::HistoryFlowView*>(m_viewController->getView("historyView"));
       
    62 
       
    63     disconnect(historyView, SIGNAL(ok(int)), this, SLOT(loadHistoryItem(int)));
       
    64 
       
    65     m_viewController->showContent(to);
       
    66 
       
    67     disconnect(historyView, SIGNAL(activated()), this, SIGNAL(activateHistory()));
       
    68     disconnect(historyView, SIGNAL(deactivated()), this, SIGNAL(deActivateHistory()));
       
    69 }
       
    70 
       
    71 void ViewStack::fromWebView(const QString &to)
       
    72 {
       
    73     m_viewController->showContent(to);
       
    74     emit (deActivateWebView());
       
    75 }
       
    76 
       
    77 
       
    78 void ViewStack::fromBookmarkTreeView(const QString &to)
       
    79 {
       
    80     m_viewController->showContent(to);
       
    81     emit(deActivateBookmark());
       
    82 }
       
    83 
       
    84 
       
    85 void ViewStack::fromBookmarkHistoryView(const QString &to)
       
    86 {
       
    87     m_viewController->showContent(to);
       
    88     emit(deActivateBookMarkHistory());
       
    89 }
       
    90 
       
    91 void ViewStack::toGoAnywhereView()
       
    92 {
       
    93     emit (activateHistory()); // by default go to history view
       
    94 
       
    95     /* Connect ALL of goAnywhere's signals in one shot */
       
    96 
       
    97     WRT::HistoryFlowView* historyView = static_cast<WRT::HistoryFlowView*>(m_viewController->getView("historyView"));
       
    98 
       
    99     safe_connect(historyView, SIGNAL(ok(int)), this, SLOT(loadHistoryItem(int)))
       
   100     safe_connect(historyView, SIGNAL(activated()), this, SIGNAL(activateHistory()));
       
   101     safe_connect(historyView, SIGNAL(deactivated()), this, SIGNAL(deActivateHistory()));
       
   102 }
       
   103 
       
   104 void  ViewStack::initWindowView()
       
   105 {
       
   106     int width = m_chromeView->size().width();
       
   107     int height = m_chromeView->size().height();
       
   108 
       
   109     // FIXME: the snippet id is hardcode
       
   110     ChromeSnippet* visibleSnippet = m_chromeView->getChromeWidget()->getSnippet("StatusBarChromeId");
       
   111     if (visibleSnippet)
       
   112         height -= (int) (visibleSnippet->rect().height()); 
       
   113 
       
   114     visibleSnippet = m_chromeView->getChromeWidget()->getSnippet("WebViewToolbarId");
       
   115     if (visibleSnippet)
       
   116         height -= (int) (visibleSnippet->rect().height()); 
       
   117 
       
   118     if (m_chromeView->displayMode() ==  ChromeView::DisplayModePortrait) {
       
   119         visibleSnippet = m_chromeView->getChromeWidget()->getSnippet("WindowCountBarId");
       
   120         if (visibleSnippet)
       
   121             height -= (int) (visibleSnippet->rect().height()); 
       
   122     }
       
   123 
       
   124     QSize windowViewSize(width, height);
       
   125     WRT::WindowFlowView* windowView = static_cast<WRT::WindowFlowView *>(m_viewController->getView("WindowView"));
       
   126     windowView->setSize(windowViewSize);
       
   127 }
       
   128 
       
   129 void ViewStack::toWindowView()
       
   130 {
       
   131     emit(activateWindowView());
       
   132 
       
   133     WRT::WindowFlowView* windowView = static_cast<WRT::WindowFlowView *>(m_viewController->getView("WindowView"));
       
   134 
       
   135     safe_connect(windowView, SIGNAL(ok(WrtBrowserContainer*)), this, SLOT(goBackFromWindowView()));
       
   136     safe_connect(windowView, SIGNAL(addPageComplete()), this, SLOT(goBackFromWindowView()));
       
   137     safe_connect(windowView, SIGNAL(centerIndexChanged(int)), this, SIGNAL(pageChanged(int)));
       
   138 }
       
   139 
       
   140 void ViewStack::toWebView()
       
   141 {
       
   142     emit (activateWebView());
       
   143 }
       
   144 
       
   145 void ViewStack::toBookmarkHistoryView()
       
   146 {
       
   147     emit(activateBookMarkHistory());
       
   148 
       
   149 }
       
   150 
       
   151 void ViewStack::toBookmarkView()
       
   152 {
       
   153     emit(activateBookmark());
       
   154 }
       
   155 
       
   156 
       
   157 void ViewStack::switchView(const QString &to, const QString &from) {
       
   158 
       
   159     if (to == from) {
       
   160         return;
       
   161     }
       
   162     if (!m_viewController) {
       
   163         return;
       
   164     }
       
   165 
       
   166     if (from == "WindowView") {
       
   167         fromWindowView(to);
       
   168     }
       
   169     else if (from == "goAnywhereView") {
       
   170         fromGoAnywhereView(to);
       
   171     }
       
   172     else if (from == "webView") {
       
   173        if (to == "WindowView")
       
   174            initWindowView(); // to fix the size issue of windows view
       
   175        fromWebView(to);
       
   176     }
       
   177     else if (from == "bookmarkHistoryView") {
       
   178         fromBookmarkHistoryView(to);
       
   179     }
       
   180     else if (from == "bookmarkTreeView") {
       
   181         fromBookmarkTreeView(to);
       
   182     }
       
   183 
       
   184     if (to == "WindowView") {
       
   185         toWindowView();
       
   186     }
       
   187     else if (to == "goAnywhereView") {
       
   188         toGoAnywhereView();
       
   189     }
       
   190     else if (to == "webView") {
       
   191         toWebView();
       
   192     }
       
   193     else if (to == "bookmarkHistoryView") {
       
   194         toBookmarkHistoryView();
       
   195     }
       
   196     else if (to == "bookmarkTreeView") {
       
   197         toBookmarkView();
       
   198     }
       
   199 }
       
   200 
       
   201 
       
   202 void ViewStack::loadHistoryItem(int item) {
       
   203 
       
   204     if (!m_viewController) {
       
   205         return;
       
   206     }
       
   207     WRT::HistoryFlowView* historyView = static_cast<WRT::HistoryFlowView*>(m_viewController->getView("historyView"));
       
   208     //var myIndex = window.viewManager.historyView.currentHistIndex;
       
   209     int myIndex = historyView->currentIndex();
       
   210 
       
   211     if (myIndex != item ) {
       
   212         //window.chrome.alert("loadFromHistory");
       
   213         WebPageController::getSingleton()->currentSetFromHistory(item);
       
   214         safe_connect(m_viewController,SIGNAL(loadProgess(const int)), this, SLOT(showContentView(const int)));
       
   215     }
       
   216     else {
       
   217         //window.chrome.alert("Just go back");
       
   218         goBackFromGoAnywhereView();
       
   219     }
       
   220 }
       
   221 
       
   222 void ViewStack::goBackFromGoAnywhereView() {
       
   223     switchView("webView", "goAnywhereView");
       
   224 }
       
   225 
       
   226 
       
   227 void ViewStack::goBackFromWindowView() {
       
   228     switchView("webView", "WindowView");
       
   229 }
       
   230 
       
   231 void ViewStack::goBackFromRecentUrlView() {
       
   232     switchView("webView", "bookmarkHistoryView");
       
   233 }
       
   234 
       
   235 void ViewStack::goBackFromBookmarkView() {
       
   236     switchView("webView", "bookmarkTreeView");
       
   237 }
       
   238 
       
   239 void ViewStack::showContentView(int progress) {
       
   240 
       
   241     if (!m_viewController) {
       
   242         return;
       
   243     }
       
   244 
       
   245     if (progress >= 30 && m_viewController->currentView()->type() == "goAnywhereView") {
       
   246         //goBackToWebView();
       
   247         goBackFromGoAnywhereView();
       
   248         disconnect(m_viewController,SIGNAL(loadProgess(const int)), this, SLOT(showContentView(const int)));
       
   249     }
       
   250     else if ( m_viewController->currentView()->type() == "webView" ) {
       
   251         disconnect(m_viewController,SIGNAL(loadProgess(const int)), this, SLOT(showContentView(const int)));
       
   252     }
       
   253 }
       
   254