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