Mercurial > minori
annotate src/gui/pages/torrents.cc @ 265:ff0b2052b234
*: add missing utf8proc files
I'm an idiot LOL
| author | Paper <paper@paper.us.eu.org> |
|---|---|
| date | Thu, 11 Apr 2024 10:22:05 -0400 |
| parents | 9a04802848c0 |
| children | f31305b9f60a |
| rev | line source |
|---|---|
|
54
466ac9870df9
add stub pages (to be implemented)
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
1 #include "gui/pages/torrents.h" |
| 258 | 2 #include "core/filesystem.h" |
| 114 | 3 #include "core/http.h" |
| 4 #include "core/session.h" | |
| 258 | 5 #include "core/strings.h" |
| 114 | 6 #include "gui/widgets/text.h" |
| 7 #include "track/media.h" | |
|
178
bc8d2ccff09c
win32/dark: use existing STL classes for dwmapi
Paper <mrpapersonic@gmail.com>
parents:
154
diff
changeset
|
8 |
| 114 | 9 #include <QByteArray> |
| 10 #include <QDataStream> | |
| 258 | 11 #include <QDebug> |
| 12 #include <QHeaderView> | |
|
230
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
221
diff
changeset
|
13 #include <QThread> |
| 258 | 14 #include <QToolBar> |
| 15 #include <QTreeView> | |
| 16 #include <QVBoxLayout> | |
|
178
bc8d2ccff09c
win32/dark: use existing STL classes for dwmapi
Paper <mrpapersonic@gmail.com>
parents:
154
diff
changeset
|
17 |
| 258 | 18 #include <algorithm> |
| 19 #include <fstream> | |
| 114 | 20 #include <iostream> |
| 21 #include <sstream> | |
| 22 | |
| 258 | 23 #include "anitomy/anitomy.h" |
|
178
bc8d2ccff09c
win32/dark: use existing STL classes for dwmapi
Paper <mrpapersonic@gmail.com>
parents:
154
diff
changeset
|
24 #include "pugixml.hpp" |
| 154 | 25 |
|
118
39521c47c7a3
*: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents:
117
diff
changeset
|
26 /* This file is very, very similar to the anime list page. |
| 250 | 27 * |
| 28 * It differs from Taiga in that it uses tabs instead of | |
| 29 * those "groups", but those are custom painted and a pain in the ass to | |
| 30 * maintain over multiple platforms. | |
| 258 | 31 */ |
|
118
39521c47c7a3
*: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents:
117
diff
changeset
|
32 |
| 114 | 33 TorrentsPageListSortFilter::TorrentsPageListSortFilter(QObject* parent) : QSortFilterProxyModel(parent) { |
| 34 } | |
| 35 | |
| 36 bool TorrentsPageListSortFilter::lessThan(const QModelIndex& l, const QModelIndex& r) const { | |
| 37 QVariant left = sourceModel()->data(l, sortRole()); | |
| 38 QVariant right = sourceModel()->data(r, sortRole()); | |
| 39 | |
| 40 switch (left.userType()) { | |
| 41 case QMetaType::Int: | |
| 42 case QMetaType::UInt: | |
| 43 case QMetaType::LongLong: | |
| 44 case QMetaType::ULongLong: return left.toInt() < right.toInt(); | |
| 45 case QMetaType::QDate: return left.toDate() < right.toDate(); | |
| 46 case QMetaType::QString: | |
| 47 default: return QString::compare(left.toString(), right.toString(), Qt::CaseInsensitive) < 0; | |
| 48 } | |
| 49 } | |
| 50 | |
| 51 /* -------------------------------------------- */ | |
| 52 | |
| 53 TorrentsPageListModel::TorrentsPageListModel(QObject* parent) : QAbstractListModel(parent) { | |
| 54 } | |
| 55 | |
|
230
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
221
diff
changeset
|
56 void TorrentsPageListModel::DownloadTorrents(QItemSelection selection) { |
|
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
221
diff
changeset
|
57 const auto indexes = selection.indexes(); |
|
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
221
diff
changeset
|
58 |
|
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
221
diff
changeset
|
59 for (const auto& index : indexes) { |
|
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
221
diff
changeset
|
60 /* a torrent file IS literally text... */ |
|
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
221
diff
changeset
|
61 const std::string link = list.at(index.row()).GetLink(); |
|
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
221
diff
changeset
|
62 const std::string filename = list.at(index.row()).GetFilename() + ".torrent"; |
|
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
221
diff
changeset
|
63 |
|
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
221
diff
changeset
|
64 const std::filesystem::path torrents_dir = Filesystem::GetTorrentsPath(); |
|
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
221
diff
changeset
|
65 std::filesystem::create_directories(torrents_dir); |
|
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
221
diff
changeset
|
66 |
|
236
4d461ef7d424
HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents:
230
diff
changeset
|
67 HTTP::GetThread* thread = new HTTP::GetThread(link, {}, this); |
|
4d461ef7d424
HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents:
230
diff
changeset
|
68 |
|
4d461ef7d424
HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents:
230
diff
changeset
|
69 connect(thread, &HTTP::GetThread::ReceivedData, this, [this, torrents_dir, filename](const QByteArray& data) { |
|
4d461ef7d424
HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents:
230
diff
changeset
|
70 std::ofstream file(torrents_dir / filename, std::ofstream::out | std::ofstream::trunc); |
|
4d461ef7d424
HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents:
230
diff
changeset
|
71 if (!file) |
|
4d461ef7d424
HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents:
230
diff
changeset
|
72 return; // wat |
|
230
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
221
diff
changeset
|
73 |
|
236
4d461ef7d424
HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents:
230
diff
changeset
|
74 file.write(data.data(), data.size()); |
|
4d461ef7d424
HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents:
230
diff
changeset
|
75 file.close(); |
|
4d461ef7d424
HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents:
230
diff
changeset
|
76 }); |
|
4d461ef7d424
HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents:
230
diff
changeset
|
77 connect(thread, &HTTP::GetThread::finished, thread, &HTTP::GetThread::deleteLater); |
|
230
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
221
diff
changeset
|
78 |
|
236
4d461ef7d424
HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents:
230
diff
changeset
|
79 thread->start(); |
|
230
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
221
diff
changeset
|
80 } |
|
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
221
diff
changeset
|
81 } |
|
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
221
diff
changeset
|
82 |
| 114 | 83 QByteArray TorrentsPageListModel::DownloadTorrentList() { |
|
116
254b1d2b7096
settings: add torrents page, make rss feed configurable
Paper <mrpapersonic@gmail.com>
parents:
114
diff
changeset
|
84 return HTTP::Get(session.config.torrents.feed_link); |
| 114 | 85 } |
| 86 | |
|
183
01d259b9c89f
pages/torrents.cc: parse feed descriptions separately
Paper <mrpapersonic@gmail.com>
parents:
178
diff
changeset
|
87 void TorrentsPageListModel::ParseFeedDescription(const std::string& description, Torrent& torrent) { |
|
01d259b9c89f
pages/torrents.cc: parse feed descriptions separately
Paper <mrpapersonic@gmail.com>
parents:
178
diff
changeset
|
88 /* Parse description... */ |
| 258 | 89 enum class Keys { |
| 90 SIZE, | |
| 91 AUTHORIZED, | |
| 92 SUBMITTER, | |
| 93 COMMENT | |
| 94 }; | |
|
183
01d259b9c89f
pages/torrents.cc: parse feed descriptions separately
Paper <mrpapersonic@gmail.com>
parents:
178
diff
changeset
|
95 |
|
01d259b9c89f
pages/torrents.cc: parse feed descriptions separately
Paper <mrpapersonic@gmail.com>
parents:
178
diff
changeset
|
96 const std::unordered_map<std::string, Keys> KeyMap = { |
| 258 | 97 {"Size", Keys::SIZE }, |
| 98 {"Authorized", Keys::AUTHORIZED}, | |
| 99 {"Submitter", Keys::SUBMITTER }, | |
| 100 {"Comment", Keys::COMMENT } | |
| 101 }; | |
|
183
01d259b9c89f
pages/torrents.cc: parse feed descriptions separately
Paper <mrpapersonic@gmail.com>
parents:
178
diff
changeset
|
102 |
|
01d259b9c89f
pages/torrents.cc: parse feed descriptions separately
Paper <mrpapersonic@gmail.com>
parents:
178
diff
changeset
|
103 /* Parse size from description */ |
|
01d259b9c89f
pages/torrents.cc: parse feed descriptions separately
Paper <mrpapersonic@gmail.com>
parents:
178
diff
changeset
|
104 std::istringstream descstream(description); |
|
01d259b9c89f
pages/torrents.cc: parse feed descriptions separately
Paper <mrpapersonic@gmail.com>
parents:
178
diff
changeset
|
105 |
|
01d259b9c89f
pages/torrents.cc: parse feed descriptions separately
Paper <mrpapersonic@gmail.com>
parents:
178
diff
changeset
|
106 for (std::string line; std::getline(descstream, line);) { |
|
01d259b9c89f
pages/torrents.cc: parse feed descriptions separately
Paper <mrpapersonic@gmail.com>
parents:
178
diff
changeset
|
107 const size_t pos = line.find_first_of(':', 0); |
|
01d259b9c89f
pages/torrents.cc: parse feed descriptions separately
Paper <mrpapersonic@gmail.com>
parents:
178
diff
changeset
|
108 if (pos == std::string::npos) |
|
01d259b9c89f
pages/torrents.cc: parse feed descriptions separately
Paper <mrpapersonic@gmail.com>
parents:
178
diff
changeset
|
109 continue; |
|
01d259b9c89f
pages/torrents.cc: parse feed descriptions separately
Paper <mrpapersonic@gmail.com>
parents:
178
diff
changeset
|
110 |
|
01d259b9c89f
pages/torrents.cc: parse feed descriptions separately
Paper <mrpapersonic@gmail.com>
parents:
178
diff
changeset
|
111 const std::string key = line.substr(0, pos); |
|
01d259b9c89f
pages/torrents.cc: parse feed descriptions separately
Paper <mrpapersonic@gmail.com>
parents:
178
diff
changeset
|
112 const std::string value = line.substr(line.find_first_not_of(": ", pos)); |
|
01d259b9c89f
pages/torrents.cc: parse feed descriptions separately
Paper <mrpapersonic@gmail.com>
parents:
178
diff
changeset
|
113 |
|
01d259b9c89f
pages/torrents.cc: parse feed descriptions separately
Paper <mrpapersonic@gmail.com>
parents:
178
diff
changeset
|
114 switch (KeyMap.at(key)) { |
| 258 | 115 case Keys::COMMENT: torrent.SetDescription(value); break; |
| 116 case Keys::SIZE: torrent.SetSize(Strings::HumanReadableSizeToBytes(value)); break; | |
|
221
53211cb1e7f5
library: add initial library stuff
Paper <paper@paper.us.eu.org>
parents:
183
diff
changeset
|
117 case Keys::AUTHORIZED: |
|
53211cb1e7f5
library: add initial library stuff
Paper <paper@paper.us.eu.org>
parents:
183
diff
changeset
|
118 if (torrent.GetGroup().empty() && value != "N/A") |
|
53211cb1e7f5
library: add initial library stuff
Paper <paper@paper.us.eu.org>
parents:
183
diff
changeset
|
119 torrent.SetGroup(value); |
|
53211cb1e7f5
library: add initial library stuff
Paper <paper@paper.us.eu.org>
parents:
183
diff
changeset
|
120 break; |
| 258 | 121 default: break; |
|
183
01d259b9c89f
pages/torrents.cc: parse feed descriptions separately
Paper <mrpapersonic@gmail.com>
parents:
178
diff
changeset
|
122 } |
|
01d259b9c89f
pages/torrents.cc: parse feed descriptions separately
Paper <mrpapersonic@gmail.com>
parents:
178
diff
changeset
|
123 } |
|
01d259b9c89f
pages/torrents.cc: parse feed descriptions separately
Paper <mrpapersonic@gmail.com>
parents:
178
diff
changeset
|
124 } |
|
01d259b9c89f
pages/torrents.cc: parse feed descriptions separately
Paper <mrpapersonic@gmail.com>
parents:
178
diff
changeset
|
125 |
| 114 | 126 void TorrentsPageListModel::ParseTorrentList(const QByteArray& ba) { |
| 127 std::istringstream stdstream(Strings::ToUtf8String(ba)); | |
| 128 | |
| 129 pugi::xml_document doc; | |
| 130 if (!doc.load(stdstream)) | |
| 131 return; // peace out | |
| 132 | |
| 133 /* my extra special dumb hack. */ | |
| 134 if (!rowCount(index(0))) { | |
| 135 beginInsertRows(QModelIndex(), 0, 0); | |
| 136 endInsertRows(); | |
| 137 } | |
| 138 | |
| 139 beginResetModel(); | |
| 140 | |
| 141 list.clear(); | |
| 142 /* this is just an rss parser; it should be in a separate class... */ | |
| 143 for (pugi::xml_node item : doc.child("rss").child("channel").children("item")) { | |
| 144 TorrentModelItem torrent; | |
| 145 torrent.SetFilename(item.child_value("title")); /* "title" == filename */ | |
| 146 { | |
| 154 | 147 anitomy::Anitomy anitomy; |
| 148 anitomy.Parse(Strings::ToWstring(torrent.GetFilename())); | |
| 149 | |
| 150 const auto& elements = anitomy.elements(); | |
| 151 | |
| 152 /* todo: patch Anitomy so that it doesn't use wide strings */ | |
| 153 torrent.SetTitle(Strings::ToUtf8String(elements.get(anitomy::kElementAnimeTitle))); | |
| 264 | 154 std::string episode = Strings::ToUtf8String(elements.get(anitomy::kElementEpisodeNumber)); |
| 155 Strings::RemoveLeadingChars(episode, '0'); | |
| 156 torrent.SetEpisode(episode); | |
| 154 | 157 torrent.SetGroup(Strings::ToUtf8String(elements.get(anitomy::kElementReleaseGroup))); |
| 158 torrent.SetResolution(Strings::ToUtf8String(elements.get(anitomy::kElementVideoResolution))); | |
| 114 | 159 } |
| 160 | |
|
260
dd211ff68b36
pages/seasons: add initial functionality
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
161 std::string description = item.child_value("description"); |
|
dd211ff68b36
pages/seasons: add initial functionality
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
162 Strings::TextifySynopsis(description); |
|
dd211ff68b36
pages/seasons: add initial functionality
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
163 ParseFeedDescription(description, torrent); |
| 114 | 164 |
| 165 torrent.SetLink(item.child_value("link")); | |
| 166 torrent.SetGuid(item.child_value("guid")); | |
| 167 { | |
| 168 const QString date_str = Strings::ToQString(item.child_value("pubDate")); | |
| 169 torrent.SetDate(QDateTime::fromString(date_str, "ddd, dd MMM yyyy HH:mm:ss t")); | |
| 170 } | |
| 171 list.push_back(torrent); | |
| 172 } | |
| 173 | |
| 174 endResetModel(); | |
| 175 } | |
| 176 | |
| 177 void TorrentsPageListModel::RefreshTorrentList() { | |
| 178 ParseTorrentList(DownloadTorrentList()); | |
| 179 } | |
| 180 | |
| 181 int TorrentsPageListModel::rowCount(const QModelIndex& parent) const { | |
| 182 return list.size(); | |
| 183 (void)(parent); | |
| 184 } | |
| 185 | |
| 186 int TorrentsPageListModel::columnCount(const QModelIndex& parent) const { | |
| 187 return NB_COLUMNS; | |
| 188 (void)(parent); | |
| 189 } | |
| 190 | |
| 191 QVariant TorrentsPageListModel::headerData(const int section, const Qt::Orientation orientation, const int role) const { | |
| 192 switch (role) { | |
| 193 case Qt::DisplayRole: { | |
| 194 switch (section) { | |
| 195 case TL_TITLE: return tr("Anime title"); | |
| 196 case TL_EPISODE: return tr("Episode"); | |
| 197 case TL_GROUP: return tr("Group"); | |
| 198 case TL_SIZE: return tr("Size"); | |
|
236
4d461ef7d424
HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents:
230
diff
changeset
|
199 case TL_RESOLUTION: return tr("Resolution"); /* "Video" in Taiga */ |
|
4d461ef7d424
HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents:
230
diff
changeset
|
200 case TL_SEEDERS: return tr("S"); |
|
4d461ef7d424
HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents:
230
diff
changeset
|
201 case TL_LEECHERS: return tr("L"); |
|
4d461ef7d424
HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents:
230
diff
changeset
|
202 case TL_DOWNLOADS: return tr("D"); |
| 114 | 203 case TL_DESCRIPTION: return tr("Description"); |
| 204 case TL_FILENAME: return tr("Filename"); | |
| 205 case TL_RELEASEDATE: return tr("Release date"); | |
| 206 default: return {}; | |
| 207 } | |
| 208 break; | |
| 209 } | |
| 210 case Qt::TextAlignmentRole: { | |
| 211 switch (section) { | |
| 212 case TL_FILENAME: | |
| 213 case TL_GROUP: | |
| 214 case TL_DESCRIPTION: | |
| 215 case TL_RESOLUTION: | |
| 216 case TL_TITLE: return QVariant(Qt::AlignLeft | Qt::AlignVCenter); | |
| 217 case TL_SEEDERS: | |
| 218 case TL_LEECHERS: | |
|
236
4d461ef7d424
HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents:
230
diff
changeset
|
219 case TL_DOWNLOADS: |
| 114 | 220 case TL_SIZE: |
| 221 case TL_EPISODE: | |
| 222 case TL_RELEASEDATE: return QVariant(Qt::AlignRight | Qt::AlignVCenter); | |
| 223 default: return {}; | |
| 224 } | |
| 225 break; | |
| 226 } | |
| 227 } | |
| 228 return QAbstractListModel::headerData(section, orientation, role); | |
| 229 } | |
| 230 | |
| 231 bool TorrentsPageListModel::setData(const QModelIndex& index, const QVariant& value, int role) { | |
| 232 TorrentModelItem& item = list.at(index.row()); | |
|
54
466ac9870df9
add stub pages (to be implemented)
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
233 |
| 114 | 234 if (index.column() == 0) { |
| 235 switch (role) { | |
| 258 | 236 case Qt::EditRole: return false; |
| 114 | 237 case Qt::CheckStateRole: |
| 238 item.SetChecked(value.toBool()); | |
| 239 emit dataChanged(index, index); | |
| 240 return true; | |
| 241 } | |
| 242 } | |
| 243 | |
| 244 return QAbstractItemModel::setData(index, value, role); | |
| 245 } | |
| 246 | |
| 247 QVariant TorrentsPageListModel::data(const QModelIndex& index, int role) const { | |
| 248 if (!index.isValid()) | |
| 249 return QVariant(); | |
|
116
254b1d2b7096
settings: add torrents page, make rss feed configurable
Paper <mrpapersonic@gmail.com>
parents:
114
diff
changeset
|
250 |
|
254b1d2b7096
settings: add torrents page, make rss feed configurable
Paper <mrpapersonic@gmail.com>
parents:
114
diff
changeset
|
251 const TorrentModelItem& item = list.at(index.row()); |
|
254b1d2b7096
settings: add torrents page, make rss feed configurable
Paper <mrpapersonic@gmail.com>
parents:
114
diff
changeset
|
252 |
| 114 | 253 switch (role) { |
| 254 case Qt::DisplayRole: | |
| 255 switch (index.column()) { | |
|
116
254b1d2b7096
settings: add torrents page, make rss feed configurable
Paper <mrpapersonic@gmail.com>
parents:
114
diff
changeset
|
256 case TL_TITLE: return Strings::ToQString(item.GetTitle()); |
|
254b1d2b7096
settings: add torrents page, make rss feed configurable
Paper <mrpapersonic@gmail.com>
parents:
114
diff
changeset
|
257 case TL_EPISODE: return Strings::ToQString(item.GetEpisode()); |
|
254b1d2b7096
settings: add torrents page, make rss feed configurable
Paper <mrpapersonic@gmail.com>
parents:
114
diff
changeset
|
258 case TL_GROUP: return Strings::ToQString(item.GetGroup()); |
|
254b1d2b7096
settings: add torrents page, make rss feed configurable
Paper <mrpapersonic@gmail.com>
parents:
114
diff
changeset
|
259 case TL_SIZE: return session.config.locale.GetLocale().formattedDataSize(item.GetSize()); |
|
254b1d2b7096
settings: add torrents page, make rss feed configurable
Paper <mrpapersonic@gmail.com>
parents:
114
diff
changeset
|
260 case TL_RESOLUTION: return Strings::ToQString(item.GetResolution()); |
|
254b1d2b7096
settings: add torrents page, make rss feed configurable
Paper <mrpapersonic@gmail.com>
parents:
114
diff
changeset
|
261 case TL_SEEDERS: return item.GetSeeders(); |
|
254b1d2b7096
settings: add torrents page, make rss feed configurable
Paper <mrpapersonic@gmail.com>
parents:
114
diff
changeset
|
262 case TL_LEECHERS: return item.GetLeechers(); |
|
236
4d461ef7d424
HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents:
230
diff
changeset
|
263 case TL_DOWNLOADS: return item.GetDownloads(); |
|
116
254b1d2b7096
settings: add torrents page, make rss feed configurable
Paper <mrpapersonic@gmail.com>
parents:
114
diff
changeset
|
264 case TL_DESCRIPTION: return Strings::ToQString(item.GetDescription()); |
|
254b1d2b7096
settings: add torrents page, make rss feed configurable
Paper <mrpapersonic@gmail.com>
parents:
114
diff
changeset
|
265 case TL_FILENAME: return Strings::ToQString(item.GetFilename()); |
|
254b1d2b7096
settings: add torrents page, make rss feed configurable
Paper <mrpapersonic@gmail.com>
parents:
114
diff
changeset
|
266 case TL_RELEASEDATE: return item.GetDate(); |
|
230
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
221
diff
changeset
|
267 default: return {}; |
| 114 | 268 } |
| 269 break; | |
| 270 case Qt::UserRole: | |
| 271 switch (index.column()) { | |
|
116
254b1d2b7096
settings: add torrents page, make rss feed configurable
Paper <mrpapersonic@gmail.com>
parents:
114
diff
changeset
|
272 case TL_EPISODE: return Strings::ToInt(item.GetEpisode(), -1); |
|
117
2c1b6782e1d0
pages/torrents: work around conversion error on Linux
Paper <mrpapersonic@gmail.com>
parents:
116
diff
changeset
|
273 /* We have to use this to work around some stupid |
|
230
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
221
diff
changeset
|
274 * "conversion ambiguous" error on Linux |
| 258 | 275 */ |
|
117
2c1b6782e1d0
pages/torrents: work around conversion error on Linux
Paper <mrpapersonic@gmail.com>
parents:
116
diff
changeset
|
276 case TL_SIZE: return QVariant::fromValue(item.GetSize()); |
| 114 | 277 default: return data(index, Qt::DisplayRole); |
| 278 } | |
| 279 break; | |
| 280 case Qt::SizeHintRole: { | |
| 281 switch (index.column()) { | |
| 282 default: { | |
|
116
254b1d2b7096
settings: add torrents page, make rss feed configurable
Paper <mrpapersonic@gmail.com>
parents:
114
diff
changeset
|
283 /* max horizontal size of 100, height size = size of current font */ |
| 114 | 284 const QString d = data(index, Qt::DisplayRole).toString(); |
| 285 const QFontMetrics metric = QFontMetrics(QFont()); | |
| 286 | |
| 287 return QSize(std::max(metric.horizontalAdvance(d), 100), metric.height()); | |
| 288 } | |
| 289 } | |
| 290 break; | |
| 291 } | |
| 292 case Qt::TextAlignmentRole: | |
| 293 switch (index.column()) { | |
| 294 case TL_FILENAME: | |
| 295 case TL_GROUP: | |
| 296 case TL_DESCRIPTION: | |
| 297 case TL_RESOLUTION: | |
| 298 case TL_TITLE: return QVariant(Qt::AlignLeft | Qt::AlignVCenter); | |
| 299 case TL_SEEDERS: | |
| 300 case TL_LEECHERS: | |
|
236
4d461ef7d424
HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents:
230
diff
changeset
|
301 case TL_DOWNLOADS: |
| 114 | 302 case TL_SIZE: |
| 303 case TL_EPISODE: | |
| 304 case TL_RELEASEDATE: return QVariant(Qt::AlignRight | Qt::AlignVCenter); | |
| 305 default: return {}; | |
| 306 } | |
| 307 break; | |
| 308 } | |
| 309 return QVariant(); | |
| 310 } | |
| 311 | |
| 312 Qt::ItemFlags TorrentsPageListModel::flags(const QModelIndex& index) const { | |
| 313 if (!index.isValid()) | |
| 314 return Qt::NoItemFlags; | |
| 315 | |
|
118
39521c47c7a3
*: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents:
117
diff
changeset
|
316 return Qt::ItemIsEnabled | Qt::ItemIsSelectable; |
| 114 | 317 } |
| 318 | |
| 319 TorrentsPage::TorrentsPage(QWidget* parent) : QFrame(parent) { | |
| 320 setFrameShape(QFrame::Box); | |
| 321 setFrameShadow(QFrame::Sunken); | |
| 322 | |
| 323 QVBoxLayout* layout = new QVBoxLayout(this); | |
| 324 layout->setContentsMargins(0, 0, 0, 0); | |
| 325 layout->setSpacing(0); | |
| 326 | |
| 327 { | |
| 328 /* Toolbar */ | |
| 329 QToolBar* toolbar = new QToolBar(this); | |
| 330 toolbar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); | |
| 331 toolbar->setIconSize(QSize(16, 16)); | |
| 332 toolbar->setMovable(false); | |
| 333 | |
| 334 { | |
| 335 /* this needs to be stored somewhere to replicate Taiga's | |
| 336 "timer" feature */ | |
| 258 | 337 toolbar->addAction(QIcon(":/icons/16x16/arrow-circle-315.png"), tr("&Check new torrents"), |
| 338 [this] { Refresh(); }); | |
| 114 | 339 } |
| 340 | |
| 341 toolbar->addSeparator(); | |
| 342 | |
| 343 { | |
| 258 | 344 toolbar->addAction(QIcon(":/icons/16x16/navigation-270-button.png"), tr("Download &marked torrents"), |
| 345 [this] { DownloadSelection(); }); | |
| 114 | 346 } |
| 347 | |
| 258 | 348 { toolbar->addAction(QIcon(":/icons/16x16/cross-button.png"), tr("&Discard all")); } |
| 114 | 349 |
| 350 toolbar->addSeparator(); | |
| 351 | |
| 258 | 352 { toolbar->addAction(QIcon(":/icons/16x16/gear.png"), tr("&Settings")); } |
| 114 | 353 |
| 354 layout->addWidget(toolbar); | |
| 355 } | |
| 356 | |
| 357 { | |
| 358 QFrame* line = new QFrame(this); | |
| 359 line->setFrameShape(QFrame::HLine); | |
| 360 line->setFrameShadow(QFrame::Sunken); | |
| 361 line->setLineWidth(1); | |
| 362 layout->addWidget(line); | |
| 363 } | |
| 364 | |
| 365 { | |
|
230
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
221
diff
changeset
|
366 treeview = new QTreeView(this); |
| 114 | 367 treeview->setUniformRowHeights(true); |
| 368 treeview->setAllColumnsShowFocus(false); | |
| 369 treeview->setAlternatingRowColors(true); | |
| 370 treeview->setSortingEnabled(true); | |
| 371 treeview->setSelectionMode(QAbstractItemView::ExtendedSelection); | |
| 372 treeview->setItemsExpandable(false); | |
| 373 treeview->setRootIsDecorated(false); | |
| 374 treeview->setContextMenuPolicy(Qt::CustomContextMenu); | |
| 375 treeview->setFrameShape(QFrame::NoFrame); | |
| 376 | |
| 377 { | |
| 378 sort_model = new TorrentsPageListSortFilter(treeview); | |
| 379 model = new TorrentsPageListModel(treeview); | |
| 380 sort_model->setSourceModel(model); | |
| 381 sort_model->setSortRole(Qt::UserRole); | |
| 382 sort_model->setSortCaseSensitivity(Qt::CaseInsensitive); | |
| 383 treeview->setModel(sort_model); | |
| 384 } | |
| 385 | |
|
236
4d461ef7d424
HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents:
230
diff
changeset
|
386 // set column sizes |
| 258 | 387 treeview->setColumnWidth(TorrentsPageListModel::TL_TITLE, 240); |
| 388 treeview->setColumnWidth(TorrentsPageListModel::TL_EPISODE, 60); | |
| 389 treeview->setColumnWidth(TorrentsPageListModel::TL_GROUP, 100); | |
| 390 treeview->setColumnWidth(TorrentsPageListModel::TL_SIZE, 70); | |
| 391 treeview->setColumnWidth(TorrentsPageListModel::TL_RESOLUTION, 100); | |
| 392 treeview->setColumnWidth(TorrentsPageListModel::TL_SEEDERS, 20); | |
| 393 treeview->setColumnWidth(TorrentsPageListModel::TL_LEECHERS, 20); | |
| 394 treeview->setColumnWidth(TorrentsPageListModel::TL_DOWNLOADS, 20); | |
|
236
4d461ef7d424
HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents:
230
diff
changeset
|
395 treeview->setColumnWidth(TorrentsPageListModel::TL_DESCRIPTION, 200); |
| 258 | 396 treeview->setColumnWidth(TorrentsPageListModel::TL_FILENAME, 200); |
|
236
4d461ef7d424
HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents:
230
diff
changeset
|
397 treeview->setColumnWidth(TorrentsPageListModel::TL_RELEASEDATE, 190); |
|
4d461ef7d424
HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents:
230
diff
changeset
|
398 |
| 250 | 399 treeview->header()->setStretchLastSection(false); |
| 400 | |
| 114 | 401 layout->addWidget(treeview); |
| 402 } | |
| 403 } | |
| 404 | |
|
230
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
221
diff
changeset
|
405 void TorrentsPage::DownloadSelection() { |
|
236
4d461ef7d424
HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents:
230
diff
changeset
|
406 if (!model) |
|
230
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
221
diff
changeset
|
407 return; |
|
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
221
diff
changeset
|
408 |
|
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
221
diff
changeset
|
409 const QItemSelection selection = sort_model->mapSelectionToSource(treeview->selectionModel()->selection()); |
|
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
221
diff
changeset
|
410 |
|
236
4d461ef7d424
HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents:
230
diff
changeset
|
411 model->DownloadTorrents(selection); |
|
230
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
221
diff
changeset
|
412 } |
|
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
221
diff
changeset
|
413 |
| 114 | 414 void TorrentsPage::Refresh() { |
| 415 if (!model) | |
| 416 return; | |
|
230
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
221
diff
changeset
|
417 |
|
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
221
diff
changeset
|
418 HTTP::GetThread* thread = new HTTP::GetThread(session.config.torrents.feed_link); |
|
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
221
diff
changeset
|
419 |
|
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
221
diff
changeset
|
420 connect(thread, &HTTP::GetThread::ReceivedData, this, [&](const QByteArray& ba) { |
|
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
221
diff
changeset
|
421 /* This is to make sure we aren't in a different thread |
|
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
221
diff
changeset
|
422 * messing around with GUI stuff |
| 258 | 423 */ |
|
230
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
221
diff
changeset
|
424 treeview->setUpdatesEnabled(false); |
|
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
221
diff
changeset
|
425 model->ParseTorrentList(ba); |
|
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
221
diff
changeset
|
426 treeview->setUpdatesEnabled(true); |
|
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
221
diff
changeset
|
427 }); |
|
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
221
diff
changeset
|
428 connect(thread, &QThread::finished, thread, &QThread::deleteLater); |
|
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
221
diff
changeset
|
429 |
|
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
221
diff
changeset
|
430 thread->start(); |
|
54
466ac9870df9
add stub pages (to be implemented)
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
431 } |
