annotate src/gui/pages/torrents.cc @ 174:f88eda79c60a

anime/db: add some more json functionality, still doesn't compile :/
author Paper <mrpapersonic@gmail.com>
date Wed, 29 Nov 2023 13:53:56 -0500
parents d43d68408d3c
children bc8d2ccff09c
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"
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
5 #include "gui/widgets/text.h"
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
6 #include "track/media.h"
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
7 #include "pugixml.hpp"
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
8 #include <QVBoxLayout>
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
9 #include <QToolBar>
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
10 #include <QTreeView>
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
11 #include <QMainWindow>
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
12 #include <QByteArray>
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
13 #include <QDataStream>
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
14 #include <QThreadPool>
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
15 #include <QDebug>
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
16 #include <iostream>
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
17 #include <sstream>
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
18 #include <algorithm>
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
19
154
d43d68408d3c dep/animia: fix XnuFdTools
Paper <mrpapersonic@gmail.com>
parents: 118
diff changeset
20 #include "anitomy/anitomy.h"
d43d68408d3c dep/animia: fix XnuFdTools
Paper <mrpapersonic@gmail.com>
parents: 118
diff changeset
21
118
39521c47c7a3 *: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents: 117
diff changeset
22 /* This file is very, very similar to the anime list page.
39521c47c7a3 *: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents: 117
diff changeset
23
39521c47c7a3 *: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents: 117
diff changeset
24 It differs from Taiga in that it uses tabs instead of
39521c47c7a3 *: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents: 117
diff changeset
25 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
26 maintain over multiple platforms. */
39521c47c7a3 *: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents: 117
diff changeset
27
114
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
28 TorrentsPageListSortFilter::TorrentsPageListSortFilter(QObject* parent) : QSortFilterProxyModel(parent) {
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
29 }
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
30
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
31 bool TorrentsPageListSortFilter::lessThan(const QModelIndex& l, const QModelIndex& r) const {
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
32 QVariant left = sourceModel()->data(l, sortRole());
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
33 QVariant right = sourceModel()->data(r, sortRole());
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 switch (left.userType()) {
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
36 case QMetaType::Int:
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
37 case QMetaType::UInt:
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
38 case QMetaType::LongLong:
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
39 case QMetaType::ULongLong: return left.toInt() < right.toInt();
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
40 case QMetaType::QDate: return left.toDate() < right.toDate();
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
41 case QMetaType::QString:
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
42 default: return QString::compare(left.toString(), right.toString(), Qt::CaseInsensitive) < 0;
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
43 }
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
44 }
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
45
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
46 /* -------------------------------------------- */
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 TorrentsPageListModel::TorrentsPageListModel(QObject* parent) : QAbstractListModel(parent) {
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 QByteArray TorrentsPageListModel::DownloadTorrentList() {
116
254b1d2b7096 settings: add torrents page, make rss feed configurable
Paper <mrpapersonic@gmail.com>
parents: 114
diff changeset
52 return HTTP::Get(session.config.torrents.feed_link);
114
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
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
55 void TorrentsPageListModel::ParseTorrentList(const QByteArray& ba) {
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
56 std::istringstream stdstream(Strings::ToUtf8String(ba));
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
57
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
58 pugi::xml_document doc;
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
59 if (!doc.load(stdstream))
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
60 return; // peace out
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
61
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
62 /* my extra special dumb hack. */
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
63 if (!rowCount(index(0))) {
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
64 beginInsertRows(QModelIndex(), 0, 0);
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
65 endInsertRows();
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
66 }
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
67
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
68 beginResetModel();
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
69
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
70 list.clear();
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
71 /* 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
72 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
73 TorrentModelItem torrent;
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
74 torrent.SetFilename(item.child_value("title")); /* "title" == filename */
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
75 {
154
d43d68408d3c dep/animia: fix XnuFdTools
Paper <mrpapersonic@gmail.com>
parents: 118
diff changeset
76 anitomy::Anitomy anitomy;
d43d68408d3c dep/animia: fix XnuFdTools
Paper <mrpapersonic@gmail.com>
parents: 118
diff changeset
77 anitomy.Parse(Strings::ToWstring(torrent.GetFilename()));
d43d68408d3c dep/animia: fix XnuFdTools
Paper <mrpapersonic@gmail.com>
parents: 118
diff changeset
78
d43d68408d3c dep/animia: fix XnuFdTools
Paper <mrpapersonic@gmail.com>
parents: 118
diff changeset
79 const auto& elements = anitomy.elements();
d43d68408d3c dep/animia: fix XnuFdTools
Paper <mrpapersonic@gmail.com>
parents: 118
diff changeset
80
d43d68408d3c dep/animia: fix XnuFdTools
Paper <mrpapersonic@gmail.com>
parents: 118
diff changeset
81 /* todo: patch Anitomy so that it doesn't use wide strings */
d43d68408d3c dep/animia: fix XnuFdTools
Paper <mrpapersonic@gmail.com>
parents: 118
diff changeset
82 torrent.SetTitle(Strings::ToUtf8String(elements.get(anitomy::kElementAnimeTitle)));
d43d68408d3c dep/animia: fix XnuFdTools
Paper <mrpapersonic@gmail.com>
parents: 118
diff changeset
83 torrent.SetEpisode(Strings::RemoveLeadingChars(Strings::ToUtf8String(elements.get(anitomy::kElementEpisodeNumber)), '0'));
d43d68408d3c dep/animia: fix XnuFdTools
Paper <mrpapersonic@gmail.com>
parents: 118
diff changeset
84 torrent.SetGroup(Strings::ToUtf8String(elements.get(anitomy::kElementReleaseGroup)));
d43d68408d3c dep/animia: fix XnuFdTools
Paper <mrpapersonic@gmail.com>
parents: 118
diff changeset
85 torrent.SetResolution(Strings::ToUtf8String(elements.get(anitomy::kElementVideoResolution)));
114
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
86 }
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
87 torrent.SetDescription(Strings::TextifySynopsis(item.child_value("description")));
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
88 {
118
39521c47c7a3 *: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents: 117
diff changeset
89 /* Parse description... */
39521c47c7a3 *: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents: 117
diff changeset
90 enum class Keys { SIZE, AUTHORIZED, SUBMITTER, COMMENT };
39521c47c7a3 *: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents: 117
diff changeset
91
39521c47c7a3 *: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents: 117
diff changeset
92 const std::unordered_map<std::string, Keys> KeyMap = {
39521c47c7a3 *: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents: 117
diff changeset
93 {"Size", Keys::SIZE},
39521c47c7a3 *: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents: 117
diff changeset
94 {"Authorized", Keys::AUTHORIZED},
39521c47c7a3 *: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents: 117
diff changeset
95 {"Submitter", Keys::SUBMITTER},
39521c47c7a3 *: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents: 117
diff changeset
96 {"Comment", Keys::COMMENT}
39521c47c7a3 *: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents: 117
diff changeset
97 };
39521c47c7a3 *: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents: 117
diff changeset
98
39521c47c7a3 *: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents: 117
diff changeset
99 const std::string description = Strings::TextifySynopsis(item.child_value("description"));
39521c47c7a3 *: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents: 117
diff changeset
100
114
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
101 /* Parse size from description */
118
39521c47c7a3 *: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents: 117
diff changeset
102 std::istringstream descstream(description);
114
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
103
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
104 for (std::string line; std::getline(descstream, line);) {
118
39521c47c7a3 *: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents: 117
diff changeset
105 const size_t pos = line.find_first_of(':', 0);
39521c47c7a3 *: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents: 117
diff changeset
106 if (pos == std::string::npos)
39521c47c7a3 *: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents: 117
diff changeset
107 continue;
39521c47c7a3 *: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents: 117
diff changeset
108
39521c47c7a3 *: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents: 117
diff changeset
109 const std::string key = line.substr(0, pos);
39521c47c7a3 *: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents: 117
diff changeset
110 const std::string value = line.substr(line.find_first_not_of(": ", pos));
114
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
111
118
39521c47c7a3 *: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents: 117
diff changeset
112 switch (KeyMap.at(key)) {
39521c47c7a3 *: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents: 117
diff changeset
113 case Keys::COMMENT:
39521c47c7a3 *: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents: 117
diff changeset
114 torrent.SetDescription(value);
39521c47c7a3 *: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents: 117
diff changeset
115 break;
39521c47c7a3 *: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents: 117
diff changeset
116 case Keys::SIZE:
39521c47c7a3 *: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents: 117
diff changeset
117 torrent.SetSize(Strings::HumanReadableSizeToBytes(value));
39521c47c7a3 *: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents: 117
diff changeset
118 break;
39521c47c7a3 *: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents: 117
diff changeset
119 default:
39521c47c7a3 *: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents: 117
diff changeset
120 break;
114
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
121 }
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
122 }
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
123 }
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
124 torrent.SetLink(item.child_value("link"));
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
125 torrent.SetGuid(item.child_value("guid"));
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
126 {
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
127 const QString date_str = Strings::ToQString(item.child_value("pubDate"));
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
128 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
129 }
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
130 list.push_back(torrent);
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
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
133 endResetModel();
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
134 }
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
135
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
136 void TorrentsPageListModel::RefreshTorrentList() {
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
137 ParseTorrentList(DownloadTorrentList());
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
138 }
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 int TorrentsPageListModel::rowCount(const QModelIndex& parent) const {
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
141 return list.size();
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
142 (void)(parent);
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
143 }
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
144
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
145 int TorrentsPageListModel::columnCount(const QModelIndex& parent) const {
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
146 return NB_COLUMNS;
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
147 (void)(parent);
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
148 }
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
149
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
150 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
151 switch (role) {
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
152 case Qt::DisplayRole: {
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
153 switch (section) {
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
154 case TL_TITLE: return tr("Anime title");
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
155 case TL_EPISODE: return tr("Episode");
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
156 case TL_GROUP: return tr("Group");
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
157 case TL_SIZE: return tr("Size");
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
158 case TL_RESOLUTION: return tr("Resolution"); /* this is named "Video" in Taiga */
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
159 case TL_SEEDERS: return tr("Seeding"); /* named "S" in Taiga */
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
160 case TL_LEECHERS: return tr("Leeching"); /* named "L" in Taiga */
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
161 case TL_DOWNLOADERS: return tr("Downloading"); /* named "D" in Taiga */
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
162 case TL_DESCRIPTION: return tr("Description");
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
163 case TL_FILENAME: return tr("Filename");
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
164 case TL_RELEASEDATE: return tr("Release date");
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
165 default: return {};
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
166 }
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
167 break;
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 case Qt::TextAlignmentRole: {
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
170 switch (section) {
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
171 case TL_FILENAME:
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
172 case TL_GROUP:
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
173 case TL_DESCRIPTION:
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
174 case TL_RESOLUTION:
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
175 case TL_TITLE: return QVariant(Qt::AlignLeft | Qt::AlignVCenter);
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
176 case TL_SEEDERS:
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
177 case TL_LEECHERS:
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
178 case TL_DOWNLOADERS:
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
179 case TL_SIZE:
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
180 case TL_EPISODE:
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
181 case TL_RELEASEDATE: return QVariant(Qt::AlignRight | Qt::AlignVCenter);
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
182 default: return {};
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
183 }
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
184 break;
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 }
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
187 return QAbstractListModel::headerData(section, orientation, role);
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
188 }
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
189
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
190 bool TorrentsPageListModel::setData(const QModelIndex& index, const QVariant& value, int role) {
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
191 TorrentModelItem& item = list.at(index.row());
54
466ac9870df9 add stub pages (to be implemented)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
192
114
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
193 if (index.column() == 0) {
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
194 switch (role) {
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
195 case Qt::EditRole:
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
196 return false;
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
197 case Qt::CheckStateRole:
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
198 item.SetChecked(value.toBool());
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
199 emit dataChanged(index, index);
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
200 return true;
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
201 }
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
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
204 return QAbstractItemModel::setData(index, value, role);
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
205 }
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
206
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
207 QVariant TorrentsPageListModel::data(const QModelIndex& index, int role) const {
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
208 if (!index.isValid())
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
209 return QVariant();
116
254b1d2b7096 settings: add torrents page, make rss feed configurable
Paper <mrpapersonic@gmail.com>
parents: 114
diff changeset
210
254b1d2b7096 settings: add torrents page, make rss feed configurable
Paper <mrpapersonic@gmail.com>
parents: 114
diff changeset
211 const TorrentModelItem& item = list.at(index.row());
254b1d2b7096 settings: add torrents page, make rss feed configurable
Paper <mrpapersonic@gmail.com>
parents: 114
diff changeset
212
114
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
213 switch (role) {
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
214 case Qt::DisplayRole:
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
215 switch (index.column()) {
116
254b1d2b7096 settings: add torrents page, make rss feed configurable
Paper <mrpapersonic@gmail.com>
parents: 114
diff changeset
216 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
217 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
218 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
219 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
220 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
221 case TL_SEEDERS: return item.GetSeeders();
254b1d2b7096 settings: add torrents page, make rss feed configurable
Paper <mrpapersonic@gmail.com>
parents: 114
diff changeset
222 case TL_LEECHERS: return item.GetLeechers();
254b1d2b7096 settings: add torrents page, make rss feed configurable
Paper <mrpapersonic@gmail.com>
parents: 114
diff changeset
223 case TL_DOWNLOADERS: return item.GetDownloaders();
254b1d2b7096 settings: add torrents page, make rss feed configurable
Paper <mrpapersonic@gmail.com>
parents: 114
diff changeset
224 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
225 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
226 case TL_RELEASEDATE: return item.GetDate();
114
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
227 default: return "";
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
228 }
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
229 break;
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
230 case Qt::UserRole:
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
231 switch (index.column()) {
116
254b1d2b7096 settings: add torrents page, make rss feed configurable
Paper <mrpapersonic@gmail.com>
parents: 114
diff changeset
232 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
233 /* We have to use this to work around some stupid
2c1b6782e1d0 pages/torrents: work around conversion error on Linux
Paper <mrpapersonic@gmail.com>
parents: 116
diff changeset
234 "conversion ambiguous" error on Linux */
2c1b6782e1d0 pages/torrents: work around conversion error on Linux
Paper <mrpapersonic@gmail.com>
parents: 116
diff changeset
235 case TL_SIZE: return QVariant::fromValue(item.GetSize());
114
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
236 default: return data(index, Qt::DisplayRole);
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 break;
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
239 case Qt::SizeHintRole: {
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
240 switch (index.column()) {
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
241 default: {
116
254b1d2b7096 settings: add torrents page, make rss feed configurable
Paper <mrpapersonic@gmail.com>
parents: 114
diff changeset
242 /* 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
243 const QString d = data(index, Qt::DisplayRole).toString();
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
244 const QFontMetrics metric = QFontMetrics(QFont());
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
245
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
246 return QSize(std::max(metric.horizontalAdvance(d), 100), metric.height());
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
247 }
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
248 }
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
249 break;
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
250 }
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
251 case Qt::TextAlignmentRole:
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
252 switch (index.column()) {
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
253 case TL_FILENAME:
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
254 case TL_GROUP:
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
255 case TL_DESCRIPTION:
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
256 case TL_RESOLUTION:
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
257 case TL_TITLE: return QVariant(Qt::AlignLeft | Qt::AlignVCenter);
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
258 case TL_SEEDERS:
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
259 case TL_LEECHERS:
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
260 case TL_DOWNLOADERS:
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
261 case TL_SIZE:
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
262 case TL_EPISODE:
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
263 case TL_RELEASEDATE: return QVariant(Qt::AlignRight | Qt::AlignVCenter);
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
264 default: return {};
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
265 }
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
266 break;
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
267 }
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
268 return QVariant();
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
269 }
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
270
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
271 Qt::ItemFlags TorrentsPageListModel::flags(const QModelIndex& index) const {
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
272 if (!index.isValid())
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
273 return Qt::NoItemFlags;
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
274
118
39521c47c7a3 *: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents: 117
diff changeset
275 return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
114
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
276 }
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
277
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
278 TorrentsPage::TorrentsPage(QWidget* parent) : QFrame(parent) {
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
279 setFrameShape(QFrame::Box);
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
280 setFrameShadow(QFrame::Sunken);
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
281
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
282 QVBoxLayout* layout = new QVBoxLayout(this);
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
283 layout->setContentsMargins(0, 0, 0, 0);
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
284 layout->setSpacing(0);
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 {
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
287 /* Toolbar */
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
288 QToolBar* toolbar = new QToolBar(this);
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
289 toolbar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
290 toolbar->setIconSize(QSize(16, 16));
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
291 toolbar->setMovable(false);
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
292
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
293 {
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
294 /* this needs to be stored somewhere to replicate Taiga's
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
295 "timer" feature */
116
254b1d2b7096 settings: add torrents page, make rss feed configurable
Paper <mrpapersonic@gmail.com>
parents: 114
diff changeset
296 toolbar->addAction(QIcon(":/icons/16x16/arrow-circle-315.png"), tr("&Check new torrents"), [this]{
114
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
297 QThreadPool::globalInstance()->start([this] {
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
298 Refresh();
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
299 });
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
300 });
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
301 }
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 toolbar->addSeparator();
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 {
116
254b1d2b7096 settings: add torrents page, make rss feed configurable
Paper <mrpapersonic@gmail.com>
parents: 114
diff changeset
306 toolbar->addAction(QIcon(":/icons/16x16/navigation-270-button.png"), tr("Download &marked torrents"));
114
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
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
309 {
116
254b1d2b7096 settings: add torrents page, make rss feed configurable
Paper <mrpapersonic@gmail.com>
parents: 114
diff changeset
310 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
311 }
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
312
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
313 toolbar->addSeparator();
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 {
116
254b1d2b7096 settings: add torrents page, make rss feed configurable
Paper <mrpapersonic@gmail.com>
parents: 114
diff changeset
316 toolbar->addAction(QIcon(":/icons/16x16/gear.png"), tr("&Settings"));
114
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
317 }
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 layout->addWidget(toolbar);
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
320 }
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
321
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 QFrame* line = new QFrame(this);
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
324 line->setFrameShape(QFrame::HLine);
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
325 line->setFrameShadow(QFrame::Sunken);
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
326 line->setLineWidth(1);
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
327 layout->addWidget(line);
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
328 }
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 QTreeView* treeview = new QTreeView(this);
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
332 treeview->setUniformRowHeights(true);
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
333 treeview->setAllColumnsShowFocus(false);
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
334 treeview->setAlternatingRowColors(true);
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
335 treeview->setSortingEnabled(true);
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
336 treeview->setSelectionMode(QAbstractItemView::ExtendedSelection);
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
337 treeview->setItemsExpandable(false);
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
338 treeview->setRootIsDecorated(false);
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
339 treeview->setContextMenuPolicy(Qt::CustomContextMenu);
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
340 treeview->setFrameShape(QFrame::NoFrame);
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
341
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
342 {
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
343 sort_model = new TorrentsPageListSortFilter(treeview);
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
344 model = new TorrentsPageListModel(treeview);
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
345 sort_model->setSourceModel(model);
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
346 sort_model->setSortRole(Qt::UserRole);
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
347 sort_model->setSortCaseSensitivity(Qt::CaseInsensitive);
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
348 treeview->setModel(sort_model);
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
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
351 layout->addWidget(treeview);
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
352 }
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
353 }
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 void TorrentsPage::Refresh() {
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
356 if (!model)
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
357 return;
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
358 model->RefreshTorrentList();
54
466ac9870df9 add stub pages (to be implemented)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
359 }
466ac9870df9 add stub pages (to be implemented)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
360
466ac9870df9 add stub pages (to be implemented)
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
361 #include "gui/pages/moc_torrents.cpp"