Browse Source

Merge pull request #12086 from FranciscoPombal/code-cleanup

Clean ups
adaptive-webui-19844
Vladimir Golovnev 4 years ago committed by GitHub
parent
commit
bad5e1f887
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 51
      src/base/bittorrent/session.cpp
  2. 14
      src/base/bittorrent/session.h
  3. 6
      src/base/rss/rss_session.cpp
  4. 6
      src/base/rss/rss_session.h
  5. 2
      src/gui/rss/rsswidget.cpp
  6. 2
      src/gui/rss/rsswidget.h
  7. 6
      src/webui/api/appcontroller.cpp

51
src/base/bittorrent/session.cpp

@ -30,6 +30,7 @@ @@ -30,6 +30,7 @@
#include "session.h"
#include <algorithm>
#include <cstdint>
#include <queue>
#include <string>
#include <utility>
@ -497,7 +498,7 @@ Session::Session(QObject *parent) @@ -497,7 +498,7 @@ Session::Session(QObject *parent)
// Regular saving of fastresume data
connect(m_resumeDataTimer, &QTimer::timeout, this, [this]() { generateResumeData(); });
const uint saveInterval = saveResumeDataInterval();
const int saveInterval = saveResumeDataInterval();
if (saveInterval > 0) {
m_resumeDataTimer->setInterval(saveInterval * 60 * 1000);
m_resumeDataTimer->start();
@ -580,12 +581,12 @@ void Session::setAppendExtensionEnabled(const bool enabled) @@ -580,12 +581,12 @@ void Session::setAppendExtensionEnabled(const bool enabled)
}
}
uint Session::refreshInterval() const
int Session::refreshInterval() const
{
return m_refreshInterval;
}
void Session::setRefreshInterval(const uint value)
void Session::setRefreshInterval(const int value)
{
if (value != refreshInterval()) {
m_refreshInterval = value;
@ -1100,7 +1101,7 @@ void Session::processBannedIPs(lt::ip_filter &filter) @@ -1100,7 +1101,7 @@ void Session::processBannedIPs(lt::ip_filter &filter)
}
}
void Session::adjustLimits(lt::settings_pack &settingsPack)
void Session::adjustLimits(lt::settings_pack &settingsPack) const
{
// Internally increase the queue limits to ensure that the magnet is started
const int maxDownloads = maxActiveDownloads();
@ -2618,12 +2619,12 @@ void Session::setBandwidthSchedulerEnabled(const bool enabled) @@ -2618,12 +2619,12 @@ void Session::setBandwidthSchedulerEnabled(const bool enabled)
}
}
uint Session::saveResumeDataInterval() const
int Session::saveResumeDataInterval() const
{
return m_saveResumeDataInterval;
}
void Session::setSaveResumeDataInterval(const uint value)
void Session::setSaveResumeDataInterval(const int value)
{
if (value == m_saveResumeDataInterval)
return;
@ -2667,10 +2668,10 @@ QString Session::networkInterface() const @@ -2667,10 +2668,10 @@ QString Session::networkInterface() const
return m_networkInterface;
}
void Session::setNetworkInterface(const QString &iface)
void Session::setNetworkInterface(const QString &interface)
{
if (iface != networkInterface()) {
m_networkInterface = iface;
if (interface != networkInterface()) {
m_networkInterface = interface;
configureListeningInterface();
}
}
@ -3655,7 +3656,7 @@ void Session::handleTorrentTrackersRemoved(TorrentHandleImpl *const torrent, con @@ -3655,7 +3656,7 @@ void Session::handleTorrentTrackersRemoved(TorrentHandleImpl *const torrent, con
for (const TrackerEntry &deletedTracker : deletedTrackers)
LogMsg(tr("Tracker '%1' was deleted from torrent '%2'").arg(deletedTracker.url(), torrent->name()));
emit trackersRemoved(torrent, deletedTrackers);
if (torrent->trackers().size() == 0)
if (torrent->trackers().empty())
emit trackerlessStateChanged(torrent, true);
emit trackersChanged(torrent);
}
@ -4334,7 +4335,7 @@ void Session::createTorrentHandle(const lt::torrent_handle &nativeHandle) @@ -4334,7 +4335,7 @@ void Session::createTorrentHandle(const lt::torrent_handle &nativeHandle)
const LoadTorrentParams params = m_loadingTorrents.take(nativeHandle.info_hash());
TorrentHandleImpl *const torrent = new TorrentHandleImpl {this, nativeHandle, params};
auto *const torrent = new TorrentHandleImpl {this, nativeHandle, params};
m_torrents.insert(torrent->hash(), torrent);
const bool hasMetadata = torrent->hasMetadata();
@ -4603,16 +4604,16 @@ void Session::handleSessionStatsAlert(const lt::session_stats_alert *p) @@ -4603,16 +4604,16 @@ void Session::handleSessionStatsAlert(const lt::session_stats_alert *p)
m_status.hasIncomingConnections = static_cast<bool>(stats[m_metricIndices.net.hasIncomingConnections]);
const auto ipOverheadDownload = stats[m_metricIndices.net.recvIPOverheadBytes];
const auto ipOverheadUpload = stats[m_metricIndices.net.sentIPOverheadBytes];
const auto totalDownload = stats[m_metricIndices.net.recvBytes] + ipOverheadDownload;
const auto totalUpload = stats[m_metricIndices.net.sentBytes] + ipOverheadUpload;
const auto totalPayloadDownload = stats[m_metricIndices.net.recvPayloadBytes];
const auto totalPayloadUpload = stats[m_metricIndices.net.sentPayloadBytes];
const auto trackerDownload = stats[m_metricIndices.net.recvTrackerBytes];
const auto trackerUpload = stats[m_metricIndices.net.sentTrackerBytes];
const auto dhtDownload = stats[m_metricIndices.dht.dhtBytesIn];
const auto dhtUpload = stats[m_metricIndices.dht.dhtBytesOut];
const int64_t ipOverheadDownload = stats[m_metricIndices.net.recvIPOverheadBytes];
const int64_t ipOverheadUpload = stats[m_metricIndices.net.sentIPOverheadBytes];
const int64_t totalDownload = stats[m_metricIndices.net.recvBytes] + ipOverheadDownload;
const int64_t totalUpload = stats[m_metricIndices.net.sentBytes] + ipOverheadUpload;
const int64_t totalPayloadDownload = stats[m_metricIndices.net.recvPayloadBytes];
const int64_t totalPayloadUpload = stats[m_metricIndices.net.sentPayloadBytes];
const int64_t trackerDownload = stats[m_metricIndices.net.recvTrackerBytes];
const int64_t trackerUpload = stats[m_metricIndices.net.sentTrackerBytes];
const int64_t dhtDownload = stats[m_metricIndices.dht.dhtBytesIn];
const int64_t dhtUpload = stats[m_metricIndices.dht.dhtBytesOut];
auto calcRate = [interval](const quint64 previous, const quint64 current)
{
@ -4648,13 +4649,13 @@ void Session::handleSessionStatsAlert(const lt::session_stats_alert *p) @@ -4648,13 +4649,13 @@ void Session::handleSessionStatsAlert(const lt::session_stats_alert *p)
m_status.diskWriteQueue = stats[m_metricIndices.peer.numPeersDownDisk];
m_status.peersCount = stats[m_metricIndices.peer.numPeersConnected];
const int numBlocksRead = stats[m_metricIndices.disk.numBlocksRead];
const int numBlocksCacheHits = stats[m_metricIndices.disk.numBlocksCacheHits];
const int64_t numBlocksRead = stats[m_metricIndices.disk.numBlocksRead];
const int64_t numBlocksCacheHits = stats[m_metricIndices.disk.numBlocksCacheHits];
m_cacheStatus.totalUsedBuffers = stats[m_metricIndices.disk.diskBlocksInUse];
m_cacheStatus.readRatio = static_cast<qreal>(numBlocksCacheHits) / std::max(numBlocksCacheHits + numBlocksRead, 1);
m_cacheStatus.readRatio = static_cast<qreal>(numBlocksCacheHits) / std::max<int64_t>(numBlocksCacheHits + numBlocksRead, 1);
m_cacheStatus.jobQueueLength = stats[m_metricIndices.disk.queuedDiskJobs];
const quint64 totalJobs = stats[m_metricIndices.disk.writeJobs] + stats[m_metricIndices.disk.readJobs]
const int64_t totalJobs = stats[m_metricIndices.disk.writeJobs] + stats[m_metricIndices.disk.readJobs]
+ stats[m_metricIndices.disk.hashJobs];
m_cacheStatus.averageJobTime = (totalJobs > 0)
? (stats[m_metricIndices.disk.diskJobTime] / totalJobs) : 0;

14
src/base/bittorrent/session.h

@ -276,8 +276,8 @@ namespace BitTorrent @@ -276,8 +276,8 @@ namespace BitTorrent
void setTrackerEnabled(bool enabled);
bool isAppendExtensionEnabled() const;
void setAppendExtensionEnabled(bool enabled);
uint refreshInterval() const;
void setRefreshInterval(uint value);
int refreshInterval() const;
void setRefreshInterval(int value);
bool isPreallocationEnabled() const;
void setPreallocationEnabled(bool enabled);
QString torrentExportDirectory() const;
@ -302,8 +302,8 @@ namespace BitTorrent @@ -302,8 +302,8 @@ namespace BitTorrent
bool isBandwidthSchedulerEnabled() const;
void setBandwidthSchedulerEnabled(bool enabled);
uint saveResumeDataInterval() const;
void setSaveResumeDataInterval(uint value);
int saveResumeDataInterval() const;
void setSaveResumeDataInterval(int value);
int port() const;
void setPort(int port);
bool useRandomPort() const;
@ -570,7 +570,7 @@ namespace BitTorrent @@ -570,7 +570,7 @@ namespace BitTorrent
void loadLTSettings(lt::settings_pack &settingsPack);
void configureNetworkInterfaces(lt::settings_pack &settingsPack);
void configurePeerClasses();
void adjustLimits(lt::settings_pack &settingsPack);
void adjustLimits(lt::settings_pack &settingsPack) const;
void applyBandwidthLimits(lt::settings_pack &settingsPack) const;
void initMetrics();
void adjustLimits();
@ -697,7 +697,7 @@ namespace BitTorrent @@ -697,7 +697,7 @@ namespace BitTorrent
CachedSettingValue<bool> m_isAddTorrentPaused;
CachedSettingValue<bool> m_isKeepTorrentTopLevelFolder;
CachedSettingValue<bool> m_isAppendExtensionEnabled;
CachedSettingValue<uint> m_refreshInterval;
CachedSettingValue<int> m_refreshInterval;
CachedSettingValue<bool> m_isPreallocationEnabled;
CachedSettingValue<QString> m_torrentExportDirectory;
CachedSettingValue<QString> m_finishedTorrentExportDirectory;
@ -707,7 +707,7 @@ namespace BitTorrent @@ -707,7 +707,7 @@ namespace BitTorrent
CachedSettingValue<int> m_altGlobalUploadSpeedLimit;
CachedSettingValue<bool> m_isAltGlobalSpeedLimitEnabled;
CachedSettingValue<bool> m_isBandwidthSchedulerEnabled;
CachedSettingValue<uint> m_saveResumeDataInterval;
CachedSettingValue<int> m_saveResumeDataInterval;
CachedSettingValue<int> m_port;
CachedSettingValue<bool> m_useRandomPort;
CachedSettingValue<QString> m_networkInterface;

6
src/base/rss/rss_session.cpp

@ -65,7 +65,7 @@ QPointer<Session> Session::m_instance = nullptr; @@ -65,7 +65,7 @@ QPointer<Session> Session::m_instance = nullptr;
Session::Session()
: m_processingEnabled(SettingsStorage::instance()->loadValue(SettingsKey_ProcessingEnabled, false).toBool())
, m_workingThread(new QThread(this))
, m_refreshInterval(SettingsStorage::instance()->loadValue(SettingsKey_RefreshInterval, 30).toUInt())
, m_refreshInterval(SettingsStorage::instance()->loadValue(SettingsKey_RefreshInterval, 30).toInt())
, m_maxArticlesPerFeed(SettingsStorage::instance()->loadValue(SettingsKey_MaxArticlesPerFeed, 50).toInt())
{
Q_ASSERT(!m_instance); // only one instance is allowed
@ -475,12 +475,12 @@ Feed *Session::feedByURL(const QString &url) const @@ -475,12 +475,12 @@ Feed *Session::feedByURL(const QString &url) const
return m_feedsByURL.value(url);
}
uint Session::refreshInterval() const
int Session::refreshInterval() const
{
return m_refreshInterval;
}
void Session::setRefreshInterval(const uint refreshInterval)
void Session::setRefreshInterval(const int refreshInterval)
{
if (m_refreshInterval != refreshInterval) {
SettingsStorage::instance()->storeValue(SettingsKey_RefreshInterval, refreshInterval);

6
src/base/rss/rss_session.h

@ -101,8 +101,8 @@ namespace RSS @@ -101,8 +101,8 @@ namespace RSS
int maxArticlesPerFeed() const;
void setMaxArticlesPerFeed(int n);
uint refreshInterval() const;
void setRefreshInterval(uint refreshInterval);
int refreshInterval() const;
void setRefreshInterval(int refreshInterval);
bool addFolder(const QString &path, QString *error = nullptr);
bool addFeed(const QString &url, const QString &path, QString *error = nullptr);
@ -152,7 +152,7 @@ namespace RSS @@ -152,7 +152,7 @@ namespace RSS
AsyncFileStorage *m_confFileStorage;
AsyncFileStorage *m_dataFileStorage;
QTimer m_refreshTimer;
uint m_refreshInterval;
int m_refreshInterval;
int m_maxArticlesPerFeed;
QHash<QString, Item *> m_itemsByPath;
QHash<QUuid, Feed *> m_feedsByUID;

2
src/gui/rss/rsswidget.cpp

@ -521,7 +521,7 @@ void RSSWidget::restoreSlidersPosition() @@ -521,7 +521,7 @@ void RSSWidget::restoreSlidersPosition()
m_ui->splitterMain->restoreState(stateMain);
}
void RSSWidget::updateRefreshInterval(uint val)
void RSSWidget::updateRefreshInterval(int val) const
{
RSS::Session::instance()->setRefreshInterval(val);
}

2
src/gui/rss/rsswidget.h

@ -54,7 +54,7 @@ public: @@ -54,7 +54,7 @@ public:
public slots:
void deleteSelectedItems();
void updateRefreshInterval(uint val);
void updateRefreshInterval(int val) const;
signals:
void unreadCountUpdated(int count);

6
src/webui/api/appcontroller.cpp

@ -254,7 +254,7 @@ void AppController::preferencesAction() @@ -254,7 +254,7 @@ void AppController::preferencesAction()
data["dyndns_domain"] = pref->getDynDomainName();
// RSS settings
data["rss_refresh_interval"] = static_cast<double>(RSS::Session::instance()->refreshInterval());
data["rss_refresh_interval"] = RSS::Session::instance()->refreshInterval();
data["rss_max_articles_per_feed"] = RSS::Session::instance()->maxArticlesPerFeed();
data["rss_processing_enabled"] = RSS::Session::instance()->isProcessingEnabled();
data["rss_auto_downloading_enabled"] = RSS::AutoDownloader::instance()->isProcessingEnabled();
@ -268,7 +268,7 @@ void AppController::preferencesAction() @@ -268,7 +268,7 @@ void AppController::preferencesAction()
// Current network interface address
data["current_interface_address"] = BitTorrent::Session::instance()->networkInterfaceAddress();
// Save resume data interval
data["save_resume_data_interval"] = static_cast<double>(session->saveResumeDataInterval());
data["save_resume_data_interval"] = session->saveResumeDataInterval();
// Recheck completed torrents
data["recheck_completed_torrents"] = pref->recheckTorrentsOnCompletion();
// Resolve peer countries
@ -654,7 +654,7 @@ void AppController::setPreferencesAction() @@ -654,7 +654,7 @@ void AppController::setPreferencesAction()
pref->setDynDomainName(it.value().toString());
if (hasKey("rss_refresh_interval"))
RSS::Session::instance()->setRefreshInterval(it.value().toUInt());
RSS::Session::instance()->setRefreshInterval(it.value().toInt());
if (hasKey("rss_max_articles_per_feed"))
RSS::Session::instance()->setMaxArticlesPerFeed(it.value().toInt());
if (hasKey("rss_processing_enabled"))

Loading…
Cancel
Save