new feature: go to currently playing song in browser

This commit is contained in:
Andrzej Rybczak
2009-02-27 00:20:45 +01:00
parent 89b53ddfdb
commit aed227ab5f
4 changed files with 40 additions and 25 deletions

View File

@@ -333,6 +333,28 @@ namespace
} }
} }
void Browser::LocateSong(const MPD::Song &s)
{
if (s.GetDirectory().empty())
return;
Config.local_browser = !s.IsFromDB();
string option = s.toString(Config.song_status_format);
locale_to_utf(option);
if (itsBrowsedDir != s.GetDirectory())
GetDirectory(s.GetDirectory());
for (size_t i = 0; i < w->Size(); i++)
{
if (w->at(i).type == itSong && option == w->at(i).song->toString(Config.song_status_format))
{
w->Highlight(i);
break;
}
}
SwitchTo();
}
void Browser::GetDirectory(string dir, string subdir) void Browser::GetDirectory(string dir, string subdir)
{ {
if (dir.empty()) if (dir.empty())

View File

@@ -50,6 +50,7 @@ class Browser : public Screen< Menu<MPD::Item> >
const std::string &CurrentDir() { return itsBrowsedDir; } const std::string &CurrentDir() { return itsBrowsedDir; }
void LocateSong(const MPD::Song &);
void GetDirectory(std::string, std::string = "/"); void GetDirectory(std::string, std::string = "/");
void ChangeBrowseMode(); void ChangeBrowseMode();
void UpdateItemList(); void UpdateItemList();

View File

@@ -174,7 +174,7 @@ void Help::GetKeybindings()
*w << DisplayKeys(Key.PrevFoundPosition) << "Go to previous found position\n"; *w << DisplayKeys(Key.PrevFoundPosition) << "Go to previous found position\n";
*w << DisplayKeys(Key.NextFoundPosition) << "Go to next found position\n"; *w << DisplayKeys(Key.NextFoundPosition) << "Go to next found position\n";
*w << DisplayKeys(Key.ToggleFindMode) << "Toggle find mode (normal/wrapped)\n"; *w << DisplayKeys(Key.ToggleFindMode) << "Toggle find mode (normal/wrapped)\n";
*w << DisplayKeys(Key.GoToContainingDir) << "Go to directory containing current item\n"; *w << DisplayKeys(Key.GoToContainingDir) << "Locate song in browser\n";
*w << DisplayKeys(Key.ToggleDisplayMode) << "Toggle display mode\n"; *w << DisplayKeys(Key.ToggleDisplayMode) << "Toggle display mode\n";
# ifdef HAVE_TAGLIB_H # ifdef HAVE_TAGLIB_H
*w << DisplayKeys(Key.EditTags) << "Edit song's tags/playlist's name\n"; *w << DisplayKeys(Key.EditTags) << "Edit song's tags/playlist's name\n";
@@ -208,6 +208,7 @@ void Help::GetKeybindings()
*w << DisplayKeys(Key.Space) << "Add item to playlist\n"; *w << DisplayKeys(Key.Space) << "Add item to playlist\n";
if (Mpd->GetHostname()[0] == '/') // are we connected to unix socket? if (Mpd->GetHostname()[0] == '/') // are we connected to unix socket?
*w << DisplayKeys(Key.SwitchTagTypeList) << "Browse MPD database/local filesystem\n"; *w << DisplayKeys(Key.SwitchTagTypeList) << "Browse MPD database/local filesystem\n";
*w << DisplayKeys(Key.GoToNowPlaying) << "Locate currently playing song\n";
*w << DisplayKeys(Key.GoToParentDir) << "Go to parent directory\n"; *w << DisplayKeys(Key.GoToParentDir) << "Go to parent directory\n";
*w << DisplayKeys(Key.Delete) << "Delete playlist\n\n\n"; *w << DisplayKeys(Key.Delete) << "Delete playlist\n\n\n";

View File

@@ -987,14 +987,21 @@ int main(int argc, char *argv[])
} }
else if (Keypressed(input, Key.GoToNowPlaying)) else if (Keypressed(input, Key.GoToNowPlaying))
{ {
if (myScreen != myPlaylist || !myPlaylist->isPlaying()) if (myScreen == myPlaylist && myPlaylist->isPlaying())
continue;
if (myPlaylist->Main()->isFiltered())
{ {
ShowMessage("%s", MPD::Message::FunctionDisabledFilteringEnabled); if (myPlaylist->Main()->isFiltered())
continue; {
ShowMessage("%s", MPD::Message::FunctionDisabledFilteringEnabled);
continue;
}
myPlaylist->Main()->Highlight(myPlaylist->NowPlaying);
}
else if (myScreen == myBrowser)
{
const Song *s = myPlaylist->NowPlayingSong();
if (s)
myBrowser->LocateSong(*s);
} }
myPlaylist->Main()->Highlight(myPlaylist->NowPlaying);
} }
else if (Keypressed(input, Key.ToggleRepeat)) else if (Keypressed(input, Key.ToggleRepeat))
{ {
@@ -1189,24 +1196,8 @@ int main(int argc, char *argv[])
else if (Keypressed(input, Key.GoToContainingDir)) else if (Keypressed(input, Key.GoToContainingDir))
{ {
Song *s = myScreen->CurrentSong(); Song *s = myScreen->CurrentSong();
if (s)
if (!s || s->GetDirectory().empty()) myBrowser->LocateSong(*s);
continue;
Config.local_browser = !s->IsFromDB();
string option = s->toString(Config.song_status_format);
locale_to_utf(option);
myBrowser->GetDirectory(s->GetDirectory());
for (size_t i = 0; i < myBrowser->Main()->Size(); i++)
{
if (myBrowser->Main()->at(i).type == itSong && option == myBrowser->Main()->at(i).song->toString(Config.song_status_format))
{
myBrowser->Main()->Highlight(i);
break;
}
}
myBrowser->SwitchTo();
} }
else if (Keypressed(input, Key.StartSearching)) else if (Keypressed(input, Key.StartSearching))
{ {