annotate src/gui/pages/torrents.cc @ 236:4d461ef7d424

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