ginebra2/ViewStack.cpp
branchGCC_SURGE
changeset 8 2e16851ffecd
parent 6 1c3b8676e58c
equal deleted inserted replaced
2:bf4420e9fa4d 8:2e16851ffecd
     1 /*
     1 /*
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 *
     5 * under the terms of "Eclipse Public License v1.0"
     5 * This program is free software: you can redistribute it and/or modify
     6 * which accompanies this distribution, and is available
     6 * it under the terms of the GNU Lesser General Public License as published by
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * the Free Software Foundation, version 2.1 of the License.
     8 *
     8 *
     9 * Initial Contributors:
     9 * This program is distributed in the hope that it will be useful,
    10 * Nokia Corporation - initial contribution.
    10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
    11 *
    11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    12 * Contributors:
    12 * GNU Lesser General Public License for more details.
    13 *
    13 *
    14 * Description: 
    14 * You should have received a copy of the GNU Lesser General Public License
       
    15 * along with this program.  If not,
       
    16 * see "http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html/".
       
    17 *
       
    18 * Description:
    15 *
    19 *
    16 */
    20 */
    17 
       
    18 
    21 
    19 #include "Utilities.h"
    22 #include "Utilities.h"
    20 #include <QtCore/QUrl>
    23 #include <QtCore/QUrl>
    21 #include "ViewStack.h"
    24 #include "ViewStack.h"
    22 #include "ViewController.h"
    25 #include "ViewController.h"
    23 #include "ChromeWidget.h"
       
    24 #include "webpagecontroller.h"
    26 #include "webpagecontroller.h"
    25 #include "HistoryFlowView.h"
    27 #include "HistoryFlowView.h"
    26 #include "BookmarksTreeView.h"
       
    27 #include "BookMarksHistoryView.h"
       
    28 #include "WindowFlowView.h"
    28 #include "WindowFlowView.h"
       
    29 #include "ChromeSnippet.h"
    29 
    30 
    30 namespace GVA {
    31 namespace GVA {
    31 
    32 
    32 static const QString KBookmarkHistoryViewName = "BookmarkHistoryView";
    33 static const QString KBookmarkHistoryViewName = "BookmarkHistoryView";
    33 static const QString KBookmarkTreeViewName = "BookmarkTreeView";
    34 static const QString KBookmarkTreeViewName = "BookmarkTreeView";
    34 static const QString KGoAnywhereViewName = "GoAnywhereView";
       
    35 static const QString KWebViewName = "WebView";
    35 static const QString KWebViewName = "WebView";
    36 static const QString KWindowViewName = "WindowView";
    36 static const QString KWindowViewName = "WindowView";
    37 static const QString KHistoryViewName = "HistoryView";
    37 static const QString KHistoryViewName = "HistoryView";
    38 static const QString KSettingsViewName = "SettingsView";
    38 static const QString KSettingsViewName = "SettingsView";
    39 
    39 
    40 
    40 
    41 ViewStack* ViewStack::getSingleton()
    41 ViewStack* ViewStack::getSingleton()
    42 {
    42 {
    43     static ViewStack* singleton = 0;
    43     static ViewStack* singleton = 0;
    44     if(!singleton)
    44     if (!singleton)
    45     {
    45     {
    46         singleton = new ViewStack;
    46         singleton = new ViewStack;
    47         singleton->setObjectName("ViewStack");
    47         singleton->setObjectName("ViewStack");
    48     } // if(! singleton)
    48     } // if (! singleton)
    49 
    49 
    50     assert(singleton);
    50     assert(singleton);
    51     return singleton;
    51     return singleton;
    52 }
    52 }
    53 
    53 
    54 void ViewStack::fromWindowView(const QString &to)
    54 void ViewStack::fromWindowView(const QString &to)
    55 {
    55 {
    56     emit (deActivateWindowView());
    56     emit (deActivateWindowView());
       
    57 
       
    58     ChromeSnippet* tbSnippet = m_chrome->getSnippet("WindowViewToolbarId");
       
    59     if (tbSnippet)
       
    60         tbSnippet->hide();
    57 
    61 
    58     //m_chromeView->setViewofCurrentPage();
    62     //m_chromeView->setViewofCurrentPage();
    59 
    63 
    60     WRT::WindowFlowView* windowView = static_cast<WRT::WindowFlowView *>(m_viewController->view(KWindowViewName));
    64     WRT::WindowFlowView* windowView = static_cast<WRT::WindowFlowView *>(m_viewController->view(KWindowViewName));
    61 
    65 
    66     m_viewController->showContent(to);
    70     m_viewController->showContent(to);
    67 }
    71 }
    68 
    72 
    69 void ViewStack::fromSettingsView(const QString &to)  // goto WebView
    73 void ViewStack::fromSettingsView(const QString &to)  // goto WebView
    70 {
    74 {
    71     emit (deActivateSettingsView());    
    75     m_viewController->showContent(to);
    72     emit (currentViewChanged());
    76     ChromeSnippet* tbSnippet = m_chrome->getSnippet("SettingsViewToolbarId");
    73     m_viewController->showContent(to);
    77     if (tbSnippet)
    74 }
    78         tbSnippet->hide();
    75 
    79 
    76 void ViewStack::fromGoAnywhereView(const QString &to)
    80     WebPageController::getSingleton()->setSettingsLoaded(0);
    77 {
       
    78     WRT::HistoryFlowView* historyView = static_cast<WRT::HistoryFlowView*>(m_viewController->view(KHistoryViewName));
       
    79     WRT::BookmarksTreeView* bookmarkTreeView = static_cast<WRT::BookmarksTreeView *>(m_viewController->view(KBookmarkTreeViewName));
       
    80     WRT::BookmarksHistoryView* bookmarkHistoryView = static_cast<WRT::BookmarksHistoryView *>(m_viewController->view(KBookmarkHistoryViewName));
       
    81 
       
    82     disconnect(historyView, SIGNAL(ok(int)), this, SLOT(loadHistoryItem(int)));
       
    83     disconnect(bookmarkTreeView, SIGNAL(openUrl(const QUrl &)), this, SLOT(goBackFromGoAnywhereView()));
       
    84     disconnect(bookmarkHistoryView, SIGNAL(openUrl(const QUrl &)), this, SLOT(goBackFromGoAnywhereView()));
       
    85 
       
    86     m_viewController->showContent(to);
       
    87 
       
    88     disconnect(bookmarkTreeView, SIGNAL(activated()), this, SIGNAL(activateBookmark()));
       
    89     disconnect(bookmarkTreeView, SIGNAL(deactivated()), this, SIGNAL(deActivateBookmark()));
       
    90     disconnect(historyView, SIGNAL(activated()), this, SIGNAL(activateHistory()));
       
    91     disconnect(historyView, SIGNAL(deactivated()), this, SIGNAL(deActivateHistory()));
       
    92     disconnect(bookmarkHistoryView, SIGNAL(activated()), this, SIGNAL(activateBookMarkHistory()));
       
    93     disconnect(bookmarkHistoryView, SIGNAL(deactivated()), this, SIGNAL(deActivateBookMarkHistory()));
       
    94 }
    81 }
    95 
    82 
    96 void ViewStack::fromWebView(const QString &to)
    83 void ViewStack::fromWebView(const QString &to)
    97 {
    84 {
    98     m_viewController->showContent(to);
    85     m_viewController->showContent(to);
    99     emit (deActivateWebView());
    86     ChromeSnippet* tbSnippet = m_chrome->getSnippet("WebViewToolbarId");
   100 }
    87     if (tbSnippet)
   101 
    88         tbSnippet->hide(false);
       
    89 }
   102 
    90 
   103 void ViewStack::fromBookmarkTreeView(const QString &to)
    91 void ViewStack::fromBookmarkTreeView(const QString &to)
   104 {
    92 {
   105     //m_viewController->showContent(to);
    93      m_viewController->showContent(to);
   106     //WRT::BookmarksTreeView* bookmarkTreeView = static_cast<WRT::BookmarksTreeView *>(m_viewController->view(KBookmarkTreeViewName));
    94     // Hide toolbar and dialog if visible
   107 
    95     ChromeSnippet* visibleSnippet = m_chrome->getSnippet("BookmarkViewToolbarId");
   108     //disconnect(bookmarkTreeView, SIGNAL(openUrl(const QUrl &)), this, SLOT(goBackFromBookmarkView()));
    96     if (visibleSnippet)
   109     m_viewController->viewChanged();
    97         visibleSnippet->hide();
   110     
    98     
   111     emit(deActivateBookmark());
    99     visibleSnippet = m_chrome->getSnippet("BookmarkDialogId");
       
   100     if (visibleSnippet)
       
   101         visibleSnippet->hide();
   112 }
   102 }
   113 
   103 
   114 
   104 
   115 void ViewStack::fromBookmarkHistoryView(const QString &to)
   105 void ViewStack::fromBookmarkHistoryView(const QString &to)
   116 {
   106 {
   117     //m_viewController->showContent(to);
   107     m_viewController->showContent(to);
   118     //WRT::BookmarksHistoryView* bookmarkHistoryView = static_cast<WRT::BookmarksHistoryView *>(m_viewController->view(KBookmarkHistoryViewName));
   108     ChromeSnippet* tbSnippet = m_chrome->getSnippet("RecentUrlViewToolbarId");
   119 
   109     if (tbSnippet)
   120     //disconnect(bookmarkHistoryView, SIGNAL(openUrl(const QUrl &)), this, SLOT(goBackFromRecentUrlView()));
   110         tbSnippet->hide();
   121     m_viewController->viewChanged();
   111     
   122 
   112     ChromeSnippet* visibleSnippet  = m_chrome->getSnippet("ClearHistoryDialogId");
   123     emit(deActivateBookMarkHistory());
       
   124 }
       
   125 
       
   126 void ViewStack::toGoAnywhereView()
       
   127 {
       
   128     emit (activateHistory()); // by default go to history view
       
   129 
       
   130     /* Connect ALL of goAnywhere's signals in one shot */
       
   131 
       
   132     WRT::HistoryFlowView* historyView = static_cast<WRT::HistoryFlowView*>(m_viewController->view(KHistoryViewName));
       
   133     WRT::BookmarksTreeView* bookmarkTreeView = static_cast<WRT::BookmarksTreeView *>(m_viewController->view(KBookmarkTreeViewName));
       
   134     WRT::BookmarksHistoryView* bookmarkHistoryView = static_cast<WRT::BookmarksHistoryView *>(m_viewController->view(KBookmarkHistoryViewName));
       
   135 
       
   136     safe_connect(historyView, SIGNAL(ok(int)), this, SLOT(loadHistoryItem(int)))
       
   137     safe_connect(bookmarkTreeView, SIGNAL(openUrl(const QUrl &)), this, SLOT(goBackFromGoAnywhereView()))
       
   138     safe_connect(bookmarkHistoryView, SIGNAL(openUrl(const QUrl &)), this, SLOT(goBackFromGoAnywhereView()));
       
   139     safe_connect(bookmarkTreeView, SIGNAL(activated()), this, SIGNAL(activateBookmark()));
       
   140     safe_connect(bookmarkTreeView, SIGNAL(deactivated()), this, SIGNAL(deActivateBookmark()));
       
   141     safe_connect(historyView, SIGNAL(activated()), this, SIGNAL(activateHistory()));
       
   142     safe_connect(historyView, SIGNAL(deactivated()), this, SIGNAL(deActivateHistory()));
       
   143     safe_connect(bookmarkHistoryView, SIGNAL(activated()), this, SIGNAL(activateBookMarkHistory()));
       
   144     safe_connect(bookmarkHistoryView, SIGNAL(deactivated()), this, SIGNAL(deActivateBookMarkHistory()));
       
   145 }
       
   146 
       
   147 void  ViewStack::initWindowView()
       
   148 {
       
   149     /*
       
   150     int width = m_chromeView->size().width();
       
   151     int height = m_chromeView->size().height();
       
   152     // FIXME: the snippet id is hardcode
       
   153     ChromeSnippet* visibleSnippet = m_chromeView->getChromeWidget()->getSnippet("StatusBarChromeId");
       
   154     if (visibleSnippet)
   113     if (visibleSnippet)
   155         height -= (int) (visibleSnippet->rect().height()); 
   114          visibleSnippet->hide();
   156 
   115 }
   157     visibleSnippet = m_chromeView->getChromeWidget()->getSnippet("WebViewToolbarId");
       
   158     if (visibleSnippet)
       
   159         height -= (int) (visibleSnippet->rect().height()); 
       
   160 
       
   161     if (m_chromeView->displayMode() ==  ChromeView::DisplayModePortrait) {
       
   162         visibleSnippet = m_chromeView->getChromeWidget()->getSnippet("WindowCountBarId");
       
   163         if (visibleSnippet)
       
   164             height -= (int) (visibleSnippet->rect().height()); 
       
   165     }
       
   166     QSize windowViewSize(100,100);
       
   167     WRT::WindowFlowView* windowView = static_cast<WRT::WindowFlowView *>(m_viewController->view(KWindowViewName));
       
   168     windowView->setSize(windowViewSize);
       
   169 */
       
   170 }
       
   171 
       
   172 
   116 
   173 void ViewStack::toWindowView()
   117 void ViewStack::toWindowView()
   174 {
   118 {
   175     emit(activateWindowView());
   119     emit(activateWindowView());
       
   120 
       
   121     ChromeSnippet* tbSnippet = m_chrome->getSnippet("WindowViewToolbarId");
       
   122     if (tbSnippet)
       
   123         tbSnippet->show();
   176 
   124 
   177     WRT::WindowFlowView* windowView = static_cast<WRT::WindowFlowView *>(m_viewController->view(KWindowViewName));
   125     WRT::WindowFlowView* windowView = static_cast<WRT::WindowFlowView *>(m_viewController->view(KWindowViewName));
   178 
   126 
   179     safe_connect(windowView, SIGNAL(ok(WrtBrowserContainer*)), this, SLOT(goBackFromWindowView()));
   127     safe_connect(windowView, SIGNAL(ok(WrtBrowserContainer*)), this, SLOT(goBackFromWindowView()));
   180     safe_connect(windowView, SIGNAL(addPageComplete()), this, SLOT(goBackFromWindowView()));
   128     safe_connect(windowView, SIGNAL(addPageComplete()), this, SLOT(goBackFromWindowView()));
   181     safe_connect(windowView, SIGNAL(centerIndexChanged(int)), this, SIGNAL(pageChanged(int)));
   129     safe_connect(windowView, SIGNAL(centerIndexChanged(int)), this, SIGNAL(pageChanged(int)));
   182 }
   130 }
   183 
   131 
   184 void  ViewStack::initSettingsView()
       
   185 {
       
   186 }
       
   187 
       
   188 void ViewStack::toSettingsView()
   132 void ViewStack::toSettingsView()
   189 {
   133 {
   190     emit(activateSettingsView());    
   134     ChromeSnippet* tbSnippet = m_chrome->getSnippet("SettingsViewToolbarId");
   191     emit(currentViewChanged());
   135     if (tbSnippet)
       
   136         tbSnippet->show();
       
   137 
       
   138     WebPageController::getSingleton()->setSettingsLoaded(0);
       
   139 
   192 }
   140 }
   193 
   141 
   194 void ViewStack::toWebView()
   142 void ViewStack::toWebView()
   195 {
   143 {
   196     emit (activateWebView());
   144     ChromeSnippet* tbSnippet = m_chrome->getSnippet("WebViewToolbarId");
       
   145     if (tbSnippet)
       
   146         tbSnippet->show(false);
   197 }
   147 }
   198 
   148 
   199 void ViewStack::toBookmarkHistoryView()
   149 void ViewStack::toBookmarkHistoryView()
   200 {
   150 {
   201     emit(activateBookMarkHistory());
   151     ChromeSnippet* tbSnippet = m_chrome->getSnippet("RecentUrlViewToolbarId");
   202 
   152     if (tbSnippet)
   203     m_viewController->viewChanged();
   153         tbSnippet->show();
   204     //WRT::BookmarksHistoryView* bookmarkHistoryView = static_cast<WRT::BookmarksHistoryView *>(m_viewController->view(KBookmarkHistoryViewName));
       
   205 
       
   206     //safe_connect(bookmarkHistoryView, SIGNAL(openUrl(const QUrl &)), this, SLOT(goBackFromRecentUrlView()));
       
   207 }
   154 }
   208 
   155 
   209 void ViewStack::toBookmarkView()
   156 void ViewStack::toBookmarkView()
   210 {
   157 {
   211     emit(activateBookmark());
   158     ChromeSnippet* tbSnippet = m_chrome->getSnippet("BookmarkViewToolbarId");
   212     
   159     if (tbSnippet)
   213     m_viewController->viewChanged();
   160         tbSnippet->show();
   214 
   161 
   215     //WRT::BookmarksTreeView* bookmarkTreeView = static_cast<WRT::BookmarksTreeView *>(m_viewController->view(KBookmarkTreeViewName));
   162     emit activateBookmark();
   216 
   163 }
   217     //safe_connect(bookmarkTreeView, SIGNAL(openUrl(const QUrl &)), this, SLOT(goBackFromBookmarkView()));
   164 
   218 }
   165 void ViewStack::creatingPage(WRT::WrtBrowserContainer* page) {
   219 
   166     Q_UNUSED(page);
       
   167 
       
   168     //qDebug() << "VIEW STACK:: Received creating Page" << page;
       
   169 
       
   170     if (m_viewController->currentView()->type() == "webView" ) {
       
   171         //qDebug() << "ViewStack::page: " << page << "Created In " << m_viewController->currentView()->type() ;
       
   172 
       
   173         WRT::WindowFlowView* windowView = static_cast<WRT::WindowFlowView *>(m_viewController->view(KWindowViewName));
       
   174         windowView->setMode(WRT::WindowView::WindowViewModeTransition);
       
   175         windowView->onPageCreated(page);
       
   176         ViewStack::getSingleton()->switchView(KWindowViewName, KWebViewName);
       
   177     }
       
   178 
       
   179 }
   220 
   180 
   221 void ViewStack::switchView(const QString &to, const QString &from) {
   181 void ViewStack::switchView(const QString &to, const QString &from) {
   222     qDebug() << "ViewStack::switchView: " << to << " " << from;
       
   223 
   182 
   224     if (to == from) {
   183     if (to == from) {
   225         return;
   184         return;
   226     }
   185     }
   227     if (!m_viewController) {
   186     if (!m_viewController) {
   229     }
   188     }
   230 
   189 
   231     if (from == KWindowViewName) {
   190     if (from == KWindowViewName) {
   232         fromWindowView(to);
   191         fromWindowView(to);
   233     }
   192     }
   234     else if (from == KGoAnywhereViewName) {
       
   235         fromGoAnywhereView(to);
       
   236     }
       
   237     else if (from == KWebViewName) {
   193     else if (from == KWebViewName) {
   238        if (to == KWindowViewName)
   194         fromWebView(to);
   239            initWindowView(); // to fix the size issue of windows view
       
   240        fromWebView(to);
       
   241     }
   195     }
   242     else if (from == KBookmarkHistoryViewName) {
   196     else if (from == KBookmarkHistoryViewName) {
   243         fromBookmarkHistoryView(to);
   197         fromBookmarkHistoryView(to);
   244     }
   198     }
   245     else if (from == KBookmarkTreeViewName) {
   199     else if (from == KBookmarkTreeViewName) {
   249         fromSettingsView(to);
   203         fromSettingsView(to);
   250     }
   204     }
   251 
   205 
   252     if (to == KWindowViewName) {
   206     if (to == KWindowViewName) {
   253         toWindowView();
   207         toWindowView();
   254     }
       
   255     else if (to == KGoAnywhereViewName) {
       
   256         toGoAnywhereView();
       
   257     }
   208     }
   258     else if (to == KWebViewName) {
   209     else if (to == KWebViewName) {
   259         toWebView();
   210         toWebView();
   260     }
   211     }
   261     else if (to == KBookmarkHistoryViewName) {
   212     else if (to == KBookmarkHistoryViewName) {
   282     if (myIndex != item ) {
   233     if (myIndex != item ) {
   283         //window.chrome.alert("loadFromHistory");
   234         //window.chrome.alert("loadFromHistory");
   284         WebPageController::getSingleton()->currentSetFromHistory(item);
   235         WebPageController::getSingleton()->currentSetFromHistory(item);
   285         safe_connect(m_viewController,SIGNAL(loadProgess(const int)), this, SLOT(showContentView(const int)));
   236         safe_connect(m_viewController,SIGNAL(loadProgess(const int)), this, SLOT(showContentView(const int)));
   286     }
   237     }
   287     else {
   238 }
   288         //window.chrome.alert("Just go back");
       
   289         goBackFromGoAnywhereView();
       
   290     }
       
   291 }
       
   292 
       
   293 void ViewStack::goBackFromGoAnywhereView() {
       
   294     switchView(KWebViewName, KGoAnywhereViewName);
       
   295 }
       
   296 
       
   297 
   239 
   298 void ViewStack::goBackFromWindowView() {
   240 void ViewStack::goBackFromWindowView() {
   299     switchView(KWebViewName, KWindowViewName);
   241     switchView(KWebViewName, KWindowViewName);
   300 }
   242 }
   301 
   243 
   310 void ViewStack::goBackFromSettingsView() {
   252 void ViewStack::goBackFromSettingsView() {
   311     switchView(KWebViewName, KSettingsViewName);
   253     switchView(KWebViewName, KSettingsViewName);
   312 }
   254 }
   313 
   255 
   314 void ViewStack::showContentView(int progress) {
   256 void ViewStack::showContentView(int progress) {
       
   257     Q_UNUSED(progress);
   315 
   258 
   316     if (!m_viewController) {
   259     if (!m_viewController) {
   317         return;
   260         return;
   318     }
   261     }
   319 
   262 
   320     if (progress >= 30 && m_viewController->currentView()->type() == KGoAnywhereViewName) {
   263     if ( m_viewController->currentView()->type() == KWebViewName ) {
   321         //goBackToWebView();
       
   322         goBackFromGoAnywhereView();
       
   323         disconnect(m_viewController,SIGNAL(loadProgess(const int)), this, SLOT(showContentView(const int)));
   264         disconnect(m_viewController,SIGNAL(loadProgess(const int)), this, SLOT(showContentView(const int)));
   324     }
   265     }
   325     else if ( m_viewController->currentView()->type() == KWebViewName ) {
       
   326         disconnect(m_viewController,SIGNAL(loadProgess(const int)), this, SLOT(showContentView(const int)));
       
   327     }
       
   328 }
   266 }
   329 
   267 
   330 }  // end of namespace
   268 }  // end of namespace
   331 
   269