Browse Source

Merge pull request #10656 from Chocobo1/vector

Code cleanups
adaptive-webui-19844
Mike Tzou 6 years ago committed by GitHub
parent
commit
f86c5442aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      src/app/main.cpp
  2. 4
      src/base/algorithm.h
  3. 1
      src/base/bittorrent/magneturi.cpp
  4. 7
      src/base/bittorrent/magneturi.h
  5. 4
      src/base/bittorrent/peerinfo.h
  6. 1
      src/base/bittorrent/private/bandwidthscheduler.cpp
  7. 10
      src/base/bittorrent/private/filterparserthread.cpp
  8. 4
      src/base/bittorrent/private/filterparserthread.h
  9. 4
      src/base/bittorrent/private/portforwarderimpl.cpp
  10. 1
      src/base/bittorrent/private/resumedatasavingmanager.cpp
  11. 3
      src/base/bittorrent/private/resumedatasavingmanager.h
  12. 16
      src/base/bittorrent/session.cpp
  13. 1
      src/base/bittorrent/session.h
  14. 9
      src/base/bittorrent/torrenthandle.cpp
  15. 2
      src/base/bittorrent/torrenthandle.h
  16. 1
      src/base/bittorrent/torrentinfo.h
  17. 4
      src/base/filesystemwatcher.h
  18. 4
      src/base/http/requestparser.cpp
  19. 3
      src/base/iconprovider.h
  20. 2
      src/base/net/smtp.cpp
  21. 17
      src/base/preferences.cpp
  22. 13
      src/base/preferences.h
  23. 2
      src/base/private/profile_p.cpp
  24. 2
      src/base/profile.h
  25. 1
      src/base/rss/rss_autodownloader.cpp
  26. 2
      src/base/rss/rss_autodownloadrule.h
  27. 2
      src/base/scanfoldersmodel.cpp
  28. 1
      src/base/search/searchhandler.h
  29. 5
      src/base/search/searchpluginmanager.cpp
  30. 3
      src/base/settingvalue.h
  31. 10
      src/base/utils/bytearray.cpp
  32. 8
      src/base/utils/bytearray.h
  33. 3
      src/base/utils/foreignapps.cpp
  34. 18
      src/base/utils/fs.cpp
  35. 29
      src/base/utils/misc.cpp
  36. 9
      src/base/utils/misc.h
  37. 3
      src/base/utils/password.cpp
  38. 2
      src/base/utils/random.cpp
  39. 5
      src/gui/optionsdialog.cpp
  40. 1
      src/gui/optionsdialog.h
  41. 2
      src/gui/properties/propertieswidget.cpp
  42. 7
      src/gui/properties/propertieswidget.h
  43. 5
      src/gui/properties/speedwidget.cpp
  44. 2
      src/gui/properties/speedwidget.h
  45. 5
      src/gui/torrentcontenttreeview.cpp
  46. 2
      src/gui/transferlistdelegate.cpp
  47. 4
      src/webui/api/appcontroller.cpp
  48. 3
      src/webui/api/authcontroller.cpp
  49. 3
      src/webui/api/authcontroller.h
  50. 6
      src/webui/webapplication.cpp
  51. 2
      src/webui/www/private/preferences_content.html

2
src/app/main.cpp

@ -261,7 +261,7 @@ int main(int argc, char *argv[])
return app->exec(params.paramList()); return app->exec(params.paramList());
} }
catch (CommandLineParameterError &er) { catch (const CommandLineParameterError &er) {
displayBadArgMessage(er.messageForUser()); displayBadArgMessage(er.messageForUser());
return EXIT_FAILURE; return EXIT_FAILURE;
} }

4
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 // To be used with associative array types, such as QMap, QHash and it's variants
template <typename T, typename BinaryPredicate template <typename T, typename BinaryPredicate
, typename std::enable_if_t<HasMappedType<T>::value, int> = 0> , typename std::enable_if_t<HasMappedType<T>::value, int> = 0>
void removeIf(T &dict, BinaryPredicate p) void removeIf(T &dict, BinaryPredicate &&p)
{ {
auto it = dict.begin(); auto it = dict.begin();
while (it != dict.end()) while (it != dict.end())
@ -60,7 +60,7 @@ namespace Algorithm
// To be used with set types, such as QSet, std::set // To be used with set types, such as QSet, std::set
template <typename T, typename UnaryPredicate template <typename T, typename UnaryPredicate
, typename std::enable_if_t<!HasMappedType<T>::value, int> = 0> , typename std::enable_if_t<!HasMappedType<T>::value, int> = 0>
void removeIf(T &set, UnaryPredicate p) void removeIf(T &set, UnaryPredicate &&p)
{ {
auto it = set.begin(); auto it = set.begin();
while (it != set.end()) while (it != set.end())

1
src/base/bittorrent/magneturi.cpp

@ -34,6 +34,7 @@
#include <libtorrent/sha1_hash.hpp> #include <libtorrent/sha1_hash.hpp>
#include <QRegularExpression> #include <QRegularExpression>
#include <QUrl>
#include "infohash.h" #include "infohash.h"

7
src/base/bittorrent/magneturi.h

@ -29,15 +29,16 @@
#ifndef BITTORRENT_MAGNETURI_H #ifndef BITTORRENT_MAGNETURI_H
#define BITTORRENT_MAGNETURI_H #define BITTORRENT_MAGNETURI_H
#include <libtorrent/add_torrent_params.hpp>
#include <QList> #include <QList>
#include <QString> #include <QString>
#include <QUrl>
#include <libtorrent/add_torrent_params.hpp>
#include "infohash.h" #include "infohash.h"
#include "trackerentry.h" #include "trackerentry.h"
class QUrl;
namespace BitTorrent namespace BitTorrent
{ {
class MagnetUri class MagnetUri

4
src/base/bittorrent/peerinfo.h

@ -29,12 +29,12 @@
#ifndef BITTORRENT_PEERINFO_H #ifndef BITTORRENT_PEERINFO_H
#define BITTORRENT_PEERINFO_H #define BITTORRENT_PEERINFO_H
#include <libtorrent/peer_info.hpp>
#include <QBitArray> #include <QBitArray>
#include <QCoreApplication> #include <QCoreApplication>
#include <QHostAddress> #include <QHostAddress>
#include <libtorrent/peer_info.hpp>
namespace BitTorrent namespace BitTorrent
{ {
class TorrentHandle; class TorrentHandle;

1
src/base/bittorrent/private/bandwidthscheduler.cpp

@ -33,6 +33,7 @@
#include <QDate> #include <QDate>
#include <QTime> #include <QTime>
#include <QTimer>
#include "base/preferences.h" #include "base/preferences.h"

10
src/base/bittorrent/private/filterparserthread.cpp

@ -245,7 +245,7 @@ int FilterParserThread::parseDATFilterFile()
m_filter.add_rule(startAddr, endAddr, lt::ip_filter::blocked); m_filter.add_rule(startAddr, endAddr, lt::ip_filter::blocked);
++ruleCount; ++ruleCount;
} }
catch (std::exception &e) { catch (const std::exception &e) {
++parseErrorCount; ++parseErrorCount;
addLog(tr("IP filter exception thrown for line %1. Exception is: %2") addLog(tr("IP filter exception thrown for line %1. Exception is: %2")
.arg(nbLine).arg(QString::fromLocal8Bit(e.what()))); .arg(nbLine).arg(QString::fromLocal8Bit(e.what())));
@ -383,7 +383,7 @@ int FilterParserThread::parseP2PFilterFile()
m_filter.add_rule(startAddr, endAddr, lt::ip_filter::blocked); m_filter.add_rule(startAddr, endAddr, lt::ip_filter::blocked);
++ruleCount; ++ruleCount;
} }
catch (std::exception &e) { catch (const std::exception &e) {
++parseErrorCount; ++parseErrorCount;
addLog(tr("IP filter exception thrown for line %1. Exception is: %2") addLog(tr("IP filter exception thrown for line %1. Exception is: %2")
.arg(nbLine).arg(QString::fromLocal8Bit(e.what()))); .arg(nbLine).arg(QString::fromLocal8Bit(e.what())));
@ -468,7 +468,7 @@ int FilterParserThread::parseP2BFilterFile()
m_filter.add_rule(first, last, lt::ip_filter::blocked); m_filter.add_rule(first, last, lt::ip_filter::blocked);
++ruleCount; ++ruleCount;
} }
catch (std::exception &) {} catch (const std::exception &) {}
} }
} }
else if (version == 3) { else if (version == 3) {
@ -518,7 +518,7 @@ int FilterParserThread::parseP2BFilterFile()
m_filter.add_rule(first, last, lt::ip_filter::blocked); m_filter.add_rule(first, last, lt::ip_filter::blocked);
++ruleCount; ++ruleCount;
} }
catch (std::exception &) {} catch (const std::exception &) {}
if (m_abort) return ruleCount; if (m_abort) return ruleCount;
} }
@ -577,7 +577,7 @@ void FilterParserThread::run()
try { try {
emit IPFilterParsed(ruleCount); emit IPFilterParsed(ruleCount);
} }
catch (std::exception &) { catch (const std::exception &) {
emit IPFilterError(); emit IPFilterError();
} }

4
src/base/bittorrent/private/filterparserthread.h

@ -29,10 +29,10 @@
#ifndef FILTERPARSERTHREAD_H #ifndef FILTERPARSERTHREAD_H
#define FILTERPARSERTHREAD_H #define FILTERPARSERTHREAD_H
#include <QThread>
#include <libtorrent/ip_filter.hpp> #include <libtorrent/ip_filter.hpp>
#include <QThread>
class QDataStream; class QDataStream;
class FilterParserThread : public QThread class FilterParserThread : public QThread

4
src/base/bittorrent/private/portforwarderimpl.cpp

@ -28,10 +28,10 @@
#include "portforwarderimpl.h" #include "portforwarderimpl.h"
#include <QDebug>
#include <libtorrent/session.hpp> #include <libtorrent/session.hpp>
#include <QDebug>
#include "base/logger.h" #include "base/logger.h"
#include "base/settingsstorage.h" #include "base/settingsstorage.h"

1
src/base/bittorrent/private/resumedatasavingmanager.cpp

@ -28,6 +28,7 @@
#include "resumedatasavingmanager.h" #include "resumedatasavingmanager.h"
#include <QByteArray>
#include <QDebug> #include <QDebug>
#include <QSaveFile> #include <QSaveFile>

3
src/base/bittorrent/private/resumedatasavingmanager.h

@ -28,10 +28,11 @@
#pragma once #pragma once
#include <QByteArray>
#include <QDir> #include <QDir>
#include <QObject> #include <QObject>
class QByteArray;
class ResumeDataSavingManager : public QObject class ResumeDataSavingManager : public QObject
{ {
Q_OBJECT Q_OBJECT

16
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") , lt::address_v6::from_string("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff")
, 1 << lt::session::global_peer_class_id); , 1 << lt::session::global_peer_class_id);
} }
catch (std::exception &) {} catch (const std::exception &) {}
#endif // TORRENT_USE_IPV6 #endif // TORRENT_USE_IPV6
if (ignoreLimitsOnLAN()) { if (ignoreLimitsOnLAN()) {
// local networks // local networks
@ -1439,7 +1439,7 @@ void Session::configurePeerClasses()
, lt::address_v6::from_string("::1") , lt::address_v6::from_string("::1")
, 1 << lt::session::local_peer_class_id); , 1 << lt::session::local_peer_class_id);
} }
catch (std::exception &) {} catch (const std::exception &) {}
#endif // TORRENT_USE_IPV6 #endif // TORRENT_USE_IPV6
} }
m_nativeSession->set_peer_class_filter(f); m_nativeSession->set_peer_class_filter(f);
@ -1870,7 +1870,7 @@ bool Session::addTorrent_impl(CreateTorrentParams params, const MagnetUri &magne
#endif #endif
handle.pause(); handle.pause();
} }
catch (std::exception &) {} catch (const std::exception &) {}
adjustLimits(); adjustLimits();
@ -3856,7 +3856,7 @@ void Session::handleAlert(const lt::alert *a)
break; break;
} }
} }
catch (std::exception &exc) { catch (const std::exception &exc) {
qWarning() << "Caught exception in " << Q_FUNC_INFO << ": " << QString::fromStdString(exc.what()); qWarning() << "Caught exception in " << Q_FUNC_INFO << ": " << QString::fromStdString(exc.what());
} }
} }
@ -4374,7 +4374,7 @@ namespace
try { try {
handle.queue_position_up(); handle.queue_position_up();
} }
catch (std::exception &exc) { catch (const std::exception &exc) {
qDebug() << Q_FUNC_INFO << " fails: " << exc.what(); qDebug() << Q_FUNC_INFO << " fails: " << exc.what();
} }
} }
@ -4384,7 +4384,7 @@ namespace
try { try {
handle.queue_position_down(); handle.queue_position_down();
} }
catch (std::exception &exc) { catch (const std::exception &exc) {
qDebug() << Q_FUNC_INFO << " fails: " << exc.what(); qDebug() << Q_FUNC_INFO << " fails: " << exc.what();
} }
} }
@ -4394,7 +4394,7 @@ namespace
try { try {
handle.queue_position_top(); handle.queue_position_top();
} }
catch (std::exception &exc) { catch (const std::exception &exc) {
qDebug() << Q_FUNC_INFO << " fails: " << exc.what(); qDebug() << Q_FUNC_INFO << " fails: " << exc.what();
} }
} }
@ -4404,7 +4404,7 @@ namespace
try { try {
handle.queue_position_bottom(); handle.queue_position_bottom();
} }
catch (std::exception &exc) { catch (const std::exception &exc) {
qDebug() << Q_FUNC_INFO << " fails: " << exc.what(); qDebug() << Q_FUNC_INFO << " fails: " << exc.what();
} }
} }

1
src/base/bittorrent/session.h

@ -43,7 +43,6 @@
#include <QSet> #include <QSet>
#include "base/settingvalue.h" #include "base/settingvalue.h"
#include "base/tristatebool.h"
#include "base/types.h" #include "base/types.h"
#include "addtorrentparams.h" #include "addtorrentparams.h"
#include "cachestatus.h" #include "cachestatus.h"

9
src/base/bittorrent/torrenthandle.cpp

@ -1174,10 +1174,8 @@ QBitArray TorrentHandle::downloadingPieces() const
std::vector<lt::partial_piece_info> queue; std::vector<lt::partial_piece_info> queue;
m_nativeHandle.get_download_queue(queue); m_nativeHandle.get_download_queue(queue);
std::vector<lt::partial_piece_info>::const_iterator it = queue.begin(); for (const lt::partial_piece_info &info : queue)
std::vector<lt::partial_piece_info>::const_iterator itend = queue.end(); result.setBit(info.piece_index);
for (; it != itend; ++it)
result.setBit(it->piece_index);
return result; return result;
} }
@ -1577,8 +1575,7 @@ void TorrentHandle::handleTrackerReplyAlert(const lt::tracker_reply_alert *p)
const QString trackerUrl(p->tracker_url()); const QString trackerUrl(p->tracker_url());
qDebug("Received a tracker reply from %s (Num_peers = %d)", qUtf8Printable(trackerUrl), p->num_peers); qDebug("Received a tracker reply from %s (Num_peers = %d)", qUtf8Printable(trackerUrl), p->num_peers);
// Connection was successful now. Remove possible old errors // Connection was successful now. Remove possible old errors
m_trackerInfos[trackerUrl].lastMessage.clear(); // Reset error/warning message m_trackerInfos[trackerUrl] = {{}, p->num_peers};
m_trackerInfos[trackerUrl].numPeers = p->num_peers;
m_session->handleTorrentTrackerReply(this, trackerUrl); m_session->handleTorrentTrackerReply(this, trackerUrl);
} }

2
src/base/bittorrent/torrenthandle.h

@ -94,7 +94,7 @@ namespace BitTorrent
struct TrackerInfo struct TrackerInfo
{ {
QString lastMessage; QString lastMessage;
quint32 numPeers = 0; int numPeers = 0;
}; };
enum class TorrentState enum class TorrentState

1
src/base/bittorrent/torrentinfo.h

@ -29,7 +29,6 @@
#ifndef BITTORRENT_TORRENTINFO_H #ifndef BITTORRENT_TORRENTINFO_H
#define BITTORRENT_TORRENTINFO_H #define BITTORRENT_TORRENTINFO_H
#include <libtorrent/fwd.hpp>
#include <libtorrent/torrent_info.hpp> #include <libtorrent/torrent_info.hpp>
#include <libtorrent/version.hpp> #include <libtorrent/version.hpp>

4
src/base/filesystemwatcher.h

@ -32,9 +32,11 @@
#include <QDir> #include <QDir>
#include <QFileSystemWatcher> #include <QFileSystemWatcher>
#include <QHash> #include <QHash>
#include <QStringList> #include <QList>
#include <QTimer> #include <QTimer>
class QStringList;
/* /*
* Subclassing QFileSystemWatcher in order to support Network File * Subclassing QFileSystemWatcher in order to support Network File
* System watching (NFS, CIFS) on Linux and Mac OS. * System watching (NFS, CIFS) on Linux and Mac OS.

4
src/base/http/requestparser.cpp

@ -253,7 +253,7 @@ bool RequestParser::parsePostMessage(const QByteArray &data)
// split data by "dash-boundary" // split data by "dash-boundary"
const QByteArray dashDelimiter = QByteArray("--") + delimiter + CRLF; const QByteArray dashDelimiter = QByteArray("--") + delimiter + CRLF;
QList<QByteArray> multipart = splitToViews(data, dashDelimiter, QString::SkipEmptyParts); QVector<QByteArray> multipart = splitToViews(data, dashDelimiter, QString::SkipEmptyParts);
if (multipart.isEmpty()) { if (multipart.isEmpty()) {
qWarning() << Q_FUNC_INFO << "multipart empty"; qWarning() << Q_FUNC_INFO << "multipart empty";
return false; return false;
@ -275,7 +275,7 @@ bool RequestParser::parsePostMessage(const QByteArray &data)
bool RequestParser::parseFormData(const QByteArray &data) bool RequestParser::parseFormData(const QByteArray &data)
{ {
const QList<QByteArray> list = splitToViews(data, EOH, QString::KeepEmptyParts); const QVector<QByteArray> list = splitToViews(data, EOH, QString::KeepEmptyParts);
if (list.size() != 2) { if (list.size() != 2) {
qWarning() << Q_FUNC_INFO << "multipart/form-data format error"; qWarning() << Q_FUNC_INFO << "multipart/form-data format error";

3
src/base/iconprovider.h

@ -31,7 +31,8 @@
#define ICONPROVIDER_H #define ICONPROVIDER_H
#include <QObject> #include <QObject>
#include <QString>
class QString;
class IconProvider : public QObject class IconProvider : public QObject
{ {

2
src/base/net/smtp.cpp

@ -33,10 +33,12 @@
#include "smtp.h" #include "smtp.h"
#include <QCryptographicHash> #include <QCryptographicHash>
#include <QDateTime>
#include <QDebug> #include <QDebug>
#include <QHostInfo> #include <QHostInfo>
#include <QStringList> #include <QStringList>
#include <QTextCodec> #include <QTextCodec>
#ifndef QT_NO_OPENSSL #ifndef QT_NO_OPENSSL
#include <QSslSocket> #include <QSslSocket>
#else #else

17
src/base/preferences.cpp

@ -29,9 +29,21 @@
#include "preferences.h" #include "preferences.h"
#ifdef Q_OS_MAC
#include <CoreServices/CoreServices.h>
#endif
#ifdef Q_OS_WIN
#include <shlobj.h>
#endif
#include <QDateTime>
#include <QDir> #include <QDir>
#include <QLocale> #include <QLocale>
#include <QNetworkCookie>
#include <QSettings> #include <QSettings>
#include <QSize>
#include <QTime>
#include <QVariant>
#ifndef DISABLE_GUI #ifndef DISABLE_GUI
#include <QApplication> #include <QApplication>
@ -40,14 +52,9 @@
#endif #endif
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
#include <shlobj.h>
#include <QRegularExpression> #include <QRegularExpression>
#endif #endif
#ifdef Q_OS_MAC
#include <CoreServices/CoreServices.h>
#endif
#include "algorithm.h" #include "algorithm.h"
#include "global.h" #include "global.h"
#include "settingsstorage.h" #include "settingsstorage.h"

13
src/base/preferences.h

@ -30,16 +30,17 @@
#ifndef PREFERENCES_H #ifndef PREFERENCES_H
#define PREFERENCES_H #define PREFERENCES_H
#include <QDateTime>
#include <QList> #include <QList>
#include <QNetworkCookie>
#include <QSize>
#include <QStringList> #include <QStringList>
#include <QTime>
#include <QVariant>
#include "base/utils/net.h" #include "base/utils/net.h"
class QDateTime;
class QNetworkCookie;
class QSize;
class QTime;
class QVariant;
enum SchedulerDays enum SchedulerDays
{ {
EVERY_DAY, EVERY_DAY,
@ -74,8 +75,6 @@ namespace DNS
}; };
} }
class SettingsStorage;
class Preferences : public QObject class Preferences : public QObject
{ {
Q_OBJECT Q_OBJECT

2
src/base/private/profile_p.cpp

@ -31,8 +31,6 @@
#include <QCoreApplication> #include <QCoreApplication>
#include "base/utils/fs.h"
Private::Profile::Profile(const QString &configurationName) Private::Profile::Profile(const QString &configurationName)
: m_configurationSuffix {configurationName.isEmpty() ? QString() : QLatin1Char('_') + configurationName} : m_configurationSuffix {configurationName.isEmpty() ? QString() : QLatin1Char('_') + configurationName}
{ {

2
src/base/profile.h

@ -33,8 +33,8 @@
#include <memory> #include <memory>
#include <QSettings> #include <QSettings>
#include <QString>
class QString;
class Application; class Application;
namespace Private namespace Private

1
src/base/rss/rss_autodownloader.cpp

@ -37,6 +37,7 @@
#include <QSaveFile> #include <QSaveFile>
#include <QThread> #include <QThread>
#include <QTimer> #include <QTimer>
#include <QUrl>
#include <QVariant> #include <QVariant>
#include <QVector> #include <QVector>

2
src/base/rss/rss_autodownloadrule.h

@ -29,10 +29,10 @@
#pragma once #pragma once
#include <QDateTime>
#include <QSharedDataPointer> #include <QSharedDataPointer>
#include <QVariant> #include <QVariant>
class QDateTime;
class QJsonObject; class QJsonObject;
class QRegularExpression; class QRegularExpression;
class TriStateBool; class TriStateBool;

2
src/base/scanfoldersmodel.cpp

@ -341,7 +341,7 @@ void ScanFoldersModel::configure()
{ {
const QVariantHash dirs = Preferences::instance()->getScanDirs(); 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) if (i.value().type() == QVariant::Int)
addPath(i.key(), static_cast<PathType>(i.value().toInt()), QString()); addPath(i.key(), static_cast<PathType>(i.value().toInt()), QString());
else else

1
src/base/search/searchhandler.h

@ -32,6 +32,7 @@
#include <QByteArray> #include <QByteArray>
#include <QList> #include <QList>
#include <QObject> #include <QObject>
#include <QString>
class QProcess; class QProcess;
class QTimer; class QTimer;

5
src/base/search/searchpluginmanager.cpp

@ -37,7 +37,6 @@
#include <QDomDocument> #include <QDomDocument>
#include <QDomElement> #include <QDomElement>
#include <QDomNode> #include <QDomNode>
#include <QList>
#include <QPointer> #include <QPointer>
#include <QProcess> #include <QProcess>
@ -494,13 +493,13 @@ void SearchPluginManager::parseVersionInfo(const QByteArray &info)
QHash<QString, PluginVersion> updateInfo; QHash<QString, PluginVersion> updateInfo;
int numCorrectData = 0; int numCorrectData = 0;
const QList<QByteArray> lines = Utils::ByteArray::splitToViews(info, "\n", QString::SkipEmptyParts); const QVector<QByteArray> lines = Utils::ByteArray::splitToViews(info, "\n", QString::SkipEmptyParts);
for (QByteArray line : lines) { for (QByteArray line : lines) {
line = line.trimmed(); line = line.trimmed();
if (line.isEmpty()) continue; if (line.isEmpty()) continue;
if (line.startsWith('#')) continue; if (line.startsWith('#')) continue;
const QList<QByteArray> list = Utils::ByteArray::splitToViews(line, ":", QString::SkipEmptyParts); const QVector<QByteArray> list = Utils::ByteArray::splitToViews(line, ":", QString::SkipEmptyParts);
if (list.size() != 2) continue; if (list.size() != 2) continue;
const QString pluginName = list.first().trimmed(); const QString pluginName = list.first().trimmed();

3
src/base/settingvalue.h

@ -33,7 +33,6 @@
#include <QMetaEnum> #include <QMetaEnum>
#include <QString> #include <QString>
#include <QVariant>
#include "settingsstorage.h" #include "settingsstorage.h"
@ -51,7 +50,7 @@ public:
// T proxyFunc(const T &a); // T proxyFunc(const T &a);
template <typename ProxyFunc> template <typename ProxyFunc>
explicit CachedSettingValue(const char *keyName, const T &defaultValue explicit CachedSettingValue(const char *keyName, const T &defaultValue
, ProxyFunc proxyFunc) , ProxyFunc &&proxyFunc)
: m_keyName(QLatin1String(keyName)) : m_keyName(QLatin1String(keyName))
, m_value(proxyFunc(loadValue(defaultValue))) , m_value(proxyFunc(loadValue(defaultValue)))
{ {

10
src/base/utils/bytearray.cpp

@ -28,15 +28,17 @@
#include "bytearray.h" #include "bytearray.h"
#include <QList> #include <QByteArray>
QList<QByteArray> Utils::ByteArray::splitToViews(const QByteArray &in, const QByteArray &sep, const QString::SplitBehavior behavior) QVector<QByteArray> Utils::ByteArray::splitToViews(const QByteArray &in, const QByteArray &sep, const QString::SplitBehavior behavior)
{ {
if (sep.isEmpty()) if (sep.isEmpty())
return {in}; return {in};
QList<QByteArray> ret; QVector<QByteArray> ret;
ret.reserve((behavior == QString::KeepEmptyParts)
? (1 + (in.size() / sep.size()))
: (1 + (in.size() / (sep.size() + 1))));
int head = 0; int head = 0;
while (head < in.size()) { while (head < in.size()) {
int end = in.indexOf(sep, head); int end = in.indexOf(sep, head);

8
src/base/utils/bytearray.h

@ -28,15 +28,17 @@
#pragma once #pragma once
#include <QByteArray>
#include <QString> #include <QString>
#include <QVector>
class QByteArray;
namespace Utils namespace Utils
{ {
namespace ByteArray namespace ByteArray
{ {
// Mimic QString::split(sep, behavior) // Mimic QString::splitRef(sep, behavior)
QList<QByteArray> splitToViews(const QByteArray &in, const QByteArray &sep, const QString::SplitBehavior behavior = QString::KeepEmptyParts); QVector<QByteArray> 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, // Mimic QByteArray::mid(pos, len) but instead of returning a full-copy,
// we only return a partial view // we only return a partial view

3
src/base/utils/foreignapps.cpp

@ -43,6 +43,7 @@
#endif #endif
#include "base/logger.h" #include "base/logger.h"
#include "base/utils/bytearray.h"
using namespace Utils::ForeignApps; using namespace Utils::ForeignApps;
@ -61,7 +62,7 @@ namespace
// Software 'Anaconda' installs its own python interpreter // Software 'Anaconda' installs its own python interpreter
// and `python --version` returns a string like this: // and `python --version` returns a string like this:
// "Python 3.4.3 :: Anaconda 2.3.0 (64-bit)" // "Python 3.4.3 :: Anaconda 2.3.0 (64-bit)"
const QList<QByteArray> outputSplit = procOutput.split(' '); const QVector<QByteArray> outputSplit = Utils::ByteArray::splitToViews(procOutput, " ", QString::SkipEmptyParts);
if (outputSplit.size() <= 1) if (outputSplit.size() <= 1)
return false; return false;

18
src/base/utils/fs.cpp

@ -34,15 +34,6 @@
#include <memory> #include <memory>
#endif #endif
#include <QCoreApplication>
#include <QDebug>
#include <QDir>
#include <QDirIterator>
#include <QFile>
#include <QFileInfo>
#include <QStorageInfo>
#include <QRegularExpression>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/types.h> #include <sys/types.h>
@ -58,6 +49,15 @@
#include <unistd.h> #include <unistd.h>
#endif #endif
#include <QCoreApplication>
#include <QDebug>
#include <QDir>
#include <QDirIterator>
#include <QFile>
#include <QFileInfo>
#include <QStorageInfo>
#include <QRegularExpression>
#include "base/bittorrent/torrenthandle.h" #include "base/bittorrent/torrenthandle.h"
#include "base/global.h" #include "base/global.h"

29
src/base/utils/misc.cpp

@ -28,9 +28,6 @@
#include "misc.h" #include "misc.h"
#include <boost/version.hpp>
#include <libtorrent/version.hpp>
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
#include <windows.h> #include <windows.h>
#include <Shlobj.h> #include <Shlobj.h>
@ -44,7 +41,9 @@
#include <CoreServices/CoreServices.h> #include <CoreServices/CoreServices.h>
#endif #endif
#include <boost/version.hpp>
#include <openssl/opensslv.h> #include <openssl/opensslv.h>
#include <libtorrent/version.hpp>
#include <QCoreApplication> #include <QCoreApplication>
#include <QRegularExpression> #include <QRegularExpression>
@ -361,30 +360,6 @@ QString Utils::Misc::getUserIDString()
return uid; return uid;
} }
QStringList Utils::Misc::toStringList(const QList<bool> &l)
{
QStringList ret;
for (const bool b : l)
ret << (b ? "1" : "0");
return ret;
}
QList<int> Utils::Misc::intListfromStringList(const QStringList &l)
{
QList<int> ret;
for (const QString &s : l)
ret << s.toInt();
return ret;
}
QList<bool> Utils::Misc::boolListfromStringList(const QStringList &l)
{
QList<bool> ret;
for (const QString &s : l)
ret << (s == "1");
return ret;
}
QString Utils::Misc::parseHtmlLinks(const QString &rawText) QString Utils::Misc::parseHtmlLinks(const QString &rawText)
{ {
QString result = rawText; QString result = rawText;

9
src/base/utils/misc.h

@ -36,9 +36,7 @@
#include <Windows.h> #include <Windows.h>
#endif #endif
#include <QString> class QString;
#include <QStringList>
enum class ShutdownDialogAction; enum class ShutdownDialogAction;
/* Miscellaneous functions that can be useful */ /* Miscellaneous functions that can be useful */
@ -87,11 +85,6 @@ namespace Utils
QString userFriendlyDuration(qlonglong seconds); QString userFriendlyDuration(qlonglong seconds);
QString getUserIDString(); QString getUserIDString();
// Convert functions
QStringList toStringList(const QList<bool> &l);
QList<int> intListfromStringList(const QStringList &l);
QList<bool> boolListfromStringList(const QStringList &l);
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
QString windowsSystemPath(); QString windowsSystemPath();

3
src/base/utils/password.cpp

@ -33,7 +33,6 @@
#include <openssl/evp.h> #include <openssl/evp.h>
#include <QByteArray> #include <QByteArray>
#include <QList>
#include <QString> #include <QString>
#include "bytearray.h" #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) bool Utils::Password::PBKDF2::verify(const QByteArray &secret, const QByteArray &password)
{ {
const QList<QByteArray> list = ByteArray::splitToViews(secret, ":", QString::SkipEmptyParts); const QVector<QByteArray> list = ByteArray::splitToViews(secret, ":", QString::SkipEmptyParts);
if (list.size() != 2) if (list.size() != 2)
return false; return false;

2
src/base/utils/random.cpp

@ -43,6 +43,8 @@
#include <cstdio> #include <cstdio>
#endif #endif
#include <QString>
#include "misc.h" #include "misc.h"
namespace namespace

5
src/gui/optionsdialog.cpp

@ -29,6 +29,7 @@
#include "optionsdialog.h" #include "optionsdialog.h"
#include <cstdlib> #include <cstdlib>
#include <limits>
#include <QApplication> #include <QApplication>
#include <QCloseEvent> #include <QCloseEvent>
@ -62,8 +63,8 @@
#include "advancedsettings.h" #include "advancedsettings.h"
#include "app/application.h" #include "app/application.h"
#include "banlistoptionsdialog.h" #include "banlistoptionsdialog.h"
#include "ipsubnetwhitelistoptionsdialog.h"
#include "guiiconprovider.h" #include "guiiconprovider.h"
#include "ipsubnetwhitelistoptionsdialog.h"
#include "rss/automatedrssdownloader.h" #include "rss/automatedrssdownloader.h"
#include "scanfoldersdelegate.h" #include "scanfoldersdelegate.h"
#include "ui_optionsdialog.h" #include "ui_optionsdialog.h"
@ -297,7 +298,7 @@ OptionsDialog::OptionsDialog(QWidget *parent)
.arg(tr("Supported parameters (case sensitive):") .arg(tr("Supported parameters (case sensitive):")
, tr("%N: Torrent name") , tr("%N: Torrent name")
, tr("%L: Category") , 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("%F: Content path (same as root path for multifile torrent)")
, tr("%R: Root path (first torrent subdirectory path)") , tr("%R: Root path (first torrent subdirectory path)")
, tr("%D: Save path") , tr("%D: Save path")

1
src/gui/optionsdialog.h

@ -29,7 +29,6 @@
#ifndef OPTIONSDIALOG_H #ifndef OPTIONSDIALOG_H
#define OPTIONSDIALOG_H #define OPTIONSDIALOG_H
#include <QButtonGroup>
#include <QDialog> #include <QDialog>
class QAbstractButton; class QAbstractButton;

2
src/gui/properties/propertieswidget.cpp

@ -29,12 +29,14 @@
#include "propertieswidget.h" #include "propertieswidget.h"
#include <QAction> #include <QAction>
#include <QDateTime>
#include <QDebug> #include <QDebug>
#include <QDir> #include <QDir>
#include <QHeaderView> #include <QHeaderView>
#include <QListWidgetItem> #include <QListWidgetItem>
#include <QMenu> #include <QMenu>
#include <QSplitter> #include <QSplitter>
#include <QShortcut>
#include <QStackedWidget> #include <QStackedWidget>
#include <QThread> #include <QThread>
#include <QUrl> #include <QUrl>

7
src/gui/properties/propertieswidget.h

@ -29,14 +29,13 @@
#ifndef PROPERTIESWIDGET_H #ifndef PROPERTIESWIDGET_H
#define PROPERTIESWIDGET_H #define PROPERTIESWIDGET_H
#include <QShortcut> #include <QList>
#include <QWidget> #include <QWidget>
#include "base/bittorrent/torrenthandle.h" #include "base/bittorrent/torrenthandle.h"
class QAction;
class QPushButton; class QPushButton;
class QTimer; class QShortcut;
class QTreeView; class QTreeView;
class DownloadedPiecesBar; class DownloadedPiecesBar;
@ -45,8 +44,6 @@ class PeerListWidget;
class PieceAvailabilityBar; class PieceAvailabilityBar;
class PropListDelegate; class PropListDelegate;
class PropTabBar; class PropTabBar;
class SpeedWidget;
class torrent_file;
class TorrentContentFilterModel; class TorrentContentFilterModel;
class TrackerListWidget; class TrackerListWidget;

5
src/gui/properties/speedwidget.cpp

@ -28,13 +28,12 @@
#include "speedwidget.h" #include "speedwidget.h"
#include <QVBoxLayout> #include <QDateTime>
#include <QHBoxLayout> #include <QHBoxLayout>
#include <QLabel> #include <QLabel>
#include <QMenu> #include <QMenu>
#include <QTimer> #include <QTimer>
#include <QVBoxLayout>
#include <libtorrent/session_status.hpp>
#include "base/bittorrent/session.h" #include "base/bittorrent/session.h"
#include "base/bittorrent/sessionstatus.h" #include "base/bittorrent/sessionstatus.h"

2
src/gui/properties/speedwidget.h

@ -34,10 +34,10 @@
#include "speedplotview.h" #include "speedplotview.h"
class QVBoxLayout;
class QHBoxLayout; class QHBoxLayout;
class QLabel; class QLabel;
class QMenu; class QMenu;
class QVBoxLayout;
class PropertiesWidget; class PropertiesWidget;
class ComboBoxMenuButton : public QComboBox class ComboBoxMenuButton : public QComboBox

5
src/gui/torrentcontenttreeview.cpp

@ -69,9 +69,8 @@ void TorrentContentTreeView::keyPressEvent(QKeyEvent *event)
const QModelIndexList selection = selectionModel()->selectedRows(TorrentContentModelItem::COL_NAME); const QModelIndexList selection = selectionModel()->selectedRows(TorrentContentModelItem::COL_NAME);
for (QModelIndexList::const_iterator i = selection.begin(); i != selection.end(); ++i) { for (const QModelIndex &index : selection) {
QModelIndex index = *i; Q_ASSERT(index.column() == TorrentContentModelItem::COL_NAME);
Q_ASSERT(i->column() == TorrentContentModelItem::COL_NAME);
model()->setData(index, state, Qt::CheckStateRole); model()->setData(index, state, Qt::CheckStateRole);
} }
} }

2
src/gui/transferlistdelegate.cpp

@ -29,6 +29,7 @@
#include "transferlistdelegate.h" #include "transferlistdelegate.h"
#include <QApplication> #include <QApplication>
#include <QDateTime>
#include <QModelIndex> #include <QModelIndex>
#include <QPainter> #include <QPainter>
#include <QStyleOptionViewItem> #include <QStyleOptionViewItem>
@ -37,7 +38,6 @@
#include <QProxyStyle> #include <QProxyStyle>
#endif #endif
#include "base/bittorrent/session.h"
#include "base/bittorrent/torrenthandle.h" #include "base/bittorrent/torrenthandle.h"
#include "base/preferences.h" #include "base/preferences.h"
#include "base/types.h" #include "base/types.h"

4
src/webui/api/appcontroller.cpp

@ -112,7 +112,7 @@ void AppController::preferencesAction()
// Automatically add torrents from // Automatically add torrents from
const QVariantHash dirs = pref->getScanDirs(); const QVariantHash dirs = pref->getScanDirs();
QVariantMap nativeDirs; 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) if (i.value().type() == QVariant::Int)
nativeDirs.insert(Utils::Fs::toNativePath(i.key()), i.value().toInt()); nativeDirs.insert(Utils::Fs::toNativePath(i.key()), i.value().toInt());
else else
@ -299,7 +299,7 @@ void AppController::setPreferencesAction()
QVariantHash oldScanDirs = pref->getScanDirs(); QVariantHash oldScanDirs = pref->getScanDirs();
QVariantHash scanDirs; QVariantHash scanDirs;
ScanFoldersModel *model = ScanFoldersModel::instance(); 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()); QString folder = Utils::Fs::fromNativePath(i.key());
int downloadType; int downloadType;
QString downloadPath; QString downloadPath;

3
src/webui/api/authcontroller.cpp

@ -28,6 +28,9 @@
#include "authcontroller.h" #include "authcontroller.h"
#include <QDateTime>
#include <QString>
#include "base/logger.h" #include "base/logger.h"
#include "base/preferences.h" #include "base/preferences.h"
#include "base/utils/password.h" #include "base/utils/password.h"

3
src/webui/api/authcontroller.h

@ -29,10 +29,11 @@
#pragma once #pragma once
#include <QHash> #include <QHash>
#include <QString>
#include "apicontroller.h" #include "apicontroller.h"
class QString;
class AuthController : public APIController class AuthController : public APIController
{ {
Q_OBJECT Q_OBJECT

6
src/webui/webapplication.cpp

@ -29,10 +29,6 @@
#include "webapplication.h" #include "webapplication.h"
#include <algorithm> #include <algorithm>
#include <functional>
#include <queue>
#include <stdexcept>
#include <vector>
#include <QDateTime> #include <QDateTime>
#include <QDebug> #include <QDebug>
@ -41,13 +37,13 @@
#include <QJsonDocument> #include <QJsonDocument>
#include <QMimeDatabase> #include <QMimeDatabase>
#include <QMimeType> #include <QMimeType>
#include <QNetworkCookie>
#include <QRegExp> #include <QRegExp>
#include <QUrl> #include <QUrl>
#include "base/algorithm.h" #include "base/algorithm.h"
#include "base/global.h" #include "base/global.h"
#include "base/http/httperror.h" #include "base/http/httperror.h"
#include "base/iconprovider.h"
#include "base/logger.h" #include "base/logger.h"
#include "base/preferences.h" #include "base/preferences.h"
#include "base/utils/bytearray.h" #include "base/utils/bytearray.h"

2
src/webui/www/private/preferences_content.html

@ -214,7 +214,7 @@
<ul> <ul>
<li>QBT_TR(%N: Torrent name)QBT_TR[CONTEXT=OptionsDialog]</li> <li>QBT_TR(%N: Torrent name)QBT_TR[CONTEXT=OptionsDialog]</li>
<li>QBT_TR(%L: Category)QBT_TR[CONTEXT=OptionsDialog]</li> <li>QBT_TR(%L: Category)QBT_TR[CONTEXT=OptionsDialog]</li>
<li>QBT_TR(%G: Tags (seperated by comma))QBT_TR[CONTEXT=OptionsDialog]</li> <li>QBT_TR(%G: Tags (separated by comma))QBT_TR[CONTEXT=OptionsDialog]</li>
<li>QBT_TR(%F: Content path (same as root path for multifile torrent))QBT_TR[CONTEXT=OptionsDialog]</li> <li>QBT_TR(%F: Content path (same as root path for multifile torrent))QBT_TR[CONTEXT=OptionsDialog]</li>
<li>QBT_TR(%R: Root path (first torrent subdirectory path))QBT_TR[CONTEXT=OptionsDialog]</li> <li>QBT_TR(%R: Root path (first torrent subdirectory path))QBT_TR[CONTEXT=OptionsDialog]</li>
<li>QBT_TR(%D: Save path)QBT_TR[CONTEXT=OptionsDialog]</li> <li>QBT_TR(%D: Save path)QBT_TR[CONTEXT=OptionsDialog]</li>

Loading…
Cancel
Save