-
Notifications
You must be signed in to change notification settings - Fork 37
/
AddURLDialog.cpp
74 lines (65 loc) · 3.21 KB
/
AddURLDialog.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
#include "AddURLDialog.h"
#include "resource.h"
#include "Tools.h"
#include "YouTubeAPI.h"
#include "GdiPlusImageLoader.h"
#include "AIMPYouTube.h"
extern HINSTANCE g_hInst;
void AddURLDialog::Show() {
HWND parent = Plugin::instance()->GetMainWindowHandle();
DialogBox(g_hInst, MAKEINTRESOURCE(IDD_ADDURL), parent, DlgProc);
}
BOOL CALLBACK AddURLDialog::DlgProc(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam) {
switch (Msg) {
case WM_CLOSE:
EndDialog(hwnd, IDCANCEL);
break;
case WM_INITDIALOG: {
int createNew = Config::GetInt32(L"CreateNewPlaylist", 1);
SendDlgItemMessage(hwnd, IDC_CREATENEW, BM_SETCHECK, createNew? BST_CHECKED : BST_UNCHECKED, NULL);
EnableWindow(GetDlgItem(hwnd, IDC_PLAYLISTTITLE), createNew);
EnableWindow(GetDlgItem(hwnd, IDC_PLAYLISTTITLECAPTION), createNew);
GdiPlusImageLoader icon(IDB_ICON, L"PNG");
HICON bitmap;
icon->GetHICON(&bitmap);
SendMessage(hwnd, WM_SETICON, ICON_BIG, (LPARAM)bitmap);
DeleteObject(bitmap);
SetWindowText (hwnd, Plugin::instance()->Lang(L"YouTube.AddURL\\Title").c_str());
SetDlgItemText(hwnd, IDC_YouTubeURLCAPTION, Plugin::instance()->Lang(L"YouTube.AddURL\\URL").c_str());
SetDlgItemText(hwnd, IDC_CREATENEW, Plugin::instance()->Lang(L"YouTube.AddURL\\CreateNew").c_str());
SetDlgItemText(hwnd, IDOK, Plugin::instance()->Lang(L"YouTube.AddURL\\OK").c_str());
SetDlgItemText(hwnd, IDC_PLAYLISTTITLECAPTION, Plugin::instance()->Lang(L"YouTube.AddURL\\PlaylistName").c_str());
SetFocus(GetDlgItem(hwnd, IDC_YouTubeURL));
} break;
case WM_COMMAND: {
switch (LOWORD(wParam)) {
case IDOK: {
wchar_t buf[1024];
GetDlgItemText(hwnd, IDC_YouTubeURL, buf, 1024);
std::wstring url(buf);
GetDlgItemText(hwnd, IDC_PLAYLISTTITLE, buf, 1024);
std::wstring playlistTitle(buf);
bool createnew = SendDlgItemMessage(hwnd, IDC_CREATENEW, BM_GETCHECK, NULL, NULL) == BST_CHECKED;
Config::SetInt32(L"CreateNewPlaylist", createnew);
if (!url.empty()) {
YouTubeAPI::ResolveUrl(url, playlistTitle, createnew);
}
EndDialog(hwnd, wParam);
} break;
case IDCANCEL:
EndDialog(hwnd, wParam);
break;
case IDC_CREATENEW:
if (HIWORD(wParam) == BN_CLICKED) {
LRESULT chkState = SendMessage((HWND)lParam, BM_GETCHECK, 0, 0);
BOOL enable = chkState == BST_CHECKED;
EnableWindow(GetDlgItem(hwnd, IDC_PLAYLISTTITLE), enable);
EnableWindow(GetDlgItem(hwnd, IDC_PLAYLISTTITLECAPTION), enable);
}
break;
}
} break;
default: return FALSE;
}
return TRUE;
}