Skip to content

Commit

Permalink
Allow save resume interval to be disabled
Browse files Browse the repository at this point in the history
Also raise the allowable upper limit
  • Loading branch information
Chocobo1 committed Jul 5, 2018
1 parent 6a16fc1 commit d61435e
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 12 deletions.
29 changes: 20 additions & 9 deletions src/base/bittorrent/session.cpp
Expand Up @@ -510,11 +510,6 @@ Session::Session(QObject *parent)
connect(m_refreshTimer, &QTimer::timeout, this, &Session::refresh);
m_refreshTimer->start();

// Regular saving of fastresume data
m_resumeDataTimer = new QTimer(this);
m_resumeDataTimer->setInterval(saveResumeDataInterval() * 60 * 1000);
connect(m_resumeDataTimer, &QTimer::timeout, this, [this]() { generateResumeData(); });

m_statistics = new Statistics(this);

updateSeedingLimitTimer();
Expand All @@ -536,7 +531,15 @@ Session::Session(QObject *parent)
m_resumeDataSavingManager->moveToThread(m_ioThread);
connect(m_ioThread, &QThread::finished, m_resumeDataSavingManager, &QObject::deleteLater);
m_ioThread->start();
m_resumeDataTimer->start();

// Regular saving of fastresume data
m_resumeDataTimer = new QTimer(this);
connect(m_resumeDataTimer, &QTimer::timeout, this, [this]() { generateResumeData(); });
const uint saveInterval = saveResumeDataInterval();
if (saveInterval > 0) {

This comment has been minimized.

Copy link
@zeule

zeule Jul 10, 2018

Contributor

@Chocobo1: condition is always true

This comment has been minimized.

Copy link
@Chocobo1

Chocobo1 Jul 10, 2018

Author Member

saveInterval == 0 can be true.

This comment has been minimized.

Copy link
@zeule

zeule Jul 10, 2018

Contributor

Oops, pardon me.

m_resumeDataTimer->setInterval(saveInterval * 60 * 1000);
m_resumeDataTimer->start();
}

// initialize PortForwarder instance
Net::PortForwarder::initInstance(m_nativeSession);
Expand Down Expand Up @@ -2704,11 +2707,19 @@ uint Session::saveResumeDataInterval() const
return m_saveResumeDataInterval;
}

void Session::setSaveResumeDataInterval(uint value)
void Session::setSaveResumeDataInterval(const uint value)
{
if (value != saveResumeDataInterval()) {
m_saveResumeDataInterval = value;
if (value == m_saveResumeDataInterval)
return;

m_saveResumeDataInterval = value;

if (value > 0) {
m_resumeDataTimer->setInterval(value * 60 * 1000);
m_resumeDataTimer->start();
}
else {
m_resumeDataTimer->stop();
}
}

Expand Down
18 changes: 15 additions & 3 deletions src/gui/advancedsettings.cpp
Expand Up @@ -28,6 +28,8 @@

#include "advancedsettings.h"

#include <limits>

#include <QFont>
#include <QHeaderView>
#include <QHostAddress>
Expand Down Expand Up @@ -129,6 +131,8 @@ AdvancedSettings::AdvancedSettings(QWidget *parent)
, this, &AdvancedSettings::updateCacheSpinSuffix);
connect(&comboBoxInterface, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged)
, this, &AdvancedSettings::updateInterfaceAddressCombo);
connect(&spinBoxSaveResumeDataInterval, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged)
, this, &AdvancedSettings::updateSaveResumeDataIntervalSuffix);
// Load settings
loadAdvancedSettings();
resizeColumnToContents(0);
Expand Down Expand Up @@ -241,6 +245,14 @@ void AdvancedSettings::updateCacheSpinSuffix(int value)
spinBoxCache.setSuffix(tr(" MiB"));
}

void AdvancedSettings::updateSaveResumeDataIntervalSuffix(const int value)
{
if (value > 0)
spinBoxSaveResumeDataInterval.setSuffix(tr(" min", " minutes"));
else
spinBoxSaveResumeDataInterval.setSuffix(tr(" (disabled)"));
}

void AdvancedSettings::updateInterfaceAddressCombo()
{
// Try to get the currently selected interface name
Expand Down Expand Up @@ -346,10 +358,10 @@ void AdvancedSettings::loadAdvancedSettings()
spinBoxSendBufferWatermarkFactor.setValue(session->sendBufferWatermarkFactor());
addRow(SEND_BUF_WATERMARK_FACTOR, tr("Send buffer watermark factor"), &spinBoxSendBufferWatermarkFactor);
// Save resume data interval
spinBoxSaveResumeDataInterval.setMinimum(1);
spinBoxSaveResumeDataInterval.setMaximum(1440);
spinBoxSaveResumeDataInterval.setMinimum(0);
spinBoxSaveResumeDataInterval.setMaximum(std::numeric_limits<int>::max());
spinBoxSaveResumeDataInterval.setValue(session->saveResumeDataInterval());
spinBoxSaveResumeDataInterval.setSuffix(tr(" m", " minutes"));
updateSaveResumeDataIntervalSuffix(spinBoxSaveResumeDataInterval.value());
addRow(SAVE_RESUME_DATA_INTERVAL, tr("Save resume data interval", "How often the fastresume file is saved."), &spinBoxSaveResumeDataInterval);
// Outgoing port Min
spinBoxOutgoingPortsMin.setMinimum(0);
Expand Down
1 change: 1 addition & 0 deletions src/gui/advancedsettings.h
Expand Up @@ -51,6 +51,7 @@ public slots:

private slots:
void updateCacheSpinSuffix(int value);
void updateSaveResumeDataIntervalSuffix(int value);
void updateInterfaceAddressCombo();

private:
Expand Down

0 comments on commit d61435e

Please sign in to comment.