From 69df8174b9815ac08da9f0359c63a3b1041240e1 Mon Sep 17 00:00:00 2001 From: "Vladimir Golovnev (Glassez)" Date: Wed, 13 Dec 2017 17:20:55 +0300 Subject: [PATCH 1/4] Allow to load TorrentInfo from data buffer --- src/base/bittorrent/torrentinfo.cpp | 27 ++++++++++++++++++--------- src/base/bittorrent/torrentinfo.h | 4 ++-- src/gui/addnewtorrentdialog.cpp | 2 +- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/base/bittorrent/torrentinfo.cpp b/src/base/bittorrent/torrentinfo.cpp index ca6976b85225..950d772c3005 100644 --- a/src/base/bittorrent/torrentinfo.cpp +++ b/src/base/bittorrent/torrentinfo.cpp @@ -60,23 +60,32 @@ TorrentInfo &TorrentInfo::operator=(const TorrentInfo &other) return *this; } -TorrentInfo TorrentInfo::loadFromFile(const QString &path, QString &error) +TorrentInfo TorrentInfo::load(const QByteArray &data, QString *error) noexcept { - error.clear(); libt::error_code ec; - TorrentInfo info(NativePtr(new libt::torrent_info(Utils::Fs::toNativePath(path).toStdString(), ec))); - if (ec) { - error = QString::fromUtf8(ec.message().c_str()); - qDebug("Cannot load .torrent file: %s", qUtf8Printable(error)); + TorrentInfo info(NativePtr(new libt::torrent_info(data.constData(), data.size(), ec))); + if (error) { + if (ec) + *error = QString::fromStdString(ec.message()); + else + error->clear(); } return info; } -TorrentInfo TorrentInfo::loadFromFile(const QString &path) +TorrentInfo TorrentInfo::loadFromFile(const QString &path, QString *error) noexcept { - QString error; - return loadFromFile(path, error); + libt::error_code ec; + TorrentInfo info(NativePtr(new libt::torrent_info(Utils::Fs::toNativePath(path).toStdString(), ec))); + if (error) { + if (ec) + *error = QString::fromStdString(ec.message()); + else + error->clear(); + } + + return info; } bool TorrentInfo::isValid() const diff --git a/src/base/bittorrent/torrentinfo.h b/src/base/bittorrent/torrentinfo.h index 6730d2f11d05..cb40c392772a 100644 --- a/src/base/bittorrent/torrentinfo.h +++ b/src/base/bittorrent/torrentinfo.h @@ -63,8 +63,8 @@ namespace BitTorrent explicit TorrentInfo(NativeConstPtr nativeInfo = NativeConstPtr()); TorrentInfo(const TorrentInfo &other); - static TorrentInfo loadFromFile(const QString &path, QString &error); - static TorrentInfo loadFromFile(const QString &path); + static TorrentInfo load(const QByteArray &data, QString *error = nullptr) noexcept; + static TorrentInfo loadFromFile(const QString &path, QString *error = nullptr) noexcept; TorrentInfo &operator=(const TorrentInfo &other); diff --git a/src/gui/addnewtorrentdialog.cpp b/src/gui/addnewtorrentdialog.cpp index 4f2c7250c03e..0af079e49967 100644 --- a/src/gui/addnewtorrentdialog.cpp +++ b/src/gui/addnewtorrentdialog.cpp @@ -286,7 +286,7 @@ bool AddNewTorrentDialog::loadTorrent(const QString &torrentPath) m_hasMetadata = true; QString error; - m_torrentInfo = BitTorrent::TorrentInfo::loadFromFile(m_filePath, error); + m_torrentInfo = BitTorrent::TorrentInfo::loadFromFile(m_filePath, &error); if (!m_torrentInfo.isValid()) { MessageBoxRaised::critical(this, tr("Invalid torrent"), tr("Failed to load the torrent: %1.\nError: %2", "Don't remove the '\n' characters. They insert a newline.").arg(Utils::Fs::toNativePath(m_filePath)).arg(error)); return false; From bb683bd39391e2bb1d97f56363eca48cb74fd890 Mon Sep 17 00:00:00 2001 From: "Vladimir Golovnev (Glassez)" Date: Thu, 2 Nov 2017 12:14:27 +0300 Subject: [PATCH 2/4] Switch built-in Web UI html to HTML5 --- src/base/http/types.h | 14 +++++++---- src/webui/abstractwebapplication.cpp | 6 ++--- src/webui/www/private/index.html | 16 ++++++------- src/webui/www/private/login.html | 6 ++--- src/webui/www/public/about.html | 2 +- src/webui/www/public/addtrackers.html | 8 +++---- src/webui/www/public/confirmdeletion.html | 4 ++-- src/webui/www/public/download.html | 24 +++++++++---------- src/webui/www/public/downloadlimit.html | 4 ++-- src/webui/www/public/filters.html | 18 +++++++------- src/webui/www/public/newcategory.html | 4 ++-- src/webui/www/public/preferences.html | 4 ++-- src/webui/www/public/preferences_content.html | 10 ++++---- src/webui/www/public/properties_content.html | 4 ++-- src/webui/www/public/rename.html | 4 ++-- src/webui/www/public/scripts/client.js | 10 ++++++-- src/webui/www/public/setlocation.html | 4 ++-- src/webui/www/public/upload.html | 18 +++++++------- src/webui/www/public/uploadlimit.html | 4 ++-- 19 files changed, 86 insertions(+), 78 deletions(-) diff --git a/src/base/http/types.h b/src/base/http/types.h index 9c8ea535ee63..b7d5c9586962 100644 --- a/src/base/http/types.h +++ b/src/base/http/types.h @@ -37,6 +37,9 @@ namespace Http { + const char METHOD_GET[] = "GET"; + const char METHOD_POST[] = "POST"; + const char HEADER_CACHE_CONTROL[] = "cache-control"; const char HEADER_CONTENT_ENCODING[] = "content-encoding"; const char HEADER_CONTENT_LENGTH[] = "content-length"; @@ -52,13 +55,14 @@ namespace Http const char HEADER_X_FRAME_OPTIONS[] = "x-frame-options"; const char HEADER_X_XSS_PROTECTION[] = "x-xss-protection"; - const char CONTENT_TYPE_CSS[] = "text/css; charset=UTF-8"; - const char CONTENT_TYPE_GIF[] = "image/gif"; - const char CONTENT_TYPE_HTML[] = "text/html; charset=UTF-8"; - const char CONTENT_TYPE_JS[] = "application/javascript; charset=UTF-8"; + const char CONTENT_TYPE_HTML[] = "text/html"; + const char CONTENT_TYPE_JS[] = "application/javascript"; const char CONTENT_TYPE_JSON[] = "application/json"; + const char CONTENT_TYPE_BMP[] = "image/bmp"; + const char CONTENT_TYPE_GIF[] = "image/gif"; + const char CONTENT_TYPE_JPEG[] = "image/jpeg"; const char CONTENT_TYPE_PNG[] = "image/png"; - const char CONTENT_TYPE_TXT[] = "text/plain; charset=UTF-8"; + const char CONTENT_TYPE_TXT[] = "text/plain"; const char CONTENT_TYPE_SVG[] = "image/svg+xml"; // portability: "\r\n" doesn't guarantee mapping to the correct value diff --git a/src/webui/abstractwebapplication.cpp b/src/webui/abstractwebapplication.cpp index d855bab0f2de..1be2e73ad310 100644 --- a/src/webui/abstractwebapplication.cpp +++ b/src/webui/abstractwebapplication.cpp @@ -225,9 +225,6 @@ bool AbstractWebApplication::readFile(const QString& path, QByteArray &data, QSt QString dataStr = QString::fromUtf8(data.constData()); translateDocument(dataStr); - if (path.endsWith("about.html") || path.endsWith("index.html") || path.endsWith("client.js")) - dataStr.replace("${VERSION}", QBT_VERSION); - data = dataStr.toUtf8(); translatedFiles_[path] = data; // cashing translated file } @@ -296,6 +293,9 @@ void AbstractWebApplication::translateDocument(QString& data) else { found = false; // no more translatable strings } + + data.replace(QLatin1String("${LANG}"), locale.left(2)); + data.replace(QLatin1String("${VERSION}"), QBT_VERSION); } } diff --git a/src/webui/www/private/index.html b/src/webui/www/private/index.html index 5741cbed4a7f..9c8d85f32332 100644 --- a/src/webui/www/private/index.html +++ b/src/webui/www/private/index.html @@ -1,8 +1,8 @@ - - + + - + qBittorrent ${VERSION} QBT_TR(Web UI)QBT_TR[CONTEXT=OptionsDialog] @@ -50,12 +50,10 @@

qBittorrent Web User Interface QBT_TR(&Resume)QBT_TR[CONTEXT=MainWindow]QBT_TR(&Resume)QBT_TR[CONTEXT=MainWindow]
  • QBT_TR(&Pause)QBT_TR[CONTEXT=MainWindow]QBT_TR(&Pause)QBT_TR[CONTEXT=MainWindow]
  • QBT_TR(&Delete)QBT_TR[CONTEXT=MainWindow]QBT_TR(&Delete)QBT_TR[CONTEXT=MainWindow]
  • - -
  • QBT_TR(Top Priority)QBT_TR[CONTEXT=MainWindow]QBT_TR(Top Priority)QBT_TR[CONTEXT=MainWindow]
  • -
  • QBT_TR(Increase Priority)QBT_TR[CONTEXT=MainWindow]QBT_TR(Increase Priority)QBT_TR[CONTEXT=MainWindow]
  • -
  • QBT_TR(Decrease Priority)QBT_TR[CONTEXT=MainWindow]QBT_TR(Decrease Priority)QBT_TR[CONTEXT=MainWindow]
  • -
  • QBT_TR(Minimum Priority)QBT_TR[CONTEXT=MainWindow]QBT_TR(Minimum Priority)QBT_TR[CONTEXT=MainWindow]
  • -
    +
  • QBT_TR(Top Priority)QBT_TR[CONTEXT=MainWindow]QBT_TR(Top Priority)QBT_TR[CONTEXT=MainWindow]
  • +
  • QBT_TR(Increase Priority)QBT_TR[CONTEXT=MainWindow]QBT_TR(Increase Priority)QBT_TR[CONTEXT=MainWindow]
  • +
  • QBT_TR(Decrease Priority)QBT_TR[CONTEXT=MainWindow]QBT_TR(Decrease Priority)QBT_TR[CONTEXT=MainWindow]
  • +
  • QBT_TR(Minimum Priority)QBT_TR[CONTEXT=MainWindow]QBT_TR(Minimum Priority)QBT_TR[CONTEXT=MainWindow]
  • QBT_TR(Force Recheck)QBT_TR[CONTEXT=TransferListWidget]QBT_TR(Force recheck)QBT_TR[CONTEXT=TransferListWidget]
  • diff --git a/src/webui/www/private/login.html b/src/webui/www/private/login.html index 6be455edde69..5eb115b5ad69 100644 --- a/src/webui/www/private/login.html +++ b/src/webui/www/private/login.html @@ -1,5 +1,5 @@ - - + + qBittorrent QBT_TR(Web UI)QBT_TR[CONTEXT=OptionsDialog] @@ -74,7 +74,7 @@

    qBittorrent QBT_TR(Web UI)QBT_TR[CONTEXT=OptionsDialog]

    qBittorrent logo
    -
    +


    diff --git a/src/webui/www/public/about.html b/src/webui/www/public/about.html index 84ee00ac9867..4d976d6cf2d9 100644 --- a/src/webui/www/public/about.html +++ b/src/webui/www/public/about.html @@ -1,4 +1,4 @@ - +qBittorrent Mascot

    qBittorrent ${VERSION} QBT_TR(Web UI)QBT_TR[CONTEXT=OptionsDialog]

    QBT_TR(An advanced BitTorrent client programmed in C++, based on Qt toolkit and libtorrent-rasterbar.)QBT_TR[CONTEXT=about]

    Copyright (c) 2011-2018 The qBittorrent project

    diff --git a/src/webui/www/public/addtrackers.html b/src/webui/www/public/addtrackers.html index c2f988571aa5..0d9d958dbeb1 100644 --- a/src/webui/www/public/addtrackers.html +++ b/src/webui/www/public/addtrackers.html @@ -1,5 +1,5 @@ - - + + QBT_TR(Trackers addition dialog)QBT_TR[CONTEXT=TrackersAdditionDlg] @@ -25,12 +25,12 @@ -
    +

    QBT_TR(List of trackers to add (one per line):)QBT_TR[CONTEXT=TrackersAdditionDlg]


    -
    +
    diff --git a/src/webui/www/public/confirmdeletion.html b/src/webui/www/public/confirmdeletion.html index 4640b03aa48a..420cf6855442 100644 --- a/src/webui/www/public/confirmdeletion.html +++ b/src/webui/www/public/confirmdeletion.html @@ -1,5 +1,5 @@ - - + + QBT_TR(Deletion confirmation - qBittorrent)QBT_TR[CONTEXT=confirmDeletionDlg] diff --git a/src/webui/www/public/download.html b/src/webui/www/public/download.html index 267c892531ba..09c0b10bcec0 100644 --- a/src/webui/www/public/download.html +++ b/src/webui/www/public/download.html @@ -1,5 +1,5 @@ - - + + QBT_TR(Add Torrent Links)QBT_TR[CONTEXT=downloadFromURL] @@ -11,7 +11,7 @@ -
    +

    QBT_TR(Download Torrents from their URLs or Magnet links)QBT_TR[CONTEXT=HttpServer]

    @@ -27,7 +27,7 @@

    QBT_TR(Download Torrents from their URLs or Magnet links)QBT

    - +
    @@ -40,33 +40,33 @@

    QBT_TR(Download Torrents from their URLs or Magnet links)QBT

    - +
    - -
    +
    - +
    - +
    - +
    - +
    -
    + +