Mercurial > wgsdk
view src/dialog/dlg_config.c @ 11:e6a594f16403
*: huge refactor
the config file has changed drastically, moving to an ini file from
that custom format; i *would* have used the win32 functions for those,
but they were barely functional, so I decided on using ini.h which is
lightweight enough.
additionally, I've added Deezer support so album art will be displayed!
unfortunately though winhttp is a pain in the ass so if I send a request
with any form of unicode chars in it it just returns a "bad request" error.
I've tried debugging this but I could never really come up with anything:
my hypothesis is that deezer expects their characters in percent-encoded
UTF-8, but winhttp is sending them in some other encoding.
the config dialog was moved out of config.c (overdue) and many more options
are given in the config as well.
main.c has been renamed to plugin.c to better differentiate it from...
everything else.
author | Paper <paper@paper.us.eu.org> |
---|---|
date | Thu, 14 Mar 2024 20:25:37 -0400 |
parents | |
children |
line wrap: on
line source
#include "dialog/dlg_config.h" #include "config.h" /* global config */ #include "plugin.h" /* update_rich_presence_details() */ #include "resource.h" /* TITLE_CHECK, ... */ #include <winuser.h> #define conf_item_to_dlg(hwnd, cons, var) \ do { \ HWND checkboxHwnd = GetDlgItem(hwnd, cons); \ SendMessage(checkboxHwnd, BM_SETCHECK, (var) ? BST_CHECKED : BST_UNCHECKED, 0); \ } while (0); #define dlg_item_to_conf(hwnd, cons, var) \ do { \ HWND checkboxHwnd = GetDlgItem(hwnd, cons); \ (var) = (SendMessage(checkboxHwnd, BM_GETCHECK, 0, 0) == BST_CHECKED); \ } while (0); static void cfg_get_controls(HWND hWnd) { dlg_item_to_conf(hWnd, TITLE_CHECK, config.display_title); dlg_item_to_conf(hWnd, ALBUM_ART_CHECK, config.display_album_art); dlg_item_to_conf(hWnd, ALBUM_NAME_CHECK, config.display_album_name); dlg_item_to_conf(hWnd, ARTIST_NAME_CHECK, config.display_artist_name); dlg_item_to_conf(hWnd, SONG_INFO_CHECK, config.display_song_info); dlg_item_to_conf(hWnd, ELAPSED_TIME_CHECK, config.show_elapsed_time); } static void cfg_set_controls(HWND hWnd) { conf_item_to_dlg(hWnd, TITLE_CHECK, config.display_title); conf_item_to_dlg(hWnd, ALBUM_ART_CHECK, config.display_album_art); conf_item_to_dlg(hWnd, ALBUM_NAME_CHECK, config.display_album_name); conf_item_to_dlg(hWnd, ARTIST_NAME_CHECK, config.display_artist_name); conf_item_to_dlg(hWnd, SONG_INFO_CHECK, config.display_song_info); conf_item_to_dlg(hWnd, ELAPSED_TIME_CHECK, config.show_elapsed_time); } #undef conf_item_to_dlg #undef dlg_item_to_conf static void cfg_on_confirm_settings_dialog(HWND hWnd) { cfg_get_controls(hWnd); cfg_save(&config); update_rich_presence_details(); } BOOL CALLBACK cfg_win_proc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { case WM_INITDIALOG: /* do nothing if this is a child window (tab page) callback, pass to the parent */ if (GetWindowLong(hWnd, GWL_STYLE) & WS_CHILD) return FALSE; cfg_set_controls(hWnd); return TRUE; case WM_COMMAND: switch (LOWORD(wParam)) { case IDOK: cfg_on_confirm_settings_dialog(hWnd); EndDialog(hWnd, 0); return TRUE; case IDCANCEL: EndDialog(hWnd, 0); return TRUE; } break; default: break; } return FALSE; }