2 * Bittorrent Client using Qt and libtorrent.
3 * Copyright (C) 2024 Vladimir Golovnev <glassez@yandex.ru>
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 * In addition, as a special exception, the copyright holders give permission to
20 * link this program with the OpenSSL project's "OpenSSL" library (or with
21 * modified versions of it that use the same license as the "OpenSSL" library),
22 * and distribute the linked executables. You must obey the GNU General Public
23 * License in all respects for all of the code used other than "OpenSSL". If you
24 * modify file(s), you may extend this exception to your version of the file(s),
25 * but you are not obligated to do so. If you do not wish to do so, delete this
26 * exception statement from your version.
29 #include "torrentsharelimitswidget.h"
31 #include "ui_torrentsharelimitswidget.h"
35 enum ShareLimitModeIndex
43 TorrentShareLimitsWidget::TorrentShareLimitsWidget(QWidget
*parent
, const qreal ratioLimit
44 , const int seedingTimeLimit
, const int inactiveSeedingTimeLimit
)
46 , m_ui
{new Ui::TorrentShareLimitsWidget
}
50 connect(m_ui
->comboBoxRatioMode
, &QComboBox::currentIndexChanged
, this, [this](const int index
)
52 m_ui
->spinBoxRatioValue
->setEnabled(index
== AssignedModeIndex
);
53 if (index
== AssignedModeIndex
)
55 m_ui
->spinBoxRatioValue
->setValue(m_ratioLimit
);
59 m_ratioLimit
= m_ui
->spinBoxRatioValue
->value();
60 m_ui
->spinBoxRatioValue
->clear();
63 connect(m_ui
->comboBoxSeedingTimeMode
, &QComboBox::currentIndexChanged
, this, [this](const int index
)
65 m_ui
->spinBoxSeedingTimeValue
->setEnabled(index
== AssignedModeIndex
);
66 if (index
== AssignedModeIndex
)
68 m_ui
->spinBoxSeedingTimeValue
->setValue(m_seedingTimeLimit
);
69 m_ui
->spinBoxSeedingTimeValue
->setSuffix(tr(" min"));
73 m_seedingTimeLimit
= m_ui
->spinBoxSeedingTimeValue
->value();
74 m_ui
->spinBoxSeedingTimeValue
->setSuffix({});
75 m_ui
->spinBoxSeedingTimeValue
->clear();
78 connect(m_ui
->comboBoxInactiveSeedingTimeMode
, &QComboBox::currentIndexChanged
, this, [this](const int index
)
80 m_ui
->spinBoxInactiveSeedingTimeValue
->setEnabled(index
== AssignedModeIndex
);
81 if (index
== AssignedModeIndex
)
83 m_ui
->spinBoxInactiveSeedingTimeValue
->setValue(m_inactiveSeedingTimeLimit
);
84 m_ui
->spinBoxInactiveSeedingTimeValue
->setSuffix(tr(" min"));
88 m_inactiveSeedingTimeLimit
= m_ui
->spinBoxInactiveSeedingTimeValue
->value();
89 m_ui
->spinBoxInactiveSeedingTimeValue
->setSuffix({});
90 m_ui
->spinBoxInactiveSeedingTimeValue
->clear();
94 setTorrentShareLimits(ratioLimit
, seedingTimeLimit
, inactiveSeedingTimeLimit
);
97 TorrentShareLimitsWidget::~TorrentShareLimitsWidget()
102 void TorrentShareLimitsWidget::setTorrentShareLimits(const qreal ratioLimit
, const int seedingTimeLimit
, const int inactiveSeedingTimeLimit
)
104 if (ratioLimit
== BitTorrent::Torrent::USE_GLOBAL_RATIO
)
106 m_ui
->comboBoxRatioMode
->setCurrentIndex(DefaultModeIndex
);
108 else if (ratioLimit
== BitTorrent::Torrent::NO_RATIO_LIMIT
)
110 m_ui
->comboBoxRatioMode
->setCurrentIndex(UnlimitedModeIndex
);
114 m_ui
->comboBoxRatioMode
->setCurrentIndex(AssignedModeIndex
);
115 m_ui
->spinBoxRatioValue
->setValue(ratioLimit
);
118 if (seedingTimeLimit
== BitTorrent::Torrent::USE_GLOBAL_SEEDING_TIME
)
120 m_ui
->comboBoxSeedingTimeMode
->setCurrentIndex(DefaultModeIndex
);
122 else if (seedingTimeLimit
== BitTorrent::Torrent::NO_SEEDING_TIME_LIMIT
)
124 m_ui
->comboBoxSeedingTimeMode
->setCurrentIndex(UnlimitedModeIndex
);
128 m_ui
->comboBoxSeedingTimeMode
->setCurrentIndex(AssignedModeIndex
);
129 m_ui
->spinBoxSeedingTimeValue
->setValue(seedingTimeLimit
);
132 if (inactiveSeedingTimeLimit
== BitTorrent::Torrent::USE_GLOBAL_INACTIVE_SEEDING_TIME
)
134 m_ui
->comboBoxInactiveSeedingTimeMode
->setCurrentIndex(DefaultModeIndex
);
136 else if (inactiveSeedingTimeLimit
== BitTorrent::Torrent::NO_INACTIVE_SEEDING_TIME_LIMIT
)
138 m_ui
->comboBoxInactiveSeedingTimeMode
->setCurrentIndex(UnlimitedModeIndex
);
142 m_ui
->comboBoxInactiveSeedingTimeMode
->setCurrentIndex(AssignedModeIndex
);
143 m_ui
->spinBoxInactiveSeedingTimeValue
->setValue(inactiveSeedingTimeLimit
);
147 qreal
TorrentShareLimitsWidget::ratioLimit() const
149 switch (m_ui
->comboBoxRatioMode
->currentIndex())
151 case DefaultModeIndex
:
153 return BitTorrent::Torrent::USE_GLOBAL_RATIO
;
154 case UnlimitedModeIndex
:
155 return BitTorrent::Torrent::NO_RATIO_LIMIT
;
156 case AssignedModeIndex
:
157 return m_ui
->spinBoxRatioValue
->value();
161 int TorrentShareLimitsWidget::seedingTimeLimit() const
163 switch (m_ui
->comboBoxSeedingTimeMode
->currentIndex())
165 case DefaultModeIndex
:
167 return BitTorrent::Torrent::USE_GLOBAL_SEEDING_TIME
;
168 case UnlimitedModeIndex
:
169 return BitTorrent::Torrent::NO_SEEDING_TIME_LIMIT
;
170 case AssignedModeIndex
:
171 return m_ui
->spinBoxSeedingTimeValue
->value();
175 int TorrentShareLimitsWidget::inactiveSeedingTimeLimit() const
177 switch (m_ui
->comboBoxInactiveSeedingTimeMode
->currentIndex())
179 case DefaultModeIndex
:
181 return BitTorrent::Torrent::USE_GLOBAL_INACTIVE_SEEDING_TIME
;
182 case UnlimitedModeIndex
:
183 return BitTorrent::Torrent::NO_INACTIVE_SEEDING_TIME_LIMIT
;
184 case AssignedModeIndex
:
185 return m_ui
->spinBoxInactiveSeedingTimeValue
->value();