comparison src/gui/pages/torrents.cc @ 291:9a88e1725fd2

*: refactor lots of stuff I forgot to put this into different commits, oops! anyway, it doesn't really matter *that* much since this is an unfinished hobby project anyway. once it starts getting stable commit history will be more important, but for now it's not that big of a deal
author Paper <paper@paper.us.eu.org>
date Sun, 12 May 2024 16:31:07 -0400
parents f31305b9f60a
children a0aa8c8c4307
comparison
equal deleted inserted replaced
290:9347e2eaf6e5 291:9a88e1725fd2
63 const std::string filename = list.at(index.row()).GetFilename() + ".torrent"; 63 const std::string filename = list.at(index.row()).GetFilename() + ".torrent";
64 64
65 const std::filesystem::path torrents_dir = Filesystem::GetTorrentsPath(); 65 const std::filesystem::path torrents_dir = Filesystem::GetTorrentsPath();
66 std::filesystem::create_directories(torrents_dir); 66 std::filesystem::create_directories(torrents_dir);
67 67
68 HTTP::GetThread* thread = new HTTP::GetThread(link, {}, this); 68 /* this sucks */
69 69 HTTP::RequestThread* thread = new HTTP::RequestThread(link, {}, "", HTTP::Type::Get, this);
70 connect(thread, &HTTP::GetThread::ReceivedData, this, [this, torrents_dir, filename](const QByteArray& data) { 70
71 connect(thread, &HTTP::RequestThread::ReceivedData, this, [this, torrents_dir, filename](const QByteArray& data) {
71 std::ofstream file(torrents_dir / filename, std::ofstream::out | std::ofstream::trunc); 72 std::ofstream file(torrents_dir / filename, std::ofstream::out | std::ofstream::trunc);
72 if (!file) 73 if (!file)
73 return; // wat 74 return; // wat
74 75
75 file.write(data.data(), data.size()); 76 file.write(data.data(), data.size());
76 file.close(); 77 file.close();
77 }); 78 });
78 connect(thread, &HTTP::GetThread::finished, thread, &HTTP::GetThread::deleteLater); 79 connect(thread, &HTTP::RequestThread::finished, thread, &HTTP::RequestThread::deleteLater);
79 80
80 thread->start(); 81 thread->start();
81 } 82 }
82 } 83 }
83 84
84 QByteArray TorrentsPageListModel::DownloadTorrentList() { 85 QByteArray TorrentsPageListModel::DownloadTorrentList() {
85 return HTTP::Get(session.config.torrents.feed_link); 86 return HTTP::Request(session.config.torrents.feed_link);
86 } 87 }
87 88
88 void TorrentsPageListModel::ParseFeedDescription(const std::string& description, Torrent& torrent) { 89 void TorrentsPageListModel::ParseFeedDescription(const std::string& description, Torrent& torrent) {
89 /* Parse description... */ 90 /* Parse description... */
90 enum class Keys { 91 enum class Keys {
414 415
415 void TorrentsPage::Refresh() { 416 void TorrentsPage::Refresh() {
416 if (!model) 417 if (!model)
417 return; 418 return;
418 419
419 HTTP::GetThread* thread = new HTTP::GetThread(session.config.torrents.feed_link); 420 HTTP::RequestThread* thread = new HTTP::RequestThread(session.config.torrents.feed_link);
420 421
421 connect(thread, &HTTP::GetThread::ReceivedData, this, [&](const QByteArray& ba) { 422 connect(thread, &HTTP::RequestThread::ReceivedData, this, [&](const QByteArray& ba) {
422 /* This is to make sure we aren't in a different thread 423 /* This is to make sure we aren't in a different thread
423 * messing around with GUI stuff 424 * messing around with GUI stuff
424 */ 425 */
425 treeview->setUpdatesEnabled(false); 426 treeview->setUpdatesEnabled(false);
426 model->ParseTorrentList(ba); 427 model->ParseTorrentList(ba);
427 treeview->setUpdatesEnabled(true); 428 treeview->setUpdatesEnabled(true);
428 }); 429 });
429 connect(thread, &QThread::finished, thread, &QThread::deleteLater); 430 connect(thread, &HTTP::RequestThread::finished, thread, &HTTP::RequestThread::deleteLater);
430 431
431 thread->start(); 432 thread->start();
432 } 433 }