This repository has been archived by the owner on Oct 4, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathTaggerDialog.h
393 lines (346 loc) · 13.1 KB
/
TaggerDialog.h
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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
#pragma once
#include "FileTagMap.h"
#include "Query.h"
#include "TrackListView.h"
#include "TagWriter.h"
#include "ComboBox.h"
#include "ListView.h"
#include "RequestThread.h"
#include "Release.h"
#include "ReleaseGroup.h"
#include "Track.h"
namespace foo_musicbrainz {
class TaggerDialog : public CDialogImpl<TaggerDialog> {
private:
CListViewCtrl release_list;
ComboBox medium_list;
ComboBox label_info_list;
ListView track_list;
CComboBox type;
CComboBox status;
CEdit artist;
CEdit album;
CEdit date;
CEdit first_release_date;
CEdit barcode;
CEdit url;
CEdit discsubtitle;
CEdit label;
CEdit catalog;
CButton groupbox;
ReleaseList *mbc;
pfc::list_t<metadb_handle_ptr> tracks;
TrackListView track_list_view;
bool loaded;
size_t current_release;
size_t current_medium;
size_t current_label_info;
public:
enum { IDD = IDD_TAGGER };
enum columns {
artist_column,
release_column,
date_column,
label_column
};
TaggerDialog(foo_musicbrainz::Query *query, pfc::list_t<metadb_handle_ptr> _tracks) :
CDialogImpl<TaggerDialog>(),
tracks(_tracks),
loaded(false),
current_release(0),
current_medium(0),
current_label_info(0)
{
mbc = new ReleaseList();
Create(core_api::get_main_window());
threaded_process::g_run_modeless(new service_impl_t<foo_musicbrainz::RequestThread>(query, m_hWnd, mbc, &tracks),
threaded_process::flag_show_progress | threaded_process::flag_show_abort, m_hWnd, "Querying data from MusicBrainz");
}
BEGIN_MSG_MAP(TaggerDialog)
MSG_WM_INITDIALOG(OnInitDialog)
MSG_WM_SHOWWINDOW(OnShowWindow)
MSG_WM_CLOSE(OnClose)
NOTIFY_HANDLER_EX(IDC_RELEASE_LIST, LVN_ITEMCHANGED, OnReleaseListChange)
NOTIFY_HANDLER_EX(IDC_TRACK_LIST, NM_CLICK, OnTrackListClick)
NOTIFY_HANDLER_EX(IDC_URL, NM_CLICK, OnLink)
NOTIFY_HANDLER_EX(IDC_URL, NM_RETURN, OnLink)
COMMAND_ID_HANDLER_EX(IDCANCEL, OnCancel)
COMMAND_ID_HANDLER_EX(IDOK, OnOk)
COMMAND_HANDLER_EX(IDC_TYPE, CBN_SELENDOK, OnTypeChange)
COMMAND_HANDLER_EX(IDC_STATUS, CBN_SELENDOK, OnStatusChange)
COMMAND_HANDLER_EX(IDC_ARTIST, EN_UPDATE, OnArtistUpdate)
COMMAND_HANDLER_EX(IDC_ALBUM, EN_UPDATE, OnAlbumUpdate)
COMMAND_HANDLER_EX(IDC_DATE, EN_UPDATE, OnDateUpdate)
COMMAND_HANDLER_EX(IDC_FIRST_RELEASE_DATE, EN_UPDATE, on_first_release_date_update)
COMMAND_HANDLER_EX(IDC_BARCODE, EN_UPDATE, on_barcode_update)
COMMAND_HANDLER_EX(IDC_MEDIUM_LIST, CBN_SELCHANGE, on_medium_change)
COMMAND_HANDLER_EX(IDC_LABEL_INFO_LIST, CBN_SELCHANGE, on_label_info_change)
COMMAND_HANDLER_EX(IDC_SUBTITLE, EN_UPDATE, on_disc_subtitle_update)
COMMAND_HANDLER_EX(IDC_LABEL, EN_UPDATE, on_label_info_update)
COMMAND_HANDLER_EX(IDC_CATALOG, EN_UPDATE, on_label_info_update)
//CHAIN_MSG_MAP(CDialogImpl<TaggerDialog>)
END_MSG_MAP()
Release *get_current_release() {
return mbc->get(current_release);
}
Medium *get_current_medium() {
return get_current_release()->get_medium(current_medium);
}
LabelInfo *get_current_label_info() {
return get_current_release()->get_label_info(current_label_info);
}
bool OnInitDialog(CWindow wndFocus, LPARAM lInitParam) {
static_api_ptr_t<modeless_dialog_manager>()->add(m_hWnd);
release_list = GetDlgItem(IDC_RELEASE_LIST);
medium_list.Attach(GetDlgItem(IDC_MEDIUM_LIST));
label_info_list.Attach(GetDlgItem(IDC_LABEL_INFO_LIST));
track_list = GetDlgItem(IDC_TRACK_LIST);
type = GetDlgItem(IDC_TYPE);
status = GetDlgItem(IDC_STATUS);
url = GetDlgItem(IDC_URL);
artist = GetDlgItem(IDC_ARTIST);
album = GetDlgItem(IDC_ALBUM);
date = GetDlgItem(IDC_DATE);
first_release_date = GetDlgItem(IDC_FIRST_RELEASE_DATE);
barcode = GetDlgItem(IDC_BARCODE);
discsubtitle = GetDlgItem(IDC_SUBTITLE);
label = GetDlgItem(IDC_LABEL);
catalog = GetDlgItem(IDC_CATALOG);
groupbox = GetDlgItem(IDC_CHOOSE_DISC);
track_list_view.Attach(track_list);
// List view styles
auto styles = LVS_EX_FULLROWSELECT | LVS_EX_LABELTIP;
release_list.SetExtendedListViewStyle(styles, styles);
track_list.SetExtendedListViewStyle(styles, styles);
// Adding release list columns
listview_helper::insert_column(release_list, artist_column, "Artist", 104);
listview_helper::insert_column(release_list, release_column, "Release", 110);
listview_helper::insert_column(release_list, date_column, "Date", 45);
listview_helper::insert_column(release_list, label_column, "Label/Cat#", 80);
// Adding track list columns
listview_helper::insert_column(track_list, 0, "", 0); // Fake column
track_list.InsertColumn(1, L"#", LVCFMT_RIGHT, 30);
track_list.DeleteColumn(0);
listview_helper::insert_column(track_list, 1, "Title", 260);
for (auto i = 0; i < ReleaseGroup::type_count; i++) {
pfc::stringcvt::string_os_from_utf8 str(ReleaseGroup::types[i]);
type.AddString(str);
}
for (auto i = 0; i < Release::status_count; i++) {
pfc::stringcvt::string_os_from_utf8 str(Release::statuses[i]);
status.AddString(str);
}
return true;
}
void OnShowWindow(BOOL bShow, UINT nStatus) {
SetMsgHandled(FALSE);
if (loaded) return;
loaded = true;
for (unsigned int i = 0; i < mbc->count(); i++) {
auto release = mbc->get(i);
// Artist
listview_helper::insert_item(release_list, i, release->get_artist_credit()->get_name(), NULL);
// Title
listview_helper::set_item_text(release_list, i, release_column, release->get_title());
// Date
listview_helper::set_item_text(release_list, i, date_column, static_cast<pfc::string8>(release->get_date()));
// Label
if (release->label_info_count() == 0) {
release->add_label_info(new LabelInfo());
}
listview_helper::set_item_text(release_list, i, label_column, release->get_label_info(0)->get_info());
}
UpdateRelease();
}
void UpdateRelease() {
Release *release = get_current_release();
// Artist
uSetWindowText(artist, release->get_artist_credit()->get_name());
// Album
uSetWindowText(album, release->get_title());
// Date
uSetWindowText(date, static_cast<pfc::string8>(release->get_date()));
// First release date
uSetWindowText(first_release_date, static_cast<pfc::string8>(release->get_release_group()->get_first_release_date()));
// Barcode
uSetWindowText(barcode, release->get_barcode());
// Type
type.SetCurSel(get_current_release()->get_release_group()->get_type_index());
// Status
status.SetCurSel(get_current_release()->get_status_index());
// VA?
if (track_list.GetColumnWidth(2) && !release->is_various()) {
track_list.SetColumnWidth(1, 260);
track_list.DeleteColumn(2);
} else if (!track_list.GetColumnWidth(2) && release->is_various()) {
track_list.SetColumnWidth(1, 195);
listview_helper::insert_column(track_list, 2, "Track artist", 130);
}
// Media
medium_list.DeleteAll();
for (size_t i = 0; i < release->medium_count(); i++) {
auto info = release->get_medium(i)->get_info();
medium_list.AddString(pfc::stringcvt::string_os_from_utf8(info));
}
if (current_medium >= release->medium_count()) {
current_medium = 0;
}
medium_list.SetCurSel(current_medium);
update_medium();
// "Choose disc"
if (release->track_count() > tracks.get_count()) {
uSetWindowText(groupbox, "Discs (choose one)");
} else {
uSetWindowText(groupbox, "Discs");
}
// Labels
label_info_list.DeleteAll();
for (size_t i = 0; i < release->label_info_count(); i++) {
auto info = release->get_label_info(i)->get_info();
label_info_list.AddString(pfc::stringcvt::string_os_from_utf8(info));
}
current_label_info = 0;
label_info_list.SetCurSel(0);
update_label_info();
// Link
pfc::string8 url_string = "<a href=\"http://musicbrainz.org/release/";
url_string += release->get_id();
url_string += "\">MusicBrainz release page</a>";
uSetWindowText(url, url_string);
}
void update_tracks() {
auto medium = get_current_medium();
track_list_view.set_medium(medium);
track_list.Resize(medium->track_count());
for (size_t item = 0; item < medium->track_count(); item++) {
pfc::string8 position;
position << medium->get_track(item)->get_position();
listview_helper::set_item_text(track_list, item, 0, position);
auto track = medium->get_track(item);
listview_helper::set_item_text(track_list, item, 1, track->get_title());
listview_helper::set_item_text(track_list, item, 2, track->get_artist_credit()->get_name());
}
}
void update_medium() {
auto release = get_current_release();
auto medium = get_current_medium();
uSetWindowText(discsubtitle, medium->get_title());
// Tracks
update_tracks();
}
void update_label_info() {
auto label_info = get_current_label_info();
uSetWindowText(label, label_info->get_name());
uSetWindowText(catalog, label_info->get_catalog_number());
}
LRESULT OnTrackListClick(LPNMHDR pnmh) {
if (((LPNMITEMACTIVATE)pnmh)->iItem != -1 && ((LPNMITEMACTIVATE)pnmh)->iSubItem != 0) {
track_list_view.Start(((LPNMITEMACTIVATE)pnmh)->iItem, ((LPNMITEMACTIVATE)pnmh)->iSubItem);
}
return 0;
}
LRESULT on_medium_change(UINT, int, CWindow) {
current_medium = medium_list.GetCurSel();
update_medium();
return 0;
}
LRESULT on_label_info_change(UINT, int, CWindow) {
current_label_info = label_info_list.GetCurSel();
update_label_info();
return 0;
}
LRESULT OnReleaseListChange(LPNMHDR pnmh) {
if (((LPNMLISTVIEW)pnmh)->iItem != -1 && ((LPNMLISTVIEW)pnmh)->uChanged & LVIS_DROPHILITED && ((LPNMLISTVIEW)pnmh)->uNewState & LVIS_SELECTED) {
if (current_release != ((LPNMITEMACTIVATE)pnmh)->iItem) {
if (track_list_view.IsActive()) track_list_view.Abort();
current_release = ((LPNMITEMACTIVATE)pnmh)->iItem;
UpdateRelease();
}
}
return 0;
}
LRESULT OnLink(LPNMHDR pnmh) {
ShellExecute(NULL, L"open", ((PNMLINK)pnmh)->item.szUrl, NULL, NULL, SW_SHOW);
return 0;
}
void OnClose() {
DestroyWindow();
}
void OnFinalMessage(HWND hwnd) {
static_api_ptr_t<modeless_dialog_manager>()->remove(m_hWnd);
delete mbc;
delete this;
}
void OnCancel(UINT uNotifyCode, int nID, CWindow wndCtl) {
DestroyWindow();
}
void OnOk(UINT uNotifyCode, int nID, CWindow wndCtl) {
FileTagMap file_tag_map(*get_current_release(), tracks, current_medium);
static_api_ptr_t<metadb_io_v2>()->update_info_async(tracks,
new service_impl_t<TagWriter>(file_tag_map),
core_api::get_main_window(), metadb_io_v2::op_flag_delay_ui, nullptr);
DestroyWindow();
}
void OnTypeChange(UINT uNotifyCode, int nID, CWindow wndCtl) {
get_current_release()->get_release_group()->set_type(type.GetCurSel());
}
void OnStatusChange(UINT uNotifyCode, int nID, CWindow wndCtl) {
get_current_release()->set_status(status.GetCurSel());
}
void OnArtistUpdate(UINT uNotifyCode, int nID, CWindow wndCtl) {
pfc::string8 str;
uGetWindowText(artist, str);
get_current_release()->get_artist_credit()->set_name(str);
listview_helper::set_item_text(release_list, current_release, artist_column, str);
}
void OnAlbumUpdate(UINT uNotifyCode, int nID, CWindow wndCtl) {
pfc::string8 str;
uGetWindowText(album, str);
get_current_release()->set_title(str);
listview_helper::set_item_text(release_list, current_release, release_column, str);
}
void OnDateUpdate(UINT uNotifyCode, int nID, CWindow wndCtl) {
pfc::string8 str;
uGetWindowText(date, str);
get_current_release()->set_date(Date(str));
listview_helper::set_item_text(release_list, current_release, date_column,
static_cast<pfc::string8>(get_current_release()->get_date()));
}
void on_first_release_date_update(UINT uNotifyCode, int nID, CWindow wndCtl) {
pfc::string8 str;
uGetWindowText(first_release_date, str);
get_current_release()->get_release_group()->set_first_release_date(Date(str));
}
void on_barcode_update(UINT, int, CWindow) {
pfc::string8 barcode_value;
uGetWindowText(barcode, barcode_value);
get_current_release()->set_barcode(barcode_value);
}
void on_disc_subtitle_update(UINT, int, CWindow) {
pfc::string8 str;
uGetWindowText(discsubtitle, str);
auto medium = get_current_medium();
medium->set_title(str);
pfc::stringcvt::string_os_from_utf8 info(medium->get_info());
medium_list.SetCurrentString(info);
}
void on_label_info_update(UINT, int id, CWindow ctrl) {
pfc::string8 str;
uGetWindowText(ctrl, str);
auto label_info = get_current_label_info();
switch (id) {
case IDC_LABEL:
label_info->set_name(str);
break;
case IDC_CATALOG:
label_info->set_catalog_number(str);
break;
}
pfc::stringcvt::string_os_from_utf8 info(label_info->get_info());
label_info_list.SetCurrentString(info);
if (current_label_info == 0) {
release_list.SetItemText(current_release, label_column, info);
}
}
};
}