diff options
-rw-r--r-- | src/application.cpp | 77 | ||||
-rw-r--r-- | src/application.h | 2 | ||||
-rw-r--r-- | src/mainwindow.cpp | 75 | ||||
-rw-r--r-- | src/mainwindow.h | 1 | ||||
-rw-r--r-- | src/networkaccessmanager.cpp | 70 | ||||
-rw-r--r-- | src/networkaccessmanager.h | 4 | ||||
-rw-r--r-- | src/webpage.cpp | 21 | ||||
-rw-r--r-- | src/webpage.h | 1 |
8 files changed, 134 insertions, 117 deletions
diff --git a/src/application.cpp b/src/application.cpp index 45d115ae..b28055f7 100644 --- a/src/application.cpp +++ b/src/application.cpp @@ -44,6 +44,7 @@ #include "adblockmanager.h" #include "webview.h" #include "filterurljob.h" +#include "tabbar.h" // KDE Includes #include <KCmdLineArgs> @@ -182,7 +183,10 @@ Application *Application::instance() void Application::postLaunch() -{ +{ + // updating rekonq configuration + updateConfiguration(); + setWindowIcon(KIcon("rekonq")); // set Icon Database Path to store "favicons" associated with web sites @@ -392,3 +396,74 @@ void Application::newWindow() loadUrl( KUrl("about:home"), Rekonq::NewWindow ); mainWindow()->mainView()->urlBarWidget()->setFocus(); } + + +void Application::updateConfiguration() +{ + MainView *view = mainWindow()->mainView(); + + // ============== General ================== + view->updateTabBar(); + + // ============== Tabs ================== + if (ReKonfig::closeTabSelectPrevious()) + view->tabBar()->setSelectionBehaviorOnRemove(QTabBar::SelectPreviousTab); + else + view->tabBar()->setSelectionBehaviorOnRemove(QTabBar::SelectRightTab); + + // =========== Fonts ============== + QWebSettings *defaultSettings = QWebSettings::globalSettings(); + + int fnSize = ReKonfig::fontSize(); + int minFnSize = ReKonfig::minFontSize(); + + QFont standardFont = ReKonfig::standardFont(); + defaultSettings->setFontFamily(QWebSettings::StandardFont, standardFont.family()); + defaultSettings->setFontSize(QWebSettings::DefaultFontSize, fnSize); + defaultSettings->setFontSize(QWebSettings::MinimumFontSize, minFnSize); + + QFont fixedFont = ReKonfig::fixedFont(); + defaultSettings->setFontFamily(QWebSettings::FixedFont, fixedFont.family()); + defaultSettings->setFontSize(QWebSettings::DefaultFixedFontSize, fnSize); + + // ================ WebKit ============================ + defaultSettings->setAttribute(QWebSettings::AutoLoadImages, ReKonfig::autoLoadImages()); + defaultSettings->setAttribute(QWebSettings::DnsPrefetchEnabled, ReKonfig::dnsPrefetch()); + defaultSettings->setAttribute(QWebSettings::JavascriptEnabled, ReKonfig::javascriptEnabled()); + defaultSettings->setAttribute(QWebSettings::JavaEnabled, ReKonfig::javaEnabled()); + defaultSettings->setAttribute(QWebSettings::JavascriptCanOpenWindows, ReKonfig::javascriptCanOpenWindows()); + defaultSettings->setAttribute(QWebSettings::JavascriptCanAccessClipboard, ReKonfig::javascriptCanAccessClipboard()); + defaultSettings->setAttribute(QWebSettings::LinksIncludedInFocusChain, ReKonfig::linksIncludedInFocusChain()); + defaultSettings->setAttribute(QWebSettings::ZoomTextOnly, ReKonfig::zoomTextOnly()); + defaultSettings->setAttribute(QWebSettings::PrintElementBackgrounds, ReKonfig::printElementBackgrounds()); + + if(ReKonfig::pluginsEnabled() == 2) + defaultSettings->setAttribute(QWebSettings::PluginsEnabled, false); + else + defaultSettings->setAttribute(QWebSettings::PluginsEnabled, true); + + // ===== HTML 5 features WebKit support ====== + defaultSettings->setAttribute(QWebSettings::OfflineStorageDatabaseEnabled, ReKonfig::offlineStorageDatabaseEnabled()); + defaultSettings->setAttribute(QWebSettings::OfflineWebApplicationCacheEnabled, ReKonfig::offlineWebApplicationCacheEnabled()); + defaultSettings->setAttribute(QWebSettings::LocalStorageEnabled, ReKonfig::localStorageEnabled()); + if(ReKonfig::localStorageEnabled()) + { + QString path = KStandardDirs::locateLocal("cache", QString("WebkitLocalStorage/rekonq"), true); + path.remove("rekonq"); + QWebSettings::setOfflineStoragePath(path); + QWebSettings::setOfflineStorageDefaultQuota(50000); + } + + // Applies user defined CSS to all open webpages. If there no longer is a + // user defined CSS removes it from all open webpages. + if(ReKonfig::userCSS().isEmpty()) + defaultSettings->setUserStyleSheetUrl( KUrl(KStandardDirs::locate("appdata" , "default.css")) ); + else + defaultSettings->setUserStyleSheetUrl(ReKonfig::userCSS()); + + // ====== load Settings on main classes + Application::historyManager()->loadSettings(); + Application::adblockManager()->loadSettings(); + + defaultSettings = 0; +} diff --git a/src/application.h b/src/application.h index fe3c50c1..87d395eb 100644 --- a/src/application.h +++ b/src/application.h @@ -136,6 +136,8 @@ private slots: void loadResolvedUrl(ThreadWeaver::Job *); + void updateConfiguration(); + private: static QWeakPointer<HistoryManager> s_historyManager; static QWeakPointer<BookmarkProvider> s_bookmarkProvider; diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index fe00ee7e..03a6194a 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -113,9 +113,6 @@ MainWindow::MainWindow() // enable window size "auto-save" setAutoSaveSettings(); - // updating rekonq configuration - updateConfiguration(); - // creating a centralWidget containing panel, m_view and the hidden findbar QWidget *centralWidget = new QWidget; centralWidget->setContentsMargins(0, 0, 0, 0); @@ -543,76 +540,6 @@ void MainWindow::setupPanels() } - -void MainWindow::updateConfiguration() -{ - // ============== General ================== - m_view->updateTabBar(); - - // ============== Tabs ================== - if (ReKonfig::closeTabSelectPrevious()) - m_view->tabBar()->setSelectionBehaviorOnRemove(QTabBar::SelectPreviousTab); - else - m_view->tabBar()->setSelectionBehaviorOnRemove(QTabBar::SelectRightTab); - - // =========== Fonts ============== - QWebSettings *defaultSettings = QWebSettings::globalSettings(); - - int fnSize = ReKonfig::fontSize(); - int minFnSize = ReKonfig::minFontSize(); - - QFont standardFont = ReKonfig::standardFont(); - defaultSettings->setFontFamily(QWebSettings::StandardFont, standardFont.family()); - defaultSettings->setFontSize(QWebSettings::DefaultFontSize, fnSize); - defaultSettings->setFontSize(QWebSettings::MinimumFontSize, minFnSize); - - QFont fixedFont = ReKonfig::fixedFont(); - defaultSettings->setFontFamily(QWebSettings::FixedFont, fixedFont.family()); - defaultSettings->setFontSize(QWebSettings::DefaultFixedFontSize, fnSize); - - // ================ WebKit ============================ - defaultSettings->setAttribute(QWebSettings::AutoLoadImages, ReKonfig::autoLoadImages()); - defaultSettings->setAttribute(QWebSettings::DnsPrefetchEnabled, ReKonfig::dnsPrefetch()); - defaultSettings->setAttribute(QWebSettings::JavascriptEnabled, ReKonfig::javascriptEnabled()); - defaultSettings->setAttribute(QWebSettings::JavaEnabled, ReKonfig::javaEnabled()); - defaultSettings->setAttribute(QWebSettings::JavascriptCanOpenWindows, ReKonfig::javascriptCanOpenWindows()); - defaultSettings->setAttribute(QWebSettings::JavascriptCanAccessClipboard, ReKonfig::javascriptCanAccessClipboard()); - defaultSettings->setAttribute(QWebSettings::LinksIncludedInFocusChain, ReKonfig::linksIncludedInFocusChain()); - defaultSettings->setAttribute(QWebSettings::ZoomTextOnly, ReKonfig::zoomTextOnly()); - defaultSettings->setAttribute(QWebSettings::PrintElementBackgrounds, ReKonfig::printElementBackgrounds()); - - if(ReKonfig::pluginsEnabled() == 2) - defaultSettings->setAttribute(QWebSettings::PluginsEnabled, false); - else - defaultSettings->setAttribute(QWebSettings::PluginsEnabled, true); - - // ===== HTML 5 features WebKit support ====== - defaultSettings->setAttribute(QWebSettings::OfflineStorageDatabaseEnabled, ReKonfig::offlineStorageDatabaseEnabled()); - defaultSettings->setAttribute(QWebSettings::OfflineWebApplicationCacheEnabled, ReKonfig::offlineWebApplicationCacheEnabled()); - defaultSettings->setAttribute(QWebSettings::LocalStorageEnabled, ReKonfig::localStorageEnabled()); - if(ReKonfig::localStorageEnabled()) - { - QString path = KStandardDirs::locateLocal("cache", QString("WebkitLocalStorage/rekonq"), true); - path.remove("rekonq"); - QWebSettings::setOfflineStoragePath(path); - QWebSettings::setOfflineStorageDefaultQuota(50000); - } - - // Applies user defined CSS to all open webpages. If there no longer is a - // user defined CSS removes it from all open webpages. - if(ReKonfig::userCSS().isEmpty()) - defaultSettings->setUserStyleSheetUrl( KUrl(KStandardDirs::locate("appdata" , "default.css")) ); - else - defaultSettings->setUserStyleSheetUrl(ReKonfig::userCSS()); - - // ====== load Settings on main classes - Application::historyManager()->loadSettings(); - Application::adblockManager()->loadSettings(); - - defaultSettings = 0; -} - - void MainWindow::openLocation() { m_view->urlBar()->selectAll(); @@ -649,7 +576,7 @@ void MainWindow::preferences() QPointer<SettingsDialog> s = new SettingsDialog(this); // keep us informed when the user changes settings - connect(s, SIGNAL(settingsChanged(const QString&)), this, SLOT(updateConfiguration())); + connect(s, SIGNAL(settingsChanged(const QString&)), Application::instance(), SLOT(updateConfiguration())); s->exec(); delete s; diff --git a/src/mainwindow.h b/src/mainwindow.h index d1509066..5c525e26 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -116,7 +116,6 @@ protected: private slots: void postLaunch(); - void updateConfiguration(); void browserLoading(bool); void updateActions(); void updateWindowTitle(const QString &title = QString()); diff --git a/src/networkaccessmanager.cpp b/src/networkaccessmanager.cpp index 99337206..15a71317 100644 --- a/src/networkaccessmanager.cpp +++ b/src/networkaccessmanager.cpp @@ -36,53 +36,65 @@ // KDE Includes #include <KDebug> +#include <KLocale> +#include <KProtocolManager> + +// Defines +#define QL1S(x) QLatin1String(x) NetworkAccessManager::NetworkAccessManager(QObject *parent) : AccessManager(parent) - , _parentPage( qobject_cast<WebPage *>(parent) ) { + QString c = KGlobal::locale()->country(); + if(c == QL1S("C")) + c = QL1S("en_US"); + if(c != QL1S("en_US")) + c.append( QL1S(", en_US") ); + + _acceptLanguage = c.toLatin1(); } -QNetworkReply *NetworkAccessManager::createRequest(Operation op, const QNetworkRequest &req, QIODevice *outgoingData) +QNetworkReply *NetworkAccessManager::createRequest(Operation op, const QNetworkRequest &request, QIODevice *outgoingData) { + WebPage *parentPage = qobject_cast<WebPage *>( parent() ); + QNetworkReply *reply = 0; - switch(op) + QNetworkRequest req = request; + req.setAttribute(QNetworkRequest::HttpPipeliningAllowedAttribute, true); + req.setRawHeader("Accept-Language", _acceptLanguage); + + KIO::CacheControl cc = KProtocolManager::cacheControl(); + switch(cc) { - case QNetworkAccessManager::HeadOperation: - kDebug() << "HEAD OPERATION"; -// if(outgoingData) -// { -// QByteArray outgoingDataByteArray = outgoingData->peek(1024 * 1024); -// kDebug() << outgoingDataByteArray; -// } - break; - - case QNetworkAccessManager::GetOperation: - kDebug() << "GET OPERATION"; - reply = Application::adblockManager()->block(req, _parentPage); - if (reply) - return reply; - break; - - case QNetworkAccessManager::PutOperation: - kDebug() << "PUT OPERATION"; - break; - - case QNetworkAccessManager::PostOperation: - kDebug() << "POST OPERATION"; + case KIO::CC_CacheOnly: // Fail request if not in cache. + req.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::AlwaysCache); break; - - case QNetworkAccessManager::DeleteOperation: - kDebug() << "DELETE OPERATION"; + + case KIO::CC_Refresh: // Always validate cached entry with remote site. + req.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferNetwork); break; + case KIO::CC_Reload: // Always fetch from remote site + req.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::AlwaysNetwork); + break; + + case KIO::CC_Cache: // Use cached entry if available. + case KIO::CC_Verify: // Validate cached entry with remote site if expired. default: - kDebug() << "UNKNOWN OPERATION"; + req.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache); break; } + + + if( op == QNetworkAccessManager::GetOperation ) + { + reply = Application::adblockManager()->block(req, parentPage); + if (reply) + return reply; + } return AccessManager::createRequest(op,req,outgoingData); } diff --git a/src/networkaccessmanager.h b/src/networkaccessmanager.h index 352f67d6..cc7d800d 100644 --- a/src/networkaccessmanager.h +++ b/src/networkaccessmanager.h @@ -48,10 +48,10 @@ public: NetworkAccessManager(QObject *parent); protected: - virtual QNetworkReply *createRequest(Operation op, const QNetworkRequest &req, QIODevice *outgoingData = 0); + virtual QNetworkReply *createRequest(Operation op, const QNetworkRequest &request, QIODevice *outgoingData = 0); private: - WebPage *_parentPage; + QByteArray _acceptLanguage; }; #endif // NETWORKACCESSMANAGER_H diff --git a/src/webpage.cpp b/src/webpage.cpp index b6f26f19..021856f7 100644 --- a/src/webpage.cpp +++ b/src/webpage.cpp @@ -148,6 +148,8 @@ WebPage::~WebPage() bool WebPage::acceptNavigationRequest(QWebFrame *frame, const QNetworkRequest &request, NavigationType type) { + _loadingUrl = request.url(); + KIO::AccessManager *manager = qobject_cast<KIO::AccessManager*>(networkAccessManager()); KIO::MetaData metaData = manager->requestMetaData(); @@ -308,8 +310,13 @@ void WebPage::handleUnsupportedContent(QNetworkReply *reply) } -void WebPage::loadFinished(bool) +void WebPage::loadFinished(bool ok) { + kDebug() << "==========================="; + kDebug() << ok; + kDebug() << mainFrame()->url(); + kDebug() << "==========================="; + Application::adblockManager()->applyHidingRules(this); QStringList list = ReKonfig::walletBlackList(); @@ -327,7 +334,7 @@ void WebPage::loadFinished(bool) void WebPage::manageNetworkErrors(QNetworkReply *reply) { Q_ASSERT(reply); - WebView *v = 0; + QWebFrame* frame = qobject_cast<QWebFrame *>(reply->request().originatingObject()); const bool isMainFrameRequest = (frame == mainFrame()); @@ -355,7 +362,6 @@ void WebPage::manageNetworkErrors(QNetworkReply *reply) break; case QNetworkReply::UnknownNetworkError: // unknown network-related error detected - if( _protHandler.postHandling(reply->request(), mainFrame()) ) break; @@ -373,13 +379,8 @@ void WebPage::manageNetworkErrors(QNetworkReply *reply) case QNetworkReply::ProtocolUnknownError: // Unknown protocol case QNetworkReply::ProtocolInvalidOperationError: // requested operation is invalid for this protocol - // don't bother on elements loading errors: - // we'll manage just main url page ones - v = qobject_cast<WebView *>(view()); - if( reply->url() != v->url() ) - break; - - mainFrame()->setHtml( errorPage(reply), reply->url() ); + if(reply->url() == _loadingUrl) + mainFrame()->setHtml( errorPage(reply), reply->url() ); break; default: diff --git a/src/webpage.h b/src/webpage.h index dcd40cf6..7c1ac2a5 100644 --- a/src/webpage.h +++ b/src/webpage.h @@ -80,6 +80,7 @@ private slots: private: QString errorPage(QNetworkReply *); + QUrl _loadingUrl; ProtocolHandler _protHandler; WebSslInfo _sslInfo; |