From d9461f348f10c038e4d0914fdcc7206c5cf48bb6 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Sun, 12 Aug 2018 23:29:26 +0800 Subject: [PATCH 1/2] Generate i18n .ts files in the correct directory Fixup 5b7c089dd2fce88017fcdc5911801fc809175c0d. Closes #9313. --- src/lang/lang.pri | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/lang/lang.pri b/src/lang/lang.pri index e08a6a20a..30d5b7106 100644 --- a/src/lang/lang.pri +++ b/src/lang/lang.pri @@ -1,5 +1,10 @@ -TRANSLATIONS += $$files(qbittorrent_*.ts) -TS_IN_NOEXT = $$replace(TRANSLATIONS,".ts","") +TS_FILES += $$files(qbittorrent_*.ts) + +# need to use full path, otherwise running +# `lupdate` will generate *.ts files in project root directory +for(file, TS_FILES) { + TRANSLATIONS += "$${PWD}/$${file}" +} isEmpty(QMAKE_LRELEASE) { win32:QMAKE_LRELEASE = $$[QT_INSTALL_BINS]\\lrelease.exe @@ -14,8 +19,9 @@ isEmpty(QMAKE_LRELEASE) { } message("Building translations") -for(L,TS_IN_NOEXT) { - message("Processing $${L}") - system("$$QMAKE_LRELEASE -silent $${L}.ts -qm $${L}.qm") - !exists("$${L}.qm"):error("Building translations failed, cannot continue") +TS_FILES_NOEXT = $$replace(TS_FILES, ".ts", "") +for(file, TS_FILES_NOEXT) { + message("Processing $${file}") + system("$$QMAKE_LRELEASE -silent $${file}.ts -qm $${file}.qm") + !exists("$${file}.qm"):error("Building translations failed, cannot continue") } From 6f2b1823ad399ad73aa42f4af55de656ea7deec5 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Sun, 12 Aug 2018 23:44:12 +0800 Subject: [PATCH 2/2] Fix lupdate errors I suspect lupdate isn't smart enough to figure out what tr() is suppose to do, so just make it a static function in class. The error was: tr() cannot be called without context --- src/base/net/downloadhandler.cpp | 104 ++++++++++++++----------------- src/base/net/downloadhandler.h | 5 +- 2 files changed, 50 insertions(+), 59 deletions(-) diff --git a/src/base/net/downloadhandler.cpp b/src/base/net/downloadhandler.cpp index 04b8500c2..7cce44e2a 100644 --- a/src/base/net/downloadhandler.cpp +++ b/src/base/net/downloadhandler.cpp @@ -34,7 +34,6 @@ #include #include #include -#include #include #include #include @@ -46,9 +45,6 @@ namespace { - QString tr(const char *message); - QString errorCodeToString(QNetworkReply::NetworkError status); - bool saveToFile(const QByteArray &replyData, QString &filePath) { QTemporaryFile tmpfile {Utils::Fs::tempPath() + "XXXXXX"}; @@ -203,60 +199,52 @@ void Net::DownloadHandler::handleRedirection(QUrl newUrl) } } -namespace +QString Net::DownloadHandler::errorCodeToString(const QNetworkReply::NetworkError status) { - QString tr(const char *message) - { - return QCoreApplication::translate("DownloadHandler", message); - } - - QString errorCodeToString(QNetworkReply::NetworkError status) - { - switch (status) { - case QNetworkReply::HostNotFoundError: - return tr("The remote host name was not found (invalid hostname)"); - case QNetworkReply::OperationCanceledError: - return tr("The operation was canceled"); - case QNetworkReply::RemoteHostClosedError: - return tr("The remote server closed the connection prematurely, before the entire reply was received and processed"); - case QNetworkReply::TimeoutError: - return tr("The connection to the remote server timed out"); - case QNetworkReply::SslHandshakeFailedError: - return tr("SSL/TLS handshake failed"); - case QNetworkReply::ConnectionRefusedError: - return tr("The remote server refused the connection"); - case QNetworkReply::ProxyConnectionRefusedError: - return tr("The connection to the proxy server was refused"); - case QNetworkReply::ProxyConnectionClosedError: - return tr("The proxy server closed the connection prematurely"); - case QNetworkReply::ProxyNotFoundError: - return tr("The proxy host name was not found"); - case QNetworkReply::ProxyTimeoutError: - return tr("The connection to the proxy timed out or the proxy did not reply in time to the request sent"); - case QNetworkReply::ProxyAuthenticationRequiredError: - return tr("The proxy requires authentication in order to honor the request but did not accept any credentials offered"); - case QNetworkReply::ContentAccessDenied: - return tr("The access to the remote content was denied (401)"); - case QNetworkReply::ContentOperationNotPermittedError: - return tr("The operation requested on the remote content is not permitted"); - case QNetworkReply::ContentNotFoundError: - return tr("The remote content was not found at the server (404)"); - case QNetworkReply::AuthenticationRequiredError: - return tr("The remote server requires authentication to serve the content but the credentials provided were not accepted"); - case QNetworkReply::ProtocolUnknownError: - return tr("The Network Access API cannot honor the request because the protocol is not known"); - case QNetworkReply::ProtocolInvalidOperationError: - return tr("The requested operation is invalid for this protocol"); - case QNetworkReply::UnknownNetworkError: - return tr("An unknown network-related error was detected"); - case QNetworkReply::UnknownProxyError: - return tr("An unknown proxy-related error was detected"); - case QNetworkReply::UnknownContentError: - return tr("An unknown error related to the remote content was detected"); - case QNetworkReply::ProtocolFailure: - return tr("A breakdown in protocol was detected"); - default: - return tr("Unknown error"); - } + switch (status) { + case QNetworkReply::HostNotFoundError: + return tr("The remote host name was not found (invalid hostname)"); + case QNetworkReply::OperationCanceledError: + return tr("The operation was canceled"); + case QNetworkReply::RemoteHostClosedError: + return tr("The remote server closed the connection prematurely, before the entire reply was received and processed"); + case QNetworkReply::TimeoutError: + return tr("The connection to the remote server timed out"); + case QNetworkReply::SslHandshakeFailedError: + return tr("SSL/TLS handshake failed"); + case QNetworkReply::ConnectionRefusedError: + return tr("The remote server refused the connection"); + case QNetworkReply::ProxyConnectionRefusedError: + return tr("The connection to the proxy server was refused"); + case QNetworkReply::ProxyConnectionClosedError: + return tr("The proxy server closed the connection prematurely"); + case QNetworkReply::ProxyNotFoundError: + return tr("The proxy host name was not found"); + case QNetworkReply::ProxyTimeoutError: + return tr("The connection to the proxy timed out or the proxy did not reply in time to the request sent"); + case QNetworkReply::ProxyAuthenticationRequiredError: + return tr("The proxy requires authentication in order to honor the request but did not accept any credentials offered"); + case QNetworkReply::ContentAccessDenied: + return tr("The access to the remote content was denied (401)"); + case QNetworkReply::ContentOperationNotPermittedError: + return tr("The operation requested on the remote content is not permitted"); + case QNetworkReply::ContentNotFoundError: + return tr("The remote content was not found at the server (404)"); + case QNetworkReply::AuthenticationRequiredError: + return tr("The remote server requires authentication to serve the content but the credentials provided were not accepted"); + case QNetworkReply::ProtocolUnknownError: + return tr("The Network Access API cannot honor the request because the protocol is not known"); + case QNetworkReply::ProtocolInvalidOperationError: + return tr("The requested operation is invalid for this protocol"); + case QNetworkReply::UnknownNetworkError: + return tr("An unknown network-related error was detected"); + case QNetworkReply::UnknownProxyError: + return tr("An unknown proxy-related error was detected"); + case QNetworkReply::UnknownContentError: + return tr("An unknown error related to the remote content was detected"); + case QNetworkReply::ProtocolFailure: + return tr("A breakdown in protocol was detected"); + default: + return tr("Unknown error"); } } diff --git a/src/base/net/downloadhandler.h b/src/base/net/downloadhandler.h index f750f1657..5d154fb38 100644 --- a/src/base/net/downloadhandler.h +++ b/src/base/net/downloadhandler.h @@ -30,10 +30,11 @@ #ifndef NET_DOWNLOADHANDLER_H #define NET_DOWNLOADHANDLER_H +#include #include + #include "downloadmanager.h" -class QNetworkReply; class QUrl; namespace Net @@ -68,6 +69,8 @@ namespace Net void assignNetworkReply(QNetworkReply *reply); void handleRedirection(QUrl newUrl); + static QString errorCodeToString(QNetworkReply::NetworkError status); + QNetworkReply *m_reply; DownloadManager *m_manager; const DownloadRequest m_downloadRequest;