diff src/library/library.cc @ 366:886f66775f31

animone: add preliminary AT-SPI stuff anime_list: finish the regular singular right click menu
author Paper <paper@tflc.us>
date Sun, 17 Nov 2024 19:56:01 -0500
parents a0aa8c8c4307
children
line wrap: on
line diff
--- a/src/library/library.cc	Wed Oct 02 23:06:43 2024 -0400
+++ b/src/library/library.cc	Sun Nov 17 19:56:01 2024 -0500
@@ -13,7 +13,31 @@
 
 namespace Library {
 
-void Database::Refresh() {
+std::optional<std::filesystem::path> Database::GetAnimeFolder(int id) {
+	// this function sucks, but it's the most I can really do for now.
+	//
+	// in the future the Refresh() function should look for directories
+	// as well that fit the anime name and *also* have episodes in them.
+	// it should give each of these directories a rating by how many
+	// episodes are contained in them. whichever directory has more episodes
+	// wins, or the first found if there is an equal amount.
+
+	for (const auto& [anime_id, episodes] : items) {
+		if (id != anime_id)
+			continue;
+
+		for (const auto& [episode, path] : episodes) {
+			return path.parent_path();
+			break;
+		}
+
+		break;
+	}
+
+	return std::nullopt;
+}
+
+void Database::Refresh(std::optional<int> find_id) {
 	items.clear();
 
 	for (const auto& folder : session.config.library.paths) {
@@ -32,7 +56,7 @@
 			const std::string title = Strings::ToUtf8String(elements.get(anitomy::kElementAnimeTitle));
 
 			const int id = Anime::db.LookupAnimeTitle(title);
-			if (id <= 0)
+			if (id <= 0 || (find_id && find_id.value() != id))
 				continue;
 
 			const int episode = Strings::ToInt<int>(Strings::ToUtf8String(elements.get(anitomy::kElementEpisodeNumber)));
@@ -43,6 +67,16 @@
 	}
 }
 
+void Database::Refresh() {
+	Refresh(std::nullopt);
+}
+
+void Database::Refresh(int id) {
+	Refresh(std::optional<int>(id));
+}
+
+// TODO export to JSON
+
 Database db;
 
 } // namespace Library