diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index b939b1fa8..afaf9e68a 100644 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -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 diff --git a/src/gui/addtorrentparamswidget.cpp b/src/gui/addtorrentparamswidget.cpp index dfad28bff..c9cced609 100644 --- a/src/gui/addtorrentparamswidget.cpp +++ b/src/gui/addtorrentparamswidget.cpp @@ -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() diff --git a/src/gui/addtorrentparamswidget.ui b/src/gui/addtorrentparamswidget.ui index e43d88169..455dd764f 100644 --- a/src/gui/addtorrentparamswidget.ui +++ b/src/gui/addtorrentparamswidget.ui @@ -7,7 +7,7 @@ 0 0 503 - 366 + 440 @@ -348,6 +348,18 @@ + + + + Torrent share limits + + + + + + + + @@ -357,6 +369,12 @@
gui/fspathedit.h
1 + + TorrentShareLimitsWidget + QWidget +
gui/torrentsharelimitswidget.h
+ 1 +
diff --git a/src/gui/torrentsharelimitswidget.cpp b/src/gui/torrentsharelimitswidget.cpp new file mode 100644 index 000000000..953222fe4 --- /dev/null +++ b/src/gui/torrentsharelimitswidget.cpp @@ -0,0 +1,187 @@ +/* + * Bittorrent Client using Qt and libtorrent. + * Copyright (C) 2024 Vladimir Golovnev + * + * 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(); + } +} diff --git a/src/gui/torrentsharelimitswidget.h b/src/gui/torrentsharelimitswidget.h new file mode 100644 index 000000000..def7d2a35 --- /dev/null +++ b/src/gui/torrentsharelimitswidget.h @@ -0,0 +1,63 @@ +/* + * Bittorrent Client using Qt and libtorrent. + * Copyright (C) 2024 Vladimir Golovnev + * + * 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 + +#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; +}; diff --git a/src/gui/torrentsharelimitswidget.ui b/src/gui/torrentsharelimitswidget.ui new file mode 100644 index 000000000..310c6482e --- /dev/null +++ b/src/gui/torrentsharelimitswidget.ui @@ -0,0 +1,169 @@ + + + TorrentShareLimitsWidget + + + + 0 + 0 + 365 + 106 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + -1 + + + + Default + + + + + Unlimited + + + + + Set to + + + + + + + + -1 + + + + Default + + + + + Unlimited + + + + + Set to + + + + + + + + Seeding time: + + + + + + + false + + + min + + + 9999999 + + + 1440 + + + + + + + Inactive seeding time: + + + + + + + -1 + + + + Default + + + + + Unlimited + + + + + Set to + + + + + + + + false + + + min + + + 9999999 + + + 1440 + + + + + + + false + + + 9998.000000000000000 + + + 0.050000000000000 + + + 1.000000000000000 + + + + + + + Ratio: + + + + + + + + + +