diff src/core/config.cc @ 147:6fdf0632c003

track: use a bit of a more sane way to manage recognition it also works with the new animia API
author Paper <mrpapersonic@gmail.com>
date Tue, 14 Nov 2023 13:19:40 -0500
parents 0a458cb26ff4
children e41505d24733
line wrap: on
line diff
--- a/src/core/config.cc	Mon Nov 13 13:52:58 2023 -0500
+++ b/src/core/config.cc	Tue Nov 14 13:19:40 2023 -0500
@@ -10,6 +10,9 @@
 #include "core/json.h"
 #include "gui/translate/anime.h"
 #include "gui/translate/config.h"
+
+#include "animia/player.h"
+
 #include <algorithm>
 #include <cstdlib>
 #include <cstring>
@@ -17,6 +20,9 @@
 #include <fstream>
 #include <limits.h>
 
+#include <QFile>
+#include <QTextStream>
+
 /* I'll use an INI-based config file instead of using an
    XML file like Taiga. */
 
@@ -42,6 +48,29 @@
 
 	recognition.detect_media_players = INI::GetIniValue<bool>(ini, "Recognition", "Detect media players", true);
 
+	/* lots of dumb logic to import the player data */
+	{
+		/* load the player data */
+		QFile f(":/players.anisthesia");
+		if (!f.exists())
+			return false;
+
+		f.open(QFile::ReadOnly | QFile::Text);
+		QTextStream ts(&f);
+
+		std::vector<animia::Player> players;
+
+		if (!animia::ParsePlayersData(Strings::ToUtf8String(ts.readAll()), players))
+			return false;
+
+		recognition.players.reserve(players.size());
+		for (const auto& player : players)
+			recognition.players.push_back({true, player});
+	}
+
+	for (auto& player : recognition.players)
+		player.first = INI::GetIniValue<bool>(ini, "Recognition/Players", player.second.name, true);
+
 	/* ew */
 	locale.SetActiveLocale(QLocale(Strings::ToQString(INI::GetIniValue<std::string>(ini, "General", "Locale", "en_US"))));
 
@@ -75,6 +104,9 @@
 
 	INI::SetIniValue(ini, "Recognition", "Detect media players", recognition.detect_media_players);
 
+	for (const auto& player : recognition.players)
+		INI::SetIniValue(ini, "Recognition/Players", player.second.name, player.first);
+
 	file.write(ini);
 
 	return 0;