diff --git a/src/mpdpp.cpp b/src/mpdpp.cpp index d4b8212d..340c4931 100644 --- a/src/mpdpp.cpp +++ b/src/mpdpp.cpp @@ -381,11 +381,11 @@ Song MPDConnection::GetCurrentSong() const Song result = item->info.song; item->info.song = 0; mpd_freeInfoEntity(item); - mpd_finishCommand(itsConnection); return result; } else return Song(); + mpd_finishCommand(itsConnection); } else return Song(); diff --git a/src/ncmpcpp.cpp b/src/ncmpcpp.cpp index 934ebb8d..5df3b3c9 100644 --- a/src/ncmpcpp.cpp +++ b/src/ncmpcpp.cpp @@ -133,6 +133,7 @@ bool redraw_header = 1; bool reload_lyrics = 0; extern bool header_update_status; +extern bool search_place; extern bool search_case_sensitive; extern bool search_match_to_pattern; @@ -1256,18 +1257,24 @@ int main(int argc, char *argv[]) break; } case 10: + { + search_place = !search_place; + mSearcher->Current().first = "[.b]Search in:[/b] " + string(search_place ? "Database" : "Current playlist"); + break; + } + case 11: { search_match_to_pattern = !search_match_to_pattern; mSearcher->Current().first = "[.b]Search mode:[/b] " + (search_match_to_pattern ? search_mode_normal : search_mode_strict); break; } - case 11: + case 12: { search_case_sensitive = !search_case_sensitive; mSearcher->Current().first = "[.b]Case sensitive:[/b] " + string(search_case_sensitive ? "Yes" : "No"); break; } - case 13: + case 14: { ShowMessage("Searching..."); Search(s); @@ -1275,12 +1282,12 @@ int main(int argc, char *argv[]) { int found = mSearcher->Size()-search_engine_static_options; found += 3; // don't count options inserted below - mSearcher->InsertSeparator(14); - mSearcher->Insert(15, make_pair("[." + Config.color1 + "]Search results:[/" + Config.color1 + "] [." + Config.color2 + "]Found " + IntoStr(found) + (found > 1 ? " songs" : " song") + "[/" + Config.color2 + "]", Song()), 1, 1); - mSearcher->InsertSeparator(16); + mSearcher->InsertSeparator(15); + mSearcher->Insert(16, make_pair("[." + Config.color1 + "]Search results:[/" + Config.color1 + "] [." + Config.color2 + "]Found " + IntoStr(found) + (found > 1 ? " songs" : " song") + "[/" + Config.color2 + "]", Song()), 1, 1); + mSearcher->InsertSeparator(17); UpdateFoundList(); ShowMessage("Searching finished!"); - for (int i = 0; i < 13; i++) + for (int i = 0; i < search_engine_static_options-4; i++) mSearcher->MakeStatic(i, 1); mSearcher->Go(wDown); mSearcher->Go(wDown); @@ -1289,7 +1296,7 @@ int main(int argc, char *argv[]) ShowMessage("No results found"); break; } - case 14: + case 15: { found_pos = 0; vFoundPositions.clear(); @@ -2734,7 +2741,7 @@ int main(int argc, char *argv[]) { if (wCurrent == mSearcher) { - mSearcher->Highlight(12); // highlight 'search' button + mSearcher->Highlight(13); // highlight 'search' button goto ENTER_SEARCH_ENGINE_SCREEN; } } @@ -2765,7 +2772,7 @@ int main(int argc, char *argv[]) if (wCurrent == mBrowser && browsed_dir != "/") wCurrent->Select(0, 0); // [..] cannot be selected, uhm. if (wCurrent == mSearcher) - wCurrent->Select(13, 0); // 'Reset' cannot be selected, omgplz. + wCurrent->Select(14, 0); // 'Reset' cannot be selected, omgplz. // hacking shit ends. need better solution :/ ShowMessage("Selection reversed!"); } diff --git a/src/search_engine.cpp b/src/search_engine.cpp index d6c786f6..fd7574de 100644 --- a/src/search_engine.cpp +++ b/src/search_engine.cpp @@ -26,6 +26,7 @@ extern Menu *mPlaylist; extern Menu< std::pair > *mSearcher; bool search_match_to_pattern = 1; +bool search_place = 1; bool search_case_sensitive = 0; string SearchEngineDisplayer(const std::pair &pair, void *, const Menu< std::pair > *menu) @@ -67,8 +68,9 @@ void PrepareSearchEngine(Song &s) mSearcher->AddOption(make_pair("[.b]Genre:[/b] " + s.GetGenre(), Song())); mSearcher->AddOption(make_pair("[.b]Comment:[/b] " + s.GetComment(), Song())); mSearcher->AddSeparator(); + mSearcher->AddOption(make_pair("[.b]Search in:[/b] " + string(search_place ? "Database" : "Current playlist"), Song())); mSearcher->AddOption(make_pair("[.b]Search mode:[/b] " + (search_match_to_pattern ? search_mode_normal : search_mode_strict), Song())); - mSearcher->AddOption(make_pair("[.b]Case sensitive:[/b] " + (string)(search_case_sensitive ? "Yes" : "No"), Song())); + mSearcher->AddOption(make_pair("[.b]Case sensitive:[/b] " + string(search_case_sensitive ? "Yes" : "No"), Song())); mSearcher->AddSeparator(); mSearcher->AddOption(make_pair("Search", Song())); mSearcher->AddOption(make_pair("Reset", Song())); @@ -80,7 +82,14 @@ void Search(Song &s) return; SongList list; - Mpd->GetDirectoryRecursive("/", list); + if (search_place) + Mpd->GetDirectoryRecursive("/", list); + else + { + list.reserve(mPlaylist->Size()); + for (int i = 0; i < mPlaylist->Size(); i++) + list.push_back(&(*mPlaylist)[i]); + } bool found = 1; @@ -191,7 +200,8 @@ void Search(Song &s) mSearcher->AddOption(make_pair(".", **it)); found = 1; } - FreeSongList(list); + if (search_place) // free song list only if it's database + FreeSongList(list); s.GetEmptyFields(0); } diff --git a/src/search_engine.h b/src/search_engine.h index 9ff0121c..1bfbfaaf 100644 --- a/src/search_engine.h +++ b/src/search_engine.h @@ -24,7 +24,7 @@ #include "mpdpp.h" #include "ncmpcpp.h" -const int search_engine_static_options = 17; +const int search_engine_static_options = 18; string SearchEngineDisplayer(const std::pair &, void *, const Menu< std::pair > *); void UpdateFoundList();