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 "browser.h" |
22 #include "browser.h" |
20 #ifndef NO_QSTM_GESTURE |
23 #ifndef NO_QSTM_GESTURE |
21 #include "WebGestureHelper.h" |
24 #include "WebGestureHelper.h" |
22 #endif |
25 #endif |
|
26 #include "../ChromeLayout.h" |
23 #include "../ChromeWidget.h" |
27 #include "../ChromeWidget.h" |
24 #include "HistoryFlowView.h" |
28 #include "HistoryFlowView.h" |
25 #include "WindowFlowView.h" |
29 #include "WindowFlowView.h" |
26 #include "WrtPageManager.h" |
30 #include "webpagecontroller.h" |
27 #include "bedrockprovisioning.h" |
31 #include "bedrockprovisioning.h" |
28 |
32 |
29 #include <QDebug> |
33 #include <QDebug> |
30 #ifdef _GVA_INSPECT_CHROME_ |
34 #ifdef _GVA_INSPECT_CHROME_ |
31 #include <QWebInspector> |
35 #include <QWebInspector> |
38 #ifdef CHROME_CONSOLE |
42 #ifdef CHROME_CONSOLE |
39 #include "ChromeConsole.h" |
43 #include "ChromeConsole.h" |
40 #endif |
44 #endif |
41 #endif |
45 #endif |
42 |
46 |
43 GinebraBrowser::GinebraBrowser(QObject * parent) |
47 GinebraBrowser::GinebraBrowser(QObject * parent, QString *url) |
44 : QObject(parent), |
48 : QObject(parent), |
|
49 m_scene(new QGraphicsScene()), |
45 m_splashScreen(NULL) |
50 m_splashScreen(NULL) |
46 { |
51 { |
|
52 // The initial url to go to when the browser is called from another app |
|
53 if (url != 0) { |
|
54 m_initialUrl = *url; |
|
55 } |
47 QString startUpChrome(BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->valueAsString("StartUpChrome")); |
56 QString startUpChrome(BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->valueAsString("StartUpChrome")); |
48 m_install = BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->valueAsString("ChromeBaseDirectory2") |
57 m_install = BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->valueAsString("ChromeBaseDirectory") |
49 + startUpChrome.section('/', 0, -2) + "/"; |
58 + startUpChrome.section('/', 0, -2) + "/"; |
50 m_chromeUrl = startUpChrome.section('/', -1); |
59 m_chromeUrl = startUpChrome.section('/', -1); |
51 m_contentUrl = BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->valueAsString("StartPage"); |
60 m_contentUrl = BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->valueAsString("StartPage"); |
|
61 |
|
62 setApplicationNameVersion(); |
52 |
63 |
53 //qDebug() << "GinebraBrowser::GinebraBrowser: " << m_install << " " << m_chromeUrl; |
64 //qDebug() << "GinebraBrowser::GinebraBrowser: " << m_install << " " << m_chromeUrl; |
54 //GVA::Settings * settings = GVA::Settings::instance(); |
65 //GVA::Settings * settings = GVA::Settings::instance(); |
55 //settings->setInstallRoot(m_install); |
66 //settings->setInstallRoot(m_install); |
56 // Create the chrome widget |
67 // Create the chrome widget |
72 inspector->resize(400,600); |
84 inspector->resize(400,600); |
73 inspector->show(); |
85 inspector->show(); |
74 connect(m_chrome->page(), SIGNAL(webInspectorTriggered(QWebElement)), inspector, SLOT(show())); |
86 connect(m_chrome->page(), SIGNAL(webInspectorTriggered(QWebElement)), inspector, SLOT(show())); |
75 #endif |
87 #endif |
76 //Create a view onto the chrome |
88 //Create a view onto the chrome |
77 m_view = new GVA::ChromeView(m_chrome); |
89 m_view = new GVA::ChromeView(m_scene, m_chrome); |
78 #ifndef NO_QSTM_GESTURE |
90 #ifndef NO_QSTM_GESTURE |
79 WebGestureHelper* gh = new WebGestureHelper(m_view); |
91 WebGestureHelper* gh = new WebGestureHelper(m_view); |
80 browserApp->setGestureHelper(gh); |
92 browserApp->setGestureHelper(gh); |
81 browserApp->setMainWindow(m_view); |
93 browserApp->setMainWindow(m_view); |
82 m_view->grabGesture(QStm_Gesture::assignedType()); |
94 m_view->grabGesture(QStm_Gesture::assignedType()); |
83 #endif |
95 #endif |
84 |
96 |
85 #ifdef Q_OS_SYMBIAN |
97 #if defined(Q_OS_SYMBIAN) || defined(Q_WS_MAEMO_5) |
86 m_view->showFullScreen(); |
98 m_view->showFullScreen(); |
87 #else |
99 #else |
88 m_view->setGeometry(0,0,360,640); |
100 m_view->setGeometry(0,0,360,640); |
89 #endif |
101 #endif |
90 |
102 |
91 showSplashScreen(); |
103 showSplashScreen(); |
92 |
104 |
93 #ifndef __gva_no_chrome__ |
105 #ifndef __gva_no_chrome__ |
94 QObject::connect(m_chrome, SIGNAL(internalChromeComplete()), this, SLOT(onChromeComplete())); |
106 QObject::connect(m_chrome, SIGNAL(internalChromeComplete()), this, SLOT(onChromeComplete())); |
95 //Load the chrome |
107 //Load the chrome |
96 m_chrome->setChromeBaseDirectory(m_install); |
108 m_chrome->setChromeBaseDirectory(m_install); |
144 homeDir.cd("favicon"); |
159 homeDir.cd("favicon"); |
145 homeDir.cdUp(); |
160 homeDir.cdUp(); |
146 homeDir.rmdir("favicon"); |
161 homeDir.rmdir("favicon"); |
147 } |
162 } |
148 */ |
163 */ |
149 void GinebraBrowser::show() |
164 void GinebraBrowser::show() |
150 { |
165 { |
151 m_view->show(); |
166 m_view->show(); |
152 } |
167 } |
153 |
168 |
154 void GinebraBrowser::onChromeComplete() |
169 void GinebraBrowser::onChromeComplete() |
155 { |
170 { |
156 #ifndef __gva_no_chrome__ |
171 #ifndef __gva_no_chrome__ |
157 ControllableViewBase *windowView = WRT::WindowFlowView::createNew(m_chrome); |
172 ControllableViewBase *windowView = WRT::WindowFlowView::createNew(m_chrome->layout()); |
158 windowView->setObjectName("WindowView"); |
173 windowView->setObjectName("WindowView"); |
159 m_chrome->addView(windowView); |
174 m_chrome->addView(windowView); |
|
175 |
|
176 ControllableViewBase *historyView = WRT::HistoryFlowView::createNew(m_chrome->layout()); |
|
177 historyView->setObjectName("HistoryView"); |
|
178 m_chrome->addView(historyView); |
|
179 |
160 #endif |
180 #endif |
161 //Create a content window and add it to the chrome |
181 //Create a content window and add it to the chrome |
162 GVA::GWebContentView *content = new GVA::GWebContentView(m_chrome, 0, "WebView"); |
182 GVA::GWebContentView *content = new GVA::GWebContentView(m_chrome, 0, "WebView"); |
163 |
|
164 //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 |
165 //content page won't hang up rendering the chrome. |
184 //content page won't hang up rendering the chrome. |
166 m_chrome->addView(content); |
185 m_chrome->addView(content); |
167 |
186 |
168 QString startPage = m_install + m_contentUrl; |
187 QString chromeBaseDir = BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->valueAsString("LocalPagesBaseDirectory"); |
169 qDebug() << "GinebraBrowser::onChromeComplete: startPage: " << startPage; |
188 QString startPage = chromeBaseDir + m_contentUrl; |
170 |
189 |
171 bool enabled = (bool) BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->valueAsInt("SaveSession"); |
190 bool enabled = (bool) BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->valueAsInt("SaveSession"); |
172 if (enabled) |
191 |
|
192 // If the browser was launched by some other app calling QDesktopServices.openUrl, go to that url |
|
193 if (!m_initialUrl.isEmpty()) { |
|
194 openUrl(m_initialUrl); |
|
195 } |
|
196 // Otherwise, load the previous page from history (if that option is enabled) |
|
197 else if (enabled && m_initialUrl.isEmpty()) { |
173 WebPageController::getSingleton()->loadFromHistory(); |
198 WebPageController::getSingleton()->loadFromHistory(); |
174 else |
199 } |
|
200 // Otherwise, load the start page |
|
201 else { |
175 content->loadUrlToCurrentPage(startPage); |
202 content->loadUrlToCurrentPage(startPage); |
176 |
203 } |
177 #ifndef __gva_no_chrome__ |
204 |
178 WRT::HistoryFlowView *historyView = new WRT::HistoryFlowView(WrtPageManager::getSingleton(), m_chrome); |
|
179 historyView->setObjectName("HistoryView"); |
|
180 m_chrome->addView(historyView); |
|
181 #endif |
|
182 m_chrome->showView("WebView"); |
205 m_chrome->showView("WebView"); |
183 destroySplashScreen(); |
206 destroySplashScreen(); |
184 } |
207 } |
185 |
208 |
|
209 void GinebraBrowser::queueOpenUrl(QString url) |
|
210 { |
|
211 emit openUrlRequested(url); |
|
212 } |
|
213 |
|
214 void GinebraBrowser::openUrl(QString url) |
|
215 { |
|
216 #ifdef Q_OS_SYMBIAN |
|
217 // Handle the url as per the old standard at |
|
218 // http://wiki.forum.nokia.com/index.php/TSS000340_-_Launching_the_Web_browser_on_S60_3rd_Edition_to_open_a_specified_URL |
|
219 QChar urlType = url.at(0); |
|
220 // Bookmark (by uid) - not handled |
|
221 if (urlType == '1') { |
|
222 return; |
|
223 } |
|
224 // Saved deck (by uid) - not handled |
|
225 else if (urlType == '2') { |
|
226 return; |
|
227 } |
|
228 // Start page - not handled |
|
229 else if (urlType == '5') { |
|
230 return; |
|
231 } |
|
232 // Bookmark folder (by uid) - not handled |
|
233 else if (urlType == '6') { |
|
234 return; |
|
235 } |
|
236 // Url or Url + space + access point |
|
237 else if (urlType == '4') { |
|
238 url = url.mid(2); // Get the real url |
|
239 if (url.contains(' ')) { // Chop off the access point if there is one because it's not currently handled |
|
240 url = url.left(url.indexOf(' ')); |
|
241 } |
|
242 } |
|
243 // If no number then it's just a plain url |
|
244 #endif /* Q_OS_SYMBIAN */ |
|
245 // Bring the browser to the front (QDesktopServices openurl is supposed to do this but doesn't) |
|
246 if (m_view) { |
|
247 m_view->activateWindow(); |
|
248 m_view->raise(); |
|
249 } |
|
250 m_contentUrl = url; |
|
251 WebPageController::getSingleton()->loadInitialUrlFromOtherApp(url); |
|
252 // GVA::GWebContentView *webView = (GVA::GWebContentView *)m_chrome->getView("WebView"); |
|
253 // if (webView != 0) { |
|
254 // m_contentUrl = url; |
|
255 // webView->loadUrlToCurrentPage(url); |
|
256 // } |
|
257 } |
|
258 |
186 void GinebraBrowser::showSplashScreen() { |
259 void GinebraBrowser::showSplashScreen() { |
187 QString splashImage = BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->valueAsString("SplashImage"); |
260 QString splashImage = BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->valueAsString("SplashImage"); |
188 QString baseDir = BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->valueAsString("ChromeBaseDirectory2"); |
261 QString baseDir = BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->valueAsString("ChromeBaseDirectory"); |
189 QString imagePath = baseDir + splashImage; |
262 QString imagePath = baseDir + splashImage; |
190 |
263 |
191 qDebug() << "ChromeView::showSplashScreen: " << imagePath; |
264 if (!imagePath.isNull()) { |
192 if(!imagePath.isNull()) { |
|
193 m_splashScreen = new QLabel(NULL); |
265 m_splashScreen = new QLabel(NULL); |
194 m_splashScreen->setAlignment(Qt::AlignCenter); |
266 m_splashScreen->setAlignment(Qt::AlignCenter); |
195 m_splashScreen->setStyleSheet("background-color: #FFF"); |
267 m_splashScreen->setStyleSheet("background-color: #FFF"); |
196 m_splashScreen->setPixmap(QPixmap(imagePath)); |
268 m_splashScreen->setPixmap(QPixmap(imagePath)); |
197 if(m_splashScreen->pixmap()->isNull()) { |
269 if (m_splashScreen->pixmap()->isNull()) { |
198 ;//qDebug() << "ChromeView::chromeLoaded: ERROR splashscreen creation failed. " << imagePath; |
270 ;//qDebug() << "ChromeView::chromeLoaded: ERROR splashscreen creation failed. " << imagePath; |
199 } |
271 } |
200 else { |
272 else { |
201 m_splashScreen->show(); |
273 m_splashScreen->show(); |
202 #ifdef Q_OS_SYMBIAN |
274 #ifdef Q_OS_SYMBIAN |
203 m_splashScreen->showFullScreen(); |
275 m_splashScreen->showFullScreen(); |
204 m_view->showFullScreen(); |
276 m_view->showFullScreen(); |
205 #else |
277 #else |
206 m_splashScreen->setGeometry(0,0,360,640); |
278 m_splashScreen->setGeometry(0,0,360,640); |
207 #endif |
279 #endif |
208 } |
280 } |
209 } |
281 } |
210 } |
282 } |
211 |
283 |
212 void GinebraBrowser::destroySplashScreen() |
284 void GinebraBrowser::destroySplashScreen() |
213 { |
285 { |
214 if(m_splashScreen) |
286 if (m_splashScreen) |
215 { |
287 { |
216 delete m_splashScreen; |
288 delete m_splashScreen; |
217 m_splashScreen = NULL; |
289 m_splashScreen = NULL; |
218 } |
290 } |
219 } |
291 } |
|
292 |
|
293 void GinebraBrowser::setApplicationNameVersion() |
|
294 { |
|
295 QCoreApplication::setApplicationName(BEDROCK_APPLICATION_NAME); |
|
296 QString browserAppVersion = BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->valueAsString("BedrockVersion"); |
|
297 QCoreApplication::setApplicationVersion(browserAppVersion); |
|
298 } |