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 MainHeight;
extern time_t Timer;
# ifdef HAVE_CURL_CURL_H
extern pthread_mutex_t CurlLock;
# endif

View File

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

View File

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

View File

@@ -58,6 +58,10 @@ class Playlist : public Screen< Menu<MPD::Song> >
void Sort();
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 SongInColumnsToString(const MPD::Song &, void *);
@@ -80,6 +84,8 @@ class Playlist : public Screen< Menu<MPD::Song> >
size_t itsRemainingTime;
size_t itsScrollBegin;
time_t itsTimer;
static void ShowTime(std::ostringstream &, size_t);
static bool Sorting(MPD::Song *a, MPD::Song *b);

View File

@@ -103,11 +103,13 @@ void UnlockStatusbar()
void TraceMpdStatus()
{
static time_t now;
if (Mpd->Connected())
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);
if (lock_statusbar_delay > 0)