changeset 52:0c4138de2ea7

anime list: we are finally read-write
author Paper <mrpapersonic@gmail.com>
date Mon, 25 Sep 2023 22:49:42 -0400
parents 75c804f713b2
children a6e51a03112e
files include/services/services.h src/gui/dialog/about.cpp src/gui/pages/anime_list.cpp src/services/anilist.cpp src/services/services.cpp
diffstat 5 files changed, 23 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/include/services/services.h	Mon Sep 25 20:29:26 2023 -0400
+++ b/include/services/services.h	Mon Sep 25 22:49:42 2023 -0400
@@ -4,6 +4,7 @@
 namespace Services {
 
 void Synchronize();
+void UpdateAnimeEntry(int id);
 bool Authorize();
 
 }; // namespace Services
--- a/src/gui/dialog/about.cpp	Mon Sep 25 20:29:26 2023 -0400
+++ b/src/gui/dialog/about.cpp	Mon Sep 25 22:49:42 2023 -0400
@@ -74,6 +74,9 @@
 	QTextCharFormat format;
 	QTextBrowser* paragraph = new QTextBrowser(this);
 	paragraph->setOpenExternalLinks(true);
+	paragraph->setFrameShape(QFrame::NoFrame);
+	paragraph->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+	paragraph->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
 	QTextCursor cursor = paragraph->textCursor();
 	SET_TITLE_FONT(font, format, cursor);
 	SET_FONT_BOLD(font, format, cursor);
--- a/src/gui/pages/anime_list.cpp	Mon Sep 25 20:29:26 2023 -0400
+++ b/src/gui/pages/anime_list.cpp	Mon Sep 25 22:49:42 2023 -0400
@@ -16,7 +16,7 @@
 #include "core/time.h"
 #include "gui/dialog/information.h"
 #include "gui/translate/anime.h"
-#include "services/anilist.h"
+#include "services/services.h"
 #include <QDebug>
 #include <QHBoxLayout>
 #include <QHeaderView>
@@ -315,7 +315,8 @@
 			return;
 		}
 
-		InformationDialog* dialog = new InformationDialog(*anime, [this] {
+		InformationDialog* dialog = new InformationDialog(*anime, [this, anime] {
+			Services::UpdateAnimeEntry(anime->GetId());
 		    Refresh();
 	    }, this);
 
@@ -339,7 +340,8 @@
 	Anime::Anime* anime =
 	    ((AnimeListWidgetModel*)sort_models[tab_bar->currentIndex()]->sourceModel())->GetAnimeFromIndex(index);
 
-	InformationDialog* dialog = new InformationDialog(*anime, [this] {
+	InformationDialog* dialog = new InformationDialog(*anime, [this, anime] {
+		Services::UpdateAnimeEntry(anime->GetId());
 		Refresh();
 	}, this);
 
--- a/src/services/anilist.cpp	Mon Sep 25 20:29:26 2023 -0400
+++ b/src/services/anilist.cpp	Mon Sep 25 22:49:42 2023 -0400
@@ -8,6 +8,7 @@
 #include "gui/translate/anilist.h"
 #include <QDesktopServices>
 #include <QInputDialog>
+#include <QDebug>
 #include <QLineEdit>
 #include <QMessageBox>
 #include <QUrl>
@@ -260,7 +261,7 @@
 	return 1;
 }
 
-int UpdateAnimeEntry(const Anime::Anime& anime) {
+int UpdateAnimeEntry(int id) {
 	/**
 	 * possible values:
 	 *
@@ -280,11 +281,9 @@
 	 * Date startedAt,
 	 * Date completedAt
 	 **/
-	const std::string query = "mutation ($media_id: Int, $progress: Int, $status: MediaListStatus, "
-	                          "$score: Int, $notes: String) {\n"
-	                          "  SaveMediaListEntry (mediaId: $media_id, progress: $progress, "
-	                          "status: $status, scoreRaw: $score, notes: "
-	                          "$notes) {\n"
+	Anime::Anime& anime = Anime::db.items[id];
+	const std::string query = "mutation ($media_id: Int, $progress: Int, $status: MediaListStatus, $score: Int, $notes: String) {\n"
+	                          "  SaveMediaListEntry (mediaId: $media_id, progress: $progress, status: $status, scoreRaw: $score, notes: $notes) {\n"
 	                          "    id\n"
 	                          "  }\n"
 	                          "}\n";
@@ -300,8 +299,8 @@
 		}}
 	};
 	// clang-format on
-	SendRequest(json.dump());
-	return 1;
+	auto ret = nlohmann::json::parse(SendRequest(json.dump()));
+	return JSON::GetInt(ret, "/data/SaveMediaListEntry/id"_json_pointer);
 }
 
 int ParseUser(const nlohmann::json& json) {
--- a/src/services/services.cpp	Mon Sep 25 20:29:26 2023 -0400
+++ b/src/services/services.cpp	Mon Sep 25 22:49:42 2023 -0400
@@ -25,6 +25,13 @@
 	}
 }
 
+void UpdateAnimeEntry(int id) {
+	switch (session.config.service) {
+		case Anime::Services::ANILIST: AniList::UpdateAnimeEntry(id); break;
+		default: break;
+	}
+}
+
 bool Authorize() {
 	switch (session.config.service) {
 		case Anime::Services::ANILIST: