Atlas Game Manager
A game manager for f95 and dlsite written in c++
Loading...
Searching...
No Matches
config.hpp
Go to the documentation of this file.
1//
2// Created by kj16609 on 1/12/23.
3//
4
5#pragma once
6#ifndef ATLAS_CONFIG_HPP
7#define ATLAS_CONFIG_HPP
8
9#include <QObject>
10#include <QSettings>
11#include <QVariant>
12
13#include <filesystem>
14
16#include "core/exceptions.hpp"
19
20#ifdef __GNUC__
21#pragma GCC diagnostic push
22#pragma GCC diagnostic ignored "-Wsign-promo"
23#endif
24
25//TODO: Add cache
26inline QSettings getSettingsObject()
27{
28 return { "./data/config.ini", QSettings::IniFormat };
29}
30
31#define STR( val ) #val
32#define KEY_VALUE( group, name ) STR( group ) "/" STR( name )
33
34#define SETTINGS_D( group, name, type, default_value ) \
35 namespace config::group::name \
36 { \
37 inline void set( const type& val ) \
38 { \
39 getSettingsObject().setValue( KEY_VALUE( group, name ), val ); \
40 } \
41 \
42 inline void setDefault() \
43 { \
44 set( default_value ); \
45 } \
46 \
47 inline type get() \
48 { \
49 if ( !getSettingsObject().contains( KEY_VALUE( group, name ) ) ) setDefault(); \
50 \
51 if ( const auto settings_obj = getSettingsObject().value( KEY_VALUE( group, name ) ); \
52 settings_obj.canConvert< type >() ) \
53 return settings_obj.value< type >(); \
54 else \
55 throw SettingsException( "Failed to convert key " KEY_VALUE( group, name ) " to desired type" ); \
56 } \
57 }
58
59#define SETTINGS_PATH( group, name, default_path ) \
60 SETTINGS_D( group, name, QString, default_path ) \
61 namespace config::group::name \
62 { \
63 inline std::filesystem::path getPath() \
64 { \
65 const std::filesystem::path filepath { group::name::get().toStdString() }; \
66 std::filesystem::create_directories( filepath ); \
67 return std::filesystem::canonical( filepath ); \
68 } \
69 \
70 inline void setPath( const std::filesystem::path path ) \
71 { \
72 group::name::set( QString::fromStdString( path.string() ) ); \
73 } \
74 }
75
76#define SETTINGS_FILE( group, name, default_path ) \
77 SETTINGS_D( group, name, QString, default_path ) \
78 namespace config::group::name \
79 { \
80 inline std::filesystem::path getPath() \
81 { \
82 const std::filesystem::path filepath { group::name::get().toStdString() }; \
83 std::filesystem::create_directories( filepath.parent_path() ); \
84 return std::filesystem::canonical( filepath ); \
85 } \
86 \
87 inline void setPath( const std::filesystem::path path ) \
88 { \
89 group::name::set( QString::fromStdString( path.string() ) ); \
90 } \
91 }
92
93#define SETTINGS( group, name, type ) \
94 namespace config::group::name \
95 { \
96 inline bool hasValue() \
97 { \
98 return getSettingsObject().contains( KEY_VALUE( group, name ) ); \
99 } \
100 \
101 inline type get() \
102 { \
103 return { getSettingsObject().value( KEY_VALUE( group, name ) ).value< type >() }; \
104 } \
105 \
106 inline void set( const type val ) \
107 { \
108 getSettingsObject().setValue( KEY_VALUE( group, name ), val ); \
109 } \
110 }
111
112#define SETTINGS_DE( group, name, type, default_value ) \
113 namespace config::group::name \
114 { \
115 namespace de_internal \
116 { \
117 inline void set( const int& val ) \
118 { \
119 getSettingsObject().setValue( KEY_VALUE( group, name ), val ); \
120 } \
121 \
122 inline void setDefault() \
123 { \
124 set( static_cast< int >( default_value ) ); \
125 } \
126 \
127 inline int get() \
128 { \
129 if ( !getSettingsObject().contains( KEY_VALUE( group, name ) ) ) setDefault(); \
130 \
131 if ( const auto settings_obj = getSettingsObject().value( KEY_VALUE( group, name ) ); \
132 settings_obj.canConvert< int >() ) \
133 return settings_obj.value< int >(); \
134 else \
135 throw SettingsException( "Failed to convert key " KEY_VALUE( group, name ) " to desired type" ); \
136 } \
137 \
138 SETTINGS_D( group, name, int, default_value ) \
139 } \
140 \
141 inline type get() \
142 { \
143 return static_cast< type >( de_internal::get() ); \
144 } \
145 \
146 inline void set( const type val ) \
147 { \
148 de_internal::set( static_cast< int >( val ) ); \
149 } \
150 }
151
152#define SETTINGS_GEO( name ) \
153 namespace config::geometry::name \
154 { \
155 inline bool hasValue() \
156 { \
157 return getSettingsObject().contains( KEY_VALUE( geometry, name ) ); \
158 } \
159 \
160 inline QByteArray get() \
161 { \
162 return { getSettingsObject().value( KEY_VALUE( geometry, name ) ).toByteArray() }; \
163 } \
164 \
165 inline void set( const QByteArray val ) \
166 { \
167 getSettingsObject().setValue( KEY_VALUE( geometry, name ), val ); \
168 } \
169 }
170
171#define SETTINGS_STATE( name ) \
172 namespace config::state::name \
173 { \
174 inline bool hasValue() \
175 { \
176 return getSettingsObject().contains( KEY_VALUE( state, name ) ); \
177 } \
178 \
179 inline QByteArray get() \
180 { \
181 return getSettingsObject().value( KEY_VALUE( state, name ) ).toByteArray(); \
182 } \
183 \
184 inline void set( const QByteArray val ) \
185 { \
186 getSettingsObject().setValue( KEY_VALUE( state, name ), val ); \
187 } \
188 }
189
190#define CONFIG_ATTACH_THIS \
191 connect( \
192 &( config::internal::getNotifier() ), \
193 &config::ConfigNotification::notification, \
194 this, \
195 &std::remove_pointer_t< decltype( this ) >::reloadConfig )
196
197SETTINGS_PATH( paths, database, "./data" )
198SETTINGS_PATH( paths, images, "./data/images" )
199SETTINGS_PATH( paths, games, "./data/games" )
200SETTINGS_FILE( paths, theme, "./themes/dark.qss" )
201
202SETTINGS_D( importer, pathparse, QString, "{creator}/{title}/{version}" )
203SETTINGS_D( importer, skipFilesize, bool, false )
204SETTINGS_D( importer, searchGameInfo, bool, true )
205SETTINGS_D( importer, downloadBanner, bool, false )
206SETTINGS_D( importer, downloadVNDB, bool, false )
207SETTINGS_D( importer, moveImported, bool, true )
208
209SETTINGS_D( logging, level, int, 2 )
210
211SETTINGS_GEO( main_window )
212SETTINGS_GEO( batch_import_dialog )
213
214SETTINGS_STATE( main_window )
215
216SETTINGS_D( ui, use_system_theme, bool, false )
217
218enum SCALE_TYPE : int
219{
220 IGNORE_ASPECT_RATIO = Qt::IgnoreAspectRatio,
221 KEEP_ASPECT_RATIO = Qt::KeepAspectRatio,
222 KEEP_ASPECT_RATIO_BY_EXPANDING = Qt::KeepAspectRatioByExpanding,
223 FIT_BLUR_EXPANDING = 3, //TODO: Remove due to confusion
224 FIT_BLUR_STRETCH = 4 //TODO: Remove due to confusion
225};
226
227enum BLUR_TYPE : int
228{
232};
233
243
245{
246 Error = -1,
248 Wide = 1,
249 Cover = 2,
250 Logo = 3,
251 SENTINEL // Used to determine the number of banner types
252};
253
255{
256 MASK_NORMAL = 1 << 0,
257 MASK_WIDE = 1 << 1,
258 MASK_COVER = 1 << 2,
259 MASK_LOGO = 1 << 3,
260};
261
262SETTINGS_DE( grid_ui, imageLayout, SCALE_TYPE, KEEP_ASPECT_RATIO ) // Default is keep aspect ratio
263SETTINGS_DE( grid_ui, blurType, BLUR_TYPE, FEATHER_IMAGE )
264SETTINGS_D( grid_ui, blurRadius, int, 30 )
265SETTINGS_D( grid_ui, featherRadius, int, 30 )
266SETTINGS_D( grid_ui, bannerSizeX, int, 537 )
267SETTINGS_D( grid_ui, bannerSizeY, int, 251 )
268SETTINGS_D( grid_ui, bannerSpacing, int, 5 )
269SETTINGS_D( grid_ui, selectedColor, QString, "0,0,255" )
270SETTINGS_D( grid_ui, selectedOpacity, int, 50 )
271SETTINGS_D( grid_ui, enableCapsuleBorder, bool, true )
272SETTINGS_D( grid_ui, borderColor, QString, "180,180,180" )
273
274SETTINGS_D( grid_ui, enableTopOverlay, bool, true )
275SETTINGS_D( grid_ui, enableBottomOverlay, bool, true )
276SETTINGS_D( grid_ui, overlayHeight, int, 26 )
277SETTINGS_D( grid_ui, overlayOpacity, int, 200 )
278SETTINGS_D( grid_ui, overlayColor, QString, "0,0,0" )
279SETTINGS_D( grid_ui, font, QString, "" )
280SETTINGS_D( grid_ui, fontSize, int, 10 )
281SETTINGS_D( grid_ui, windowHeight, int, 780 )
282SETTINGS_D( grid_ui, windowWidth, int, 1520 )
283SETTINGS_D( grid_ui, itemViewWidth, int, 1266 )
284SETTINGS_D( grid_ui, itemViewHeight, int, 694 )
285
296
297SETTINGS_DE( grid_ui, titleLocation, LOCATION, BOTTOM_CENTER ) //0:none, 1:top, 2:bottom
298SETTINGS_DE( grid_ui, engineLocation, LOCATION, BOTTOM_LEFT )
299SETTINGS_DE( grid_ui, versionLocation, LOCATION, BOTTOM_RIGHT )
300SETTINGS_DE( grid_ui, creatorLocation, LOCATION, TOP_LEFT )
301
302SETTINGS_D( grid_ui, favIconLocation, int, 0 )
303SETTINGS_D( grid_ui, gameIconLocation, int, 0 )
304SETTINGS_D( grid_ui, ratingIconLocation, int, 0 )
305SETTINGS_D( grid_ui, downloadIconLocation, int, 0 )
306SETTINGS_D( grid_ui, engineIconLocation, int, 0 )
307
308SETTINGS_D( grid_ui, showFavIcon, bool, false )
309SETTINGS_D( grid_ui, showGameIcon, bool, false )
310SETTINGS_D( grid_ui, showRatingIcon, bool, false )
311SETTINGS_D( grid_ui, showDownloadIcon, bool, false )
312SETTINGS_D( grid_ui, showEngineIcon, bool, false )
313SETTINGS_D( grid_ui, centerWidgets, bool, false )
314
315SETTINGS_D( ui, stretch_banner_images, bool, false )
316SETTINGS_D( ui, use_simple_layout, bool, true )
317
318SETTINGS_D( application, font, QString, "" )
319SETTINGS_D( application, fontSize, int, 10 )
320SETTINGS_FILE( application, theme_folder, "./themes" )
321SETTINGS_D( application, update_channel, QString, "stable" )
322
323SETTINGS_D( remote, allow_checks, bool, false )
324SETTINGS_D( remote, last_check, int, 0 )
326 remote, check_rate, int, std::chrono::duration_cast< std::chrono::seconds >( std::chrono::hours( 24 ) ).count() )
327
328SETTINGS_D( threads, import_threads, int, 2 )
329SETTINGS_D( threads, image_import_threads, int, 4 )
330SETTINGS_D( threads, image_loader_threads, int, 2 )
331SETTINGS_D( threads, import_pre_loader_threads, int, 4 )
332
333SETTINGS_D( experimental, local_match, bool, false )
334SETTINGS_D( experimental, loading_preview, bool, false )
335SETTINGS_D( experimental, loading_preview_blur, int, 90 )
336SETTINGS_D( experimental, use_blurhash, bool, false )
337
338#ifdef __GNUC__
339#pragma GCC diagnostic pop
340#endif
341
342#endif //ATLAS_CONFIG_HPP
#define SETTINGS_DE(group, name, type, default_value)
Definition config.hpp:112
BannerMask
Definition config.hpp:255
@ MASK_COVER
Definition config.hpp:258
@ MASK_WIDE
Definition config.hpp:257
@ MASK_NORMAL
Definition config.hpp:256
@ MASK_LOGO
Definition config.hpp:259
PreviewType
Definition config.hpp:235
@ PREVIEW_PREVIEW
Definition config.hpp:238
@ PREVIEW_UNKNOWN
Definition config.hpp:236
@ PREVIEW_COVER
Definition config.hpp:240
@ PREVIEW_BANNER
Definition config.hpp:237
@ PREVIEW_LOGO
Definition config.hpp:241
@ PREVIEW_BANNER_WIDE
Definition config.hpp:239
BLUR_TYPE
Definition config.hpp:228
@ SQUARE
Definition config.hpp:231
@ FEATHER_IMAGE
Definition config.hpp:230
@ BACKGROUND_ONLY
Definition config.hpp:229
#define SETTINGS_D(group, name, type, default_value)
Definition config.hpp:34
QSettings getSettingsObject()
Definition config.hpp:26
LOCATION
Definition config.hpp:287
@ TOP_CENTER
Definition config.hpp:290
@ BOTTOM_RIGHT
Definition config.hpp:294
@ TOP_LEFT
Definition config.hpp:289
@ BOTTOM_LEFT
Definition config.hpp:292
@ BOTTOM_CENTER
Definition config.hpp:293
@ TOP_RIGHT
Definition config.hpp:291
@ NONE
Definition config.hpp:288
#define SETTINGS_GEO(name)
Definition config.hpp:152
#define SETTINGS_STATE(name)
Definition config.hpp:171
SCALE_TYPE
Definition config.hpp:219
@ KEEP_ASPECT_RATIO_BY_EXPANDING
Definition config.hpp:222
@ IGNORE_ASPECT_RATIO
Definition config.hpp:220
@ KEEP_ASPECT_RATIO
Definition config.hpp:221
@ FIT_BLUR_STRETCH
Definition config.hpp:224
@ FIT_BLUR_EXPANDING
Definition config.hpp:223
BannerType
Definition config.hpp:245
@ Logo
Definition config.hpp:250
@ Error
Definition config.hpp:246
@ Normal
Definition config.hpp:247
@ SENTINEL
Definition config.hpp:251
@ Wide
Definition config.hpp:248
@ Cover
Definition config.hpp:249
#define SETTINGS_PATH(group, name, default_path)
Definition config.hpp:59
#define SETTINGS_FILE(group, name, default_path)
Definition config.hpp:76
Definition parser.hpp:12