xref: /MusicPlayer2/MusicPlayer2/CHotkeyManager.cpp (revision 0fc1c23250c9d2ac73d9c13c8e94c7a863ad989d)
1 #include "stdafx.h"
2 #include "CHotkeyManager.h"
3 #include "MusicPlayer2.h"
4 #include "Common.h"
5 
6 
CHotkeyManager()7 CHotkeyManager::CHotkeyManager()
8 {
9 }
10 
11 
~CHotkeyManager()12 CHotkeyManager::~CHotkeyManager()
13 {
14 }
15 
SetHotKey(eHotKeyId id,CHotKey key)16 void CHotkeyManager::SetHotKey(eHotKeyId id, CHotKey key)
17 {
18 	m_hotkey_group[id] = key;
19 }
20 
GetHotKey(eHotKeyId id)21 CHotKey CHotkeyManager::GetHotKey(eHotKeyId id)
22 {
23 	return m_hotkey_group[id];
24 }
25 
RegisterAllHotKey()26 void CHotkeyManager::RegisterAllHotKey()
27 {
28 	for (const auto& hot_key : m_hotkey_group)
29 	{
30 		WORD control_key = hot_key.second.Modifiers();
31 
32 		if (hot_key.second.key == 0 || control_key == 0)
33 			continue;
34 
35 		RegisterHotKey(theApp.m_pMainWnd->GetSafeHwnd(), hot_key.first, control_key, hot_key.second.key);
36 	}
37 }
38 
UnRegisterAllHotKey()39 void CHotkeyManager::UnRegisterAllHotKey()
40 {
41 	for (const auto& hot_key : m_hotkey_group)
42 	{
43 		UnregisterHotKey(theApp.m_pMainWnd->GetSafeHwnd(), hot_key.first);
44 	}
45 }
46 
FromHotkeyGroup(const HotKeyMap & group)47 void CHotkeyManager::FromHotkeyGroup(const HotKeyMap& group)
48 {
49 	m_hotkey_group = group;
50 }
51 
GetHotKeyGroup() const52 const CHotkeyManager::HotKeyMap & CHotkeyManager::GetHotKeyGroup() const
53 {
54 	return m_hotkey_group;
55 }
56 
LoadFromIni(const CIniHelper & ini)57 void CHotkeyManager::LoadFromIni(const CIniHelper & ini)
58 {
59 	CHotKey hot_key;
60 	hot_key.FromString(ini.GetString(L"hot_key", L"play_pause", L"Ctrl+Shift+116"));
61 	SetHotKey(HK_PLAY_PAUSE, hot_key);
62 
63 	hot_key.FromString(ini.GetString(L"hot_key", L"stop", L"Ctrl+Shift+117"));
64 	SetHotKey(HK_STOP, hot_key);
65 
66 	hot_key.FromString(ini.GetString(L"hot_key", L"fast_forward", L"Ctrl+Shift+119"));
67 	SetHotKey(HK_FF, hot_key);
68 
69 	hot_key.FromString(ini.GetString(L"hot_key", L"rewind", L"Ctrl+Shift+118"));
70 	SetHotKey(HK_REW, hot_key);
71 
72 	hot_key.FromString(ini.GetString(L"hot_key", L"previous", L"Ctrl+Shift+37"));
73 	SetHotKey(HK_PREVIOUS, hot_key);
74 
75 	hot_key.FromString(ini.GetString(L"hot_key", L"next", L"Ctrl+Shift+39"));
76 	SetHotKey(HK_NEXT, hot_key);
77 
78 	hot_key.FromString(ini.GetString(L"hot_key", L"volume_up", L"Ctrl+Shift+38"));
79 	SetHotKey(HK_VOLUME_UP, hot_key);
80 
81 	hot_key.FromString(ini.GetString(L"hot_key", L"volume_down", L"Ctrl+Shift+40"));
82 	SetHotKey(HK_VOLUME_DOWN, hot_key);
83 
84 	hot_key.FromString(ini.GetString(L"hot_key", L"exit", L""));
85 	SetHotKey(HK_EXIT, hot_key);
86 
87 	hot_key.FromString(ini.GetString(L"hot_key", L"show_hide_player", L""));
88 	SetHotKey(HK_SHOW_HIDE_PLAYER, hot_key);
89 
90 	hot_key.FromString(ini.GetString(L"hot_key", L"show_hide_desktop_lyric", L""));
91 	SetHotKey(HK_SHOW_HIDE_DESKTOP_LYRIC, hot_key);
92 
93 	hot_key.FromString(ini.GetString(L"hot_key", L"add_to_my_favourite", L""));
94 	SetHotKey(HK_ADD_TO_MY_FAVOURITE, hot_key);
95 }
96 
SaveToTni(CIniHelper & ini)97 void CHotkeyManager::SaveToTni(CIniHelper & ini)
98 {
99 	wstring str;
100 	str = GetHotKey(HK_PLAY_PAUSE).ToString();
101 	ini.WriteString(L"hot_key", L"play_pause", str);
102 
103 	str = GetHotKey(HK_STOP).ToString();
104 	ini.WriteString(L"hot_key", L"stop", str);
105 
106 	str = GetHotKey(HK_FF).ToString();
107 	ini.WriteString(L"hot_key", L"fast_forward", str);
108 
109 	str = GetHotKey(HK_REW).ToString();
110 	ini.WriteString(L"hot_key", L"rewind", str);
111 
112 	str = GetHotKey(HK_PREVIOUS).ToString();
113 	ini.WriteString(L"hot_key", L"previous", str);
114 
115 	str = GetHotKey(HK_NEXT).ToString();
116 	ini.WriteString(L"hot_key", L"next", str);
117 
118 	str = GetHotKey(HK_VOLUME_UP).ToString();
119 	ini.WriteString(L"hot_key", L"volume_up", str);
120 
121 	str = GetHotKey(HK_VOLUME_DOWN).ToString();
122 	ini.WriteString(L"hot_key", L"volume_down", str);
123 
124 	str = GetHotKey(HK_EXIT).ToString();
125 	ini.WriteString(L"hot_key", L"exit", str);
126 
127     str = GetHotKey(HK_SHOW_HIDE_PLAYER).ToString();
128     ini.WriteString(L"hot_key", L"show_hide_player", str);
129 
130 	str = GetHotKey(HK_SHOW_HIDE_DESKTOP_LYRIC).ToString();
131 	ini.WriteString(L"hot_key", L"show_hide_desktop_lyric", str);
132 
133 	str = GetHotKey(HK_ADD_TO_MY_FAVOURITE).ToString();
134 	ini.WriteString(L"hot_key", L"add_to_my_favourite", str);
135 }
136