Browse Source

Make use of chrono literals from std library

adaptive-webui-19844
Chocobo1 2 years ago
parent
commit
6de72ecc77
No known key found for this signature in database
GPG Key ID: 210D9C873253A68C
  1. 5
      src/app/main.cpp
  2. 6
      src/base/bittorrent/bandwidthscheduler.cpp
  3. 11
      src/base/bittorrent/session.cpp
  4. 2
      src/base/bittorrent/statistics.cpp
  5. 9
      src/base/http/server.cpp
  6. 9
      src/base/net/dnsupdater.cpp
  7. 2
      src/base/net/dnsupdater.h
  8. 9
      src/base/rss/rss_session.cpp
  9. 6
      src/base/search/searchhandler.cpp
  10. 6
      src/base/settingsstorage.cpp
  11. 4
      src/base/torrentfileswatcher.cpp
  12. 2
      src/gui/mainwindow.cpp
  13. 4
      src/gui/properties/speedplotview.cpp
  14. 2
      src/gui/properties/speedplotview.h
  15. 1
      src/gui/properties/speedwidget.cpp
  16. 6
      src/gui/shutdownconfirmdialog.cpp
  17. 5
      src/webui/api/appcontroller.cpp

5
src/app/main.cpp

@ -29,6 +29,7 @@ @@ -29,6 +29,7 @@
#include <QtGlobal>
#include <chrono>
#include <cstdlib>
#include <memory>
@ -79,6 +80,8 @@ Q_IMPORT_PLUGIN(QICOPlugin) @@ -79,6 +80,8 @@ Q_IMPORT_PLUGIN(QICOPlugin)
#include "gui/utils.h"
#endif
using namespace std::chrono_literals;
void displayVersion();
bool userAgreesWithLegalNotice();
void displayBadArgMessage(const QString &message);
@ -284,7 +287,7 @@ void showSplashScreen() @@ -284,7 +287,7 @@ void showSplashScreen()
painter.drawText(224 - painter.fontMetrics().horizontalAdvance(version), 270, version);
QSplashScreen *splash = new QSplashScreen(splashImg);
splash->show();
QTimer::singleShot(1500, splash, &QObject::deleteLater);
QTimer::singleShot(1500ms, splash, &QObject::deleteLater);
qApp->processEvents();
}
#endif // DISABLE_GUI

6
src/base/bittorrent/bandwidthscheduler.cpp

@ -29,14 +29,16 @@ @@ -29,14 +29,16 @@
#include "bandwidthscheduler.h"
#include <chrono>
#include <utility>
#include <QDate>
#include <QTime>
#include <QTimer>
#include "base/preferences.h"
using namespace std::chrono_literals;
BandwidthScheduler::BandwidthScheduler(QObject *parent)
: QObject(parent)
, m_lastAlternative(false)
@ -51,7 +53,7 @@ void BandwidthScheduler::start() @@ -51,7 +53,7 @@ void BandwidthScheduler::start()
// Timeout regularly to accommodate for external system clock changes
// eg from the user or from a timesync utility
m_timer.start(30000);
m_timer.start(30s);
}
bool BandwidthScheduler::isTimeForAlternative() const

11
src/base/bittorrent/session.cpp

@ -30,6 +30,7 @@ @@ -30,6 +30,7 @@
#include "session.h"
#include <algorithm>
#include <chrono>
#include <cstdint>
#include <ctime>
#include <queue>
@ -107,6 +108,7 @@ @@ -107,6 +108,7 @@
#include "torrentimpl.h"
#include "tracker.h"
using namespace std::chrono_literals;
using namespace BitTorrent;
const Path CATEGORIES_FILE_NAME {u"categories.json"_qs};
@ -442,11 +444,11 @@ Session::Session(QObject *parent) @@ -442,11 +444,11 @@ Session::Session(QObject *parent)
m_port = Utils::Random::rand(1024, 65535);
m_recentErroredTorrentsTimer->setSingleShot(true);
m_recentErroredTorrentsTimer->setInterval(1000);
m_recentErroredTorrentsTimer->setInterval(1s);
connect(m_recentErroredTorrentsTimer, &QTimer::timeout
, this, [this]() { m_recentErroredTorrents.clear(); });
m_seedingLimitTimer->setInterval(10000);
m_seedingLimitTimer->setInterval(10s);
connect(m_seedingLimitTimer, &QTimer::timeout, this, &Session::processShareLimits);
initializeNativeSession();
@ -497,7 +499,7 @@ Session::Session(QObject *parent) @@ -497,7 +499,7 @@ Session::Session(QObject *parent)
const int saveInterval = saveResumeDataInterval();
if (saveInterval > 0)
{
m_resumeDataTimer->setInterval(saveInterval * 60 * 1000);
m_resumeDataTimer->setInterval(std::chrono::minutes(saveInterval));
m_resumeDataTimer->start();
}
@ -2907,7 +2909,7 @@ void Session::setSaveResumeDataInterval(const int value) @@ -2907,7 +2909,7 @@ void Session::setSaveResumeDataInterval(const int value)
if (value > 0)
{
m_resumeDataTimer->setInterval(value * 60 * 1000);
m_resumeDataTimer->setInterval(std::chrono::minutes(value));
m_resumeDataTimer->start();
}
else
@ -5243,7 +5245,6 @@ void Session::handleSessionStatsAlert(const lt::session_stats_alert *p) @@ -5243,7 +5245,6 @@ void Session::handleSessionStatsAlert(const lt::session_stats_alert *p)
{
Q_ASSERT(current >= previous);
Q_ASSERT(interval >= 0);
using namespace std::chrono_literals;
return (((current - previous) * lt::microseconds(1s).count()) / interval);
};

2
src/base/bittorrent/statistics.cpp

@ -40,7 +40,7 @@ @@ -40,7 +40,7 @@
using namespace std::chrono_literals;
using namespace BitTorrent;
const qint64 SAVE_INTERVAL = std::chrono::milliseconds(15min).count();
const int SAVE_INTERVAL = std::chrono::milliseconds(15min).count();
Statistics::Statistics(Session *session)
: QObject(session)

9
src/base/http/server.cpp

@ -31,6 +31,7 @@ @@ -31,6 +31,7 @@
#include "server.h"
#include <algorithm>
#include <chrono>
#include <QNetworkProxy>
#include <QSslCipher>
@ -44,11 +45,13 @@ @@ -44,11 +45,13 @@
#include "base/utils/net.h"
#include "connection.h"
using namespace std::chrono_literals;
namespace
{
const int KEEP_ALIVE_DURATION = 7 * 1000; // milliseconds
const int KEEP_ALIVE_DURATION = std::chrono::milliseconds(7s).count();
const int CONNECTIONS_LIMIT = 500;
const int CONNECTIONS_SCAN_INTERVAL = 2; // seconds
const std::chrono::seconds CONNECTIONS_SCAN_INTERVAL {2};
QList<QSslCipher> safeCipherList()
{
@ -81,7 +84,7 @@ Server::Server(IRequestHandler *requestHandler, QObject *parent) @@ -81,7 +84,7 @@ Server::Server(IRequestHandler *requestHandler, QObject *parent)
auto *dropConnectionTimer = new QTimer(this);
connect(dropConnectionTimer, &QTimer::timeout, this, &Server::dropTimedOutConnection);
dropConnectionTimer->start(CONNECTIONS_SCAN_INTERVAL * 1000);
dropConnectionTimer->start(CONNECTIONS_SCAN_INTERVAL);
}
void Server::incomingConnection(const qintptr socketDescriptor)

9
src/base/net/dnsupdater.cpp

@ -37,8 +37,11 @@ @@ -37,8 +37,11 @@
#include "base/net/downloadmanager.h"
#include "base/version.h"
using namespace std::chrono_literals;
using namespace Net;
const std::chrono::seconds IP_CHECK_INTERVAL = 30min;
DNSUpdater::DNSUpdater(QObject *parent)
: QObject(parent)
, m_state(OK)
@ -52,14 +55,14 @@ DNSUpdater::DNSUpdater(QObject *parent) @@ -52,14 +55,14 @@ DNSUpdater::DNSUpdater(QObject *parent)
m_lastIP = QHostAddress(pref->getDNSLastIP());
// Start IP checking timer
m_ipCheckTimer.setInterval(IP_CHECK_INTERVAL_MS);
m_ipCheckTimer.setInterval(IP_CHECK_INTERVAL);
connect(&m_ipCheckTimer, &QTimer::timeout, this, &DNSUpdater::checkPublicIP);
m_ipCheckTimer.start();
// Check lastUpdate to avoid flooding
if (!m_lastIPCheckTime.isValid()
|| (m_lastIPCheckTime.secsTo(QDateTime::currentDateTime()) * 1000 > IP_CHECK_INTERVAL_MS))
{
|| (m_lastIPCheckTime.secsTo(QDateTime::currentDateTime()) > IP_CHECK_INTERVAL.count()))
{
checkPublicIP();
}
}

2
src/base/net/dnsupdater.h

@ -68,8 +68,6 @@ namespace Net @@ -68,8 +68,6 @@ namespace Net
FATAL
};
static const int IP_CHECK_INTERVAL_MS = 1800000; // 30 min
QString getUpdateUrl() const;
void processIPUpdateReply(const QString &reply);

9
src/base/rss/rss_session.cpp

@ -30,6 +30,8 @@ @@ -30,6 +30,8 @@
#include "rss_session.h"
#include <chrono>
#include <QDebug>
#include <QJsonDocument>
#include <QJsonObject>
@ -48,7 +50,6 @@ @@ -48,7 +50,6 @@
#include "rss_folder.h"
#include "rss_item.h"
const int MsecsPerMin = 60000;
const QString CONF_FOLDER_NAME = u"rss"_qs;
const QString DATA_FOLDER_NAME = u"rss/articles"_qs;
const QString FEEDS_FILE_NAME = u"feeds.json"_qs;
@ -92,7 +93,7 @@ Session::Session() @@ -92,7 +93,7 @@ Session::Session()
connect(&m_refreshTimer, &QTimer::timeout, this, &Session::refresh);
if (isProcessingEnabled())
{
m_refreshTimer.start(refreshInterval() * MsecsPerMin);
m_refreshTimer.start(std::chrono::minutes(refreshInterval()));
refresh();
}
@ -433,7 +434,7 @@ void Session::setProcessingEnabled(const bool enabled) @@ -433,7 +434,7 @@ void Session::setProcessingEnabled(const bool enabled)
m_storeProcessingEnabled = enabled;
if (enabled)
{
m_refreshTimer.start(refreshInterval() * MsecsPerMin);
m_refreshTimer.start(std::chrono::minutes(refreshInterval()));
refresh();
}
else
@ -480,7 +481,7 @@ void Session::setRefreshInterval(const int refreshInterval) @@ -480,7 +481,7 @@ void Session::setRefreshInterval(const int refreshInterval)
if (m_storeRefreshInterval != refreshInterval)
{
m_storeRefreshInterval = refreshInterval;
m_refreshTimer.start(m_storeRefreshInterval * MsecsPerMin);
m_refreshTimer.start(std::chrono::minutes(m_storeRefreshInterval));
}
}

6
src/base/search/searchhandler.cpp

@ -29,6 +29,8 @@ @@ -29,6 +29,8 @@
#include "searchhandler.h"
#include <chrono>
#include <QMetaObject>
#include <QProcess>
#include <QTimer>
@ -40,6 +42,8 @@ @@ -40,6 +42,8 @@
#include "base/utils/fs.h"
#include "searchpluginmanager.h"
using namespace std::chrono_literals;
namespace
{
enum SearchResultColumn
@ -85,7 +89,7 @@ SearchHandler::SearchHandler(const QString &pattern, const QString &category, co @@ -85,7 +89,7 @@ SearchHandler::SearchHandler(const QString &pattern, const QString &category, co
m_searchTimeout->setSingleShot(true);
connect(m_searchTimeout, &QTimer::timeout, this, &SearchHandler::cancelSearch);
m_searchTimeout->start(180000); // 3 min
m_searchTimeout->start(3min);
// deferred start allows clients to handle starting-related signals
QMetaObject::invokeMethod(this, [this]() { m_searchProcess->start(QIODevice::ReadOnly); }

6
src/base/settingsstorage.cpp

@ -29,7 +29,9 @@ @@ -29,7 +29,9 @@
#include "settingsstorage.h"
#include <chrono>
#include <memory>
#include <QFile>
#include <QHash>
@ -39,6 +41,8 @@ @@ -39,6 +41,8 @@
#include "profile.h"
#include "utils/fs.h"
using namespace std::chrono_literals;
namespace
{
// Encapsulates serialization of settings in "atomic" way.
@ -73,7 +77,7 @@ SettingsStorage::SettingsStorage() @@ -73,7 +77,7 @@ SettingsStorage::SettingsStorage()
: m_data {TransactionalSettings(u"qBittorrent"_qs).read()}
{
m_timer.setSingleShot(true);
m_timer.setInterval(5 * 1000);
m_timer.setInterval(5s);
connect(&m_timer, &QTimer::timeout, this, &SettingsStorage::save);
}

4
src/base/torrentfileswatcher.cpp

@ -63,7 +63,7 @@ @@ -63,7 +63,7 @@
using namespace std::chrono_literals;
const std::chrono::duration WATCH_INTERVAL = 10s;
const std::chrono::seconds WATCH_INTERVAL {10};
const int MAX_FAILED_RETRIES = 5;
const QString CONF_FILE_NAME = u"watched_folders.json"_qs;
@ -478,7 +478,7 @@ void TorrentFilesWatcher::Worker::removeWatchedFolder(const Path &path) @@ -478,7 +478,7 @@ void TorrentFilesWatcher::Worker::removeWatchedFolder(const Path &path)
void TorrentFilesWatcher::Worker::scheduleWatchedFolderProcessing(const Path &path)
{
QTimer::singleShot(2000, this, [this, path]()
QTimer::singleShot(2s, this, [this, path]()
{
processWatchedFolder(path);
});

2
src/gui/mainwindow.cpp

@ -1762,7 +1762,7 @@ void MainWindow::createTrayIcon(const int retries) @@ -1762,7 +1762,7 @@ void MainWindow::createTrayIcon(const int retries)
if (retries > 0)
{
LogMsg(tr("System tray icon is not available, retrying..."), Log::WARNING);
QTimer::singleShot(std::chrono::seconds(2), this, [this, retries]()
QTimer::singleShot(2s, this, [this, retries]()
{
if (Preferences::instance()->systemTrayEnabled())
createTrayIcon(retries - 1);

4
src/gui/properties/speedplotview.cpp

@ -267,7 +267,7 @@ quint64 SpeedPlotView::maxYValue() const @@ -267,7 +267,7 @@ quint64 SpeedPlotView::maxYValue() const
if (!m_properties[static_cast<GraphID>(id)].enable)
continue;
milliseconds duration {0ms};
milliseconds duration {0};
for (int i = static_cast<int>(queue.size()) - 1; i >= 0; --i)
{
maxYValue = std::max(maxYValue, queue[i].data[id]);
@ -360,7 +360,7 @@ void SpeedPlotView::paintEvent(QPaintEvent *) @@ -360,7 +360,7 @@ void SpeedPlotView::paintEvent(QPaintEvent *)
continue;
QVector<QPoint> points;
milliseconds duration {0ms};
milliseconds duration {0};
for (int i = static_cast<int>(queue.size()) - 1; i >= 0; --i)
{

2
src/gui/properties/speedplotview.h

@ -111,7 +111,7 @@ private: @@ -111,7 +111,7 @@ private:
private:
const milliseconds m_resolution;
const milliseconds m_maxDuration;
milliseconds m_currentDuration {0ms};
milliseconds m_currentDuration {0};
int m_counter = 0;
SampleData m_accumulator {};
DataCircularBuffer m_sink {};

1
src/gui/properties/speedwidget.cpp

@ -32,7 +32,6 @@ @@ -32,7 +32,6 @@
#include <QHBoxLayout>
#include <QLabel>
#include <QMenu>
#include <QTimer>
#include <QVBoxLayout>
#include "base/bittorrent/session.h"

6
src/gui/shutdownconfirmdialog.cpp

@ -29,6 +29,8 @@ @@ -29,6 +29,8 @@
#include "shutdownconfirmdialog.h"
#include <chrono>
#include <QDialogButtonBox>
#include <QIcon>
#include <QPushButton>
@ -38,6 +40,8 @@ @@ -38,6 +40,8 @@
#include "ui_shutdownconfirmdialog.h"
#include "utils.h"
using namespace std::chrono_literals;
ShutdownConfirmDialog::ShutdownConfirmDialog(QWidget *parent, const ShutdownDialogAction &action)
: QDialog(parent)
, m_ui(new Ui::ShutdownConfirmDialog)
@ -64,7 +68,7 @@ ShutdownConfirmDialog::ShutdownConfirmDialog(QWidget *parent, const ShutdownDial @@ -64,7 +68,7 @@ ShutdownConfirmDialog::ShutdownConfirmDialog(QWidget *parent, const ShutdownDial
setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint);
move(Utils::Gui::screenCenter(this));
m_timer.setInterval(1000); // 1sec
m_timer.setInterval(1s);
connect(&m_timer, &QTimer::timeout, this, &ShutdownConfirmDialog::updateSeconds);
}

5
src/webui/api/appcontroller.cpp

@ -31,6 +31,7 @@ @@ -31,6 +31,7 @@
#include "appcontroller.h"
#include <algorithm>
#include <chrono>
#include <QCoreApplication>
#include <QDebug>
@ -62,6 +63,8 @@ @@ -62,6 +63,8 @@
#include "base/version.h"
#include "../webapplication.h"
using namespace std::chrono_literals;
void AppController::webapiVersionAction()
{
setResult(API_VERSION.toString());
@ -93,7 +96,7 @@ void AppController::shutdownAction() @@ -93,7 +96,7 @@ void AppController::shutdownAction()
// Special case handling for shutdown, we
// need to reply to the Web UI before
// actually shutting down.
QTimer::singleShot(100, qApp, &QCoreApplication::quit);
QTimer::singleShot(100ms, qApp, &QCoreApplication::quit);
}
void AppController::preferencesAction()

Loading…
Cancel
Save