comparison 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
comparison
equal deleted inserted replaced
117:2c1b6782e1d0 118:39521c47c7a3
15 #include <QDebug> 15 #include <QDebug>
16 #include <iostream> 16 #include <iostream>
17 #include <sstream> 17 #include <sstream>
18 #include <algorithm> 18 #include <algorithm>
19 19
20 /* This file is very, very similar to the anime list page.
21
22 It differs from Taiga in that it uses tabs instead of
23 those "groups", but those are custom painted and a pain in the ass to
24 maintain over multiple platforms. */
25
20 TorrentsPageListSortFilter::TorrentsPageListSortFilter(QObject* parent) : QSortFilterProxyModel(parent) { 26 TorrentsPageListSortFilter::TorrentsPageListSortFilter(QObject* parent) : QSortFilterProxyModel(parent) {
21 } 27 }
22 28
23 bool TorrentsPageListSortFilter::lessThan(const QModelIndex& l, const QModelIndex& r) const { 29 bool TorrentsPageListSortFilter::lessThan(const QModelIndex& l, const QModelIndex& r) const {
24 QVariant left = sourceModel()->data(l, sortRole()); 30 QVariant left = sourceModel()->data(l, sortRole());
72 torrent.SetGroup(elements["group"]); 78 torrent.SetGroup(elements["group"]);
73 torrent.SetResolution(elements["resolution"]); 79 torrent.SetResolution(elements["resolution"]);
74 } 80 }
75 torrent.SetDescription(Strings::TextifySynopsis(item.child_value("description"))); 81 torrent.SetDescription(Strings::TextifySynopsis(item.child_value("description")));
76 { 82 {
83 /* Parse description... */
84 enum class Keys { SIZE, AUTHORIZED, SUBMITTER, COMMENT };
85
86 const std::unordered_map<std::string, Keys> KeyMap = {
87 {"Size", Keys::SIZE},
88 {"Authorized", Keys::AUTHORIZED},
89 {"Submitter", Keys::SUBMITTER},
90 {"Comment", Keys::COMMENT}
91 };
92
93 const std::string description = Strings::TextifySynopsis(item.child_value("description"));
94
77 /* Parse size from description */ 95 /* Parse size from description */
78 std::istringstream descstream(torrent.GetDescription()); 96 std::istringstream descstream(description);
79 97
80 for (std::string line; std::getline(descstream, line);) { 98 for (std::string line; std::getline(descstream, line);) {
81 const std::string match = "Size: "; 99 const size_t pos = line.find_first_of(':', 0);
82 size_t pos = line.find(match); 100 if (pos == std::string::npos)
83 101 continue;
84 if (!pos) { 102
85 const std::string size = line.substr(pos + match.length()); 103 const std::string key = line.substr(0, pos);
86 torrent.SetSize(Strings::HumanReadableSizeToBytes(size)); 104 const std::string value = line.substr(line.find_first_not_of(": ", pos));
105
106 switch (KeyMap.at(key)) {
107 case Keys::COMMENT:
108 torrent.SetDescription(value);
109 break;
110 case Keys::SIZE:
111 torrent.SetSize(Strings::HumanReadableSizeToBytes(value));
112 break;
113 default:
114 break;
87 } 115 }
88 } 116 }
89 } 117 }
90 torrent.SetLink(item.child_value("link")); 118 torrent.SetLink(item.child_value("link"));
91 torrent.SetGuid(item.child_value("guid")); 119 torrent.SetGuid(item.child_value("guid"));
200 "conversion ambiguous" error on Linux */ 228 "conversion ambiguous" error on Linux */
201 case TL_SIZE: return QVariant::fromValue(item.GetSize()); 229 case TL_SIZE: return QVariant::fromValue(item.GetSize());
202 default: return data(index, Qt::DisplayRole); 230 default: return data(index, Qt::DisplayRole);
203 } 231 }
204 break; 232 break;
205 case Qt::CheckStateRole:
206 switch (index.column()) {
207 case 0: return item.GetChecked() ? Qt::Checked : Qt::Unchecked;
208 default: return {};
209 }
210 case Qt::SizeHintRole: { 233 case Qt::SizeHintRole: {
211 switch (index.column()) { 234 switch (index.column()) {
212 default: { 235 default: {
213 /* max horizontal size of 100, height size = size of current font */ 236 /* max horizontal size of 100, height size = size of current font */
214 const QString d = data(index, Qt::DisplayRole).toString(); 237 const QString d = data(index, Qt::DisplayRole).toString();
241 264
242 Qt::ItemFlags TorrentsPageListModel::flags(const QModelIndex& index) const { 265 Qt::ItemFlags TorrentsPageListModel::flags(const QModelIndex& index) const {
243 if (!index.isValid()) 266 if (!index.isValid())
244 return Qt::NoItemFlags; 267 return Qt::NoItemFlags;
245 268
246 const TorrentModelItem& item = list.at(index.row()); 269 return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
247
248 if (item.GetChecked() || index.column() == 0)
249 return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsUserCheckable;
250 else
251 return Qt::ItemIsSelectable | Qt::ItemIsUserCheckable;
252 } 270 }
253 271
254 TorrentsPage::TorrentsPage(QWidget* parent) : QFrame(parent) { 272 TorrentsPage::TorrentsPage(QWidget* parent) : QFrame(parent) {
255 setFrameShape(QFrame::Box); 273 setFrameShape(QFrame::Box);
256 setFrameShadow(QFrame::Sunken); 274 setFrameShadow(QFrame::Sunken);