-
Notifications
You must be signed in to change notification settings - Fork 2
/
preferences.cpp
192 lines (155 loc) · 7.45 KB
/
preferences.cpp
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
/*
Copyright (c) 2008-2015, Skyler Kehren
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted
provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of
conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of
conditions and the following disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of the author nor the names of its contributors may be used to endorse
or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "stdafx.h"
namespace FooSnarl {
namespace Preferences {
static const GUID guid_titleformat_data = { 0xf6d66cdc, 0x872c, 0x48bc,{ 0xa7, 0x98, 0x1a, 0x6a, 0xab, 0x64, 0xcf, 0x45 } };
static const char* titleformat_default = "$if(%isplaying%,$if(%ispaused%,Paused,Now Playing),Stopped)";
cfg_string titleformat_data(guid_titleformat_data, titleformat_default);
static const GUID guid_textformat_data = { 0x76c6cd47, 0xf1b9, 0x49a7,{ 0x89, 0x44, 0x45, 0x90, 0x9a, 0x96, 0x7a, 0x7f } };
static const char* textformat_default = "[%album artist%$crlf()]%title%";
cfg_string textformat_data(guid_textformat_data, textformat_default);
// {71CACCA2-7291-44DB-9168-49E50F6F2152}
static const GUID guid_enable_actions_data = { 0x71cacca2, 0x7291, 0x44db,{ 0x91, 0x68, 0x49, 0xe5, 0xf, 0x6f, 0x21, 0x52 } };
static const bool enable_actions_default = true;
cfg_bool enable_actions_data(guid_enable_actions_data, enable_actions_default);
/* static const GUID guid_timeout = { 0xb224f26b, 0x9799, 0x40c0,{ 0x9f, 0x56, 0x87, 0x27, 0x70, 0x90, 0x1e, 0x9b } };
static const int32_t timeout_default = 5;
cfg_int timeout_data(guid_timeout, timeout_default);*/
}
class CMyPreferences : public CDialogImpl<CMyPreferences>, public preferences_page_instance {
public:
CMyPreferences(preferences_page_callback::ptr callback) : m_callback(callback){}
//dialog resource ID
enum {IDD = IDD_FOOSNARL_PREFS};
//WTL Message Map
BEGIN_MSG_MAP_EX(CMyPreferences)
MSG_WM_INITDIALOG(OnInitDialog)
COMMAND_HANDLER_EX(IDC_TITLEFORMAT_DATA,EN_UPDATE, OnChanged)
COMMAND_HANDLER_EX(IDC_TEXTFORMAT_DATA, EN_UPDATE, OnChanged)
COMMAND_HANDLER_EX(IDC_ENABLEACTIONS,BN_CLICKED,OnChanged)
COMMAND_HANDLER_EX(IDC_TITLEFORMAT_DATA, EN_SETFOCUS, OnSetFocus)
COMMAND_HANDLER_EX(IDC_TEXTFORMAT_DATA, EN_SETFOCUS, OnSetFocus)
COMMAND_HANDLER_EX(IDC_TESTBUTTON,BN_CLICKED,OnTestButtonClick)
NOTIFY_HANDLER_EX(IDC_SYNTAXHELP,NM_CLICK, OnSyntaxHelpClick)
END_MSG_MAP()
private:
CEdit titleformat;
CEdit textformat;
CEdit enableactions;
CEdit dlg_title;
const preferences_page_callback::ptr m_callback;
BOOL OnInitDialog(CWindow, LPARAM) {
titleformat = GetDlgItem(IDC_TITLEFORMAT_DATA);
textformat = GetDlgItem(IDC_TEXTFORMAT_DATA);
enableactions = GetDlgItem(IDC_ENABLEACTIONS);
dlg_title = GetDlgItem(IDC_TITLE);
CFont *m_pFont = new CFont();
m_pFont->CreatePointFont(128, _T("Microsoft Sans Serif"), 0, true, false);
dlg_title.SetFont(m_pFont->m_hFont, TRUE);
uSetWindowText(titleformat, Preferences::titleformat_data);
uSetWindowText(textformat, Preferences::textformat_data);
CheckDlgButton(IDC_ENABLEACTIONS, Preferences::enable_actions_data);
return FALSE;
}
bool has_changed(){
pfc::string8 temp;
uGetWindowText(titleformat,temp);
if(Preferences::titleformat_data != temp) return true;
uGetWindowText(textformat,temp);
if(Preferences::textformat_data != temp) return true;
if (Preferences::enable_actions_data != (bool) IsDlgButtonChecked(IDC_ENABLEACTIONS)) return true;
return false;
}
t_uint32 get_state(){
t_uint32 state = preferences_state::resettable;
if(has_changed()) state |= preferences_state::changed;
return state;
}
void apply(){
uGetWindowText(titleformat, Preferences::titleformat_data);
uGetWindowText(textformat, Preferences::textformat_data);
Preferences::enable_actions_data = (bool)IsDlgButtonChecked(IDC_ENABLEACTIONS);
}
void on_change(){
//tell the host that our state has changed to enable/disable the apply button appropriately.
m_callback->on_state_changed();
}
void reset(){
uSetWindowText(titleformat, Preferences::titleformat_default);
uSetWindowText(textformat, Preferences::textformat_default);
CheckDlgButton(IDC_ENABLEACTIONS, Preferences::enable_actions_default);
}
void OnChanged(UINT, int, HWND c){
on_change();
if (c == titleformat || c == textformat) {
UpdatePreview(c);
}
}
void OnSetFocus(UINT, int, HWND c) {
UpdatePreview(c);
}
void OnTestButtonClick(UINT, int, HWND) {
foo_snarl.send_snarl_message(MessageClass::Auto, uGetWindowText(titleformat), uGetWindowText(textformat),(bool)IsDlgButtonChecked(IDC_ENABLEACTIONS)); //uGetDlgItemInt(IDC_TIMEOUT, NULL, FALSE)
}
void UpdatePreview(HWND c) {
pfc::string formatstring = uGetWindowText(c);
static_api_ptr_t<playback_control> pc;
static_api_ptr_t<playlist_manager> pm;
metadb_handle_ptr handle;
service_ptr_t<titleformat_object> script;
pfc::string_formatter formattedtext;
if (!pc->get_now_playing(handle)) {
pm->activeplaylist_get_focus_item_handle(handle);
}
if (handle.is_empty()) return;
//Process title format string
static_api_ptr_t<titleformat_compiler>()->compile_safe_ex(script, formatstring.ptr(), "Invalid format script");
pc->playback_format_title_ex(handle, NULL, formattedtext, script, NULL, play_control::display_level_titles);
uSetWindowText(GetDlgItem(IDC_FORMATPREVIEW), formattedtext.toString());
}
LRESULT OnSyntaxHelpClick(NMHDR *pNotifyStruct) {
//Open syntax help file or browser window...
ShellExecuteA(NULL, "open", "http://wiki.hydrogenaud.io/index.php?title=Foobar2000:Titleformat_Reference", NULL, NULL, SW_SHOWNORMAL);
return 0;
}
};
class Preferences_Page_FooSnarl : public preferences_page_impl<CMyPreferences> {
public:
const char * get_name(){
return "FooSnarl";
}
GUID get_guid(){
// {B30D44EB-D37C-4F6A-B589-39A707158641}
static const GUID guid = { 0xb30d44eb, 0xd37c, 0x4f6a, { 0xb5, 0x89, 0x39, 0xa7, 0x7, 0x15, 0x86, 0x41 } };
return guid;
}
GUID get_parent_guid(){
return preferences_page::guid_tools;
}
bool get_help_url(pfc::string_base & out){
out = "https://github.com/pyrodogg/FooSnarl";
return true;
}
};
preferences_page_factory_t<Preferences_Page_FooSnarl> _;
}