status: split NcmpcppStatusChanged into smaller pieces

This commit is contained in:
Andrzej Rybczak
2012-09-12 02:41:21 +02:00
parent 8973aac7a1
commit 8f065e2da3
24 changed files with 633 additions and 510 deletions

View File

@@ -41,6 +41,7 @@ ncmpcpp_SOURCES = \
statusbar.cpp \
tag_editor.cpp \
tiny_tag_editor.cpp \
title.cpp \
visualizer.cpp \
window.cpp
@@ -94,5 +95,6 @@ noinst_HEADERS = \
statusbar.h \
tag_editor.h \
tiny_tag_editor.h \
title.h \
visualizer.h \
window.h

View File

@@ -53,6 +53,7 @@
#include "tag_editor.h"
#include "tiny_tag_editor.h"
#include "visualizer.h"
#include "title.h"
#ifdef HAVE_TAGLIB_H
# include "fileref.h"
@@ -129,7 +130,6 @@ void Action::SetResizeFlags()
void Action::ResizeScreen()
{
using Global::MainHeight;
using Global::RedrawStatusbar;
using Global::wHeader;
using Global::wFooter;
@@ -174,27 +174,24 @@ void Action::ResizeScreen()
wFooter->resize(COLS, Config.statusbar_visibility ? 2 : 1);
ApplyToVisibleWindows(&BasicScreen::Refresh);
RedrawStatusbar = true;
MPD::StatusChanges changes;
Status::Changes::elapsedTime();
if (!Mpd.isPlaying() || DesignChanged)
{
changes.PlayerState = 1;
Status::Changes::playerState();
if (DesignChanged)
changes.Volume = 1;
Status::Changes::mixer();
}
// Note: routines for drawing separator if alternative user
// interface is active and header is hidden are placed in
// NcmpcppStatusChanges.StatusFlags
changes.StatusFlags = 1; // force status update
NcmpcppStatusChanged(&Mpd, changes, 0);
Status::Changes::flags();
if (DesignChanged)
{
RedrawStatusbar = true;
NcmpcppStatusChanged(&Mpd, MPD::StatusChanges(), 0);
DesignChanged = 0;
DesignChanged = false;
Statusbar::msg("User interface: %s", Config.new_design ? "Alternative" : "Classic");
}
DrawHeader();
drawHeader();
wFooter->refresh();
refresh();
}
@@ -245,7 +242,7 @@ void Action::Seek()
SeekingInProgress = true;
while (true)
{
TraceMpdStatus();
Status::trace();
myPlaylist->UpdateTimer();
int howmuch = Config.incremental_seeking ? (Timer.tv_sec-t.tv_sec)/2+Config.seek_time : Config.seek_time;
@@ -742,7 +739,7 @@ void MasterScreen::Run()
myInactiveScreen = myScreen;
myScreen = myLockedScreen;
DrawHeader();
drawHeader();
}
bool SlaveScreen::canBeRun() const
@@ -763,7 +760,7 @@ void SlaveScreen::Run()
myScreen = myInactiveScreen;
myInactiveScreen = myLockedScreen;
DrawHeader();
drawHeader();
}
void VolumeUp::Run()
@@ -804,7 +801,7 @@ void Delete::Run()
question += ToString(wideShorten(ToWString(name), COLS-question.size()-10));
question += "\"?";
}
bool yes = AskYesNoQuestion(question, TraceMpdStatus);
bool yes = AskYesNoQuestion(question, Status::trace);
if (yes)
{
bool success = true;
@@ -849,7 +846,7 @@ void Delete::Run()
question += ToString(wideShorten(ToWString(myPlaylistEditor->Playlists->current().value()), COLS-question.size()-10));
question += "\"?";
}
bool yes = AskYesNoQuestion(question, TraceMpdStatus);
bool yes = AskYesNoQuestion(question, Status::trace);
if (yes)
{
auto list = getSelectedOrCurrent(myPlaylistEditor->Playlists->begin(), myPlaylistEditor->Playlists->end(), myPlaylistEditor->Playlists->currentI());
@@ -929,7 +926,7 @@ void SavePlaylist::Run()
}
else if (result == MPD_SERVER_ERROR_EXIST)
{
bool yes = AskYesNoQuestion("Playlist \"" + playlist_name + "\" already exists, overwrite?", TraceMpdStatus);
bool yes = AskYesNoQuestion("Playlist \"" + playlist_name + "\" already exists, overwrite?", Status::trace);
if (yes)
{
Mpd.DeletePlaylist(playlist_name);
@@ -1232,7 +1229,7 @@ void JumpToPlayingSong::Run()
else if (myScreen == myBrowser)
{
myBrowser->LocateSong(myPlaylist->nowPlayingSong());
DrawHeader();
drawHeader();
}
else if (myScreen == myLibrary)
{
@@ -1782,7 +1779,7 @@ void CropMainPlaylist::Run()
{
bool yes = true;
if (Config.ask_before_clearing_main_playlist)
yes = AskYesNoQuestion("Do you really want to crop main playlist?", TraceMpdStatus);
yes = AskYesNoQuestion("Do you really want to crop main playlist?", Status::trace);
if (yes)
{
Statusbar::msg("Cropping playlist...");
@@ -1802,7 +1799,7 @@ void CropPlaylist::Run()
std::string playlist = myPlaylistEditor->Playlists->current().value();
bool yes = true;
if (Config.ask_before_clearing_main_playlist)
yes = AskYesNoQuestion("Do you really want to crop playlist \"" + playlist + "\"?", TraceMpdStatus);
yes = AskYesNoQuestion("Do you really want to crop playlist \"" + playlist + "\"?", Status::trace);
if (yes)
{
auto delete_fun = std::bind(&MPD::Connection::PlaylistDelete, _1, playlist, _2);
@@ -1816,7 +1813,7 @@ void ClearMainPlaylist::Run()
{
bool yes = true;
if (Config.ask_before_clearing_main_playlist)
yes = AskYesNoQuestion("Do you really want to clear main playlist?", TraceMpdStatus);
yes = AskYesNoQuestion("Do you really want to clear main playlist?", Status::trace);
if (yes)
{
auto delete_fun = std::bind(&MPD::Connection::Delete, _1, _2);
@@ -1838,7 +1835,7 @@ void ClearPlaylist::Run()
std::string playlist = myPlaylistEditor->Playlists->current().value();
bool yes = true;
if (Config.ask_before_clearing_main_playlist)
yes = AskYesNoQuestion("Do you really want to clear playlist \"" + playlist + "\"?", TraceMpdStatus);
yes = AskYesNoQuestion("Do you really want to clear playlist \"" + playlist + "\"?", Status::trace);
if (yes)
{
auto delete_fun = std::bind(&MPD::Connection::PlaylistDelete, _1, playlist, _2);
@@ -1902,7 +1899,7 @@ void ApplyFilter::Run()
{
myPlaylist->EnableHighlighting();
Playlist::ReloadTotalLength = true;
DrawHeader();
drawHeader();
}
ListsChangeFinisher();
}
@@ -2007,7 +2004,7 @@ void ToggleReplayGainMode::Run()
int answer = 0;
do
{
TraceMpdStatus();
Status::trace();
answer = wFooter->readKey();
}
while (answer != 'o' && answer != 't' && answer != 'a');
@@ -2051,7 +2048,7 @@ void AddRandomItems::Run()
int answer = 0;
do
{
TraceMpdStatus();
Status::trace();
answer = wFooter->readKey();
}
while (answer != 's' && answer != 'a' && answer != 'b');
@@ -2121,7 +2118,7 @@ void ToggleLibraryTagType::Run()
int answer = 0;
do
{
TraceMpdStatus();
Status::trace();
answer = wFooter->readKey();
}
while (answer != 'a' && answer != 'A' && answer != 'y' && answer != 'g' && answer != 'c' && answer != 'p');

View File

@@ -36,6 +36,7 @@
#include "statusbar.h"
#include "tag_editor.h"
#include "utility/comparators.h"
#include "title.h"
using namespace std::placeholders;
@@ -117,7 +118,7 @@ void Browser::SwitchTo()
if (myScreen != this && myScreen->isTabbable())
Global::myPrevScreen = myScreen;
myScreen = this;
DrawHeader();
drawHeader();
}
std::wstring Browser::Title()
@@ -141,7 +142,7 @@ void Browser::EnterPressed()
GetDirectory(getParentDirectory(itsBrowsedDir), itsBrowsedDir);
else
GetDirectory(item.name, itsBrowsedDir);
DrawHeader();
drawHeader();
break;
}
case itSong:
@@ -231,7 +232,7 @@ void Browser::MouseButtonPressed(MEVENT me)
if (me.bstate & BUTTON1_PRESSED)
{
GetDirectory(w->current().value().name);
DrawHeader();
drawHeader();
}
else
{
@@ -383,7 +384,7 @@ void Browser::LocateSong(const MPD::Song &s)
break;
}
}
DrawHeader();
drawHeader();
}
void Browser::GetDirectory(std::string dir, std::string subdir)
@@ -568,7 +569,7 @@ void Browser::ChangeBrowseMode()
itsBrowsedDir.resize(itsBrowsedDir.length()-1);
w->reset();
GetDirectory(itsBrowsedDir);
DrawHeader();
drawHeader();
}
bool Browser::deleteItem(const MPD::Item &item)

View File

@@ -32,6 +32,7 @@
#include "settings.h"
#include "status.h"
#include "statusbar.h"
#include "title.h"
using Global::MainHeight;
using Global::MainStartY;
@@ -103,7 +104,7 @@ void Clock::SwitchTo()
if (myScreen != this && myScreen->isTabbable())
Global::myPrevScreen = myScreen;
myScreen = this;
DrawHeader();
drawHeader();
Prepare();
itsPane->refresh();
// clearing screen apparently fixes the problem with last digits being misrendered

View File

@@ -35,7 +35,5 @@ size_t Global::MainHeight;
bool Global::ShowMessages = false;
bool Global::SeekingInProgress = false;
bool Global::RedrawStatusbar = true;
std::string Global::VolumeState;
timeval Global::Timer;

View File

@@ -61,9 +61,6 @@ namespace Global
// indicates whether seeking action in currently in progress
extern bool SeekingInProgress;
// indicates whether statusbar should be immediately repainted
extern bool RedrawStatusbar;
// string that represents volume in right top corner. being global
// to be used for calculating width offsets in various files.
extern std::string VolumeState;

View File

@@ -26,6 +26,7 @@
#include "settings.h"
#include "status.h"
#include "utility/wide_string.h"
#include "title.h"
using Global::MainHeight;
using Global::MainStartY;
@@ -131,7 +132,7 @@ void Help::SwitchTo()
if (myScreen != this && myScreen->isTabbable())
Global::myPrevScreen = myScreen;
myScreen = this;
DrawHeader();
drawHeader();
}
std::wstring Help::Title()

View File

@@ -38,6 +38,7 @@
#include "charset.h"
#include "global.h"
#include "statusbar.h"
#include "title.h"
using Global::MainHeight;
using Global::MainStartY;
@@ -106,7 +107,7 @@ void Lastfm::SwitchTo()
myOldScreen = myScreen;
myScreen = this;
DrawHeader();
drawHeader();
}
void Lastfm::Load()

View File

@@ -34,6 +34,7 @@
#include "settings.h"
#include "song.h"
#include "statusbar.h"
#include "title.h"
using Global::MainHeight;
using Global::MainStartY;
@@ -81,7 +82,7 @@ void Lyrics::Update()
const MPD::Song s = myPlaylist->nowPlayingSong();
if (!s.empty() && !s.getArtist().empty() && !s.getTitle().empty())
{
DrawHeader();
drawHeader();
itsScrollBegin = 0;
itsSong = s;
Load();
@@ -130,7 +131,7 @@ void Lyrics::SwitchTo()
itsSong = *s;
Load();
DrawHeader();
drawHeader();
}
else
{

View File

@@ -34,6 +34,7 @@
#include "statusbar.h"
#include "utility/comparators.h"
#include "utility/type_conversions.h"
#include "title.h"
using namespace std::placeholders;
@@ -238,7 +239,7 @@ void MediaLibrary::SwitchTo()
if (myScreen != this && myScreen->isTabbable())
Global::myPrevScreen = myScreen;
myScreen = this;
DrawHeader();
drawHeader();
markSongsInPlaylist(songsProxyList());
Refresh();
}

View File

@@ -42,6 +42,7 @@
#include "status.h"
#include "statusbar.h"
#include "visualizer.h"
#include "title.h"
namespace
{
@@ -71,7 +72,7 @@ namespace
# ifndef USE_PDCURSES // destroying screen somehow crashes pdcurses
NC::destroyScreen();
# endif // USE_PDCURSES
WindowTitle("");
windowTitle("");
}
}
@@ -179,8 +180,8 @@ int main(int argc, char **argv)
if (Config.startup_screen != myScreen)
Config.startup_screen->SwitchTo();
Mpd.SetStatusUpdater(NcmpcppStatusChanged, 0);
Mpd.SetErrorHandler(NcmpcppErrorCallback, 0);
Mpd.SetStatusUpdater(Status::update, 0);
Mpd.SetErrorHandler(Status::handleError, 0);
// local variables
Key input(0, Key::Standard);
@@ -199,7 +200,7 @@ int main(int argc, char **argv)
Mpd.OrderDataFetching();
if (Config.jump_to_now_playing_song_at_start)
{
TraceMpdStatus();
Status::trace();
int curr_pos = Mpd.GetCurrentSongPos();
if (curr_pos >= 0)
myPlaylist->Items->highlight(curr_pos);
@@ -230,7 +231,7 @@ int main(int argc, char **argv)
}
}
TraceMpdStatus();
Status::trace();
ShowMessages = true;
@@ -242,7 +243,7 @@ int main(int argc, char **argv)
&& (myScreen == myPlaylist || myScreen == myBrowser || myScreen == myLyrics)
)
{
DrawHeader();
drawHeader();
past = Timer;
}

View File

@@ -27,6 +27,7 @@
#include "settings.h"
#include "status.h"
#include "statusbar.h"
#include "title.h"
using Global::MainHeight;
using Global::MainStartY;
@@ -66,7 +67,7 @@ void Outputs::SwitchTo()
Global::myPrevScreen = myScreen;
myScreen = this;
w->Window::clear();
DrawHeader();
drawHeader();
}
void Outputs::Resize()

View File

@@ -31,6 +31,7 @@
#include "status.h"
#include "statusbar.h"
#include "utility/comparators.h"
#include "title.h"
using namespace std::placeholders;
@@ -122,7 +123,7 @@ void Playlist::SwitchTo()
EnableHighlighting();
if (w != Items) // even if sorting window is active, background has to be refreshed anyway
Items->display();
DrawHeader();
drawHeader();
}
void Playlist::Resize()

View File

@@ -33,6 +33,7 @@
#include "statusbar.h"
#include "tag_editor.h"
#include "utility/comparators.h"
#include "title.h"
using namespace std::placeholders;
@@ -134,7 +135,7 @@ void PlaylistEditor::SwitchTo()
if (myScreen != this && myScreen->isTabbable())
Global::myPrevScreen = myScreen;
myScreen = this;
DrawHeader();
drawHeader();
markSongsInPlaylist(contentProxyList());
Refresh();
}

View File

@@ -31,6 +31,7 @@
#include "status.h"
#include "statusbar.h"
#include "utility/comparators.h"
#include "title.h"
using namespace std::placeholders;
@@ -149,7 +150,7 @@ void SearchEngine::SwitchTo()
if (myScreen != this && myScreen->isTabbable())
Global::myPrevScreen = myScreen;
myScreen = this;
DrawHeader();
drawHeader();
markSongsInPlaylist(getProxySongList());
}

View File

@@ -22,6 +22,7 @@
#include "helpers.h"
#include "song_info.h"
#include "tag_editor.h"
#include "title.h"
#ifdef HAVE_TAGLIB_H
# include "fileref.h"
@@ -102,7 +103,7 @@ void SongInfo::SwitchTo()
// redraw header after we're done with the file, since reading it from disk
// takes a bit of time and having header updated before content of a window
// is displayed doesn't look nice.
DrawHeader();
drawHeader();
}
void SongInfo::PrepareSong(MPD::Song &s)

View File

@@ -18,12 +18,8 @@
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
#include <cstring>
#include <sys/time.h>
#include <iostream>
#include <stdexcept>
#include "browser.h"
#include "charset.h"
#include "global.h"
@@ -40,10 +36,9 @@
#include "statusbar.h"
#include "tag_editor.h"
#include "visualizer.h"
#include "title.h"
using Global::myScreen;
using Global::myLockedScreen;
using Global::myInactiveScreen;
using Global::wFooter;
using Global::wHeader;
@@ -51,26 +46,32 @@ using Global::wHeader;
using Global::Timer;
using Global::VolumeState;
#ifndef USE_PDCURSES
void WindowTitle(const std::string &status)
{
if (strcmp(getenv("TERM"), "linux") && Config.set_window_title)
std::cout << "\033]0;" << status << "\7";
}
#endif // !USE_PDCURSES
namespace {//
void DrawNowPlayingTitle(MPD::Song &np)
timeval past = { 0, 0 };
size_t playing_song_scroll_begin = 0;
size_t first_line_scroll_begin = 0;
size_t second_line_scroll_begin = 0;
std::string player_state;
char mpd_repeat;
char mpd_random;
char mpd_single;
char mpd_consume;
char mpd_crossfade;
char mpd_db_updating;
void drawTitle(const MPD::Song &np)
{
if (np.empty())
np = myPlaylist->nowPlayingSong();
if (!np.empty())
WindowTitle(np.toString(Config.song_window_title_format));
assert(!np.empty());
windowTitle(np.toString(Config.song_window_title_format));
}
void TraceMpdStatus()
{
static timeval past = { 0, 0 };
}
void Status::trace()
{
gettimeofday(&Timer, 0);
if (Mpd.Connected() && (Mpd.SupportsIdle() || Timer.tv_sec > past.tv_sec))
{
@@ -103,7 +104,7 @@ void TraceMpdStatus()
Statusbar::tryRedraw();
}
void NcmpcppErrorCallback(MPD::Connection *, int errorid, const char *msg, void *)
void Status::handleError(MPD::Connection * , int errorid, const char *msg, void *)
{
// for errorid:
// - 0-7 bits define MPD_ERROR_* codes, compare them with (0xff & errorid)
@@ -126,20 +127,8 @@ void NcmpcppErrorCallback(MPD::Connection *, int errorid, const char *msg, void
Statusbar::msg("MPD: %s", msg);
}
void NcmpcppStatusChanged(MPD::Connection *, MPD::StatusChanges changed, void *)
void Status::Changes::playlist()
{
static size_t playing_song_scroll_begin = 0;
static size_t first_line_scroll_begin = 0;
static size_t second_line_scroll_begin = 0;
static std::string player_state;
MPD::Song np;
int sx = wFooter->getX();
int sy = wFooter->getY();
if (changed.Playlist)
{
myPlaylist->Items->clearSearchResults();
withUnfilteredMenuReapplyFilter(*myPlaylist->Items, []() {
size_t playlist_length = Mpd.GetPlaylistLength();
@@ -169,7 +158,8 @@ void NcmpcppStatusChanged(MPD::Connection *, MPD::StatusChanges changed, void *)
}
});
DrawNowPlayingTitle(np);
if (Mpd.isPlaying())
drawTitle(myPlaylist->nowPlayingSong());
Playlist::ReloadTotalLength = true;
Playlist::ReloadRemaining = true;
@@ -182,9 +172,10 @@ void NcmpcppStatusChanged(MPD::Connection *, MPD::StatusChanges changed, void *)
markSongsInPlaylist(myLibrary->songsProxyList());
if (isVisible(myPlaylistEditor))
markSongsInPlaylist(myPlaylistEditor->contentProxyList());
}
if (changed.StoredPlaylists)
{
}
void Status::Changes::storedPlaylists()
{
if (myPlaylistEditor->Main())
{
myPlaylistEditor->requestPlaylistsUpdate();
@@ -196,9 +187,10 @@ void NcmpcppStatusChanged(MPD::Connection *, MPD::StatusChanges changed, void *)
if (isVisible(myBrowser))
myBrowser->Refresh();
}
}
if (changed.Database)
{
}
void Status::Changes::database()
{
if (myBrowser->Main())
{
if (isVisible(myBrowser))
@@ -219,10 +211,10 @@ void NcmpcppStatusChanged(MPD::Connection *, MPD::StatusChanges changed, void *)
else
myLibrary->Tags->clear();
}
changed.DBUpdating = 1;
}
if (changed.PlayerState)
{
}
void Status::Changes::playerState()
{
MPD::PlayerState state = Mpd.GetState();
switch (state)
{
@@ -233,11 +225,11 @@ void NcmpcppStatusChanged(MPD::Connection *, MPD::StatusChanges changed, void *)
}
case MPD::psPlay:
{
DrawNowPlayingTitle(np);
drawTitle(myPlaylist->nowPlayingSong());
player_state = Config.new_design ? "[playing]" : "Playing: ";
Playlist::ReloadRemaining = true;
if (Mpd.GetOldState() == MPD::psStop) // show track info in status immediately
changed.ElapsedTime = 1;
elapsedTime();
break;
}
case MPD::psPause:
@@ -247,7 +239,7 @@ void NcmpcppStatusChanged(MPD::Connection *, MPD::StatusChanges changed, void *)
}
case MPD::psStop:
{
WindowTitle("ncmpcpp " VERSION);
windowTitle("ncmpcpp " VERSION);
if (Progressbar::isUnlocked())
Progressbar::draw(0, 0);
Playlist::ReloadRemaining = true;
@@ -255,8 +247,8 @@ void NcmpcppStatusChanged(MPD::Connection *, MPD::StatusChanges changed, void *)
{
*wHeader << NC::XY(0, 0) << wclrtoeol << NC::XY(0, 1) << wclrtoeol;
player_state = "[stopped]";
changed.Volume = 1;
changed.StatusFlags = 1;
mixer();
flags();
}
else
player_state.clear();
@@ -267,10 +259,12 @@ void NcmpcppStatusChanged(MPD::Connection *, MPD::StatusChanges changed, void *)
break;
}
}
# ifdef ENABLE_VISUALIZER
if (myScreen == myVisualizer)
wFooter->setTimeout(state == MPD::psPlay ? Visualizer::WindowTimeout : 500);
# endif // ENABLE_VISUALIZER
if (Config.new_design)
{
*wHeader << NC::XY(0, 1) << NC::fmtBold << player_state << NC::fmtBoldEnd;
@@ -284,9 +278,14 @@ void NcmpcppStatusChanged(MPD::Connection *, MPD::StatusChanges changed, void *)
else
*wFooter << NC::fmtBold << player_state << NC::fmtBoldEnd;
}
}
if (changed.SongID)
{
}
void Status::Changes::songID()
{
Playlist::ReloadRemaining = true;
playing_song_scroll_begin = 0;
first_line_scroll_begin = 0;
second_line_scroll_begin = 0;
if (Mpd.isPlaying())
{
GNUC_UNUSED int res;
@@ -298,24 +297,29 @@ void NcmpcppStatusChanged(MPD::Connection *, MPD::StatusChanges changed, void *)
Lyrics::DownloadInBackground(myPlaylist->nowPlayingSong());
# endif // HAVE_CURL_CURL_H
DrawNowPlayingTitle(np);
drawTitle(myPlaylist->nowPlayingSong());
if (Config.autocenter_mode && !myPlaylist->Items->isFiltered())
myPlaylist->Items->highlight(Mpd.GetCurrentlyPlayingSongPos());
if (Config.now_playing_lyrics && isVisible(myLyrics) && Global::myOldScreen == myPlaylist)
myLyrics->ReloadNP = 1;
elapsedTime();
}
Playlist::ReloadRemaining = true;
playing_song_scroll_begin = 0;
first_line_scroll_begin = 0;
second_line_scroll_begin = 0;
}
void Status::Changes::elapsedTime()
{
if (!Mpd.isPlaying())
{
if (Statusbar::isUnlocked() && Config.statusbar_visibility)
*wFooter << NC::XY(0, 1) << wclrtoeol;
return;
}
if (changed.ElapsedTime || changed.SongID || Global::RedrawStatusbar)
{
if (Mpd.isPlaying())
{
DrawNowPlayingTitle(np);
MPD::Song np = myPlaylist->nowPlayingSong();
drawTitle(np);
std::string tracklength;
if (Config.new_design)
@@ -363,7 +367,7 @@ void NcmpcppStatusChanged(MPD::Connection *, MPD::StatusChanges changed, void *)
*wHeader << NC::XY(wHeader->getWidth()-VolumeState.length(), 0) << Config.volume_color << VolumeState << NC::clEnd;
changed.StatusFlags = 1;
flags();
}
else if (Statusbar::isUnlocked() && Config.statusbar_visibility)
{
@@ -400,65 +404,51 @@ void NcmpcppStatusChanged(MPD::Connection *, MPD::StatusChanges changed, void *)
}
if (Progressbar::isUnlocked())
Progressbar::draw(Mpd.GetElapsedTime(), Mpd.GetTotalTime());
Global::RedrawStatusbar = false;
}
else
{
if (Statusbar::isUnlocked() && Config.statusbar_visibility)
*wFooter << NC::XY(0, 1) << wclrtoeol;
}
}
}
static char mpd_repeat;
static char mpd_random;
static char mpd_single;
static char mpd_consume;
static char mpd_crossfade;
static char mpd_db_updating;
if (changed.Repeat)
{
void Status::Changes::repeat()
{
mpd_repeat = Mpd.GetRepeat() ? 'r' : 0;
Statusbar::msg("Repeat mode is %s", !mpd_repeat ? "off" : "on");
}
if (changed.Random)
{
}
void Status::Changes::random()
{
mpd_random = Mpd.GetRandom() ? 'z' : 0;
Statusbar::msg("Random mode is %s", !mpd_random ? "off" : "on");
}
if (changed.Single)
{
}
void Status::Changes::single()
{
mpd_single = Mpd.GetSingle() ? 's' : 0;
Statusbar::msg("Single mode is %s", !mpd_single ? "off" : "on");
}
if (changed.Consume)
{
}
void Status::Changes::consume()
{
mpd_consume = Mpd.GetConsume() ? 'c' : 0;
Statusbar::msg("Consume mode is %s", !mpd_consume ? "off" : "on");
}
if (changed.Crossfade)
{
}
void Status::Changes::crossfade()
{
int crossfade = Mpd.GetCrossfade();
mpd_crossfade = crossfade ? 'x' : 0;
Statusbar::msg("Crossfade set to %d seconds", crossfade);
}
if (changed.DBUpdating)
{
// mpd-0.{14,15} doesn't support idle notification that dbupdate had
// finished and nothing changed, so we need to switch it off for them.
if (!Mpd.SupportsIdle() || Mpd.Version() > 15)
}
void Status::Changes::dbUpdateState()
{
mpd_db_updating = Mpd.GetDBIsUpdating() ? 'U' : 0;
Statusbar::msg(Mpd.GetDBIsUpdating() ? "Database update started" : "Database update finished");
if (changed.Database && myScreen == mySelectedItemsAdder)
{
myScreen->SwitchTo(); // switch to previous screen
Statusbar::msg("Database has changed, you need to select your item(s) once again");
}
}
if (changed.StatusFlags && (Config.header_visibility || Config.new_design))
{
std::string switch_state;
}
void Status::Changes::flags()
{
if (!Config.header_visibility && !Config.new_design)
return;
std::string switch_state;
if (Config.new_design)
{
switch_state += '[';
@@ -510,9 +500,13 @@ void NcmpcppStatusChanged(MPD::Connection *, MPD::StatusChanges changed, void *)
attroff(A_BOLD|COLOR_PAIR(Config.state_line_color));
refresh();
}
}
if (changed.Volume && Config.display_volume_level && (Config.header_visibility || Config.new_design))
{
}
void Status::Changes::mixer()
{
if (!Config.display_volume_level || (!Config.header_visibility && !Config.new_design))
return;
VolumeState = Config.new_design ? " Vol: " : " Volume: ";
int volume = Mpd.GetVolume();
if (volume < 0)
@@ -526,41 +520,50 @@ void NcmpcppStatusChanged(MPD::Connection *, MPD::StatusChanges changed, void *)
*wHeader << NC::XY(wHeader->getWidth()-VolumeState.length(), 0) << VolumeState;
*wHeader << NC::clEnd;
wHeader->refresh();
}
if (changed.Outputs)
{
}
void Status::Changes::outputs()
{
# ifdef ENABLE_OUTPUTS
myOutputs->FetchList();
# endif // ENABLE_OUTPUTS
}
wFooter->goToXY(sx, sy);
if (changed.PlayerState || (changed.ElapsedTime && (!Config.new_design || Mpd.GetState() == MPD::psPlay)))
wFooter->refresh();
if (changed.Playlist || changed.Database || changed.PlayerState || changed.SongID)
ApplyToVisibleWindows(&BasicScreen::RefreshWindow);
}
void DrawHeader()
void Status::update(MPD::Connection *, MPD::StatusChanges changes, void *)
{
if (!Config.header_visibility)
return;
if (Config.new_design)
{
std::wstring title = myScreen->Title();
*wHeader << NC::XY(0, 3) << wclrtoeol;
*wHeader << NC::fmtBold << Config.alternative_ui_separator_color;
mvwhline(wHeader->raw(), 2, 0, 0, COLS);
mvwhline(wHeader->raw(), 4, 0, 0, COLS);
*wHeader << NC::XY((COLS-wideLength(title))/2, 3);
*wHeader << Config.header_color << title << NC::clEnd;
*wHeader << NC::clEnd << NC::fmtBoldEnd;
}
else
{
*wHeader << NC::XY(0, 0) << wclrtoeol << NC::fmtBold << myScreen->Title() << NC::fmtBoldEnd;
*wHeader << Config.volume_color;
*wHeader << NC::XY(wHeader->getWidth()-VolumeState.length(), 0) << VolumeState;
*wHeader << NC::clEnd;
}
wHeader->refresh();
if (changes.Playlist)
Changes::playlist();
if (changes.StoredPlaylists)
Changes::storedPlaylists();
if (changes.Database)
Changes::database();
if (changes.PlayerState)
Changes::playerState();
if (changes.SongID)
Changes::songID();
if (changes.ElapsedTime)
Changes::elapsedTime();
if (changes.Repeat)
Changes::repeat();
if (changes.Random)
Changes::random();
if (changes.Single)
Changes::single();
if (changes.Consume)
Changes::consume();
if (changes.Crossfade)
Changes::crossfade();
if (changes.DBUpdating)
Changes::dbUpdateState();
if (changes.StatusFlags)
Changes::flags();
if (changes.Volume)
Changes::mixer();
if (changes.Outputs)
Changes::outputs();
if (changes.PlayerState || (changes.ElapsedTime && (!Config.new_design || Mpd.GetState() == MPD::psPlay)))
wFooter->refresh();
if (changes.Playlist || changes.Database || changes.PlayerState || changes.SongID)
ApplyToVisibleWindows(&BasicScreen::RefreshWindow);
}

View File

@@ -24,18 +24,34 @@
#include "interfaces.h"
#include "mpdpp.h"
#ifndef USE_PDCURSES
void WindowTitle(const std::string &);
#else
# define WindowTitle(x);
#endif // USE_PDCURSES
namespace Status {//
void DrawNowPlayingTitle();
void trace();
void TraceMpdStatus();
void NcmpcppStatusChanged(MPD::Connection *, MPD::StatusChanges, void *);
void NcmpcppErrorCallback(MPD::Connection *, int, const char *, void *);
void handleError(MPD::Connection * , int errorid, const char *msg, void *);
void DrawHeader();
void update(MPD::Connection *, MPD::StatusChanges changes, void *);
namespace Changes {//
void playlist();
void storedPlaylists();
void database();
void playerState();
void songID();
void elapsedTime();
void repeat();
void random();
void single();
void consume();
void crossfade();
void dbUpdateState();
void flags();
void mixer();
void outputs();
}
}
#endif

View File

@@ -175,7 +175,7 @@ void Statusbar::Helpers::mpd()
void Statusbar::Helpers::getString(const std::wstring &)
{
TraceMpdStatus();
Status::trace();
}
void Statusbar::Helpers::ApplyFilterImmediately::operator()(const std::wstring &ws)
@@ -194,6 +194,6 @@ void Statusbar::Helpers::ApplyFilterImmediately::operator()(const std::wstring &
m_f->applyFilter(ToString(m_ws));
myScreen->RefreshWindow();
}
TraceMpdStatus();
Status::trace();
}
}

View File

@@ -45,6 +45,7 @@
#include "song_info.h"
#include "statusbar.h"
#include "utility/comparators.h"
#include "title.h"
using namespace std::placeholders;
@@ -226,7 +227,7 @@ void TagEditor::SwitchTo()
if (myScreen != this && myScreen->isTabbable())
Global::myPrevScreen = myScreen;
myScreen = this;
DrawHeader();
drawHeader();
Refresh();
}
@@ -497,7 +498,7 @@ void TagEditor::EnterPressed()
if (w == TagTypes && id == 5)
{
bool yes = Action::AskYesNoQuestion("Number tracks?", TraceMpdStatus);
bool yes = Action::AskYesNoQuestion("Number tracks?", Status::trace);
if (yes)
{
auto it = EditedSongs.begin();

View File

@@ -38,6 +38,7 @@
#include "search_engine.h"
#include "statusbar.h"
#include "tag_editor.h"
#include "title.h"
using Global::MainHeight;
using Global::MainStartY;
@@ -83,7 +84,7 @@ void TinyTagEditor::SwitchTo()
myOldScreen = myScreen;
myScreen = this;
DrawHeader();
drawHeader();
}
else
{

65
src/title.cpp Normal file
View File

@@ -0,0 +1,65 @@
/***************************************************************************
* Copyright (C) 2008-2012 by Andrzej Rybczak *
* electricityispower@gmail.com *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
#include <cstring>
#include <iostream>
#include "global.h"
#include "settings.h"
#include "title.h"
#ifdef USE_PDCURSES
void windowTitle(const std::string &) { }
#else
void windowTitle(const std::string &status)
{
if (strcmp(getenv("TERM"), "linux") && Config.set_window_title)
std::cout << "\033]0;" << status << "\7";
}
#endif // USE_PDCURSES
void drawHeader()
{
using Global::myScreen;
using Global::wHeader;
using Global::VolumeState;
if (!Config.header_visibility)
return;
if (Config.new_design)
{
std::wstring title = myScreen->Title();
*wHeader << NC::XY(0, 3) << wclrtoeol;
*wHeader << NC::fmtBold << Config.alternative_ui_separator_color;
mvwhline(wHeader->raw(), 2, 0, 0, COLS);
mvwhline(wHeader->raw(), 4, 0, 0, COLS);
*wHeader << NC::XY((COLS-wideLength(title))/2, 3);
*wHeader << Config.header_color << title << NC::clEnd;
*wHeader << NC::clEnd << NC::fmtBoldEnd;
}
else
{
*wHeader << NC::XY(0, 0) << wclrtoeol << NC::fmtBold << myScreen->Title() << NC::fmtBoldEnd;
*wHeader << Config.volume_color;
*wHeader << NC::XY(wHeader->getWidth()-VolumeState.length(), 0) << VolumeState;
*wHeader << NC::clEnd;
}
wHeader->refresh();
}

30
src/title.h Normal file
View File

@@ -0,0 +1,30 @@
/***************************************************************************
* Copyright (C) 2008-2012 by Andrzej Rybczak *
* electricityispower@gmail.com *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
#ifndef _TITLE_H
#define _TITLE_H
#include "window.h"
void windowTitle(const std::string &title);
void drawHeader();
#endif

View File

@@ -35,6 +35,7 @@
#include "settings.h"
#include "status.h"
#include "statusbar.h"
#include "title.h"
using Global::MainStartY;
using Global::MainHeight;
@@ -82,7 +83,7 @@ void Visualizer::SwitchTo()
if (myScreen != this && myScreen->isTabbable())
Global::myPrevScreen = myScreen;
myScreen = this;
DrawHeader();
drawHeader();
w->clear();
SetFD();