settings: configuration file processing rewrite

This commit is contained in:
Andrzej Rybczak
2014-08-28 18:57:16 +02:00
parent 8a1e4a48dd
commit 4b933b29e1
35 changed files with 1881 additions and 1446 deletions

View File

@@ -80,19 +80,19 @@ std::string playerStateToString(MPD::PlayerState ps)
result = "[unknown]";
break;
case MPD::psPlay:
if (Config.new_design)
if (Config.design == Design::Alternative)
result = "[playing]";
else
result = "Playing: ";
break;
case MPD::psPause:
if (Config.new_design)
if (Config.design == Design::Alternative)
result = "[paused] ";
else
result = "[Paused] ";
break;
case MPD::psStop:
if (Config.new_design)
if (Config.design == Design::Alternative)
result = "[stopped]";
break;
default:
@@ -337,7 +337,7 @@ void Status::Changes::playerState()
if (Progressbar::isUnlocked())
Progressbar::draw(0, 0);
Playlist::ReloadRemaining = true;
if (Config.new_design)
if (Config.design == Design::Alternative)
{
*wHeader << NC::XY(0, 0) << wclrtoeol << NC::XY(0, 1) << wclrtoeol;
mixer();
@@ -358,7 +358,7 @@ void Status::Changes::playerState()
# endif // ENABLE_VISUALIZER
std::string state = playerStateToString(State::player());
if (Config.new_design)
if (Config.design == Design::Alternative)
{
*wHeader << NC::XY(0, 1) << NC::Format::Bold << state << NC::Format::NoBold;
wHeader->refresh();
@@ -428,85 +428,88 @@ void Status::Changes::elapsedTime(bool update_elapsed)
drawTitle(np);
std::string tracklength;
if (Config.new_design)
switch (Config.design)
{
if (Config.display_remaining_time)
{
tracklength = "-";
tracklength += MPD::Song::ShowTime(st.totalTime()-st.elapsedTime());
}
else
tracklength = MPD::Song::ShowTime(st.elapsedTime());
if (st.totalTime())
{
tracklength += "/";
tracklength += MPD::Song::ShowTime(st.totalTime());
}
// bitrate here doesn't look good, but it can be moved somewhere else later
if (Config.display_bitrate && st.kbps())
{
tracklength += " ";
tracklength += boost::lexical_cast<std::string>(st.kbps());
tracklength += " kbps";
}
NC::WBuffer first, second;
stringToBuffer(ToWString(Charset::utf8ToLocale(np.toString(Config.new_header_first_line, Config.tags_separator, "$"))), first);
stringToBuffer(ToWString(Charset::utf8ToLocale(np.toString(Config.new_header_second_line, Config.tags_separator, "$"))), second);
size_t first_len = wideLength(first.str());
size_t first_margin = (std::max(tracklength.length()+1, VolumeState.length()))*2;
size_t first_start = first_len < COLS-first_margin ? (COLS-first_len)/2 : tracklength.length()+1;
size_t second_len = wideLength(second.str());
size_t second_margin = (std::max(ps.length(), size_t(8))+1)*2;
size_t second_start = second_len < COLS-second_margin ? (COLS-second_len)/2 : ps.length()+1;
if (!Global::SeekingInProgress)
*wHeader << NC::XY(0, 0) << wclrtoeol << tracklength;
*wHeader << NC::XY(first_start, 0);
writeCyclicBuffer(first, *wHeader, first_line_scroll_begin, COLS-tracklength.length()-VolumeState.length()-1, L" ** ");
*wHeader << NC::XY(0, 1) << wclrtoeol << NC::Format::Bold << ps << NC::Format::NoBold;
*wHeader << NC::XY(second_start, 1);
writeCyclicBuffer(second, *wHeader, second_line_scroll_begin, COLS-ps.length()-8-2, L" ** ");
*wHeader << NC::XY(wHeader->getWidth()-VolumeState.length(), 0) << Config.volume_color << VolumeState << NC::Color::End;
flags();
}
else if (Statusbar::isUnlocked() && Config.statusbar_visibility)
{
if (Config.display_bitrate && st.kbps())
{
tracklength += " [";
tracklength += boost::lexical_cast<std::string>(st.kbps());
tracklength += " kbps]";
}
tracklength += " [";
if (st.totalTime())
{
case Design::Classic:
if (Statusbar::isUnlocked() && Config.statusbar_visibility)
{
if (Config.display_bitrate && st.kbps())
{
tracklength += " [";
tracklength += boost::lexical_cast<std::string>(st.kbps());
tracklength += " kbps]";
}
tracklength += " [";
if (st.totalTime())
{
if (Config.display_remaining_time)
{
tracklength += "-";
tracklength += MPD::Song::ShowTime(st.totalTime()-st.elapsedTime());
}
else
tracklength += MPD::Song::ShowTime(st.elapsedTime());
tracklength += "/";
tracklength += MPD::Song::ShowTime(st.totalTime());
tracklength += "]";
}
else
{
tracklength += MPD::Song::ShowTime(st.elapsedTime());
tracklength += "]";
}
NC::WBuffer np_song;
stringToBuffer(ToWString(Charset::utf8ToLocale(np.toString(Config.song_status_format, Config.tags_separator, "$"))), np_song);
*wFooter << NC::XY(0, 1) << wclrtoeol << NC::Format::Bold << ps << NC::Format::NoBold;
writeCyclicBuffer(np_song, *wFooter, playing_song_scroll_begin, wFooter->getWidth()-ps.length()-tracklength.length(), L" ** ");
*wFooter << NC::Format::Bold << NC::XY(wFooter->getWidth()-tracklength.length(), 1) << tracklength << NC::Format::NoBold;
}
break;
case Design::Alternative:
if (Config.display_remaining_time)
{
tracklength += "-";
tracklength = "-";
tracklength += MPD::Song::ShowTime(st.totalTime()-st.elapsedTime());
}
else
tracklength += MPD::Song::ShowTime(st.elapsedTime());
tracklength += "/";
tracklength += MPD::Song::ShowTime(st.totalTime());
tracklength += "]";
}
else
{
tracklength += MPD::Song::ShowTime(st.elapsedTime());
tracklength += "]";
}
NC::WBuffer np_song;
stringToBuffer(ToWString(Charset::utf8ToLocale(np.toString(Config.song_status_format, Config.tags_separator, "$"))), np_song);
*wFooter << NC::XY(0, 1) << wclrtoeol << NC::Format::Bold << ps << NC::Format::NoBold;
writeCyclicBuffer(np_song, *wFooter, playing_song_scroll_begin, wFooter->getWidth()-ps.length()-tracklength.length(), L" ** ");
*wFooter << NC::Format::Bold << NC::XY(wFooter->getWidth()-tracklength.length(), 1) << tracklength << NC::Format::NoBold;
tracklength = MPD::Song::ShowTime(st.elapsedTime());
if (st.totalTime())
{
tracklength += "/";
tracklength += MPD::Song::ShowTime(st.totalTime());
}
// bitrate here doesn't look good, but it can be moved somewhere else later
if (Config.display_bitrate && st.kbps())
{
tracklength += " ";
tracklength += boost::lexical_cast<std::string>(st.kbps());
tracklength += " kbps";
}
NC::WBuffer first, second;
stringToBuffer(ToWString(Charset::utf8ToLocale(np.toString(Config.new_header_first_line, Config.tags_separator, "$"))), first);
stringToBuffer(ToWString(Charset::utf8ToLocale(np.toString(Config.new_header_second_line, Config.tags_separator, "$"))), second);
size_t first_len = wideLength(first.str());
size_t first_margin = (std::max(tracklength.length()+1, VolumeState.length()))*2;
size_t first_start = first_len < COLS-first_margin ? (COLS-first_len)/2 : tracklength.length()+1;
size_t second_len = wideLength(second.str());
size_t second_margin = (std::max(ps.length(), size_t(8))+1)*2;
size_t second_start = second_len < COLS-second_margin ? (COLS-second_len)/2 : ps.length()+1;
if (!Global::SeekingInProgress)
*wHeader << NC::XY(0, 0) << wclrtoeol << tracklength;
*wHeader << NC::XY(first_start, 0);
writeCyclicBuffer(first, *wHeader, first_line_scroll_begin, COLS-tracklength.length()-VolumeState.length()-1, L" ** ");
*wHeader << NC::XY(0, 1) << wclrtoeol << NC::Format::Bold << ps << NC::Format::NoBold;
*wHeader << NC::XY(second_start, 1);
writeCyclicBuffer(second, *wHeader, second_line_scroll_begin, COLS-ps.length()-8-2, L" ** ");
*wHeader << NC::XY(wHeader->getWidth()-VolumeState.length(), 0) << Config.volume_color << VolumeState << NC::Color::End;
flags();
}
if (Progressbar::isUnlocked())
Progressbar::draw(st.elapsedTime(), st.totalTime());
@@ -557,69 +560,78 @@ void Status::Changes::dbUpdateState(bool show_msg)
void Status::Changes::flags()
{
if (!Config.header_visibility && !Config.new_design)
if (!Config.header_visibility && Config.design == Design::Classic)
return;
std::string switch_state;
if (Config.new_design)
switch (Config.design)
{
switch_state += '[';
switch_state += m_repeat ? m_repeat : '-';
switch_state += m_random ? m_random : '-';
switch_state += m_single ? m_single : '-';
switch_state += m_consume ? m_consume : '-';
switch_state += m_crossfade ? m_crossfade : '-';
switch_state += m_db_updating ? m_db_updating : '-';
switch_state += ']';
*wHeader << NC::XY(COLS-switch_state.length(), 1) << NC::Format::Bold << Config.state_flags_color << switch_state << NC::Color::End << NC::Format::NoBold;
if (Config.new_design && !Config.header_visibility) // in this case also draw separator
{
*wHeader << NC::Format::Bold << NC::Color::Black;
mvwhline(wHeader->raw(), 2, 0, 0, COLS);
*wHeader << NC::Color::End << NC::Format::NoBold;
}
wHeader->refresh();
}
else
{
if (m_repeat)
switch_state += m_repeat;
if (m_random)
switch_state += m_random;
if (m_single)
switch_state += m_single;
if (m_consume)
switch_state += m_consume;
if (m_crossfade)
switch_state += m_crossfade;
if (m_db_updating)
switch_state += m_db_updating;
// this is done by raw ncurses because creating another
// window only for handling this is quite silly
attrset(A_BOLD|COLOR_PAIR(int(Config.state_line_color)));
mvhline(1, 0, 0, COLS);
if (!switch_state.empty())
{
mvprintw(1, COLS-switch_state.length()-3, "[");
attroff(COLOR_PAIR(int(Config.state_line_color)));
attron(COLOR_PAIR(int(Config.state_flags_color)));
mvprintw(1, COLS-switch_state.length()-2, "%s", switch_state.c_str());
attroff(COLOR_PAIR(int(Config.state_flags_color)));
attron(COLOR_PAIR(int(Config.state_line_color)));
mvprintw(1, COLS-2, "]");
}
attroff(A_BOLD|COLOR_PAIR(int(Config.state_line_color)));
refresh();
case Design::Classic:
if (m_repeat)
switch_state += m_repeat;
if (m_random)
switch_state += m_random;
if (m_single)
switch_state += m_single;
if (m_consume)
switch_state += m_consume;
if (m_crossfade)
switch_state += m_crossfade;
if (m_db_updating)
switch_state += m_db_updating;
// this is done by raw ncurses because creating another
// window only for handling this is quite silly
attrset(A_BOLD|COLOR_PAIR(int(Config.state_line_color)));
mvhline(1, 0, 0, COLS);
if (!switch_state.empty())
{
mvprintw(1, COLS-switch_state.length()-3, "[");
attroff(COLOR_PAIR(int(Config.state_line_color)));
attron(COLOR_PAIR(int(Config.state_flags_color)));
mvprintw(1, COLS-switch_state.length()-2, "%s", switch_state.c_str());
attroff(COLOR_PAIR(int(Config.state_flags_color)));
attron(COLOR_PAIR(int(Config.state_line_color)));
mvprintw(1, COLS-2, "]");
}
attroff(A_BOLD|COLOR_PAIR(int(Config.state_line_color)));
refresh();
break;
case Design::Alternative:
switch_state += '[';
switch_state += m_repeat ? m_repeat : '-';
switch_state += m_random ? m_random : '-';
switch_state += m_single ? m_single : '-';
switch_state += m_consume ? m_consume : '-';
switch_state += m_crossfade ? m_crossfade : '-';
switch_state += m_db_updating ? m_db_updating : '-';
switch_state += ']';
*wHeader << NC::XY(COLS-switch_state.length(), 1) << NC::Format::Bold << Config.state_flags_color << switch_state << NC::Color::End << NC::Format::NoBold;
if (!Config.header_visibility) // in this case also draw separator
{
*wHeader << NC::Format::Bold << NC::Color::Black;
mvwhline(wHeader->raw(), 2, 0, 0, COLS);
*wHeader << NC::Color::End << NC::Format::NoBold;
}
wHeader->refresh();
break;
}
}
void Status::Changes::mixer()
{
if (!Config.display_volume_level || (!Config.header_visibility && !Config.new_design))
if (!Config.display_volume_level || (!Config.header_visibility && Config.design == Design::Classic))
return;
VolumeState = Config.new_design ? " Vol: " : " Volume: ";
switch (Config.design)
{
case Design::Classic:
VolumeState = " " "Volume" ": ";
break;
case Design::Alternative:
VolumeState = " " "Vol" ": ";
break;
}
if (State::volume() < 0)
VolumeState += "n/a";
else