Grabby/GrbyCfg/GeneralCfg.c

182 lines
4 KiB
C
Raw Normal View History

/* General configuration dialog */
#include "stdafx.h"
#include "GrbyCfg.h"
int CALLBACK
ScreenshotBrowseCallback(HWND hWnd,
UINT uMsg,
LPARAM lParam,
LPARAM lpData)
{
if (uMsg == BFFM_INITIALIZED && lpData) {
// Set root dir
SendMessage(hWnd,
BFFM_SETSELECTION,
1,
lpData);
}
return 0;
}
INT_PTR CALLBACK
GeneralTab_DlgProc(HWND hDlg,
UINT uMsg,
WPARAM wParam,
LPARAM lParam)
{
static Config *cfg = NULL;
static HWND hStoreDir = NULL,
hCustomShortcut = NULL,
hParentDlg = NULL;
switch (uMsg) {
case WM_INITDIALOG:
hParentDlg = GetParent(hDlg);
cfg = GetConfig();
if (!cfg) {
// TODO: better error management
// (probably SendMessage upstream)
MessageBox(hDlg,
_T("Can't get config! (TODO: error msg)"),
_T("Config Error"),
MB_OK | MB_ICONERROR);
DestroyWindow(hDlg);
}
hStoreDir = GetDlgItem(hDlg, IDC_SCRNDIR);
if (!hStoreDir) {
// TODO: error management x_x
return FALSE;
}
if (strlen(cfg->ScreenshotDir) > 0) {
// Set the screenshot dir, if we have it
SendMessage(hStoreDir,
EM_SETLIMITTEXT,
(WPARAM)MAX_PATH,
0);
SetWindowText(hStoreDir,
cfg->ScreenshotDir);
}
if (cfg->KeepScreenshots) {
// Keep screenshots after upload?
CheckDlgButton(hDlg,
IDC_KEEPIMGS,
BST_CHECKED);
}
if (cfg->HelperStartup) {
// Launch helper on startup?
CheckDlgButton(hDlg,
IDC_LAUNCHHELPER,
BST_CHECKED);
}
hCustomShortcut = GetDlgItem(hDlg,
IDC_CUSTOMKEY);
if (!hCustomShortcut) {
// TODO: error management orz
return FALSE;
}
// Enable the shortcut input if Custom is set
EnableWindow(hCustomShortcut,
(cfg->HelperShortcut == HSC_CUSTOM));
// Also, check the correct radio box. This is hacky and
// expects IDC_RDMAC/WIN/CUSTOM is not changed, so uhhhh
// please don't change that assumption? ^_^;;
CheckDlgButton(hDlg,
IDC_RDMAC + min(2, cfg->HelperShortcut),
BST_CHECKED);
break;
case WM_NOTIFY:
// TODO
break;
case WM_COMMAND:
switch (LOWORD(wParam)) {
case IDC_LAUNCHHELPER:
cfg->HelperStartup =
(IsDlgButtonChecked(hDlg, IDC_LAUNCHHELPER) == BST_CHECKED);
ChangedSetting(hParentDlg);
break;
case IDC_KEEPIMGS:
cfg->KeepScreenshots =
(IsDlgButtonChecked(hDlg, IDC_KEEPIMGS) == BST_CHECKED);
ChangedSetting(hParentDlg);
break;
case IDC_RDMAC:
case IDC_RDWIN:
case IDC_RDCUSTOM:
// Generates the correct enum val a la GetConfig.
cfg->HelperShortcut = IsChecked(IDC_RDMAC) ? HSC_MACOS :
(IsChecked(IDC_RDWIN) ? HSC_WIN10 : HSC_CUSTOM);
// Enable/Disable the Custom Shortcut control as needed
EnableWindow(hCustomShortcut,
(cfg->HelperShortcut == HSC_CUSTOM));
ChangedSetting(hParentDlg);
break;
case IDC_SCRDIRBROWSE: {
LPITEMIDLIST lPidl;
BROWSEINFO bi = {0};
bi.hwndOwner = hDlg;
bi.lParam = (LPARAM)cfg->ScreenshotDir;
bi.lpfn = ScreenshotBrowseCallback;
bi.lpszTitle = _T("Select Screenshot Folder");
lPidl = SHBrowseForFolder(&bi);
if (lPidl == NULL) {
// Cancelled
break;
}
SHGetPathFromIDList(lPidl,
cfg->ScreenshotDir);
// We don't need the PIDL anymore, so free it
{
LPMALLOC pMalloc;
if (SHGetMalloc(&pMalloc) == NOERROR) {
IMalloc_Free(pMalloc, lPidl);
IMalloc_Release(pMalloc);
}
}
// Update the edit control
SetWindowText(hStoreDir,
cfg->ScreenshotDir);
ChangedSetting(hParentDlg);
}
break;
default:
return FALSE;
}
break;
default:
// User-defined messages
if (uMsg == WMU_SAVE_CONFIG) {
GetWindowText(hStoreDir,
cfg->ScreenshotDir,
MAX_PATH - 1);
if (!SaveConfig(cfg)) {
// TODO: error management
OutputDebugString(_T("no save x_x"));
}
} else {
// Not a message we care about
return FALSE;
}
}
return TRUE;
}