changeset 666:98a7fbbe9d88 qt5

Merge from default branch, and build fixes
author Chris Cannam
date Fri, 27 May 2016 09:55:56 +0100
parents f9b805d8cab4 (diff) 88061103b878 (current diff)
children 0f3e086066fc
files easyhg.pro src/hgrunner.cpp
diffstat 6 files changed, 46 insertions(+), 37 deletions(-) [+]
line wrap: on
line diff
--- a/easyhg.pro	Wed Mar 23 14:49:49 2016 +0000
+++ b/easyhg.pro	Fri May 27 09:55:56 2016 +0100
@@ -5,7 +5,6 @@
 TARGET = EasyMercurial
 
 QT += widgets
-QMAKE_CXXFLAGS += -DQT_DISABLE_DEPRECATED_BEFORE=0x000000
 
 # We use the 10.5 SDK and Carbon for all 32-bit OS/X,
 # and 10.6 with Cocoa for all 64-bit. (Since EasyHg 1.2,
--- a/src/common.cpp	Wed Mar 23 14:49:49 2016 +0000
+++ b/src/common.cpp	Fri May 27 09:55:56 2016 +0100
@@ -299,7 +299,7 @@
         // chars: replace with Unicode character
         if (i+5 < s.length() && s[i] == '\\' && s[i+1] == 'u') {
             QString uni = s.mid(i+2, 4);
-            QByteArray ba = QByteArray::fromHex(uni.toAscii());
+            QByteArray ba = QByteArray::fromHex(uni.toLatin1());
             d += QChar(ba[1], ba[0]);
             i += 5;
             continue;
--- a/src/debug.cpp	Wed Mar 23 14:49:49 2016 +0000
+++ b/src/debug.cpp	Fri May 27 09:55:56 2016 +0100
@@ -25,7 +25,7 @@
 #include <QDir>
 #include <QCoreApplication>
 #include <QDateTime>
-#include <QDesktopServices>
+#include <QStandardPaths>
 
 #include <cstdio>
 
@@ -41,8 +41,8 @@
         prefix = new char[20];
         sprintf(prefix, "[%lu]", (unsigned long)QCoreApplication::applicationPid());
         QString logFileName = QDir::homePath() + "/.easyhg.log"; // the fallback
-        QString logDir = QDesktopServices::storageLocation
-            (QDesktopServices::DataLocation);
+        QString logDir = QStandardPaths::writableLocation
+            (QStandardPaths::DataLocation);
         if (logDir != "" &&
             (QDir(logDir).exists() ||
              QDir().mkpath(logDir))) {
--- a/src/hgrunner.cpp	Wed Mar 23 14:49:49 2016 +0000
+++ b/src/hgrunner.cpp	Fri May 27 09:55:56 2016 +0100
@@ -22,7 +22,7 @@
 
 #include <QSettings>
 #include <QInputDialog>
-#include <QDesktopServices>
+#include <QStandardPaths>
 #include <QTemporaryFile>
 #include <QDir>
 #include <QProgressBar>
@@ -411,7 +411,7 @@
             emit commandCompleted(completedAction, m_stdout);
         } else {
             DEBUG << "HgRunner::finished: Command failed, exit code "
-                  << procExitCode << ", exit status " << procExitStatus
+                  << procExitCode << ", exit status " << int(procExitStatus)
                   << ", stderr follows" << endl;
             DEBUG << m_stderr << endl;
             emit commandFailed(completedAction, m_stderr, m_stdout);
@@ -454,8 +454,8 @@
 
 void HgRunner::pruneOldAuthFiles()
 {
-    QString path = QDesktopServices::storageLocation
-        (QDesktopServices::CacheLocation);
+    QString path = QStandardPaths::writableLocation
+        (QStandardPaths::CacheLocation);
     QDir d(path);
     if (!d.exists()) return;
     QStringList filters;
@@ -489,8 +489,8 @@
         }
         QString fileExt16 = QString::fromLocal8Bit(fileExt.toBase64()).left(16)
             .replace('+', '-').replace('/', '_');
-        QString path = QDesktopServices::storageLocation
-            (QDesktopServices::CacheLocation);
+        QString path = QStandardPaths::writableLocation
+            (QStandardPaths::CacheLocation);
         QDir().mkpath(path);
         if (path == "") {
             DEBUG << "HgRunner::addExtensionOptions: Failed to get cache location" << endl;
--- a/src/versiontester.cpp	Wed Mar 23 14:49:49 2016 +0000
+++ b/src/versiontester.cpp	Fri May 27 09:55:56 2016 +0100
@@ -20,24 +20,30 @@
 
 #include <iostream>
 
-#include <QHttp>
+#include <QNetworkAccessManager>
+
+static QNetworkAccessManager nm;
 
 VersionTester::VersionTester(QString hostname, QString versionFilePath,
 			     QString myVersion) :
-    m_httpFailed(false),
-    m_myVersion(myVersion)
+    m_myVersion(myVersion),
+    m_reply(0),
+    m_httpFailed(false)
 {
-    QHttp *http = new QHttp();
-    connect(http, SIGNAL(responseHeaderReceived(const QHttpResponseHeader &)),
-            this, SLOT(httpResponseHeaderReceived(const QHttpResponseHeader &)));
-    connect(http, SIGNAL(done(bool)),
-            this, SLOT(httpDone(bool)));
-    http->setHost(hostname);
-    http->get(versionFilePath);
+    QUrl url(QString("http://%1/%2").arg(hostname).arg(versionFilePath));
+    std::cerr << "VersionTester: URL is " << url << std::endl;
+    m_reply = nm.get(QNetworkRequest(url));
+    connect(m_reply, SIGNAL(error(QNetworkReply::NetworkError)),
+            this, SLOT(error(QNetworkReply::NetworkError)));
+    connect(m_reply, SIGNAL(finished()), this, SLOT(finished()));
 }
 
 VersionTester::~VersionTester()
 {
+    if (m_reply) {
+        m_reply->abort();
+        m_reply->deleteLater();
+    }
 }
 
 bool
@@ -66,31 +72,35 @@
 }
 
 void
-VersionTester::httpResponseHeaderReceived(const QHttpResponseHeader &h)
+VersionTester::error(QNetworkReply::NetworkError)
 {
-    if (h.statusCode() / 100 != 2) m_httpFailed = true;
+    std::cerr << "VersionTester: error: " << m_reply->errorString() << std::endl;
+    m_httpFailed = true;
 }
 
 void
-VersionTester::httpDone(bool error)
+VersionTester::finished()
 {
-    QHttp *http = const_cast<QHttp *>(dynamic_cast<const QHttp *>(sender()));
-    if (!http) return;
-    http->deleteLater();
-    if (error || m_httpFailed) return;
+    m_reply->deleteLater();
+    if (m_httpFailed) return;
 
-    QByteArray responseData = http->readAll();
+    int status = m_reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
+    if (status / 100 != 2) {
+        std::cerr << "VersionTester: error: http status = " << status << std::endl;
+        return;
+    }
+
+    QByteArray responseData = m_reply->readAll();
     QString str = QString::fromUtf8(responseData.data());
     QStringList lines = str.split('\n', QString::SkipEmptyParts);
     if (lines.empty()) return;
 
     QString latestVersion = lines[0];
     DEBUG << "Comparing current version \"" << m_myVersion
-	  << "\" with latest version \"" << latestVersion
-	  << "\"" << endl;
+          << "\" with latest version \"" << latestVersion
+          << "\"" << endl;
     if (isVersionNewerThan(latestVersion, m_myVersion)) {
         emit newerVersionAvailable(latestVersion);
     }
 }
 
-
--- a/src/versiontester.h	Wed Mar 23 14:49:49 2016 +0000
+++ b/src/versiontester.h	Fri May 27 09:55:56 2016 +0100
@@ -21,8 +21,7 @@
 #include <QStringList>
 #include <QString>
 #include <QObject>
-
-class QHttpResponseHeader;
+#include <QNetworkReply>
 
 class VersionTester : public QObject
 {
@@ -38,12 +37,13 @@
     void newerVersionAvailable(QString);
 
 protected slots:
-    void httpResponseHeaderReceived(const QHttpResponseHeader &);
-    void httpDone(bool);
+    void finished();
+    void error(QNetworkReply::NetworkError);
 
 private:
+    QString m_myVersion;
+    QNetworkReply *m_reply;
     bool m_httpFailed;
-    QString m_myVersion;
 };
 
 #endif