-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathUIElementPlaylistCallback.cpp
254 lines (191 loc) · 8.11 KB
/
UIElementPlaylistCallback.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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
/** $VER: UIElementPlaylistCallback.cpp (2024.12.02) P. Stuer **/
#include "pch.h"
#include "UIElement.h"
#include "UIElementTracker.h"
#include "Encoding.h"
#include "Exceptions.h"
#include "Support.h"
#include <SDK/titleformat.h>
#include <SDK/playlist.h>
#include <SDK/ui.h>
#pragma hdrstop
#pragma region playlist_callback
/// <summary>
/// Called when items have been added to the specified playlist.
/// </summary>
void UIElement::on_items_added(t_size playlistIndex, t_size startIndex, metadb_handle_list_cref data, const bit_array & selection)
{
const std::wstring Text = Stringify(ToJSON(data));
const std::wstring Script = ::FormatText(L"onPlaylistItemsAdded(%d, %d, \"%s\")", (int) playlistIndex, (int) startIndex, Text.c_str());
ExecuteScript(Script);
}
/// <summary>
/// Called when the items of the specified playlist have been reordered.
/// </summary>
void UIElement::on_items_reordered(t_size playlistIndex, const t_size * itemOrder, t_size itemCount)
{
const std::wstring Text = ToJSON(itemOrder, itemCount);
const std::wstring Script = ::FormatText(L"onPlaylistItemsReordered(%d, \"%s\")", (int) playlistIndex, Text.c_str());
ExecuteScript(Script);
}
/// <summary>
/// Called when items of the specified playlist are being removed.
/// </summary>
void UIElement::on_items_removing(t_size playlistIndex, const bit_array & mask, t_size oldCount, t_size newCount)
{
const std::wstring Text = ToJSON(mask, oldCount);
const std::wstring Script = ::FormatText(L"onPlaylistItemsRemoving(%d, \"%s\", %d)", (int) playlistIndex, Text.c_str(), (int) newCount);
ExecuteScript(Script);
}
/// <summary>
/// Called when items of the specified playlist have been removed.
/// </summary>
void UIElement::on_items_removed(t_size playlistIndex, const bit_array & mask, t_size oldCount, t_size newCount)
{
const std::wstring Text = ToJSON(mask, oldCount);
const std::wstring Script = ::FormatText(L"onPlaylistItemsRemoved(%d, \"%s\", %d)", (int) playlistIndex, Text.c_str(), (int) newCount);
ExecuteScript(Script);
}
/// <summary>
/// Called when some playlist items of the specified playlist have been modified.
/// </summary>
void UIElement::on_items_modified(t_size playlistIndex, const bit_array & mask)
{
t_size ItemCount = playlist_manager_v4::get()->playlist_get_item_count(playlistIndex);
const std::wstring Text = ToJSON(mask, ItemCount);
const std::wstring Script = ::FormatText(L"onPlaylistItemsModified(%d, \"%s\")", (int) playlistIndex, Text.c_str());
ExecuteScript(Script);
}
/// <summary>
/// Called when some playlist items of the specified playlist have been modified from playback.
/// </summary>
void UIElement::on_items_modified_fromplayback(t_size playlistIndex, const bit_array & mask, play_control::t_display_level displayLevel)
{
t_size ItemCount = playlist_manager_v4::get()->playlist_get_item_count(playlistIndex);
const std::wstring Text = ToJSON(mask, ItemCount);
const std::wstring Script = ::FormatText(L"onPlaylistItemsModifiedFromPlayback(%d, \"%s\")", (int) playlistIndex, Text.c_str());
ExecuteScript(Script);
}
/// <summary>
/// Called when items of the specified playlist have been replaced.
/// </summary>
void UIElement::on_items_replaced(t_size playlistIndex, const bit_array & mask, const pfc::list_base_const_t<playlist_callback::t_on_items_replaced_entry> & replacedItems)
{
t_size ItemCount = playlist_manager_v4::get()->playlist_get_item_count(playlistIndex);
const std::wstring Text = ToJSON(mask, ItemCount);
const std::wstring Script = ::FormatText(L"onPlaylistItemsReplaced(%d, \"%s\")", (int) playlistIndex, Text.c_str());
ExecuteScript(Script);
}
/// <summary>
/// Called when the specified item of a playlist has been ensured to be visible.
/// </summary>
void UIElement::on_item_ensure_visible(t_size playlistIndex, t_size itemIndex)
{
const std::wstring Script = ::FormatText(L"onPlaylistItemEnsureVisible(%d, %d)", (int) playlistIndex, (int) itemIndex);
ExecuteScript(Script);
}
/// <summary>
/// Called when a new playlist has been created.
/// </summary>
void UIElement::on_playlist_created(t_size playlistIndex, const char * name, t_size size)
{
const std::wstring Script = ::FormatText(L"onPlaylistCreated(%d, \"%s\")", (int) playlistIndex, ::UTF8ToWide(name, size).c_str());
ExecuteScript(Script);
}
/// <summary>
/// Called when the specified playlist has been renamed.
/// </summary>
void UIElement::on_playlist_renamed(t_size playlistIndex, const char * name, t_size size)
{
const std::wstring Script = ::FormatText(L"onPlaylistRenamed(%d, \"%s\")", (int) playlistIndex, ::UTF8ToWide(name, size).c_str());
ExecuteScript(Script);
}
/// <summary>
/// Called when the active playlist changes.
/// </summary>
void UIElement::on_playlist_activate(t_size oldPlaylistIndex, t_size newPlaylistIndex)
{
const std::wstring Script = ::FormatText(L"onPlaylistActivated(%d, %d)", (int) oldPlaylistIndex, (int) newPlaylistIndex);
ExecuteScript(Script);
}
/// <summary>
/// Called when the specified playlist has been locked or unlocked.
/// </summary>
void UIElement::on_playlist_locked(t_size playlistIndex, bool isLocked)
{
const std::wstring Script = ::FormatText(isLocked ? L"onPlaylistLocked(%d)" : L"onPlaylistUnlocked(%d)", (int) playlistIndex);
ExecuteScript(Script);
}
/// <summary>
/// Called when the selected items changed.
/// </summary>
void UIElement::on_items_selection_change(t_size playlistIndex, const bit_array & affectedItems, const bit_array & state)
{
t_size ItemCount = playlist_manager_v4::get()->playlist_get_item_count(playlistIndex);
const std::wstring Text = ToJSON(affectedItems, ItemCount);
const std::wstring Script = ::FormatText(L"onPlaylistSelectedItemsChanged(%d, \"%s\")", (int) playlistIndex, Text.c_str());
ExecuteScript(Script);
}
/// <summary>
/// Called when the focused item of a playlist changed.
/// </summary>
void UIElement::on_item_focus_change(t_size playlistIndex, t_size fromIndex, t_size toIndex)
{
const std::wstring Script = ::FormatText(L"onPlaylistFocusedItemChanged(%d, %d, %d)", (int) playlistIndex, (int) fromIndex, (int) toIndex);
ExecuteScript(Script);
}
/// <summary>
/// Called when the playlists have beenn reordered.
/// </summary>
void UIElement::on_playlists_reorder(const t_size * playlistOrder, t_size playlistCount)
{
const std::wstring Text = ToJSON(playlistOrder, playlistCount);
const std::wstring Script = ::FormatText(L"onPlaylistsReordered(\"%s\")", Text.c_str());
ExecuteScript(Script);
}
/// <summary>
/// Called when playlists are being removed.
/// </summary>
void UIElement::on_playlists_removing(const bit_array & mask, t_size oldCount, t_size newCount)
{
const std::wstring Text = ToJSON(mask, oldCount);
const std::wstring Script = ::FormatText(L"onPlaylistsRemoving(\"%s\", %d)", Text.c_str(), (int) newCount);
ExecuteScript(Script);
}
/// <summary>
/// Called when playlists have been removed.
/// </summary>
void UIElement::on_playlists_removed(const bit_array & mask, t_size oldCount, t_size newCount)
{
const std::wstring Text = ToJSON(mask, oldCount);
const std::wstring Script = ::FormatText(L"onPlaylistsRemoved(\"%s\", %d)", Text.c_str(), (int) newCount);
ExecuteScript(Script);
}
/// <summary>
/// Called when the default format has been changed.
/// </summary>
void UIElement::on_default_format_changed()
{
const std::wstring Script = L"onDefaultFormatChanged()";
ExecuteScript(Script);
}
/// <summary>
/// Called when the playback order changed.
/// </summary>
void UIElement::on_playback_order_changed(t_size playbackOrderIndex)
{
const std::wstring Script = ::FormatText(L"onPlaybackOrderChanged(%d)", (int) playbackOrderIndex);
ExecuteScript(Script);
}
/// <summary>
/// Executes a script.
/// </summary>
void UIElement::ExecuteScript(const std::wstring & script) const noexcept
{
if (_WebView == nullptr)
return;
HRESULT hr = _WebView->ExecuteScript(script.c_str(), nullptr);
if (!SUCCEEDED(hr))
console::print(::GetErrorMessage(hr, ::FormatText(STR_COMPONENT_BASENAME " failed to call %s", ::WideToUTF8(script).c_str())).c_str());
}
#pragma endregion