Skip to content
This repository
Browse code

Use old method to find current URL in Qt < 4.8.0

  • Loading branch information...
commit f95e4ebe0b2711da1b776caebd89c72f9f09ef03 1 parent ecfa783
Matthew Horan authored October 22, 2012
16  src/CurrentUrl.cpp
@@ -6,8 +6,24 @@ CurrentUrl::CurrentUrl(WebPageManager *manager, QStringList &arguments, QObject
6 6
 }
7 7
 
8 8
 void CurrentUrl::start() {
  9
+#if QT_VERSION >= QT_VERSION_CHECK(4, 8, 0)
9 10
   QStringList arguments;
10 11
   QVariant result = page()->invokeCapybaraFunction("currentUrl", arguments);
11 12
   QString url = result.toString();
12 13
   emit finished(new Response(true, url));
  14
+#else
  15
+  QUrl humanUrl = wasRedirectedAndNotModifiedByJavascript() ?
  16
+    page()->currentFrame()->url() : page()->currentFrame()->requestedUrl();
  17
+  QByteArray encodedBytes = humanUrl.toEncoded();
  18
+  emit finished(new Response(true, encodedBytes));
13 19
 }
  20
+
  21
+bool CurrentUrl::wasRegularLoad() {
  22
+  return page()->currentFrame()->url() == page()->currentFrame()->requestedUrl();
  23
+}
  24
+
  25
+bool CurrentUrl::wasRedirectedAndNotModifiedByJavascript() {
  26
+  return !wasRegularLoad() && page()->currentFrame()->url() == page()->history()->currentItem().url();
  27
+#endif
  28
+}
  29
+
6  src/CurrentUrl.h
@@ -6,5 +6,11 @@ class CurrentUrl : public SocketCommand {
6 6
   public:
7 7
     CurrentUrl(WebPageManager *, QStringList &arguments, QObject *parent = 0);
8 8
     virtual void start();
  9
+#if QT_VERSION < QT_VERSION_CHECK(4, 8, 0)
  10
+
  11
+    private:
  12
+      bool wasRegularLoad();
  13
+      bool wasRedirectedAndNotModifiedByJavascript();
  14
+#endif
9 15
 };
10 16
 
1  src/WebPageManager.cpp
@@ -100,6 +100,7 @@ void WebPageManager::reset() {
100 100
   m_pages.first()->deleteLater();
101 101
   m_pages.clear();
102 102
   createPage(this)->setFocus();
  103
+  currentPage()->currentFrame()->setUrl(QUrl("about:blank"));
103 104
 }
104 105
 
105 106
 NetworkCookieJar *WebPageManager::cookieJar() {

0 notes on commit f95e4eb

Please sign in to comment.
Something went wrong with that request. Please try again.