36 #include <QMessageBox>
45 #include "ui_torrentoptionsdialog.h"
48 #define SETTINGS_KEY(name) "TorrentOptionsDialog/" name
56 if (
value > slider->maximum())
57 slider->setMaximum(
value);
58 slider->setValue(
value);
66 , m_currentCategoriesString {QString::fromLatin1(
"--%1--").arg(tr(
"Currently used categories"))}
68 Q_ASSERT(!torrents.empty());
73 m_ui->savePath->setDialogCaption(tr(
"Choose save path"));
75 m_ui->downloadPath->setDialogCaption(tr(
"Choose save path"));
78 bool allSameUpLimit =
true;
79 bool allSameDownLimit =
true;
80 bool allSameRatio =
true;
81 bool allSameSeedingTime =
true;
82 bool allTorrentsArePrivate =
true;
83 bool allSameDHT =
true;
84 bool allSamePEX =
true;
85 bool allSameLSD =
true;
86 bool allSameSequential =
true;
87 bool allSameFirstLastPieces =
true;
88 bool allSameAutoTMM =
true;
89 bool allSameSavePath =
true;
90 bool allSameDownloadPath =
true;
92 const bool isFirstTorrentAutoTMMEnabled = torrents[0]->isAutoTMMEnabled();
93 const QString firstTorrentSavePath = torrents[0]->savePath();
94 const QString firstTorrentDownloadPath = torrents[0]->downloadPath();
95 const QString firstTorrentCategory = torrents[0]->category();
97 const int firstTorrentUpLimit = std::max(0, torrents[0]->uploadLimit());
98 const int firstTorrentDownLimit = std::max(0, torrents[0]->downloadLimit());
100 const qreal firstTorrentRatio = torrents[0]->ratioLimit();
101 const int firstTorrentSeedingTime = torrents[0]->seedingTimeLimit();
103 const bool isFirstTorrentDHTDisabled = torrents[0]->isDHTDisabled();
104 const bool isFirstTorrentPEXDisabled = torrents[0]->isPEXDisabled();
105 const bool isFirstTorrentLSDDisabled = torrents[0]->isLSDDisabled();
106 const bool isFirstTorrentSequentialEnabled = torrents[0]->isSequentialDownload();
107 const bool isFirstTorrentFirstLastPiecesEnabled = torrents[0]->hasFirstLastPiecePriority();
116 if (torrent->isAutoTMMEnabled() != isFirstTorrentAutoTMMEnabled)
117 allSameAutoTMM =
false;
121 if (torrent->savePath() != firstTorrentSavePath)
122 allSameSavePath =
false;
124 if (allSameDownloadPath)
126 if (torrent->downloadPath() != firstTorrentDownloadPath)
127 allSameDownloadPath =
false;
131 if (torrent->category() != firstTorrentCategory)
136 if (std::max(0, torrent->uploadLimit()) != firstTorrentUpLimit)
137 allSameUpLimit =
false;
139 if (allSameDownLimit)
141 if (std::max(0, torrent->downloadLimit()) != firstTorrentDownLimit)
142 allSameDownLimit =
false;
146 if (torrent->ratioLimit() != firstTorrentRatio)
147 allSameRatio =
false;
149 if (allSameSeedingTime)
151 if (torrent->seedingTimeLimit() != firstTorrentSeedingTime)
152 allSameSeedingTime =
false;
154 if (allTorrentsArePrivate)
156 if (!torrent->isPrivate())
157 allTorrentsArePrivate =
false;
161 if (torrent->isDHTDisabled() != isFirstTorrentDHTDisabled)
166 if (torrent->isPEXDisabled() != isFirstTorrentPEXDisabled)
171 if (torrent->isLSDDisabled() != isFirstTorrentLSDDisabled)
174 if (allSameSequential)
176 if (torrent->isSequentialDownload() != isFirstTorrentSequentialEnabled)
177 allSameSequential =
false;
179 if (allSameFirstLastPieces)
181 if (torrent->hasFirstLastPiecePriority() != isFirstTorrentFirstLastPiecesEnabled)
182 allSameFirstLastPieces =
false;
187 m_ui->checkAutoTMM->setChecked(isFirstTorrentAutoTMMEnabled);
189 m_ui->checkAutoTMM->setCheckState(Qt::PartiallyChecked);
192 m_ui->savePath->setSelectedPath(firstTorrentSavePath);
194 if (allSameDownloadPath)
196 m_ui->downloadPath->setSelectedPath(firstTorrentDownloadPath);
197 m_ui->checkUseDownloadPath->setChecked(!firstTorrentDownloadPath.isEmpty());
201 m_ui->checkUseDownloadPath->setCheckState(Qt::PartiallyChecked);
207 m_ui->comboCategory->clearEditText();
210 else if (!firstTorrentCategory.isEmpty())
212 m_ui->comboCategory->setCurrentText(firstTorrentCategory);
213 m_ui->comboCategory->addItem(firstTorrentCategory);
215 m_ui->comboCategory->addItem(QString());
227 const bool isAltLimitEnabled = session->isAltGlobalSpeedLimitEnabled();
228 const int globalUploadLimit = isAltLimitEnabled
229 ? (session->altGlobalUploadSpeedLimit() / 1024)
230 : (session->globalUploadSpeedLimit() / 1024);
231 const int globalDownloadLimit = isAltLimitEnabled
232 ? (session->altGlobalDownloadSpeedLimit() / 1024)
233 : (session->globalDownloadSpeedLimit() / 1024);
235 const int uploadVal = std::max(0, (firstTorrentUpLimit / 1024));
236 const int downloadVal = std::max(0, (firstTorrentDownLimit / 1024));
237 int maxUpload = (globalUploadLimit <= 0) ? 10000 : globalUploadLimit;
238 int maxDownload = (globalDownloadLimit <= 0) ? 10000 : globalDownloadLimit;
241 if (uploadVal > maxUpload)
242 maxUpload = uploadVal;
243 if (downloadVal > maxDownload)
244 maxDownload = downloadVal;
246 m_ui->sliderUploadLimit->setMaximum(maxUpload);
247 m_ui->sliderUploadLimit->setValue(allSameUpLimit ? uploadVal : (maxUpload / 2));
250 m_ui->spinUploadLimit->setValue(uploadVal);
254 m_ui->spinUploadLimit->setSpecialValueText(QString::fromUtf8(
C_INEQUALITY));
255 m_ui->spinUploadLimit->setMinimum(-1);
256 m_ui->spinUploadLimit->setValue(-1);
257 connect(
m_ui->spinUploadLimit, qOverload<int>(&QSpinBox::valueChanged)
261 m_ui->sliderDownloadLimit->setMaximum(maxDownload);
262 m_ui->sliderDownloadLimit->setValue(allSameDownLimit ? downloadVal : (maxDownload / 2));
263 if (allSameDownLimit)
265 m_ui->spinDownloadLimit->setValue(downloadVal);
269 m_ui->spinDownloadLimit->setSpecialValueText(QString::fromUtf8(
C_INEQUALITY));
270 m_ui->spinDownloadLimit->setMinimum(-1);
271 m_ui->spinDownloadLimit->setValue(-1);
272 connect(
m_ui->spinDownloadLimit, qOverload<int>(&QSpinBox::valueChanged)
276 const bool useGlobalValue = allSameRatio && allSameSeedingTime
280 if (!allSameRatio || !allSameSeedingTime)
282 m_ui->radioUseGlobalShareLimits->setChecked(
false);
283 m_ui->radioNoLimit->setChecked(
false);
284 m_ui->radioTorrentLimit->setChecked(
false);
286 else if (useGlobalValue)
288 m_ui->radioUseGlobalShareLimits->setChecked(
true);
293 m_ui->radioNoLimit->setChecked(
true);
297 m_ui->radioTorrentLimit->setChecked(
true);
298 if (firstTorrentRatio >= 0)
299 m_ui->checkMaxRatio->setChecked(
true);
300 if (firstTorrentSeedingTime >= 0)
301 m_ui->checkMaxTime->setChecked(
true);
304 const qreal maxRatio = (allSameRatio && (firstTorrentRatio >= 0))
305 ? firstTorrentRatio : session->globalMaxRatio();
306 const int maxSeedingTime = (allSameSeedingTime && (firstTorrentSeedingTime >= 0))
307 ? firstTorrentSeedingTime : session->globalMaxSeedingMinutes();
308 m_ui->spinRatioLimit->setValue(maxRatio);
309 m_ui->spinTimeLimit->setValue(maxSeedingTime);
311 if (!allTorrentsArePrivate)
314 m_ui->checkDisableDHT->setChecked(isFirstTorrentDHTDisabled);
316 m_ui->checkDisableDHT->setCheckState(Qt::PartiallyChecked);
319 m_ui->checkDisablePEX->setChecked(isFirstTorrentPEXDisabled);
321 m_ui->checkDisablePEX->setCheckState(Qt::PartiallyChecked);
324 m_ui->checkDisableLSD->setChecked(isFirstTorrentLSDDisabled);
326 m_ui->checkDisableLSD->setCheckState(Qt::PartiallyChecked);
330 m_ui->checkDisableDHT->setChecked(
true);
331 m_ui->checkDisableDHT->setEnabled(
false);
332 m_ui->checkDisablePEX->setChecked(
true);
333 m_ui->checkDisablePEX->setEnabled(
false);
334 m_ui->checkDisableLSD->setChecked(
true);
335 m_ui->checkDisableLSD->setEnabled(
false);
338 const QString privateTorrentsTooltip = tr(
"Not applicable to private torrents");
339 m_ui->checkDisableDHT->setToolTip(privateTorrentsTooltip);
340 m_ui->checkDisablePEX->setToolTip(privateTorrentsTooltip);
341 m_ui->checkDisableLSD->setToolTip(privateTorrentsTooltip);
343 if (allSameSequential)
344 m_ui->checkSequential->setChecked(isFirstTorrentSequentialEnabled);
346 m_ui->checkSequential->setCheckState(Qt::PartiallyChecked);
348 if (allSameFirstLastPieces)
349 m_ui->checkFirstLastPieces->setChecked(isFirstTorrentFirstLastPiecesEnabled);
351 m_ui->checkFirstLastPieces->setCheckState(Qt::PartiallyChecked);
355 m_ui->savePath->selectedPath(),
356 m_ui->downloadPath->selectedPath(),
357 m_ui->comboCategory->currentText(),
360 m_ui->spinUploadLimit->value(),
361 m_ui->spinDownloadLimit->value(),
362 m_ui->checkAutoTMM->checkState(),
363 m_ui->checkUseDownloadPath->checkState(),
364 m_ui->checkDisableDHT->checkState(),
365 m_ui->checkDisablePEX->checkState(),
366 m_ui->checkDisableLSD->checkState(),
367 m_ui->checkSequential->checkState(),
368 m_ui->checkFirstLastPieces->checkState()
383 connect(
m_ui->spinUploadLimit, qOverload<int>(&QSpinBox::valueChanged)
384 ,
this, [
this](
const int value) { updateSliderValue(m_ui->sliderUploadLimit, value); });
385 connect(
m_ui->spinDownloadLimit, qOverload<int>(&QSpinBox::valueChanged)
386 ,
this, [
this](
const int value) { updateSliderValue(m_ui->sliderDownloadLimit, value); });
388 connect(
m_ui->checkMaxRatio, &QCheckBox::toggled,
m_ui->spinRatioLimit, &QDoubleSpinBox::setEnabled);
389 connect(
m_ui->checkMaxTime, &QCheckBox::toggled,
m_ui->spinTimeLimit, &QSpinBox::setEnabled);
404 if (
m_ui->radioTorrentLimit->isChecked() && !
m_ui->checkMaxRatio->isChecked() && !
m_ui->checkMaxTime->isChecked())
406 QMessageBox::critical(
this, tr(
"No share limit method selected"), tr(
"Please select a limit method first"));
414 if (!torrent)
continue;
419 if (
m_ui->checkAutoTMM->checkState() == Qt::Unchecked)
421 const QString
savePath =
m_ui->savePath->selectedPath();
425 const Qt::CheckState useDownloadPathState =
m_ui->checkUseDownloadPath->checkState();
426 if (useDownloadPathState == Qt::Checked)
432 else if (useDownloadPathState == Qt::Unchecked)
438 const QString
category =
m_ui->comboCategory->currentText();
453 const qreal ratioLimit =
getRatio();
482 if (
m_ui->buttonGroup->checkedId() == -1)
485 if (
m_ui->radioUseGlobalShareLimits->isChecked())
488 if (
m_ui->radioNoLimit->isChecked() || !
m_ui->checkMaxRatio->isChecked())
491 return m_ui->spinRatioLimit->value();
496 if (
m_ui->buttonGroup->checkedId() == -1)
499 if (
m_ui->radioUseGlobalShareLimits->isChecked())
502 if (
m_ui->radioNoLimit->isChecked() || !
m_ui->checkMaxTime->isChecked())
505 return m_ui->spinTimeLimit->value();
512 if (
m_ui->checkAutoTMM->checkState() == Qt::Checked)
516 m_ui->savePath->setSelectedPath(QString());
527 m_ui->comboCategory->clearEditText();
532 m_ui->comboCategory->lineEdit()->setPlaceholderText(QString());
538 if (
m_ui->checkAutoTMM->checkState() == Qt::Unchecked)
540 m_ui->groupBoxSavePath->setEnabled(
true);
547 m_ui->groupBoxSavePath->setEnabled(
false);
548 if (
m_ui->checkAutoTMM->checkState() == Qt::Checked)
552 m_ui->savePath->setSelectedPath(QString());
553 m_ui->downloadPath->setSelectedPath(QString());
554 m_ui->checkUseDownloadPath->setCheckState(Qt::PartiallyChecked);
567 m_ui->savePath->setSelectedPath(QString());
568 m_ui->downloadPath->setSelectedPath(QString());
569 m_ui->checkUseDownloadPath->setCheckState(Qt::PartiallyChecked);
576 const bool isChecked =
m_ui->checkUseDownloadPath->checkState() == Qt::Checked;
577 m_ui->downloadPath->setEnabled(isChecked);
578 if (isChecked &&
m_ui->downloadPath->selectedPath().isEmpty())
586 QAbstractButton *currentRadio =
m_ui->buttonGroup->checkedButton();
590 m_ui->buttonGroup->setExclusive(
false);
591 currentRadio->setChecked(
false);
592 m_ui->buttonGroup->setExclusive(
true);
597 m_ui->checkMaxRatio->setEnabled(
m_ui->radioTorrentLimit->isChecked());
598 m_ui->checkMaxTime->setEnabled(
m_ui->radioTorrentLimit->isChecked());
600 m_ui->spinRatioLimit->setEnabled(
m_ui->radioTorrentLimit->isChecked() &&
m_ui->checkMaxRatio->isChecked());
601 m_ui->spinTimeLimit->setEnabled(
m_ui->radioTorrentLimit->isChecked() &&
m_ui->checkMaxTime->isChecked());
606 m_ui->spinUploadLimit->setMinimum(0);
607 m_ui->spinUploadLimit->setSpecialValueText(QString::fromUtf8(
C_INFINITY));
608 disconnect(
m_ui->spinUploadLimit, qOverload<int>(&QSpinBox::valueChanged)
614 m_ui->spinDownloadLimit->setMinimum(0);
615 m_ui->spinDownloadLimit->setSpecialValueText(QString::fromUtf8(
C_INFINITY));
616 disconnect(
m_ui->spinDownloadLimit, qOverload<int>(&QSpinBox::valueChanged)
static Session * instance()
QString categorySavePath(const QString &categoryName) const
QString categoryDownloadPath(const QString &categoryName) const
static const int NO_SEEDING_TIME_LIMIT
virtual void setDHTDisabled(bool disable)=0
virtual void setSequentialDownload(bool enable)=0
virtual void setAutoTMMEnabled(bool enabled)=0
virtual void setDownloadPath(const QString &downloadPath)=0
static const int USE_GLOBAL_SEEDING_TIME
virtual void setFirstLastPiecePriority(bool enabled)=0
static const qreal NO_RATIO_LIMIT
virtual void setUploadLimit(int limit)=0
virtual void setSeedingTimeLimit(int limit)=0
virtual void setSavePath(const QString &savePath)=0
virtual bool setCategory(const QString &category)=0
virtual bool isPrivate() const =0
static const qreal USE_GLOBAL_RATIO
virtual void setDownloadLimit(int limit)=0
virtual void setLSDDisabled(bool disable)=0
virtual void setPEXDisabled(bool disable)=0
virtual void setRatioLimit(qreal limit)=0
@ DirectorySave
selecting directories for saving
Ui::TorrentOptionsDialog * m_ui
void handleRatioTypeChanged()
QAbstractButton * m_previousRadio
struct TorrentOptionsDialog::@10 m_initialValues
void handleDownSpeedLimitChanged()
int getSeedingTime() const
QString m_currentCategoriesString
SettingValue< QSize > m_storeDialogSize
void handleCategoryChanged(int index)
~TorrentOptionsDialog() override
QVector< BitTorrent::TorrentID > m_torrentIDs
void handleUpSpeedLimitChanged()
void handleUseDownloadPathChanged()
TorrentOptionsDialog(QWidget *parent, const QVector< BitTorrent::Torrent * > &torrents)
constexpr std::add_const_t< T > & asConst(T &t) noexcept
QString expandPathAbs(const QString &path)
QString toNativePath(const QString &path)
void resize(QWidget *widget, const QSize &newSize={})
void setValue(const QString &key, const T &value)
T value(const QString &key, const T &defaultValue={})
void updateSliderValue(QSlider *slider, const int value)
const int MIXED_SHARE_LIMITS
#define SETTINGS_KEY(name)
const char C_INEQUALITY[]