annotate src/dialog/dlg_config.c @ 12:dd427b7cc459 default tip

json: replace with nxjson library more lightweight, reduces the binary size by about 40 kb
author Paper <paper@paper.us.eu.org>
date Fri, 15 Mar 2024 20:46:18 -0400
parents e6a594f16403
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11
e6a594f16403 *: huge refactor
Paper <paper@paper.us.eu.org>
parents:
diff changeset
1 #include "dialog/dlg_config.h"
e6a594f16403 *: huge refactor
Paper <paper@paper.us.eu.org>
parents:
diff changeset
2 #include "config.h" /* global config */
e6a594f16403 *: huge refactor
Paper <paper@paper.us.eu.org>
parents:
diff changeset
3 #include "plugin.h" /* update_rich_presence_details() */
e6a594f16403 *: huge refactor
Paper <paper@paper.us.eu.org>
parents:
diff changeset
4 #include "resource.h" /* TITLE_CHECK, ... */
e6a594f16403 *: huge refactor
Paper <paper@paper.us.eu.org>
parents:
diff changeset
5
e6a594f16403 *: huge refactor
Paper <paper@paper.us.eu.org>
parents:
diff changeset
6 #include <winuser.h>
e6a594f16403 *: huge refactor
Paper <paper@paper.us.eu.org>
parents:
diff changeset
7
e6a594f16403 *: huge refactor
Paper <paper@paper.us.eu.org>
parents:
diff changeset
8 #define conf_item_to_dlg(hwnd, cons, var) \
e6a594f16403 *: huge refactor
Paper <paper@paper.us.eu.org>
parents:
diff changeset
9 do { \
e6a594f16403 *: huge refactor
Paper <paper@paper.us.eu.org>
parents:
diff changeset
10 HWND checkboxHwnd = GetDlgItem(hwnd, cons); \
e6a594f16403 *: huge refactor
Paper <paper@paper.us.eu.org>
parents:
diff changeset
11 SendMessage(checkboxHwnd, BM_SETCHECK, (var) ? BST_CHECKED : BST_UNCHECKED, 0); \
e6a594f16403 *: huge refactor
Paper <paper@paper.us.eu.org>
parents:
diff changeset
12 } while (0);
e6a594f16403 *: huge refactor
Paper <paper@paper.us.eu.org>
parents:
diff changeset
13 #define dlg_item_to_conf(hwnd, cons, var) \
e6a594f16403 *: huge refactor
Paper <paper@paper.us.eu.org>
parents:
diff changeset
14 do { \
e6a594f16403 *: huge refactor
Paper <paper@paper.us.eu.org>
parents:
diff changeset
15 HWND checkboxHwnd = GetDlgItem(hwnd, cons); \
e6a594f16403 *: huge refactor
Paper <paper@paper.us.eu.org>
parents:
diff changeset
16 (var) = (SendMessage(checkboxHwnd, BM_GETCHECK, 0, 0) == BST_CHECKED); \
e6a594f16403 *: huge refactor
Paper <paper@paper.us.eu.org>
parents:
diff changeset
17 } while (0);
e6a594f16403 *: huge refactor
Paper <paper@paper.us.eu.org>
parents:
diff changeset
18 static void cfg_get_controls(HWND hWnd) {
e6a594f16403 *: huge refactor
Paper <paper@paper.us.eu.org>
parents:
diff changeset
19 dlg_item_to_conf(hWnd, TITLE_CHECK, config.display_title);
e6a594f16403 *: huge refactor
Paper <paper@paper.us.eu.org>
parents:
diff changeset
20 dlg_item_to_conf(hWnd, ALBUM_ART_CHECK, config.display_album_art);
e6a594f16403 *: huge refactor
Paper <paper@paper.us.eu.org>
parents:
diff changeset
21 dlg_item_to_conf(hWnd, ALBUM_NAME_CHECK, config.display_album_name);
e6a594f16403 *: huge refactor
Paper <paper@paper.us.eu.org>
parents:
diff changeset
22 dlg_item_to_conf(hWnd, ARTIST_NAME_CHECK, config.display_artist_name);
e6a594f16403 *: huge refactor
Paper <paper@paper.us.eu.org>
parents:
diff changeset
23 dlg_item_to_conf(hWnd, SONG_INFO_CHECK, config.display_song_info);
e6a594f16403 *: huge refactor
Paper <paper@paper.us.eu.org>
parents:
diff changeset
24 dlg_item_to_conf(hWnd, ELAPSED_TIME_CHECK, config.show_elapsed_time);
e6a594f16403 *: huge refactor
Paper <paper@paper.us.eu.org>
parents:
diff changeset
25 }
e6a594f16403 *: huge refactor
Paper <paper@paper.us.eu.org>
parents:
diff changeset
26
e6a594f16403 *: huge refactor
Paper <paper@paper.us.eu.org>
parents:
diff changeset
27 static void cfg_set_controls(HWND hWnd) {
e6a594f16403 *: huge refactor
Paper <paper@paper.us.eu.org>
parents:
diff changeset
28 conf_item_to_dlg(hWnd, TITLE_CHECK, config.display_title);
e6a594f16403 *: huge refactor
Paper <paper@paper.us.eu.org>
parents:
diff changeset
29 conf_item_to_dlg(hWnd, ALBUM_ART_CHECK, config.display_album_art);
e6a594f16403 *: huge refactor
Paper <paper@paper.us.eu.org>
parents:
diff changeset
30 conf_item_to_dlg(hWnd, ALBUM_NAME_CHECK, config.display_album_name);
e6a594f16403 *: huge refactor
Paper <paper@paper.us.eu.org>
parents:
diff changeset
31 conf_item_to_dlg(hWnd, ARTIST_NAME_CHECK, config.display_artist_name);
e6a594f16403 *: huge refactor
Paper <paper@paper.us.eu.org>
parents:
diff changeset
32 conf_item_to_dlg(hWnd, SONG_INFO_CHECK, config.display_song_info);
e6a594f16403 *: huge refactor
Paper <paper@paper.us.eu.org>
parents:
diff changeset
33 conf_item_to_dlg(hWnd, ELAPSED_TIME_CHECK, config.show_elapsed_time);
e6a594f16403 *: huge refactor
Paper <paper@paper.us.eu.org>
parents:
diff changeset
34 }
e6a594f16403 *: huge refactor
Paper <paper@paper.us.eu.org>
parents:
diff changeset
35 #undef conf_item_to_dlg
e6a594f16403 *: huge refactor
Paper <paper@paper.us.eu.org>
parents:
diff changeset
36 #undef dlg_item_to_conf
e6a594f16403 *: huge refactor
Paper <paper@paper.us.eu.org>
parents:
diff changeset
37
e6a594f16403 *: huge refactor
Paper <paper@paper.us.eu.org>
parents:
diff changeset
38 static void cfg_on_confirm_settings_dialog(HWND hWnd) {
e6a594f16403 *: huge refactor
Paper <paper@paper.us.eu.org>
parents:
diff changeset
39 cfg_get_controls(hWnd);
e6a594f16403 *: huge refactor
Paper <paper@paper.us.eu.org>
parents:
diff changeset
40 cfg_save(&config);
e6a594f16403 *: huge refactor
Paper <paper@paper.us.eu.org>
parents:
diff changeset
41 update_rich_presence_details();
e6a594f16403 *: huge refactor
Paper <paper@paper.us.eu.org>
parents:
diff changeset
42 }
e6a594f16403 *: huge refactor
Paper <paper@paper.us.eu.org>
parents:
diff changeset
43
e6a594f16403 *: huge refactor
Paper <paper@paper.us.eu.org>
parents:
diff changeset
44 BOOL CALLBACK cfg_win_proc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {
e6a594f16403 *: huge refactor
Paper <paper@paper.us.eu.org>
parents:
diff changeset
45 switch (msg) {
e6a594f16403 *: huge refactor
Paper <paper@paper.us.eu.org>
parents:
diff changeset
46 case WM_INITDIALOG:
e6a594f16403 *: huge refactor
Paper <paper@paper.us.eu.org>
parents:
diff changeset
47 /* do nothing if this is a child window (tab page) callback, pass to the parent */
e6a594f16403 *: huge refactor
Paper <paper@paper.us.eu.org>
parents:
diff changeset
48 if (GetWindowLong(hWnd, GWL_STYLE) & WS_CHILD)
e6a594f16403 *: huge refactor
Paper <paper@paper.us.eu.org>
parents:
diff changeset
49 return FALSE;
e6a594f16403 *: huge refactor
Paper <paper@paper.us.eu.org>
parents:
diff changeset
50
e6a594f16403 *: huge refactor
Paper <paper@paper.us.eu.org>
parents:
diff changeset
51 cfg_set_controls(hWnd);
e6a594f16403 *: huge refactor
Paper <paper@paper.us.eu.org>
parents:
diff changeset
52 return TRUE;
e6a594f16403 *: huge refactor
Paper <paper@paper.us.eu.org>
parents:
diff changeset
53 case WM_COMMAND:
e6a594f16403 *: huge refactor
Paper <paper@paper.us.eu.org>
parents:
diff changeset
54 switch (LOWORD(wParam)) {
e6a594f16403 *: huge refactor
Paper <paper@paper.us.eu.org>
parents:
diff changeset
55 case IDOK:
e6a594f16403 *: huge refactor
Paper <paper@paper.us.eu.org>
parents:
diff changeset
56 cfg_on_confirm_settings_dialog(hWnd);
e6a594f16403 *: huge refactor
Paper <paper@paper.us.eu.org>
parents:
diff changeset
57 EndDialog(hWnd, 0);
e6a594f16403 *: huge refactor
Paper <paper@paper.us.eu.org>
parents:
diff changeset
58 return TRUE;
e6a594f16403 *: huge refactor
Paper <paper@paper.us.eu.org>
parents:
diff changeset
59 case IDCANCEL:
e6a594f16403 *: huge refactor
Paper <paper@paper.us.eu.org>
parents:
diff changeset
60 EndDialog(hWnd, 0);
e6a594f16403 *: huge refactor
Paper <paper@paper.us.eu.org>
parents:
diff changeset
61 return TRUE;
e6a594f16403 *: huge refactor
Paper <paper@paper.us.eu.org>
parents:
diff changeset
62 }
e6a594f16403 *: huge refactor
Paper <paper@paper.us.eu.org>
parents:
diff changeset
63 break;
e6a594f16403 *: huge refactor
Paper <paper@paper.us.eu.org>
parents:
diff changeset
64 default:
e6a594f16403 *: huge refactor
Paper <paper@paper.us.eu.org>
parents:
diff changeset
65 break;
e6a594f16403 *: huge refactor
Paper <paper@paper.us.eu.org>
parents:
diff changeset
66 }
e6a594f16403 *: huge refactor
Paper <paper@paper.us.eu.org>
parents:
diff changeset
67
e6a594f16403 *: huge refactor
Paper <paper@paper.us.eu.org>
parents:
diff changeset
68 return FALSE;
e6a594f16403 *: huge refactor
Paper <paper@paper.us.eu.org>
parents:
diff changeset
69 }