1 /* |
1 /* |
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
2 * Copyright (c) 2009 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 |
|
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 * |
4 * |
9 * Initial Contributors: |
5 * This program is free software: you can redistribute it and/or modify |
10 * Nokia Corporation - initial contribution. |
6 * it under the terms of the GNU Lesser General Public License as published by |
|
7 * the Free Software Foundation, version 2.1 of the License. |
|
8 * |
|
9 * This program is distributed in the hope that it will be useful, |
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 * GNU Lesser General Public License for more details. |
11 * |
13 * |
12 * Contributors: |
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/". |
13 * |
17 * |
14 * Description: |
18 * Description: |
15 * |
19 * |
16 */ |
20 */ |
17 |
21 |
18 |
|
19 #include <assert.h> |
22 #include <assert.h> |
20 |
23 |
|
24 #include "BookmarksManager.h" |
21 #include "actionjsobject.h" |
25 #include "actionjsobject.h" |
22 #include "qwebframe.h" |
|
23 #include "qwebhistory.h" |
|
24 #include "qgraphicswebview.h" |
|
25 #include "webpagedata.h" |
26 #include "webpagedata.h" |
26 #include "wrtbrowsercontainer.h" |
27 #include "wrtbrowsercontainer.h" |
27 #include "wrtbrowsercontainer_p.h" |
28 #include "wrtbrowsercontainer_p.h" |
28 #include "webpagecontroller_p.h" |
29 #include "webpagecontroller_p.h" |
29 #include "webpagecontroller.h" |
30 #include "webpagecontroller.h" |
30 #include "webcontentview.h" |
|
31 #include "UiUtil.h" |
31 #include "UiUtil.h" |
32 //#include "wrtsettings.h" |
|
33 #include "bedrockprovisioning.h" |
32 #include "bedrockprovisioning.h" |
34 #include "secureuicontroller.h" |
33 #include "secureuicontroller.h" |
35 #include "LoadController.h" |
34 #include "LoadController.h" |
|
35 #include "ContentAgent.h" |
|
36 #include "lowmemoryhandler.h" |
|
37 #include <QWebFrame> |
|
38 #include <QWebHistory> |
|
39 #include <QGraphicsWebView> |
36 #include <QFile> |
40 #include <QFile> |
37 #include <QDir> |
41 #include <QDir> |
38 #include <QtGui> |
42 #include <QtGui> |
39 #include <qdesktopservices.h> |
|
40 #include <QCoreApplication> |
43 #include <QCoreApplication> |
41 |
44 #include <QWebSecurityOrigin> |
42 #define BEDROCK_APPLICATION_NAME "Bedrock" |
45 #include <QWebDatabase> |
43 #define BEDROCK_VERSION_DEFAULT "BetaRelease" |
46 #include <QWebSettings> |
|
47 #include <QtCore/QSettings> |
|
48 using namespace WRT; |
|
49 |
|
50 #if defined(Q_OS_SYMBIAN) // for shareToMail |
|
51 #include <miutset.h> |
|
52 #include <sendui.h> |
|
53 #include <cmessagedata.h> |
|
54 #include <txtrich.h> |
|
55 #include <SendUiConsts.h> |
|
56 const TUid KShareOnline = { 0x200009D5 }; |
|
57 const TUid KShareOnOvi = { 0x2001AA43 }; |
|
58 #endif |
|
59 |
44 #define MAX_NUM_WINDOWS_TO_RESTORE 5 |
60 #define MAX_NUM_WINDOWS_TO_RESTORE 5 |
45 #define MAX_NUM_WINDOWS 5 |
61 #define MAX_NUM_WINDOWS 5 |
46 |
62 |
47 static const char KHISTORYEXTENSION[] = ".history"; |
63 static const char KHISTORYEXTENSION[] = ".history"; |
48 |
|
49 void BWF_EXPORT qt_websettings_setLocalStorageDatabasePath(QWebSettings* settings, const QString& path); |
|
50 |
|
51 // -------------------------------------------- |
|
52 |
|
53 //QEvent::Type WebPageControllerUpdateViewPortEvent::staticType() { |
|
54 // static int s_type = QEvent::registerEventType(); |
|
55 // return (QEvent::Type)s_type; |
|
56 //} |
|
57 |
|
58 // -------------------------------------------- |
|
59 |
64 |
60 WebPageControllerPrivate::WebPageControllerPrivate(WebPageController* qq) : |
65 WebPageControllerPrivate::WebPageControllerPrivate(WebPageController* qq) : |
61 q(qq), |
66 q(qq), |
62 m_widgetParent(0), |
67 m_widgetParent(0), |
63 m_currentPage(-1), |
68 m_currentPage(-1), |
74 m_actionStop->setObjectName("stop"); |
79 m_actionStop->setObjectName("stop"); |
75 m_actionBack = new QAction("Back",m_widgetParent); |
80 m_actionBack = new QAction("Back",m_widgetParent); |
76 m_actionBack->setObjectName("back"); |
81 m_actionBack->setObjectName("back"); |
77 m_actionForward = new QAction("Forward",m_widgetParent); |
82 m_actionForward = new QAction("Forward",m_widgetParent); |
78 m_actionForward->setObjectName("forward"); |
83 m_actionForward->setObjectName("forward"); |
79 m_actionWebInspector = new QAction("Web Inspector",m_widgetParent); |
|
80 m_actionWebInspector->setObjectName("webInspector"); |
|
81 |
84 |
82 m_actionReload->setEnabled(false); |
85 m_actionReload->setEnabled(false); |
83 m_actionStop->setEnabled(false); |
86 m_actionStop->setEnabled(false); |
84 m_actionBack->setEnabled(false); |
87 m_actionBack->setEnabled(false); |
85 m_actionForward->setEnabled(false); |
88 m_actionForward->setEnabled(false); |
86 m_actionWebInspector->setVisible(false); |
|
87 |
89 |
88 } |
90 } |
89 |
91 |
90 WebPageControllerPrivate::~WebPageControllerPrivate() |
92 WebPageControllerPrivate::~WebPageControllerPrivate() |
91 { |
93 { |
92 // save history in the persistent storage, delete history files first |
94 // save history in the persistent storage, delete history files first |
|
95 |
93 bool enabled = (bool) BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->valueAsInt("SaveSession"); |
96 bool enabled = (bool) BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->valueAsInt("SaveSession"); |
94 if (enabled) |
97 if (enabled) |
95 { |
98 { |
96 q->deleteHistory(); |
99 q->deleteHistory(); |
97 if(donotsaveFlag == false) |
100 if(donotsaveFlag == false) |
98 { |
101 { |
99 q->saveNumberOfWindows(); |
102 int windowsSaved = 0; |
100 q->saveHistory(); |
103 int activeWindowId = 0; |
|
104 q->saveHistory(&windowsSaved, &activeWindowId); |
|
105 q->saveNumberOfWindows(windowsSaved); |
|
106 q->saveActiveWindowId(activeWindowId); |
101 } |
107 } |
102 donotsaveFlag = true; |
108 donotsaveFlag = true; |
|
109 } |
|
110 else |
|
111 { |
|
112 q->deleteDataFiles(); |
103 } |
113 } |
104 /* #if defined(Q_OS_SYMBIAN) |
114 /* #if defined(Q_OS_SYMBIAN) |
105 // clean up all pages |
115 // clean up all pages |
106 while ( !m_allPages.isEmpty() ) |
116 while ( !m_allPages.isEmpty() ) |
107 q->closePage(m_allPages.at(0)); |
117 q->closePage(m_allPages.at(0)); |
132 * so that higher-level functions need not know or care about what the active page is, etc. |
142 * so that higher-level functions need not know or care about what the active page is, etc. |
133 */ |
143 */ |
134 |
144 |
135 WebPageController::WebPageController ( QObject* parent ) : |
145 WebPageController::WebPageController ( QObject* parent ) : |
136 QObject ( parent ), |
146 QObject ( parent ), |
137 d(new WebPageControllerPrivate(this)) |
147 m_networkError (false), |
|
148 m_networkErrorMsg("No network error"), |
|
149 m_networkErrorUrl("No Url"), |
|
150 m_promptMsg("No message"), |
|
151 m_promptReserved(""), |
|
152 m_memoryHandler(new LowMemoryHandler(this)), |
|
153 d(new WebPageControllerPrivate(this)), |
|
154 m_settingsLoaded(0), |
|
155 m_bErrorUrlMatches(false) |
138 { |
156 { |
139 // Register a new MetaType WebPageData. It is needed to serialize history (starage) |
157 // Register a new MetaType WebPageData. It is needed to serialize history (starage) |
140 qRegisterMetaTypeStreamOperators<WebPageData> ("WebPageData"); |
158 qRegisterMetaTypeStreamOperators<WebPageData> ("WebPageData"); |
141 |
159 |
142 #ifndef QT_NO_DESKTOPSERVICES |
160 d->m_historyDir = BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->valueAsString("DataBaseDirectory"); |
143 d->m_historyDir = QDesktopServices::storageLocation(QDesktopServices::DataLocation); |
|
144 #else |
|
145 d->m_historyDir = QDir::homePath(); |
|
146 #endif |
|
147 #ifdef Q_OS_SYMBIAN |
|
148 if (d->m_historyDir.startsWith("Z")) |
|
149 d->m_historyDir.replace(0,1,"C"); |
|
150 #endif |
|
151 |
161 |
152 // auto-connect actions |
162 // auto-connect actions |
153 connect( d->m_actionReload, SIGNAL( triggered() ), this, SLOT( currentReload() ) ); |
163 connect( d->m_actionReload, SIGNAL( triggered() ), this, SLOT( currentReload() ) ); |
154 connect( d->m_actionStop, SIGNAL( triggered() ), this, SLOT( currentStop() ) ); |
164 connect( d->m_actionStop, SIGNAL( triggered() ), this, SLOT( currentStop() ) ); |
155 connect( d->m_actionBack, SIGNAL( triggered() ), this, SLOT( currentBack() ) ); |
165 connect( d->m_actionBack, SIGNAL( triggered() ), this, SLOT( currentBack() ) ); |
156 connect( d->m_actionForward, SIGNAL( triggered() ), this, SLOT( currentForward() ) ); |
166 connect( d->m_actionForward, SIGNAL( triggered() ), this, SLOT( currentForward() ) ); |
157 connect( d->m_actionWebInspector, SIGNAL( triggered() ), this, SLOT( webInspector() ) ); |
167 |
158 |
168 connect( m_memoryHandler, SIGNAL( lowMemory() ), this, SIGNAL( lowMemory() ) ); |
159 // Catch changes to settings |
169 connect( m_memoryHandler, SIGNAL( lowMemory() ), this, SLOT( handleLowMemory() ) ); |
160 connect(BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning(), SIGNAL(settingChanged(const QString &)), this, SLOT(settingChanged(const QString &))); |
170 connect( m_memoryHandler, SIGNAL( outOfMemory() ), this, SIGNAL( outOfMemory() ) ); |
161 |
171 connect( m_memoryHandler, SIGNAL( outOfMemory() ), this, SLOT( handleOutOfMemory() ) ); |
162 // Initialize UA specific params. |
172 m_memoryHandler->start(); |
163 initUASettingsAndData(); |
173 |
164 // initialize from settings |
|
165 settingChanged("DeveloperExtras"); |
|
166 updateJSActions(); |
174 updateJSActions(); |
167 |
175 |
168 m_bRestoreSession = false; |
176 m_bRestoreSession = false; |
169 bool enabled = (bool) BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->valueAsInt("SaveSession"); |
177 bool enabled = (bool) BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->valueAsInt("SaveSession"); |
170 if (enabled) m_bRestoreSession = true; |
178 if (enabled) m_bRestoreSession = true; |
171 |
179 |
172 } |
180 } |
173 |
181 |
174 WebPageController::~WebPageController() |
182 WebPageController::~WebPageController() |
175 { |
183 { |
|
184 m_memoryHandler->stop(); |
176 delete d; |
185 delete d; |
177 } |
186 } |
178 |
187 |
179 |
188 |
180 |
189 |
195 |
204 |
196 // emit signal for creating network connection. |
205 // emit signal for creating network connection. |
197 |
206 |
198 Q_ASSERT( page ); |
207 Q_ASSERT( page ); |
199 page->settings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, (bool) BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->valueAsInt("DeveloperExtras")); |
208 page->settings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, (bool) BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->valueAsInt("DeveloperExtras")); |
|
209 connect( page, SIGNAL( loadFinished(bool) ), SLOT( onLoadFinishedForBackgroundWindow(bool) ) ); |
|
210 |
|
211 // emit signal indicating that new page is being created |
|
212 emit creatingPage( page ); |
200 |
213 |
201 /* Add the new page after the current page */ |
214 /* Add the new page after the current page */ |
202 WRT::WrtBrowserContainer * theCurrentPage = currentPage(); |
215 WRT::WrtBrowserContainer * theCurrentPage = currentPage(); |
203 int index = d->m_allPages.indexOf(theCurrentPage); |
216 int index = d->m_allPages.indexOf(theCurrentPage); |
204 d->m_allPages.insert (index+1, page ); |
217 d->m_allPages.insert (index+1, page ); |
205 |
218 |
|
219 // set the max number of pages to hold in the memory page cache to pages |
|
220 // The Page Cache allows for a nicer user experience when navigating forth or back to pages in |
|
221 // the forward/back history, by pausing and resuming up to pages per page group |
|
222 |
|
223 int maxPagesInCache = BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->valueAsInt("MaxPagesInCache"); |
|
224 page->settings()->setMaximumPagesInCache(maxPagesInCache); |
206 |
225 |
207 // emit signal |
226 // emit signal |
208 emit pageCreated( page ); |
227 emit pageCreated( page ); |
209 |
228 |
210 |
|
211 // AUTO-activate this page ONLY if there are no other pages |
229 // AUTO-activate this page ONLY if there are no other pages |
212 if(d->m_allPages.size() == 1) { |
230 if(d->m_allPages.size() == 1) { |
213 setCurrentPage(page); |
231 setCurrentPage(page); |
214 } |
232 } |
215 int count = historyWindowCount(); |
233 int count = historyWindowCount(); |
216 if(index+1 < count) |
234 int activeWinId = activeWindowId(); |
|
235 |
|
236 if (m_bRestoreSession) |
217 startupRestoreHistory(NULL, index+1, page); |
237 startupRestoreHistory(NULL, index+1, page); |
218 |
238 |
219 } |
239 } |
220 return page; |
240 return page; |
221 } |
241 } |
222 |
242 |
223 |
243 |
224 QWebPage* WebPageController::openPage() |
244 WRT::WrtBrowserContainer* WebPageController::openPage() |
225 { |
245 { |
226 WRT::WrtBrowserContainer* page = NULL; |
246 WRT::WrtBrowserContainer* page = NULL; |
227 |
247 |
228 page = openPage(this, 0); |
248 page = openPage(this, 0); |
229 page->setPageFactory(this); |
249 page->setPageFactory(this); |
230 |
250 |
231 return page; |
251 return page; |
232 } |
252 } |
233 |
253 |
234 QWebPage* WebPageController::openPageFromHistory(int index) |
254 WRT::WrtBrowserContainer* WebPageController::openPageFromHistory(int index) |
235 { |
255 { |
236 QDir dir(d->m_historyDir); |
256 QDir dir(d->m_historyDir); |
237 QFileInfoList fileList(dir.entryInfoList(QDir::Files)); |
257 QFileInfoList fileList(dir.entryInfoList(QDir::Files)); |
238 QString indexStr; |
258 QString indexStr; |
239 indexStr.setNum(index); |
259 indexStr.setNum(index); |
261 * @param page WRT::WrtBrowserContainer instance to be closed |
281 * @param page WRT::WrtBrowserContainer instance to be closed |
262 * @see WRT::WrtBrowserContainer |
282 * @see WRT::WrtBrowserContainer |
263 */ |
283 */ |
264 void WebPageController::closePage ( WRT::WrtBrowserContainer *page ) |
284 void WebPageController::closePage ( WRT::WrtBrowserContainer *page ) |
265 { |
285 { |
266 WRT::WrtBrowserContainer * theCurrentPage = currentPage(); |
286 if(pageCount() > 1) { |
267 bool updateCurrentPageIndex = false; |
287 WRT::WrtBrowserContainer * theCurrentPage = currentPage(); |
268 |
288 bool updateCurrentPageIndex = false; |
269 // get index of page we want to remove |
289 |
270 int closeIndex = d->m_allPages.indexOf(page); |
290 // get index of page we want to remove |
271 if(closeIndex < 0) |
291 int closeIndex = d->m_allPages.indexOf(page); |
272 return; |
292 if(closeIndex < 0) |
273 |
293 return; |
274 // was this page the "current page?" |
294 |
275 // if so, we need to select the page to become the new one |
295 // was this page the "current page?" |
276 // select the previous page unless at the beginning, then select next |
296 // if so, we need to select the page to become the new one |
277 if(page == theCurrentPage) { |
297 // select the previous page unless at the beginning, then select next |
278 int newCurrIndex = closeIndex - 1; |
298 if(page == theCurrentPage) { |
279 if(closeIndex == 0 ) { |
299 int newCurrIndex = closeIndex - 1; |
280 newCurrIndex = closeIndex + 1; |
300 if(closeIndex == 0 ) { |
281 } |
301 newCurrIndex = closeIndex + 1; |
|
302 } |
282 |
303 |
283 // change the current page |
304 // change the current page |
284 if(newCurrIndex >= 0) { |
305 if(newCurrIndex >= 0) { |
285 theCurrentPage = d->m_allPages.at(newCurrIndex); |
306 theCurrentPage = d->m_allPages.at(newCurrIndex); |
286 setCurrentPage(theCurrentPage); |
307 setCurrentPage(theCurrentPage); |
287 updateCurrentPageIndex = true; |
308 updateCurrentPageIndex = true; |
|
309 } |
|
310 else { |
|
311 d->m_currentPage = -1; |
|
312 emit pageChanged(page, NULL); |
|
313 } |
288 } |
314 } |
289 else { |
315 else { |
290 d->m_currentPage = -1; |
316 /* Adjust m_currentPage if the index of the page deleted is less than |
291 emit pageChanged(page, NULL); |
317 * current page |
|
318 */ |
|
319 if (closeIndex < d->m_currentPage ) |
|
320 updateCurrentPageIndex = true; |
292 } |
321 } |
293 } |
322 |
294 else { |
323 // actually delete the page from the list |
295 /* Adjust m_currentPage if the index of the page deleted is less than |
324 d->m_allPages.removeAt(closeIndex); |
296 * current page |
325 |
297 */ |
326 // update the current page index if necessary |
298 if (closeIndex < d->m_currentPage ) |
327 // (this will just update the index now that we've removed the page from the list) |
299 updateCurrentPageIndex = true; |
328 if(updateCurrentPageIndex) { |
300 } |
329 int index = d->m_allPages.indexOf(theCurrentPage); |
301 |
330 if(index >= 0) |
302 // actually delete the page from the list |
331 d->m_currentPage = index; |
303 d->m_allPages.removeAt(closeIndex); |
332 } |
304 |
333 |
305 // update the current page index if necessary |
334 // and emit sig that it was done |
306 // (this will just update the index now that we've removed the page from the list) |
335 emit pageDeleted(page); |
307 if(updateCurrentPageIndex) { |
336 |
308 int index = d->m_allPages.indexOf(theCurrentPage); |
337 delete page; |
309 if(index >= 0) |
338 } |
310 d->m_currentPage = index; |
|
311 } |
|
312 |
|
313 // and emit sig that it was done |
|
314 emit pageDeleted(page); |
|
315 |
|
316 delete page; |
|
317 } |
339 } |
318 |
340 |
319 /*! |
341 /*! |
320 * Activate the given page as the current page |
342 * Activate the given page as the current page |
321 * @param page page handle for setting current page |
343 * @param page page handle for setting current page |
345 disconnect(oldPage, 0, this, 0); |
367 disconnect(oldPage, 0, this, 0); |
346 disconnect(oldPage->mainFrame(), 0, this, 0); |
368 disconnect(oldPage->mainFrame(), 0, this, 0); |
347 disconnect(oldPage->networkAccessManager(), 0, this, 0); |
369 disconnect(oldPage->networkAccessManager(), 0, this, 0); |
348 disconnect(oldPage->loadController(), 0, this, 0); |
370 disconnect(oldPage->loadController(), 0, this, 0); |
349 connect(oldPage, SIGNAL(createNewWindow(WrtBrowserContainer*)), this, SLOT(createWindow(WrtBrowserContainer*))); |
371 connect(oldPage, SIGNAL(createNewWindow(WrtBrowserContainer*)), this, SLOT(createWindow(WrtBrowserContainer*))); |
350 } |
372 connect(oldPage, SIGNAL(loadFinished(bool)), SLOT(onLoadFinishedForBackgroundWindow(bool))); |
351 |
373 } |
352 // aggregate "current page" signalling from this page to PageMgr clients |
374 // aggregate "current page" signalling from this page to PageMgr clients |
353 connect(page, SIGNAL(secureStateChange(int)), this, SLOT(secureStateChange(int))); |
375 connect(page, SIGNAL(secureStateChange(int)), this, SLOT(secureStateChange(int))); |
354 connect( page->mainFrame(), SIGNAL ( titleChanged ( const QString& ) ), SIGNAL ( titleChanged ( const QString& ) ) ); |
376 connect( page->mainFrame(), SIGNAL ( titleChanged ( const QString& ) ), SIGNAL ( titleChanged ( const QString& ) ) ); |
355 connect( page, SIGNAL( loadStarted() ), SIGNAL( loadStarted() ) ); |
377 connect( page, SIGNAL( loadStarted() ), SIGNAL( loadStarted() ) ); |
|
378 connect( page->mainFrame(), SIGNAL(initialLayoutCompleted() ), SIGNAL( initialLayoutCompleted() ) ); |
356 connect( page, SIGNAL( loadProgress(int) ), SIGNAL( loadProgress(int) ) ); |
379 connect( page, SIGNAL( loadProgress(int) ), SIGNAL( loadProgress(int) ) ); |
357 connect( page, SIGNAL( loadFinished(bool) ), SIGNAL( loadFinished(bool) ) ); |
380 connect( page, SIGNAL( loadFinished(bool) ), SLOT( onLoadFinished(bool) ) ); |
|
381 |
|
382 connect( page, SIGNAL( databaseQuotaExceeded (QWebFrame *,QString) ), SLOT( onDatabaseQuotaExceeded (QWebFrame *,QString)) ); |
|
383 |
358 connect( page->mainFrame(), SIGNAL( iconChanged() ), SIGNAL( pageIconChanged() ) ); |
384 connect( page->mainFrame(), SIGNAL( iconChanged() ), SIGNAL( pageIconChanged() ) ); |
359 connect( page->loadController(), SIGNAL( pageLoadStarted() ), SIGNAL( pageLoadStarted() ) ); |
385 connect( page->loadController(), SIGNAL( pageLoadStarted() ), SIGNAL( pageLoadStarted() ) ); |
|
386 connect( page->loadController(), SIGNAL( pageLoadFailed() ), SIGNAL( pageLoadFailed() ) ); |
360 connect( page->loadController(), SIGNAL( pageLoadProgress(int) ), SIGNAL( pageLoadProgress(int) ) ); |
387 connect( page->loadController(), SIGNAL( pageLoadProgress(int) ), SIGNAL( pageLoadProgress(int) ) ); |
361 connect( page->loadController(), SIGNAL( pageLoadFinished(bool) ), SIGNAL( pageLoadFinished(bool) ) ); |
388 connect( page->loadController(), SIGNAL( pageLoadFinished(bool) ), SIGNAL( pageLoadFinished(bool) ) ); |
362 connect( page->loadController(), SIGNAL( pageUrlChanged(QString) ), SIGNAL( pageUrlChanged(QString) ) ); |
389 connect( page->loadController(), SIGNAL( pageUrlChanged(QString) ), SIGNAL( pageUrlChanged(QString) ) ); |
363 connect( page, SIGNAL(createNewWindow(WrtBrowserContainer*)), this, SLOT(createWindow(WrtBrowserContainer*))); |
390 connect( page, SIGNAL(createNewWindow(WrtBrowserContainer*)), this, SLOT(createWindow(WrtBrowserContainer*))); |
364 |
391 |
|
392 |
365 // Connect the unsuportedContent signal to start a new download |
393 // Connect the unsuportedContent signal to start a new download |
366 connect( page, SIGNAL(unsupportedContent(QNetworkReply *)), this, SLOT(unsupportedContentArrived(QNetworkReply *))); |
394 connect( page, SIGNAL(unsupportedContent(QNetworkReply *)), this, SLOT(unsupportedContentArrived(QNetworkReply *))); |
367 |
395 |
368 connect( page, SIGNAL( loadStarted() ), SLOT( updateStatePageLoading() ) ); |
396 connect( page, SIGNAL( loadStarted() ), SLOT( updateStatePageLoading() ) ); |
369 connect( page, SIGNAL( loadFinished(bool) ), SLOT( updateStatePageLoadComplete(bool) ) ); |
397 |
370 |
398 |
371 connect( page->mainFrame(), SIGNAL( iconChanged() ), this, SIGNAL( currentPageIconChanged() ) ); |
399 connect( page->mainFrame(), SIGNAL( iconChanged() ), this, SIGNAL( currentPageIconChanged() ) ); |
372 connect( page->mainFrame(), SIGNAL( urlChanged( const QUrl &)), this, SIGNAL( currentPageUrlChanged( const QUrl &) )); |
400 connect( page->mainFrame(), SIGNAL( urlChanged( const QUrl &)), this, SIGNAL( currentPageUrlChanged( const QUrl &) )); |
373 connect( page->mainFrame(), SIGNAL( urlChanged( const QUrl &)), this, SLOT( urlChanged( const QUrl &) )); |
401 connect( page->mainFrame(), SIGNAL( urlChanged( const QUrl &)), this, SLOT( urlChanged( const QUrl &) )); |
374 |
402 |
375 connect( page, SIGNAL( networkRequestStarted(QWebFrame*, QNetworkRequest*)), this, SIGNAL( networkRequestStarted(QWebFrame*, QNetworkRequest*))); |
|
376 connect( page->networkAccessManager(), SIGNAL(sslErrors(QNetworkReply *, const QList<QSslError> &)), this, SIGNAL( sslErrors(QNetworkReply *, const QList<QSslError> &))); |
403 connect( page->networkAccessManager(), SIGNAL(sslErrors(QNetworkReply *, const QList<QSslError> &)), this, SIGNAL( sslErrors(QNetworkReply *, const QList<QSslError> &))); |
377 connect( page->networkAccessManager(), SIGNAL(showMessageBox(WRT::MessageBoxProxy*)), this, SIGNAL(showMessageBox(WRT::MessageBoxProxy*))); |
404 connect( page->networkAccessManager(), SIGNAL(showMessageBox(WRT::MessageBoxProxy*)), this, SIGNAL(showMessageBox(WRT::MessageBoxProxy*))); |
|
405 // Connect network reply errors |
|
406 connect( page->networkAccessManager(), SIGNAL( networkErrorHappened(const QString &) ), this, SIGNAL( networkErrorHappened(const QString &) ) ); |
|
407 connect( page->networkAccessManager(), SIGNAL( networkErrorHappened(const QString &) ), this, SLOT( processNetworkErrorHappened(const QString &) ) ); |
|
408 connect( page->networkAccessManager(), SIGNAL( networkErrorUrl(const QUrl &) ), this, SLOT( processNetworkErrorUrl(const QUrl &) ) ); |
|
409 |
378 connect(currentPage(), SIGNAL(pageScrollPositionZero()), this, SIGNAL(pageScrollPositionZero()) ); |
410 connect(currentPage(), SIGNAL(pageScrollPositionZero()), this, SIGNAL(pageScrollPositionZero()) ); |
379 connect(page, SIGNAL(scrollRequested(int, int, const QRect & )), this, SIGNAL(pageScrollRequested(int, int, const QRect & )) ); |
411 connect(page, SIGNAL(scrollRequested(int, int, const QRect & )), this, SIGNAL(pageScrollRequested(int, int, const QRect & )) ); |
380 |
412 |
381 Q_ASSERT ( d->m_currentPage >= 0 ); |
413 Q_ASSERT ( d->m_currentPage >= 0 ); |
382 |
414 |
383 updateActions(false); |
415 updateActions(false); |
384 |
416 |
385 emit pageChanged( oldPage, page ); |
417 emit pageChanged( oldPage, page ); |
386 } |
418 } |
|
419 |
|
420 |
|
421 |
|
422 void WebPageController::onLoadFinished(bool ok) |
|
423 { |
|
424 updateStatePageLoadComplete(ok); |
|
425 if (ok) { |
|
426 QTimer::singleShot(300, this, SLOT(updateHistory())); |
|
427 } |
|
428 else { |
|
429 emit(loadFinished(false)); |
|
430 } |
|
431 } |
|
432 |
|
433 |
|
434 void WebPageController::onDatabaseQuotaExceeded (QWebFrame *frame, QString database) |
|
435 { |
|
436 QString dbdir = QWebSettings::offlineStoragePath (); |
|
437 QDir dir(dbdir); |
|
438 |
|
439 if(!dir.exists()||(dir.count() <= 1)) // empty DB |
|
440 return; |
|
441 |
|
442 |
|
443 if(frame) |
|
444 { |
|
445 QWebSecurityOrigin qwso = frame->securityOrigin(); |
|
446 qint64 quota = qwso.databaseQuota() ; |
|
447 qint64 usage = qwso.databaseUsage() ; |
|
448 } |
|
449 m_promptMsg = "Database Quota Error"; |
|
450 emit databaseQuotaExceeded (frame, database); |
|
451 |
|
452 return; |
|
453 } |
|
454 |
|
455 void WebPageController::onLoadFinishedForBackgroundWindow(bool ok) |
|
456 { |
|
457 if (!ok) |
|
458 return; |
|
459 WRT::WrtBrowserContainer* page = qobject_cast<WRT::WrtBrowserContainer*> (sender()); |
|
460 if (page) |
|
461 page->setUpdateThumbnail(true); |
|
462 } |
|
463 |
|
464 void WebPageController::updateHistory() |
|
465 { |
|
466 BookmarksManager::getSingleton()->addHistory(currentDocUrl(), currentDocTitle()); |
|
467 emit(loadFinished(true)); |
|
468 } |
|
469 |
|
470 /*! |
|
471 * Handling of network error happens signal |
|
472 * @return Returns current page handle |
|
473 * @see WRT::WrtBrowserContainer |
|
474 */ |
|
475 void WebPageController::processNetworkErrorHappened(const QString & msg ) |
|
476 { |
|
477 m_networkError = true; |
|
478 m_networkErrorMsg = msg; |
|
479 } |
|
480 |
|
481 /*! |
|
482 * Handling of network error associated url |
|
483 * @return Returns current page handle |
|
484 * @see WRT::WrtBrowserContainer |
|
485 */ |
|
486 void WebPageController::processNetworkErrorUrl(const QUrl & url ) |
|
487 { |
|
488 QString errorUrl = url.toString(); |
|
489 QString requestedUrl = currentRequestedUrl(); |
|
490 m_networkErrorUrl = url.toString(); |
|
491 |
|
492 // Check if requestedUrl matches the URL from the network error |
|
493 // This is to resolve the problems when error popups occur when they shouldn't |
|
494 // especially during download. |
|
495 int matches = m_networkErrorUrl.compare(requestedUrl); |
|
496 if (matches == 0) m_bErrorUrlMatches = true; |
|
497 } |
|
498 |
|
499 //void QWEBKIT_EXPORT qt_drt_garbageCollector_collect(); |
|
500 |
|
501 /*! |
|
502 * Try to release as much memory as possible from caches and collectors |
|
503 */ |
|
504 void WebPageController::releaseMemory() |
|
505 { |
|
506 // clears JavaScript Collector heap; private export in QWebFrame, so commented out for now |
|
507 // qt_drt_garbageCollector_collect(); |
|
508 |
|
509 // webkit/webkit/qt/api |
|
510 QWebSettings::clearIconDatabase(); |
|
511 QWebSettings::clearMemoryCaches(); |
|
512 |
|
513 QPixmapCache::clear(); |
|
514 } |
|
515 |
|
516 /*! |
|
517 * Handle low memory signals from LowMemoryHandler |
|
518 * @see LowMemoryHandler |
|
519 */ |
|
520 void WebPageController::handleLowMemory() |
|
521 { |
|
522 currentStop(); |
|
523 releaseMemory(); |
|
524 } |
|
525 |
|
526 /*! |
|
527 * Handle out of memory signals from LowMemoryHandler |
|
528 * @see LowMemoryHandler |
|
529 */ |
|
530 void WebPageController::handleOutOfMemory() |
|
531 { |
|
532 currentStop(); |
|
533 releaseMemory(); |
|
534 } |
387 |
535 |
388 /*! |
536 /*! |
389 * Retrieve a pointer to the current WRT::WrtBrowserContainer |
537 * Retrieve a pointer to the current WRT::WrtBrowserContainer |
390 * @return Returns current page handle |
538 * @return Returns current page handle |
391 * @see WRT::WrtBrowserContainer |
539 * @see WRT::WrtBrowserContainer |
594 void WebPageController::currentLoad(const QString &url) |
696 void WebPageController::currentLoad(const QString &url) |
595 { |
697 { |
596 currentLoad(QUrl(url)); |
698 currentLoad(QUrl(url)); |
597 } |
699 } |
598 |
700 |
|
701 /* |
|
702 Share the url through mail client |
|
703 */ |
|
704 #if defined(Q_OS_SYMBIAN) |
|
705 void WebPageController::share(const QString &url) |
|
706 { |
|
707 QString body = url; |
|
708 CSendUi* sendUi = CSendUi::NewLC(); |
|
709 CMessageData* messageData = CMessageData::NewLC(); |
|
710 |
|
711 TSendingCapabilities sendingCapabilities; |
|
712 sendingCapabilities.iFlags = TSendingCapabilities::ESupportsAttachments; |
|
713 |
|
714 // Not interested in these following services |
|
715 CArrayFixFlat<TUid>* array = new (ELeave) CArrayFixFlat<TUid>(8); |
|
716 CleanupStack::PushL(array); |
|
717 array->AppendL(KSenduiTechnologyMmsUid); |
|
718 array->AppendL(KSenduiTechnologyIMUid); |
|
719 array->AppendL(KMmsDirectUpload); |
|
720 array->AppendL(KMmsIndirectUpload); |
|
721 array->AppendL(KMmsUploadService1Id); |
|
722 array->AppendL(KMmsUploadService2Id); |
|
723 array->AppendL(KMmsUploadService3Id); |
|
724 array->AppendL(KMmsUploadService4Id); |
|
725 array->AppendL(KShareOnline); |
|
726 array->AppendL(KShareOnOvi); |
|
727 |
|
728 // Body |
|
729 CParaFormatLayer* paraFormat = CParaFormatLayer::NewL(); |
|
730 CleanupStack::PushL( paraFormat ); |
|
731 CCharFormatLayer* charFormat = CCharFormatLayer::NewL(); |
|
732 CleanupStack::PushL( charFormat ); |
|
733 CRichText* bodyRichText = CRichText::NewL( paraFormat, charFormat ); |
|
734 CleanupStack::PushL( bodyRichText ); |
|
735 |
|
736 TPtrC bodyPtr(reinterpret_cast<const TUint16*>(body.utf16())); |
|
737 |
|
738 if( bodyPtr.Length() ) |
|
739 bodyRichText->InsertL( 0, bodyPtr ); |
|
740 else |
|
741 bodyRichText->InsertL( 0, KNullDesC ); |
|
742 |
|
743 messageData->SetBodyTextL( bodyRichText ); |
|
744 sendUi->ShowQueryAndSendL(messageData, sendingCapabilities, array); |
|
745 CleanupStack::PopAndDestroy( 6 ); // bodyRichText, charFormat, paraFormat, messageData, sendUi |
|
746 } |
|
747 #else |
|
748 void WebPageController::share(const QString &url) |
|
749 { |
|
750 return; // Not supported |
|
751 } |
|
752 #endif |
|
753 |
|
754 /* |
|
755 Feedback from user |
|
756 */ |
|
757 #if defined(Q_OS_SYMBIAN) |
|
758 void WebPageController::feedbackMail(const QString &mailAddress, const QString &mailBody) |
|
759 { |
|
760 QString to = mailAddress; |
|
761 QString body = mailBody; |
|
762 CSendUi* sendUi = CSendUi::NewLC(); |
|
763 CMessageData* messageData = CMessageData::NewLC(); |
|
764 |
|
765 // Body |
|
766 CParaFormatLayer* paraFormat = CParaFormatLayer::NewL(); |
|
767 CleanupStack::PushL( paraFormat ); |
|
768 CCharFormatLayer* charFormat = CCharFormatLayer::NewL(); |
|
769 CleanupStack::PushL( charFormat ); |
|
770 CRichText* bodyRichText = CRichText::NewL( paraFormat, charFormat ); |
|
771 CleanupStack::PushL( bodyRichText ); |
|
772 TPtrC ToPtr(reinterpret_cast<const TUint16*>(to.utf16())); |
|
773 TPtrC bodyPtr(reinterpret_cast<const TUint16*>(body.utf16())); |
|
774 if( bodyPtr.Length() ) |
|
775 bodyRichText->InsertL( 0, bodyPtr ); |
|
776 else |
|
777 bodyRichText->InsertL( 0, KNullDesC ); |
|
778 |
|
779 messageData->AppendToAddressL( ToPtr ); |
|
780 messageData->SetBodyTextL( bodyRichText ); |
|
781 |
|
782 TRAP_IGNORE(sendUi->CreateAndSendMessageL( KUidMsgTypeSMTP, messageData )); |
|
783 // TRAP_IGNORE(sendUi->CreateAndSendMessageL( KSenduiMtmSmsUid, messageData )); |
|
784 CleanupStack::PopAndDestroy( 5 ); |
|
785 } |
|
786 #else |
|
787 void WebPageController::feedbackMail(const QString &mailAddress, const QString &mailBody) |
|
788 { |
|
789 return; // Not supported |
|
790 } |
|
791 #endif |
599 /*! |
792 /*! |
600 Load an item into the current page from a given /a historyIndex |
793 Load an item into the current page from a given /a historyIndex |
601 */ |
794 */ |
602 void WebPageController::currentSetFromHistory(int historyIndex) |
795 void WebPageController::currentSetFromHistory(int historyIndex) |
603 { |
796 { |
903 } |
1044 } |
904 |
1045 |
905 return winStr; |
1046 return winStr; |
906 } |
1047 } |
907 |
1048 |
908 void WebPageController::saveHistory() |
1049 void WebPageController::saveHistory(int* windowsSaved, int* activeWindowId) |
909 { |
1050 { |
910 QString indexStr; |
1051 QString indexStr; |
|
1052 int index = 0; |
|
1053 |
911 unsigned int pageCount = d->m_allPages.count(); |
1054 unsigned int pageCount = d->m_allPages.count(); |
912 int index = 0; |
1055 |
913 |
1056 // Get index of current page |
914 WRT::WrtBrowserContainer* theCurrentPage = currentPage(); |
1057 WRT::WrtBrowserContainer* theCurrentPage = currentPage(); |
915 int currentIndex = d->m_allPages.indexOf(theCurrentPage); |
1058 int currentIndex = d->m_allPages.indexOf(theCurrentPage); |
916 |
1059 |
917 //if(pageCount == 1) |
|
918 //{ |
|
919 QWebHistoryItem item = theCurrentPage->history()->currentItem(); |
|
920 |
|
921 setLastUrl(item.url().toString()); |
|
922 //} |
|
923 |
|
924 for (int tIndex = 0; tIndex < pageCount; tIndex++) |
1060 for (int tIndex = 0; tIndex < pageCount; tIndex++) |
925 { |
1061 { |
926 if(tIndex == pageCount-1) |
1062 // Don't save blank windows |
927 index = currentIndex; |
1063 WrtBrowserContainer* page = d->m_allPages.at(tIndex); |
928 else if(tIndex == currentIndex) |
1064 QString pageUrl = page->history()->currentItem().url().toString(); |
929 index = pageCount-1; |
1065 if (!pageUrl.isEmpty()) |
930 else |
1066 { |
931 index = tIndex; |
1067 |
932 |
1068 // In case of blank windows, reset the active window id |
933 if (index >= MAX_NUM_WINDOWS_TO_RESTORE) return; |
1069 if (currentIndex == tIndex) *activeWindowId = index; |
934 indexStr.setNum(tIndex); |
1070 |
935 QString historyFile = d->m_historyDir + QLatin1String("/history") + indexStr + QLatin1String(".history"); |
1071 // Serialize page to file |
936 // Save the History state to disk |
1072 indexStr.setNum(index); |
937 QFile file(historyFile); |
1073 QString historyFile = d->m_historyDir + QLatin1String("/history") + indexStr + QLatin1String(".history"); |
938 if(file.open(QIODevice::WriteOnly)) { |
1074 QFile file(historyFile); |
939 QDataStream save(&file); |
1075 if(file.open(QIODevice::WriteOnly)) { |
940 save << *(d->m_allPages.at(index)->history()); |
1076 QDataStream save(&file); |
941 qDebug() << "Saved History<<:" << historyFile; |
1077 save << *(d->m_allPages.at(tIndex)->history()); |
942 file.flush(); |
1078 file.flush(); |
943 file.close(); |
1079 file.close(); |
|
1080 } |
|
1081 index++; |
944 } |
1082 } |
945 } |
1083 } |
|
1084 |
|
1085 // Save last url |
|
1086 WRT::WrtBrowserContainer* currentPage = d->m_allPages.at(*activeWindowId); |
|
1087 QWebHistoryItem item = theCurrentPage->history()->currentItem(); |
|
1088 QString lastUrl = item.url().toString(); |
|
1089 setLastUrl(lastUrl); |
|
1090 *windowsSaved = index; |
946 } |
1091 } |
947 |
1092 |
948 void WebPageController::deleteDataFiles() |
1093 void WebPageController::deleteDataFiles() |
949 { |
1094 { |
|
1095 |
950 QDir dir(d->m_historyDir); |
1096 QDir dir(d->m_historyDir); |
951 |
1097 |
952 QString lasturlFile = d->m_historyDir + QLatin1String("/lasturl") + QLatin1String(".dat"); |
1098 QString lasturlFile = d->m_historyDir + QLatin1String("/lasturl") + QLatin1String(".dat"); |
953 QFile file1(lasturlFile); |
1099 QFile file1(lasturlFile); |
954 if(file1.open(QIODevice::ReadOnly)) |
1100 if(file1.open(QIODevice::ReadOnly)) |
962 if(file2.open(QIODevice::ReadOnly)) |
1108 if(file2.open(QIODevice::ReadOnly)) |
963 { |
1109 { |
964 file2.remove(); |
1110 file2.remove(); |
965 file2.close(); |
1111 file2.close(); |
966 } |
1112 } |
|
1113 |
|
1114 d->donotsaveFlag = true; |
967 |
1115 |
968 } |
1116 } |
969 |
1117 |
|
1118 QString WebPageController::getTextEncoding() |
|
1119 { |
|
1120 //QString encoding = QWebSettings::globalSettings()->defaultTextEncoding(); |
|
1121 QString encoding = BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->value("BrowserEncoding").toString(); |
|
1122 |
|
1123 if(encoding == "Automatic") |
|
1124 QWebSettings::globalSettings()->setDefaultTextEncoding(""); |
|
1125 else |
|
1126 QWebSettings::globalSettings()->setDefaultTextEncoding(encoding); |
|
1127 |
|
1128 return encoding; |
|
1129 } |
|
1130 |
|
1131 |
|
1132 void WebPageController::setTextEncoding(const QString & encoding ) |
|
1133 { |
|
1134 if(encoding == "Automatic") |
|
1135 QWebSettings::globalSettings()->setDefaultTextEncoding(""); |
|
1136 else |
|
1137 QWebSettings::globalSettings()->setDefaultTextEncoding(encoding); |
|
1138 |
|
1139 BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->setValue("BrowserEncoding", encoding); |
|
1140 return ; |
|
1141 } |
|
1142 |
|
1143 |
|
1144 void WebPageController::setSettingsLoaded(int value) |
|
1145 { |
|
1146 m_settingsLoaded = value; |
|
1147 } |
|
1148 |
|
1149 int WebPageController::getSettingsLoaded() |
|
1150 { |
|
1151 return m_settingsLoaded; |
|
1152 } |
|
1153 |
970 void WebPageController::savePopupSettings(int val) |
1154 void WebPageController::savePopupSettings(int val) |
971 { |
1155 { |
972 BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->setValue("PopupBlocking", val); |
1156 BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->setValue("PopupBlocking", val); |
|
1157 |
|
1158 //qDebug() << "WebPageController::savePopupSettings " << val << d->m_allPages.count(); |
|
1159 for (int tIndex = 0; tIndex < d->m_allPages.count(); tIndex++) |
|
1160 { |
|
1161 WrtBrowserContainer* page = d->m_allPages.at(tIndex); |
|
1162 page->settings()->setAttribute(QWebSettings::JavascriptCanOpenWindows, !val); |
|
1163 |
|
1164 } |
|
1165 |
973 } |
1166 } |
974 |
1167 |
975 bool WebPageController::getPopupSettings() |
1168 bool WebPageController::getPopupSettings() |
976 { |
1169 { |
977 bool val = (bool)BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->value("PopupBlocking").toInt(); |
1170 bool val = (bool)BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->value("PopupBlocking").toInt(); |
978 return val; |
1171 return val; |
979 |
1172 |
980 } |
1173 } |
981 |
1174 |
982 void WebPageController::saveNumberOfWindows() |
1175 |
|
1176 void WebPageController::saveSaverestoreSettings(int val) |
|
1177 { |
|
1178 BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->setValue("SaveSession", val); |
|
1179 BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->setValue("SaveHistory", val); |
|
1180 |
|
1181 if(val == 0) |
|
1182 d->donotsaveFlag = true; // do not save .dat file |
|
1183 else // val = 1 |
|
1184 d->donotsaveFlag = false; |
|
1185 |
|
1186 } |
|
1187 |
|
1188 bool WebPageController::getSaverestoreSettings() |
|
1189 { |
|
1190 bool val = (bool)BEDROCK_PROVISIONING::BedrockProvisioning::createBedrockProvisioning()->value("SaveSession").toInt(); |
|
1191 return val; |
|
1192 |
|
1193 } |
|
1194 |
|
1195 void WebPageController::saveNumberOfWindows(int windowsSaved) |
983 { |
1196 { |
984 QString winFile = d->m_historyDir + QLatin1String("/numwindow") + QLatin1String(".dat"); |
1197 QString winFile = d->m_historyDir + QLatin1String("/numwindow") + QLatin1String(".dat"); |
985 int winCount = d->m_allPages.count(); |
|
986 |
1198 |
987 QFile file(winFile); |
1199 QFile file(winFile); |
988 if(file.open(QIODevice::WriteOnly)) { |
1200 if(file.open(QIODevice::WriteOnly)) { |
989 QTextStream textStream(&file); |
1201 QTextStream textStream(&file); |
990 textStream << winCount; |
1202 textStream << windowsSaved; |
|
1203 textStream.flush(); |
|
1204 file.close(); |
|
1205 } |
|
1206 |
|
1207 } |
|
1208 void WebPageController::saveActiveWindowId(int activeWindowId) |
|
1209 { |
|
1210 QString winFile = d->m_historyDir + QLatin1String("/activewindow") + QLatin1String(".dat"); |
|
1211 |
|
1212 QFile file(winFile); |
|
1213 if(file.open(QIODevice::WriteOnly)) { |
|
1214 QTextStream textStream(&file); |
|
1215 textStream << activeWindowId; |
991 textStream.flush(); |
1216 textStream.flush(); |
992 file.close(); |
1217 file.close(); |
993 } |
1218 } |
994 |
1219 |
995 } |
1220 } |
1244 QSize currSize = view->size().toSize(); |
1523 QSize currSize = view->size().toSize(); |
1245 |
1524 |
1246 bool needRestore = false; |
1525 bool needRestore = false; |
1247 |
1526 |
1248 for (int i = 0; i < allPages()->count(); i++) { |
1527 for (int i = 0; i < allPages()->count(); i++) { |
1249 WRT::WrtBrowserContainer* page = allPages()->at(i); |
1528 WRT::WrtBrowserContainer* page = allPages()->at(i); |
1250 QWebHistoryItem item = page->history()->currentItem(); |
1529 QWebHistoryItem item = page->history()->currentItem(); |
1251 |
1530 WebPageData data = item.userData().value<WebPageData>(); |
1252 WebPageData data = item.userData().value<WebPageData>(); |
|
1253 |
1531 |
1254 // If not still a blank window, check whether we need to update the img |
1532 // If not still a blank window, check whether we need to update the img |
1255 if (!page->emptyWindow() ){ |
1533 if (!page->emptyWindow() ){ |
1256 QImage img = data.m_thumbnail; |
1534 QImage img = data.m_thumbnail; |
1257 |
1535 bool isSameMode = ( (img.size().width() > img.size().height()) == (currSize.width() > currSize.height()) ); |
1258 bool isSameMode = ( (img.size().width() > img.size().height()) == (currSize.width() > currSize.height()) ); |
1536 if (img.isNull() || !isSameMode) { |
1259 if (img.isNull() || !isSameMode) { |
1537 needRestore = true; |
1260 |
1538 view->setPage(page); |
1261 qDebug() << "need new thumbnail!!!" << img.size() << ":" << currSize; |
1539 page->setWebWidget(view); |
1262 needRestore = true; |
1540 QCoreApplication::sendEvent(view, new WebPageControllerUpdateViewPortEvent()); |
1263 view->setPage(page); |
1541 page->savePageDataToHistoryItem(page->mainFrame(), &item); |
1264 page->setWebWidget(view); |
1542 page->setUpdateThumbnail(false); |
1265 QCoreApplication::sendEvent(view, new WebPageControllerUpdateViewPortEvent()); |
1543 } |
1266 page->savePageDataToHistoryItem(page->mainFrame(), &item); |
1544 if (page->needUpdateThumbnail()) { |
1267 } |
1545 page->savePageDataToHistoryItem(page->mainFrame(), &item); |
|
1546 page->setUpdateThumbnail(false); |
|
1547 } |
1268 } |
1548 } |
1269 } |
1549 } |
1270 |
1550 |
1271 // restore |
1551 // restore |
1272 if (needRestore) |
1552 if (needRestore) { |
1273 { |
|
1274 view->setPage(savedPage); |
1553 view->setPage(savedPage); |
1275 savedPage->setWebWidget(view); |
1554 savedPage->setWebWidget(view); |
1276 } |
1555 } |
1277 } |
1556 } |
1278 |
1557 |
1279 void WebPageController::updatePageThumbnails() |
1558 void WebPageController::updatePageThumbnails() |
1280 { |
1559 { |
1281 // update current page's thumbnail forcely |
1560 // update current page's thumbnail forcely since the scrolling position may change |
1282 WRT::WrtBrowserContainer *page = currentPage(); |
1561 WRT::WrtBrowserContainer *page = currentPage(); |
1283 QWebHistoryItem item = page->history()->currentItem(); |
1562 QWebHistoryItem item = page->history()->currentItem(); |
1284 |
|
1285 page->savePageDataToHistoryItem(page->mainFrame(), &item); |
1563 page->savePageDataToHistoryItem(page->mainFrame(), &item); |
1286 |
1564 page->setUpdateThumbnail(false); |
1287 WebPageData data = item.userData().value<WebPageData>(); |
|
1288 |
|
1289 checkAndUpdatePageThumbnails(); |
1565 checkAndUpdatePageThumbnails(); |
1290 } |
1566 } |
1291 |
1567 |
1292 void WebPageController::resizeAndUpdatePageThumbnails(QSize& s) |
1568 void WebPageController::resizeAndUpdatePageThumbnails(QSize& s) |
1293 { |
1569 { |