Browse Source

Merge pull request #10296 from thalieht/clang-tidy

Some suggestions from Clang-tidy
adaptive-webui-19844
Mike Tzou 6 years ago committed by GitHub
parent
commit
1c14a08390
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      src/app/application.cpp
  2. 23
      src/app/cmdoptions.cpp
  3. 2
      src/app/main.cpp
  4. 10
      src/base/bittorrent/private/filterparserthread.cpp
  5. 4
      src/base/bittorrent/private/speedmonitor.cpp
  6. 3
      src/base/bittorrent/private/statistics.cpp
  7. 6
      src/base/bittorrent/session.cpp
  8. 12
      src/base/bittorrent/torrenthandle.cpp
  9. 24
      src/base/bittorrent/torrentinfo.cpp
  10. 8
      src/base/bittorrent/trackerentry.cpp
  11. 4
      src/base/http/server.cpp
  12. 4
      src/base/logger.cpp
  13. 6
      src/base/net/dnsupdater.cpp
  14. 2
      src/base/net/geoipmanager.cpp
  15. 29
      src/base/net/private/geoipdatabase.cpp
  16. 20
      src/base/rss/private/rss_parser.cpp
  17. 4
      src/base/rss/rss_autodownloadrule.cpp
  18. 4
      src/base/rss/rss_item.cpp
  19. 10
      src/base/scanfoldersmodel.cpp
  20. 4
      src/base/settingsstorage.cpp
  21. 1
      src/base/torrentfileguard.cpp
  22. 5
      src/base/torrentfileguard.h
  23. 12
      src/base/torrentfilter.cpp
  24. 2
      src/base/utils/foreignapps.cpp
  25. 8
      src/base/utils/misc.cpp
  26. 2
      src/base/utils/net.cpp
  27. 2
      src/gui/autoexpandabledialog.cpp
  28. 20
      src/gui/categoryfiltermodel.cpp
  29. 2
      src/gui/categoryfilterwidget.cpp
  30. 12
      src/gui/cookiesmodel.cpp
  31. 2
      src/gui/fspathedit.cpp
  32. 5
      src/gui/fspathedit_p.cpp
  33. 2
      src/gui/guiiconprovider.cpp
  34. 2
      src/gui/loglistwidget.cpp
  35. 17
      src/gui/mainwindow.cpp
  36. 28
      src/gui/optionsdialog.cpp
  37. 4
      src/gui/powermanagement/powermanagement_x11.cpp
  38. 2
      src/gui/previewselectdialog.cpp
  39. 2
      src/gui/programupdater.cpp
  40. 5
      src/gui/properties/piecesbar.cpp
  41. 8
      src/gui/properties/propertieswidget.cpp
  42. 6
      src/gui/properties/proplistdelegate.cpp
  43. 3
      src/gui/properties/trackerlistwidget.cpp
  44. 2
      src/gui/rss/articlelistwidget.cpp
  45. 2
      src/gui/rss/feedlistwidget.cpp
  46. 2
      src/gui/rss/htmlbrowser.cpp
  47. 2
      src/gui/rss/rsswidget.cpp
  48. 8
      src/gui/scanfoldersdelegate.cpp
  49. 4
      src/gui/search/pluginselectdialog.cpp
  50. 2
      src/gui/search/searchjobwidget.cpp
  51. 2
      src/gui/search/searchwidget.cpp
  52. 2
      src/gui/statusbar.cpp
  53. 14
      src/gui/tagfiltermodel.cpp
  54. 2
      src/gui/tagfilterwidget.cpp
  55. 14
      src/gui/torrentcontentfiltermodel.cpp
  56. 44
      src/gui/torrentcontentmodel.cpp
  57. 2
      src/gui/torrentcontentmodelitem.cpp
  58. 2
      src/gui/torrentcontenttreeview.cpp
  59. 46
      src/gui/transferlistfilterswidget.cpp
  60. 44
      src/gui/transferlistmodel.cpp
  61. 25
      src/gui/transferlistsortmodel.cpp
  62. 8
      src/gui/transferlistwidget.cpp
  63. 4
      src/gui/utils.cpp
  64. 7
      src/webui/api/appcontroller.cpp
  65. 4
      src/webui/api/synccontroller.cpp
  66. 12
      src/webui/webapplication.cpp

2
src/app/application.cpp

@ -345,7 +345,7 @@ void Application::sendNotificationEmail(const BitTorrent::TorrentHandle *torrent
// Send the notification email // Send the notification email
const Preferences *pref = Preferences::instance(); const Preferences *pref = Preferences::instance();
Net::Smtp *smtp = new Net::Smtp(this); auto *smtp = new Net::Smtp(this);
smtp->sendMail(pref->getMailNotificationSender(), smtp->sendMail(pref->getMailNotificationSender(),
pref->getMailNotificationEmail(), pref->getMailNotificationEmail(),
tr("[qBittorrent] '%1' has finished downloading").arg(torrent->name()), tr("[qBittorrent] '%1' has finished downloading").arg(torrent->name()),

23
src/app/cmdoptions.cpp

@ -89,8 +89,8 @@ namespace
if ((USAGE_TEXT_COLUMN - usage.length() - 4) > 0) if ((USAGE_TEXT_COLUMN - usage.length() - 4) > 0)
return res + QString(USAGE_TEXT_COLUMN - usage.length() - 4, ' '); return res + QString(USAGE_TEXT_COLUMN - usage.length() - 4, ' ');
else
return res; return res;
} }
private: private:
@ -256,13 +256,13 @@ namespace
if (parts.size() == 1) { if (parts.size() == 1) {
return TriStateBool(m_defaultValue); return TriStateBool(m_defaultValue);
} }
else if (parts.size() == 2) { if (parts.size() == 2) {
QString val = parts[1]; QString val = parts[1];
if ((val.toUpper() == QLatin1String("TRUE")) || (val == QLatin1String("1"))) { if ((val.toUpper() == QLatin1String("TRUE")) || (val == QLatin1String("1"))) {
return TriStateBool::True; return TriStateBool::True;
} }
else if ((val.toUpper() == QLatin1String("FALSE")) || (val == QLatin1String("0"))) { if ((val.toUpper() == QLatin1String("FALSE")) || (val == QLatin1String("0"))) {
return TriStateBool::False; return TriStateBool::False;
} }
} }
@ -281,20 +281,19 @@ namespace
if (val.isEmpty()) { if (val.isEmpty()) {
return TriStateBool(m_defaultValue); return TriStateBool(m_defaultValue);
} }
else if (val == QLatin1String("-1")) { if (val == QLatin1String("-1")) {
return TriStateBool::Undefined; return TriStateBool::Undefined;
} }
else if ((val.toUpper() == QLatin1String("TRUE")) || (val == QLatin1String("1"))) { if ((val.toUpper() == QLatin1String("TRUE")) || (val == QLatin1String("1"))) {
return TriStateBool::True; return TriStateBool::True;
} }
else if ((val.toUpper() == QLatin1String("FALSE")) || (val == QLatin1String("0"))) { if ((val.toUpper() == QLatin1String("FALSE")) || (val == QLatin1String("0"))) {
return TriStateBool::False; return TriStateBool::False;
} }
else {
qDebug() << QObject::tr("Expected %1 in environment variable '%2', but got '%3'") qDebug() << QObject::tr("Expected %1 in environment variable '%2', but got '%3'")
.arg(QLatin1String("true|false"), envVarName(), val); .arg(QLatin1String("true|false"), envVarName(), val);
return TriStateBool::Undefined; return TriStateBool::Undefined;
}
} }
bool m_defaultValue; bool m_defaultValue;

2
src/app/main.cpp

@ -29,6 +29,7 @@
#include <QtGlobal> #include <QtGlobal>
#include <csignal>
#include <cstdlib> #include <cstdlib>
#if !defined Q_OS_WIN && !defined Q_OS_HAIKU #if !defined Q_OS_WIN && !defined Q_OS_HAIKU
@ -59,7 +60,6 @@ Q_IMPORT_PLUGIN(QICOPlugin)
#include <cstdio> #include <cstdio>
#endif // DISABLE_GUI #endif // DISABLE_GUI
#include <signal.h>
#ifdef STACKTRACE #ifdef STACKTRACE
#ifdef Q_OS_UNIX #ifdef Q_OS_UNIX
#include "stacktrace.h" #include "stacktrace.h"

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

@ -177,9 +177,8 @@ int FilterParserThread::parseDATFilterFile()
memmove(buffer.data(), buffer.data() + start, offset); memmove(buffer.data(), buffer.data() + start, offset);
break; break;
} }
else {
++nbLine; ++nbLine;
}
if ((buffer[start] == '#') if ((buffer[start] == '#')
|| ((buffer[start] == '/') && ((start + 1 < dataSize) && (buffer[start + 1] == '/')))) { || ((buffer[start] == '/') && ((start + 1 < dataSize) && (buffer[start + 1] == '/')))) {
@ -325,9 +324,8 @@ int FilterParserThread::parseP2PFilterFile()
memmove(buffer.data(), buffer.data() + start, offset); memmove(buffer.data(), buffer.data() + start, offset);
break; break;
} }
else {
++nbLine; ++nbLine;
}
if ((buffer[start] == '#') if ((buffer[start] == '#')
|| ((buffer[start] == '/') && ((start + 1 < dataSize) && (buffer[start + 1] == '/')))) { || ((buffer[start] == '/') && ((start + 1 < dataSize) && (buffer[start + 1] == '/')))) {

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

@ -47,10 +47,10 @@ void SpeedMonitor::addSample(const SpeedSample &sample)
SpeedSampleAvg SpeedMonitor::average() const SpeedSampleAvg SpeedMonitor::average() const
{ {
if (m_speedSamples.empty()) if (m_speedSamples.empty())
return SpeedSampleAvg(); return {};
const qreal k = qreal(1.) / m_speedSamples.size(); const qreal k = qreal(1.) / m_speedSamples.size();
return SpeedSampleAvg(m_sum.download * k, m_sum.upload * k); return {m_sum.download * k, m_sum.upload * k};
} }
void SpeedMonitor::reset() void SpeedMonitor::reset()

3
src/base/bittorrent/private/statistics.cpp

@ -30,15 +30,12 @@
#include <QDateTime> #include <QDateTime>
#include <libtorrent/session.hpp>
#include "base/bittorrent/session.h" #include "base/bittorrent/session.h"
#include "base/bittorrent/sessionstatus.h" #include "base/bittorrent/sessionstatus.h"
#include "base/profile.h" #include "base/profile.h"
static const qint64 SAVE_INTERVAL = 15 * 60 * 1000; static const qint64 SAVE_INTERVAL = 15 * 60 * 1000;
namespace libt = libtorrent;
using namespace BitTorrent; using namespace BitTorrent;
Statistics::Statistics(Session *session) Statistics::Statistics(Session *session)

6
src/base/bittorrent/session.cpp

@ -4299,11 +4299,11 @@ namespace
using PCONVERTIFACENAMETOLUID = NETIO_STATUS (WINAPI *)(const WCHAR *, PNET_LUID); using PCONVERTIFACENAMETOLUID = NETIO_STATUS (WINAPI *)(const WCHAR *, PNET_LUID);
const auto ConvertIfaceNameToLuid = Utils::Misc::loadWinAPI<PCONVERTIFACENAMETOLUID>("Iphlpapi.dll", "ConvertInterfaceNameToLuidW"); const auto ConvertIfaceNameToLuid = Utils::Misc::loadWinAPI<PCONVERTIFACENAMETOLUID>("Iphlpapi.dll", "ConvertInterfaceNameToLuidW");
if (!ConvertIfaceNameToLuid) return QString(); if (!ConvertIfaceNameToLuid) return {};
using PCONVERTIFACELUIDTOGUID = NETIO_STATUS (WINAPI *)(const NET_LUID *, GUID *); using PCONVERTIFACELUIDTOGUID = NETIO_STATUS (WINAPI *)(const NET_LUID *, GUID *);
const auto ConvertIfaceLuidToGuid = Utils::Misc::loadWinAPI<PCONVERTIFACELUIDTOGUID>("Iphlpapi.dll", "ConvertInterfaceLuidToGuid"); const auto ConvertIfaceLuidToGuid = Utils::Misc::loadWinAPI<PCONVERTIFACELUIDTOGUID>("Iphlpapi.dll", "ConvertInterfaceLuidToGuid");
if (!ConvertIfaceLuidToGuid) return QString(); if (!ConvertIfaceLuidToGuid) return {};
NET_LUID luid; NET_LUID luid;
const LONG res = ConvertIfaceNameToLuid(name.toStdWString().c_str(), &luid); const LONG res = ConvertIfaceNameToLuid(name.toStdWString().c_str(), &luid);
@ -4313,7 +4313,7 @@ namespace
return QUuid(guid).toString().toUpper(); return QUuid(guid).toString().toUpper();
} }
return QString(); return {};
} }
#endif #endif
} }

12
src/base/bittorrent/torrenthandle.cpp

@ -297,7 +297,7 @@ QString TorrentHandle::savePath(bool actual) const
QString TorrentHandle::rootPath(bool actual) const QString TorrentHandle::rootPath(bool actual) const
{ {
if ((filesCount() > 1) && !hasRootFolder()) if ((filesCount() > 1) && !hasRootFolder())
return QString(); return {};
const QString firstFilePath = filePath(0); const QString firstFilePath = filePath(0);
const int slashIndex = firstFilePath.indexOf('/'); const int slashIndex = firstFilePath.indexOf('/');
@ -593,7 +593,7 @@ QString TorrentHandle::filePath(int index) const
QString TorrentHandle::fileName(int index) const QString TorrentHandle::fileName(int index) const
{ {
if (!hasMetadata()) return QString(); if (!hasMetadata()) return {};
return Utils::Fs::fileName(filePath(index)); return Utils::Fs::fileName(filePath(index));
} }
@ -606,7 +606,7 @@ qlonglong TorrentHandle::fileSize(int index) const
// to all files in a torrent // to all files in a torrent
QStringList TorrentHandle::absoluteFilePaths() const QStringList TorrentHandle::absoluteFilePaths() const
{ {
if (!hasMetadata()) return QStringList(); if (!hasMetadata()) return {};
const QDir saveDir(savePath(true)); const QDir saveDir(savePath(true));
QStringList res; QStringList res;
@ -617,7 +617,7 @@ QStringList TorrentHandle::absoluteFilePaths() const
QStringList TorrentHandle::absoluteFilePathsUnwanted() const QStringList TorrentHandle::absoluteFilePathsUnwanted() const
{ {
if (!hasMetadata()) return QStringList(); if (!hasMetadata()) return {};
const QDir saveDir(savePath(true)); const QDir saveDir(savePath(true));
QStringList res; QStringList res;
@ -987,7 +987,7 @@ QDateTime TorrentHandle::lastSeenComplete() const
if (m_nativeStatus.last_seen_complete > 0) if (m_nativeStatus.last_seen_complete > 0)
return QDateTime::fromTime_t(m_nativeStatus.last_seen_complete); return QDateTime::fromTime_t(m_nativeStatus.last_seen_complete);
else else
return QDateTime(); return {};
} }
QDateTime TorrentHandle::completedTime() const QDateTime TorrentHandle::completedTime() const
@ -995,7 +995,7 @@ QDateTime TorrentHandle::completedTime() const
if (m_nativeStatus.completed_time > 0) if (m_nativeStatus.completed_time > 0)
return QDateTime::fromTime_t(m_nativeStatus.completed_time); return QDateTime::fromTime_t(m_nativeStatus.completed_time);
else else
return QDateTime(); return {};
} }
int TorrentHandle::timeSinceUpload() const int TorrentHandle::timeSinceUpload() const

24
src/base/bittorrent/torrentinfo.cpp

@ -133,32 +133,32 @@ bool TorrentInfo::isValid() const
InfoHash TorrentInfo::hash() const InfoHash TorrentInfo::hash() const
{ {
if (!isValid()) return InfoHash(); if (!isValid()) return {};
return m_nativeInfo->info_hash(); return m_nativeInfo->info_hash();
} }
QString TorrentInfo::name() const QString TorrentInfo::name() const
{ {
if (!isValid()) return QString(); if (!isValid()) return {};
return QString::fromStdString(m_nativeInfo->name()); return QString::fromStdString(m_nativeInfo->name());
} }
QDateTime TorrentInfo::creationDate() const QDateTime TorrentInfo::creationDate() const
{ {
if (!isValid()) return QDateTime(); if (!isValid()) return {};
const boost::optional<time_t> t = m_nativeInfo->creation_date(); const boost::optional<time_t> t = m_nativeInfo->creation_date();
return t ? QDateTime::fromTime_t(*t) : QDateTime(); return t ? QDateTime::fromTime_t(*t) : QDateTime();
} }
QString TorrentInfo::creator() const QString TorrentInfo::creator() const
{ {
if (!isValid()) return QString(); if (!isValid()) return {};
return QString::fromStdString(m_nativeInfo->creator()); return QString::fromStdString(m_nativeInfo->creator());
} }
QString TorrentInfo::comment() const QString TorrentInfo::comment() const
{ {
if (!isValid()) return QString(); if (!isValid()) return {};
return QString::fromStdString(m_nativeInfo->comment()); return QString::fromStdString(m_nativeInfo->comment());
} }
@ -200,7 +200,7 @@ int TorrentInfo::piecesCount() const
QString TorrentInfo::filePath(const int index) const QString TorrentInfo::filePath(const int index) const
{ {
if (!isValid()) return QString(); if (!isValid()) return {};
return Utils::Fs::fromNativePath(QString::fromStdString(m_nativeInfo->files().file_path(index))); return Utils::Fs::fromNativePath(QString::fromStdString(m_nativeInfo->files().file_path(index)));
} }
@ -220,7 +220,7 @@ QString TorrentInfo::fileName(const int index) const
QString TorrentInfo::origFilePath(const int index) const QString TorrentInfo::origFilePath(const int index) const
{ {
if (!isValid()) return QString(); if (!isValid()) return {};
return Utils::Fs::fromNativePath(QString::fromStdString(m_nativeInfo->orig_files().file_path(index))); return Utils::Fs::fromNativePath(QString::fromStdString(m_nativeInfo->orig_files().file_path(index)));
} }
@ -238,7 +238,7 @@ qlonglong TorrentInfo::fileOffset(const int index) const
QList<TrackerEntry> TorrentInfo::trackers() const QList<TrackerEntry> TorrentInfo::trackers() const
{ {
if (!isValid()) return QList<TrackerEntry>(); if (!isValid()) return {};
QList<TrackerEntry> trackers; QList<TrackerEntry> trackers;
for (const libt::announce_entry &tracker : m_nativeInfo->trackers()) for (const libt::announce_entry &tracker : m_nativeInfo->trackers())
@ -249,7 +249,7 @@ QList<TrackerEntry> TorrentInfo::trackers() const
QList<QUrl> TorrentInfo::urlSeeds() const QList<QUrl> TorrentInfo::urlSeeds() const
{ {
if (!isValid()) return QList<QUrl>(); if (!isValid()) return {};
QList<QUrl> urlSeeds; QList<QUrl> urlSeeds;
for (const libt::web_seed_entry &webSeed : m_nativeInfo->web_seeds()) for (const libt::web_seed_entry &webSeed : m_nativeInfo->web_seeds())
@ -261,8 +261,8 @@ QList<QUrl> TorrentInfo::urlSeeds() const
QByteArray TorrentInfo::metadata() const QByteArray TorrentInfo::metadata() const
{ {
if (!isValid()) return QByteArray(); if (!isValid()) return {};
return QByteArray(m_nativeInfo->metadata().get(), m_nativeInfo->metadata_size()); return {m_nativeInfo->metadata().get(), m_nativeInfo->metadata_size()};
} }
QStringList TorrentInfo::filesForPiece(const int pieceIndex) const QStringList TorrentInfo::filesForPiece(const int pieceIndex) const
@ -281,7 +281,7 @@ QStringList TorrentInfo::filesForPiece(const int pieceIndex) const
QVector<int> TorrentInfo::fileIndicesForPiece(const int pieceIndex) const QVector<int> TorrentInfo::fileIndicesForPiece(const int pieceIndex) const
{ {
if (!isValid() || (pieceIndex < 0) || (pieceIndex >= piecesCount())) if (!isValid() || (pieceIndex < 0) || (pieceIndex >= piecesCount()))
return QVector<int>(); return {};
const std::vector<libt::file_slice> files( const std::vector<libt::file_slice> files(
nativeInfo()->map_block(pieceIndex, 0, nativeInfo()->piece_size(pieceIndex))); nativeInfo()->map_block(pieceIndex, 0, nativeInfo()->piece_size(pieceIndex)));

8
src/base/bittorrent/trackerentry.cpp

@ -59,12 +59,12 @@ TrackerEntry::Status TrackerEntry::status() const
// true when the tracker hasn't been tried yet. // true when the tracker hasn't been tried yet.
if (m_nativeEntry.verified && m_nativeEntry.is_working()) if (m_nativeEntry.verified && m_nativeEntry.is_working())
return Working; return Working;
else if ((m_nativeEntry.fails == 0) && m_nativeEntry.updating) if ((m_nativeEntry.fails == 0) && m_nativeEntry.updating)
return Updating; return Updating;
else if (m_nativeEntry.fails == 0) if (m_nativeEntry.fails == 0)
return NotContacted; return NotContacted;
else
return NotWorking; return NotWorking;
} }
void TrackerEntry::setTier(const int value) void TrackerEntry::setTier(const int value)

4
src/base/http/server.cpp

@ -74,7 +74,7 @@ Server::Server(IRequestHandler *requestHandler, QObject *parent)
setProxy(QNetworkProxy::NoProxy); setProxy(QNetworkProxy::NoProxy);
QSslSocket::setDefaultCiphers(safeCipherList()); QSslSocket::setDefaultCiphers(safeCipherList());
QTimer *dropConnectionTimer = new QTimer(this); auto *dropConnectionTimer = new QTimer(this);
connect(dropConnectionTimer, &QTimer::timeout, this, &Server::dropTimedOutConnection); connect(dropConnectionTimer, &QTimer::timeout, this, &Server::dropTimedOutConnection);
dropConnectionTimer->start(CONNECTIONS_SCAN_INTERVAL * 1000); dropConnectionTimer->start(CONNECTIONS_SCAN_INTERVAL * 1000);
} }
@ -102,7 +102,7 @@ void Server::incomingConnection(qintptr socketDescriptor)
static_cast<QSslSocket *>(serverSocket)->startServerEncryption(); static_cast<QSslSocket *>(serverSocket)->startServerEncryption();
} }
Connection *c = new Connection(serverSocket, m_requestHandler, this); auto *c = new Connection(serverSocket, m_requestHandler, this);
m_connections.append(c); m_connections.append(c);
} }

4
src/base/logger.cpp

@ -98,7 +98,7 @@ QVector<Log::Msg> Logger::getMessages(int lastKnownId) const
return m_messages; return m_messages;
if (diff <= 0) if (diff <= 0)
return QVector<Log::Msg>(); return {};
return m_messages.mid(size - diff); return m_messages.mid(size - diff);
} }
@ -114,7 +114,7 @@ QVector<Log::Peer> Logger::getPeers(int lastKnownId) const
return m_peers; return m_peers;
if (diff <= 0) if (diff <= 0)
return QVector<Log::Peer>(); return {};
return m_peers.mid(size - diff); return m_peers.mid(size - diff);
} }

6
src/base/net/dnsupdater.cpp

@ -288,11 +288,11 @@ QUrl DNSUpdater::getRegistrationUrl(int service)
{ {
switch (service) { switch (service) {
case DNS::DYNDNS: case DNS::DYNDNS:
return QUrl("https://www.dyndns.com/account/services/hosts/add.html"); return {"https://www.dyndns.com/account/services/hosts/add.html"};
case DNS::NOIP: case DNS::NOIP:
return QUrl("https://www.noip.com/remote-access"); return {"https://www.noip.com/remote-access"};
default: default:
Q_ASSERT(0); Q_ASSERT(0);
} }
return QUrl(); return {};
} }

2
src/base/net/geoipmanager.cpp

@ -129,7 +129,7 @@ QString GeoIPManager::lookup(const QHostAddress &hostAddr) const
if (m_enabled && m_geoIPDatabase) if (m_enabled && m_geoIPDatabase)
return m_geoIPDatabase->lookup(hostAddr); return m_geoIPDatabase->lookup(hostAddr);
return QString(); return {};
} }
QString GeoIPManager::CountryName(const QString &countryISOCode) QString GeoIPManager::CountryName(const QString &countryISOCode)

29
src/base/net/private/geoipdatabase.cpp

@ -171,14 +171,14 @@ QString GeoIPDatabase::lookup(const QHostAddress &hostAddr) const
ptr += m_recordBytes; ptr += m_recordBytes;
quint32 id = 0; quint32 id = 0;
uchar *idPtr = reinterpret_cast<uchar *>(&id); auto *idPtr = reinterpret_cast<uchar *>(&id);
memcpy(&idPtr[4 - m_recordBytes], ptr, m_recordBytes); memcpy(&idPtr[4 - m_recordBytes], ptr, m_recordBytes);
fromBigEndian(idPtr, 4); fromBigEndian(idPtr, 4);
if (id == m_nodeCount) { if (id == m_nodeCount) {
return QString(); return {};
} }
else if (id > m_nodeCount) { if (id > m_nodeCount) {
QString country = m_countries.value(id); QString country = m_countries.value(id);
if (country.isEmpty()) { if (country.isEmpty()) {
const quint32 offset = id - m_nodeCount - sizeof(DATA_SECTION_SEPARATOR); const quint32 offset = id - m_nodeCount - sizeof(DATA_SECTION_SEPARATOR);
@ -191,13 +191,12 @@ QString GeoIPDatabase::lookup(const QHostAddress &hostAddr) const
} }
return country; return country;
} }
else {
ptr = m_data + (id * m_nodeSize); ptr = m_data + (id * m_nodeSize);
}
} }
} }
return QString(); return {};
} }
#define CHECK_METADATA_REQ(key, type) \ #define CHECK_METADATA_REQ(key, type) \
@ -205,7 +204,7 @@ if (!metadata.contains(#key)) { \
error = errMsgNotFound.arg(#key); \ error = errMsgNotFound.arg(#key); \
return false; \ return false; \
} \ } \
else if (metadata.value(#key).userType() != QMetaType::type) { \ if (metadata.value(#key).userType() != QMetaType::type) { \
error = errMsgInvalid.arg(#key); \ error = errMsgInvalid.arg(#key); \
return false; \ return false; \
} }
@ -299,20 +298,20 @@ QVariantHash GeoIPDatabase::readMetadata() const
if (index >= 0) { if (index >= 0) {
if (m_size > MAX_METADATA_SIZE) if (m_size > MAX_METADATA_SIZE)
index += (m_size - MAX_METADATA_SIZE); // from begin of all data index += (m_size - MAX_METADATA_SIZE); // from begin of all data
quint32 offset = static_cast<quint32>(index + strlen(METADATA_BEGIN_MARK)); auto offset = static_cast<quint32>(index + strlen(METADATA_BEGIN_MARK));
QVariant metadata = readDataField(offset); QVariant metadata = readDataField(offset);
if (metadata.userType() == QMetaType::QVariantHash) if (metadata.userType() == QMetaType::QVariantHash)
return metadata.toHash(); return metadata.toHash();
} }
return QVariantHash(); return {};
} }
QVariant GeoIPDatabase::readDataField(quint32 &offset) const QVariant GeoIPDatabase::readDataField(quint32 &offset) const
{ {
DataFieldDescriptor descr; DataFieldDescriptor descr;
if (!readDataFieldDescriptor(offset, descr)) if (!readDataFieldDescriptor(offset, descr))
return QVariant(); return {};
quint32 locOffset = offset; quint32 locOffset = offset;
bool usePointer = false; bool usePointer = false;
@ -321,7 +320,7 @@ QVariant GeoIPDatabase::readDataField(quint32 &offset) const
// convert offset from data section to global // convert offset from data section to global
locOffset = descr.offset + (m_nodeCount * m_recordSize / 4) + sizeof(DATA_SECTION_SEPARATOR); locOffset = descr.offset + (m_nodeCount * m_recordSize / 4) + sizeof(DATA_SECTION_SEPARATOR);
if (!readDataFieldDescriptor(locOffset, descr)) if (!readDataFieldDescriptor(locOffset, descr))
return QVariant(); return {};
} }
QVariant fieldValue; QVariant fieldValue;
@ -460,12 +459,12 @@ QVariant GeoIPDatabase::readMapValue(quint32 &offset, quint32 count) const
for (quint32 i = 0; i < count; ++i) { for (quint32 i = 0; i < count; ++i) {
QVariant field = readDataField(offset); QVariant field = readDataField(offset);
if (field.userType() != QMetaType::QString) if (field.userType() != QMetaType::QString)
return QVariant(); return {};
QString key = field.toString(); QString key = field.toString();
field = readDataField(offset); field = readDataField(offset);
if (field.userType() == QVariant::Invalid) if (field.userType() == QVariant::Invalid)
return QVariant(); return {};
map[key] = field; map[key] = field;
} }
@ -480,7 +479,7 @@ QVariant GeoIPDatabase::readArrayValue(quint32 &offset, quint32 count) const
for (quint32 i = 0; i < count; ++i) { for (quint32 i = 0; i < count; ++i) {
QVariant field = readDataField(offset); QVariant field = readDataField(offset);
if (field.userType() == QVariant::Invalid) if (field.userType() == QVariant::Invalid)
return QVariant(); return {};
array.append(field); array.append(field);
} }

20
src/base/rss/private/rss_parser.cpp

@ -464,7 +464,7 @@ namespace
offset = parts[2].toInt(&ok[0]) * 3600; offset = parts[2].toInt(&ok[0]) * 3600;
int offsetMin = parts[3].toInt(&ok[1]); int offsetMin = parts[3].toInt(&ok[1]);
if (!ok[0] || !ok[1] || offsetMin > 59) if (!ok[0] || !ok[1] || offsetMin > 59)
return QDateTime(); return {};
offset += offsetMin * 60; offset += offsetMin * 60;
negOffset = (parts[1] == QLatin1String("-")); negOffset = (parts[1] == QLatin1String("-"));
if (negOffset) if (negOffset)
@ -494,7 +494,7 @@ namespace
for (int i = 0, end = zone.size(); (i < end) && !nonalpha; ++i) for (int i = 0, end = zone.size(); (i < end) && !nonalpha; ++i)
nonalpha = !isalpha(zone[i]); nonalpha = !isalpha(zone[i]);
if (nonalpha) if (nonalpha)
return QDateTime(); return {};
// TODO: Attempt to recognize the time zone abbreviation? // TODO: Attempt to recognize the time zone abbreviation?
negOffset = true; // unknown time zone: RFC 2822 treats as '-0000' negOffset = true; // unknown time zone: RFC 2822 treats as '-0000'
} }
@ -556,22 +556,20 @@ void Parser::parse_impl(const QByteArray &feedData)
foundChannel = true; foundChannel = true;
break; break;
} }
else {
qDebug() << "Skip rss item: " << xml.name(); qDebug() << "Skip rss item: " << xml.name();
xml.skipCurrentElement(); xml.skipCurrentElement();
}
} }
break; break;
} }
else if (xml.name() == "feed") { // Atom feed if (xml.name() == "feed") { // Atom feed
parseAtomChannel(xml); parseAtomChannel(xml);
foundChannel = true; foundChannel = true;
break; break;
} }
else {
qDebug() << "Skip root item: " << xml.name(); qDebug() << "Skip root item: " << xml.name();
xml.skipCurrentElement(); xml.skipCurrentElement();
}
} }
if (!foundChannel) { if (!foundChannel) {

4
src/base/rss/rss_autodownloadrule.cpp

@ -68,7 +68,7 @@ namespace
switch (static_cast<int>(triStateBool)) { switch (static_cast<int>(triStateBool)) {
case 0: return false; case 0: return false;
case 1: return true; case 1: return true;
default: return QJsonValue(); default: return {};
} }
} }
@ -159,7 +159,7 @@ QString computeEpisodeName(const QString &article)
// See if we can extract an season/episode number or date from the title // See if we can extract an season/episode number or date from the title
if (!match.hasMatch()) if (!match.hasMatch())
return QString(); return {};
QStringList ret; QStringList ret;
for (int i = 1; i <= match.lastCapturedIndex(); ++i) { for (int i = 1; i <= match.lastCapturedIndex(); ++i) {

4
src/base/rss/rss_item.cpp

@ -81,8 +81,8 @@ QString Item::joinPath(const QString &path1, const QString &path2)
{ {
if (path1.isEmpty()) if (path1.isEmpty())
return path2; return path2;
else
return path1 + Item::PathSeparator + path2; return (path1 + Item::PathSeparator + path2);
} }
QStringList Item::expandPath(const QString &path) QStringList Item::expandPath(const QString &path)

10
src/base/scanfoldersmodel.cpp

@ -107,7 +107,7 @@ int ScanFoldersModel::columnCount(const QModelIndex &parent) const
QVariant ScanFoldersModel::data(const QModelIndex &index, int role) const QVariant ScanFoldersModel::data(const QModelIndex &index, int role) const
{ {
if (!index.isValid() || (index.row() >= rowCount())) if (!index.isValid() || (index.row() >= rowCount()))
return QVariant(); return {};
const PathData *pathData = m_pathList.at(index.row()); const PathData *pathData = m_pathList.at(index.row());
QVariant value; QVariant value;
@ -141,7 +141,7 @@ QVariant ScanFoldersModel::data(const QModelIndex &index, int role) const
QVariant ScanFoldersModel::headerData(int section, Qt::Orientation orientation, int role) const QVariant ScanFoldersModel::headerData(int section, Qt::Orientation orientation, int role) const
{ {
if ((orientation != Qt::Horizontal) || (role != Qt::DisplayRole) || (section < 0) || (section >= columnCount())) if ((orientation != Qt::Horizontal) || (role != Qt::DisplayRole) || (section < 0) || (section >= columnCount()))
return QVariant(); return {};
QVariant title; QVariant title;
@ -183,7 +183,7 @@ bool ScanFoldersModel::setData(const QModelIndex &index, const QVariant &value,
return false; return false;
if (role == Qt::UserRole) { if (role == Qt::UserRole) {
PathType type = static_cast<PathType>(value.toInt()); auto type = static_cast<PathType>(value.toInt());
if (type == CUSTOM_LOCATION) if (type == CUSTOM_LOCATION)
return false; return false;
@ -311,7 +311,7 @@ QString ScanFoldersModel::downloadPathTorrentFolder(const QString &filePath) con
if (data->downloadType == CUSTOM_LOCATION) if (data->downloadType == CUSTOM_LOCATION)
return data->downloadPath; return data->downloadPath;
return QString(); return {};
} }
int ScanFoldersModel::findPathData(const QString &path) const int ScanFoldersModel::findPathData(const QString &path) const
@ -399,5 +399,5 @@ QString ScanFoldersModel::pathTypeDisplayName(const PathType type)
default: default:
qDebug("Invalid PathType: %d", type); qDebug("Invalid PathType: %d", type);
}; };
return QString(); return {};
} }

4
src/base/settingsstorage.cpp

@ -282,7 +282,7 @@ QString TransactionalSettings::deserialize(const QString &name, QVariantHash &da
SettingsPtr settings = Profile::instance().applicationSettings(name); SettingsPtr settings = Profile::instance().applicationSettings(name);
if (settings->allKeys().isEmpty()) if (settings->allKeys().isEmpty())
return QString(); return {};
// Copy everything into memory. This means even keys inserted in the file manually // Copy everything into memory. This means even keys inserted in the file manually
// or that we don't touch directly in this code (eg disabled by ifdef). This ensures // or that we don't touch directly in this code (eg disabled by ifdef). This ensures
@ -314,5 +314,5 @@ QString TransactionalSettings::serialize(const QString &name, const QVariantHash
Logger::instance()->addMessage(QObject::tr("An unknown error occurred while trying to write the configuration file."), Log::CRITICAL); Logger::instance()->addMessage(QObject::tr("An unknown error occurred while trying to write the configuration file."), Log::CRITICAL);
break; break;
} }
return QString(); return {};
} }

1
src/base/torrentfileguard.cpp

@ -86,4 +86,3 @@ CachedSettingValue<TorrentFileGuard::AutoDeleteMode> &TorrentFileGuard::autoDele
static CachedSettingValue<AutoDeleteMode> setting("Core/AutoDeleteAddedTorrentFile", AutoDeleteMode::Never); static CachedSettingValue<AutoDeleteMode> setting("Core/AutoDeleteAddedTorrentFile", AutoDeleteMode::Never);
return setting; return setting;
} }

5
src/base/torrentfileguard.h

@ -26,8 +26,7 @@
* exception statement from your version. * exception statement from your version.
*/ */
#ifndef TOFFENTFILEGURAD_H #pragma once
#define TOFFENTFILEGURAD_H
#include <QObject> #include <QObject>
#include <QString> #include <QString>
@ -82,5 +81,3 @@ private:
AutoDeleteMode m_mode; AutoDeleteMode m_mode;
bool m_wasAdded; bool m_wasAdded;
}; };
#endif // TOFFENTFILEGURAD_H

12
src/base/torrentfilter.cpp

@ -44,7 +44,6 @@ const TorrentFilter TorrentFilter::InactiveTorrent(TorrentFilter::Inactive);
const TorrentFilter TorrentFilter::ErroredTorrent(TorrentFilter::Errored); const TorrentFilter TorrentFilter::ErroredTorrent(TorrentFilter::Errored);
using BitTorrent::TorrentHandle; using BitTorrent::TorrentHandle;
using BitTorrent::TorrentState;
TorrentFilter::TorrentFilter() TorrentFilter::TorrentFilter()
: m_type(All) : m_type(All)
@ -174,19 +173,22 @@ bool TorrentFilter::matchState(const BitTorrent::TorrentHandle *const torrent) c
bool TorrentFilter::matchHash(const BitTorrent::TorrentHandle *const torrent) const bool TorrentFilter::matchHash(const BitTorrent::TorrentHandle *const torrent) const
{ {
if (m_hashSet == AnyHash) return true; if (m_hashSet == AnyHash) return true;
else return m_hashSet.contains(torrent->hash());
return m_hashSet.contains(torrent->hash());
} }
bool TorrentFilter::matchCategory(const BitTorrent::TorrentHandle *const torrent) const bool TorrentFilter::matchCategory(const BitTorrent::TorrentHandle *const torrent) const
{ {
if (m_category.isNull()) return true; if (m_category.isNull()) return true;
else return (torrent->belongsToCategory(m_category));
return (torrent->belongsToCategory(m_category));
} }
bool TorrentFilter::matchTag(const BitTorrent::TorrentHandle *const torrent) const bool TorrentFilter::matchTag(const BitTorrent::TorrentHandle *const torrent) const
{ {
// Empty tag is a special value to indicate we're filtering for untagged torrents. // Empty tag is a special value to indicate we're filtering for untagged torrents.
if (m_tag.isNull()) return true; if (m_tag.isNull()) return true;
else if (m_tag.isEmpty()) return torrent->tags().isEmpty(); if (m_tag.isEmpty()) return torrent->tags().isEmpty();
else return (torrent->hasTag(m_tag));
return (torrent->hasTag(m_tag));
} }

2
src/base/utils/foreignapps.cpp

@ -227,7 +227,7 @@ namespace
return path; return path;
} }
return QString(); return {};
} }
#endif // Q_OS_WIN #endif // Q_OS_WIN
} }

8
src/base/utils/misc.cpp

@ -97,7 +97,7 @@ namespace
if (sizeInBytes < 0) return false; if (sizeInBytes < 0) return false;
int i = 0; int i = 0;
qreal rawVal = static_cast<qreal>(sizeInBytes); auto rawVal = static_cast<qreal>(sizeInBytes);
while ((rawVal >= 1024.) && (i <= static_cast<int>(Utils::Misc::SizeUnit::ExbiByte))) { while ((rawVal >= 1024.) && (i <= static_cast<int>(Utils::Misc::SizeUnit::ExbiByte))) {
rawVal /= 1024.; rawVal /= 1024.;
@ -256,7 +256,7 @@ QPoint Utils::Misc::screenCenter(const QWidget *w)
QDesktopWidget *desktop = QApplication::desktop(); QDesktopWidget *desktop = QApplication::desktop();
int scrn = desktop->screenNumber(parent); // fallback to `primaryScreen` when parent is invalid int scrn = desktop->screenNumber(parent); // fallback to `primaryScreen` when parent is invalid
QRect r = desktop->availableGeometry(scrn); QRect r = desktop->availableGeometry(scrn);
return QPoint(r.x() + (r.width() - w->frameSize().width()) / 2, r.y() + (r.height() - w->frameSize().height()) / 2); return {r.x() + (r.width() - w->frameSize().width()) / 2, r.y() + (r.height() - w->frameSize().height()) / 2};
} }
#endif #endif
@ -285,8 +285,8 @@ int Utils::Misc::friendlyUnitPrecision(SizeUnit unit)
// friendlyUnit's number of digits after the decimal point // friendlyUnit's number of digits after the decimal point
if (unit == SizeUnit::Byte) return 0; if (unit == SizeUnit::Byte) return 0;
if (unit <= SizeUnit::MebiByte) return 1; if (unit <= SizeUnit::MebiByte) return 1;
else if (unit == SizeUnit::GibiByte) return 2; if (unit == SizeUnit::GibiByte) return 2;
else return 3; return 3;
} }
qlonglong Utils::Misc::sizeInBytes(qreal size, Utils::Misc::SizeUnit unit) qlonglong Utils::Misc::sizeInBytes(qreal size, Utils::Misc::SizeUnit unit)

2
src/base/utils/net.cpp

@ -110,7 +110,7 @@ namespace Utils
QSslKey key {data, QSsl::Rsa}; QSslKey key {data, QSsl::Rsa};
if (!key.isNull()) if (!key.isNull())
return key; return key;
return QSslKey(data, QSsl::Ec); return {data, QSsl::Ec};
} }
bool isSSLKeyValid(const QByteArray &data) bool isSSLKeyValid(const QByteArray &data)

2
src/gui/autoexpandabledialog.cpp

@ -71,7 +71,7 @@ QString AutoExpandableDialog::getText(QWidget *parent, const QString &title, con
if (ok) if (ok)
*ok = res; *ok = res;
if (!res) return QString(); if (!res) return {};
return d.m_ui->textEdit->text(); return d.m_ui->textEdit->text();
} }

20
src/gui/categoryfiltermodel.cpp

@ -207,7 +207,7 @@ int CategoryFilterModel::columnCount(const QModelIndex &) const
QVariant CategoryFilterModel::data(const QModelIndex &index, int role) const QVariant CategoryFilterModel::data(const QModelIndex &index, int role) const
{ {
if (!index.isValid()) return QVariant(); if (!index.isValid()) return {};
auto item = static_cast<CategoryModelItem *>(index.internalPointer()); auto item = static_cast<CategoryModelItem *>(index.internalPointer());
@ -224,7 +224,7 @@ QVariant CategoryFilterModel::data(const QModelIndex &index, int role) const
return item->torrentsCount(); return item->torrentsCount();
} }
return QVariant(); return {};
} }
Qt::ItemFlags CategoryFilterModel::flags(const QModelIndex &index) const Qt::ItemFlags CategoryFilterModel::flags(const QModelIndex &index) const
@ -240,32 +240,32 @@ QVariant CategoryFilterModel::headerData(int section, Qt::Orientation orientatio
if (section == 0) if (section == 0)
return tr("Categories"); return tr("Categories");
return QVariant(); return {};
} }
QModelIndex CategoryFilterModel::index(int row, int column, const QModelIndex &parent) const QModelIndex CategoryFilterModel::index(int row, int column, const QModelIndex &parent) const
{ {
if (column > 0) if (column > 0)
return QModelIndex(); return {};
if (parent.isValid() && (parent.column() != 0)) if (parent.isValid() && (parent.column() != 0))
return QModelIndex(); return {};
auto parentItem = parent.isValid() ? static_cast<CategoryModelItem *>(parent.internalPointer()) auto parentItem = parent.isValid() ? static_cast<CategoryModelItem *>(parent.internalPointer())
: m_rootItem; : m_rootItem;
if (row < parentItem->childCount()) if (row < parentItem->childCount())
return createIndex(row, column, parentItem->childAt(row)); return createIndex(row, column, parentItem->childAt(row));
return QModelIndex(); return {};
} }
QModelIndex CategoryFilterModel::parent(const QModelIndex &index) const QModelIndex CategoryFilterModel::parent(const QModelIndex &index) const
{ {
if (!index.isValid()) if (!index.isValid())
return QModelIndex(); return {};
auto item = static_cast<CategoryModelItem *>(index.internalPointer()); auto item = static_cast<CategoryModelItem *>(index.internalPointer());
if (!item) return QModelIndex(); if (!item) return {};
return this->index(item->parent()); return this->index(item->parent());
} }
@ -291,13 +291,13 @@ QModelIndex CategoryFilterModel::index(const QString &categoryName) const
QString CategoryFilterModel::categoryName(const QModelIndex &index) const QString CategoryFilterModel::categoryName(const QModelIndex &index) const
{ {
if (!index.isValid()) return QString(); if (!index.isValid()) return {};
return static_cast<CategoryModelItem *>(index.internalPointer())->fullName(); return static_cast<CategoryModelItem *>(index.internalPointer())->fullName();
} }
QModelIndex CategoryFilterModel::index(CategoryModelItem *item) const QModelIndex CategoryFilterModel::index(CategoryModelItem *item) const
{ {
if (!item || !item->parent()) return QModelIndex(); if (!item || !item->parent()) return {};
return index(item->pos(), 0, index(item->parent())); return index(item->pos(), 0, index(item->parent()));
} }

2
src/gui/categoryfilterwidget.cpp

@ -59,7 +59,7 @@ namespace
CategoryFilterWidget::CategoryFilterWidget(QWidget *parent) CategoryFilterWidget::CategoryFilterWidget(QWidget *parent)
: QTreeView(parent) : QTreeView(parent)
{ {
CategoryFilterProxyModel *proxyModel = new CategoryFilterProxyModel(this); auto *proxyModel = new CategoryFilterProxyModel(this);
proxyModel->setSortCaseSensitivity(Qt::CaseInsensitive); proxyModel->setSortCaseSensitivity(Qt::CaseInsensitive);
proxyModel->setSourceModel(new CategoryFilterModel(this)); proxyModel->setSourceModel(new CategoryFilterModel(this));
setModel(proxyModel); setModel(proxyModel);

12
src/gui/cookiesmodel.cpp

@ -58,7 +58,7 @@ QVariant CookiesModel::headerData(int section, Qt::Orientation orientation, int
} }
} }
return QVariant(); return {};
} }
QModelIndex CookiesModel::index(int row, int column, const QModelIndex &parent) const QModelIndex CookiesModel::index(int row, int column, const QModelIndex &parent) const
@ -66,7 +66,7 @@ QModelIndex CookiesModel::index(int row, int column, const QModelIndex &parent)
if (parent.isValid() // no items with valid parent if (parent.isValid() // no items with valid parent
|| (row < 0) || (row >= m_cookies.size()) || (row < 0) || (row >= m_cookies.size())
|| (column < 0) || (column >= NB_COLUMNS)) || (column < 0) || (column >= NB_COLUMNS))
return QModelIndex(); return {};
return createIndex(row, column, &m_cookies[row]); return createIndex(row, column, &m_cookies[row]);
} }
@ -74,7 +74,7 @@ QModelIndex CookiesModel::index(int row, int column, const QModelIndex &parent)
QModelIndex CookiesModel::parent(const QModelIndex &index) const QModelIndex CookiesModel::parent(const QModelIndex &index) const
{ {
Q_UNUSED(index); Q_UNUSED(index);
return QModelIndex(); return {};
} }
int CookiesModel::rowCount(const QModelIndex &parent) const int CookiesModel::rowCount(const QModelIndex &parent) const
@ -94,7 +94,7 @@ QVariant CookiesModel::data(const QModelIndex &index, int role) const
{ {
if (!index.isValid() || (index.row() >= m_cookies.size()) if (!index.isValid() || (index.row() >= m_cookies.size())
|| ((role != Qt::DisplayRole) && (role != Qt::EditRole))) || ((role != Qt::DisplayRole) && (role != Qt::EditRole)))
return QVariant(); return {};
switch (index.column()) { switch (index.column()) {
case COL_DOMAIN: case COL_DOMAIN:
@ -109,7 +109,7 @@ QVariant CookiesModel::data(const QModelIndex &index, int role) const
return m_cookies[index.row()].expirationDate(); return m_cookies[index.row()].expirationDate();
} }
return QVariant(); return {};
} }
bool CookiesModel::setData(const QModelIndex &index, const QVariant &value, int role) bool CookiesModel::setData(const QModelIndex &index, const QVariant &value, int role)
@ -157,7 +157,7 @@ bool CookiesModel::insertRows(int row, int count, const QModelIndex &parent)
bool CookiesModel::removeRows(int row, int count, const QModelIndex &parent) bool CookiesModel::removeRows(int row, int count, const QModelIndex &parent)
{ {
if ((m_cookies.size() == 0) if ((m_cookies.isEmpty())
|| (row >= m_cookies.size()) || (row >= m_cookies.size())
|| ((row + count) > m_cookies.size())) || ((row + count) > m_cookies.size()))
return false; return false;

2
src/gui/fspathedit.cpp

@ -184,7 +184,7 @@ FileSystemPathEdit::FileSystemPathEdit(Private::FileEditorWithCompletion *editor
Q_D(FileSystemPathEdit); Q_D(FileSystemPathEdit);
editor->widget()->setParent(this); editor->widget()->setParent(this);
QHBoxLayout *layout = new QHBoxLayout(this); auto *layout = new QHBoxLayout(this);
layout->setContentsMargins(0, 0, 0, 0); layout->setContentsMargins(0, 0, 0, 0);
layout->addWidget(editor->widget()); layout->addWidget(editor->widget());
layout->addWidget(d->m_browseBtn); layout->addWidget(d->m_browseBtn);

5
src/gui/fspathedit_p.cpp

@ -251,8 +251,7 @@ void Private::FileLineEdit::keyPressEvent(QKeyEvent *e)
showCompletionPopup(); showCompletionPopup();
} }
const FileSystemPathValidator *validator = auto *validator = qobject_cast<const FileSystemPathValidator *>(this->validator());
qobject_cast<const FileSystemPathValidator *>(this->validator());
if (validator) { if (validator) {
FileSystemPathValidator::TestResult lastTestResult = validator->lastTestResult(); FileSystemPathValidator::TestResult lastTestResult = validator->lastTestResult();
QValidator::State lastState = validator->lastValidationState(); QValidator::State lastState = validator->lastValidationState();
@ -312,7 +311,7 @@ QString Private::FileLineEdit::warningText(FileSystemPathValidator::TestResult r
case TestResult::CantWrite: case TestResult::CantWrite:
return tr("Does not have write permission in '%1'"); return tr("Does not have write permission in '%1'");
default: default:
return QString(); return {};
} }
} }

2
src/gui/guiiconprovider.cpp

@ -90,7 +90,7 @@ QIcon GuiIconProvider::getIcon(const QString &iconId, const QString &fallback) c
QIcon GuiIconProvider::getFlagIcon(const QString &countryIsoCode) const QIcon GuiIconProvider::getFlagIcon(const QString &countryIsoCode) const
{ {
if (countryIsoCode.isEmpty()) return QIcon(); if (countryIsoCode.isEmpty()) return {};
return QIcon(":/icons/flags/" + countryIsoCode.toLower() + ".svg"); return QIcon(":/icons/flags/" + countryIsoCode.toLower() + ".svg");
} }

2
src/gui/loglistwidget.cpp

@ -78,7 +78,7 @@ void LogListWidget::keyPressEvent(QKeyEvent *event)
void LogListWidget::appendLine(const QString &line, const Log::MsgType &type) void LogListWidget::appendLine(const QString &line, const Log::MsgType &type)
{ {
QListWidgetItem *item = new QListWidgetItem; auto *item = new QListWidgetItem;
// We need to use QLabel here to support rich text // We need to use QLabel here to support rich text
QLabel *lbl = new QLabel(line); QLabel *lbl = new QLabel(line);
lbl->setContentsMargins(4, 2, 4, 2); lbl->setContentsMargins(4, 2, 4, 2);

17
src/gui/mainwindow.cpp

@ -199,7 +199,7 @@ MainWindow::MainWindow(QWidget *parent)
m_ui->menuAutoShutdownOnDownloadsCompletion->setIcon(GuiIconProvider::instance()->getIcon("application-exit")); m_ui->menuAutoShutdownOnDownloadsCompletion->setIcon(GuiIconProvider::instance()->getIcon("application-exit"));
m_ui->actionManageCookies->setIcon(GuiIconProvider::instance()->getIcon("preferences-web-browser-cookies")); m_ui->actionManageCookies->setIcon(GuiIconProvider::instance()->getIcon("preferences-web-browser-cookies"));
QMenu *lockMenu = new QMenu(this); auto *lockMenu = new QMenu(this);
QAction *defineUiLockPasswdAct = lockMenu->addAction(tr("&Set Password")); QAction *defineUiLockPasswdAct = lockMenu->addAction(tr("&Set Password"));
connect(defineUiLockPasswdAct, &QAction::triggered, this, &MainWindow::defineUILockPassword); connect(defineUiLockPasswdAct, &QAction::triggered, this, &MainWindow::defineUILockPassword);
QAction *clearUiLockPasswdAct = lockMenu->addAction(tr("&Clear Password")); QAction *clearUiLockPasswdAct = lockMenu->addAction(tr("&Clear Password"));
@ -222,7 +222,7 @@ MainWindow::MainWindow(QWidget *parent)
m_splitter = new QSplitter(Qt::Horizontal, this); m_splitter = new QSplitter(Qt::Horizontal, this);
// vSplitter->setChildrenCollapsible(false); // vSplitter->setChildrenCollapsible(false);
QSplitter *hSplitter = new QSplitter(Qt::Vertical, this); auto *hSplitter = new QSplitter(Qt::Vertical, this);
hSplitter->setChildrenCollapsible(false); hSplitter->setChildrenCollapsible(false);
hSplitter->setFrameShape(QFrame::NoFrame); hSplitter->setFrameShape(QFrame::NoFrame);
@ -380,7 +380,7 @@ MainWindow::MainWindow(QWidget *parent)
QTimer::singleShot(0, this, &MainWindow::on_actionSearchWidget_triggered); QTimer::singleShot(0, this, &MainWindow::on_actionSearchWidget_triggered);
// Auto shutdown actions // Auto shutdown actions
QActionGroup *autoShutdownGroup = new QActionGroup(this); auto *autoShutdownGroup = new QActionGroup(this);
autoShutdownGroup->setExclusive(true); autoShutdownGroup->setExclusive(true);
autoShutdownGroup->addAction(m_ui->actionAutoShutdownDisabled); autoShutdownGroup->addAction(m_ui->actionAutoShutdownDisabled);
autoShutdownGroup->addAction(m_ui->actionAutoExit); autoShutdownGroup->addAction(m_ui->actionAutoExit);
@ -555,7 +555,7 @@ void MainWindow::addToolbarContextMenu()
m_toolbarMenu->addAction(textBesideIcons); m_toolbarMenu->addAction(textBesideIcons);
m_toolbarMenu->addAction(textUnderIcons); m_toolbarMenu->addAction(textUnderIcons);
m_toolbarMenu->addAction(followSystemStyle); m_toolbarMenu->addAction(followSystemStyle);
QActionGroup *textPositionGroup = new QActionGroup(m_toolbarMenu); auto *textPositionGroup = new QActionGroup(m_toolbarMenu);
textPositionGroup->addAction(iconsOnly); textPositionGroup->addAction(iconsOnly);
iconsOnly->setCheckable(true); iconsOnly->setCheckable(true);
textPositionGroup->addAction(textOnly); textPositionGroup->addAction(textOnly);
@ -567,7 +567,7 @@ void MainWindow::addToolbarContextMenu()
textPositionGroup->addAction(followSystemStyle); textPositionGroup->addAction(followSystemStyle);
followSystemStyle->setCheckable(true); followSystemStyle->setCheckable(true);
const Qt::ToolButtonStyle buttonStyle = static_cast<Qt::ToolButtonStyle>(pref->getToolbarTextPosition()); const auto buttonStyle = static_cast<Qt::ToolButtonStyle>(pref->getToolbarTextPosition());
if ((buttonStyle >= Qt::ToolButtonIconOnly) && (buttonStyle <= Qt::ToolButtonFollowStyle)) if ((buttonStyle >= Qt::ToolButtonIconOnly) && (buttonStyle <= Qt::ToolButtonFollowStyle))
m_ui->toolBar->setToolButtonStyle(buttonStyle); m_ui->toolBar->setToolButtonStyle(buttonStyle);
switch (buttonStyle) { switch (buttonStyle) {
@ -758,9 +758,8 @@ void MainWindow::tabChanged(int newTab)
m_searchFilterAction->setVisible(true); m_searchFilterAction->setVisible(true);
return; return;
} }
else { m_searchFilterAction->setVisible(false);
m_searchFilterAction->setVisible(false);
}
if (m_tabs->currentWidget() == m_searchWidget) { if (m_tabs->currentWidget() == m_searchWidget) {
qDebug("Changed tab to search engine, giving focus to search input"); qDebug("Changed tab to search engine, giving focus to search input");
m_searchWidget->giveFocusToSearchInput(); m_searchWidget->giveFocusToSearchInput();
@ -796,7 +795,7 @@ void MainWindow::cleanup()
#endif #endif
// remove all child widgets // remove all child widgets
while (QWidget *w = findChild<QWidget * >()) while (auto *w = findChild<QWidget *>())
delete w; delete w;
} }

28
src/gui/optionsdialog.cpp

@ -454,7 +454,7 @@ OptionsDialog::OptionsDialog(QWidget *parent)
m_ui->textTempPath->setMode(FileSystemPathEdit::Mode::DirectorySave); m_ui->textTempPath->setMode(FileSystemPathEdit::Mode::DirectorySave);
// disable mouse wheel event on widgets to avoid mis-selection // disable mouse wheel event on widgets to avoid mis-selection
WheelEventEater *wheelEventEater = new WheelEventEater(this); auto *wheelEventEater = new WheelEventEater(this);
for (QComboBox *widget : asConst(findChildren<QComboBox *>())) for (QComboBox *widget : asConst(findChildren<QComboBox *>()))
widget->installEventFilter(wheelEventEater); widget->installEventFilter(wheelEventEater);
for (QSpinBox *widget : asConst(findChildren<QSpinBox *>())) for (QSpinBox *widget : asConst(findChildren<QSpinBox *>()))
@ -548,7 +548,7 @@ void OptionsDialog::saveOptions()
// Load the translation // Load the translation
QString locale = getLocale(); QString locale = getLocale();
if (pref->getLocale() != locale) { if (pref->getLocale() != locale) {
QTranslator *translator = new QTranslator; auto *translator = new QTranslator;
if (translator->load(QLatin1String(":/lang/qbittorrent_") + locale)) if (translator->load(QLatin1String(":/lang/qbittorrent_") + locale))
qDebug("%s locale recognized, using translation.", qUtf8Printable(locale)); qDebug("%s locale recognized, using translation.", qUtf8Printable(locale));
else else
@ -592,7 +592,7 @@ void OptionsDialog::saveOptions()
m_ui->checkAssociateMagnetLinks->setEnabled(!m_ui->checkAssociateMagnetLinks->isChecked()); m_ui->checkAssociateMagnetLinks->setEnabled(!m_ui->checkAssociateMagnetLinks->isChecked());
} }
#endif #endif
Application *const app = static_cast<Application*>(QCoreApplication::instance()); auto *const app = static_cast<Application *>(QCoreApplication::instance());
app->setFileLoggerPath(m_ui->textFileLogPath->selectedPath()); app->setFileLoggerPath(m_ui->textFileLogPath->selectedPath());
app->setFileLoggerBackup(m_ui->checkFileLogBackup->isChecked()); app->setFileLoggerBackup(m_ui->checkFileLogBackup->isChecked());
app->setFileLoggerMaxSize(m_ui->spinFileLogSize->value() * 1024); app->setFileLoggerMaxSize(m_ui->spinFileLogSize->value() * 1024);
@ -1209,32 +1209,32 @@ int OptionsDialog::getMaxConnecs() const
{ {
if (!m_ui->checkMaxConnecs->isChecked()) if (!m_ui->checkMaxConnecs->isChecked())
return -1; return -1;
else
return m_ui->spinMaxConnec->value(); return m_ui->spinMaxConnec->value();
} }
int OptionsDialog::getMaxConnecsPerTorrent() const int OptionsDialog::getMaxConnecsPerTorrent() const
{ {
if (!m_ui->checkMaxConnecsPerTorrent->isChecked()) if (!m_ui->checkMaxConnecsPerTorrent->isChecked())
return -1; return -1;
else
return m_ui->spinMaxConnecPerTorrent->value(); return m_ui->spinMaxConnecPerTorrent->value();
} }
int OptionsDialog::getMaxUploads() const int OptionsDialog::getMaxUploads() const
{ {
if (!m_ui->checkMaxUploads->isChecked()) if (!m_ui->checkMaxUploads->isChecked())
return -1; return -1;
else
return m_ui->spinMaxUploads->value(); return m_ui->spinMaxUploads->value();
} }
int OptionsDialog::getMaxUploadsPerTorrent() const int OptionsDialog::getMaxUploadsPerTorrent() const
{ {
if (!m_ui->checkMaxUploadsPerTorrent->isChecked()) if (!m_ui->checkMaxUploadsPerTorrent->isChecked())
return -1; return -1;
else
return m_ui->spinMaxUploadsPerTorrent->value(); return m_ui->spinMaxUploadsPerTorrent->value();
} }
void OptionsDialog::on_buttonBox_accepted() void OptionsDialog::on_buttonBox_accepted()
@ -1447,14 +1447,14 @@ QString OptionsDialog::getTorrentExportDir() const
{ {
if (m_ui->checkExportDir->isChecked()) if (m_ui->checkExportDir->isChecked())
return Utils::Fs::expandPathAbs(m_ui->textExportDir->selectedPath()); return Utils::Fs::expandPathAbs(m_ui->textExportDir->selectedPath());
return QString(); return {};
} }
QString OptionsDialog::getFinishedTorrentExportDir() const QString OptionsDialog::getFinishedTorrentExportDir() const
{ {
if (m_ui->checkExportDirFin->isChecked()) if (m_ui->checkExportDirFin->isChecked())
return Utils::Fs::expandPathAbs(m_ui->textExportDirFin->selectedPath()); return Utils::Fs::expandPathAbs(m_ui->textExportDirFin->selectedPath());
return QString(); return {};
} }
// Return action on double-click on a downloading torrent set in options // Return action on double-click on a downloading torrent set in options
@ -1645,7 +1645,7 @@ QString OptionsDialog::languageToLocalizedString(const QLocale &locale)
case QLocale::English: { case QLocale::English: {
if (locale.country() == QLocale::Australia) if (locale.country() == QLocale::Australia)
return QString::fromUtf8(C_LOCALE_ENGLISH_AUSTRALIA); return QString::fromUtf8(C_LOCALE_ENGLISH_AUSTRALIA);
else if (locale.country() == QLocale::UnitedKingdom) if (locale.country() == QLocale::UnitedKingdom)
return QString::fromUtf8(C_LOCALE_ENGLISH_UNITEDKINGDOM); return QString::fromUtf8(C_LOCALE_ENGLISH_UNITEDKINGDOM);
return QString::fromUtf8(C_LOCALE_ENGLISH); return QString::fromUtf8(C_LOCALE_ENGLISH);
} }

4
src/gui/powermanagement/powermanagement_x11.cpp

@ -82,7 +82,7 @@ void PowerManagementInhibitor::requestIdle()
call.setArguments(args); call.setArguments(args);
QDBusPendingCall pcall = QDBusConnection::sessionBus().asyncCall(call, 1000); QDBusPendingCall pcall = QDBusConnection::sessionBus().asyncCall(call, 1000);
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pcall, this); auto *watcher = new QDBusPendingCallWatcher(pcall, this);
connect(watcher, &QDBusPendingCallWatcher::finished, this, &PowerManagementInhibitor::onAsyncReply); connect(watcher, &QDBusPendingCallWatcher::finished, this, &PowerManagementInhibitor::onAsyncReply);
} }
@ -119,7 +119,7 @@ void PowerManagementInhibitor::requestBusy()
call.setArguments(args); call.setArguments(args);
QDBusPendingCall pcall = QDBusConnection::sessionBus().asyncCall(call, 1000); QDBusPendingCall pcall = QDBusConnection::sessionBus().asyncCall(call, 1000);
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pcall, this); auto *watcher = new QDBusPendingCallWatcher(pcall, this);
connect(watcher, &QDBusPendingCallWatcher::finished, this, &PowerManagementInhibitor::onAsyncReply); connect(watcher, &QDBusPendingCallWatcher::finished, this, &PowerManagementInhibitor::onAsyncReply);
} }

2
src/gui/previewselectdialog.cpp

@ -124,7 +124,7 @@ PreviewSelectDialog::~PreviewSelectDialog()
void PreviewSelectDialog::previewButtonClicked() void PreviewSelectDialog::previewButtonClicked()
{ {
QModelIndexList selectedIndexes = previewList->selectionModel()->selectedRows(FILE_INDEX); QModelIndexList selectedIndexes = previewList->selectionModel()->selectedRows(FILE_INDEX);
if (selectedIndexes.size() == 0) return; if (selectedIndexes.isEmpty()) return;
// Flush data // Flush data
m_torrent->flushCache(); m_torrent->flushCache();

2
src/gui/programupdater.cpp

@ -166,6 +166,6 @@ namespace
if (xml.isCharacters() && !xml.isWhitespace()) if (xml.isCharacters() && !xml.isWhitespace())
return xml.text().toString(); return xml.text().toString();
return QString(); return {};
} }
} }

5
src/gui/properties/piecesbar.cpp

@ -147,9 +147,8 @@ bool PiecesBar::event(QEvent *e)
showToolTip(static_cast<QHelpEvent *>(e)); showToolTip(static_cast<QHelpEvent *>(e));
return true; return true;
} }
else {
return base::event(e); return base::event(e);
}
} }
void PiecesBar::enterEvent(QEvent *e) void PiecesBar::enterEvent(QEvent *e)

8
src/gui/properties/propertieswidget.cpp

@ -198,7 +198,7 @@ void PropertiesWidget::showPiecesDownloaded(bool show)
void PropertiesWidget::setVisibility(bool visible) void PropertiesWidget::setVisibility(bool visible)
{ {
if (!visible && (m_state == VISIBLE)) { if (!visible && (m_state == VISIBLE)) {
QSplitter *hSplitter = static_cast<QSplitter *>(parentWidget()); auto *hSplitter = static_cast<QSplitter *>(parentWidget());
m_ui->stackedProperties->setVisible(false); m_ui->stackedProperties->setVisible(false);
m_slideSizes = hSplitter->sizes(); m_slideSizes = hSplitter->sizes();
hSplitter->handle(1)->setVisible(false); hSplitter->handle(1)->setVisible(false);
@ -211,7 +211,7 @@ void PropertiesWidget::setVisibility(bool visible)
if (visible && (m_state == REDUCED)) { if (visible && (m_state == REDUCED)) {
m_ui->stackedProperties->setVisible(true); m_ui->stackedProperties->setVisible(true);
QSplitter *hSplitter = static_cast<QSplitter *>(parentWidget()); auto *hSplitter = static_cast<QSplitter *>(parentWidget());
hSplitter->handle(1)->setDisabled(false); hSplitter->handle(1)->setDisabled(false);
hSplitter->handle(1)->setVisible(true); hSplitter->handle(1)->setVisible(true);
hSplitter->setSizes(m_slideSizes); hSplitter->setSizes(m_slideSizes);
@ -344,7 +344,7 @@ void PropertiesWidget::readSettings()
if (sizesStr.size() == 2) { if (sizesStr.size() == 2) {
m_slideSizes << sizesStr.first().toInt(); m_slideSizes << sizesStr.first().toInt();
m_slideSizes << sizesStr.last().toInt(); m_slideSizes << sizesStr.last().toInt();
QSplitter *hSplitter = static_cast<QSplitter *>(parentWidget()); auto *hSplitter = static_cast<QSplitter *>(parentWidget());
hSplitter->setSizes(m_slideSizes); hSplitter->setSizes(m_slideSizes);
} }
const int currentTab = pref->getPropCurTab(); const int currentTab = pref->getPropCurTab();
@ -360,7 +360,7 @@ void PropertiesWidget::saveSettings()
Preferences *const pref = Preferences::instance(); Preferences *const pref = Preferences::instance();
pref->setPropVisible(m_state == VISIBLE); pref->setPropVisible(m_state == VISIBLE);
// Splitter sizes // Splitter sizes
QSplitter *hSplitter = static_cast<QSplitter *>(parentWidget()); auto *hSplitter = static_cast<QSplitter *>(parentWidget());
QList<int> sizes; QList<int> sizes;
if (m_state == VISIBLE) if (m_state == VISIBLE)
sizes = hSplitter->sizes(); sizes = hSplitter->sizes();

6
src/gui/properties/proplistdelegate.cpp

@ -153,7 +153,7 @@ void PropListDelegate::paint(QPainter *painter, const QStyleOptionViewItem &opti
void PropListDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const void PropListDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
{ {
QComboBox *combobox = static_cast<QComboBox *>(editor); auto *combobox = static_cast<QComboBox *>(editor);
// Set combobox index // Set combobox index
switch (static_cast<BitTorrent::FilePriority>(index.data().toInt())) { switch (static_cast<BitTorrent::FilePriority>(index.data().toInt())) {
case BitTorrent::FilePriority::Ignored: case BitTorrent::FilePriority::Ignored:
@ -184,7 +184,7 @@ QWidget *PropListDelegate::createEditor(QWidget *parent, const QStyleOptionViewI
if (index.data().toInt() == static_cast<int>(BitTorrent::FilePriority::Mixed)) if (index.data().toInt() == static_cast<int>(BitTorrent::FilePriority::Mixed))
return nullptr; return nullptr;
QComboBox *editor = new QComboBox(parent); auto *editor = new QComboBox(parent);
editor->setFocusPolicy(Qt::StrongFocus); editor->setFocusPolicy(Qt::StrongFocus);
editor->addItem(tr("Do not download", "Do not download (priority)")); editor->addItem(tr("Do not download", "Do not download (priority)"));
editor->addItem(tr("Normal", "Normal (priority)")); editor->addItem(tr("Normal", "Normal (priority)"));
@ -195,7 +195,7 @@ QWidget *PropListDelegate::createEditor(QWidget *parent, const QStyleOptionViewI
void PropListDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const void PropListDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
{ {
QComboBox *combobox = static_cast<QComboBox *>(editor); auto *combobox = static_cast<QComboBox *>(editor);
int value = combobox->currentIndex(); int value = combobox->currentIndex();
qDebug("PropListDelegate: setModelData(%d)", value); qDebug("PropListDelegate: setModelData(%d)", value);

3
src/gui/properties/trackerlistwidget.cpp

@ -466,8 +466,7 @@ void TrackerListWidget::editSelectedTracker()
QList<BitTorrent::TrackerEntry> trackers = torrent->trackers(); QList<BitTorrent::TrackerEntry> trackers = torrent->trackers();
bool match = false; bool match = false;
for (int i = 0; i < trackers.size(); ++i) { for (auto &entry : trackers) {
BitTorrent::TrackerEntry &entry = trackers[i];
if (newTrackerURL == QUrl(entry.url())) { if (newTrackerURL == QUrl(entry.url())) {
QMessageBox::warning(this, tr("Tracker editing failed"), tr("The tracker URL already exists.")); QMessageBox::warning(this, tr("Tracker editing failed"), tr("The tracker URL already exists."));
return; return;

2
src/gui/rss/articlelistwidget.cpp

@ -117,7 +117,7 @@ void ArticleListWidget::checkInvariant() const
QListWidgetItem *ArticleListWidget::createItem(RSS::Article *article) const QListWidgetItem *ArticleListWidget::createItem(RSS::Article *article) const
{ {
Q_ASSERT(article); Q_ASSERT(article);
QListWidgetItem *item = new QListWidgetItem; auto *item = new QListWidgetItem;
item->setData(Qt::DisplayRole, article->title()); item->setData(Qt::DisplayRole, article->title());
item->setData(Qt::UserRole, reinterpret_cast<quintptr>(article)); item->setData(Qt::UserRole, reinterpret_cast<quintptr>(article));

2
src/gui/rss/feedlistwidget.cpp

@ -232,7 +232,7 @@ void FeedListWidget::dropEvent(QDropEvent *event)
QTreeWidgetItem *FeedListWidget::createItem(RSS::Item *rssItem, QTreeWidgetItem *parentItem) QTreeWidgetItem *FeedListWidget::createItem(RSS::Item *rssItem, QTreeWidgetItem *parentItem)
{ {
QTreeWidgetItem *item = new QTreeWidgetItem; auto *item = new QTreeWidgetItem;
item->setData(0, Qt::DisplayRole, QString("%1 (%2)").arg(rssItem->name()).arg(rssItem->unreadCount())); item->setData(0, Qt::DisplayRole, QString("%1 (%2)").arg(rssItem->name()).arg(rssItem->unreadCount()));
item->setData(0, Qt::UserRole, reinterpret_cast<quintptr>(rssItem)); item->setData(0, Qt::UserRole, reinterpret_cast<quintptr>(rssItem));
m_rssToTreeItemMapping[rssItem] = item; m_rssToTreeItemMapping[rssItem] = item;

2
src/gui/rss/htmlbrowser.cpp

@ -80,7 +80,7 @@ QVariant HtmlBrowser::loadResource(int type, const QUrl &name)
m_netManager->get(req); m_netManager->get(req);
} }
return QVariant(); return {};
} }
return QTextBrowser::loadResource(type, name); return QTextBrowser::loadResource(type, name);

2
src/gui/rss/rsswidget.cpp

@ -150,7 +150,7 @@ void RSSWidget::displayRSSListMenu(const QPoint &pos)
m_feedListWidget->clearSelection(); m_feedListWidget->clearSelection();
QMenu myRSSListMenu(this); QMenu myRSSListMenu(this);
QList<QTreeWidgetItem *> selectedItems = m_feedListWidget->selectedItems(); QList<QTreeWidgetItem *> selectedItems = m_feedListWidget->selectedItems();
if (selectedItems.size() > 0) { if (!selectedItems.isEmpty()) {
myRSSListMenu.addAction(m_ui->actionUpdate); myRSSListMenu.addAction(m_ui->actionUpdate);
myRSSListMenu.addAction(m_ui->actionMarkItemsRead); myRSSListMenu.addAction(m_ui->actionMarkItemsRead);
myRSSListMenu.addSeparator(); myRSSListMenu.addSeparator();

8
src/gui/scanfoldersdelegate.cpp

@ -44,7 +44,7 @@ ScanFoldersDelegate::ScanFoldersDelegate(QObject *parent, QTreeView *foldersView
void ScanFoldersDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const void ScanFoldersDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
{ {
QComboBox *combobox = static_cast<QComboBox*>(editor); auto *combobox = static_cast<QComboBox*>(editor);
// Set combobox index // Set combobox index
if (index.data(Qt::UserRole).toInt() == ScanFoldersModel::CUSTOM_LOCATION) if (index.data(Qt::UserRole).toInt() == ScanFoldersModel::CUSTOM_LOCATION)
combobox->setCurrentIndex(4); // '4' is the index of the item after the separator in the QComboBox menu combobox->setCurrentIndex(4); // '4' is the index of the item after the separator in the QComboBox menu
@ -56,7 +56,7 @@ QWidget *ScanFoldersDelegate::createEditor(QWidget *parent, const QStyleOptionVi
{ {
if (index.column() != ScanFoldersModel::DOWNLOAD) return nullptr; if (index.column() != ScanFoldersModel::DOWNLOAD) return nullptr;
QComboBox *editor = new QComboBox(parent); auto *editor = new QComboBox(parent);
editor->setFocusPolicy(Qt::StrongFocus); editor->setFocusPolicy(Qt::StrongFocus);
editor->addItem(ScanFoldersModel::pathTypeDisplayName(ScanFoldersModel::DOWNLOAD_IN_WATCH_FOLDER)); editor->addItem(ScanFoldersModel::pathTypeDisplayName(ScanFoldersModel::DOWNLOAD_IN_WATCH_FOLDER));
@ -75,7 +75,7 @@ QWidget *ScanFoldersDelegate::createEditor(QWidget *parent, const QStyleOptionVi
void ScanFoldersDelegate::comboboxIndexChanged(int index) void ScanFoldersDelegate::comboboxIndexChanged(int index)
{ {
if (index == ScanFoldersModel::CUSTOM_LOCATION) { if (index == ScanFoldersModel::CUSTOM_LOCATION) {
QWidget *w = static_cast<QWidget *>(sender()); auto *w = static_cast<QWidget *>(sender());
if (w && w->parentWidget()) if (w && w->parentWidget())
w->parentWidget()->setFocus(); w->parentWidget()->setFocus();
} }
@ -83,7 +83,7 @@ void ScanFoldersDelegate::comboboxIndexChanged(int index)
void ScanFoldersDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const void ScanFoldersDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
{ {
QComboBox *combobox = static_cast<QComboBox*>(editor); auto *combobox = static_cast<QComboBox*>(editor);
int value = combobox->currentIndex(); int value = combobox->currentIndex();
switch (value) { switch (value) {

4
src/gui/search/pluginselectdialog.cpp

@ -270,7 +270,7 @@ void PluginSelectDialog::loadSupportedSearchPlugins()
void PluginSelectDialog::addNewPlugin(const QString &pluginName) void PluginSelectDialog::addNewPlugin(const QString &pluginName)
{ {
QTreeWidgetItem *item = new QTreeWidgetItem(m_ui->pluginsTree); auto *item = new QTreeWidgetItem(m_ui->pluginsTree);
PluginInfo *plugin = m_pluginManager->pluginInfo(pluginName); PluginInfo *plugin = m_pluginManager->pluginInfo(pluginName);
item->setText(PLUGIN_NAME, plugin->fullName); item->setText(PLUGIN_NAME, plugin->fullName);
item->setText(PLUGIN_URL, plugin->url); item->setText(PLUGIN_URL, plugin->url);
@ -326,7 +326,7 @@ void PluginSelectDialog::finishPluginUpdate()
void PluginSelectDialog::on_installButton_clicked() void PluginSelectDialog::on_installButton_clicked()
{ {
PluginSourceDialog *dlg = new PluginSourceDialog(this); auto *dlg = new PluginSourceDialog(this);
connect(dlg, &PluginSourceDialog::askForLocalFile, this, &PluginSelectDialog::askForLocalPlugin); connect(dlg, &PluginSourceDialog::askForLocalFile, this, &PluginSelectDialog::askForLocalPlugin);
connect(dlg, &PluginSourceDialog::askForUrl, this, &PluginSelectDialog::askForPluginUrl); connect(dlg, &PluginSourceDialog::askForUrl, this, &PluginSelectDialog::askForPluginUrl);
} }

2
src/gui/search/searchjobwidget.cpp

@ -385,7 +385,7 @@ QString SearchJobWidget::statusText(SearchJobWidget::Status st)
case Status::NoResults: case Status::NoResults:
return tr("Search returned no results"); return tr("Search returned no results");
default: default:
return QString(); return {};
} }
} }

2
src/gui/search/searchwidget.cpp

@ -83,7 +83,7 @@ namespace
case SearchJobWidget::Status::NoResults: case SearchJobWidget::Status::NoResults:
return QLatin1String("task-attention"); return QLatin1String("task-attention");
default: default:
return QString(); return {};
} }
} }
} }

2
src/gui/statusbar.cpp

@ -55,7 +55,7 @@ StatusBar::StatusBar(QWidget *parent)
BitTorrent::Session *const session = BitTorrent::Session::instance(); BitTorrent::Session *const session = BitTorrent::Session::instance();
connect(session, &BitTorrent::Session::speedLimitModeChanged, this, &StatusBar::updateAltSpeedsBtn); connect(session, &BitTorrent::Session::speedLimitModeChanged, this, &StatusBar::updateAltSpeedsBtn);
QWidget *container = new QWidget(this); QWidget *container = new QWidget(this);
QHBoxLayout *layout = new QHBoxLayout(container); auto *layout = new QHBoxLayout(container);
layout->setContentsMargins(0,0,0,0); layout->setContentsMargins(0,0,0,0);
container->setLayout(layout); container->setLayout(layout);

14
src/gui/tagfiltermodel.cpp

@ -114,7 +114,7 @@ bool TagFilterModel::isSpecialItem(const QModelIndex &index)
QVariant TagFilterModel::data(const QModelIndex &index, int role) const QVariant TagFilterModel::data(const QModelIndex &index, int role) const
{ {
if (!index.isValid() || (index.column() != 0)) if (!index.isValid() || (index.column() != 0))
return QVariant(); return {};
const int row = index.internalId(); const int row = index.internalId();
Q_ASSERT(isValidRow(row)); Q_ASSERT(isValidRow(row));
@ -129,7 +129,7 @@ QVariant TagFilterModel::data(const QModelIndex &index, int role) const
case Qt::UserRole: case Qt::UserRole:
return item.torrentsCount(); return item.torrentsCount();
default: default:
return QVariant(); return {};
} }
} }
@ -145,13 +145,13 @@ QVariant TagFilterModel::headerData(int section, Qt::Orientation orientation, in
if ((orientation == Qt::Horizontal) && (role == Qt::DisplayRole)) if ((orientation == Qt::Horizontal) && (role == Qt::DisplayRole))
if (section == 0) if (section == 0)
return tr("Tags"); return tr("Tags");
return QVariant(); return {};
} }
QModelIndex TagFilterModel::index(int row, int, const QModelIndex &) const QModelIndex TagFilterModel::index(int row, int, const QModelIndex &) const
{ {
if (!isValidRow(row)) if (!isValidRow(row))
return QModelIndex(); return {};
return createIndex(row, 0, row); return createIndex(row, 0, row);
} }
@ -171,14 +171,14 @@ QModelIndex TagFilterModel::index(const QString &tag) const
{ {
const int row = findRow(tag); const int row = findRow(tag);
if (!isValidRow(row)) if (!isValidRow(row))
return QModelIndex(); return {};
return index(row, 0, QModelIndex()); return index(row, 0, QModelIndex());
} }
QString TagFilterModel::tag(const QModelIndex &index) const QString TagFilterModel::tag(const QModelIndex &index) const
{ {
if (!index.isValid()) if (!index.isValid())
return QString(); return {};
const int row = index.internalId(); const int row = index.internalId();
Q_ASSERT(isValidRow(row)); Q_ASSERT(isValidRow(row));
return m_tagItems[row].tag(); return m_tagItems[row].tag();
@ -326,7 +326,7 @@ QVector<TagModelItem *> TagFilterModel::findItems(const QSet<QString> &tags)
TagModelItem *TagFilterModel::allTagsItem() TagModelItem *TagFilterModel::allTagsItem()
{ {
Q_ASSERT(m_tagItems.size() > 0); Q_ASSERT(!m_tagItems.isEmpty());
return &m_tagItems[0]; return &m_tagItems[0];
} }

2
src/gui/tagfilterwidget.cpp

@ -60,7 +60,7 @@ namespace
TagFilterWidget::TagFilterWidget(QWidget *parent) TagFilterWidget::TagFilterWidget(QWidget *parent)
: QTreeView(parent) : QTreeView(parent)
{ {
TagFilterProxyModel *proxyModel = new TagFilterProxyModel(this); auto *proxyModel = new TagFilterProxyModel(this);
proxyModel->setSortCaseSensitivity(Qt::CaseInsensitive); proxyModel->setSortCaseSensitivity(Qt::CaseInsensitive);
proxyModel->setSourceModel(new TagFilterModel(this)); proxyModel->setSourceModel(new TagFilterModel(this));
setModel(proxyModel); setModel(proxyModel);

14
src/gui/torrentcontentfiltermodel.cpp

@ -66,10 +66,10 @@ int TorrentContentFilterModel::getFileIndex(const QModelIndex &index) const
QModelIndex TorrentContentFilterModel::parent(const QModelIndex &child) const QModelIndex TorrentContentFilterModel::parent(const QModelIndex &child) const
{ {
if (!child.isValid()) return QModelIndex(); if (!child.isValid()) return {};
QModelIndex sourceParent = m_model->parent(mapToSource(child)); QModelIndex sourceParent = m_model->parent(mapToSource(child));
if (!sourceParent.isValid()) return QModelIndex(); if (!sourceParent.isValid()) return {};
return mapFromSource(sourceParent); return mapFromSource(sourceParent);
} }
@ -96,12 +96,11 @@ bool TorrentContentFilterModel::lessThan(const QModelIndex &left, const QModelIn
const QString strR = right.data().toString(); const QString strR = right.data().toString();
return Utils::String::naturalLessThan<Qt::CaseInsensitive>(strL, strR); return Utils::String::naturalLessThan<Qt::CaseInsensitive>(strL, strR);
} }
else if ((leftType == TorrentContentModelItem::FolderType) && (sortOrder() == Qt::AscendingOrder)) { if ((leftType == TorrentContentModelItem::FolderType) && (sortOrder() == Qt::AscendingOrder)) {
return true; return true;
} }
else {
return false; return false;
}
} }
default: default:
return QSortFilterProxyModel::lessThan(left, right); return QSortFilterProxyModel::lessThan(left, right);
@ -136,8 +135,7 @@ bool TorrentContentFilterModel::hasFiltered(const QModelIndex &folder) const
if (m_model->hasChildren(childIndex)) { if (m_model->hasChildren(childIndex)) {
if (hasFiltered(childIndex)) if (hasFiltered(childIndex))
return true; return true;
else continue;
continue;
} }
name = childIndex.data().toString(); name = childIndex.data().toString();
if (name.contains(filterRegExp())) if (name.contains(filterRegExp()))

44
src/gui/torrentcontentmodel.cpp

@ -113,12 +113,12 @@ namespace
const QString ext = info.suffix(); const QString ext = info.suffix();
if (!ext.isEmpty()) { if (!ext.isEmpty()) {
QPixmap cached; QPixmap cached;
if (QPixmapCache::find(ext, &cached)) return QIcon(cached); if (QPixmapCache::find(ext, &cached)) return {cached};
const QPixmap pixmap = pixmapForExtension(ext); const QPixmap pixmap = pixmapForExtension(ext);
if (!pixmap.isNull()) { if (!pixmap.isNull()) {
QPixmapCache::insert(ext, pixmap); QPixmapCache::insert(ext, pixmap);
return QIcon(pixmap); return {pixmap};
} }
} }
return UnifiedFileIconProvider::icon(info); return UnifiedFileIconProvider::icon(info);
@ -140,7 +140,7 @@ namespace
HRESULT hr = ::SHGetFileInfoW(extWithDot.toStdWString().c_str(), HRESULT hr = ::SHGetFileInfoW(extWithDot.toStdWString().c_str(),
FILE_ATTRIBUTE_NORMAL, &sfi, sizeof(sfi), SHGFI_ICON | SHGFI_USEFILEATTRIBUTES); FILE_ATTRIBUTE_NORMAL, &sfi, sizeof(sfi), SHGFI_ICON | SHGFI_USEFILEATTRIBUTES);
if (FAILED(hr)) if (FAILED(hr))
return QPixmap(); return {};
QPixmap iconPixmap = QtWin::fromHICON(sfi.hIcon); QPixmap iconPixmap = QtWin::fromHICON(sfi.hIcon);
::DestroyIcon(sfi.hIcon); ::DestroyIcon(sfi.hIcon);
@ -287,8 +287,8 @@ int TorrentContentModel::columnCount(const QModelIndex &parent) const
{ {
if (parent.isValid()) if (parent.isValid())
return static_cast<TorrentContentModelItem*>(parent.internalPointer())->columnCount(); return static_cast<TorrentContentModelItem*>(parent.internalPointer())->columnCount();
else
return m_rootItem->columnCount(); return m_rootItem->columnCount();
} }
bool TorrentContentModel::setData(const QModelIndex &index, const QVariant &value, int role) bool TorrentContentModel::setData(const QModelIndex &index, const QVariant &value, int role)
@ -297,7 +297,7 @@ bool TorrentContentModel::setData(const QModelIndex &index, const QVariant &valu
return false; return false;
if ((index.column() == TorrentContentModelItem::COL_NAME) && (role == Qt::CheckStateRole)) { if ((index.column() == TorrentContentModelItem::COL_NAME) && (role == Qt::CheckStateRole)) {
TorrentContentModelItem *item = static_cast<TorrentContentModelItem*>(index.internalPointer()); auto *item = static_cast<TorrentContentModelItem*>(index.internalPointer());
qDebug("setData(%s, %d", qUtf8Printable(item->name()), value.toInt()); qDebug("setData(%s, %d", qUtf8Printable(item->name()), value.toInt());
if (static_cast<int>(item->priority()) != value.toInt()) { if (static_cast<int>(item->priority()) != value.toInt()) {
BitTorrent::FilePriority prio = BitTorrent::FilePriority::Normal; BitTorrent::FilePriority prio = BitTorrent::FilePriority::Normal;
@ -318,7 +318,7 @@ bool TorrentContentModel::setData(const QModelIndex &index, const QVariant &valu
if (role == Qt::EditRole) { if (role == Qt::EditRole) {
Q_ASSERT(index.isValid()); Q_ASSERT(index.isValid());
TorrentContentModelItem *item = static_cast<TorrentContentModelItem*>(index.internalPointer()); auto *item = static_cast<TorrentContentModelItem*>(index.internalPointer());
switch (index.column()) { switch (index.column()) {
case TorrentContentModelItem::COL_NAME: case TorrentContentModelItem::COL_NAME:
item->setName(value.toString()); item->setName(value.toString());
@ -343,7 +343,7 @@ TorrentContentModelItem::ItemType TorrentContentModel::itemType(const QModelInde
int TorrentContentModel::getFileIndex(const QModelIndex &index) int TorrentContentModel::getFileIndex(const QModelIndex &index)
{ {
TorrentContentModelItem *item = static_cast<TorrentContentModelItem*>(index.internalPointer()); auto *item = static_cast<TorrentContentModelItem*>(index.internalPointer());
if (item->itemType() == TorrentContentModelItem::FileType) if (item->itemType() == TorrentContentModelItem::FileType)
return static_cast<TorrentContentModelFile*>(item)->fileIndex(); return static_cast<TorrentContentModelFile*>(item)->fileIndex();
@ -354,15 +354,15 @@ int TorrentContentModel::getFileIndex(const QModelIndex &index)
QVariant TorrentContentModel::data(const QModelIndex &index, int role) const QVariant TorrentContentModel::data(const QModelIndex &index, int role) const
{ {
if (!index.isValid()) if (!index.isValid())
return QVariant(); return {};
TorrentContentModelItem *item = static_cast<TorrentContentModelItem*>(index.internalPointer()); auto *item = static_cast<TorrentContentModelItem*>(index.internalPointer());
if ((index.column() == TorrentContentModelItem::COL_NAME) && (role == Qt::DecorationRole)) { if ((index.column() == TorrentContentModelItem::COL_NAME) && (role == Qt::DecorationRole)) {
if (item->itemType() == TorrentContentModelItem::FolderType) if (item->itemType() == TorrentContentModelItem::FolderType)
return getDirectoryIcon(); return getDirectoryIcon();
else
return m_fileIconProvider->icon(QFileInfo(item->name())); return m_fileIconProvider->icon(QFileInfo(item->name()));
} }
if ((index.column() == TorrentContentModelItem::COL_NAME) && (role == Qt::CheckStateRole)) { if ((index.column() == TorrentContentModelItem::COL_NAME) && (role == Qt::CheckStateRole)) {
@ -376,7 +376,7 @@ QVariant TorrentContentModel::data(const QModelIndex &index, int role) const
if (role == Qt::DisplayRole) if (role == Qt::DisplayRole)
return item->data(index.column()); return item->data(index.column());
return QVariant(); return {};
} }
Qt::ItemFlags TorrentContentModel::flags(const QModelIndex &index) const Qt::ItemFlags TorrentContentModel::flags(const QModelIndex &index) const
@ -395,16 +395,16 @@ QVariant TorrentContentModel::headerData(int section, Qt::Orientation orientatio
if ((orientation == Qt::Horizontal) && (role == Qt::DisplayRole)) if ((orientation == Qt::Horizontal) && (role == Qt::DisplayRole))
return m_rootItem->data(section); return m_rootItem->data(section);
return QVariant(); return {};
} }
QModelIndex TorrentContentModel::index(int row, int column, const QModelIndex &parent) const QModelIndex TorrentContentModel::index(int row, int column, const QModelIndex &parent) const
{ {
if (parent.isValid() && (parent.column() != 0)) if (parent.isValid() && (parent.column() != 0))
return QModelIndex(); return {};
if (column >= TorrentContentModelItem::NB_COL) if (column >= TorrentContentModelItem::NB_COL)
return QModelIndex(); return {};
TorrentContentModelFolder *parentItem; TorrentContentModelFolder *parentItem;
if (!parent.isValid()) if (!parent.isValid())
@ -414,26 +414,26 @@ QModelIndex TorrentContentModel::index(int row, int column, const QModelIndex &p
Q_ASSERT(parentItem); Q_ASSERT(parentItem);
if (row >= parentItem->childCount()) if (row >= parentItem->childCount())
return QModelIndex(); return {};
TorrentContentModelItem *childItem = parentItem->child(row); TorrentContentModelItem *childItem = parentItem->child(row);
if (childItem) if (childItem)
return createIndex(row, column, childItem); return createIndex(row, column, childItem);
return QModelIndex(); return {};
} }
QModelIndex TorrentContentModel::parent(const QModelIndex &index) const QModelIndex TorrentContentModel::parent(const QModelIndex &index) const
{ {
if (!index.isValid()) if (!index.isValid())
return QModelIndex(); return {};
TorrentContentModelItem *childItem = static_cast<TorrentContentModelItem*>(index.internalPointer()); auto *childItem = static_cast<TorrentContentModelItem*>(index.internalPointer());
if (!childItem) if (!childItem)
return QModelIndex(); return {};
TorrentContentModelItem *parentItem = childItem->parent(); TorrentContentModelItem *parentItem = childItem->parent();
if (parentItem == m_rootItem) if (parentItem == m_rootItem)
return QModelIndex(); return {};
return createIndex(parentItem->row(), 0, parentItem); return createIndex(parentItem->row(), 0, parentItem);
} }

2
src/gui/torrentcontentmodelitem.cpp

@ -121,7 +121,7 @@ QVariant TorrentContentModelItem::data(int column) const
return availability(); return availability();
default: default:
Q_ASSERT(false); Q_ASSERT(false);
return QVariant(); return {};
} }
} }

2
src/gui/torrentcontenttreeview.cpp

@ -81,7 +81,7 @@ QModelIndex TorrentContentTreeView::currentNameCell()
QModelIndex current = currentIndex(); QModelIndex current = currentIndex();
if (!current.isValid()) { if (!current.isValid()) {
Q_ASSERT(false); Q_ASSERT(false);
return QModelIndex(); return {};
} }
return model()->index(current.row(), TorrentContentModelItem::COL_NAME, current.parent()); return model()->index(current.row(), TorrentContentModelItem::COL_NAME, current.parent());

46
src/gui/transferlistfilterswidget.cpp

@ -129,31 +129,31 @@ StatusFilterWidget::StatusFilterWidget(QWidget *parent, TransferListWidget *tran
, this, &StatusFilterWidget::updateTorrentNumbers); , this, &StatusFilterWidget::updateTorrentNumbers);
// Add status filters // Add status filters
QListWidgetItem *all = new QListWidgetItem(this); auto *all = new QListWidgetItem(this);
all->setData(Qt::DisplayRole, QVariant(tr("All (0)", "this is for the status filter"))); all->setData(Qt::DisplayRole, QVariant(tr("All (0)", "this is for the status filter")));
all->setData(Qt::DecorationRole, QIcon(":/icons/skin/filterall.svg")); all->setData(Qt::DecorationRole, QIcon(":/icons/skin/filterall.svg"));
QListWidgetItem *downloading = new QListWidgetItem(this); auto *downloading = new QListWidgetItem(this);
downloading->setData(Qt::DisplayRole, QVariant(tr("Downloading (0)"))); downloading->setData(Qt::DisplayRole, QVariant(tr("Downloading (0)")));
downloading->setData(Qt::DecorationRole, QIcon(":/icons/skin/downloading.svg")); downloading->setData(Qt::DecorationRole, QIcon(":/icons/skin/downloading.svg"));
QListWidgetItem *seeding = new QListWidgetItem(this); auto *seeding = new QListWidgetItem(this);
seeding->setData(Qt::DisplayRole, QVariant(tr("Seeding (0)"))); seeding->setData(Qt::DisplayRole, QVariant(tr("Seeding (0)")));
seeding->setData(Qt::DecorationRole, QIcon(":/icons/skin/uploading.svg")); seeding->setData(Qt::DecorationRole, QIcon(":/icons/skin/uploading.svg"));
QListWidgetItem *completed = new QListWidgetItem(this); auto *completed = new QListWidgetItem(this);
completed->setData(Qt::DisplayRole, QVariant(tr("Completed (0)"))); completed->setData(Qt::DisplayRole, QVariant(tr("Completed (0)")));
completed->setData(Qt::DecorationRole, QIcon(":/icons/skin/completed.svg")); completed->setData(Qt::DecorationRole, QIcon(":/icons/skin/completed.svg"));
QListWidgetItem *resumed = new QListWidgetItem(this); auto *resumed = new QListWidgetItem(this);
resumed->setData(Qt::DisplayRole, QVariant(tr("Resumed (0)"))); resumed->setData(Qt::DisplayRole, QVariant(tr("Resumed (0)")));
resumed->setData(Qt::DecorationRole, QIcon(":/icons/skin/resumed.svg")); resumed->setData(Qt::DecorationRole, QIcon(":/icons/skin/resumed.svg"));
QListWidgetItem *paused = new QListWidgetItem(this); auto *paused = new QListWidgetItem(this);
paused->setData(Qt::DisplayRole, QVariant(tr("Paused (0)"))); paused->setData(Qt::DisplayRole, QVariant(tr("Paused (0)")));
paused->setData(Qt::DecorationRole, QIcon(":/icons/skin/paused.svg")); paused->setData(Qt::DecorationRole, QIcon(":/icons/skin/paused.svg"));
QListWidgetItem *active = new QListWidgetItem(this); auto *active = new QListWidgetItem(this);
active->setData(Qt::DisplayRole, QVariant(tr("Active (0)"))); active->setData(Qt::DisplayRole, QVariant(tr("Active (0)")));
active->setData(Qt::DecorationRole, QIcon(":/icons/skin/filteractive.svg")); active->setData(Qt::DecorationRole, QIcon(":/icons/skin/filteractive.svg"));
QListWidgetItem *inactive = new QListWidgetItem(this); auto *inactive = new QListWidgetItem(this);
inactive->setData(Qt::DisplayRole, QVariant(tr("Inactive (0)"))); inactive->setData(Qt::DisplayRole, QVariant(tr("Inactive (0)")));
inactive->setData(Qt::DecorationRole, QIcon(":/icons/skin/filterinactive.svg")); inactive->setData(Qt::DecorationRole, QIcon(":/icons/skin/filterinactive.svg"));
QListWidgetItem *errored = new QListWidgetItem(this); auto *errored = new QListWidgetItem(this);
errored->setData(Qt::DisplayRole, QVariant(tr("Errored (0)"))); errored->setData(Qt::DisplayRole, QVariant(tr("Errored (0)")));
errored->setData(Qt::DecorationRole, QIcon(":/icons/skin/error.svg")); errored->setData(Qt::DecorationRole, QIcon(":/icons/skin/error.svg"));
@ -198,16 +198,16 @@ TrackerFiltersList::TrackerFiltersList(QWidget *parent, TransferListWidget *tran
, m_totalTorrents(0) , m_totalTorrents(0)
, m_downloadTrackerFavicon(true) , m_downloadTrackerFavicon(true)
{ {
QListWidgetItem *allTrackers = new QListWidgetItem(this); auto *allTrackers = new QListWidgetItem(this);
allTrackers->setData(Qt::DisplayRole, QVariant(tr("All (0)", "this is for the tracker filter"))); allTrackers->setData(Qt::DisplayRole, QVariant(tr("All (0)", "this is for the tracker filter")));
allTrackers->setData(Qt::DecorationRole, GuiIconProvider::instance()->getIcon("network-server")); allTrackers->setData(Qt::DecorationRole, GuiIconProvider::instance()->getIcon("network-server"));
QListWidgetItem *noTracker = new QListWidgetItem(this); auto *noTracker = new QListWidgetItem(this);
noTracker->setData(Qt::DisplayRole, QVariant(tr("Trackerless (0)"))); noTracker->setData(Qt::DisplayRole, QVariant(tr("Trackerless (0)")));
noTracker->setData(Qt::DecorationRole, GuiIconProvider::instance()->getIcon("network-server")); noTracker->setData(Qt::DecorationRole, GuiIconProvider::instance()->getIcon("network-server"));
QListWidgetItem *errorTracker = new QListWidgetItem(this); auto *errorTracker = new QListWidgetItem(this);
errorTracker->setData(Qt::DisplayRole, QVariant(tr("Error (0)"))); errorTracker->setData(Qt::DisplayRole, QVariant(tr("Error (0)")));
errorTracker->setData(Qt::DecorationRole, style()->standardIcon(QStyle::SP_MessageBoxCritical)); errorTracker->setData(Qt::DecorationRole, style()->standardIcon(QStyle::SP_MessageBoxCritical));
QListWidgetItem *warningTracker = new QListWidgetItem(this); auto *warningTracker = new QListWidgetItem(this);
warningTracker->setData(Qt::DisplayRole, QVariant(tr("Warning (0)"))); warningTracker->setData(Qt::DisplayRole, QVariant(tr("Warning (0)")));
warningTracker->setData(Qt::DecorationRole, style()->standardIcon(QStyle::SP_MessageBoxWarning)); warningTracker->setData(Qt::DecorationRole, style()->standardIcon(QStyle::SP_MessageBoxWarning));
m_trackers.insert("", QStringList()); m_trackers.insert("", QStringList());
@ -485,7 +485,7 @@ void TrackerFiltersList::handleNewTorrent(BitTorrent::TorrentHandle *const torre
addItem(tracker.url(), hash); addItem(tracker.url(), hash);
//Check for trackerless torrent //Check for trackerless torrent
if (trackers.size() == 0) if (trackers.isEmpty())
addItem("", hash); addItem("", hash);
item(0)->setText(tr("All (%1)", "this is for the tracker filter").arg(++m_totalTorrents)); item(0)->setText(tr("All (%1)", "this is for the tracker filter").arg(++m_totalTorrents));
@ -499,7 +499,7 @@ void TrackerFiltersList::torrentAboutToBeDeleted(BitTorrent::TorrentHandle *cons
removeItem(tracker.url(), hash); removeItem(tracker.url(), hash);
//Check for trackerless torrent //Check for trackerless torrent
if (trackers.size() == 0) if (trackers.isEmpty())
removeItem("", hash); removeItem("", hash);
item(0)->setText(tr("All (%1)", "this is for the tracker filter").arg(--m_totalTorrents)); item(0)->setText(tr("All (%1)", "this is for the tracker filter").arg(--m_totalTorrents));
@ -543,12 +543,12 @@ QStringList TrackerFiltersList::getHashes(int row)
{ {
if (row == 1) if (row == 1)
return m_trackers.value(""); return m_trackers.value("");
else if (row == 2) if (row == 2)
return m_errors.keys(); return m_errors.keys();
else if (row == 3) if (row == 3)
return m_warnings.keys(); return m_warnings.keys();
else
return m_trackers.value(trackerFromRow(row)); return m_trackers.value(trackerFromRow(row));
} }
TransferListFiltersWidget::TransferListFiltersWidget(QWidget *parent, TransferListWidget *transferList) TransferListFiltersWidget::TransferListFiltersWidget(QWidget *parent, TransferListWidget *transferList)
@ -558,10 +558,10 @@ TransferListFiltersWidget::TransferListFiltersWidget(QWidget *parent, TransferLi
Preferences *const pref = Preferences::instance(); Preferences *const pref = Preferences::instance();
// Construct lists // Construct lists
QVBoxLayout *vLayout = new QVBoxLayout(this); auto *vLayout = new QVBoxLayout(this);
QScrollArea *scroll = new QScrollArea(this); auto *scroll = new QScrollArea(this);
QFrame *frame = new QFrame(scroll); QFrame *frame = new QFrame(scroll);
QVBoxLayout *frameLayout = new QVBoxLayout(frame); auto *frameLayout = new QVBoxLayout(frame);
QFont font; QFont font;
font.setBold(true); font.setBold(true);
font.setCapitalization(QFont::AllUppercase); font.setCapitalization(QFont::AllUppercase);
@ -586,7 +586,7 @@ TransferListFiltersWidget::TransferListFiltersWidget(QWidget *parent, TransferLi
statusLabel->setFont(font); statusLabel->setFont(font);
frameLayout->addWidget(statusLabel); frameLayout->addWidget(statusLabel);
StatusFilterWidget *statusFilters = new StatusFilterWidget(this, transferList); auto *statusFilters = new StatusFilterWidget(this, transferList);
frameLayout->addWidget(statusFilters); frameLayout->addWidget(statusFilters);
QCheckBox *categoryLabel = new QCheckBox(tr("Categories"), this); QCheckBox *categoryLabel = new QCheckBox(tr("Categories"), this);

44
src/gui/transferlistmodel.cpp

@ -125,7 +125,7 @@ QVariant TransferListModel::headerData(int section, Qt::Orientation orientation,
case TR_LAST_ACTIVITY: return tr("Last Activity", "Time passed since a chunk was downloaded/uploaded"); case TR_LAST_ACTIVITY: return tr("Last Activity", "Time passed since a chunk was downloaded/uploaded");
case TR_TOTAL_SIZE: return tr("Total Size", "i.e. Size including unwanted data"); case TR_TOTAL_SIZE: return tr("Total Size", "i.e. Size including unwanted data");
default: default:
return QVariant(); return {};
} }
} }
else if (role == Qt::TextAlignmentRole) { else if (role == Qt::TextAlignmentRole) {
@ -149,22 +149,22 @@ QVariant TransferListModel::headerData(int section, Qt::Orientation orientation,
case TR_RATIO: case TR_RATIO:
case TR_PRIORITY: case TR_PRIORITY:
case TR_LAST_ACTIVITY: case TR_LAST_ACTIVITY:
return QVariant(Qt::AlignRight | Qt::AlignVCenter); return {Qt::AlignRight | Qt::AlignVCenter};
default: default:
return QAbstractListModel::headerData(section, orientation, role); return QAbstractListModel::headerData(section, orientation, role);
} }
} }
} }
return QVariant(); return {};
} }
QVariant TransferListModel::data(const QModelIndex &index, int role) const QVariant TransferListModel::data(const QModelIndex &index, int role) const
{ {
if (!index.isValid()) return QVariant(); if (!index.isValid()) return {};
BitTorrent::TorrentHandle *const torrent = m_torrents.value(index.row()); BitTorrent::TorrentHandle *const torrent = m_torrents.value(index.row());
if (!torrent) return QVariant(); if (!torrent) return {};
if ((role == Qt::DecorationRole) && (index.column() == TR_NAME)) if ((role == Qt::DecorationRole) && (index.column() == TR_NAME))
return getIconByState(torrent->state()); return getIconByState(torrent->state());
@ -173,7 +173,7 @@ QVariant TransferListModel::data(const QModelIndex &index, int role) const
return getColorByState(torrent->state()); return getColorByState(torrent->state());
if ((role != Qt::DisplayRole) && (role != Qt::UserRole)) if ((role != Qt::DisplayRole) && (role != Qt::UserRole))
return QVariant(); return {};
switch (index.column()) { switch (index.column()) {
case TR_NAME: case TR_NAME:
@ -243,7 +243,7 @@ QVariant TransferListModel::data(const QModelIndex &index, int role) const
return torrent->totalSize(); return torrent->totalSize();
} }
return QVariant(); return {};
} }
bool TransferListModel::setData(const QModelIndex &index, const QVariant &value, int role) bool TransferListModel::setData(const QModelIndex &index, const QVariant &value, int role)
@ -366,32 +366,32 @@ QColor getColorByState(BitTorrent::TorrentState state)
case BitTorrent::TorrentState::ForcedDownloading: case BitTorrent::TorrentState::ForcedDownloading:
case BitTorrent::TorrentState::DownloadingMetadata: case BitTorrent::TorrentState::DownloadingMetadata:
if (!dark) if (!dark)
return QColor(34, 139, 34); // Forest Green return {34, 139, 34}; // Forest Green
else else
return QColor(50, 205, 50); // Lime Green return {50, 205, 50}; // Lime Green
case BitTorrent::TorrentState::Allocating: case BitTorrent::TorrentState::Allocating:
case BitTorrent::TorrentState::StalledDownloading: case BitTorrent::TorrentState::StalledDownloading:
case BitTorrent::TorrentState::StalledUploading: case BitTorrent::TorrentState::StalledUploading:
if (!dark) if (!dark)
return QColor(0, 0, 0); // Black return {0, 0, 0}; // Black
else else
return QColor(204, 204, 204); // Gray 80 return {204, 204, 204}; // Gray 80
case BitTorrent::TorrentState::Uploading: case BitTorrent::TorrentState::Uploading:
case BitTorrent::TorrentState::ForcedUploading: case BitTorrent::TorrentState::ForcedUploading:
if (!dark) if (!dark)
return QColor(65, 105, 225); // Royal Blue return {65, 105, 225}; // Royal Blue
else else
return QColor(99, 184, 255); // Steel Blue 1 return {99, 184, 255}; // Steel Blue 1
case BitTorrent::TorrentState::PausedDownloading: case BitTorrent::TorrentState::PausedDownloading:
return QColor(250, 128, 114); // Salmon return {250, 128, 114}; // Salmon
case BitTorrent::TorrentState::PausedUploading: case BitTorrent::TorrentState::PausedUploading:
if (!dark) if (!dark)
return QColor(0, 0, 139); // Dark Blue return {0, 0, 139}; // Dark Blue
else else
return QColor(79, 148, 205); // Steel Blue 3 return {79, 148, 205}; // Steel Blue 3
case BitTorrent::TorrentState::Error: case BitTorrent::TorrentState::Error:
case BitTorrent::TorrentState::MissingFiles: case BitTorrent::TorrentState::MissingFiles:
return QColor(255, 0, 0); // red return {255, 0, 0}; // red
case BitTorrent::TorrentState::QueuedDownloading: case BitTorrent::TorrentState::QueuedDownloading:
case BitTorrent::TorrentState::QueuedUploading: case BitTorrent::TorrentState::QueuedUploading:
case BitTorrent::TorrentState::CheckingDownloading: case BitTorrent::TorrentState::CheckingDownloading:
@ -399,14 +399,14 @@ QColor getColorByState(BitTorrent::TorrentState state)
case BitTorrent::TorrentState::CheckingResumeData: case BitTorrent::TorrentState::CheckingResumeData:
case BitTorrent::TorrentState::Moving: case BitTorrent::TorrentState::Moving:
if (!dark) if (!dark)
return QColor(0, 128, 128); // Teal return {0, 128, 128}; // Teal
else else
return QColor(0, 205, 205); // Cyan 3 return {0, 205, 205}; // Cyan 3
case BitTorrent::TorrentState::Unknown: case BitTorrent::TorrentState::Unknown:
return QColor(255, 0, 0); // red return {255, 0, 0}; // red
default: default:
Q_ASSERT(false); Q_ASSERT(false);
return QColor(255, 0, 0); // red return {255, 0, 0}; // red
} }
} }
@ -468,6 +468,6 @@ bool isDarkTheme()
{ {
const QPalette pal = QApplication::palette(); const QPalette pal = QApplication::palette();
// QPalette::Base is used for the background of the Treeview // QPalette::Base is used for the background of the Treeview
const QColor color = pal.color(QPalette::Active, QPalette::Base); const QColor &color = pal.color(QPalette::Active, QPalette::Base);
return (color.lightness() < 127); return (color.lightness() < 127);
} }

25
src/gui/transferlistsortmodel.cpp

@ -104,8 +104,8 @@ bool TransferListSortModel::lessThan(const QModelIndex &left, const QModelIndex
// In this case QSortFilterProxyModel::lessThan() converts other types to QString and // In this case QSortFilterProxyModel::lessThan() converts other types to QString and
// sorts them. // sorts them.
// Thus we can't use the code in the default label. // Thus we can't use the code in the default label.
const BitTorrent::TorrentState leftValue = left.data().value<BitTorrent::TorrentState>(); const auto leftValue = left.data().value<BitTorrent::TorrentState>();
const BitTorrent::TorrentState rightValue = right.data().value<BitTorrent::TorrentState>(); const auto rightValue = right.data().value<BitTorrent::TorrentState>();
if (leftValue != rightValue) if (leftValue != rightValue)
return leftValue < rightValue; return leftValue < rightValue;
@ -160,8 +160,8 @@ bool TransferListSortModel::lessThan(const QModelIndex &left, const QModelIndex
const bool isAscendingOrder = (sortOrder() == Qt::AscendingOrder); const bool isAscendingOrder = (sortOrder() == Qt::AscendingOrder);
if (isSeedingL) if (isSeedingL)
return !isAscendingOrder; return !isAscendingOrder;
else
return isAscendingOrder; return isAscendingOrder;
} }
const qlonglong etaL = left.data().toLongLong(); const qlonglong etaL = left.data().toLongLong();
@ -171,15 +171,14 @@ bool TransferListSortModel::lessThan(const QModelIndex &left, const QModelIndex
if (isInvalidL && isInvalidR) { if (isInvalidL && isInvalidR) {
if (isSeedingL) // Both seeding if (isSeedingL) // Both seeding
return dateLessThan(TransferListModel::TR_SEED_DATE, left, right, true); return dateLessThan(TransferListModel::TR_SEED_DATE, left, right, true);
else
return (prioL < prioR); return (prioL < prioR);
} }
else if (!isInvalidL && !isInvalidR) { if (!isInvalidL && !isInvalidR) {
return (etaL < etaR); return (etaL < etaR);
} }
else {
return !isInvalidL; return !isInvalidL;
}
} }
case TransferListModel::TR_LAST_ACTIVITY: { case TransferListModel::TR_LAST_ACTIVITY: {
@ -221,8 +220,8 @@ bool TransferListSortModel::lowerPositionThan(const QModelIndex &left, const QMo
if ((queueL > 0) || (queueR > 0)) { if ((queueL > 0) || (queueR > 0)) {
if ((queueL > 0) && (queueR > 0)) if ((queueL > 0) && (queueR > 0))
return queueL < queueR; return queueL < queueR;
else
return queueL != 0; return queueL != 0;
} }
// Sort according to TR_SEED_DATE // Sort according to TR_SEED_DATE
@ -262,7 +261,7 @@ bool TransferListSortModel::filterAcceptsRow(int sourceRow, const QModelIndex &s
bool TransferListSortModel::matchFilter(int sourceRow, const QModelIndex &sourceParent) const bool TransferListSortModel::matchFilter(int sourceRow, const QModelIndex &sourceParent) const
{ {
TransferListModel *model = qobject_cast<TransferListModel *>(sourceModel()); auto *model = qobject_cast<TransferListModel *>(sourceModel());
if (!model) return false; if (!model) return false;
BitTorrent::TorrentHandle *const torrent = model->torrentHandle(model->index(sourceRow, 0, sourceParent)); BitTorrent::TorrentHandle *const torrent = model->torrentHandle(model->index(sourceRow, 0, sourceParent));

8
src/gui/transferlistwidget.cpp

@ -101,7 +101,7 @@ namespace
QSize CheckBoxIconHelper::sizeHint() const QSize CheckBoxIconHelper::sizeHint() const
{ {
const int dim = QCheckBox::sizeHint().height(); const int dim = QCheckBox::sizeHint().height();
return QSize(dim, dim); return {dim, dim};
} }
void CheckBoxIconHelper::initStyleOption(QStyleOptionButton *opt) const void CheckBoxIconHelper::initStyleOption(QStyleOptionButton *opt) const
@ -153,7 +153,7 @@ namespace
} }
m_checkBoxOffset.setWidth(layoutPadding.width()); m_checkBoxOffset.setWidth(layoutPadding.width());
QHBoxLayout *layout = new QHBoxLayout(this); auto *layout = new QHBoxLayout(this);
layout->addWidget(m_checkBox); layout->addWidget(m_checkBox);
layout->addStretch(); layout->addStretch();
layout->setContentsMargins(layoutPadding.width(), layoutPadding.height(), layoutPadding.width(), layoutPadding.height()); layout->setContentsMargins(layoutPadding.width(), layoutPadding.height(), layoutPadding.width(), layoutPadding.height());
@ -812,7 +812,7 @@ QStringList TransferListWidget::askTagsForSelection(const QString &dialogTitle)
const QString tagsInput = AutoExpandableDialog::getText( const QString tagsInput = AutoExpandableDialog::getText(
this, dialogTitle, tr("Comma-separated tags:"), QLineEdit::Normal, "", &ok).trimmed(); this, dialogTitle, tr("Comma-separated tags:"), QLineEdit::Normal, "", &ok).trimmed();
if (!ok || tagsInput.isEmpty()) if (!ok || tagsInput.isEmpty())
return QStringList(); return {};
tags = tagsInput.split(',', QString::SkipEmptyParts); tags = tagsInput.split(',', QString::SkipEmptyParts);
for (QString &tag : tags) { for (QString &tag : tags) {
tag = tag.trimmed(); tag = tag.trimmed();
@ -878,7 +878,7 @@ void TransferListWidget::clearSelectionTags()
void TransferListWidget::displayListMenu(const QPoint&) void TransferListWidget::displayListMenu(const QPoint&)
{ {
const QModelIndexList selectedIndexes = selectionModel()->selectedRows(); const QModelIndexList selectedIndexes = selectionModel()->selectedRows();
if (selectedIndexes.size() == 0) return; if (selectedIndexes.isEmpty()) return;
// Create actions // Create actions
QAction actionStart(GuiIconProvider::instance()->getIcon("media-playback-start"), tr("Resume", "Resume/start the torrent"), nullptr); QAction actionStart(GuiIconProvider::instance()->getIcon("media-playback-start"), tr("Resume", "Resume/start the torrent"), nullptr);

4
src/gui/utils.cpp

@ -96,7 +96,7 @@ QSize Utils::Gui::smallIconSize(const QWidget *widget)
// Get DPI scaled icon size (device-dependent), see QT source // Get DPI scaled icon size (device-dependent), see QT source
// under a 1080p screen is usually 16x16 // under a 1080p screen is usually 16x16
const int s = QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize, nullptr, widget); const int s = QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize, nullptr, widget);
return QSize(s, s); return {s, s};
} }
QSize Utils::Gui::mediumIconSize(const QWidget *widget) QSize Utils::Gui::mediumIconSize(const QWidget *widget)
@ -110,5 +110,5 @@ QSize Utils::Gui::largeIconSize(const QWidget *widget)
// Get DPI scaled icon size (device-dependent), see QT source // Get DPI scaled icon size (device-dependent), see QT source
// under a 1080p screen is usually 32x32 // under a 1080p screen is usually 32x32
const int s = QApplication::style()->pixelMetric(QStyle::PM_LargeIconSize, nullptr, widget); const int s = QApplication::style()->pixelMetric(QStyle::PM_LargeIconSize, nullptr, widget);
return QSize(s, s); return {s, s};
} }

7
src/webui/api/appcontroller.cpp

@ -329,7 +329,7 @@ void AppController::setPreferencesAction()
// Update deleted folders // Update deleted folders
for (auto i = oldScanDirs.cbegin(); i != oldScanDirs.cend(); ++i) { for (auto i = oldScanDirs.cbegin(); i != oldScanDirs.cend(); ++i) {
const QString folder = i.key(); const QString &folder = i.key();
if (!scanDirs.contains(folder)) { if (!scanDirs.contains(folder)) {
model->removePath(folder); model->removePath(folder);
qDebug("Removed watched folder %s", qUtf8Printable(folder)); qDebug("Removed watched folder %s", qUtf8Printable(folder));
@ -491,10 +491,11 @@ void AppController::setPreferencesAction()
if (m.contains("locale")) { if (m.contains("locale")) {
QString locale = m["locale"].toString(); QString locale = m["locale"].toString();
if (pref->getLocale() != locale) { if (pref->getLocale() != locale) {
QTranslator *translator = new QTranslator; auto *translator = new QTranslator;
if (translator->load(QLatin1String(":/lang/qbittorrent_") + locale)) { if (translator->load(QLatin1String(":/lang/qbittorrent_") + locale)) {
qDebug("%s locale recognized, using translation.", qUtf8Printable(locale)); qDebug("%s locale recognized, using translation.", qUtf8Printable(locale));
}else{ }
else {
qDebug("%s locale unrecognized, using default (en).", qUtf8Printable(locale)); qDebug("%s locale unrecognized, using default (en).", qUtf8Printable(locale));
} }
qApp->installTranslator(translator); qApp->installTranslator(translator);

4
src/webui/api/synccontroller.cpp

@ -434,9 +434,9 @@ void SyncController::maindataAction()
data["torrents"] = torrents; data["torrents"] = torrents;
QVariantHash categories; QVariantHash categories;
const auto categoriesList = session->categories(); const auto &categoriesList = session->categories();
for (auto it = categoriesList.cbegin(); it != categoriesList.cend(); ++it) { for (auto it = categoriesList.cbegin(); it != categoriesList.cend(); ++it) {
const auto key = it.key(); const auto &key = it.key();
categories[key] = QVariantMap { categories[key] = QVariantMap {
{"name", key}, {"name", key},
{"savePath", it.value()} {"savePath", it.value()}

12
src/webui/webapplication.cpp

@ -94,7 +94,7 @@ namespace
inline QUrl urlFromHostHeader(const QString &hostHeader) inline QUrl urlFromHostHeader(const QString &hostHeader)
{ {
if (!hostHeader.contains(QLatin1String("://"))) if (!hostHeader.contains(QLatin1String("://")))
return QUrl(QLatin1String("http://") + hostHeader); return {QLatin1String("http://") + hostHeader};
return hostHeader; return hostHeader;
} }
@ -509,13 +509,9 @@ QString WebApplication::generateSid() const
QString sid; QString sid;
do { do {
const size_t size = 6; const quint32 tmp[] = {Utils::Random::rand(), Utils::Random::rand(), Utils::Random::rand()
quint32 tmp[size]; , Utils::Random::rand(), Utils::Random::rand(), Utils::Random::rand()};
sid = QByteArray::fromRawData(reinterpret_cast<const char *>(tmp), sizeof(tmp)).toBase64();
for (size_t i = 0; i < size; ++i)
tmp[i] = Utils::Random::rand();
sid = QByteArray::fromRawData(reinterpret_cast<const char *>(tmp), sizeof(quint32) * size).toBase64();
} }
while (m_sessions.contains(sid)); while (m_sessions.contains(sid));

Loading…
Cancel
Save