@@ -513,9 +513,9 @@ SessionImpl::SessionImpl(QObject *parent)
513513 , m_additionalTrackersURL(BITTORRENT_SESSION_KEY(u" AdditionalTrackersURL" _s))
514514 , m_globalMaxRatio(BITTORRENT_SESSION_KEY(u" GlobalMaxRatio" _s), -1 , [](qreal r) { return r < 0 ? -1 . : r; })
515515 , m_globalMaxSeedingMinutes(BITTORRENT_SESSION_KEY(u" GlobalMaxSeedingMinutes" _s)
516- , Torrent:: NO_SEEDING_TIME_LIMIT, lowerLimited(Torrent:: NO_SEEDING_TIME_LIMIT))
516+ , NO_SEEDING_TIME_LIMIT, lowerLimited(NO_SEEDING_TIME_LIMIT))
517517 , m_globalMaxInactiveSeedingMinutes(BITTORRENT_SESSION_KEY(u" GlobalMaxInactiveSeedingMinutes" _s)
518- , Torrent::NO_INACTIVE_SEEDING_TIME_LIMIT , lowerLimited(Torrent::NO_INACTIVE_SEEDING_TIME_LIMIT ))
518+ , NO_SEEDING_TIME_LIMIT , lowerLimited(NO_SEEDING_TIME_LIMIT ))
519519 , m_isAddTorrentToQueueTop(BITTORRENT_SESSION_KEY(u" AddTorrentToTopOfQueue" _s), false )
520520 , m_isAddTorrentStopped(BITTORRENT_SESSION_KEY(u" AddTorrentStopped" _s), false )
521521 , m_torrentStopCondition(BITTORRENT_SESSION_KEY(u" TorrentStopCondition" _s), Torrent::StopCondition::None)
@@ -972,6 +972,62 @@ Path SessionImpl::categoryDownloadPath(const QString &categoryName, const Catego
972972 return (basePath / path);
973973}
974974
975+ qreal SessionImpl::categoryRatioLimit (const QString &categoryName) const
976+ {
977+ if (categoryName.isEmpty ())
978+ return globalMaxRatio ();
979+
980+ if (const auto ratioLimit = categoryOptions (categoryName).ratioLimit ;
981+ ratioLimit != DEFAULT_RATIO_LIMIT)
982+ {
983+ return ratioLimit;
984+ }
985+
986+ return categoryRatioLimit (parentCategoryName (categoryName));
987+ }
988+
989+ int SessionImpl::categorySeedingTimeLimit (const QString &categoryName) const
990+ {
991+ if (categoryName.isEmpty ())
992+ return globalMaxSeedingMinutes ();
993+
994+ if (const auto seedingTimeLimit = categoryOptions (categoryName).seedingTimeLimit ;
995+ seedingTimeLimit != DEFAULT_SEEDING_TIME_LIMIT)
996+ {
997+ return seedingTimeLimit;
998+ }
999+
1000+ return categorySeedingTimeLimit (parentCategoryName (categoryName));
1001+ }
1002+
1003+ int SessionImpl::categoryInactiveSeedingTimeLimit (const QString &categoryName) const
1004+ {
1005+ if (categoryName.isEmpty ())
1006+ return globalMaxInactiveSeedingMinutes ();
1007+
1008+ if (const auto inactiveSeedingTimeLimit = categoryOptions (categoryName).inactiveSeedingTimeLimit ;
1009+ inactiveSeedingTimeLimit != DEFAULT_SEEDING_TIME_LIMIT)
1010+ {
1011+ return inactiveSeedingTimeLimit;
1012+ }
1013+
1014+ return categoryInactiveSeedingTimeLimit (parentCategoryName (categoryName));
1015+ }
1016+
1017+ ShareLimitAction SessionImpl::categoryShareLimitAction (const QString &categoryName) const
1018+ {
1019+ if (categoryName.isEmpty ())
1020+ return shareLimitAction ();
1021+
1022+ if (const auto shareLimitAction = categoryOptions (categoryName).shareLimitAction ;
1023+ shareLimitAction != ShareLimitAction::Default)
1024+ {
1025+ return shareLimitAction;
1026+ }
1027+
1028+ return categoryShareLimitAction (parentCategoryName (categoryName));
1029+ }
1030+
9751031DownloadPathOption SessionImpl::resolveCategoryDownloadPathOption (const QString &categoryName, const std::optional<DownloadPathOption> &option) const
9761032{
9771033 if (categoryName.isEmpty ())
@@ -1008,24 +1064,25 @@ bool SessionImpl::addCategory(const QString &name, const CategoryOptions &option
10081064 return true ;
10091065}
10101066
1011- bool SessionImpl::editCategory (const QString &name , const CategoryOptions &options)
1067+ bool SessionImpl::setCategoryOptions (const QString &categoryName , const CategoryOptions &options)
10121068{
1013- const auto it = m_categories.find (name );
1069+ const auto it = m_categories.find (categoryName );
10141070 if (it == m_categories.end ())
10151071 return false ;
10161072
10171073 CategoryOptions ¤tOptions = it.value ();
10181074 if (options == currentOptions)
10191075 return false ;
10201076
1021- if (isDisableAutoTMMWhenCategorySavePathChanged ())
1077+ if (isDisableAutoTMMWhenCategorySavePathChanged ()
1078+ && ((options.savePath != currentOptions.savePath ) || (options.downloadPath != currentOptions.downloadPath )))
10221079 {
10231080 // This should be done before changing the category options
10241081 // to prevent the torrent from being moved at the new save path.
10251082
10261083 for (TorrentImpl *const torrent : asConst (m_torrents))
10271084 {
1028- if (torrent->category () == name )
1085+ if (torrent->category () == categoryName )
10291086 torrent->setAutoTMMEnabled (false );
10301087 }
10311088 }
@@ -1035,11 +1092,11 @@ bool SessionImpl::editCategory(const QString &name, const CategoryOptions &optio
10351092
10361093 for (TorrentImpl *const torrent : asConst (m_torrents))
10371094 {
1038- if (torrent->category () == name )
1095+ if (torrent->category () == categoryName )
10391096 torrent->handleCategoryOptionsChanged ();
10401097 }
10411098
1042- emit categoryOptionsChanged (name );
1099+ emit categoryOptionsChanged (categoryName );
10431100 return true ;
10441101}
10451102
@@ -1235,7 +1292,7 @@ qreal SessionImpl::globalMaxRatio() const
12351292void SessionImpl::setGlobalMaxRatio (qreal ratio)
12361293{
12371294 if (ratio < 0 )
1238- ratio = Torrent:: NO_RATIO_LIMIT;
1295+ ratio = NO_RATIO_LIMIT;
12391296
12401297 if (ratio != globalMaxRatio ())
12411298 {
@@ -1251,7 +1308,7 @@ int SessionImpl::globalMaxSeedingMinutes() const
12511308
12521309void SessionImpl::setGlobalMaxSeedingMinutes (int minutes)
12531310{
1254- minutes = std::max (minutes, Torrent:: NO_SEEDING_TIME_LIMIT);
1311+ minutes = std::max (minutes, NO_SEEDING_TIME_LIMIT);
12551312
12561313 if (minutes != globalMaxSeedingMinutes ())
12571314 {
@@ -1267,7 +1324,7 @@ int SessionImpl::globalMaxInactiveSeedingMinutes() const
12671324
12681325void SessionImpl::setGlobalMaxInactiveSeedingMinutes (int minutes)
12691326{
1270- minutes = std::max (minutes, Torrent::NO_INACTIVE_SEEDING_TIME_LIMIT );
1327+ minutes = std::max (minutes, NO_SEEDING_TIME_LIMIT );
12711328
12721329 if (minutes != globalMaxInactiveSeedingMinutes ())
12731330 {
@@ -2310,14 +2367,9 @@ void SessionImpl::processTorrentShareLimits(TorrentImpl *torrent)
23102367 if (!torrent->isFinished () || torrent->isForced ())
23112368 return ;
23122369
2313- const auto effectiveLimit = []<typename T>(const T limit, const T useGlobalLimit, const T globalLimit) -> T
2314- {
2315- return (limit == useGlobalLimit) ? globalLimit : limit;
2316- };
2317-
2318- const qreal ratioLimit = effectiveLimit (torrent->ratioLimit (), Torrent::USE_GLOBAL_RATIO, globalMaxRatio ());
2319- const int seedingTimeLimit = effectiveLimit (torrent->seedingTimeLimit (), Torrent::USE_GLOBAL_SEEDING_TIME, globalMaxSeedingMinutes ());
2320- const int inactiveSeedingTimeLimit = effectiveLimit (torrent->inactiveSeedingTimeLimit (), Torrent::USE_GLOBAL_INACTIVE_SEEDING_TIME, globalMaxInactiveSeedingMinutes ());
2370+ const qreal ratioLimit = torrent->effectiveRatioLimit ();
2371+ const int seedingTimeLimit = torrent->effectiveSeedingTimeLimit ();
2372+ const int inactiveSeedingTimeLimit = torrent->effectiveInactiveSeedingTimeLimit ();
23212373
23222374 bool reached = false ;
23232375 QString description;
@@ -2344,7 +2396,7 @@ void SessionImpl::processTorrentShareLimits(TorrentImpl *torrent)
23442396 if (reached)
23452397 {
23462398 const QString torrentName = tr (" Torrent: \" %1\" ." ).arg (torrent->name ());
2347- const ShareLimitAction shareLimitAction = ( torrent->shareLimitAction () == ShareLimitAction::Default) ? m_shareLimitAction : torrent-> shareLimitAction ();
2399+ const ShareLimitAction shareLimitAction = torrent->effectiveShareLimitAction ();
23482400
23492401 if (shareLimitAction == ShareLimitAction::Remove)
23502402 {
@@ -5172,9 +5224,9 @@ bool SessionImpl::isKnownTorrent(const InfoHash &infoHash) const
51725224
51735225void SessionImpl::updateSeedingLimitTimer ()
51745226{
5175- if ((globalMaxRatio () == Torrent:: NO_RATIO_LIMIT) && !hasPerTorrentRatioLimit ()
5176- && (globalMaxSeedingMinutes () == Torrent:: NO_SEEDING_TIME_LIMIT) && !hasPerTorrentSeedingTimeLimit ()
5177- && (globalMaxInactiveSeedingMinutes () == Torrent::NO_INACTIVE_SEEDING_TIME_LIMIT ) && !hasPerTorrentInactiveSeedingTimeLimit ())
5227+ if ((globalMaxRatio () == NO_RATIO_LIMIT) && !hasPerTorrentRatioLimit ()
5228+ && (globalMaxSeedingMinutes () == NO_SEEDING_TIME_LIMIT) && !hasPerTorrentSeedingTimeLimit ()
5229+ && (globalMaxInactiveSeedingMinutes () == NO_SEEDING_TIME_LIMIT ) && !hasPerTorrentInactiveSeedingTimeLimit ())
51785230 {
51795231 if (m_seedingLimitTimer->isActive ())
51805232 m_seedingLimitTimer->stop ();
0 commit comments