Mercurial > minori
annotate src/core/config.cc @ 137:69db40272acd
dep/animia: [WIP] huge refactor
this WILL NOT compile, because lots of code has been changed
and every API in the original codebase has been removed.
note that this api setup is not exactly permanent...
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Fri, 10 Nov 2023 13:52:47 -0500 |
parents | 0a458cb26ff4 |
children | 6fdf0632c003 |
rev | line source |
---|---|
9 | 1 /** |
2 * config.cpp: | |
3 * parses the config... lol | |
4 **/ | |
5 #include "core/config.h" | |
101
c537996cf67b
*: multitude of config changes
Paper <mrpapersonic@gmail.com>
parents:
90
diff
changeset
|
6 #include "core/strings.h" |
9 | 7 #include "core/anime.h" |
102 | 8 #include "core/ini.h" |
9 | 9 #include "core/filesystem.h" |
10 #include "core/json.h" | |
90
c4bb49c2f6eb
config: improve handling of vars
Paper <mrpapersonic@gmail.com>
parents:
81
diff
changeset
|
11 #include "gui/translate/anime.h" |
c4bb49c2f6eb
config: improve handling of vars
Paper <mrpapersonic@gmail.com>
parents:
81
diff
changeset
|
12 #include "gui/translate/config.h" |
101
c537996cf67b
*: multitude of config changes
Paper <mrpapersonic@gmail.com>
parents:
90
diff
changeset
|
13 #include <algorithm> |
9 | 14 #include <cstdlib> |
15 #include <cstring> | |
16 #include <filesystem> | |
17 #include <fstream> | |
18 #include <limits.h> | |
19 | |
120 | 20 /* I'll use an INI-based config file instead of using an |
21 XML file like Taiga. */ | |
22 | |
9 | 23 int Config::Load() { |
135
0a458cb26ff4
filesystem: move to using std::filesystem after C++17 switch
Paper <mrpapersonic@gmail.com>
parents:
120
diff
changeset
|
24 std::filesystem::path cfg_path = Filesystem::GetConfigPath(); |
102 | 25 |
135
0a458cb26ff4
filesystem: move to using std::filesystem after C++17 switch
Paper <mrpapersonic@gmail.com>
parents:
120
diff
changeset
|
26 mINI::INIFile file(cfg_path.string()); |
101
c537996cf67b
*: multitude of config changes
Paper <mrpapersonic@gmail.com>
parents:
90
diff
changeset
|
27 mINI::INIStructure ini; |
c537996cf67b
*: multitude of config changes
Paper <mrpapersonic@gmail.com>
parents:
90
diff
changeset
|
28 file.read(ini); |
c537996cf67b
*: multitude of config changes
Paper <mrpapersonic@gmail.com>
parents:
90
diff
changeset
|
29 |
120 | 30 service = Translate::ToService(INI::GetIniValue<std::string>(ini, "General", "Service", "None")); |
31 | |
32 anime_list.language = Translate::ToLanguage(INI::GetIniValue<std::string>(ini, "Anime List", "Title language", "Romaji")); | |
33 anime_list.display_aired_episodes = INI::GetIniValue<bool>(ini, "Anime List", "Display only aired episodes", true); | |
34 anime_list.display_available_episodes = INI::GetIniValue<bool>(ini, "Anime List", "Display only available episodes in library", true); | |
35 anime_list.highlight_anime_if_available = INI::GetIniValue<bool>(ini, "Anime List", "Highlight anime if available", true); | |
36 anime_list.highlighted_anime_above_others = INI::GetIniValue<bool>(ini, "Anime List", "Display highlighted anime above others", false); | |
116
254b1d2b7096
settings: add torrents page, make rss feed configurable
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
37 |
120 | 38 auth.anilist.auth_token = INI::GetIniValue<std::string>(ini, "Authentication/AniList", "Auth Token", ""); |
39 auth.anilist.user_id = INI::GetIniValue<int>(ini, "Authentication/AniList", "User ID", 0); | |
40 | |
41 torrents.feed_link = INI::GetIniValue<std::string>(ini, "Torrents", "RSS feed", "https://www.tokyotosho.info/rss.php?filter=1,11&zwnj=0"); | |
116
254b1d2b7096
settings: add torrents page, make rss feed configurable
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
42 |
135
0a458cb26ff4
filesystem: move to using std::filesystem after C++17 switch
Paper <mrpapersonic@gmail.com>
parents:
120
diff
changeset
|
43 recognition.detect_media_players = INI::GetIniValue<bool>(ini, "Recognition", "Detect media players", true); |
0a458cb26ff4
filesystem: move to using std::filesystem after C++17 switch
Paper <mrpapersonic@gmail.com>
parents:
120
diff
changeset
|
44 |
120 | 45 /* ew */ |
46 locale.SetActiveLocale(QLocale(Strings::ToQString(INI::GetIniValue<std::string>(ini, "General", "Locale", "en_US")))); | |
116
254b1d2b7096
settings: add torrents page, make rss feed configurable
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
47 |
120 | 48 theme.SetTheme(Translate::ToTheme(INI::GetIniValue<std::string>(ini, "Appearance", "Theme", "Default"))); |
101
c537996cf67b
*: multitude of config changes
Paper <mrpapersonic@gmail.com>
parents:
90
diff
changeset
|
49 |
9 | 50 return 0; |
51 } | |
52 | |
118
39521c47c7a3
*: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents:
116
diff
changeset
|
53 int Config::Save() const { |
135
0a458cb26ff4
filesystem: move to using std::filesystem after C++17 switch
Paper <mrpapersonic@gmail.com>
parents:
120
diff
changeset
|
54 std::filesystem::path cfg_path = Filesystem::GetConfigPath(); |
0a458cb26ff4
filesystem: move to using std::filesystem after C++17 switch
Paper <mrpapersonic@gmail.com>
parents:
120
diff
changeset
|
55 Filesystem::CreateDirectories(cfg_path); |
101
c537996cf67b
*: multitude of config changes
Paper <mrpapersonic@gmail.com>
parents:
90
diff
changeset
|
56 |
135
0a458cb26ff4
filesystem: move to using std::filesystem after C++17 switch
Paper <mrpapersonic@gmail.com>
parents:
120
diff
changeset
|
57 mINI::INIFile file(cfg_path.string()); |
101
c537996cf67b
*: multitude of config changes
Paper <mrpapersonic@gmail.com>
parents:
90
diff
changeset
|
58 mINI::INIStructure ini; |
c537996cf67b
*: multitude of config changes
Paper <mrpapersonic@gmail.com>
parents:
90
diff
changeset
|
59 |
120 | 60 INI::SetIniValue(ini, "General", "Service", service); |
61 INI::SetIniValue(ini, "General", "Locale", locale.GetLocale().name()); | |
62 | |
63 INI::SetIniValue(ini, "Anime List", "Title language", anime_list.language); | |
64 INI::SetIniValue(ini, "Anime List", "Display only aired episodes", anime_list.display_aired_episodes); | |
65 INI::SetIniValue(ini, "Anime List", "Display only available episodes in library", anime_list.display_available_episodes); | |
66 INI::SetIniValue(ini, "Anime List", "Highlight anime if available", anime_list.highlight_anime_if_available); | |
67 INI::SetIniValue(ini, "Anime List", "Display highlighted anime above others", anime_list.highlighted_anime_above_others); | |
68 | |
69 INI::SetIniValue(ini, "Authentication/AniList", "Auth Token", auth.anilist.auth_token); | |
70 INI::SetIniValue(ini, "Authentication/AniList", "User ID", auth.anilist.user_id); | |
71 | |
72 INI::SetIniValue(ini, "Appearance", "Theme", theme.GetTheme()); | |
73 | |
74 INI::SetIniValue(ini, "Torrents", "RSS feed", torrents.feed_link); | |
75 | |
76 INI::SetIniValue(ini, "Recognition", "Detect media players", recognition.detect_media_players); | |
101
c537996cf67b
*: multitude of config changes
Paper <mrpapersonic@gmail.com>
parents:
90
diff
changeset
|
77 |
102 | 78 file.write(ini); |
101
c537996cf67b
*: multitude of config changes
Paper <mrpapersonic@gmail.com>
parents:
90
diff
changeset
|
79 |
9 | 80 return 0; |
81 } |