Mercurial > minori
diff src/gui/pages/torrents.cc @ 118:39521c47c7a3
*: another huge megacommit, SORRY
The torrents page works a lot better now
Added the edit option to the anime list right click menu
Vectorized currently playing files
Available player and extensions are now loaded at runtime
from files in (dotpath)/players.json and (dotpath)/extensions.json
These paths are not permanent and will likely be moved to
(dotpath)/recognition
...
...
...
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Tue, 07 Nov 2023 23:40:54 -0500 |
parents | 2c1b6782e1d0 |
children | d43d68408d3c |
line wrap: on
line diff
--- a/src/gui/pages/torrents.cc Tue Nov 07 16:06:17 2023 -0500 +++ b/src/gui/pages/torrents.cc Tue Nov 07 23:40:54 2023 -0500 @@ -17,6 +17,12 @@ #include <sstream> #include <algorithm> +/* This file is very, very similar to the anime list page. + + It differs from Taiga in that it uses tabs instead of + those "groups", but those are custom painted and a pain in the ass to + maintain over multiple platforms. */ + TorrentsPageListSortFilter::TorrentsPageListSortFilter(QObject* parent) : QSortFilterProxyModel(parent) { } @@ -74,16 +80,38 @@ } torrent.SetDescription(Strings::TextifySynopsis(item.child_value("description"))); { + /* Parse description... */ + enum class Keys { SIZE, AUTHORIZED, SUBMITTER, COMMENT }; + + const std::unordered_map<std::string, Keys> KeyMap = { + {"Size", Keys::SIZE}, + {"Authorized", Keys::AUTHORIZED}, + {"Submitter", Keys::SUBMITTER}, + {"Comment", Keys::COMMENT} + }; + + const std::string description = Strings::TextifySynopsis(item.child_value("description")); + /* Parse size from description */ - std::istringstream descstream(torrent.GetDescription()); + std::istringstream descstream(description); for (std::string line; std::getline(descstream, line);) { - const std::string match = "Size: "; - size_t pos = line.find(match); + const size_t pos = line.find_first_of(':', 0); + if (pos == std::string::npos) + continue; + + const std::string key = line.substr(0, pos); + const std::string value = line.substr(line.find_first_not_of(": ", pos)); - if (!pos) { - const std::string size = line.substr(pos + match.length()); - torrent.SetSize(Strings::HumanReadableSizeToBytes(size)); + switch (KeyMap.at(key)) { + case Keys::COMMENT: + torrent.SetDescription(value); + break; + case Keys::SIZE: + torrent.SetSize(Strings::HumanReadableSizeToBytes(value)); + break; + default: + break; } } } @@ -202,11 +230,6 @@ default: return data(index, Qt::DisplayRole); } break; - case Qt::CheckStateRole: - switch (index.column()) { - case 0: return item.GetChecked() ? Qt::Checked : Qt::Unchecked; - default: return {}; - } case Qt::SizeHintRole: { switch (index.column()) { default: { @@ -243,12 +266,7 @@ if (!index.isValid()) return Qt::NoItemFlags; - const TorrentModelItem& item = list.at(index.row()); - - if (item.GetChecked() || index.column() == 0) - return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsUserCheckable; - else - return Qt::ItemIsSelectable | Qt::ItemIsUserCheckable; + return Qt::ItemIsEnabled | Qt::ItemIsSelectable; } TorrentsPage::TorrentsPage(QWidget* parent) : QFrame(parent) {