forked from Dremora/foo_musicbrainz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQueryByMBIDDialog.h
69 lines (58 loc) · 1.87 KB
/
QueryByMBIDDialog.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
#pragma once
#include <regex>
#include "Query.h"
#include "TaggerDialog.h"
namespace foo_musicbrainz {
class QueryByMBIDDialog : public CDialogImpl<QueryByMBIDDialog> {
private:
pfc::list_t<metadb_handle_ptr> tracks;
CButton ok;
pfc::string8 mbid;
public:
enum { IDD = IDD_CUSTOM_QUERY_MBID };
QueryByMBIDDialog(pfc::list_t<metadb_handle_ptr> _tracks, pfc::string8 &_mbid)
: CDialogImpl<QueryByMBIDDialog>(),
tracks(_tracks),
mbid(_mbid)
{
Create(core_api::get_main_window());
}
BEGIN_MSG_MAP(CCustomQueryMBID)
MSG_WM_INITDIALOG(OnInitDialog)
MSG_WM_CLOSE(OnClose)
COMMAND_HANDLER_EX(IDC_MBID, EN_UPDATE, OnUpdate)
COMMAND_ID_HANDLER_EX(IDCANCEL, OnCancel)
COMMAND_ID_HANDLER_EX(IDOK, OnOk)
END_MSG_MAP()
BOOL OnInitDialog(CWindow wndFocus, LPARAM lInitParam) {
static_api_ptr_t<modeless_dialog_manager>()->add(m_hWnd);
ok = GetDlgItem(IDOK);
uSetDlgItemText(m_hWnd, IDC_MBID, mbid);
return true;
}
void OnClose() {
DestroyWindow();
}
void OnFinalMessage(HWND hwnd) {
static_api_ptr_t<modeless_dialog_manager>()->remove(m_hWnd);
delete this;
}
void OnUpdate(UINT uNotifyCode, int nID, CWindow wndCtl) {
std::tr1::regex rx("^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$");
if (regex_search(string_utf8_from_window(m_hWnd, IDC_MBID).get_ptr(), rx)) {
ok.EnableWindow(true);
}
else ok.EnableWindow(false);
}
void OnCancel(UINT uNotifyCode, int nID, CWindow wndCtl) {
DestroyWindow();
}
void OnOk(UINT uNotifyCode, int nID, CWindow wndCtl) {
pfc::string8 id = string_utf8_from_window(m_hWnd, IDC_MBID);
auto query = new Query("release", id);
query->add_param("inc", "artists+labels+recordings+release-groups+artist-credits", false);
new TaggerDialog(query, tracks);
DestroyWindow();
}
};
}