Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport changes to v4.6.x #19582

Merged
merged 16 commits into from
Oct 8, 2023
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
11 changes: 8 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,21 @@ feature_option(STACKTRACE "Enable stacktrace support" ON)
feature_option(TESTING "Build internal testing suite" OFF)
feature_option(VERBOSE_CONFIGURE "Show information about PACKAGES_FOUND and PACKAGES_NOT_FOUND in the configure output (only useful for debugging the CMake build scripts)" OFF)

if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
if (CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
feature_option_dependent(DBUS
"Enable support for notifications and power-management features via D-Bus on Linux"
"Enable support for notifications and power-management features via D-Bus"
ON "GUI" OFF
)
endif()

if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
feature_option_dependent(SYSTEMD
"Install systemd service file. Target directory is overridable with `SYSTEMD_SERVICES_INSTALL_DIR` variable"
OFF "NOT GUI" OFF
)
elseif (MSVC)
endif()

if (MSVC)
feature_option(MSVC_RUNTIME_DYNAMIC "Use MSVC dynamic runtime library (-MD) instead of static (-MT)" ON)
endif()

Expand Down
3 changes: 2 additions & 1 deletion src/app/signalhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#endif

#include <QCoreApplication>
#include <QMetaObject>

#include "base/version.h"

Expand Down Expand Up @@ -89,7 +90,7 @@ namespace
const char *msgs[] = {"Catching signal: ", sysSigName[signum], "\nExiting cleanly\n"};
std::for_each(std::begin(msgs), std::end(msgs), safePrint);
signal(signum, SIG_DFL);
QCoreApplication::exit(); // unsafe, but exit anyway
QMetaObject::invokeMethod(qApp, [] { QCoreApplication::exit(); }, Qt::QueuedConnection); // unsafe, but exit anyway
}

#ifdef STACKTRACE
Expand Down
22 changes: 14 additions & 8 deletions src/base/bittorrent/dbresumedatastorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ namespace BitTorrent
Q_DISABLE_COPY_MOVE(Worker)

public:
Worker(const Path &dbPath, QReadWriteLock &dbLock);
Worker(const Path &dbPath, QReadWriteLock &dbLock, QObject *parent = nullptr);

void run() override;
void requestInterruption();
Expand Down Expand Up @@ -332,7 +332,7 @@ BitTorrent::DBResumeDataStorage::DBResumeDataStorage(const Path &dbPath, QObject
updateDB(dbVersion);
}

m_asyncWorker = new Worker(dbPath, m_dbLock);
m_asyncWorker = new Worker(dbPath, m_dbLock, this);
m_asyncWorker->start();
}

Expand Down Expand Up @@ -611,10 +611,15 @@ void BitTorrent::DBResumeDataStorage::updateDB(const int fromVersion) const

if (fromVersion <= 4)
{
const auto alterTableTorrentsQuery = u"ALTER TABLE %1 ADD %2"_s
.arg(quoted(DB_TABLE_TORRENTS), makeColumnDefinition(DB_COLUMN_INACTIVE_SEEDING_TIME_LIMIT, "INTEGER NOT NULL DEFAULT -2"));
if (!query.exec(alterTableTorrentsQuery))
throw RuntimeError(query.lastError().text());
const auto testQuery = u"SELECT COUNT(%1) FROM %2;"_s
.arg(quoted(DB_COLUMN_INACTIVE_SEEDING_TIME_LIMIT.name), quoted(DB_TABLE_TORRENTS));
if (!query.exec(testQuery))
{
const auto alterTableTorrentsQuery = u"ALTER TABLE %1 ADD %2"_s
.arg(quoted(DB_TABLE_TORRENTS), makeColumnDefinition(DB_COLUMN_INACTIVE_SEEDING_TIME_LIMIT, "INTEGER NOT NULL DEFAULT -2"));
if (!query.exec(alterTableTorrentsQuery))
throw RuntimeError(query.lastError().text());
}
}

const QString updateMetaVersionQuery = makeUpdateStatement(DB_TABLE_META, {DB_COLUMN_NAME, DB_COLUMN_VALUE});
Expand Down Expand Up @@ -653,8 +658,9 @@ void BitTorrent::DBResumeDataStorage::enableWALMode() const
throw RuntimeError(tr("WAL mode is probably unsupported due to filesystem limitations."));
}

BitTorrent::DBResumeDataStorage::Worker::Worker(const Path &dbPath, QReadWriteLock &dbLock)
: m_path {dbPath}
BitTorrent::DBResumeDataStorage::Worker::Worker(const Path &dbPath, QReadWriteLock &dbLock, QObject *parent)
: QThread(parent)
, m_path {dbPath}
, m_dbLock {dbLock}
{
}
Expand Down
53 changes: 37 additions & 16 deletions src/base/bittorrent/sessionimpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5555,10 +5555,13 @@ void SessionImpl::handleAlert(const lt::alert *a)
dispatchTorrentAlert(static_cast<const lt::torrent_alert *>(a));
break;
case lt::state_update_alert::alert_type:
handleStateUpdateAlert(static_cast<const lt::state_update_alert*>(a));
handleStateUpdateAlert(static_cast<const lt::state_update_alert *>(a));
break;
case lt::session_error_alert::alert_type:
handleSessionErrorAlert(static_cast<const lt::session_error_alert *>(a));
break;
case lt::session_stats_alert::alert_type:
handleSessionStatsAlert(static_cast<const lt::session_stats_alert*>(a));
handleSessionStatsAlert(static_cast<const lt::session_stats_alert *>(a));
break;
case lt::tracker_announce_alert::alert_type:
case lt::tracker_error_alert::alert_type:
Expand All @@ -5567,56 +5570,59 @@ void SessionImpl::handleAlert(const lt::alert *a)
handleTrackerAlert(static_cast<const lt::tracker_alert *>(a));
break;
case lt::file_error_alert::alert_type:
handleFileErrorAlert(static_cast<const lt::file_error_alert*>(a));
handleFileErrorAlert(static_cast<const lt::file_error_alert *>(a));
break;
case lt::add_torrent_alert::alert_type:
// handled separately
break;
case lt::torrent_removed_alert::alert_type:
handleTorrentRemovedAlert(static_cast<const lt::torrent_removed_alert*>(a));
handleTorrentRemovedAlert(static_cast<const lt::torrent_removed_alert *>(a));
break;
case lt::torrent_deleted_alert::alert_type:
handleTorrentDeletedAlert(static_cast<const lt::torrent_deleted_alert*>(a));
handleTorrentDeletedAlert(static_cast<const lt::torrent_deleted_alert *>(a));
break;
case lt::torrent_delete_failed_alert::alert_type:
handleTorrentDeleteFailedAlert(static_cast<const lt::torrent_delete_failed_alert*>(a));
handleTorrentDeleteFailedAlert(static_cast<const lt::torrent_delete_failed_alert *>(a));
break;
case lt::portmap_error_alert::alert_type:
handlePortmapWarningAlert(static_cast<const lt::portmap_error_alert*>(a));
handlePortmapWarningAlert(static_cast<const lt::portmap_error_alert *>(a));
break;
case lt::portmap_alert::alert_type:
handlePortmapAlert(static_cast<const lt::portmap_alert*>(a));
handlePortmapAlert(static_cast<const lt::portmap_alert *>(a));
break;
case lt::peer_blocked_alert::alert_type:
handlePeerBlockedAlert(static_cast<const lt::peer_blocked_alert*>(a));
handlePeerBlockedAlert(static_cast<const lt::peer_blocked_alert *>(a));
break;
case lt::peer_ban_alert::alert_type:
handlePeerBanAlert(static_cast<const lt::peer_ban_alert*>(a));
handlePeerBanAlert(static_cast<const lt::peer_ban_alert *>(a));
break;
case lt::url_seed_alert::alert_type:
handleUrlSeedAlert(static_cast<const lt::url_seed_alert*>(a));
handleUrlSeedAlert(static_cast<const lt::url_seed_alert *>(a));
break;
case lt::listen_succeeded_alert::alert_type:
handleListenSucceededAlert(static_cast<const lt::listen_succeeded_alert*>(a));
handleListenSucceededAlert(static_cast<const lt::listen_succeeded_alert *>(a));
break;
case lt::listen_failed_alert::alert_type:
handleListenFailedAlert(static_cast<const lt::listen_failed_alert*>(a));
handleListenFailedAlert(static_cast<const lt::listen_failed_alert *>(a));
break;
case lt::external_ip_alert::alert_type:
handleExternalIPAlert(static_cast<const lt::external_ip_alert*>(a));
handleExternalIPAlert(static_cast<const lt::external_ip_alert *>(a));
break;
case lt::alerts_dropped_alert::alert_type:
handleAlertsDroppedAlert(static_cast<const lt::alerts_dropped_alert *>(a));
break;
case lt::storage_moved_alert::alert_type:
handleStorageMovedAlert(static_cast<const lt::storage_moved_alert*>(a));
handleStorageMovedAlert(static_cast<const lt::storage_moved_alert *>(a));
break;
case lt::storage_moved_failed_alert::alert_type:
handleStorageMovedFailedAlert(static_cast<const lt::storage_moved_failed_alert*>(a));
handleStorageMovedFailedAlert(static_cast<const lt::storage_moved_failed_alert *>(a));
break;
case lt::socks5_alert::alert_type:
handleSocks5Alert(static_cast<const lt::socks5_alert *>(a));
break;
case lt::i2p_alert::alert_type:
handleI2PAlert(static_cast<const lt::i2p_alert *>(a));
break;
#ifdef QBT_USES_LIBTORRENT2
case lt::torrent_conflict_alert::alert_type:
handleTorrentConflictAlert(static_cast<const lt::torrent_conflict_alert *>(a));
Expand Down Expand Up @@ -5923,6 +5929,12 @@ void SessionImpl::handleExternalIPAlert(const lt::external_ip_alert *p)
}
}

void SessionImpl::handleSessionErrorAlert(const lt::session_error_alert *p) const
{
LogMsg(tr("BitTorrent session encountered a serious error. Reason: \"%1\"")
.arg(QString::fromStdString(p->message())), Log::CRITICAL);
}

void SessionImpl::handleSessionStatsAlert(const lt::session_stats_alert *p)
{
if (m_refreshEnqueued)
Expand Down Expand Up @@ -6117,6 +6129,15 @@ void SessionImpl::handleSocks5Alert(const lt::socks5_alert *p) const
}
}

void SessionImpl::handleI2PAlert(const lt::i2p_alert *p) const
{
if (p->error)
{
LogMsg(tr("I2P error. Message: \"%1\".")
.arg(QString::fromStdString(p->message())), Log::WARNING);
}
}

void SessionImpl::handleTrackerAlert(const lt::tracker_alert *a)
{
TorrentImpl *torrent = m_torrents.value(a->handle.info_hash());
Expand Down
2 changes: 2 additions & 0 deletions src/base/bittorrent/sessionimpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -564,11 +564,13 @@ namespace BitTorrent
void handleListenSucceededAlert(const lt::listen_succeeded_alert *p);
void handleListenFailedAlert(const lt::listen_failed_alert *p);
void handleExternalIPAlert(const lt::external_ip_alert *p);
void handleSessionErrorAlert(const lt::session_error_alert *p) const;
void handleSessionStatsAlert(const lt::session_stats_alert *p);
void handleAlertsDroppedAlert(const lt::alerts_dropped_alert *p) const;
void handleStorageMovedAlert(const lt::storage_moved_alert *p);
void handleStorageMovedFailedAlert(const lt::storage_moved_failed_alert *p);
void handleSocks5Alert(const lt::socks5_alert *p) const;
void handleI2PAlert(const lt::i2p_alert *p) const;
void handleTrackerAlert(const lt::tracker_alert *a);
#ifdef QBT_USES_LIBTORRENT2
void handleTorrentConflictAlert(const lt::torrent_conflict_alert *a);
Expand Down
3 changes: 3 additions & 0 deletions src/base/bittorrent/torrentimpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,9 @@ void TorrentImpl::replaceTrackers(QVector<TrackerEntry> trackers)
{
// TODO: use std::erase_if() in C++20
trackers.erase(std::remove_if(trackers.begin(), trackers.end(), [](const TrackerEntry &entry) { return entry.url.isEmpty(); }), trackers.end());
// Filter out duplicate trackers
const auto uniqueTrackers = QSet<TrackerEntry>(trackers.cbegin(), trackers.cend());
trackers = QVector<TrackerEntry>(uniqueTrackers.cbegin(), uniqueTrackers.cend());
std::sort(trackers.begin(), trackers.end()
, [](const TrackerEntry &lhs, const TrackerEntry &rhs) { return lhs.tier < rhs.tier; });

Expand Down
3 changes: 1 addition & 2 deletions src/base/rss/feed_serializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ const int ARTICLEDATALIST_TYPEID = qRegisterMetaType<QVector<QVariantHash>>();

void RSS::Private::FeedSerializer::load(const Path &dataFileName, const QString &url)
{
const int fileMaxSize = 10 * 1024 * 1024;
const auto readResult = Utils::IO::readFile(dataFileName, fileMaxSize);
const auto readResult = Utils::IO::readFile(dataFileName, -1);
if (!readResult)
{
if (readResult.error().status == Utils::IO::ReadError::NotExist)
Expand Down
4 changes: 2 additions & 2 deletions src/base/torrentfileswatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ TorrentFilesWatcher *TorrentFilesWatcher::instance()
}

TorrentFilesWatcher::TorrentFilesWatcher(QObject *parent)
: QObject {parent}
: QObject(parent)
, m_ioThread {new QThread}
{
const auto *btSession = BitTorrent::Session::instance();
Expand All @@ -163,7 +163,7 @@ void TorrentFilesWatcher::initWorker()
connect(m_asyncWorker, &TorrentFilesWatcher::Worker::torrentFound, this, &TorrentFilesWatcher::onTorrentFound);

m_asyncWorker->moveToThread(m_ioThread.get());
connect(m_ioThread.get(), &QThread::finished, m_asyncWorker, &QObject::deleteLater);
connect(m_ioThread.get(), &QObject::destroyed, this, [this] { delete m_asyncWorker; });
m_ioThread->start();

for (auto it = m_watchedFolders.cbegin(); it != m_watchedFolders.cend(); ++it)
Expand Down
24 changes: 18 additions & 6 deletions src/gui/aboutdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

#include "aboutdialog.h"

#include <QClipboard>

#include "base/global.h"
#include "base/path.h"
#include "base/unicodestrings.h"
Expand Down Expand Up @@ -74,22 +76,19 @@ AboutDialog::AboutDialog(QWidget *parent)
m_ui->labelMascot->setPixmap(Utils::Gui::scaledPixmap(Path(u":/icons/mascot.png"_s), this));

// Thanks
if (const auto readResult = Utils::IO::readFile(Path(u":/thanks.html"_s), -1, QIODevice::Text)
; readResult)
if (const auto readResult = Utils::IO::readFile(Path(u":/thanks.html"_s), -1, QIODevice::Text))
{
m_ui->textBrowserThanks->setHtml(QString::fromUtf8(readResult.value()));
}

// Translation
if (const auto readResult = Utils::IO::readFile(Path(u":/translators.html"_s), -1, QIODevice::Text)
; readResult)
if (const auto readResult = Utils::IO::readFile(Path(u":/translators.html"_s), -1, QIODevice::Text))
{
m_ui->textBrowserTranslation->setHtml(QString::fromUtf8(readResult.value()));
}

// License
if (const auto readResult = Utils::IO::readFile(Path(u":/gpl.html"_s), -1, QIODevice::Text)
; readResult)
if (const auto readResult = Utils::IO::readFile(Path(u":/gpl.html"_s), -1, QIODevice::Text))
{
m_ui->textBrowserLicense->setHtml(QString::fromUtf8(readResult.value()));
}
Expand All @@ -101,6 +100,8 @@ AboutDialog::AboutDialog(QWidget *parent)
m_ui->labelOpensslVer->setText(Utils::Misc::opensslVersionString());
m_ui->labelZlibVer->setText(Utils::Misc::zlibVersionString());

connect(m_ui->btnCopyToClipboard, &QAbstractButton::clicked, this, &AboutDialog::copyVersionsToClipboard);

const QString DBIPText = u"<html><head/><body><p>"
u"%1 (<a href=\"https://db-ip.com/\">https://db-ip.com/</a>)"
u"</p></body></html>"_s
Expand All @@ -117,3 +118,14 @@ AboutDialog::~AboutDialog()
m_storeDialogSize = size();
delete m_ui;
}

void AboutDialog::copyVersionsToClipboard() const
{
const QString versions = u"%1 %2\n%3 %4\n%5 %6\n%7 %8\n%9 %10\n"_s
.arg(m_ui->labelQt->text(), m_ui->labelQtVer->text()
, m_ui->labelLibt->text(), m_ui->labelLibtVer->text()
, m_ui->labelBoost->text(), m_ui->labelBoostVer->text()
, m_ui->labelOpenssl->text(), m_ui->labelOpensslVer->text()
, m_ui->labelZlib->text(), m_ui->labelZlibVer->text());
qApp->clipboard()->setText(versions);
}
2 changes: 2 additions & 0 deletions src/gui/aboutdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ class AboutDialog final : public QDialog
~AboutDialog() override;

private:
void copyVersionsToClipboard() const;

Ui::AboutDialog *m_ui = nullptr;
SettingValue<QSize> m_storeDialogSize;
};
Loading