-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfind_release_dialog.cpp
More file actions
1249 lines (907 loc) · 32.4 KB
/
find_release_dialog.cpp
File metadata and controls
1249 lines (907 loc) · 32.4 KB
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
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "stdafx.h"
#include "configuration_dialog.h"
#include "tasks.h"
#include "utils.h"
#include "utils_db.h"
#include "tag_mappings_dialog.h"
#include "find_release_dialog.h"
// {F924481B-17A0-423F-B1A6-07293DC46810}
static const GUID guid_cfg_dialog_position_find_release_dlg = { 0xf924481b, 0x17a0, 0x423f, { 0xb1, 0xa6, 0x7, 0x29, 0x3d, 0xc4, 0x68, 0x10 } };
static cfgDialogPosition cfg_dialog_position_find_release_dlg(guid_cfg_dialog_position_find_release_dlg);
void load_global_icons() {
auto dpiX = QueryScreenDPIEx(core_api::get_main_window()).cx;
bool bdark = fb2k::isDarkMode();
g_hIcon_quian = LoadDpiIconResource(!bdark ? Icon::Quian : Icon::Quian_Dark, dpiX);
g_hIcon_rec = LoadDpiBitmapResource(Icon::Record, bdark);
}
// constructor
CFindReleaseDialog::CFindReleaseDialog(HWND p_parent, metadb_handle_list items, foo_conf cfg) : m_items(items), conf(cfg),
m_va(false), cewb_artist_search(), cewb_release_filter(), cewb_release_url(), m_dctree(this, &m_tracer), m_alist(this, &m_tracer) {
load_global_icons();
//HWND
m_artist_list = nullptr;
m_release_tree = nullptr;
m_edit_artist = nullptr;
m_edit_release = nullptr;
m_edit_filter = nullptr;
//..
m_updating_releases = false;
m_tickCount = 0;
static_api_ptr_t<titleformat_compiler>()->compile_force(m_album_name_script, "[%album%]");
static_api_ptr_t<titleformat_compiler>()->compile_force(m_artist_name_script, "[%artist%]");
static_api_ptr_t<titleformat_compiler>()->compile_force(m_album_artist_script, "[%album artist%]");
}
CFindReleaseDialog::~CFindReleaseDialog() {
if (g_discogs) {
awt_update_mod_flag(/*fromFlag*/false);
if (!g_discogs->tag_mappings_dialog) {
//lo former, hi current: back to normal mode
CONF.mode_write_alt = MAKELPARAM(HIWORD(CONF.mode_write_alt), 0);
}
#ifdef SIM_VA_MA_BETA
//disable
CONF.find_release_dlg_flags &= ~FLG_VARIOUS_AS_MULTI_ARTIST;
g_clear_va_ma_releases();
#endif
g_discogs->find_release_dialog = nullptr;
}
}
void CFindReleaseDialog::show() /*override*/ {
if (g_discogs->find_release_artist_dialog) {
::ShowWindow(g_discogs->find_release_artist_dialog->m_hWnd, SW_SHOW);
}
MyCDialogImpl::show();
}
void CFindReleaseDialog::hide() /*override*/ {
if (g_discogs->find_release_artist_dialog) {
::ShowWindow(g_discogs->find_release_artist_dialog->m_hWnd, SW_HIDE);
}
MyCDialogImpl::hide();
}
void CFindReleaseDialog::enable(bool is_enabled) /*override*/ {
//..
}
void CFindReleaseDialog::enable_alt(bool is_enabled) {
if (CONF.awt_get_alt_mode()) { uSetWindowText(m_hWnd, "Find Releases (PWT)"); }
else { uSetWindowText(m_hWnd, "Find Releases"); }
HWND h1 = GetDlgItem(IDC_RELEASE_URL_TEXT);
HWND h2 = GetDlgItem(IDC_BTN_PROCESS_RELEASE);
HWND h3 = GetDlgItem(IDC_LABEL_RELEASE_ID);
HWND h4 = GetDlgItem(IDC_BTN_CONFIGURE);
for (HWND walk = ::GetWindow(m_hWnd, GW_CHILD); walk != NULL; ) {
HWND next = ::GetWindow(walk, GW_HWNDNEXT);
if (is_enabled && next != h1 && next != h2 && next != h3 && next != h4)
::uEnableWindow(next, !is_enabled);
else if (!is_enabled) {
//..
return;
}
walk = next;
}
}
// settings
void CFindReleaseDialog::pushcfg() {
if (build_current_cfg()) {
CONF.save(CConf::cfgFilter::FIND, conf);
CONF.load();
}
}
inline bool CFindReleaseDialog::build_current_cfg() {
bool bres = false;
bool bcheck = IsDlgButtonChecked(IDC_CHK_ONLY_EXACT_MATCHES);
if (CONF.display_exact_matches != bcheck) {
conf.display_exact_matches = bcheck;
bres |= true;
}
if ((CONF.find_release_filter_flag & FilterFlag::Versions) != (conf.find_release_filter_flag & FilterFlag::Versions)) {
bres |= true;
}
if ((CONF.find_release_filter_flag & FilterFlag::RoleMain) != (conf.find_release_filter_flag & FilterFlag::RoleMain)) {
bres |= true;
}
//bind artist profile panel
size_t attach_flagged = (IsDlgButtonChecked(IDC_CHK_RELEASE_SHOW_PROFILE) == BST_CHECKED) ?
FLG_PROFILE_DLG_SHOW : 0;
size_t open_flagged = g_discogs->find_release_artist_dialog ? FLG_PROFILE_DLG_ATTACHED : 0;
conf.find_release_dlg_flags &= ~(FLG_PROFILE_DLG_SHOW | FLG_PROFILE_DLG_ATTACHED);
conf.find_release_dlg_flags |= (attach_flagged | open_flagged);
int mask = ~(~0 << 3);
if ((CONF.find_release_dlg_flags & mask) != (conf.find_release_dlg_flags & mask)) {
bres |= true;
}
return bres;
}
void CFindReleaseDialog::init_cfged_dialog_controls() {
// TEXT BOX RETURN OVERRIDE
set_enter_key_override(conf.release_enter_key_override);
//INIT HISTORY, HISTORY OVERRIDE
size_t max_items = LOWORD(conf.history_enabled_max);
if (conf.history_enabled()) {
m_oplogger.init(conf.history_enabled(), max_items);
}
//init artist profile panel
if (conf.find_release_dlg_flags & flg_fr::FLG_PROFILE_DLG_SHOW) {
uButton_SetCheck(m_hWnd, IDC_CHK_RELEASE_SHOW_PROFILE, true);
if (conf.find_release_dlg_flags & flg_fr::FLG_PROFILE_DLG_ATTACHED) {
if (!g_discogs->find_release_artist_dialog) {
// new profile dlg
g_discogs->find_release_artist_dialog =
fb2k::newDialog<CFindReleaseArtistDialog>(core_api::get_main_window(), SW_HIDE);
}
}
}
// tree stats
if (conf.find_release_dlg_flags & flg_fr::FLG_SHOW_RELEASE_TREE_STATS) {
print_root_stats(m_row_stats, false/*save*/);
}
else {
pfc::string8 artist_name = m_alist.Get_Artist() ? m_alist.Get_Artist()->name : "";
pfc::string8 artist_id = m_alist.Get_Artist() ? m_alist.Get_Artist()->id : "";
rppair row_stats{ std::pair("",""), std::pair(artist_name, artist_id) };
print_root_stats(row_stats, /*overwrite*/ !m_row_stats.second.first.get_length());
}
}
// message map
LRESULT CFindReleaseDialog::OnButtonNext(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/) {
pfc::string8 release_id;
release_id = trim(uGetWindowText(m_edit_release).c_str());
if (is_number(release_id.c_str()) || id_from_url(m_edit_release, release_id)) {
trigger_release(release_id);
}
return TRUE;
}
//from Enter key hook
bool CFindReleaseDialog::ForwardVKReturn()
{
HWND hwnd = GetFocus();
if (hwnd == m_artist_list) {
m_alist.Default_Action();
return true;
}
else if (hwnd == m_release_tree) {
m_dctree.vkreturn_test_master_expand_release();
//want return
return true;
}
return false;
}
bool OAuthCheck(const foo_conf& conf) {
if (!g_discogs->gave_oauth_warning && (!conf.oauth_token.get_length() || !conf.oauth_token_secret.get_length())) {
g_discogs->gave_oauth_warning = true;
if (!g_discogs->configuration_dialog) {
static_api_ptr_t<ui_control>()->show_preferences(guid_pref_page);
}
if (CConfigurationDialog* dlg = g_discogs->configuration_dialog) {
dlg->show_oauth_msg("Please configure OAuth.", true);
::SetFocus(dlg->m_hWnd);
}
return false;
}
return true;
}
// on init dialog
#define OVRCEDIT
#define VKHOOK
bool CFindReleaseDialog::get_VA_search_str(pfc::string8& out) {
size_t max_search_artists = 3;
size_t ileft = max_search_artists;
std::vector<pfc::string8> vsa;
for (auto witem : m_items) {
bool badd = false;
pfc::string8 buffer;
witem->format_title(nullptr, buffer, m_artist_name_script, nullptr);
if (ileft == max_search_artists) {
if (buffer.get_length()) {
badd = true;
}
}
else {
if (std::find(vsa.begin(), vsa.end(), buffer) == vsa.end()) {
badd = true;
}
}
if (badd) {
vsa.emplace_back(buffer);
--ileft;
}
if (!ileft) {
break;
}
}
std::ostringstream oss;
if (vsa.size() > 1)
{
std::copy(vsa.begin(), vsa.end() - 1, std::ostream_iterator<pfc::string8>(oss, "+"));
oss << vsa.back();
out = oss.str().c_str();
return true;
}
else {
return false;
}
}
LRESULT CFindReleaseDialog::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/) {
SetIcon(g_discogs->icon);
enable_alt(CONF.awt_get_alt_mode());
m_edit_artist = GetDlgItem(IDC_EDIT_SEARCH);
m_edit_filter = GetDlgItem(IDC_EDIT_FILTER);
m_edit_release = GetDlgItem(IDC_RELEASE_URL_TEXT);
m_artist_list = GetDlgItem(IDC_ARTIST_LIST);
m_release_tree = GetDlgItem(IDC_RELEASE_TREE);
cewb_artist_search.SubclassWindow(m_edit_artist);
cewb_release_filter.SubclassWindow(m_edit_filter);
cewb_release_url.SubclassWindow(m_edit_release);
set_history_key_override();
cewb_release_filter.SetEnterEscHandlers();
cewb_artist_search.SetEnterEscHandlers();
cewb_release_url.SetEnterEscHandlers();
m_artist_link.SubclassWindow(GetDlgItem(IDC_STATIC_FIND_REL_STATS));
COLORREF lnktx = m_dark.IsDark() ? GetSysColor(/*COLOR_BTNHIGHLIGHT*/COLOR_MENUHILIGHT) : (COLORREF)(-1);
m_artist_link.m_clrLink = lnktx;
m_artist_link.m_clrVisited = lnktx;
// init cfged
init_cfged_dialog_controls();
bool db_ready_to_search = false;
// retreive selection info
pfc::string8 frm_album;
pfc::string8 frm_artist;
pfc::string8 frm_album_artist;
// album name, artist name, album artist
metadb_handle_ptr item = m_items[0];
item->format_title(nullptr, frm_album, m_album_name_script, nullptr); //ALBUM
item->format_title(nullptr, frm_artist, m_artist_name_script, nullptr); //ARTIST
item->format_title(nullptr, frm_album_artist, m_album_artist_script, nullptr); //ALBUM ARTIST
bool bvarious = STR_EQUAL(frm_album_artist, "VA") || frm_album_artist.has_prefix("VA ");
bvarious |= frm_album_artist.toLower().has_prefix("various") /*|| frm_album_artist.toLower().has_prefix("various artists")*/;
bvarious |= frm_album_artist.toLower().has_prefix("varios") /*|| frm_album_artist.toLower().has_prefix("varios artistas")*/;
m_va = bvarious;
if (m_va) {
pfc::string8 buffer;
if (get_VA_search_str(buffer)) {
m_va_search = buffer;
}
}
//init versions-roles checkboxes
if (conf.find_release_filter_flag & FilterFlag::Versions) {
uButton_SetCheck(m_hWnd, IDC_CHK_FIND_RELEASE_FILTER_VERS, true);
}
if (conf.find_release_filter_flag & FilterFlag::RoleMain) {
uButton_SetCheck(m_hWnd, IDC_CHK_FIND_RELEASE_FILTER_ROLEMAIN, true);
}
if (m_va_search.get_length()) {
::EnableWindow(uGetDlgItem(IDC_CHK_FIND_RELEASE_FILTER_ROLEMAIN), false);
conf.find_release_filter_flag &= ~(FilterFlag::RoleMain);
}
// init tracer
m_tracer.init_tracker_tags(m_items);
// use album artist or artist name
const char* artist = frm_album_artist.get_length() ? frm_album_artist.get_ptr() :
frm_artist.get_length() ? frm_artist.get_ptr() : "";
//init artist search/release id textboxes
if (!m_tracer.has_release() && CONF.awt_get_alt_mode()) {
file_info_impl finfo;
metadb_handle_ptr item = m_items[0];
item->get_info(finfo);
pfc::string8 release_id;
if (g_discogs->file_info_get_tag(item, finfo, "WWW", release_id)) {
uSetWindowText(m_edit_release, m_tracer.has_release() ? std::to_string(m_tracer.release_id).c_str() : release_id);
if (id_from_url(m_edit_release, release_id)) {
m_tracer.release_id = std::atoi(release_id); //tracer
m_tracer.release_tag = true;
}
}
}
else {
uSetWindowText(m_edit_release, m_tracer.has_release() ? std::to_string(m_tracer.release_id).c_str() : "");
}
if (m_va && m_va_search.get_length()) {
uSetWindowText(m_edit_artist, m_va_search);
uSetWindowText(uGetDlgItem(IDC_BTN_SEARCH), "Search VA");
}
else {
uSetWindowText(m_edit_artist, artist ? artist : "");
}
// dlg resize and dimensions
DlgResize_Init(mygripp.enabled, true);
cfg_dialog_position_find_release_dlg.AddWindow(m_hWnd);
HWND wndReplace = ::GetDlgItem(m_hWnd, IDC_ARTIST_LIST);
m_alist.CreateInDialog(*this, IDC_ARTIST_LIST, wndReplace);
m_alist.InitializeHeaderCtrl(HDS_HIDDEN);
m_artist_list = m_alist.m_hWnd;
if (CONF.awt_get_alt_mode()) {
//..
}
else {
m_alist.Inititalize();
}
m_dctree.Inititalize(m_release_tree, m_edit_filter, m_edit_release, m_items, frm_album /*ALBUM*/);
SetWindowSubclass(m_artist_list, EnterKeySubclassProc, 0, 0);
SetWindowSubclass(m_release_tree, EnterKeySubclassProc, 0, 0);
// dark mode
m_dark.AddDialog(m_hWnd);
m_dark.AddControls(m_hWnd);
CustomFont(m_hWnd, HIWORD(conf.custom_font));
{
bool brelease_ided = m_tracer.release_tag && m_tracer.release_id != pfc_infinite;
bool bskip_ided = conf.skip_mng_flag & SkipMng::RELEASE_DLG_IDED;
bool cfg_always_load_artist_ided_preview = /*force*/true && !CONF.awt_get_alt_mode();
if (!(bskip_ided && brelease_ided)) {
//route
pfc::string8 artist_meta = trim(uGetWindowText(m_edit_artist));
route_artist_search(artist_meta, false, m_tracer.artist_tag);
}
else
{
if (cfg_always_load_artist_ided_preview && m_tracer.artist_tag) {
//route
pfc::string8 artist_meta = trim(uGetWindowText(m_edit_artist));
route_artist_search(artist_meta, false, true);
}
}
}
//..
//album filter textbox
block_filter_box_events(true);
uSetWindowText(m_edit_filter, frm_album);
block_filter_box_events(false);
HWND hwnd = uGetDlgItem(IDC_STATIC_FIND_REL_SEARCH_STATS);
::ShowWindow(hwnd, SW_HIDE);
// SHOW RELEASE DLG OR SKIP TO MATCH TRACKS
if (OAuthCheck(conf) || (db_ready_to_search)) {
bool brelease_ided = m_tracer.release_tag && m_tracer.release_id != pfc_infinite;
bool bskip_ided = conf.skip_mng_flag & SkipMng::RELEASE_DLG_IDED;
//autofill release id
uSetWindowText(m_edit_release, brelease_ided ? std::to_string(m_tracer.release_id).c_str() : "");
if (bskip_ided && brelease_ided) {
//.. skip find release dialog
trigger_release(std::to_string(m_tracer.release_id).c_str());
//..
return FALSE;
}
else {
//.. Find Release dialog
show();
//default buttons
UINT default_button = 0;
if (m_tracer.has_amr() || m_tracer.release_tag) {
default_button = IDC_BTN_PROCESS_RELEASE;
}
else if (!artist) {
default_button = IDC_EDIT_SEARCH;
}
else if (artist) {
default_button = IDC_BTN_SEARCH;
}
if (default_button) {
uSendMessage(m_hWnd, WM_NEXTDLGCTL, (WPARAM)(HWND)GetDlgItem(default_button), TRUE);
}
else {
uSendMessage(m_hWnd, WM_NEXTDLGCTL, (WPARAM)(HWND)cewb_release_filter, TRUE);
}
}
}
else {
show();
}
//prevent default control focus
return FALSE;
}
LRESULT CFindReleaseDialog::OnContextMenu(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) {
HWND hwndCtrl = (HWND)wParam;
HWND hwndArtistList = GetDlgItem(IDC_ARTIST_LIST);
HWND hwndReleaseTree = GetDlgItem(IDC_RELEASE_TREE);
if (hwndCtrl != hwndArtistList && hwndCtrl != hwndReleaseTree) {
bHandled = TRUE;
}
else {
//artist list and release tree are chained
bHandled = FALSE;
}
//return value is meaningless
return FALSE;
}
LRESULT CFindReleaseDialog::OnDestroy(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/) {
pushcfg();
if (g_discogs) {
//destroy artist panel instance
if (g_discogs->find_release_artist_dialog
&& (conf.find_release_dlg_flags & (FLG_PROFILE_DLG_SHOW | FLG_PROFILE_DLG_ATTACHED)) == (FLG_PROFILE_DLG_SHOW | FLG_PROFILE_DLG_ATTACHED)) {
g_discogs->find_release_artist_dialog->DestroyWindow();
}
}
cfg_dialog_position_find_release_dlg.RemoveWindow(m_hWnd);
KillTimer(KTypeFilterTimerID);
return FALSE;
}
LRESULT CFindReleaseDialog::OnButtonSearch(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/) {
pfc::string8 artist_meta = trim(uGetWindowText(m_edit_artist));
bool force_get_by_id = id_from_url(m_edit_artist, artist_meta);
if (artist_meta.get_length()) {
route_artist_search(artist_meta, true, force_get_by_id);
}
return FALSE;
}
void CFindReleaseDialog::on_get_artist_done(cupdRelSrc updsrc, Artist_ptr& artist) {
auto list_artist_p = m_alist.Get_Selected_Id();
auto selection_ok = !list_artist_p.get_length() || list_artist_p.equals(artist->id);
if (!selection_ok) {
return;
}
m_alist.on_get_artist_done(updsrc, artist);
if (m_dctree.Get_Size() && m_dctree.Get_Artist().get() && atoi(m_dctree.Get_Artist()->id) == atoi(artist->id)) {
return;
}
cupdRelSrc cupdsrc = updsrc;
if (cupdsrc == updRelSrc::ArtistProfile) {
cupdsrc.extended |= ol::full_cache() && conf.auto_rel_load_on_select;
}
if (cupdsrc.oninit || cupdsrc == updRelSrc::ArtistList || (!cupdsrc.oninit && cupdsrc == updRelSrc::ArtistProfile && cupdsrc.extended)) {
m_dctree.on_get_artist_done(cupdsrc, artist);
if (conf.auto_rel_load_on_open || cupdsrc.extended) {
if ((cupdsrc == updRelSrc::ArtistList || updsrc == updRelSrc::UndefFast) && m_dctree.Get_Size() && m_tracer.has_master()) {
m_dctree.OnInitExpand(mounted_param(m_tracer.master_i, ~0, true, false).lparam());
}
}
}
}
void CFindReleaseDialog::on_search_artist_done(const pfc::array_t<Artist_ptr>& p_artist_exact_matches, const pfc::array_t<Artist_ptr>& p_artist_other_matches, bool append) {
bool exact_matches = IsDlgButtonChecked(IDC_CHK_ONLY_EXACT_MATCHES) == BST_CHECKED;
HWND hwnd = uGetDlgItem(IDC_STATIC_FIND_REL_SEARCH_STATS);
if (!(p_artist_exact_matches.get_count() || p_artist_other_matches.get_count())) {
uSetWindowText(hwnd, "No matches found");
::ShowWindow(hwnd, SW_SHOW);
}
else {
uSetWindowText(hwnd, "");
}
if (!p_artist_exact_matches.get_count() && p_artist_other_matches.get_count()) {
CheckDlgButton(IDC_CHK_ONLY_EXACT_MATCHES, false);
}
if (m_tracer.is_multi_artist()) {
m_alist.set_artists(exact_matches, append, nullptr, p_artist_exact_matches, p_artist_other_matches);
}
else {
m_alist.set_artists(exact_matches, append, nullptr, p_artist_exact_matches, p_artist_other_matches);
}
//spawns on list item selection (not by default)
if (!append) {
m_alist.fill_artist_list(exact_matches, m_tracer.has_amr(), updRelSrc::ArtistSearch);
}
}
std::pair<rppair_t, rppair_t> CFindReleaseDialog::update_releases(const pfc::string8& filter, updRelSrc updsrc, bool init_expand) {
std::pair<rppair_t, rppair_t> res;
m_dctree.EnableDispInfo(false);
bool brolemain_filter = conf.find_release_filter_flag & FilterFlag::RoleMain;
// forward update releases
res = m_dctree.update_releases(filter, updsrc, init_expand, brolemain_filter);
m_dctree.EnableDispInfo(true);
return res;
}
void CFindReleaseDialog::OnTypeFilterTimer(WPARAM id)
{
if (id == KTypeFilterTimerID) {
switch (++m_tickCount) {
case 1:
break;
case 2:
break;
case 3:
pfc::string8 strFilter = trim(uGetWindowText(m_edit_filter));
if (!is_filter_autofill_enabled() && strFilter.get_length()) {
rppair row;
row.first.first = strFilter;
try {
add_history(oplog_type::filter, kHistoryFilterButton, row);
}
catch (foo_discogs_exception e) {
pfc::string8 error;
error << ("(skipped) ") << e.what() << "\n";
completion_notify::ptr reply;
popup_message_v3::query_t query = { "Information",
error.c_str(), popup_message::icon_error,
popup_message_v3::buttonOK,
popup_message_v3::iconQuestion,
reply
};
popup_message_v3::get()->show_query_modal(query);
}
}
//..
apply_filter(strFilter);
//..
KillTimer(KTypeFilterTimerID);
break;
}
}
}
void CFindReleaseDialog::apply_filter(pfc::string8 strFilter, bool force_redraw, bool force_rebuild) {
// forwarded apply_filter
m_dctree.apply_filter(strFilter, force_redraw, force_rebuild);
}
LRESULT CFindReleaseDialog::OnEditFilter(WORD wNotifyCode, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/) {
if (is_filter_box_event_enabled() && wNotifyCode == EN_CHANGE) {
//supress auto-fill filter box on user interaction
block_autofill_release_filter(true);
pfc::string8 buffer = trim(uGetWindowText(m_edit_filter));
if (buffer.length()) {
KFilterTimerOn(m_hWnd);
}
else {
KillTimer(KTypeFilterTimerID);
//..
apply_filter(buffer);
//..
}
}
return false;
}
LRESULT CFindReleaseDialog::OnCheckboxBindProfilePanel(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/) {
bool state = IsDlgButtonChecked(IDC_CHK_RELEASE_SHOW_PROFILE);
conf.find_release_dlg_flags =
state ?
conf.find_release_dlg_flags | flg_fr::FLG_PROFILE_DLG_ATTACHED
: conf.find_release_dlg_flags & ~flg_fr::FLG_PROFILE_DLG_ATTACHED;
if (state && !g_discogs->find_release_artist_dialog)
m_alist.ShowArtistProfile();
return FALSE;
}
LRESULT CFindReleaseDialog::OnCheckboxOnlyExactMatches(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/) {
if (wID == IDC_CHK_ONLY_EXACT_MATCHES) {
conf.display_exact_matches = IsDlgButtonChecked(IDC_CHK_ONLY_EXACT_MATCHES) == BST_CHECKED;
m_alist.fill_artist_list(conf.display_exact_matches, m_tracer.has_amr(), updRelSrc::ArtistListCheckExact);
}
return FALSE;
}
LRESULT CFindReleaseDialog::OnCheckboxFindReleaseFilterFlags(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/) {
bool force_refresh, force_rebuild;
//get dlg filter
pfc::string8 strFilter = trim(uGetWindowText(m_edit_filter));
if (wID == IDC_CHK_FIND_RELEASE_FILTER_ROLEMAIN) {
bool checked = IsDlgButtonChecked(IDC_CHK_FIND_RELEASE_FILTER_ROLEMAIN) == BST_CHECKED;
if (checked)
conf.find_release_filter_flag |= FilterFlag::RoleMain;
else
conf.find_release_filter_flag &= ~(FilterFlag::RoleMain);
force_refresh = force_rebuild = true;
}
else if (wID == IDC_CHK_FIND_RELEASE_FILTER_VERS) {
bool checked = IsDlgButtonChecked(IDC_CHK_FIND_RELEASE_FILTER_VERS) == BST_CHECKED;
if (checked)
conf.find_release_filter_flag |= FilterFlag::Versions;
else
conf.find_release_filter_flag &= ~(FilterFlag::Versions);
force_refresh = true; force_rebuild = false;
set_role_label(checked);
//skip if filter is empty
if (!strFilter.get_length()) {
return FALSE;
}
}
else {
return FALSE;
}
KillTimer(KTypeFilterTimerID);
//
apply_filter(strFilter, force_refresh, force_rebuild);
//
return FALSE;
}
LRESULT CFindReleaseDialog::OnButtonConfigure(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/) {
if (!g_discogs->configuration_dialog) {
static_api_ptr_t<ui_control>()->show_preferences(guid_pref_page);
}
else {
::SetFocus(g_discogs->configuration_dialog->m_hWnd);
}
return FALSE;
}
//todo: rev
void CFindReleaseDialog::trigger_release(const pfc::string8& release_id) {
if (std::atoi(release_id) == 0) {
uMessageBox(m_hWnd, "Release Id non-valid Release Id, unable to continue.", "foo_discogger: Error", MB_APPLMODAL | MB_ICONASTERISK);
return;
}
pfc::string8 offline_artist_id;
bool bskip_idded_release_dlg = conf.skip_mng_flag & SkipMng::RELEASE_DLG_IDED;
if (bskip_idded_release_dlg && m_tracer.has_artist()) {
size_t artist_id = m_tracer.get_artist_id_store();
offline_artist_id = std::to_string(artist_id).c_str();
}
else {
//dlg button
if (m_alist.Get_Artist()) {
// list selection artist has preference, even if is NOT the artist_id meta
offline_artist_id = m_alist.Get_Artist()->id;
}
else if (m_tracer.has_artist()) {
// artist_id meta
offline_artist_id = std::to_string(m_tracer.get_artist_id_store()).c_str();
}
else {
//offline cache not available
offline_artist_id = "";
}
}
try {
service_ptr_t<process_release_callback> task = new service_impl_t<process_release_callback>(this, release_id, offline_artist_id, "", m_items);
task->start(m_hWnd);
}
catch (locked_task_exception e)
{
log_msg(e.what());
}
}
// expand_master_release_process_done
void CFindReleaseDialog::on_expand_master_release_done(const MasterRelease_ptr& master_release, int list_index, threaded_process_status& p_status, abort_callback& p_abort) {
// forward on expand master release done
m_dctree.on_expand_master_release_done(master_release, list_index, p_status, p_abort);
}
void CFindReleaseDialog::on_expand_master_release_complete() {
// * ACTIVE TASK NULL
m_active_task = NULL;
}
void CFindReleaseDialog::call_expand_master_service(MasterRelease_ptr& release, int pos) {
if (release->sub_releases.get_size()) {
//already loaded
return;
}
pfc::string8 offlineArtistId = "";
if (m_alist.Get_Artist())
offlineArtistId = m_alist.Get_Artist()->id;
else
if (m_alist.Get_Artists().get_count() > 0)
offlineArtistId = m_alist.Get_Artists()[0]->id;
service_ptr_t<expand_master_release_process_callback> task =
new service_impl_t<expand_master_release_process_callback>(release, pos, offlineArtistId);
m_active_task = &task;
task->start(m_hWnd);
}
// convey artist-list and artist-profile actions
void CFindReleaseDialog::convey_artist_list_selection(cupdRelSrc cupdsrc) {
//from Default action (ArtistList) or List selection (ArtistProfile)
PFC_ASSERT(cupdsrc == updRelSrc::ArtistList || cupdsrc == updRelSrc::ArtistProfile);
t_size pos = m_alist.GetSingleSel();
if (pos == ~0 || (cupdsrc != updRelSrc::ArtistList && cupdsrc != updRelSrc::ArtistProfile)) {
return;
}
Artist_ptr artist = m_alist.Get_Artists()[pos];
bool need_releases = cupdsrc == updRelSrc::ArtistList && !artist->loaded_releases;
bool need_data = !(artist->loaded_preview || artist->loaded);
need_data |= need_releases;
if (ol::full_cache() && cupdsrc == updRelSrc::ArtistProfile && conf.auto_rel_load_on_select) {
need_data = true;
}
// UPDATE DLG CONTROLS WITH SELECTED PROFILE DATA OR LAUNCH TASK TO COLLECT IT
if (need_data || cupdsrc == updRelSrc::UndefFast || cupdsrc == updRelSrc::ArtistList)
{
{
std::lock_guard<std::mutex> guard(m_loading_selection_rw_mutex);
m_loading_selection_id = atoi(artist.get()->id);
}
if (artist->id.equals("0") || artist->id.equals("194"/*various artists*/)) {
g_discogs->find_release_dialog->on_get_artist_done(cupdsrc, artist);
return;
}
service_ptr_t<get_artist_process_callback> task =
new service_impl_t<get_artist_process_callback>(cupdsrc, artist->id.get_ptr());
task->start(m_hWnd);
}
else
{
{
std::lock_guard<std::mutex> guard(m_loading_selection_rw_mutex);
m_loading_selection_id = pfc_infinite; //pending udpates validation on done
}
UpdateArtistProfile(artist);
}
}
// route
void CFindReleaseDialog::route_artist_search(pfc::string8 artistname, bool dlgbutton, bool idded) {
bool b_idded_from_init = !dlgbutton && idded;
pfc::string8 artist_id;
bool cfg_skip_get_artist_if_present = true;
bool cfg_fast_load_artist_if_idded = true;
updRelSrc updsrc = updRelSrc::Undef;
bool by_any = dlgbutton ||
conf.enable_autosearch ||
(m_tracer.has_artist() && cfg_fast_load_artist_if_idded);
bool by_name = artistname.get_length();
bool by_id = false;
bool by_id_cfg_fast = false;
if (dlgbutton) {
by_id = false;
by_id |= idded;
if (by_id)