1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-25 09:13:06 +00:00

keep labels in order added, rather than alphabetically (#3271)

This commit is contained in:
Viacheslav Chimishuk 2022-06-17 01:08:42 +03:00 committed by GitHub
parent 06e5767234
commit 0397176c10
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 8 deletions

View file

@ -119,7 +119,7 @@ static auto loadLabels(tr_variant* dict, tr_torrent* tor)
}
}
tor->setLabels(std::data(labels), std::size(labels));
tor->setLabels(labels);
return tr_resume::Labels;
}

View file

@ -979,7 +979,7 @@ static char const* setLabels(tr_torrent* tor, tr_variant* list)
return errmsg;
}
tor->setLabels(std::data(labels), std::size(labels));
tor->setLabels(labels);
return nullptr;
}

View file

@ -11,7 +11,6 @@
#include <csignal> /* signal() */
#include <ctime>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <string_view>
@ -714,7 +713,7 @@ static void torrentInit(tr_torrent* tor, tr_ctor const* ctor)
tor->finishedSeedingByIdle = false;
auto const& labels = tr_ctorGetLabels(ctor);
tor->setLabels(std::data(labels), std::size(labels));
tor->setLabels(labels);
tor->uniqueId = session->torrents().add(tor);
@ -1909,11 +1908,18 @@ void tr_torrentSetFileDLs(tr_torrent* tor, tr_file_index_t const* files, tr_file
****
***/
void tr_torrent::setLabels(tr_quark const* new_labels, size_t n_labels)
void tr_torrent::setLabels(std::vector<tr_quark> const& new_labels)
{
auto const lock = unique_lock();
auto const sorted_unique = std::set<tr_quark>{ new_labels, new_labels + n_labels };
this->labels = { std::begin(sorted_unique), std::end(sorted_unique) };
this->labels.clear();
for (auto label : new_labels)
{
if (std::find(std::begin(this->labels), std::end(this->labels), label) == std::end(this->labels))
{
this->labels.push_back(label);
}
}
this->labels.shrink_to_fit();
this->setDirty();
}

View file

@ -581,7 +581,7 @@ public:
void setDateActive(time_t t);
void setLabels(tr_quark const* labels, size_t n_labels);
void setLabels(std::vector<tr_quark> const& new_labels);
/** Return the mime-type (e.g. "audio/x-flac") that matches more of the
torrent's content than any other mime-type. */