ginebra2/emulator/browser.cpp
changeset 6 1c3b8676e58c
parent 5 0f2326c2a325
child 10 232fbd5a2dcb
equal deleted inserted replaced
5:0f2326c2a325 6:1c3b8676e58c
    21 
    21 
    22 #include "browser.h"
    22 #include "browser.h"
    23 #ifndef NO_QSTM_GESTURE
    23 #ifndef NO_QSTM_GESTURE
    24 #include "WebGestureHelper.h"
    24 #include "WebGestureHelper.h"
    25 #endif
    25 #endif
       
    26 #include "../ChromeLayout.h"
    26 #include "../ChromeWidget.h"
    27 #include "../ChromeWidget.h"
    27 #include "HistoryFlowView.h"
    28 #include "HistoryFlowView.h"
    28 #include "WindowFlowView.h"
    29 #include "WindowFlowView.h"
    29 #include "webpagecontroller.h"
    30 #include "webpagecontroller.h"
    30 #include "bedrockprovisioning.h"
    31 #include "bedrockprovisioning.h"
    43 #endif
    44 #endif
    44 #endif
    45 #endif
    45 
    46 
    46 GinebraBrowser::GinebraBrowser(QObject * parent, QString *url)
    47 GinebraBrowser::GinebraBrowser(QObject * parent, QString *url)
    47   : QObject(parent),
    48   : QObject(parent),
       
    49     m_scene(new QGraphicsScene()),
    48     m_splashScreen(NULL)
    50     m_splashScreen(NULL)
    49 {
    51 {
    50   // The initial url to go to when the browser is called from another app
    52   // The initial url to go to when the browser is called from another app
    51   if (url != 0) {
    53   if (url != 0) {
    52       qDebug() << "GinebraBrowser::GinebraBrowser - initialurl=" << *url;
       
    53 //      m_initialUrl = url->mid(2);
       
    54       m_initialUrl = *url;
    54       m_initialUrl = *url;
    55   }
    55   }
    56   QString startUpChrome(BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->valueAsString("StartUpChrome"));
    56   QString startUpChrome(BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->valueAsString("StartUpChrome"));
    57   m_install = BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->valueAsString("ChromeBaseDirectory")
    57   m_install = BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->valueAsString("ChromeBaseDirectory")
    58       + startUpChrome.section('/', 0, -2) + "/";
    58       + startUpChrome.section('/', 0, -2) + "/";
    84   inspector->resize(400,600);
    84   inspector->resize(400,600);
    85   inspector->show();
    85   inspector->show();
    86   connect(m_chrome->page(), SIGNAL(webInspectorTriggered(QWebElement)), inspector, SLOT(show()));
    86   connect(m_chrome->page(), SIGNAL(webInspectorTriggered(QWebElement)), inspector, SLOT(show()));
    87 #endif
    87 #endif
    88   //Create a view onto the chrome
    88   //Create a view onto the chrome
    89   m_view = new GVA::ChromeView(m_chrome);
    89   m_view = new GVA::ChromeView(m_scene, m_chrome);
    90 #ifndef NO_QSTM_GESTURE
    90 #ifndef NO_QSTM_GESTURE
    91   WebGestureHelper* gh = new WebGestureHelper(m_view);
    91   WebGestureHelper* gh = new WebGestureHelper(m_view);
    92   browserApp->setGestureHelper(gh);
    92   browserApp->setGestureHelper(gh);
    93   browserApp->setMainWindow(m_view);
    93   browserApp->setMainWindow(m_view);
    94   m_view->grabGesture(QStm_Gesture::assignedType());
    94   m_view->grabGesture(QStm_Gesture::assignedType());
   126 {
   126 {
   127   delete m_chrome;
   127   delete m_chrome;
   128   delete WebPageController::getSingleton();
   128   delete WebPageController::getSingleton();
   129   delete m_view;
   129   delete m_view;
   130   destroySplashScreen();
   130   destroySplashScreen();
       
   131   delete m_scene;
   131 
   132 
   132 #ifndef NO_QSTM_GESTURE
   133 #ifndef NO_QSTM_GESTURE
   133   WebGestureHelper* gh = browserApp->gestureHelper();
   134   WebGestureHelper* gh = browserApp->gestureHelper();
   134   delete gh;
   135   delete gh;
   135 #endif
   136 #endif
   166 }
   167 }
   167 
   168 
   168 void GinebraBrowser::onChromeComplete()
   169 void GinebraBrowser::onChromeComplete()
   169 {
   170 {
   170 #ifndef __gva_no_chrome__
   171 #ifndef __gva_no_chrome__
   171   ControllableViewBase *windowView = WRT::WindowFlowView::createNew(m_chrome);
   172   ControllableViewBase *windowView = WRT::WindowFlowView::createNew(m_chrome->layout());
   172   windowView->setObjectName("WindowView");
   173   windowView->setObjectName("WindowView");
   173   m_chrome->addView(windowView);
   174   m_chrome->addView(windowView);
   174 
   175 
   175   ControllableViewBase *historyView = WRT::HistoryFlowView::createNew(m_chrome);
   176   ControllableViewBase *historyView = WRT::HistoryFlowView::createNew(m_chrome->layout());
   176   historyView->setObjectName("HistoryView");
   177   historyView->setObjectName("HistoryView");
   177   m_chrome->addView(historyView);
   178   m_chrome->addView(historyView);
   178 
   179 
   179 #endif
   180 #endif
   180   //Create a content window and add it to the chrome
   181   //Create a content window and add it to the chrome
   181   GVA::GWebContentView *content = new GVA::GWebContentView(m_chrome, 0, "WebView");
   182   GVA::GWebContentView *content = new GVA::GWebContentView(m_chrome, 0, "WebView");
   182   //Load the initial content after the chrome loads. This makes sure that an initial bad
   183   //Load the initial content after the chrome loads. This makes sure that an initial bad
   183   //content page won't hang up rendering the chrome.
   184   //content page won't hang up rendering the chrome.
   184   m_chrome->addView(content);
   185   m_chrome->addView(content);
   185 
   186 
   186   QString chromeBaseDir = BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->valueAsString("ChromeBaseDirectory");
   187   QString chromeBaseDir = BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->valueAsString("LocalPagesBaseDirectory");
   187   QString startPage = chromeBaseDir + m_contentUrl;
   188   QString startPage = chromeBaseDir + m_contentUrl;
   188   qDebug() << "GinebraBrowser::onChromeComplete: startPage: " << startPage;
       
   189 
   189 
   190   bool enabled = (bool) BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->valueAsInt("SaveSession");
   190   bool enabled = (bool) BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->valueAsInt("SaveSession");
   191 
   191 
   192   // If the browser was launched by some other app calling QDesktopServices.openUrl, go to that url
   192   // If the browser was launched by some other app calling QDesktopServices.openUrl, go to that url
   193   if (!m_initialUrl.isEmpty()) {
   193   if (!m_initialUrl.isEmpty()) {
   194       qDebug() << "called from openurl, loading page " << m_initialUrl;
       
   195       openUrl(m_initialUrl);
   194       openUrl(m_initialUrl);
   196   }
   195   }
   197   // Otherwise, load the previous page from history (if that option is enabled)
   196   // Otherwise, load the previous page from history (if that option is enabled)
   198   else if (enabled && m_initialUrl.isEmpty()) {
   197   else if (enabled && m_initialUrl.isEmpty()) {
   199     qDebug() << "loading page from history";
       
   200     WebPageController::getSingleton()->loadFromHistory();
   198     WebPageController::getSingleton()->loadFromHistory();
   201   }
   199   }
   202   // Otherwise, load the start page
   200   // Otherwise, load the start page
   203   else {
   201   else {
   204     qDebug() << "loading startpage " << startPage;
       
   205     content->loadUrlToCurrentPage(startPage);
   202     content->loadUrlToCurrentPage(startPage);
   206   }
   203   }
   207 
   204 
   208   m_chrome->showView("WebView");
   205   m_chrome->showView("WebView");
   209   destroySplashScreen();
   206   destroySplashScreen();
   248     // Bring the browser to the front (QDesktopServices openurl is supposed to do this but doesn't)
   245     // Bring the browser to the front (QDesktopServices openurl is supposed to do this but doesn't)
   249     if (m_view) {
   246     if (m_view) {
   250         m_view->activateWindow();
   247         m_view->activateWindow();
   251         m_view->raise();
   248         m_view->raise();
   252     }
   249     }
   253     qDebug() << "GinebraBrowser::openUrl - " << url;
       
   254     m_contentUrl = url;
   250     m_contentUrl = url;
   255     WebPageController::getSingleton()->loadInitialUrlFromOtherApp(url);
   251     WebPageController::getSingleton()->loadInitialUrlFromOtherApp(url);
   256 //    GVA::GWebContentView *webView = (GVA::GWebContentView *)m_chrome->getView("WebView");
   252 //    GVA::GWebContentView *webView = (GVA::GWebContentView *)m_chrome->getView("WebView");
   257 //    if (webView != 0) {
   253 //    if (webView != 0) {
   258 //        m_contentUrl = url;
   254 //        m_contentUrl = url;
   263 void GinebraBrowser::showSplashScreen() {
   259 void GinebraBrowser::showSplashScreen() {
   264   QString splashImage = BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->valueAsString("SplashImage");
   260   QString splashImage = BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->valueAsString("SplashImage");
   265   QString baseDir = BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->valueAsString("ChromeBaseDirectory");
   261   QString baseDir = BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->valueAsString("ChromeBaseDirectory");
   266   QString imagePath =   baseDir + splashImage;
   262   QString imagePath =   baseDir + splashImage;
   267 
   263 
   268   qDebug() << "ChromeView::showSplashScreen: " << imagePath;
       
   269   if (!imagePath.isNull()) {
   264   if (!imagePath.isNull()) {
   270     m_splashScreen = new QLabel(NULL);
   265     m_splashScreen = new QLabel(NULL);
   271     m_splashScreen->setAlignment(Qt::AlignCenter);
   266     m_splashScreen->setAlignment(Qt::AlignCenter);
   272     m_splashScreen->setStyleSheet("background-color: #FFF");
   267     m_splashScreen->setStyleSheet("background-color: #FFF");
   273     m_splashScreen->setPixmap(QPixmap(imagePath));
   268     m_splashScreen->setPixmap(QPixmap(imagePath));