diff options
Diffstat (limited to 'apps/plugins/mpegplayer/mpeg_settings.c')
-rw-r--r-- | apps/plugins/mpegplayer/mpeg_settings.c | 118 |
1 files changed, 118 insertions, 0 deletions
diff --git a/apps/plugins/mpegplayer/mpeg_settings.c b/apps/plugins/mpegplayer/mpeg_settings.c new file mode 100644 index 0000000000..dc63626c10 --- /dev/null +++ b/apps/plugins/mpegplayer/mpeg_settings.c | |||
@@ -0,0 +1,118 @@ | |||
1 | #include "plugin.h" | ||
2 | #include "lib/configfile.h" | ||
3 | |||
4 | #include "mpeg_settings.h" | ||
5 | |||
6 | extern struct plugin_api* rb; | ||
7 | |||
8 | struct mpeg_settings settings; | ||
9 | static struct mpeg_settings old_settings; | ||
10 | |||
11 | #define SETTINGS_VERSION 1 | ||
12 | #define SETTINGS_MIN_VERSION 1 | ||
13 | #define SETTINGS_FILENAME "mpegplayer.cfg" | ||
14 | |||
15 | static char* showfps_options[] = {"No", "Yes"}; | ||
16 | static char* limitfps_options[] = {"No", "Yes"}; | ||
17 | static char* skipframes_options[] = {"No", "Yes"}; | ||
18 | |||
19 | static struct configdata config[] = | ||
20 | { | ||
21 | {TYPE_ENUM, 0, 2, &settings.showfps, "Show FPS", showfps_options, NULL}, | ||
22 | {TYPE_ENUM, 0, 2, &settings.limitfps, "Limit FPS", limitfps_options, NULL}, | ||
23 | {TYPE_ENUM, 0, 2, &settings.skipframes, "Skip frames", skipframes_options, NULL}, | ||
24 | }; | ||
25 | |||
26 | bool mpeg_menu(void) | ||
27 | { | ||
28 | int m; | ||
29 | int result; | ||
30 | int menu_quit=0; | ||
31 | |||
32 | static const struct opt_items noyes[2] = { | ||
33 | { "No", -1 }, | ||
34 | { "Yes", -1 }, | ||
35 | }; | ||
36 | |||
37 | static const struct menu_item items[] = { | ||
38 | { "Display FPS", NULL }, | ||
39 | { "Limit FPS", NULL }, | ||
40 | { "Skip frames", NULL }, | ||
41 | { "Quit mpegplayer", NULL }, | ||
42 | }; | ||
43 | |||
44 | m = rb->menu_init(items, sizeof(items) / sizeof(*items), | ||
45 | NULL, NULL, NULL, NULL); | ||
46 | |||
47 | rb->button_clear_queue(); | ||
48 | |||
49 | while (!menu_quit) { | ||
50 | result=rb->menu_show(m); | ||
51 | |||
52 | switch(result) | ||
53 | { | ||
54 | case 0: /* Show FPS */ | ||
55 | rb->set_option("Display FPS",&settings.showfps,INT, | ||
56 | noyes, 2, NULL); | ||
57 | break; | ||
58 | case 1: /* Limit FPS */ | ||
59 | rb->set_option("Limit FPS",&settings.limitfps,INT, | ||
60 | noyes, 2, NULL); | ||
61 | break; | ||
62 | case 2: /* Skip frames */ | ||
63 | rb->set_option("Skip frames",&settings.skipframes,INT, | ||
64 | noyes, 2, NULL); | ||
65 | break; | ||
66 | default: | ||
67 | menu_quit=1; | ||
68 | break; | ||
69 | } | ||
70 | } | ||
71 | |||
72 | rb->menu_exit(m); | ||
73 | |||
74 | rb->lcd_clear_display(); | ||
75 | rb->lcd_update(); | ||
76 | |||
77 | return (result==3); | ||
78 | } | ||
79 | |||
80 | |||
81 | void init_settings(void) | ||
82 | { | ||
83 | /* Set the default settings */ | ||
84 | settings.showfps = 0; /* Do not show FPS */ | ||
85 | settings.limitfps = 0; /* Do not limit FPS */ | ||
86 | settings.skipframes = 0; /* Do not skip frames */ | ||
87 | |||
88 | configfile_init(rb); | ||
89 | |||
90 | if (configfile_load(SETTINGS_FILENAME, config, | ||
91 | sizeof(config)/sizeof(*config), | ||
92 | SETTINGS_MIN_VERSION | ||
93 | ) < 0) | ||
94 | { | ||
95 | /* If the loading failed, save a new config file (as the disk is | ||
96 | already spinning) */ | ||
97 | configfile_save(SETTINGS_FILENAME, config, | ||
98 | sizeof(config)/sizeof(*config), | ||
99 | SETTINGS_VERSION); | ||
100 | } | ||
101 | |||
102 | /* Keep a copy of the saved version of the settings - so we can check if | ||
103 | the settings have changed when we quit */ | ||
104 | old_settings = settings; | ||
105 | } | ||
106 | |||
107 | void save_settings(void) | ||
108 | { | ||
109 | /* Save the user settings if they have changed */ | ||
110 | if (rb->memcmp(&settings,&old_settings,sizeof(settings))!=0) { | ||
111 | configfile_save(SETTINGS_FILENAME, config, | ||
112 | sizeof(config)/sizeof(*config), | ||
113 | SETTINGS_VERSION); | ||
114 | |||
115 | /* Store the settings in old_settings - to check for future changes */ | ||
116 | old_settings = settings; | ||
117 | } | ||
118 | } | ||