Mercurial > minori
comparison src/gui/pages/torrents.cc @ 116:254b1d2b7096
settings: add torrents page, make rss feed configurable
| author | Paper <mrpapersonic@gmail.com> |
|---|---|
| date | Tue, 07 Nov 2023 13:52:13 -0500 |
| parents | ab191e28e69d |
| children | 2c1b6782e1d0 |
comparison
equal
deleted
inserted
replaced
| 115:c72b907b9bef | 116:254b1d2b7096 |
|---|---|
| 39 | 39 |
| 40 TorrentsPageListModel::TorrentsPageListModel(QObject* parent) : QAbstractListModel(parent) { | 40 TorrentsPageListModel::TorrentsPageListModel(QObject* parent) : QAbstractListModel(parent) { |
| 41 } | 41 } |
| 42 | 42 |
| 43 QByteArray TorrentsPageListModel::DownloadTorrentList() { | 43 QByteArray TorrentsPageListModel::DownloadTorrentList() { |
| 44 return HTTP::Get("https://www.tokyotosho.info/rss.php?filter=1,11&zwnj=0"); | 44 return HTTP::Get(session.config.torrents.feed_link); |
| 45 } | 45 } |
| 46 | 46 |
| 47 void TorrentsPageListModel::ParseTorrentList(const QByteArray& ba) { | 47 void TorrentsPageListModel::ParseTorrentList(const QByteArray& ba) { |
| 48 std::istringstream stdstream(Strings::ToUtf8String(ba)); | 48 std::istringstream stdstream(Strings::ToUtf8String(ba)); |
| 49 | 49 |
| 171 } | 171 } |
| 172 | 172 |
| 173 QVariant TorrentsPageListModel::data(const QModelIndex& index, int role) const { | 173 QVariant TorrentsPageListModel::data(const QModelIndex& index, int role) const { |
| 174 if (!index.isValid()) | 174 if (!index.isValid()) |
| 175 return QVariant(); | 175 return QVariant(); |
| 176 | |
| 177 const TorrentModelItem& item = list.at(index.row()); | |
| 178 | |
| 176 switch (role) { | 179 switch (role) { |
| 177 case Qt::DisplayRole: | 180 case Qt::DisplayRole: |
| 178 switch (index.column()) { | 181 switch (index.column()) { |
| 179 case TL_TITLE: return Strings::ToQString(list.at(index.row()).GetTitle()); | 182 case TL_TITLE: return Strings::ToQString(item.GetTitle()); |
| 180 case TL_EPISODE: return Strings::ToQString(list.at(index.row()).GetEpisode()); | 183 case TL_EPISODE: return Strings::ToQString(item.GetEpisode()); |
| 181 case TL_GROUP: return Strings::ToQString(list.at(index.row()).GetGroup()); | 184 case TL_GROUP: return Strings::ToQString(item.GetGroup()); |
| 182 case TL_SIZE: return session.config.locale.GetLocale().formattedDataSize(list.at(index.row()).GetSize()); | 185 case TL_SIZE: return session.config.locale.GetLocale().formattedDataSize(item.GetSize()); |
| 183 case TL_RESOLUTION: return Strings::ToQString(list.at(index.row()).GetResolution()); | 186 case TL_RESOLUTION: return Strings::ToQString(item.GetResolution()); |
| 184 case TL_SEEDERS: return list.at(index.row()).GetSeeders(); | 187 case TL_SEEDERS: return item.GetSeeders(); |
| 185 case TL_LEECHERS: return list.at(index.row()).GetLeechers(); | 188 case TL_LEECHERS: return item.GetLeechers(); |
| 186 case TL_DOWNLOADERS: return list.at(index.row()).GetDownloaders(); | 189 case TL_DOWNLOADERS: return item.GetDownloaders(); |
| 187 case TL_DESCRIPTION: return Strings::ToQString(list.at(index.row()).GetDescription()); | 190 case TL_DESCRIPTION: return Strings::ToQString(item.GetDescription()); |
| 188 case TL_FILENAME: return Strings::ToQString(list.at(index.row()).GetFilename()); | 191 case TL_FILENAME: return Strings::ToQString(item.GetFilename()); |
| 189 case TL_RELEASEDATE: return list.at(index.row()).GetDate(); | 192 case TL_RELEASEDATE: return item.GetDate(); |
| 190 default: return ""; | 193 default: return ""; |
| 191 } | 194 } |
| 192 break; | 195 break; |
| 193 case Qt::UserRole: | 196 case Qt::UserRole: |
| 194 switch (index.column()) { | 197 switch (index.column()) { |
| 195 case TL_EPISODE: return Strings::ToInt(list.at(index.row()).GetEpisode(), -1); | 198 case TL_EPISODE: return Strings::ToInt(item.GetEpisode(), -1); |
| 196 case TL_SIZE: return list.at(index.row()).GetSize(); | 199 case TL_SIZE: return item.GetSize(); |
| 197 default: return data(index, Qt::DisplayRole); | 200 default: return data(index, Qt::DisplayRole); |
| 198 } | 201 } |
| 199 break; | 202 break; |
| 200 case Qt::CheckStateRole: | 203 case Qt::CheckStateRole: |
| 201 switch (index.column()) { | 204 switch (index.column()) { |
| 202 case 0: return list.at(index.row()).GetChecked() ? Qt::Checked : Qt::Unchecked; | 205 case 0: return item.GetChecked() ? Qt::Checked : Qt::Unchecked; |
| 203 default: return {}; | 206 default: return {}; |
| 204 } | 207 } |
| 205 case Qt::SizeHintRole: { | 208 case Qt::SizeHintRole: { |
| 206 switch (index.column()) { | 209 switch (index.column()) { |
| 207 default: { | 210 default: { |
| 211 /* max horizontal size of 100, height size = size of current font */ | |
| 208 const QString d = data(index, Qt::DisplayRole).toString(); | 212 const QString d = data(index, Qt::DisplayRole).toString(); |
| 209 const QFontMetrics metric = QFontMetrics(QFont()); | 213 const QFontMetrics metric = QFontMetrics(QFont()); |
| 210 | 214 |
| 211 return QSize(std::max(metric.horizontalAdvance(d), 100), metric.height()); | 215 return QSize(std::max(metric.horizontalAdvance(d), 100), metric.height()); |
| 212 } | 216 } |
| 261 toolbar->setMovable(false); | 265 toolbar->setMovable(false); |
| 262 | 266 |
| 263 { | 267 { |
| 264 /* this needs to be stored somewhere to replicate Taiga's | 268 /* this needs to be stored somewhere to replicate Taiga's |
| 265 "timer" feature */ | 269 "timer" feature */ |
| 266 QAction* action = toolbar->addAction(QIcon(":/icons/16x16/arrow-circle-315.png"), tr("&Check new torrents"), [this]{ | 270 toolbar->addAction(QIcon(":/icons/16x16/arrow-circle-315.png"), tr("&Check new torrents"), [this]{ |
| 267 QThreadPool::globalInstance()->start([this] { | 271 QThreadPool::globalInstance()->start([this] { |
| 268 Refresh(); | 272 Refresh(); |
| 269 }); | 273 }); |
| 270 }); | 274 }); |
| 271 } | 275 } |
| 272 | 276 |
| 273 toolbar->addSeparator(); | 277 toolbar->addSeparator(); |
| 274 | 278 |
| 275 { | 279 { |
| 276 QAction* action = toolbar->addAction(QIcon(":/icons/16x16/navigation-270-button.png"), tr("Download &marked torrents")); | 280 toolbar->addAction(QIcon(":/icons/16x16/navigation-270-button.png"), tr("Download &marked torrents")); |
| 277 } | 281 } |
| 278 | 282 |
| 279 { | 283 { |
| 280 QAction* action = toolbar->addAction(QIcon(":/icons/16x16/cross-button.png"), tr("&Discard all")); | 284 toolbar->addAction(QIcon(":/icons/16x16/cross-button.png"), tr("&Discard all")); |
| 281 } | 285 } |
| 282 | 286 |
| 283 toolbar->addSeparator(); | 287 toolbar->addSeparator(); |
| 284 | 288 |
| 285 { | 289 { |
| 286 QAction* action = toolbar->addAction(QIcon(":/icons/16x16/gear.png"), tr("&Settings")); | 290 toolbar->addAction(QIcon(":/icons/16x16/gear.png"), tr("&Settings")); |
| 287 } | 291 } |
| 288 | 292 |
| 289 layout->addWidget(toolbar); | 293 layout->addWidget(toolbar); |
| 290 } | 294 } |
| 291 | 295 |
