move Global::Timer to Playlist class

This commit is contained in:
Andrzej Rybczak
2009-03-12 20:20:26 +01:00
parent d5a68a1a60
commit 0aa36f3fb2
5 changed files with 38 additions and 29 deletions

View File

@@ -38,8 +38,6 @@ namespace Global
extern size_t MainStartY; extern size_t MainStartY;
extern size_t MainHeight; extern size_t MainHeight;
extern time_t Timer;
# ifdef HAVE_CURL_CURL_H # ifdef HAVE_CURL_CURL_H
extern pthread_mutex_t CurlLock; extern pthread_mutex_t CurlLock;
# endif # endif

View File

@@ -70,8 +70,6 @@ Connection *Global::Mpd;
size_t Global::MainStartY; size_t Global::MainStartY;
size_t Global::MainHeight; size_t Global::MainHeight;
time_t Global::Timer;
bool Global::BlockItemListUpdate = 0; bool Global::BlockItemListUpdate = 0;
bool Global::MessagesAllowed = 0; bool Global::MessagesAllowed = 0;
@@ -161,7 +159,7 @@ int main(int argc, char *argv[])
myScreen = myPlaylist; myScreen = myPlaylist;
time(&Timer); myPlaylist->UpdateTimer();
Mpd->SetStatusUpdater(NcmpcppStatusChanged, NULL); Mpd->SetStatusUpdater(NcmpcppStatusChanged, NULL);
Mpd->SetErrorHandler(NcmpcppErrorCallback, NULL); Mpd->SetErrorHandler(NcmpcppErrorCallback, NULL);
@@ -248,12 +246,9 @@ int main(int argc, char *argv[])
if (!title_allowed) if (!title_allowed)
RedrawHeader = 1; RedrawHeader = 1;
title_allowed = 1; title_allowed = 1;
time(&Timer);
if (myScreen == myPlaylist) if (myScreen == myPlaylist)
{ myPlaylist->EnableHighlighting();
myPlaylist->Main()->Highlighting(1);
}
else if ( else if (
myScreen == myLibrary myScreen == myLibrary
|| myScreen == myPlaylistEditor || myScreen == myPlaylistEditor
@@ -460,7 +455,7 @@ int main(int argc, char *argv[])
{ {
size_t id = myPlaylist->Main()->Choice(); size_t id = myPlaylist->Main()->Choice();
TraceMpdStatus(); TraceMpdStatus();
time(&Timer); myPlaylist->UpdateTimer();
if (myPlaylist->NowPlaying > myPlaylist->CurrentSong()->GetPosition()) // needed for keeping proper if (myPlaylist->NowPlaying > myPlaylist->CurrentSong()->GetPosition()) // needed for keeping proper
myPlaylist->NowPlaying--; // position of now playing song. myPlaylist->NowPlaying--; // position of now playing song.
Mpd->DeleteID(myPlaylist->CurrentSong()->GetID()); Mpd->DeleteID(myPlaylist->CurrentSong()->GetID());
@@ -526,7 +521,7 @@ int main(int argc, char *argv[])
while (!myPlaylistEditor->Content->Empty() && Keypressed(input, Key.Delete)) while (!myPlaylistEditor->Content->Empty() && Keypressed(input, Key.Delete))
{ {
TraceMpdStatus(); TraceMpdStatus();
time(&Timer); myPlaylist->UpdateTimer();
Mpd->Delete(myPlaylistEditor->Playlists->Current(), myPlaylistEditor->Content->Choice()); Mpd->Delete(myPlaylistEditor->Playlists->Current(), myPlaylistEditor->Content->Choice());
myPlaylistEditor->Content->DeleteOption(myPlaylistEditor->Content->Choice()); myPlaylistEditor->Content->DeleteOption(myPlaylistEditor->Content->Choice());
myPlaylistEditor->Content->Refresh(); myPlaylistEditor->Content->Refresh();
@@ -629,7 +624,7 @@ int main(int argc, char *argv[])
while (Keypressed(input, Key.MvSongUp) && list.front() > 0) while (Keypressed(input, Key.MvSongUp) && list.front() > 0)
{ {
TraceMpdStatus(); TraceMpdStatus();
time(&Timer); myPlaylist->UpdateTimer();
for (vector<size_t>::iterator it = list.begin(); it != list.end(); it++) for (vector<size_t>::iterator it = list.begin(); it != list.end(); it++)
{ {
(*it)--; (*it)--;
@@ -656,7 +651,7 @@ int main(int argc, char *argv[])
while (Keypressed(input, Key.MvSongUp) && to > 0) while (Keypressed(input, Key.MvSongUp) && to > 0)
{ {
TraceMpdStatus(); TraceMpdStatus();
time(&Timer); myPlaylist->UpdateTimer();
to--; to--;
myPlaylist->Main()->at(from).SetPosition(to); myPlaylist->Main()->at(from).SetPosition(to);
myPlaylist->Main()->at(to).SetPosition(from); myPlaylist->Main()->at(to).SetPosition(from);
@@ -682,7 +677,7 @@ int main(int argc, char *argv[])
while (Keypressed(input, Key.MvSongUp) && list.front() > 0) while (Keypressed(input, Key.MvSongUp) && list.front() > 0)
{ {
TraceMpdStatus(); TraceMpdStatus();
time(&Timer); myPlaylist->UpdateTimer();
for (vector<size_t>::iterator it = list.begin(); it != list.end(); it++) for (vector<size_t>::iterator it = list.begin(); it != list.end(); it++)
{ {
(*it)--; (*it)--;
@@ -705,7 +700,7 @@ int main(int argc, char *argv[])
while (Keypressed(input, Key.MvSongUp) && to > 0) while (Keypressed(input, Key.MvSongUp) && to > 0)
{ {
TraceMpdStatus(); TraceMpdStatus();
time(&Timer); myPlaylist->UpdateTimer();
to--; to--;
myPlaylistEditor->Content->Swap(to, to+1); myPlaylistEditor->Content->Swap(to, to+1);
myPlaylistEditor->Content->Scroll(wUp); myPlaylistEditor->Content->Scroll(wUp);
@@ -744,7 +739,7 @@ int main(int argc, char *argv[])
while (Keypressed(input, Key.MvSongDown) && list.back() < myPlaylist->Main()->Size()-1) while (Keypressed(input, Key.MvSongDown) && list.back() < myPlaylist->Main()->Size()-1)
{ {
TraceMpdStatus(); TraceMpdStatus();
time(&Timer); myPlaylist->UpdateTimer();
for (vector<size_t>::reverse_iterator it = list.rbegin(); it != list.rend(); it++) for (vector<size_t>::reverse_iterator it = list.rbegin(); it != list.rend(); it++)
{ {
(*it)++; (*it)++;
@@ -771,7 +766,7 @@ int main(int argc, char *argv[])
while (Keypressed(input, Key.MvSongDown) && to < myPlaylist->Main()->Size()-1) while (Keypressed(input, Key.MvSongDown) && to < myPlaylist->Main()->Size()-1)
{ {
TraceMpdStatus(); TraceMpdStatus();
time(&Timer); myPlaylist->UpdateTimer();
to++; to++;
myPlaylist->Main()->at(from).SetPosition(to); myPlaylist->Main()->at(from).SetPosition(to);
myPlaylist->Main()->at(to).SetPosition(from); myPlaylist->Main()->at(to).SetPosition(from);
@@ -798,7 +793,7 @@ int main(int argc, char *argv[])
while (Keypressed(input, Key.MvSongDown) && list.back() < myPlaylistEditor->Content->Size()-1) while (Keypressed(input, Key.MvSongDown) && list.back() < myPlaylistEditor->Content->Size()-1)
{ {
TraceMpdStatus(); TraceMpdStatus();
time(&Timer); myPlaylist->UpdateTimer();
for (vector<size_t>::reverse_iterator it = list.rbegin(); it != list.rend(); it++) for (vector<size_t>::reverse_iterator it = list.rbegin(); it != list.rend(); it++)
{ {
(*it)++; (*it)++;
@@ -821,7 +816,7 @@ int main(int argc, char *argv[])
while (Keypressed(input, Key.MvSongDown) && to < myPlaylistEditor->Content->Size()-1) while (Keypressed(input, Key.MvSongDown) && to < myPlaylistEditor->Content->Size()-1)
{ {
TraceMpdStatus(); TraceMpdStatus();
time(&Timer); myPlaylist->UpdateTimer();
to++; to++;
myPlaylistEditor->Content->Swap(to, to-1); myPlaylistEditor->Content->Swap(to, to-1);
myPlaylistEditor->Content->Scroll(wDown); myPlaylistEditor->Content->Scroll(wDown);
@@ -934,10 +929,10 @@ int main(int argc, char *argv[])
while (Keypressed(input, Key.SeekForward) || Keypressed(input, Key.SeekBackward)) while (Keypressed(input, Key.SeekForward) || Keypressed(input, Key.SeekBackward))
{ {
TraceMpdStatus(); TraceMpdStatus();
time(&Timer); myPlaylist->UpdateTimer();
myPlaylist->Main()->ReadKey(input); myPlaylist->Main()->ReadKey(input);
int howmuch = Config.incremental_seeking ? (Timer-t)/2+Config.seek_time : Config.seek_time; int howmuch = Config.incremental_seeking ? (myPlaylist->Timer()-t)/2+Config.seek_time : Config.seek_time;
if (songpos < s->GetTotalLength() && Keypressed(input, Key.SeekForward)) if (songpos < s->GetTotalLength() && Keypressed(input, Key.SeekForward))
{ {
@@ -1450,7 +1445,7 @@ int main(int argc, char *argv[])
myBrowser->GetDirectory("/"); myBrowser->GetDirectory("/");
myPlaylistEditor->Playlists->Clear(0); // make playlist editor update itself myPlaylistEditor->Playlists->Clear(0); // make playlist editor update itself
} }
time(&Timer); myPlaylist->UpdateTimer();
FreeSongList(result); FreeSongList(result);
} }
else if (Keypressed(input, Key.Crop)) else if (Keypressed(input, Key.Crop))
@@ -1514,8 +1509,7 @@ int main(int argc, char *argv[])
else if (Keypressed(input, Key.SortPlaylist) && myScreen == myPlaylist) else if (Keypressed(input, Key.SortPlaylist) && myScreen == myPlaylist)
{ {
myPlaylist->Sort(); myPlaylist->Sort();
myPlaylist->Main()->Highlighting(1); myPlaylist->EnableHighlighting();
time(&Timer);
} }
else if (Keypressed(input, Key.ApplyFilter)) else if (Keypressed(input, Key.ApplyFilter))
{ {
@@ -1538,8 +1532,7 @@ int main(int argc, char *argv[])
if (myScreen == myPlaylist) if (myScreen == myPlaylist)
{ {
time(&Timer); myPlaylist->EnableHighlighting();
myPlaylist->Main()->Highlighting(1);
Playlist::ReloadTotalLength = 1; Playlist::ReloadTotalLength = 1;
RedrawHeader = 1; RedrawHeader = 1;
} }
@@ -1555,7 +1548,7 @@ int main(int argc, char *argv[])
Statusbar() << "Find " << (Keypressed(input, Key.FindForward) ? "forward" : "backward") << ": "; Statusbar() << "Find " << (Keypressed(input, Key.FindForward) ? "forward" : "backward") << ": ";
string findme = wFooter->GetString(mList->GetSearchConstraint()); string findme = wFooter->GetString(mList->GetSearchConstraint());
UnlockStatusbar(); UnlockStatusbar();
time(&Timer); myPlaylist->UpdateTimer();
if (!findme.empty()) if (!findme.empty())
ShowMessage("Searching..."); ShowMessage("Searching...");
@@ -1571,6 +1564,9 @@ int main(int argc, char *argv[])
mList->NextFound(Config.wrapped_search); mList->NextFound(Config.wrapped_search);
else else
mList->PrevFound(Config.wrapped_search); mList->PrevFound(Config.wrapped_search);
if (myScreen == myPlaylist)
myPlaylist->EnableHighlighting();
} }
else if (Keypressed(input, Key.NextFoundPosition) || Keypressed(input, Key.PrevFoundPosition)) else if (Keypressed(input, Key.NextFoundPosition) || Keypressed(input, Key.PrevFoundPosition))
{ {

View File

@@ -90,6 +90,7 @@ void Playlist::SwitchTo()
myScreen = this; myScreen = this;
w->Window::Clear(); w->Window::Clear();
EnableHighlighting();
RedrawHeader = 1; RedrawHeader = 1;
} }
@@ -274,6 +275,12 @@ void Playlist::FixPositions(size_t beginning)
w->ShowFiltered(); w->ShowFiltered();
} }
void Playlist::EnableHighlighting()
{
w->Highlighting(1);
UpdateTimer();
}
bool Playlist::Sorting(MPD::Song *a, MPD::Song *b) bool Playlist::Sorting(MPD::Song *a, MPD::Song *b)
{ {
for (size_t i = 0; i < SortOptions; i++) for (size_t i = 0; i < SortOptions; i++)

View File

@@ -58,6 +58,10 @@ class Playlist : public Screen< Menu<MPD::Song> >
void Sort(); void Sort();
void FixPositions(size_t = 0); void FixPositions(size_t = 0);
void EnableHighlighting();
void UpdateTimer() { time(&itsTimer); }
time_t Timer() const { return itsTimer; }
static std::string SongToString(const MPD::Song &, void *); static std::string SongToString(const MPD::Song &, void *);
static std::string SongInColumnsToString(const MPD::Song &, void *); static std::string SongInColumnsToString(const MPD::Song &, void *);
@@ -80,6 +84,8 @@ class Playlist : public Screen< Menu<MPD::Song> >
size_t itsRemainingTime; size_t itsRemainingTime;
size_t itsScrollBegin; size_t itsScrollBegin;
time_t itsTimer;
static void ShowTime(std::ostringstream &, size_t); static void ShowTime(std::ostringstream &, size_t);
static bool Sorting(MPD::Song *a, MPD::Song *b); static bool Sorting(MPD::Song *a, MPD::Song *b);

View File

@@ -103,11 +103,13 @@ void UnlockStatusbar()
void TraceMpdStatus() void TraceMpdStatus()
{ {
static time_t now;
if (Mpd->Connected()) if (Mpd->Connected())
Mpd->UpdateStatus(); Mpd->UpdateStatus();
time_t now = time(NULL);
if (myScreen == myPlaylist && now == Timer+Config.playlist_disable_highlight_delay) time(&now);
if (myScreen == myPlaylist && now == myPlaylist->Timer()+Config.playlist_disable_highlight_delay)
myPlaylist->Main()->Highlighting(!Config.playlist_disable_highlight_delay); myPlaylist->Main()->Highlighting(!Config.playlist_disable_highlight_delay);
if (lock_statusbar_delay > 0) if (lock_statusbar_delay > 0)