Mercurial > minori
comparison src/gui/pages/torrents.cc @ 236:4d461ef7d424
HUGE UPDATE: convert build system to autotools
why? because cmake sucks :)
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Fri, 19 Jan 2024 00:24:02 -0500 |
parents | 2f5a9247e501 |
children | c130f47f6f48 |
comparison
equal
deleted
inserted
replaced
235:593108b3d555 | 236:4d461ef7d424 |
---|---|
61 const std::string filename = list.at(index.row()).GetFilename() + ".torrent"; | 61 const std::string filename = list.at(index.row()).GetFilename() + ".torrent"; |
62 | 62 |
63 const std::filesystem::path torrents_dir = Filesystem::GetTorrentsPath(); | 63 const std::filesystem::path torrents_dir = Filesystem::GetTorrentsPath(); |
64 std::filesystem::create_directories(torrents_dir); | 64 std::filesystem::create_directories(torrents_dir); |
65 | 65 |
66 std::ofstream file(torrents_dir / filename, std::ofstream::out | std::ofstream::trunc); | 66 HTTP::GetThread* thread = new HTTP::GetThread(link, {}, this); |
67 if (!file) | 67 |
68 return; // wat | 68 connect(thread, &HTTP::GetThread::ReceivedData, this, [this, torrents_dir, filename](const QByteArray& data) { |
69 | 69 std::ofstream file(torrents_dir / filename, std::ofstream::out | std::ofstream::trunc); |
70 const QByteArray data = HTTP::Get(link); | 70 if (!file) |
71 file.write(data.data(), data.size()); | 71 return; // wat |
72 | 72 |
73 file.close(); | 73 file.write(data.data(), data.size()); |
74 file.close(); | |
75 }); | |
76 connect(thread, &HTTP::GetThread::finished, thread, &HTTP::GetThread::deleteLater); | |
77 | |
78 thread->start(); | |
74 } | 79 } |
75 } | 80 } |
76 | 81 |
77 QByteArray TorrentsPageListModel::DownloadTorrentList() { | 82 QByteArray TorrentsPageListModel::DownloadTorrentList() { |
78 return HTTP::Get(session.config.torrents.feed_link); | 83 return HTTP::Get(session.config.torrents.feed_link); |
184 switch (section) { | 189 switch (section) { |
185 case TL_TITLE: return tr("Anime title"); | 190 case TL_TITLE: return tr("Anime title"); |
186 case TL_EPISODE: return tr("Episode"); | 191 case TL_EPISODE: return tr("Episode"); |
187 case TL_GROUP: return tr("Group"); | 192 case TL_GROUP: return tr("Group"); |
188 case TL_SIZE: return tr("Size"); | 193 case TL_SIZE: return tr("Size"); |
189 case TL_RESOLUTION: return tr("Resolution"); /* this is named "Video" in Taiga */ | 194 case TL_RESOLUTION: return tr("Resolution"); /* "Video" in Taiga */ |
190 case TL_SEEDERS: return tr("Seeding"); /* named "S" in Taiga */ | 195 case TL_SEEDERS: return tr("S"); |
191 case TL_LEECHERS: return tr("Leeching"); /* named "L" in Taiga */ | 196 case TL_LEECHERS: return tr("L"); |
192 case TL_DOWNLOADERS: return tr("Downloading"); /* named "D" in Taiga */ | 197 case TL_DOWNLOADS: return tr("D"); |
193 case TL_DESCRIPTION: return tr("Description"); | 198 case TL_DESCRIPTION: return tr("Description"); |
194 case TL_FILENAME: return tr("Filename"); | 199 case TL_FILENAME: return tr("Filename"); |
195 case TL_RELEASEDATE: return tr("Release date"); | 200 case TL_RELEASEDATE: return tr("Release date"); |
196 default: return {}; | 201 default: return {}; |
197 } | 202 } |
204 case TL_DESCRIPTION: | 209 case TL_DESCRIPTION: |
205 case TL_RESOLUTION: | 210 case TL_RESOLUTION: |
206 case TL_TITLE: return QVariant(Qt::AlignLeft | Qt::AlignVCenter); | 211 case TL_TITLE: return QVariant(Qt::AlignLeft | Qt::AlignVCenter); |
207 case TL_SEEDERS: | 212 case TL_SEEDERS: |
208 case TL_LEECHERS: | 213 case TL_LEECHERS: |
209 case TL_DOWNLOADERS: | 214 case TL_DOWNLOADS: |
210 case TL_SIZE: | 215 case TL_SIZE: |
211 case TL_EPISODE: | 216 case TL_EPISODE: |
212 case TL_RELEASEDATE: return QVariant(Qt::AlignRight | Qt::AlignVCenter); | 217 case TL_RELEASEDATE: return QVariant(Qt::AlignRight | Qt::AlignVCenter); |
213 default: return {}; | 218 default: return {}; |
214 } | 219 } |
249 case TL_GROUP: return Strings::ToQString(item.GetGroup()); | 254 case TL_GROUP: return Strings::ToQString(item.GetGroup()); |
250 case TL_SIZE: return session.config.locale.GetLocale().formattedDataSize(item.GetSize()); | 255 case TL_SIZE: return session.config.locale.GetLocale().formattedDataSize(item.GetSize()); |
251 case TL_RESOLUTION: return Strings::ToQString(item.GetResolution()); | 256 case TL_RESOLUTION: return Strings::ToQString(item.GetResolution()); |
252 case TL_SEEDERS: return item.GetSeeders(); | 257 case TL_SEEDERS: return item.GetSeeders(); |
253 case TL_LEECHERS: return item.GetLeechers(); | 258 case TL_LEECHERS: return item.GetLeechers(); |
254 case TL_DOWNLOADERS: return item.GetDownloaders(); | 259 case TL_DOWNLOADS: return item.GetDownloads(); |
255 case TL_DESCRIPTION: return Strings::ToQString(item.GetDescription()); | 260 case TL_DESCRIPTION: return Strings::ToQString(item.GetDescription()); |
256 case TL_FILENAME: return Strings::ToQString(item.GetFilename()); | 261 case TL_FILENAME: return Strings::ToQString(item.GetFilename()); |
257 case TL_RELEASEDATE: return item.GetDate(); | 262 case TL_RELEASEDATE: return item.GetDate(); |
258 default: return {}; | 263 default: return {}; |
259 } | 264 } |
287 case TL_DESCRIPTION: | 292 case TL_DESCRIPTION: |
288 case TL_RESOLUTION: | 293 case TL_RESOLUTION: |
289 case TL_TITLE: return QVariant(Qt::AlignLeft | Qt::AlignVCenter); | 294 case TL_TITLE: return QVariant(Qt::AlignLeft | Qt::AlignVCenter); |
290 case TL_SEEDERS: | 295 case TL_SEEDERS: |
291 case TL_LEECHERS: | 296 case TL_LEECHERS: |
292 case TL_DOWNLOADERS: | 297 case TL_DOWNLOADS: |
293 case TL_SIZE: | 298 case TL_SIZE: |
294 case TL_EPISODE: | 299 case TL_EPISODE: |
295 case TL_RELEASEDATE: return QVariant(Qt::AlignRight | Qt::AlignVCenter); | 300 case TL_RELEASEDATE: return QVariant(Qt::AlignRight | Qt::AlignVCenter); |
296 default: return {}; | 301 default: return {}; |
297 } | 302 } |
378 sort_model->setSortRole(Qt::UserRole); | 383 sort_model->setSortRole(Qt::UserRole); |
379 sort_model->setSortCaseSensitivity(Qt::CaseInsensitive); | 384 sort_model->setSortCaseSensitivity(Qt::CaseInsensitive); |
380 treeview->setModel(sort_model); | 385 treeview->setModel(sort_model); |
381 } | 386 } |
382 | 387 |
388 // set column sizes | |
389 treeview->setColumnWidth(TorrentsPageListModel::TL_TITLE, 240); | |
390 treeview->setColumnWidth(TorrentsPageListModel::TL_EPISODE, 60); | |
391 treeview->setColumnWidth(TorrentsPageListModel::TL_GROUP, 100); | |
392 treeview->setColumnWidth(TorrentsPageListModel::TL_SIZE, 70); | |
393 treeview->setColumnWidth(TorrentsPageListModel::TL_RESOLUTION, 100); | |
394 treeview->setColumnWidth(TorrentsPageListModel::TL_SEEDERS, 20); | |
395 treeview->setColumnWidth(TorrentsPageListModel::TL_LEECHERS, 20); | |
396 treeview->setColumnWidth(TorrentsPageListModel::TL_DOWNLOADS, 20); | |
397 treeview->setColumnWidth(TorrentsPageListModel::TL_DESCRIPTION, 200); | |
398 treeview->setColumnWidth(TorrentsPageListModel::TL_FILENAME, 200); | |
399 treeview->setColumnWidth(TorrentsPageListModel::TL_RELEASEDATE, 190); | |
400 | |
383 layout->addWidget(treeview); | 401 layout->addWidget(treeview); |
384 } | 402 } |
385 } | 403 } |
386 | 404 |
387 void TorrentsPage::DownloadSelection() { | 405 void TorrentsPage::DownloadSelection() { |
388 /* we only want one of these at a time, because if we don't | 406 if (!model) |
389 * we have the possibility of going into Multithreading Hell | |
390 */ | |
391 static QThread* thread = nullptr; | |
392 | |
393 if (!model || thread) | |
394 return; | 407 return; |
395 | 408 |
396 const QItemSelection selection = sort_model->mapSelectionToSource(treeview->selectionModel()->selection()); | 409 const QItemSelection selection = sort_model->mapSelectionToSource(treeview->selectionModel()->selection()); |
397 | 410 |
398 thread = QThread::create([this, selection] { | 411 model->DownloadTorrents(selection); |
399 model->DownloadTorrents(selection); | |
400 }); | |
401 | |
402 connect(thread, &QThread::finished, thread, &QThread::deleteLater); | |
403 connect(thread, &QThread::finished, this, [&] { thread = nullptr; }); | |
404 | |
405 thread->start(); | |
406 } | 412 } |
407 | 413 |
408 void TorrentsPage::Refresh() { | 414 void TorrentsPage::Refresh() { |
409 if (!model) | 415 if (!model) |
410 return; | 416 return; |
421 }); | 427 }); |
422 connect(thread, &QThread::finished, thread, &QThread::deleteLater); | 428 connect(thread, &QThread::finished, thread, &QThread::deleteLater); |
423 | 429 |
424 thread->start(); | 430 thread->start(); |
425 } | 431 } |
426 | |
427 #include "gui/pages/moc_torrents.cpp" |