aboutsummaryrefslogtreecommitdiff
path: root/Src/Plugins/Library/ml_history/prefs.cpp
blob: 8fa3832d229692c283f22e991f26ab7c18ce6d04 (plain) (blame)
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#include "main.h"
#include "..\..\General\gen_ml/config.h"
#include "resource.h"

void hideShowRecentItemsCheckboxes(HWND hwndDlg) 
{
	int enabled = IsDlgButtonChecked(hwndDlg, IDC_CHECK1);
	int wait_secs = !!g_config->ReadInt(L"recent_wait_secs",0);
	int wait_percent = !!g_config->ReadInt(L"recent_wait_percent",0);
	int wait_end = !!g_config->ReadInt(L"recent_wait_end",0);
	EnableWindow(GetDlgItem(hwndDlg, IDC_CHECK2), enabled);
	EnableWindow(GetDlgItem(hwndDlg, IDC_CHECK3), enabled);
	EnableWindow(GetDlgItem(hwndDlg, IDC_CHECK4), enabled);
	EnableWindow(GetDlgItem(hwndDlg, IDC_CHECK5), enabled);
	EnableWindow(GetDlgItem(hwndDlg, IDC_CHECK6), enabled);
	EnableWindow(GetDlgItem(hwndDlg, IDC_CHECK7), enabled);
	EnableWindow(GetDlgItem(hwndDlg, IDC_EDIT1), enabled && !!g_config->ReadInt(L"recent_limitd",1));
	EnableWindow(GetDlgItem(hwndDlg, IDC_STATIC1), enabled);
	EnableWindow(GetDlgItem(hwndDlg, IDC_STATIC3), enabled);
	EnableWindow(GetDlgItem(hwndDlg, IDC_STATIC4), enabled);
	EnableWindow(GetDlgItem(hwndDlg, IDC_STATIC5), enabled);
	EnableWindow(GetDlgItem(hwndDlg, IDC_STATIC6), enabled);
	EnableWindow(GetDlgItem(hwndDlg, IDC_EDIT2), enabled && wait_secs);
	EnableWindow(GetDlgItem(hwndDlg, IDC_EDIT3), enabled && wait_percent);
	EnableWindow(GetDlgItem(hwndDlg, IDC_STATIC7), enabled && !(wait_end && !wait_secs && !wait_percent));
	EnableWindow(GetDlgItem(hwndDlg, IDC_COMBO1), enabled && !(wait_end && !wait_secs && !wait_percent));
}

BOOL CALLBACK PrefsProc(HWND hwndDlg, UINT uMsg, WPARAM wParam,LPARAM lParam)
{
	static int need_ref;
	switch (uMsg)
	{
		case WM_INITDIALOG:
		{
			CheckDlgButton(hwndDlg,IDC_CHECK2,(g_config->ReadInt(L"recent_track",1)&1)?BST_CHECKED:0);
			CheckDlgButton(hwndDlg,IDC_CHECK3,(g_config->ReadInt(L"recent_track",1)&2)?0:BST_CHECKED);
			CheckDlgButton(hwndDlg,IDC_CHECK1,!!g_config->ReadInt(L"showrecentitems",1));
			CheckDlgButton(hwndDlg,IDC_CHECK4,!!g_config->ReadInt(L"recent_limitd",1));
			CheckDlgButton(hwndDlg,IDC_CHECK5,!!g_config->ReadInt(L"recent_wait_secs",0));
			CheckDlgButton(hwndDlg,IDC_CHECK6,!!g_config->ReadInt(L"recent_wait_percent",0));
			CheckDlgButton(hwndDlg,IDC_CHECK7,!!g_config->ReadInt(L"recent_wait_end",0));
			
			int item = (int)SendDlgItemMessageW(hwndDlg,IDC_COMBO1,CB_ADDSTRING,0,(LPARAM)WASABI_API_LNGSTRINGW(IDS_DISABLED));
			SendDlgItemMessageW(hwndDlg,IDC_COMBO1,CB_SETITEMDATA,item,0);
			item = (int)SendDlgItemMessageW(hwndDlg,IDC_COMBO1,CB_ADDSTRING,0,(LPARAM)WASABI_API_LNGSTRINGW(IDS_PODCAST_ONLY));
			SendDlgItemMessageW(hwndDlg,IDC_COMBO1,CB_SETITEMDATA,item,1);
			item = (int)SendDlgItemMessageW(hwndDlg,IDC_COMBO1,CB_ADDSTRING,0,(LPARAM)WASABI_API_LNGSTRINGW(IDS_ANY_APPLICABLE));
			SendDlgItemMessageW(hwndDlg,IDC_COMBO1,CB_SETITEMDATA,item,2);
			SendDlgItemMessageW(hwndDlg,IDC_COMBO1,CB_SETCURSEL,g_config->ReadInt(L"resumeplayback",0),0);

			SetDlgItemInt(hwndDlg,IDC_EDIT1,g_config->ReadInt(L"recent_limitnd",30),FALSE);
			SetDlgItemInt(hwndDlg,IDC_EDIT2,g_config->ReadInt(L"recent_wait_secs_lim",5),FALSE);
			SetDlgItemInt(hwndDlg,IDC_EDIT3,g_config->ReadInt(L"recent_wait_percent_lim",50),FALSE);
			need_ref=0;
			hideShowRecentItemsCheckboxes(hwndDlg);
			break;
		}

		case WM_COMMAND:
			switch(LOWORD(wParam))
			{
				case IDC_CHECK1:
				{
					int a=!!IsDlgButtonChecked(hwndDlg,IDC_CHECK1);
					g_config->WriteInt(L"showrecentitems",a);
					if (a) history_init();
					else history_quit();
					hideShowRecentItemsCheckboxes(hwndDlg);
				}
					break;

				case IDC_EDIT1:
					if (HIWORD(wParam) == EN_CHANGE)
					{
						BOOL t;
						int v=GetDlgItemInt(hwndDlg,IDC_EDIT1,&t,FALSE);
						if (t) g_config->WriteInt(L"recent_limitnd",v);
						need_ref++;
					}
					break;

				case IDC_CHECK4:
					g_config->WriteInt(L"recent_limitd",!!IsDlgButtonChecked(hwndDlg,IDC_CHECK4));
					EnableWindow(GetDlgItem(hwndDlg,IDC_EDIT1),!!g_config->ReadInt(L"recent_limitd",1));
					need_ref++;
					break;

				case IDC_CHECK2:
				case IDC_CHECK3:
					g_config->WriteInt(L"recent_track",(IsDlgButtonChecked(hwndDlg,IDC_CHECK2)?1:0) | (IsDlgButtonChecked(hwndDlg,IDC_CHECK3)?0:2));
					break;

				case IDC_CHECK5:
					g_config->WriteInt(L"recent_wait_secs",!!IsDlgButtonChecked(hwndDlg,IDC_CHECK5));
					hideShowRecentItemsCheckboxes(hwndDlg);
					break;

				case IDC_CHECK6:
					g_config->WriteInt(L"recent_wait_percent",!!IsDlgButtonChecked(hwndDlg,IDC_CHECK6));
					hideShowRecentItemsCheckboxes(hwndDlg);
					break;

				case IDC_CHECK7:
					g_config->WriteInt(L"recent_wait_end",!!IsDlgButtonChecked(hwndDlg,IDC_CHECK7));
					hideShowRecentItemsCheckboxes(hwndDlg);
					break;

				case IDC_COMBO1:
					if (HIWORD(wParam) == CBN_SELCHANGE)
					{
						int item = (int)SendDlgItemMessageW(hwndDlg,IDC_COMBO1,CB_GETCURSEL,0,0);
						if (item != CB_ERR)
						{
							g_config->WriteInt(L"resumeplayback", (int)SendDlgItemMessageW(hwndDlg,IDC_COMBO1,CB_GETITEMDATA,item,0));
						}
					}
					break;

				case IDC_EDIT2:
					if (HIWORD(wParam) == EN_CHANGE)
					{
						BOOL t;
						int v=GetDlgItemInt(hwndDlg,IDC_EDIT2,&t,FALSE);
						if (t)
						{
							if(v < 0)
							{
								v = 1;
								SetDlgItemInt(hwndDlg, IDC_EDIT2, v, 0);
							}
							g_config->WriteInt(L"recent_wait_secs_lim",v);
						}
						need_ref++;
					}
					break;

				case IDC_EDIT3:
					if (HIWORD(wParam) == EN_CHANGE)
					{
						BOOL t;
						int v=GetDlgItemInt(hwndDlg,IDC_EDIT3,&t,FALSE);
						if(t)
						{
							int tweaked = 0;
							if(v > 99){
								v = 99;
								tweaked = 1;
							}
							else if(v < 1)
							{
								v = 1;
								tweaked = 1;
							}
							if(tweaked)
							{
								SetDlgItemInt(hwndDlg, IDC_EDIT3, v, 0);
							}

							g_config->WriteInt(L"recent_wait_percent_lim",v);
						}
						need_ref++;
					}
					break;
			};
			break;

		case WM_DESTROY:
			if (need_ref)
			{
				g_config->WriteInt(L"recent_limitlt",0); // make sure it gets refreshed
				// TODO: only do this if the history view is open
				PostMessage(plugin.hwndLibraryParent,WM_USER+30,0,0);	
			}
			break;
	}
	return 0;
}