diff 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
line wrap: on
line diff
--- a/src/gui/pages/torrents.cc	Tue Jan 16 15:22:29 2024 -0500
+++ b/src/gui/pages/torrents.cc	Fri Jan 19 00:24:02 2024 -0500
@@ -63,14 +63,19 @@
 		const std::filesystem::path torrents_dir = Filesystem::GetTorrentsPath();
 		std::filesystem::create_directories(torrents_dir);
 
-		std::ofstream file(torrents_dir / filename, std::ofstream::out | std::ofstream::trunc);
-		if (!file)
-			return; // wat
+		HTTP::GetThread* thread = new HTTP::GetThread(link, {}, this);
+
+		connect(thread, &HTTP::GetThread::ReceivedData, this, [this, torrents_dir, filename](const QByteArray& data) {
+			std::ofstream file(torrents_dir / filename, std::ofstream::out | std::ofstream::trunc);
+			if (!file)
+				return; // wat
 
-		const QByteArray data = HTTP::Get(link);
-		file.write(data.data(), data.size());
+			file.write(data.data(), data.size());
+			file.close();
+		});
+		connect(thread, &HTTP::GetThread::finished, thread, &HTTP::GetThread::deleteLater);
 
-		file.close();
+		thread->start();
 	}
 }
 
@@ -186,10 +191,10 @@
 				case TL_EPISODE: return tr("Episode");
 				case TL_GROUP: return tr("Group");
 				case TL_SIZE: return tr("Size");
-				case TL_RESOLUTION: return tr("Resolution"); /* this is named "Video" in Taiga */
-				case TL_SEEDERS: return tr("Seeding"); /* named "S" in Taiga */
-				case TL_LEECHERS: return tr("Leeching"); /* named "L" in Taiga */
-				case TL_DOWNLOADERS: return tr("Downloading"); /* named "D" in Taiga */
+				case TL_RESOLUTION: return tr("Resolution"); /* "Video" in Taiga */
+				case TL_SEEDERS: return tr("S");
+				case TL_LEECHERS: return tr("L");
+				case TL_DOWNLOADS: return tr("D");
 				case TL_DESCRIPTION: return tr("Description");
 				case TL_FILENAME: return tr("Filename");
 				case TL_RELEASEDATE: return tr("Release date");
@@ -206,7 +211,7 @@
 				case TL_TITLE: return QVariant(Qt::AlignLeft | Qt::AlignVCenter);
 				case TL_SEEDERS:
 				case TL_LEECHERS:
-				case TL_DOWNLOADERS:
+				case TL_DOWNLOADS:
 				case TL_SIZE:
 				case TL_EPISODE:
 				case TL_RELEASEDATE: return QVariant(Qt::AlignRight | Qt::AlignVCenter);
@@ -251,7 +256,7 @@
 				case TL_RESOLUTION: return Strings::ToQString(item.GetResolution());
 				case TL_SEEDERS: return item.GetSeeders();
 				case TL_LEECHERS: return item.GetLeechers();
-				case TL_DOWNLOADERS: return item.GetDownloaders();
+				case TL_DOWNLOADS: return item.GetDownloads();
 				case TL_DESCRIPTION: return Strings::ToQString(item.GetDescription());
 				case TL_FILENAME: return Strings::ToQString(item.GetFilename());
 				case TL_RELEASEDATE: return item.GetDate();
@@ -289,7 +294,7 @@
 				case TL_TITLE: return QVariant(Qt::AlignLeft | Qt::AlignVCenter);
 				case TL_SEEDERS:
 				case TL_LEECHERS:
-				case TL_DOWNLOADERS:
+				case TL_DOWNLOADS:
 				case TL_SIZE:
 				case TL_EPISODE:
 				case TL_RELEASEDATE: return QVariant(Qt::AlignRight | Qt::AlignVCenter);
@@ -380,29 +385,30 @@
 			treeview->setModel(sort_model);
 		}
 
+		// set column sizes
+		treeview->setColumnWidth(TorrentsPageListModel::TL_TITLE,       240);
+		treeview->setColumnWidth(TorrentsPageListModel::TL_EPISODE,     60);
+		treeview->setColumnWidth(TorrentsPageListModel::TL_GROUP,       100);
+		treeview->setColumnWidth(TorrentsPageListModel::TL_SIZE,        70);
+		treeview->setColumnWidth(TorrentsPageListModel::TL_RESOLUTION,  100);
+		treeview->setColumnWidth(TorrentsPageListModel::TL_SEEDERS,     20);
+		treeview->setColumnWidth(TorrentsPageListModel::TL_LEECHERS,    20);
+		treeview->setColumnWidth(TorrentsPageListModel::TL_DOWNLOADS,   20);
+		treeview->setColumnWidth(TorrentsPageListModel::TL_DESCRIPTION, 200);
+		treeview->setColumnWidth(TorrentsPageListModel::TL_FILENAME,    200);
+		treeview->setColumnWidth(TorrentsPageListModel::TL_RELEASEDATE, 190);
+
 		layout->addWidget(treeview);
 	}
 }
 
 void TorrentsPage::DownloadSelection() {
-	/* we only want one of these at a time, because if we don't
-	 * we have the possibility of going into Multithreading Hell
-	*/
-	static QThread* thread = nullptr;
-
-	if (!model || thread)
+	if (!model)
 		return;
 
 	const QItemSelection selection = sort_model->mapSelectionToSource(treeview->selectionModel()->selection());
 
-	thread = QThread::create([this, selection] {
-		model->DownloadTorrents(selection);
-	});
-
-	connect(thread, &QThread::finished, thread, &QThread::deleteLater);
-	connect(thread, &QThread::finished, this, [&] { thread = nullptr; });
-
-	thread->start();
+	model->DownloadTorrents(selection);
 }
 
 void TorrentsPage::Refresh() {
@@ -423,5 +429,3 @@
 
 	thread->start();
 }
-
-#include "gui/pages/moc_torrents.cpp"