From ff707ea5af4891345b4211bdc52f0468a5c737e0 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Thu, 16 May 2019 11:27:26 +0800 Subject: [PATCH 1/9] Change splitToViews() return type to QVector --- src/base/http/requestparser.cpp | 4 ++-- src/base/search/searchpluginmanager.cpp | 5 ++--- src/base/utils/bytearray.cpp | 10 ++++++---- src/base/utils/bytearray.h | 8 +++++--- src/base/utils/foreignapps.cpp | 3 ++- src/base/utils/password.cpp | 3 +-- 6 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/base/http/requestparser.cpp b/src/base/http/requestparser.cpp index fa5ded1c8..524c57772 100644 --- a/src/base/http/requestparser.cpp +++ b/src/base/http/requestparser.cpp @@ -253,7 +253,7 @@ bool RequestParser::parsePostMessage(const QByteArray &data) // split data by "dash-boundary" const QByteArray dashDelimiter = QByteArray("--") + delimiter + CRLF; - QList multipart = splitToViews(data, dashDelimiter, QString::SkipEmptyParts); + QVector multipart = splitToViews(data, dashDelimiter, QString::SkipEmptyParts); if (multipart.isEmpty()) { qWarning() << Q_FUNC_INFO << "multipart empty"; return false; @@ -275,7 +275,7 @@ bool RequestParser::parsePostMessage(const QByteArray &data) bool RequestParser::parseFormData(const QByteArray &data) { - const QList list = splitToViews(data, EOH, QString::KeepEmptyParts); + const QVector list = splitToViews(data, EOH, QString::KeepEmptyParts); if (list.size() != 2) { qWarning() << Q_FUNC_INFO << "multipart/form-data format error"; diff --git a/src/base/search/searchpluginmanager.cpp b/src/base/search/searchpluginmanager.cpp index d751cdf80..12d5280b4 100644 --- a/src/base/search/searchpluginmanager.cpp +++ b/src/base/search/searchpluginmanager.cpp @@ -37,7 +37,6 @@ #include #include #include -#include #include #include @@ -494,13 +493,13 @@ void SearchPluginManager::parseVersionInfo(const QByteArray &info) QHash updateInfo; int numCorrectData = 0; - const QList lines = Utils::ByteArray::splitToViews(info, "\n", QString::SkipEmptyParts); + const QVector lines = Utils::ByteArray::splitToViews(info, "\n", QString::SkipEmptyParts); for (QByteArray line : lines) { line = line.trimmed(); if (line.isEmpty()) continue; if (line.startsWith('#')) continue; - const QList list = Utils::ByteArray::splitToViews(line, ":", QString::SkipEmptyParts); + const QVector list = Utils::ByteArray::splitToViews(line, ":", QString::SkipEmptyParts); if (list.size() != 2) continue; const QString pluginName = list.first().trimmed(); diff --git a/src/base/utils/bytearray.cpp b/src/base/utils/bytearray.cpp index 9ef543e25..128aa93a3 100644 --- a/src/base/utils/bytearray.cpp +++ b/src/base/utils/bytearray.cpp @@ -28,15 +28,17 @@ #include "bytearray.h" -#include +#include -QList Utils::ByteArray::splitToViews(const QByteArray &in, const QByteArray &sep, const QString::SplitBehavior behavior) +QVector Utils::ByteArray::splitToViews(const QByteArray &in, const QByteArray &sep, const QString::SplitBehavior behavior) { if (sep.isEmpty()) return {in}; - QList ret; - + QVector ret; + ret.reserve((behavior == QString::KeepEmptyParts) + ? (1 + (in.size() / sep.size())) + : (1 + (in.size() / (sep.size() + 1)))); int head = 0; while (head < in.size()) { int end = in.indexOf(sep, head); diff --git a/src/base/utils/bytearray.h b/src/base/utils/bytearray.h index a9e6e89ea..f0d055ecf 100644 --- a/src/base/utils/bytearray.h +++ b/src/base/utils/bytearray.h @@ -28,15 +28,17 @@ #pragma once -#include #include +#include + +class QByteArray; namespace Utils { namespace ByteArray { - // Mimic QString::split(sep, behavior) - QList splitToViews(const QByteArray &in, const QByteArray &sep, const QString::SplitBehavior behavior = QString::KeepEmptyParts); + // Mimic QString::splitRef(sep, behavior) + QVector splitToViews(const QByteArray &in, const QByteArray &sep, const QString::SplitBehavior behavior = QString::KeepEmptyParts); // Mimic QByteArray::mid(pos, len) but instead of returning a full-copy, // we only return a partial view diff --git a/src/base/utils/foreignapps.cpp b/src/base/utils/foreignapps.cpp index 8047a827d..f32b55e45 100644 --- a/src/base/utils/foreignapps.cpp +++ b/src/base/utils/foreignapps.cpp @@ -43,6 +43,7 @@ #endif #include "base/logger.h" +#include "base/utils/bytearray.h" using namespace Utils::ForeignApps; @@ -61,7 +62,7 @@ namespace // Software 'Anaconda' installs its own python interpreter // and `python --version` returns a string like this: // "Python 3.4.3 :: Anaconda 2.3.0 (64-bit)" - const QList outputSplit = procOutput.split(' '); + const QVector outputSplit = Utils::ByteArray::splitToViews(procOutput, " ", QString::SkipEmptyParts); if (outputSplit.size() <= 1) return false; diff --git a/src/base/utils/password.cpp b/src/base/utils/password.cpp index ec9257ab5..e7bf0cbf6 100644 --- a/src/base/utils/password.cpp +++ b/src/base/utils/password.cpp @@ -33,7 +33,6 @@ #include #include -#include #include #include "bytearray.h" @@ -99,7 +98,7 @@ bool Utils::Password::PBKDF2::verify(const QByteArray &secret, const QString &pa bool Utils::Password::PBKDF2::verify(const QByteArray &secret, const QByteArray &password) { - const QList list = ByteArray::splitToViews(secret, ":", QString::SkipEmptyParts); + const QVector list = ByteArray::splitToViews(secret, ":", QString::SkipEmptyParts); if (list.size() != 2) return false; From 401bdbf3d9afb2e7f10524380a47d842f46f4268 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Thu, 16 May 2019 11:56:10 +0800 Subject: [PATCH 2/9] Remove unused functions --- src/base/utils/misc.cpp | 29 ++--------------------------- src/base/utils/misc.h | 9 +-------- 2 files changed, 3 insertions(+), 35 deletions(-) diff --git a/src/base/utils/misc.cpp b/src/base/utils/misc.cpp index ee87c3e1d..39c066f75 100644 --- a/src/base/utils/misc.cpp +++ b/src/base/utils/misc.cpp @@ -28,9 +28,6 @@ #include "misc.h" -#include -#include - #ifdef Q_OS_WIN #include #include @@ -44,7 +41,9 @@ #include #endif +#include #include +#include #include #include @@ -361,30 +360,6 @@ QString Utils::Misc::getUserIDString() return uid; } -QStringList Utils::Misc::toStringList(const QList &l) -{ - QStringList ret; - for (const bool b : l) - ret << (b ? "1" : "0"); - return ret; -} - -QList Utils::Misc::intListfromStringList(const QStringList &l) -{ - QList ret; - for (const QString &s : l) - ret << s.toInt(); - return ret; -} - -QList Utils::Misc::boolListfromStringList(const QStringList &l) -{ - QList ret; - for (const QString &s : l) - ret << (s == "1"); - return ret; -} - QString Utils::Misc::parseHtmlLinks(const QString &rawText) { QString result = rawText; diff --git a/src/base/utils/misc.h b/src/base/utils/misc.h index a8ca900f0..7c9a0e371 100644 --- a/src/base/utils/misc.h +++ b/src/base/utils/misc.h @@ -36,9 +36,7 @@ #include #endif -#include -#include - +class QString; enum class ShutdownDialogAction; /* Miscellaneous functions that can be useful */ @@ -87,11 +85,6 @@ namespace Utils QString userFriendlyDuration(qlonglong seconds); QString getUserIDString(); - // Convert functions - QStringList toStringList(const QList &l); - QList intListfromStringList(const QStringList &l); - QList boolListfromStringList(const QStringList &l); - #ifdef Q_OS_WIN QString windowsSystemPath(); From e288de7ec1dc4c9b4beb023f7b3e9fc6a7166086 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Thu, 16 May 2019 13:41:29 +0800 Subject: [PATCH 3/9] Forward declare as much as possible --- src/base/bittorrent/magneturi.cpp | 1 + src/base/bittorrent/magneturi.h | 7 ++++--- src/base/bittorrent/peerinfo.h | 4 ++-- .../bittorrent/private/bandwidthscheduler.cpp | 1 + .../bittorrent/private/filterparserthread.h | 4 ++-- .../bittorrent/private/portforwarderimpl.cpp | 4 ++-- .../private/resumedatasavingmanager.cpp | 1 + .../private/resumedatasavingmanager.h | 3 ++- src/base/bittorrent/session.h | 1 - src/base/bittorrent/torrentinfo.h | 1 - src/base/filesystemwatcher.h | 4 +++- src/base/iconprovider.h | 3 ++- src/base/net/smtp.cpp | 2 ++ src/base/preferences.cpp | 17 ++++++++++++----- src/base/preferences.h | 13 ++++++------- src/base/private/profile_p.cpp | 2 -- src/base/profile.h | 2 +- src/base/rss/rss_autodownloader.cpp | 1 + src/base/rss/rss_autodownloadrule.h | 2 +- src/base/search/searchhandler.h | 1 + src/base/settingvalue.h | 1 - src/base/utils/fs.cpp | 18 +++++++++--------- src/base/utils/random.cpp | 2 ++ src/gui/optionsdialog.cpp | 3 ++- src/gui/optionsdialog.h | 1 - src/gui/properties/propertieswidget.cpp | 2 ++ src/gui/properties/propertieswidget.h | 7 ++----- src/gui/properties/speedwidget.cpp | 5 ++--- src/gui/properties/speedwidget.h | 2 +- src/gui/transferlistdelegate.cpp | 2 +- src/webui/api/authcontroller.cpp | 3 +++ src/webui/api/authcontroller.h | 3 ++- src/webui/webapplication.cpp | 6 +----- 33 files changed, 71 insertions(+), 58 deletions(-) diff --git a/src/base/bittorrent/magneturi.cpp b/src/base/bittorrent/magneturi.cpp index f15ff39d0..cff9bb6cf 100644 --- a/src/base/bittorrent/magneturi.cpp +++ b/src/base/bittorrent/magneturi.cpp @@ -34,6 +34,7 @@ #include #include +#include #include "infohash.h" diff --git a/src/base/bittorrent/magneturi.h b/src/base/bittorrent/magneturi.h index e2b8757c3..f82dfc8d6 100644 --- a/src/base/bittorrent/magneturi.h +++ b/src/base/bittorrent/magneturi.h @@ -29,15 +29,16 @@ #ifndef BITTORRENT_MAGNETURI_H #define BITTORRENT_MAGNETURI_H +#include + #include #include -#include - -#include #include "infohash.h" #include "trackerentry.h" +class QUrl; + namespace BitTorrent { class MagnetUri diff --git a/src/base/bittorrent/peerinfo.h b/src/base/bittorrent/peerinfo.h index 6aae66f75..6fb3114af 100644 --- a/src/base/bittorrent/peerinfo.h +++ b/src/base/bittorrent/peerinfo.h @@ -29,12 +29,12 @@ #ifndef BITTORRENT_PEERINFO_H #define BITTORRENT_PEERINFO_H +#include + #include #include #include -#include - namespace BitTorrent { class TorrentHandle; diff --git a/src/base/bittorrent/private/bandwidthscheduler.cpp b/src/base/bittorrent/private/bandwidthscheduler.cpp index 308b3217e..a541a2427 100644 --- a/src/base/bittorrent/private/bandwidthscheduler.cpp +++ b/src/base/bittorrent/private/bandwidthscheduler.cpp @@ -33,6 +33,7 @@ #include #include +#include #include "base/preferences.h" diff --git a/src/base/bittorrent/private/filterparserthread.h b/src/base/bittorrent/private/filterparserthread.h index 0f374bbf5..7b86aa4f6 100644 --- a/src/base/bittorrent/private/filterparserthread.h +++ b/src/base/bittorrent/private/filterparserthread.h @@ -29,10 +29,10 @@ #ifndef FILTERPARSERTHREAD_H #define FILTERPARSERTHREAD_H -#include - #include +#include + class QDataStream; class FilterParserThread : public QThread diff --git a/src/base/bittorrent/private/portforwarderimpl.cpp b/src/base/bittorrent/private/portforwarderimpl.cpp index 23d8d6dbd..1a7eb02bf 100644 --- a/src/base/bittorrent/private/portforwarderimpl.cpp +++ b/src/base/bittorrent/private/portforwarderimpl.cpp @@ -28,10 +28,10 @@ #include "portforwarderimpl.h" -#include - #include +#include + #include "base/logger.h" #include "base/settingsstorage.h" diff --git a/src/base/bittorrent/private/resumedatasavingmanager.cpp b/src/base/bittorrent/private/resumedatasavingmanager.cpp index f9dc7b847..4fd93722d 100644 --- a/src/base/bittorrent/private/resumedatasavingmanager.cpp +++ b/src/base/bittorrent/private/resumedatasavingmanager.cpp @@ -28,6 +28,7 @@ #include "resumedatasavingmanager.h" +#include #include #include diff --git a/src/base/bittorrent/private/resumedatasavingmanager.h b/src/base/bittorrent/private/resumedatasavingmanager.h index 3f27d94a0..ffef21e91 100644 --- a/src/base/bittorrent/private/resumedatasavingmanager.h +++ b/src/base/bittorrent/private/resumedatasavingmanager.h @@ -28,10 +28,11 @@ #pragma once -#include #include #include +class QByteArray; + class ResumeDataSavingManager : public QObject { Q_OBJECT diff --git a/src/base/bittorrent/session.h b/src/base/bittorrent/session.h index d2c91b7e8..65a540414 100644 --- a/src/base/bittorrent/session.h +++ b/src/base/bittorrent/session.h @@ -43,7 +43,6 @@ #include #include "base/settingvalue.h" -#include "base/tristatebool.h" #include "base/types.h" #include "addtorrentparams.h" #include "cachestatus.h" diff --git a/src/base/bittorrent/torrentinfo.h b/src/base/bittorrent/torrentinfo.h index 207736954..f06f64765 100644 --- a/src/base/bittorrent/torrentinfo.h +++ b/src/base/bittorrent/torrentinfo.h @@ -29,7 +29,6 @@ #ifndef BITTORRENT_TORRENTINFO_H #define BITTORRENT_TORRENTINFO_H -#include #include #include diff --git a/src/base/filesystemwatcher.h b/src/base/filesystemwatcher.h index ac17d7124..af4c96163 100644 --- a/src/base/filesystemwatcher.h +++ b/src/base/filesystemwatcher.h @@ -32,9 +32,11 @@ #include #include #include -#include +#include #include +class QStringList; + /* * Subclassing QFileSystemWatcher in order to support Network File * System watching (NFS, CIFS) on Linux and Mac OS. diff --git a/src/base/iconprovider.h b/src/base/iconprovider.h index 3bba13361..b6ea47f8c 100644 --- a/src/base/iconprovider.h +++ b/src/base/iconprovider.h @@ -31,7 +31,8 @@ #define ICONPROVIDER_H #include -#include + +class QString; class IconProvider : public QObject { diff --git a/src/base/net/smtp.cpp b/src/base/net/smtp.cpp index 4cffa215c..1e009069a 100644 --- a/src/base/net/smtp.cpp +++ b/src/base/net/smtp.cpp @@ -33,10 +33,12 @@ #include "smtp.h" #include +#include #include #include #include #include + #ifndef QT_NO_OPENSSL #include #else diff --git a/src/base/preferences.cpp b/src/base/preferences.cpp index a96522f5c..81ac30e1f 100644 --- a/src/base/preferences.cpp +++ b/src/base/preferences.cpp @@ -29,9 +29,21 @@ #include "preferences.h" +#ifdef Q_OS_MAC +#include +#endif +#ifdef Q_OS_WIN +#include +#endif + +#include #include #include +#include #include +#include +#include +#include #ifndef DISABLE_GUI #include @@ -40,14 +52,9 @@ #endif #ifdef Q_OS_WIN -#include #include #endif -#ifdef Q_OS_MAC -#include -#endif - #include "algorithm.h" #include "global.h" #include "settingsstorage.h" diff --git a/src/base/preferences.h b/src/base/preferences.h index d8aaab2e2..26ed99dbc 100644 --- a/src/base/preferences.h +++ b/src/base/preferences.h @@ -30,16 +30,17 @@ #ifndef PREFERENCES_H #define PREFERENCES_H -#include #include -#include -#include #include -#include -#include #include "base/utils/net.h" +class QDateTime; +class QNetworkCookie; +class QSize; +class QTime; +class QVariant; + enum SchedulerDays { EVERY_DAY, @@ -74,8 +75,6 @@ namespace DNS }; } -class SettingsStorage; - class Preferences : public QObject { Q_OBJECT diff --git a/src/base/private/profile_p.cpp b/src/base/private/profile_p.cpp index 656beeebf..e5a211cc8 100644 --- a/src/base/private/profile_p.cpp +++ b/src/base/private/profile_p.cpp @@ -31,8 +31,6 @@ #include -#include "base/utils/fs.h" - Private::Profile::Profile(const QString &configurationName) : m_configurationSuffix {configurationName.isEmpty() ? QString() : QLatin1Char('_') + configurationName} { diff --git a/src/base/profile.h b/src/base/profile.h index 34b627a10..290248105 100644 --- a/src/base/profile.h +++ b/src/base/profile.h @@ -33,8 +33,8 @@ #include #include -#include +class QString; class Application; namespace Private diff --git a/src/base/rss/rss_autodownloader.cpp b/src/base/rss/rss_autodownloader.cpp index 4a8609b3f..10513ac9d 100644 --- a/src/base/rss/rss_autodownloader.cpp +++ b/src/base/rss/rss_autodownloader.cpp @@ -37,6 +37,7 @@ #include #include #include +#include #include #include diff --git a/src/base/rss/rss_autodownloadrule.h b/src/base/rss/rss_autodownloadrule.h index 15fd113fb..15e22b735 100644 --- a/src/base/rss/rss_autodownloadrule.h +++ b/src/base/rss/rss_autodownloadrule.h @@ -29,10 +29,10 @@ #pragma once -#include #include #include +class QDateTime; class QJsonObject; class QRegularExpression; class TriStateBool; diff --git a/src/base/search/searchhandler.h b/src/base/search/searchhandler.h index fae52d05c..3cf71318a 100644 --- a/src/base/search/searchhandler.h +++ b/src/base/search/searchhandler.h @@ -32,6 +32,7 @@ #include #include #include +#include class QProcess; class QTimer; diff --git a/src/base/settingvalue.h b/src/base/settingvalue.h index e3ff237c1..b2d13b353 100644 --- a/src/base/settingvalue.h +++ b/src/base/settingvalue.h @@ -33,7 +33,6 @@ #include #include -#include #include "settingsstorage.h" diff --git a/src/base/utils/fs.cpp b/src/base/utils/fs.cpp index ae9d1d31a..ab29a9a2c 100644 --- a/src/base/utils/fs.cpp +++ b/src/base/utils/fs.cpp @@ -34,15 +34,6 @@ #include #endif -#include -#include -#include -#include -#include -#include -#include -#include - #include #include @@ -58,6 +49,15 @@ #include #endif +#include +#include +#include +#include +#include +#include +#include +#include + #include "base/bittorrent/torrenthandle.h" #include "base/global.h" diff --git a/src/base/utils/random.cpp b/src/base/utils/random.cpp index fde12462e..ef46fe860 100644 --- a/src/base/utils/random.cpp +++ b/src/base/utils/random.cpp @@ -43,6 +43,8 @@ #include #endif +#include + #include "misc.h" namespace diff --git a/src/gui/optionsdialog.cpp b/src/gui/optionsdialog.cpp index 14a7d34b7..5ae565937 100644 --- a/src/gui/optionsdialog.cpp +++ b/src/gui/optionsdialog.cpp @@ -29,6 +29,7 @@ #include "optionsdialog.h" #include +#include #include #include @@ -62,8 +63,8 @@ #include "advancedsettings.h" #include "app/application.h" #include "banlistoptionsdialog.h" -#include "ipsubnetwhitelistoptionsdialog.h" #include "guiiconprovider.h" +#include "ipsubnetwhitelistoptionsdialog.h" #include "rss/automatedrssdownloader.h" #include "scanfoldersdelegate.h" #include "ui_optionsdialog.h" diff --git a/src/gui/optionsdialog.h b/src/gui/optionsdialog.h index 4e3a2d841..1565fdd19 100644 --- a/src/gui/optionsdialog.h +++ b/src/gui/optionsdialog.h @@ -29,7 +29,6 @@ #ifndef OPTIONSDIALOG_H #define OPTIONSDIALOG_H -#include #include class QAbstractButton; diff --git a/src/gui/properties/propertieswidget.cpp b/src/gui/properties/propertieswidget.cpp index eb10e0d0c..b6e60dd06 100644 --- a/src/gui/properties/propertieswidget.cpp +++ b/src/gui/properties/propertieswidget.cpp @@ -29,12 +29,14 @@ #include "propertieswidget.h" #include +#include #include #include #include #include #include #include +#include #include #include #include diff --git a/src/gui/properties/propertieswidget.h b/src/gui/properties/propertieswidget.h index de8b22d2d..c0c5750d3 100644 --- a/src/gui/properties/propertieswidget.h +++ b/src/gui/properties/propertieswidget.h @@ -29,14 +29,13 @@ #ifndef PROPERTIESWIDGET_H #define PROPERTIESWIDGET_H -#include +#include #include #include "base/bittorrent/torrenthandle.h" -class QAction; class QPushButton; -class QTimer; +class QShortcut; class QTreeView; class DownloadedPiecesBar; @@ -45,8 +44,6 @@ class PeerListWidget; class PieceAvailabilityBar; class PropListDelegate; class PropTabBar; -class SpeedWidget; -class torrent_file; class TorrentContentFilterModel; class TrackerListWidget; diff --git a/src/gui/properties/speedwidget.cpp b/src/gui/properties/speedwidget.cpp index 0ab151413..b3a1d3b3a 100644 --- a/src/gui/properties/speedwidget.cpp +++ b/src/gui/properties/speedwidget.cpp @@ -28,13 +28,12 @@ #include "speedwidget.h" -#include +#include #include #include #include #include - -#include +#include #include "base/bittorrent/session.h" #include "base/bittorrent/sessionstatus.h" diff --git a/src/gui/properties/speedwidget.h b/src/gui/properties/speedwidget.h index 148e40f55..79979b2a0 100644 --- a/src/gui/properties/speedwidget.h +++ b/src/gui/properties/speedwidget.h @@ -34,10 +34,10 @@ #include "speedplotview.h" -class QVBoxLayout; class QHBoxLayout; class QLabel; class QMenu; +class QVBoxLayout; class PropertiesWidget; class ComboBoxMenuButton : public QComboBox diff --git a/src/gui/transferlistdelegate.cpp b/src/gui/transferlistdelegate.cpp index d64d74e35..7a314310f 100644 --- a/src/gui/transferlistdelegate.cpp +++ b/src/gui/transferlistdelegate.cpp @@ -29,6 +29,7 @@ #include "transferlistdelegate.h" #include +#include #include #include #include @@ -37,7 +38,6 @@ #include #endif -#include "base/bittorrent/session.h" #include "base/bittorrent/torrenthandle.h" #include "base/preferences.h" #include "base/types.h" diff --git a/src/webui/api/authcontroller.cpp b/src/webui/api/authcontroller.cpp index 5798f77ec..1a34f163c 100644 --- a/src/webui/api/authcontroller.cpp +++ b/src/webui/api/authcontroller.cpp @@ -28,6 +28,9 @@ #include "authcontroller.h" +#include +#include + #include "base/logger.h" #include "base/preferences.h" #include "base/utils/password.h" diff --git a/src/webui/api/authcontroller.h b/src/webui/api/authcontroller.h index 287aee3da..0dd896473 100644 --- a/src/webui/api/authcontroller.h +++ b/src/webui/api/authcontroller.h @@ -29,10 +29,11 @@ #pragma once #include -#include #include "apicontroller.h" +class QString; + class AuthController : public APIController { Q_OBJECT diff --git a/src/webui/webapplication.cpp b/src/webui/webapplication.cpp index c0b15b001..07bbb68ec 100644 --- a/src/webui/webapplication.cpp +++ b/src/webui/webapplication.cpp @@ -29,10 +29,6 @@ #include "webapplication.h" #include -#include -#include -#include -#include #include #include @@ -41,13 +37,13 @@ #include #include #include +#include #include #include #include "base/algorithm.h" #include "base/global.h" #include "base/http/httperror.h" -#include "base/iconprovider.h" #include "base/logger.h" #include "base/preferences.h" #include "base/utils/bytearray.h" From 6738cdd715a511049ed35ead55b1a44a6fe09f05 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Thu, 16 May 2019 15:02:17 +0800 Subject: [PATCH 4/9] Constify exception references --- src/app/main.cpp | 2 +- .../bittorrent/private/filterparserthread.cpp | 10 +++++----- src/base/bittorrent/session.cpp | 16 ++++++++-------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/app/main.cpp b/src/app/main.cpp index a26c167d1..b17f6ce7a 100644 --- a/src/app/main.cpp +++ b/src/app/main.cpp @@ -261,7 +261,7 @@ int main(int argc, char *argv[]) return app->exec(params.paramList()); } - catch (CommandLineParameterError &er) { + catch (const CommandLineParameterError &er) { displayBadArgMessage(er.messageForUser()); return EXIT_FAILURE; } diff --git a/src/base/bittorrent/private/filterparserthread.cpp b/src/base/bittorrent/private/filterparserthread.cpp index cf7b19b81..ba275384c 100644 --- a/src/base/bittorrent/private/filterparserthread.cpp +++ b/src/base/bittorrent/private/filterparserthread.cpp @@ -245,7 +245,7 @@ int FilterParserThread::parseDATFilterFile() m_filter.add_rule(startAddr, endAddr, lt::ip_filter::blocked); ++ruleCount; } - catch (std::exception &e) { + catch (const std::exception &e) { ++parseErrorCount; addLog(tr("IP filter exception thrown for line %1. Exception is: %2") .arg(nbLine).arg(QString::fromLocal8Bit(e.what()))); @@ -383,7 +383,7 @@ int FilterParserThread::parseP2PFilterFile() m_filter.add_rule(startAddr, endAddr, lt::ip_filter::blocked); ++ruleCount; } - catch (std::exception &e) { + catch (const std::exception &e) { ++parseErrorCount; addLog(tr("IP filter exception thrown for line %1. Exception is: %2") .arg(nbLine).arg(QString::fromLocal8Bit(e.what()))); @@ -468,7 +468,7 @@ int FilterParserThread::parseP2BFilterFile() m_filter.add_rule(first, last, lt::ip_filter::blocked); ++ruleCount; } - catch (std::exception &) {} + catch (const std::exception &) {} } } else if (version == 3) { @@ -518,7 +518,7 @@ int FilterParserThread::parseP2BFilterFile() m_filter.add_rule(first, last, lt::ip_filter::blocked); ++ruleCount; } - catch (std::exception &) {} + catch (const std::exception &) {} if (m_abort) return ruleCount; } @@ -577,7 +577,7 @@ void FilterParserThread::run() try { emit IPFilterParsed(ruleCount); } - catch (std::exception &) { + catch (const std::exception &) { emit IPFilterError(); } diff --git a/src/base/bittorrent/session.cpp b/src/base/bittorrent/session.cpp index e2ea1d689..184c2dbae 100644 --- a/src/base/bittorrent/session.cpp +++ b/src/base/bittorrent/session.cpp @@ -1400,7 +1400,7 @@ void Session::configurePeerClasses() , lt::address_v6::from_string("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff") , 1 << lt::session::global_peer_class_id); } - catch (std::exception &) {} + catch (const std::exception &) {} #endif // TORRENT_USE_IPV6 if (ignoreLimitsOnLAN()) { // local networks @@ -1439,7 +1439,7 @@ void Session::configurePeerClasses() , lt::address_v6::from_string("::1") , 1 << lt::session::local_peer_class_id); } - catch (std::exception &) {} + catch (const std::exception &) {} #endif // TORRENT_USE_IPV6 } m_nativeSession->set_peer_class_filter(f); @@ -1870,7 +1870,7 @@ bool Session::addTorrent_impl(CreateTorrentParams params, const MagnetUri &magne #endif handle.pause(); } - catch (std::exception &) {} + catch (const std::exception &) {} adjustLimits(); @@ -3856,7 +3856,7 @@ void Session::handleAlert(const lt::alert *a) break; } } - catch (std::exception &exc) { + catch (const std::exception &exc) { qWarning() << "Caught exception in " << Q_FUNC_INFO << ": " << QString::fromStdString(exc.what()); } } @@ -4374,7 +4374,7 @@ namespace try { handle.queue_position_up(); } - catch (std::exception &exc) { + catch (const std::exception &exc) { qDebug() << Q_FUNC_INFO << " fails: " << exc.what(); } } @@ -4384,7 +4384,7 @@ namespace try { handle.queue_position_down(); } - catch (std::exception &exc) { + catch (const std::exception &exc) { qDebug() << Q_FUNC_INFO << " fails: " << exc.what(); } } @@ -4394,7 +4394,7 @@ namespace try { handle.queue_position_top(); } - catch (std::exception &exc) { + catch (const std::exception &exc) { qDebug() << Q_FUNC_INFO << " fails: " << exc.what(); } } @@ -4404,7 +4404,7 @@ namespace try { handle.queue_position_bottom(); } - catch (std::exception &exc) { + catch (const std::exception &exc) { qDebug() << Q_FUNC_INFO << " fails: " << exc.what(); } } From c75500670d6d074edfc7e5aeb4fbac72d0f3b79b Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Thu, 16 May 2019 16:25:53 +0800 Subject: [PATCH 5/9] Use forwarding reference when passing function objects So instead of passing every function objects by value (a copy is made), now function objects will be handled properly by reference (for lvalues) or by value (for rvalues). --- src/base/algorithm.h | 4 ++-- src/base/settingvalue.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/base/algorithm.h b/src/base/algorithm.h index 01aa39324..6eb9089b6 100644 --- a/src/base/algorithm.h +++ b/src/base/algorithm.h @@ -50,7 +50,7 @@ namespace Algorithm // To be used with associative array types, such as QMap, QHash and it's variants template ::value, int> = 0> - void removeIf(T &dict, BinaryPredicate p) + void removeIf(T &dict, BinaryPredicate &&p) { auto it = dict.begin(); while (it != dict.end()) @@ -60,7 +60,7 @@ namespace Algorithm // To be used with set types, such as QSet, std::set template ::value, int> = 0> - void removeIf(T &set, UnaryPredicate p) + void removeIf(T &set, UnaryPredicate &&p) { auto it = set.begin(); while (it != set.end()) diff --git a/src/base/settingvalue.h b/src/base/settingvalue.h index b2d13b353..64998e2d4 100644 --- a/src/base/settingvalue.h +++ b/src/base/settingvalue.h @@ -50,7 +50,7 @@ public: // T proxyFunc(const T &a); template explicit CachedSettingValue(const char *keyName, const T &defaultValue - , ProxyFunc proxyFunc) + , ProxyFunc &&proxyFunc) : m_keyName(QLatin1String(keyName)) , m_value(proxyFunc(loadValue(defaultValue))) { From 10e1c35998da6267d2eb563add8b9435ab7b7335 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Fri, 17 May 2019 11:20:47 +0800 Subject: [PATCH 6/9] Avoid unnecessary double lookup --- src/base/bittorrent/torrenthandle.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/base/bittorrent/torrenthandle.cpp b/src/base/bittorrent/torrenthandle.cpp index 09847116c..1759d6fd0 100644 --- a/src/base/bittorrent/torrenthandle.cpp +++ b/src/base/bittorrent/torrenthandle.cpp @@ -1577,8 +1577,7 @@ void TorrentHandle::handleTrackerReplyAlert(const lt::tracker_reply_alert *p) const QString trackerUrl(p->tracker_url()); qDebug("Received a tracker reply from %s (Num_peers = %d)", qUtf8Printable(trackerUrl), p->num_peers); // Connection was successful now. Remove possible old errors - m_trackerInfos[trackerUrl].lastMessage.clear(); // Reset error/warning message - m_trackerInfos[trackerUrl].numPeers = p->num_peers; + m_trackerInfos[trackerUrl] = {{}, p->num_peers}; m_session->handleTorrentTrackerReply(this, trackerUrl); } From e92209475edf79b49dacdd5b2bd33a329d263785 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Fri, 17 May 2019 11:24:01 +0800 Subject: [PATCH 7/9] Use range-based for loops --- src/base/bittorrent/torrenthandle.cpp | 6 ++---- src/base/scanfoldersmodel.cpp | 2 +- src/gui/torrentcontenttreeview.cpp | 5 ++--- src/webui/api/appcontroller.cpp | 4 ++-- 4 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/base/bittorrent/torrenthandle.cpp b/src/base/bittorrent/torrenthandle.cpp index 1759d6fd0..36be7b90c 100644 --- a/src/base/bittorrent/torrenthandle.cpp +++ b/src/base/bittorrent/torrenthandle.cpp @@ -1174,10 +1174,8 @@ QBitArray TorrentHandle::downloadingPieces() const std::vector queue; m_nativeHandle.get_download_queue(queue); - std::vector::const_iterator it = queue.begin(); - std::vector::const_iterator itend = queue.end(); - for (; it != itend; ++it) - result.setBit(it->piece_index); + for (const lt::partial_piece_info &info : queue) + result.setBit(info.piece_index); return result; } diff --git a/src/base/scanfoldersmodel.cpp b/src/base/scanfoldersmodel.cpp index 119b3eea9..8bee1d533 100644 --- a/src/base/scanfoldersmodel.cpp +++ b/src/base/scanfoldersmodel.cpp @@ -341,7 +341,7 @@ void ScanFoldersModel::configure() { const QVariantHash dirs = Preferences::instance()->getScanDirs(); - for (QVariantHash::const_iterator i = dirs.begin(), e = dirs.end(); i != e; ++i) { + for (auto i = dirs.cbegin(); i != dirs.cend(); ++i) { if (i.value().type() == QVariant::Int) addPath(i.key(), static_cast(i.value().toInt()), QString()); else diff --git a/src/gui/torrentcontenttreeview.cpp b/src/gui/torrentcontenttreeview.cpp index 3d9149508..712964a95 100644 --- a/src/gui/torrentcontenttreeview.cpp +++ b/src/gui/torrentcontenttreeview.cpp @@ -69,9 +69,8 @@ void TorrentContentTreeView::keyPressEvent(QKeyEvent *event) const QModelIndexList selection = selectionModel()->selectedRows(TorrentContentModelItem::COL_NAME); - for (QModelIndexList::const_iterator i = selection.begin(); i != selection.end(); ++i) { - QModelIndex index = *i; - Q_ASSERT(i->column() == TorrentContentModelItem::COL_NAME); + for (const QModelIndex &index : selection) { + Q_ASSERT(index.column() == TorrentContentModelItem::COL_NAME); model()->setData(index, state, Qt::CheckStateRole); } } diff --git a/src/webui/api/appcontroller.cpp b/src/webui/api/appcontroller.cpp index d62942a30..57ca4aa46 100644 --- a/src/webui/api/appcontroller.cpp +++ b/src/webui/api/appcontroller.cpp @@ -112,7 +112,7 @@ void AppController::preferencesAction() // Automatically add torrents from const QVariantHash dirs = pref->getScanDirs(); QVariantMap nativeDirs; - for (QVariantHash::const_iterator i = dirs.cbegin(), e = dirs.cend(); i != e; ++i) { + for (auto i = dirs.cbegin(); i != dirs.cend(); ++i) { if (i.value().type() == QVariant::Int) nativeDirs.insert(Utils::Fs::toNativePath(i.key()), i.value().toInt()); else @@ -299,7 +299,7 @@ void AppController::setPreferencesAction() QVariantHash oldScanDirs = pref->getScanDirs(); QVariantHash scanDirs; ScanFoldersModel *model = ScanFoldersModel::instance(); - for (QVariantMap::const_iterator i = nativeDirs.cbegin(), e = nativeDirs.cend(); i != e; ++i) { + for (auto i = nativeDirs.cbegin(); i != nativeDirs.cend(); ++i) { QString folder = Utils::Fs::fromNativePath(i.key()); int downloadType; QString downloadPath; From cb4c53c8489c0e10a9f0d808b389286682f700db Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Fri, 17 May 2019 11:55:16 +0800 Subject: [PATCH 8/9] Follow the type used in libtorrent --- src/base/bittorrent/torrenthandle.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/base/bittorrent/torrenthandle.h b/src/base/bittorrent/torrenthandle.h index 725ff24f6..14a218965 100644 --- a/src/base/bittorrent/torrenthandle.h +++ b/src/base/bittorrent/torrenthandle.h @@ -94,7 +94,7 @@ namespace BitTorrent struct TrackerInfo { QString lastMessage; - quint32 numPeers = 0; + int numPeers = 0; }; enum class TorrentState From 802af70e2f1c3d1fa7deffc14d0ecbec0b9768f6 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Sun, 19 May 2019 18:47:55 +0800 Subject: [PATCH 9/9] Fix typos --- src/gui/optionsdialog.cpp | 2 +- src/webui/www/private/preferences_content.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gui/optionsdialog.cpp b/src/gui/optionsdialog.cpp index 5ae565937..5368ee190 100644 --- a/src/gui/optionsdialog.cpp +++ b/src/gui/optionsdialog.cpp @@ -298,7 +298,7 @@ OptionsDialog::OptionsDialog(QWidget *parent) .arg(tr("Supported parameters (case sensitive):") , tr("%N: Torrent name") , tr("%L: Category") - , tr("%G: Tags (seperated by comma)") + , tr("%G: Tags (separated by comma)") , tr("%F: Content path (same as root path for multifile torrent)") , tr("%R: Root path (first torrent subdirectory path)") , tr("%D: Save path") diff --git a/src/webui/www/private/preferences_content.html b/src/webui/www/private/preferences_content.html index 068413703..69b380061 100644 --- a/src/webui/www/private/preferences_content.html +++ b/src/webui/www/private/preferences_content.html @@ -214,7 +214,7 @@
  • QBT_TR(%N: Torrent name)QBT_TR[CONTEXT=OptionsDialog]
  • QBT_TR(%L: Category)QBT_TR[CONTEXT=OptionsDialog]
  • -
  • QBT_TR(%G: Tags (seperated by comma))QBT_TR[CONTEXT=OptionsDialog]
  • +
  • QBT_TR(%G: Tags (separated by comma))QBT_TR[CONTEXT=OptionsDialog]
  • QBT_TR(%F: Content path (same as root path for multifile torrent))QBT_TR[CONTEXT=OptionsDialog]
  • QBT_TR(%R: Root path (first torrent subdirectory path))QBT_TR[CONTEXT=OptionsDialog]
  • QBT_TR(%D: Save path)QBT_TR[CONTEXT=OptionsDialog]