-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgpplayer_conf.c
116 lines (83 loc) · 2.23 KB
/
gpplayer_conf.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
//SPDX-License-Identifier: GPL-2.0-or-later
/*
Copyright (C) 2007-2024 Cyril Hrubis <[email protected]>
*/
#include <string.h>
#include <utils/gp_json_serdes.h>
#include <utils/gp_app_cfg.h>
#include <utils/gp_path.h>
#include <widgets/gp_app_info.h>
#include "audio_decoder.h"
#include "gpplayer_conf.h"
static struct gpplayer_conf conf = {
.softvol = 100,
};
const struct gpplayer_conf *gpplayer_conf = &conf;
static gp_json_struct conf_desc[] = {
GP_JSON_SERDES_STR_CPY(struct gpplayer_conf, decoder, 0, sizeof(conf.decoder)),
GP_JSON_SERDES_STR_DUP(struct gpplayer_conf, last_dialog_path, 0, SIZE_MAX),
GP_JSON_SERDES_BOOL(struct gpplayer_conf, playlist_repeat, 0),
GP_JSON_SERDES_BOOL(struct gpplayer_conf, playlist_shuffle, 0),
GP_JSON_SERDES_UINT8(struct gpplayer_conf, softvol, 0, 0, AUDIO_DECODER_SOFTVOL_MAX),
{}
};
void gpplayer_conf_load(void)
{
char *conf_path;
conf_path = gp_app_cfg_path(gp_app_info_name(), "config.json");
if (!conf_path)
return;
gp_json_load_struct(conf_path, conf_desc, &conf);
free(conf_path);
}
void gpplayer_conf_save(void)
{
char *conf_path;
if (!conf.dirty)
return;
if (gp_app_cfg_mkpath(gp_app_info_name()))
return;
conf_path = gp_app_cfg_path(gp_app_info_name(), "config.json");
if (!conf_path)
return;
gp_json_save_struct(conf_path, conf_desc, &conf);
free(conf_path);
conf.dirty = 0;
}
void gpplayer_conf_decoder_set(const char *decoder)
{
conf.dirty = 1;
strncpy(conf.decoder, decoder, sizeof(conf.decoder)-1);
}
void gpplayer_conf_softvol_set(uint8_t softvol)
{
if (softvol > AUDIO_DECODER_SOFTVOL_MAX)
softvol = AUDIO_DECODER_SOFTVOL_MAX;
if (softvol == conf.softvol)
return;
conf.softvol = softvol;
conf.dirty = 1;
}
void gpplayer_conf_last_dialog_path_set(const char *path)
{
char *new_path = gp_dirname(path);
if (!new_path)
return;
free(conf.last_dialog_path);
conf.last_dialog_path = new_path;
conf.dirty = 1;
}
void gpplayer_conf_playlist_repeat_set(bool val)
{
if (conf.playlist_repeat == val)
return;
conf.playlist_repeat = val;
conf.dirty = 1;
}
void gpplayer_conf_playlist_shuffle_set(bool val)
{
if (conf.playlist_shuffle == val)
return;
conf.playlist_shuffle = val;
conf.dirty = 1;
}