diff src/gui/pages/anime_list.cc @ 118:39521c47c7a3

*: another huge megacommit, SORRY The torrents page works a lot better now Added the edit option to the anime list right click menu Vectorized currently playing files Available player and extensions are now loaded at runtime from files in (dotpath)/players.json and (dotpath)/extensions.json These paths are not permanent and will likely be moved to (dotpath)/recognition ... ... ...
author Paper <mrpapersonic@gmail.com>
date Tue, 07 Nov 2023 23:40:54 -0500
parents ab191e28e69d
children bc8d2ccff09c
line wrap: on
line diff
--- a/src/gui/pages/anime_list.cc	Tue Nov 07 16:06:17 2023 -0500
+++ b/src/gui/pages/anime_list.cc	Tue Nov 07 23:40:54 2023 -0500
@@ -108,13 +108,13 @@
 				case AL_TITLE: return QString::fromUtf8(list[index.row()].GetUserPreferredTitle().c_str());
 				case AL_PROGRESS:
 					return QString::number(list[index.row()].GetUserProgress()) + "/" +
-					       QString::number(list[index.row()].GetEpisodes());
+						   QString::number(list[index.row()].GetEpisodes());
 				case AL_EPISODES: return list[index.row()].GetEpisodes();
 				case AL_SCORE: return list[index.row()].GetUserScore();
 				case AL_TYPE: return Strings::ToQString(Translate::ToString(list[index.row()].GetFormat()));
 				case AL_SEASON:
 					return Strings::ToQString(Translate::ToString(list[index.row()].GetSeason())) + " " +
-					       QString::number(list[index.row()].GetAirDate().GetYear());
+						   QString::number(list[index.row()].GetAirDate().GetYear());
 				case AL_AVG_SCORE: return QString::number(list[index.row()].GetAudienceScore()) + "%";
 				case AL_STARTED: return list[index.row()].GetUserDateStarted().GetAsQDate();
 				case AL_COMPLETED: return list[index.row()].GetUserDateCompleted().GetAsQDate();
@@ -163,8 +163,8 @@
 }
 
 void AnimeListPageModel::RefreshList() {
-	bool has_children = !!rowCount(index(0));
-	if (!has_children) {
+	/* equivalent to hasChildren()... */
+	if (!rowCount(index(0))) {
 		beginInsertRows(QModelIndex(), 0, 0);
 		endInsertRows();
 	}
@@ -233,7 +233,8 @@
 		if (i == AnimeListPageModel::AL_TITLE)
 			continue;
 		const auto column_name =
-		    sort_models[tab_bar->currentIndex()]->headerData(i, Qt::Horizontal, Qt::DisplayRole).toString();
+			sort_models[tab_bar->currentIndex()]->headerData(i, Qt::Horizontal, Qt::DisplayRole).toString();
+
 		QAction* action = menu->addAction(column_name, this, [this, i](const bool checked) {
 			if (!checked && (VisibleColumnsCount() <= 1))
 				return;
@@ -245,6 +246,7 @@
 
 			// SaveSettings();
 		});
+
 		action->setCheckable(true);
 		action->setChecked(!tree_view->isColumnHidden(i));
 	}
@@ -266,9 +268,9 @@
 	menu->setToolTipsVisible(true);
 
 	AnimeListPageModel* source_model =
-	    reinterpret_cast<AnimeListPageModel*>(sort_models[tab_bar->currentIndex()]->sourceModel());
+		reinterpret_cast<AnimeListPageModel*>(sort_models[tab_bar->currentIndex()]->sourceModel());
 	const QItemSelection selection =
-	    sort_models[tab_bar->currentIndex()]->mapSelectionToSource(tree_view->selectionModel()->selection());
+		sort_models[tab_bar->currentIndex()]->mapSelectionToSource(tree_view->selectionModel()->selection());
 
 	std::set<Anime::Anime*> animes;
 	for (const auto& index : selection.indexes()) {
@@ -281,8 +283,9 @@
 
 	menu->addAction(tr("Information"), [this, animes] {
 		for (auto& anime : animes) {
-			InformationDialog* dialog = new InformationDialog(
-			    *anime, [this, anime] { UpdateAnime(anime->GetId()); }, this);
+			InformationDialog* dialog = new InformationDialog(*anime, [this, anime] {
+				UpdateAnime(anime->GetId());
+			}, InformationDialog::PAGE_MAIN_INFO, this);
 
 			dialog->show();
 			dialog->raise();
@@ -290,6 +293,17 @@
 		}
 	});
 	menu->addSeparator();
+	menu->addAction(tr("Edit"), [this, animes] {
+		for (auto& anime : animes) {
+			InformationDialog* dialog = new InformationDialog(*anime, [this, anime] {
+				UpdateAnime(anime->GetId());
+			}, InformationDialog::PAGE_MY_LIST, this);
+
+			dialog->show();
+			dialog->raise();
+			dialog->activateWindow();
+		}
+	});
 	menu->addAction(tr("Delete from list..."), [this, animes] {
 		for (auto& anime : animes) {
 			RemoveAnime(anime->GetId());
@@ -301,19 +315,20 @@
 void AnimeListPage::ItemDoubleClicked() {
 	/* throw out any other garbage */
 	const QItemSelection selection =
-	    sort_models[tab_bar->currentIndex()]->mapSelectionToSource(tree_view->selectionModel()->selection());
+		sort_models[tab_bar->currentIndex()]->mapSelectionToSource(tree_view->selectionModel()->selection());
 	if (!selection.indexes().first().isValid()) {
 		return;
 	}
 
 	AnimeListPageModel* source_model =
-	    reinterpret_cast<AnimeListPageModel*>(sort_models[tab_bar->currentIndex()]->sourceModel());
+		reinterpret_cast<AnimeListPageModel*>(sort_models[tab_bar->currentIndex()]->sourceModel());
 
 	const QModelIndex index = source_model->index(selection.indexes().first().row());
 	Anime::Anime* anime = source_model->GetAnimeFromIndex(index);
 
-	InformationDialog* dialog = new InformationDialog(
-	    *anime, [this, anime] { UpdateAnime(anime->GetId()); }, this);
+	InformationDialog* dialog = new InformationDialog(*anime, [this, anime] {
+		UpdateAnime(anime->GetId());
+	}, InformationDialog::PAGE_MAIN_INFO, this);
 
 	dialog->show();
 	dialog->raise();
@@ -328,7 +343,7 @@
 void AnimeListPage::RefreshTabs() {
 	for (unsigned int i = 0; i < sort_models.size(); i++)
 		tab_bar->setTabText(i, Strings::ToQString(Translate::ToString(Anime::ListStatuses[i])) + " (" +
-		                           QString::number(Anime::db.GetListsAnimeAmount(Anime::ListStatuses[i])) + ")");
+								   QString::number(Anime::db.GetListsAnimeAmount(Anime::ListStatuses[i])) + ")");
 }
 
 void AnimeListPage::Refresh() {
@@ -423,7 +438,7 @@
 
 	for (unsigned int i = 0; i < sort_models.size(); i++) {
 		tab_bar->addTab(Strings::ToQString(Translate::ToString(Anime::ListStatuses[i])) + " (" +
-		                QString::number(Anime::db.GetListsAnimeAmount(Anime::ListStatuses[i])) + ")");
+						QString::number(Anime::db.GetListsAnimeAmount(Anime::ListStatuses[i])) + ")");
 		sort_models[i] = new AnimeListPageSortFilter(tree_view);
 		sort_models[i]->setSourceModel(new AnimeListPageModel(this, Anime::ListStatuses[i]));
 		sort_models[i]->setSortRole(Qt::UserRole);
@@ -441,10 +456,10 @@
 
 	/* Enter & return keys */
 	connect(new QShortcut(Qt::Key_Return, tree_view, nullptr, nullptr, Qt::WidgetShortcut), &QShortcut::activated, this,
-	        &AnimeListPage::ItemDoubleClicked);
+			&AnimeListPage::ItemDoubleClicked);
 
 	connect(new QShortcut(Qt::Key_Enter, tree_view, nullptr, nullptr, Qt::WidgetShortcut), &QShortcut::activated, this,
-	        &AnimeListPage::ItemDoubleClicked);
+			&AnimeListPage::ItemDoubleClicked);
 
 	tree_view->header()->setStretchLastSection(false);
 	tree_view->header()->setContextMenuPolicy(Qt::CustomContextMenu);