From 04d4555b470a56f841ffa095b6abf7fbf0438c0b Mon Sep 17 00:00:00 2001 From: David Rosca Date: Wed, 21 Jan 2015 12:38:12 +0100 Subject: [PATCH] Don't duplicate convertUrlToText function in WebView --- src/lib/navigation/locationbar.cpp | 4 ++-- src/lib/navigation/locationbar.h | 3 ++- src/lib/webkit/webview.cpp | 21 +++------------------ 3 files changed, 7 insertions(+), 21 deletions(-) diff --git a/src/lib/navigation/locationbar.cpp b/src/lib/navigation/locationbar.cpp index 44b502786..939445591 100644 --- a/src/lib/navigation/locationbar.cpp +++ b/src/lib/navigation/locationbar.cpp @@ -210,11 +210,11 @@ LoadRequest LocationBar::createLoadRequest() const return req; } -QString LocationBar::convertUrlToText(const QUrl &url) const +QString LocationBar::convertUrlToText(const QUrl &url) { // It was most probably entered by user, so don't urlencode it if (url.scheme().isEmpty()) { - return url.toString(); + return QUrl::fromPercentEncoding(url.toEncoded()); } QString stringUrl = QzTools::urlEncodeQueryString(url); diff --git a/src/lib/navigation/locationbar.h b/src/lib/navigation/locationbar.h index 62c6c57d4..b2afb41e2 100644 --- a/src/lib/navigation/locationbar.h +++ b/src/lib/navigation/locationbar.h @@ -44,6 +44,8 @@ public: TabbedWebView* webView() const; void setWebView(TabbedWebView* view); + static QString convertUrlToText(const QUrl &url); + public slots: void setText(const QString &text); void showUrl(const QUrl &url); @@ -88,7 +90,6 @@ private: void paintEvent(QPaintEvent* event); LoadRequest createLoadRequest() const; - QString convertUrlToText(const QUrl &url) const; void refreshTextFormat(); LocationCompleter* m_completer; diff --git a/src/lib/webkit/webview.cpp b/src/lib/webkit/webview.cpp index 8e45d2540..0c04ac211 100644 --- a/src/lib/webkit/webview.cpp +++ b/src/lib/webkit/webview.cpp @@ -31,6 +31,7 @@ #include "settings.h" #include "qzsettings.h" #include "enhancedmenu.h" +#include "locationbar.h" #ifdef USE_HUNSPELL #include "qtwebkit/spellcheck/speller.h" @@ -129,27 +130,11 @@ bool WebView::isTitleEmpty() const return QWebView::title().isEmpty(); } -static QString convertUrlToText(const QUrl &url) -{ - // It was most probably entered by user, so don't urlencode it - if (url.scheme().isEmpty()) { - return url.toString(); - } - - QString stringUrl = QzTools::urlEncodeQueryString(url); - - if (stringUrl == QLatin1String("about:blank")) { - stringUrl.clear(); - } - - return stringUrl; -} - QUrl WebView::url() const { QUrl returnUrl = page()->url(); - if (convertUrlToText(returnUrl).isEmpty()) { + if (LocationBar::convertUrlToText(returnUrl).isEmpty()) { returnUrl = m_aboutToLoadUrl; } @@ -417,7 +402,7 @@ void WebView::reload() { m_isReloading = true; - if (convertUrlToText(QWebView::url()).isEmpty() && !m_aboutToLoadUrl.isEmpty()) { + if (LocationBar::convertUrlToText(QWebView::url()).isEmpty() && !m_aboutToLoadUrl.isEmpty()) { load(m_aboutToLoadUrl); return; }