1
1
/*
2
2
* Bittorrent Client using Qt and libtorrent.
3
+ * Copyright (C) 2024 Vladimir Golovnev <glassez@yandex.ru>
3
4
* Copyright (C) 2020 thalieht
4
5
* Copyright (C) 2011 Christian Kandeler
5
6
* Copyright (C) 2011 Christophe Dumez <chris@qbittorrent.org>
49
50
50
51
namespace
51
52
{
52
- const int MIXED_SHARE_LIMITS = -9 ;
53
-
54
53
void updateSliderValue (QSlider *slider, const int value)
55
54
{
56
55
if (value > slider->maximum ())
@@ -283,47 +282,13 @@ TorrentOptionsDialog::TorrentOptionsDialog(QWidget *parent, const QVector<BitTor
283
282
, this , &TorrentOptionsDialog::handleDownSpeedLimitChanged);
284
283
}
285
284
286
- const bool useGlobalValue = allSameRatio && allSameSeedingTime
287
- && (firstTorrentRatio == BitTorrent::Torrent::USE_GLOBAL_RATIO)
288
- && (firstTorrentSeedingTime == BitTorrent::Torrent::USE_GLOBAL_SEEDING_TIME)
289
- && (firstTorrentInactiveSeedingTime == BitTorrent::Torrent::USE_GLOBAL_INACTIVE_SEEDING_TIME);
290
-
291
- if (!allSameRatio || !allSameSeedingTime || !allSameInactiveSeedingTime)
292
- {
293
- m_ui->radioUseGlobalShareLimits ->setChecked (false );
294
- m_ui->radioNoLimit ->setChecked (false );
295
- m_ui->radioTorrentLimit ->setChecked (false );
296
- }
297
- else if (useGlobalValue)
298
- {
299
- m_ui->radioUseGlobalShareLimits ->setChecked (true );
300
- }
301
- else if ((firstTorrentRatio == BitTorrent::Torrent::NO_RATIO_LIMIT)
302
- && (firstTorrentSeedingTime == BitTorrent::Torrent::NO_SEEDING_TIME_LIMIT)
303
- && (firstTorrentInactiveSeedingTime == BitTorrent::Torrent::NO_INACTIVE_SEEDING_TIME_LIMIT))
304
- {
305
- m_ui->radioNoLimit ->setChecked (true );
306
- }
307
- else
308
- {
309
- m_ui->radioTorrentLimit ->setChecked (true );
310
- if (firstTorrentRatio >= 0 )
311
- m_ui->checkMaxRatio ->setChecked (true );
312
- if (firstTorrentSeedingTime >= 0 )
313
- m_ui->checkMaxTime ->setChecked (true );
314
- if (firstTorrentInactiveSeedingTime >= 0 )
315
- m_ui->checkMaxInactiveTime ->setChecked (true );
316
- }
317
-
318
- const qreal maxRatio = (allSameRatio && (firstTorrentRatio >= 0 ))
319
- ? firstTorrentRatio : session->globalMaxRatio ();
320
- const int maxSeedingTime = (allSameSeedingTime && (firstTorrentSeedingTime >= 0 ))
321
- ? firstTorrentSeedingTime : session->globalMaxSeedingMinutes ();
322
- const int maxInactiveSeedingTime = (allSameInactiveSeedingTime && (firstTorrentInactiveSeedingTime >= 0 ))
323
- ? firstTorrentInactiveSeedingTime : session->globalMaxInactiveSeedingMinutes ();
324
- m_ui->spinRatioLimit ->setValue (maxRatio);
325
- m_ui->spinTimeLimit ->setValue (maxSeedingTime);
326
- m_ui->spinInactiveTimeLimit ->setValue (maxInactiveSeedingTime);
285
+ m_ui->torrentShareLimitsWidget ->setDefaultLimits (session->globalMaxRatio (), session->globalMaxSeedingMinutes (), session->globalMaxInactiveSeedingMinutes ());
286
+ if (allSameRatio)
287
+ m_ui->torrentShareLimitsWidget ->setRatioLimit (firstTorrentRatio);
288
+ if (allSameSeedingTime)
289
+ m_ui->torrentShareLimitsWidget ->setSeedingTimeLimit (firstTorrentSeedingTime);
290
+ if (allSameInactiveSeedingTime)
291
+ m_ui->torrentShareLimitsWidget ->setInactiveSeedingTimeLimit (firstTorrentInactiveSeedingTime);
327
292
328
293
if (!allTorrentsArePrivate)
329
294
{
@@ -369,27 +334,26 @@ TorrentOptionsDialog::TorrentOptionsDialog(QWidget *parent, const QVector<BitTor
369
334
370
335
m_initialValues =
371
336
{
372
- m_ui->savePath ->selectedPath (),
373
- m_ui->downloadPath ->selectedPath (),
374
- m_ui->comboCategory ->currentText (),
375
- getRatio (),
376
- getSeedingTime (),
377
- getInactiveSeedingTime (),
378
- m_ui->spinUploadLimit ->value (),
379
- m_ui->spinDownloadLimit ->value (),
380
- m_ui->checkAutoTMM ->checkState (),
381
- m_ui->checkUseDownloadPath ->checkState (),
382
- m_ui->checkDisableDHT ->checkState (),
383
- m_ui->checkDisablePEX ->checkState (),
384
- m_ui->checkDisableLSD ->checkState (),
385
- m_ui->checkSequential ->checkState (),
386
- m_ui->checkFirstLastPieces ->checkState ()
337
+ . savePath = m_ui->savePath ->selectedPath (),
338
+ . downloadPath = m_ui->downloadPath ->selectedPath (),
339
+ . category = m_ui->comboCategory ->currentText (),
340
+ . ratio = m_ui-> torrentShareLimitsWidget -> ratioLimit (),
341
+ . seedingTime = m_ui-> torrentShareLimitsWidget -> seedingTimeLimit (),
342
+ . inactiveSeedingTime = m_ui-> torrentShareLimitsWidget -> inactiveSeedingTimeLimit (),
343
+ . upSpeedLimit = m_ui->spinUploadLimit ->value (),
344
+ . downSpeedLimit = m_ui->spinDownloadLimit ->value (),
345
+ . autoTMM = m_ui->checkAutoTMM ->checkState (),
346
+ . useDownloadPath = m_ui->checkUseDownloadPath ->checkState (),
347
+ . disableDHT = m_ui->checkDisableDHT ->checkState (),
348
+ . disablePEX = m_ui->checkDisablePEX ->checkState (),
349
+ . disableLSD = m_ui->checkDisableLSD ->checkState (),
350
+ . sequential = m_ui->checkSequential ->checkState (),
351
+ . firstLastPieces = m_ui->checkFirstLastPieces ->checkState ()
387
352
};
388
353
389
354
// Needs to be called after the initial values struct is initialized
390
355
handleTMMChanged ();
391
356
handleUseDownloadPathChanged ();
392
- handleRatioTypeChanged ();
393
357
394
358
connect (m_ui->checkAutoTMM , &QCheckBox::clicked, this , &TorrentOptionsDialog::handleTMMChanged);
395
359
connect (m_ui->checkUseDownloadPath , &QCheckBox::clicked, this , &TorrentOptionsDialog::handleUseDownloadPathChanged);
@@ -403,12 +367,6 @@ TorrentOptionsDialog::TorrentOptionsDialog(QWidget *parent, const QVector<BitTor
403
367
connect (m_ui->spinDownloadLimit , qOverload<int >(&QSpinBox::valueChanged)
404
368
, this , [this ](const int value) { updateSliderValue (m_ui->sliderDownloadLimit , value); });
405
369
406
- connect (m_ui->checkMaxRatio , &QCheckBox::toggled, m_ui->spinRatioLimit , &QWidget::setEnabled);
407
- connect (m_ui->checkMaxTime , &QCheckBox::toggled, m_ui->spinTimeLimit , &QWidget::setEnabled);
408
- connect (m_ui->checkMaxInactiveTime , &QCheckBox::toggled, m_ui->spinInactiveTimeLimit , &QSpinBox::setEnabled);
409
-
410
- connect (m_ui->buttonGroup , &QButtonGroup::idClicked, this , &TorrentOptionsDialog::handleRatioTypeChanged);
411
-
412
370
if (const QSize dialogSize = m_storeDialogSize; dialogSize.isValid ())
413
371
resize (dialogSize);
414
372
}
@@ -421,13 +379,6 @@ TorrentOptionsDialog::~TorrentOptionsDialog()
421
379
422
380
void TorrentOptionsDialog::accept ()
423
381
{
424
- if (m_ui->radioTorrentLimit ->isChecked () && !m_ui->checkMaxRatio ->isChecked ()
425
- && !m_ui->checkMaxTime ->isChecked () && !m_ui->checkMaxInactiveTime ->isChecked ())
426
- {
427
- QMessageBox::critical (this , tr (" No share limit method selected" ), tr (" Please select a limit method first" ));
428
- return ;
429
- }
430
-
431
382
auto *session = BitTorrent::Session::instance ();
432
383
for (const BitTorrent::TorrentID &id : asConst (m_torrentIDs))
433
384
{
@@ -471,17 +422,23 @@ void TorrentOptionsDialog::accept()
471
422
if (m_initialValues.downSpeedLimit != m_ui->spinDownloadLimit ->value ())
472
423
torrent->setDownloadLimit (m_ui->spinDownloadLimit ->value () * 1024 );
473
424
474
- const qreal ratioLimit = getRatio ();
475
- if (m_initialValues.ratio != ratioLimit)
476
- torrent->setRatioLimit (ratioLimit);
425
+ if (const std::optional<qreal> ratioLimit = m_ui->torrentShareLimitsWidget ->ratioLimit ();
426
+ m_initialValues.ratio != ratioLimit)
427
+ {
428
+ torrent->setRatioLimit (ratioLimit.value ());
429
+ }
477
430
478
- const int seedingTimeLimit = getSeedingTime ();
479
- if (m_initialValues.seedingTime != seedingTimeLimit)
480
- torrent->setSeedingTimeLimit (seedingTimeLimit);
431
+ if (const std::optional<int > seedingTimeLimit = m_ui->torrentShareLimitsWidget ->seedingTimeLimit ();
432
+ m_initialValues.seedingTime != seedingTimeLimit)
433
+ {
434
+ torrent->setSeedingTimeLimit (seedingTimeLimit.value ());
435
+ }
481
436
482
- const int inactiveSeedingTimeLimit = getInactiveSeedingTime ();
483
- if (m_initialValues.inactiveSeedingTime != inactiveSeedingTimeLimit)
484
- torrent->setInactiveSeedingTimeLimit (inactiveSeedingTimeLimit);
437
+ if (const std::optional<int > inactiveSeedingTimeLimit = m_ui->torrentShareLimitsWidget ->inactiveSeedingTimeLimit ();
438
+ m_initialValues.inactiveSeedingTime != inactiveSeedingTimeLimit)
439
+ {
440
+ torrent->setInactiveSeedingTimeLimit (inactiveSeedingTimeLimit.value ());
441
+ }
485
442
486
443
if (!torrent->isPrivate ())
487
444
{
@@ -502,48 +459,6 @@ void TorrentOptionsDialog::accept()
502
459
QDialog::accept ();
503
460
}
504
461
505
- qreal TorrentOptionsDialog::getRatio () const
506
- {
507
- if (m_ui->buttonGroup ->checkedId () == -1 ) // No radio button is selected
508
- return MIXED_SHARE_LIMITS;
509
-
510
- if (m_ui->radioUseGlobalShareLimits ->isChecked ())
511
- return BitTorrent::Torrent::USE_GLOBAL_RATIO;
512
-
513
- if (m_ui->radioNoLimit ->isChecked () || !m_ui->checkMaxRatio ->isChecked ())
514
- return BitTorrent::Torrent::NO_RATIO_LIMIT;
515
-
516
- return m_ui->spinRatioLimit ->value ();
517
- }
518
-
519
- int TorrentOptionsDialog::getSeedingTime () const
520
- {
521
- if (m_ui->buttonGroup ->checkedId () == -1 ) // No radio button is selected
522
- return MIXED_SHARE_LIMITS;
523
-
524
- if (m_ui->radioUseGlobalShareLimits ->isChecked ())
525
- return BitTorrent::Torrent::USE_GLOBAL_SEEDING_TIME;
526
-
527
- if (m_ui->radioNoLimit ->isChecked () || !m_ui->checkMaxTime ->isChecked ())
528
- return BitTorrent::Torrent::NO_SEEDING_TIME_LIMIT;
529
-
530
- return m_ui->spinTimeLimit ->value ();
531
- }
532
-
533
- int TorrentOptionsDialog::getInactiveSeedingTime () const
534
- {
535
- if (m_ui->buttonGroup ->checkedId () == -1 ) // No radio button is selected
536
- return MIXED_SHARE_LIMITS;
537
-
538
- if (m_ui->radioUseGlobalShareLimits ->isChecked ())
539
- return BitTorrent::Torrent::USE_GLOBAL_INACTIVE_SEEDING_TIME;
540
-
541
- if (m_ui->radioNoLimit ->isChecked () || !m_ui->checkMaxInactiveTime ->isChecked ())
542
- return BitTorrent::Torrent::NO_INACTIVE_SEEDING_TIME_LIMIT;
543
-
544
- return m_ui->spinInactiveTimeLimit ->value ();
545
- }
546
-
547
462
void TorrentOptionsDialog::handleCategoryChanged ([[maybe_unused]] const int index)
548
463
{
549
464
if (m_ui->checkAutoTMM ->checkState () == Qt::Checked)
@@ -619,31 +534,6 @@ void TorrentOptionsDialog::handleUseDownloadPathChanged()
619
534
m_ui->downloadPath ->setSelectedPath (BitTorrent::Session::instance ()->downloadPath ());
620
535
}
621
536
622
- void TorrentOptionsDialog::handleRatioTypeChanged ()
623
- {
624
- if ((m_initialValues.ratio == MIXED_SHARE_LIMITS) || (m_initialValues.seedingTime == MIXED_SHARE_LIMITS)
625
- || (m_initialValues.inactiveSeedingTime == MIXED_SHARE_LIMITS))
626
- {
627
- QAbstractButton *currentRadio = m_ui->buttonGroup ->checkedButton ();
628
- if (currentRadio && (currentRadio == m_previousRadio))
629
- {
630
- // Hack to deselect the currently selected radio button programmatically because Qt doesn't allow it in exclusive mode
631
- m_ui->buttonGroup ->setExclusive (false );
632
- currentRadio->setChecked (false );
633
- m_ui->buttonGroup ->setExclusive (true );
634
- }
635
- m_previousRadio = m_ui->buttonGroup ->checkedButton ();
636
- }
637
-
638
- m_ui->checkMaxRatio ->setEnabled (m_ui->radioTorrentLimit ->isChecked ());
639
- m_ui->checkMaxTime ->setEnabled (m_ui->radioTorrentLimit ->isChecked ());
640
- m_ui->checkMaxInactiveTime ->setEnabled (m_ui->radioTorrentLimit ->isChecked ());
641
-
642
- m_ui->spinRatioLimit ->setEnabled (m_ui->radioTorrentLimit ->isChecked () && m_ui->checkMaxRatio ->isChecked ());
643
- m_ui->spinTimeLimit ->setEnabled (m_ui->radioTorrentLimit ->isChecked () && m_ui->checkMaxTime ->isChecked ());
644
- m_ui->spinInactiveTimeLimit ->setEnabled (m_ui->radioTorrentLimit ->isChecked () && m_ui->checkMaxInactiveTime ->isChecked ());
645
- }
646
-
647
537
void TorrentOptionsDialog::handleUpSpeedLimitChanged ()
648
538
{
649
539
m_ui->spinUploadLimit ->setMinimum (0 );
0 commit comments