allow searching in current playlist

This commit is contained in:
unK
2008-10-19 23:00:46 +02:00
parent f7e56300cf
commit 5775eaf039
4 changed files with 31 additions and 14 deletions

View File

@@ -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();

View File

@@ -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!");
}

View File

@@ -26,6 +26,7 @@ extern Menu<Song> *mPlaylist;
extern Menu< std::pair<string, Song> > *mSearcher;
bool search_match_to_pattern = 1;
bool search_place = 1;
bool search_case_sensitive = 0;
string SearchEngineDisplayer(const std::pair<string, Song> &pair, void *, const Menu< std::pair<string, Song> > *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);
}

View File

@@ -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<string, Song> &, void *, const Menu< std::pair<string, Song> > *);
void UpdateFoundList();