From cc563d9f786c1d594c31a26a0a60538919859437 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Sun, 10 Dec 2023 23:07:29 +0800 Subject: [PATCH] Fix incorrect usage of translation functions PR #20107. --- src/base/bittorrent/torrentimpl.cpp | 86 ++++++++++++------------ src/gui/trackerlist/trackerlistmodel.cpp | 34 +++++----- src/gui/uithemedialog.cpp | 2 + src/gui/uithemesource.h | 4 ++ 4 files changed, 67 insertions(+), 59 deletions(-) diff --git a/src/base/bittorrent/torrentimpl.cpp b/src/base/bittorrent/torrentimpl.cpp index 1c7bc88f2..c7ed105a5 100644 --- a/src/base/bittorrent/torrentimpl.cpp +++ b/src/base/bittorrent/torrentimpl.cpp @@ -1767,53 +1767,55 @@ void TorrentImpl::endReceivedMetadataHandling(const Path &savePath, const PathLi } void TorrentImpl::reload() -try { - m_completedFiles.fill(false); - m_filesProgress.fill(0); - m_pieces.fill(false); - m_nativeStatus.pieces.clear_all(); - m_nativeStatus.num_pieces = 0; - - const auto queuePos = m_nativeHandle.queue_position(); - - m_nativeSession->remove_torrent(m_nativeHandle, lt::session::delete_partfile); - - lt::add_torrent_params p = m_ltAddTorrentParams; - p.flags |= lt::torrent_flags::update_subscribe - | lt::torrent_flags::override_trackers - | lt::torrent_flags::override_web_seeds; - - if (m_isStopped) + try { - p.flags |= lt::torrent_flags::paused; - p.flags &= ~lt::torrent_flags::auto_managed; + m_completedFiles.fill(false); + m_filesProgress.fill(0); + m_pieces.fill(false); + m_nativeStatus.pieces.clear_all(); + m_nativeStatus.num_pieces = 0; + + const auto queuePos = m_nativeHandle.queue_position(); + + m_nativeSession->remove_torrent(m_nativeHandle, lt::session::delete_partfile); + + lt::add_torrent_params p = m_ltAddTorrentParams; + p.flags |= lt::torrent_flags::update_subscribe + | lt::torrent_flags::override_trackers + | lt::torrent_flags::override_web_seeds; + + if (m_isStopped) + { + p.flags |= lt::torrent_flags::paused; + p.flags &= ~lt::torrent_flags::auto_managed; + } + else if (m_operatingMode == TorrentOperatingMode::AutoManaged) + { + p.flags |= (lt::torrent_flags::auto_managed | lt::torrent_flags::paused); + } + else + { + p.flags &= ~(lt::torrent_flags::auto_managed | lt::torrent_flags::paused); + } + + auto *const extensionData = new ExtensionData; + p.userdata = LTClientData(extensionData); + m_nativeHandle = m_nativeSession->add_torrent(p); + + m_nativeStatus = extensionData->status; + + if (queuePos >= lt::queue_position_t {}) + m_nativeHandle.queue_position_set(queuePos); + m_nativeStatus.queue_position = queuePos; + + updateState(); } - else if (m_operatingMode == TorrentOperatingMode::AutoManaged) + catch (const lt::system_error &err) { - p.flags |= (lt::torrent_flags::auto_managed | lt::torrent_flags::paused); + throw RuntimeError(tr("Failed to reload torrent. Torrent: %1. Reason: %2") + .arg(id().toString(), QString::fromLocal8Bit(err.what()))); } - else - { - p.flags &= ~(lt::torrent_flags::auto_managed | lt::torrent_flags::paused); - } - - auto *const extensionData = new ExtensionData; - p.userdata = LTClientData(extensionData); - m_nativeHandle = m_nativeSession->add_torrent(p); - - m_nativeStatus = extensionData->status; - - if (queuePos >= lt::queue_position_t {}) - m_nativeHandle.queue_position_set(queuePos); - m_nativeStatus.queue_position = queuePos; - - updateState(); -} -catch (const lt::system_error &err) -{ - throw RuntimeError(tr("Failed to reload torrent. Torrent: %1. Reason: %2") - .arg(id().toString(), QString::fromLocal8Bit(err.what()))); } void TorrentImpl::pause() diff --git a/src/gui/trackerlist/trackerlistmodel.cpp b/src/gui/trackerlist/trackerlistmodel.cpp index 3ac377327..4b4c6e42b 100644 --- a/src/gui/trackerlist/trackerlistmodel.cpp +++ b/src/gui/trackerlist/trackerlistmodel.cpp @@ -54,14 +54,14 @@ using namespace std::chrono_literals; using namespace boost::multi_index; -const std::chrono::milliseconds ANNOUNCE_TIME_REFRESH_INTERVAL = 4s; - namespace { - const QString STR_WORKING = TrackerListModel::tr("Working"); - const QString STR_DISABLED = TrackerListModel::tr("Disabled"); - const QString STR_TORRENT_DISABLED = TrackerListModel::tr("Disabled for this torrent"); - const QString STR_PRIVATE_MSG = TrackerListModel::tr("This torrent is private"); + const std::chrono::milliseconds ANNOUNCE_TIME_REFRESH_INTERVAL = 4s; + + const char STR_WORKING[] = QT_TRANSLATE_NOOP("TrackerListModel", "Working"); + const char STR_DISABLED[] = QT_TRANSLATE_NOOP("TrackerListModel", "Disabled"); + const char STR_TORRENT_DISABLED[] = QT_TRANSLATE_NOOP("TrackerListModel", "Disabled for this torrent"); + const char STR_PRIVATE_MSG[] = QT_TRANSLATE_NOOP("TrackerListModel", "This torrent is private"); QString prettyCount(const int val) { @@ -73,7 +73,7 @@ namespace switch (status) { case BitTorrent::TrackerEntryStatus::Working: - return TrackerListModel::tr("Working"); + return TrackerListModel::tr(STR_WORKING); case BitTorrent::TrackerEntryStatus::Updating: return TrackerListModel::tr("Updating..."); case BitTorrent::TrackerEntryStatus::NotWorking: @@ -91,34 +91,34 @@ namespace QString statusDHT(const BitTorrent::Torrent *torrent) { if (!torrent->session()->isDHTEnabled()) - return STR_DISABLED; + return TrackerListModel::tr(STR_DISABLED); if (torrent->isPrivate() || torrent->isDHTDisabled()) - return STR_TORRENT_DISABLED; + return TrackerListModel::tr(STR_TORRENT_DISABLED); - return STR_WORKING; + return TrackerListModel::tr(STR_WORKING); } QString statusPeX(const BitTorrent::Torrent *torrent) { if (!torrent->session()->isPeXEnabled()) - return STR_DISABLED; + return TrackerListModel::tr(STR_DISABLED); if (torrent->isPrivate() || torrent->isPEXDisabled()) - return STR_TORRENT_DISABLED; + return TrackerListModel::tr(STR_TORRENT_DISABLED); - return STR_WORKING; + return TrackerListModel::tr(STR_WORKING); } QString statusLSD(const BitTorrent::Torrent *torrent) { if (!torrent->session()->isLSDEnabled()) - return STR_DISABLED; + return TrackerListModel::tr(STR_DISABLED); if (torrent->isPrivate() || torrent->isLSDDisabled()) - return STR_TORRENT_DISABLED; + return TrackerListModel::tr(STR_TORRENT_DISABLED); - return STR_WORKING; + return TrackerListModel::tr(STR_WORKING); } } @@ -299,7 +299,7 @@ void TrackerListModel::populate() const QList trackerEntries = m_torrent->trackers(); m_items->reserve(trackerEntries.size() + STICKY_ROW_COUNT); - const QString &privateTorrentMessage = m_torrent->isPrivate() ? STR_PRIVATE_MSG : u""_s; + const QString &privateTorrentMessage = m_torrent->isPrivate() ? tr(STR_PRIVATE_MSG) : u""_s; m_items->emplace_back(std::make_shared(u"** [DHT] **", privateTorrentMessage)); m_items->emplace_back(std::make_shared(u"** [PeX] **", privateTorrentMessage)); m_items->emplace_back(std::make_shared(u"** [LSD] **", privateTorrentMessage)); diff --git a/src/gui/uithemedialog.cpp b/src/gui/uithemedialog.cpp index 3187a0f15..ef2b5626d 100644 --- a/src/gui/uithemedialog.cpp +++ b/src/gui/uithemedialog.cpp @@ -67,6 +67,7 @@ namespace class ColorWidget final : public QFrame { Q_DISABLE_COPY_MOVE(ColorWidget) + Q_DECLARE_TR_FUNCTIONS(ColorWidget) public: explicit ColorWidget(const QColor ¤tColor, const QColor &defaultColor, QWidget *parent = nullptr) @@ -140,6 +141,7 @@ private: class IconWidget final : public QLabel { Q_DISABLE_COPY_MOVE(IconWidget) + Q_DECLARE_TR_FUNCTIONS(IconWidget) public: explicit IconWidget(const Path ¤tPath, const Path &defaultPath, QWidget *parent = nullptr) diff --git a/src/gui/uithemesource.h b/src/gui/uithemesource.h index cb2afbbeb..cd7870595 100644 --- a/src/gui/uithemesource.h +++ b/src/gui/uithemesource.h @@ -61,6 +61,8 @@ public: class DefaultThemeSource final : public UIThemeSource { + Q_DECLARE_TR_FUNCTIONS(DefaultThemeSource) + public: DefaultThemeSource(); @@ -78,6 +80,8 @@ private: class CustomThemeSource : public UIThemeSource { + Q_DECLARE_TR_FUNCTIONS(CustomThemeSource) + public: QColor getColor(const QString &colorId, ColorMode colorMode) const override; Path getIconPath(const QString &iconId, ColorMode colorMode) const override;