Add seeding limits to RSS and Watched folders options UI

PR #20324.
Closes #19605.
This commit is contained in:
Vladimir Golovnev 2024-01-27 14:30:27 +03:00 committed by GitHub
parent df41940ebc
commit d652a10495
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 450 additions and 2 deletions

View file

@ -29,6 +29,7 @@ qt_wrap_ui(UI_HEADERS
torrentcategorydialog.ui
torrentcreatordialog.ui
torrentoptionsdialog.ui
torrentsharelimitswidget.ui
torrenttagsdialog.ui
trackerentriesdialog.ui
trackersadditiondialog.ui
@ -104,6 +105,7 @@ add_library(qbt_gui STATIC
torrentcontentwidget.h
torrentcreatordialog.h
torrentoptionsdialog.h
torrentsharelimitswidget.h
torrenttagsdialog.h
trackerentriesdialog.h
trackerlist/trackerlistitemdelegate.h
@ -200,6 +202,7 @@ add_library(qbt_gui STATIC
torrentcontentwidget.cpp
torrentcreatordialog.cpp
torrentoptionsdialog.cpp
torrentsharelimitswidget.cpp
torrenttagsdialog.cpp
trackerentriesdialog.cpp
trackerlist/trackerlistitemdelegate.cpp

View file

@ -143,7 +143,12 @@ void AddTorrentParamsWidget::setAddTorrentParams(BitTorrent::AddTorrentParams ad
BitTorrent::AddTorrentParams AddTorrentParamsWidget::addTorrentParams() const
{
return cleanParams(m_addTorrentParams);
BitTorrent::AddTorrentParams addTorrentParams = cleanParams(m_addTorrentParams);
addTorrentParams.ratioLimit = m_ui->torrentShareLimitsWidget->ratioLimit();
addTorrentParams.seedingTimeLimit = m_ui->torrentShareLimitsWidget->seedingTimeLimit();
addTorrentParams.inactiveSeedingTimeLimit = m_ui->torrentShareLimitsWidget->inactiveSeedingTimeLimit();
return addTorrentParams;
}
void AddTorrentParamsWidget::populate()
@ -263,6 +268,9 @@ void AddTorrentParamsWidget::populate()
else
m_addTorrentParams.addToQueueTop = data.toBool();
});
m_ui->torrentShareLimitsWidget->setTorrentShareLimits(m_addTorrentParams.ratioLimit
, m_addTorrentParams.seedingTimeLimit, m_addTorrentParams.inactiveSeedingTimeLimit);
}
void AddTorrentParamsWidget::loadCustomSavePathOptions()

View file

@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>503</width>
<height>366</height>
<height>440</height>
</rect>
</property>
<property name="windowTitle">
@ -348,6 +348,18 @@
</widget>
</widget>
</item>
<item>
<widget class="QGroupBox" name="torrentShareLimitsBox">
<property name="title">
<string>Torrent share limits</string>
</property>
<layout class="QVBoxLayout" name="torrentShareLimitsBoxLayout">
<item>
<widget class="TorrentShareLimitsWidget" name="torrentShareLimitsWidget" native="true"/>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<customwidgets>
@ -357,6 +369,12 @@
<header>gui/fspathedit.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>TorrentShareLimitsWidget</class>
<extends>QWidget</extends>
<header>gui/torrentsharelimitswidget.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/>

View file

@ -0,0 +1,187 @@
/*
* Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2024 Vladimir Golovnev <glassez@yandex.ru>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* In addition, as a special exception, the copyright holders give permission to
* link this program with the OpenSSL project's "OpenSSL" library (or with
* modified versions of it that use the same license as the "OpenSSL" library),
* and distribute the linked executables. You must obey the GNU General Public
* License in all respects for all of the code used other than "OpenSSL". If you
* modify file(s), you may extend this exception to your version of the file(s),
* but you are not obligated to do so. If you do not wish to do so, delete this
* exception statement from your version.
*/
#include "torrentsharelimitswidget.h"
#include "ui_torrentsharelimitswidget.h"
namespace
{
enum ShareLimitModeIndex
{
DefaultModeIndex,
UnlimitedModeIndex,
AssignedModeIndex
};
}
TorrentShareLimitsWidget::TorrentShareLimitsWidget(QWidget *parent, const qreal ratioLimit
, const int seedingTimeLimit, const int inactiveSeedingTimeLimit)
: QWidget(parent)
, m_ui {new Ui::TorrentShareLimitsWidget}
{
m_ui->setupUi(this);
connect(m_ui->comboBoxRatioMode, &QComboBox::currentIndexChanged, this, [this](const int index)
{
m_ui->spinBoxRatioValue->setEnabled(index == AssignedModeIndex);
if (index == AssignedModeIndex)
{
m_ui->spinBoxRatioValue->setValue(m_ratioLimit);
}
else
{
m_ratioLimit = m_ui->spinBoxRatioValue->value();
m_ui->spinBoxRatioValue->clear();
}
});
connect(m_ui->comboBoxSeedingTimeMode, &QComboBox::currentIndexChanged, this, [this](const int index)
{
m_ui->spinBoxSeedingTimeValue->setEnabled(index == AssignedModeIndex);
if (index == AssignedModeIndex)
{
m_ui->spinBoxSeedingTimeValue->setValue(m_seedingTimeLimit);
m_ui->spinBoxSeedingTimeValue->setSuffix(tr(" min"));
}
else
{
m_seedingTimeLimit = m_ui->spinBoxSeedingTimeValue->value();
m_ui->spinBoxSeedingTimeValue->setSuffix({});
m_ui->spinBoxSeedingTimeValue->clear();
}
});
connect(m_ui->comboBoxInactiveSeedingTimeMode, &QComboBox::currentIndexChanged, this, [this](const int index)
{
m_ui->spinBoxInactiveSeedingTimeValue->setEnabled(index == AssignedModeIndex);
if (index == AssignedModeIndex)
{
m_ui->spinBoxInactiveSeedingTimeValue->setValue(m_inactiveSeedingTimeLimit);
m_ui->spinBoxInactiveSeedingTimeValue->setSuffix(tr(" min"));
}
else
{
m_inactiveSeedingTimeLimit = m_ui->spinBoxInactiveSeedingTimeValue->value();
m_ui->spinBoxInactiveSeedingTimeValue->setSuffix({});
m_ui->spinBoxInactiveSeedingTimeValue->clear();
}
});
setTorrentShareLimits(ratioLimit, seedingTimeLimit, inactiveSeedingTimeLimit);
}
TorrentShareLimitsWidget::~TorrentShareLimitsWidget()
{
delete m_ui;
}
void TorrentShareLimitsWidget::setTorrentShareLimits(const qreal ratioLimit, const int seedingTimeLimit, const int inactiveSeedingTimeLimit)
{
if (ratioLimit == BitTorrent::Torrent::USE_GLOBAL_RATIO)
{
m_ui->comboBoxRatioMode->setCurrentIndex(DefaultModeIndex);
}
else if (ratioLimit == BitTorrent::Torrent::NO_RATIO_LIMIT)
{
m_ui->comboBoxRatioMode->setCurrentIndex(UnlimitedModeIndex);
}
else
{
m_ui->comboBoxRatioMode->setCurrentIndex(AssignedModeIndex);
m_ui->spinBoxRatioValue->setValue(ratioLimit);
}
if (seedingTimeLimit == BitTorrent::Torrent::USE_GLOBAL_SEEDING_TIME)
{
m_ui->comboBoxSeedingTimeMode->setCurrentIndex(DefaultModeIndex);
}
else if (seedingTimeLimit == BitTorrent::Torrent::NO_SEEDING_TIME_LIMIT)
{
m_ui->comboBoxSeedingTimeMode->setCurrentIndex(UnlimitedModeIndex);
}
else
{
m_ui->comboBoxSeedingTimeMode->setCurrentIndex(AssignedModeIndex);
m_ui->spinBoxSeedingTimeValue->setValue(seedingTimeLimit);
}
if (inactiveSeedingTimeLimit == BitTorrent::Torrent::USE_GLOBAL_INACTIVE_SEEDING_TIME)
{
m_ui->comboBoxInactiveSeedingTimeMode->setCurrentIndex(DefaultModeIndex);
}
else if (inactiveSeedingTimeLimit == BitTorrent::Torrent::NO_INACTIVE_SEEDING_TIME_LIMIT)
{
m_ui->comboBoxInactiveSeedingTimeMode->setCurrentIndex(UnlimitedModeIndex);
}
else
{
m_ui->comboBoxInactiveSeedingTimeMode->setCurrentIndex(AssignedModeIndex);
m_ui->spinBoxInactiveSeedingTimeValue->setValue(inactiveSeedingTimeLimit);
}
}
qreal TorrentShareLimitsWidget::ratioLimit() const
{
switch (m_ui->comboBoxRatioMode->currentIndex())
{
case DefaultModeIndex:
default:
return BitTorrent::Torrent::USE_GLOBAL_RATIO;
case UnlimitedModeIndex:
return BitTorrent::Torrent::NO_RATIO_LIMIT;
case AssignedModeIndex:
return m_ui->spinBoxRatioValue->value();
}
}
int TorrentShareLimitsWidget::seedingTimeLimit() const
{
switch (m_ui->comboBoxSeedingTimeMode->currentIndex())
{
case DefaultModeIndex:
default:
return BitTorrent::Torrent::USE_GLOBAL_SEEDING_TIME;
case UnlimitedModeIndex:
return BitTorrent::Torrent::NO_SEEDING_TIME_LIMIT;
case AssignedModeIndex:
return m_ui->spinBoxSeedingTimeValue->value();
}
}
int TorrentShareLimitsWidget::inactiveSeedingTimeLimit() const
{
switch (m_ui->comboBoxInactiveSeedingTimeMode->currentIndex())
{
case DefaultModeIndex:
default:
return BitTorrent::Torrent::USE_GLOBAL_INACTIVE_SEEDING_TIME;
case UnlimitedModeIndex:
return BitTorrent::Torrent::NO_INACTIVE_SEEDING_TIME_LIMIT;
case AssignedModeIndex:
return m_ui->spinBoxInactiveSeedingTimeValue->value();
}
}

View file

@ -0,0 +1,63 @@
/*
* Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2024 Vladimir Golovnev <glassez@yandex.ru>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* In addition, as a special exception, the copyright holders give permission to
* link this program with the OpenSSL project's "OpenSSL" library (or with
* modified versions of it that use the same license as the "OpenSSL" library),
* and distribute the linked executables. You must obey the GNU General Public
* License in all respects for all of the code used other than "OpenSSL". If you
* modify file(s), you may extend this exception to your version of the file(s),
* but you are not obligated to do so. If you do not wish to do so, delete this
* exception statement from your version.
*/
#pragma once
#include <QWidget>
#include "base/bittorrent/torrent.h"
namespace Ui
{
class TorrentShareLimitsWidget;
}
class TorrentShareLimitsWidget final : public QWidget
{
Q_OBJECT
Q_DISABLE_COPY_MOVE(TorrentShareLimitsWidget)
public:
explicit TorrentShareLimitsWidget(QWidget *parent = nullptr
, qreal ratioLimit = BitTorrent::Torrent::USE_GLOBAL_RATIO
, int seedingTimeLimit = BitTorrent::Torrent::USE_GLOBAL_SEEDING_TIME
, int inactiveSeedingTimeLimit = BitTorrent::Torrent::USE_GLOBAL_INACTIVE_SEEDING_TIME);
~TorrentShareLimitsWidget() override;
void setTorrentShareLimits(qreal ratioLimit, int seedingTimeLimit, int inactiveSeedingTimeLimit);
qreal ratioLimit() const;
int seedingTimeLimit() const;
int inactiveSeedingTimeLimit() const;
private:
Ui::TorrentShareLimitsWidget *m_ui = nullptr;
int m_seedingTimeLimit = 0;
int m_inactiveSeedingTimeLimit = 0;
qreal m_ratioLimit = 0;
};

View file

@ -0,0 +1,169 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>TorrentShareLimitsWidget</class>
<widget class="QWidget" name="TorrentShareLimitsWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>365</width>
<height>106</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="1">
<widget class="QComboBox" name="comboBoxRatioMode">
<property name="currentIndex">
<number>-1</number>
</property>
<item>
<property name="text">
<string>Default</string>
</property>
</item>
<item>
<property name="text">
<string>Unlimited</string>
</property>
</item>
<item>
<property name="text">
<string>Set to</string>
</property>
</item>
</widget>
</item>
<item row="2" column="1">
<widget class="QComboBox" name="comboBoxInactiveSeedingTimeMode">
<property name="currentIndex">
<number>-1</number>
</property>
<item>
<property name="text">
<string>Default</string>
</property>
</item>
<item>
<property name="text">
<string>Unlimited</string>
</property>
</item>
<item>
<property name="text">
<string>Set to</string>
</property>
</item>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="labelSeedingTime">
<property name="text">
<string>Seeding time:</string>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QSpinBox" name="spinBoxInactiveSeedingTimeValue">
<property name="enabled">
<bool>false</bool>
</property>
<property name="suffix">
<string extracomment="minutes"> min</string>
</property>
<property name="maximum">
<number>9999999</number>
</property>
<property name="value">
<number>1440</number>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="labelInactiveSeedingTime">
<property name="text">
<string>Inactive seeding time:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="comboBoxSeedingTimeMode">
<property name="currentIndex">
<number>-1</number>
</property>
<item>
<property name="text">
<string>Default</string>
</property>
</item>
<item>
<property name="text">
<string>Unlimited</string>
</property>
</item>
<item>
<property name="text">
<string>Set to</string>
</property>
</item>
</widget>
</item>
<item row="1" column="2">
<widget class="QSpinBox" name="spinBoxSeedingTimeValue">
<property name="enabled">
<bool>false</bool>
</property>
<property name="suffix">
<string extracomment="minutes"> min</string>
</property>
<property name="maximum">
<number>9999999</number>
</property>
<property name="value">
<number>1440</number>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QDoubleSpinBox" name="spinBoxRatioValue">
<property name="enabled">
<bool>false</bool>
</property>
<property name="maximum">
<double>9998.000000000000000</double>
</property>
<property name="singleStep">
<double>0.050000000000000</double>
</property>
<property name="value">
<double>1.000000000000000</double>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="labelRatio">
<property name="text">
<string>Ratio:</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>