This repository has been archived by the owner on Dec 11, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsearch.h
executable file
·156 lines (116 loc) · 4.53 KB
/
search.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
#pragma once
#include "foo_subsonic.h"
#include "subsoniclibraryscanner.h"
#include "searchQueryThread.h"
#include "ListviewHelper.h"
#include "SimpleHttpClientConfigurator.h"
class SearchDialog : public CDialogImpl<SearchDialog> {
private:
CButton find_button;
CEdit search_term;
CListViewCtrl results;
CComboBox cbResultCount;
HACCEL m_haccelerator;
foo_subsonic::SubsonicLibraryScanner scanner;
COLORREF bgColor;
COLORREF fgColor;
public:
enum { IDD = IDD_SEARCH };
BEGIN_MSG_MAP(SearchDialog)
MSG_WM_INITDIALOG(OnInitDialog)
MSG_WM_CLOSE(OnClose)
COMMAND_ID_HANDLER_EX(IDOK, OnOk)
COMMAND_ID_HANDLER_EX(IDCANCEL, OnCancel)
MESSAGE_HANDLER(ID_SEARCH_DONE, OnSearchDone)
NOTIFY_HANDLER(IDC_RESULTLIST, NM_DBLCLK, OnLButtonDblClick)
END_MSG_MAP()
enum columns {
artist_column,
track_column,
album_column,
duration_column
};
SearchDialog(COLORREF fgcolor, COLORREF bgcolor) {
m_haccelerator = NULL;
fgColor = fgcolor;
bgColor = bgcolor;
Create(core_api::get_main_window());
}
bool OnInitDialog(CWindow wndFocus, LPARAM lInitParam) {
static_api_ptr_t<modeless_dialog_manager>()->add(m_hWnd);
search_term.Attach(GetDlgItem(IDC_SEARCHTERM));
find_button = GetDlgItem(IDOK);
results.Attach(GetDlgItem(IDC_RESULTLIST));
cbResultCount = GetDlgItem(IDC_CB_RESULT_COUNT);
cbResultCount.AddString(L"10");
cbResultCount.AddString(L"20");
cbResultCount.AddString(L"50");
cbResultCount.AddString(L"100");
cbResultCount.AddString(L"150");
cbResultCount.AddString(L"200");
cbResultCount.SelectString(0, L"200");
auto styles = LVS_EX_FULLROWSELECT | LVS_EX_LABELTIP;
results.SetExtendedListViewStyle(styles, styles);
// Adding release list columns
listviewHelper::insert_column(results, artist_column, "Artist", 104);
listviewHelper::insert_column(results, track_column, "Track", 110);
listviewHelper::insert_column(results, album_column, "Album", 110);
listviewHelper::insert_column(results, duration_column, "Duration", 50);
results.SetBkColor(bgColor);
results.SetTextColor(fgColor);
results.SetTextBkColor(bgColor);
search_term.SetFocus();
return true;
}
void OnClose() {
DestroyWindow();
}
void OnCancel(UINT uNotifyCode, int nID, CWindow wndCtl) {
DestroyWindow();
}
void OnOk(UINT uNotifyCode, int nID, CWindow wndCtl) {
if (nID == IDOK) {
pfc::string8 params = SimpleHttpClientConfigurator::url_encode(string_utf8_from_window(m_hWnd, IDC_SEARCHTERM));
params << "&albumCount=0&artistCount=0&songCount=" << string_utf8_from_window(m_hWnd, IDC_CB_RESULT_COUNT);
threaded_process::g_run_modeless(new service_impl_t<foo_subsonic::SearchQueryThread>(&scanner, m_hWnd, params),
threaded_process::flag_show_progress | threaded_process::flag_show_abort, m_hWnd, "Searching Subsonic Server");
}
}
LRESULT OnSearchDone(UINT, WPARAM, LPARAM, BOOL&) {
std::list<Track*>* trackList = SqliteCacheDb::getInstance()->getAllSearchResults()->getTracks();
std::list<Track*>::iterator trackIterator;
for (trackIterator = trackList->begin(); trackIterator != trackList->end(); trackIterator++) {
char durationStr[20];
int iDuration = atoi((*trackIterator)->get_duration());
snprintf(durationStr, sizeof(durationStr), "%02d:%02d", iDuration / 60, iDuration % 60);
Track* store = *trackIterator;
listviewHelper::insert_item4(results, 0, (*trackIterator)->get_artist(), (*trackIterator)->get_title(), (*trackIterator)->get_album(), durationStr, (DWORD_PTR)store);
}
return 0;
}
LRESULT OnLButtonDblClick(int /*idCtrl*/, LPNMHDR pNMHDR, BOOL& /*bHandled*/) {
for (INT nItem = results.GetNextItem(-1, LVNI_SELECTED); nItem >= 0; nItem = results.GetNextItem(nItem, LVNI_SELECTED))
{
if (nItem > -1) {
DWORD_PTR ptr = results.GetItemData(nItem);
CoreEntity* coreType = reinterpret_cast<CoreEntity*>(ptr);
if (coreType->get_type() == ENTRY_TYPE_TRACK) { // Track
if (ptr != NULL) {
Track* track = reinterpret_cast<Track*>(ptr);
uDebugLog() << "Got Track=" << track->get_title() << ", Artist=" << track->get_artist();
const char* url = track->get_streamUrl().c_str();
static_api_ptr_t<playlist_incoming_item_filter_v2>()->process_locations_async(
pfc::list_single_ref_t<const char*>(url),
playlist_incoming_item_filter_v2::op_flag_background,
NULL,
NULL,
m_hWnd,
p_notify
);
}
}
}
}
return 0;
}
};