make parts of interface hideable

This commit is contained in:
unknown
2008-08-07 23:05:27 +02:00
parent 12946d6bdd
commit 9d9d77f140
8 changed files with 187 additions and 93 deletions

View File

@@ -61,12 +61,16 @@
#
#song_status_format = "(%l) {%a - }{%t}|{%f}"
#
##### window title settings #####
#song_window_title_format = "{%a - }{%t}|{%f}"
#
##### interface settings #####
#
#header_visibility = "yes"
#
#statusbar_visibility = "yes"
#
#enable_window_title = "yes"
#
#song_window_title_format = "{%a - }{%t}|{%f}"
#
##### colors definitions #####
#
#empty_tag_color = "cyan"

View File

@@ -76,6 +76,24 @@ string DisplaySong(const Song &s, const string &song_template)
for (string::const_iterator it = song_template.begin(); it != song_template.end(); it++)
{
if (*it == '}')
{
if (!tags_present)
result = result.substr(0, result.length()-i);
it++;
link_tags = 0;
i = 0;
if (*it == '|' && *(it+1) == '{')
{
if (!tags_present)
it++;
else
while (*++it != '}');
}
}
if (*it == '}')
{
if (!tags_present)
@@ -119,7 +137,10 @@ string DisplaySong(const Song &s, const string &song_template)
if (link_tags)
{
if (s.GetTotalLength() > 0)
{
result += s.GetLength();
i += s.GetLength().length();
}
else
tags_present = 0;
}
@@ -130,11 +151,13 @@ string DisplaySong(const Song &s, const string &song_template)
case 'F':
{
result += s.GetFile();
i += s.GetFile().length();
break;
}
case 'f':
{
result += s.GetShortFilename();
i += s.GetShortFilename().length();
break;
}
case 'a':
@@ -142,7 +165,10 @@ string DisplaySong(const Song &s, const string &song_template)
if (link_tags)
{
if (s.GetArtist() != UNKNOWN_ARTIST)
{
result += s.GetArtist();
i += s.GetArtist().length();
}
else
tags_present = 0;
}
@@ -155,7 +181,10 @@ string DisplaySong(const Song &s, const string &song_template)
if (link_tags)
{
if (s.GetAlbum() != UNKNOWN_ALBUM)
{
result += s.GetAlbum();
i += s.GetAlbum().length();
}
else
tags_present = 0;
}
@@ -168,7 +197,10 @@ string DisplaySong(const Song &s, const string &song_template)
if (link_tags)
{
if (s.GetYear() != EMPTY_TAG)
{
result += s.GetYear();
i += s.GetYear().length();
}
else
tags_present = 0;
}
@@ -181,7 +213,10 @@ string DisplaySong(const Song &s, const string &song_template)
if (link_tags)
{
if (s.GetTrack() != EMPTY_TAG)
{
result += s.GetTrack();
i += s.GetTrack().length();
}
else
tags_present = 0;
}
@@ -194,7 +229,10 @@ string DisplaySong(const Song &s, const string &song_template)
if (link_tags)
{
if (s.GetGenre() != EMPTY_TAG)
{
result += s.GetGenre();
i += s.GetGenre().length();
}
else
tags_present = 0;
}
@@ -207,7 +245,10 @@ string DisplaySong(const Song &s, const string &song_template)
if (link_tags)
{
if (s.GetComment() != EMPTY_TAG)
{
result += s.GetComment();
i += s.GetComment().length();
}
else
tags_present = 0;
}
@@ -220,7 +261,10 @@ string DisplaySong(const Song &s, const string &song_template)
if (link_tags)
{
if (s.GetTitle() != UNKNOWN_TITLE)
{
result += s.GetTitle();
i += s.GetTitle().length();
}
else
tags_present = 0;
}
@@ -382,9 +426,12 @@ void ShowMessage(const string &message, int delay)
{
block_delay = time(NULL);
block_statusbar_update_delay = delay;
block_statusbar_update = 1;
if (Config.statusbar_visibility)
block_statusbar_update = 1;
else
block_progressbar_update = 1;
wFooter->Bold(0);
wFooter->WriteXY(0, 1, message, 1);
wFooter->WriteXY(0, Config.statusbar_visibility, message, 1);
wFooter->Bold(1);
}
}

View File

@@ -381,7 +381,7 @@ void Menu::Highlight(int which)
itsHighlight = which-1;
if (which > itsHeight)
itsBeginning = which-itsHeight/2;
itsBeginning = itsHighlight-itsHeight/2;
else
itsBeginning = 0;
}

View File

@@ -27,13 +27,21 @@
#define FOR_EACH_MPD_DATA(x) for (; (x); (x) = mpd_data_get_next(x))
#define BLOCK_STATUSBAR_UPDATE \
block_statusbar_update = 1; \
if (Config.statusbar_visibility) \
block_statusbar_update = 1; \
else \
block_progressbar_update = 1; \
allow_statusbar_unblock = 0
#define UNBLOCK_STATUSBAR_UPDATE \
allow_statusbar_unblock = 1; \
if (block_statusbar_update_delay < 0) \
block_statusbar_update = 0
{ \
if (Config.statusbar_visibility) \
block_statusbar_update = 0; \
else \
block_progressbar_update = 0; \
}
#ifdef HAVE_TAGLIB_H
const string tag_screen_keydesc = "\tE e : Edit song's tags\n";
@@ -137,12 +145,23 @@ int main(int argc, char *argv[])
curs_set(0);
EnableColors();
mPlaylist = new Menu(0, 2, COLS, LINES-4, "", Config.main_color, brNone);
int main_start_y = 2;
int main_height = LINES-4;
if (!Config.header_visibility)
{
main_start_y -= 2;
main_height += 2;
}
if (!Config.statusbar_visibility)
main_height++;
mPlaylist = new Menu(0, main_start_y, COLS, main_height, "", Config.main_color, brNone);
mBrowser = new Menu(mPlaylist->EmptyClone());
mTagEditor = new Menu(mPlaylist->EmptyClone());
mSearcher = new Menu(mPlaylist->EmptyClone());
sHelp = new Scrollpad(0, 2, COLS, LINES-4, "", Config.main_color, brNone);
sHelp = new Scrollpad(0, main_start_y, COLS, main_height, "", Config.main_color, brNone);
sHelp->Add(" [b]Keys - Movement\n -----------------------------------------[/b]\n");
sHelp->Add("\tUp : Move Cursor up\n");
@@ -201,22 +220,21 @@ int main(int argc, char *argv[])
sHelp->Add(" [b]Keys - Tag Editor\n -----------------------------------------[/b]\n");
sHelp->Add("\tEnter : Change option\n");
wHeader = new Window(0, 0, COLS, 2, "", Config.header_color, brNone);
wFooter = new Window(0, LINES-2, COLS, 2, "", Config.statusbar_color, brNone);
if (Config.header_visibility)
{
wHeader = new Window(0, 0, COLS, 2, "", Config.header_color, brNone);
wHeader->Display();
}
wHeader->Display();
int footer_start_y = LINES-(Config.statusbar_visibility ? 2 : 1);
int footer_height = Config.statusbar_visibility ? 2 : 1;
wFooter = new Window(0, footer_start_y, COLS, footer_height, "", Config.statusbar_color, brNone);
wFooter->Display();
mpd_signal_connect_error(conn, (ErrorCallback)NcmpcppErrorCallback, NULL);
mpd_signal_connect_status_changed(conn, (StatusChangedCallback)NcmpcppStatusChanged, NULL);
mvwhline(wHeader->RawWin(), 1, 0, 0, wHeader->GetWidth());
wHeader->Refresh();
wFooter->SetColor(Config.progressbar_color);
mvwhline(wFooter->RawWin(), 0, 0, 0, wFooter->GetWidth());
wFooter->SetColor(Config.statusbar_color);
wFooter->Refresh();
wCurrent = mPlaylist;
current_screen = csPlaylist;
@@ -236,69 +254,72 @@ int main(int argc, char *argv[])
{
TraceMpdStatus();
string title;
int max_allowed_title_length = wHeader->GetWidth()-volume_state.length();
messages_allowed = 1;
switch (current_screen)
if (Config.header_visibility)
{
case csHelp:
title = "Help";
break;
case csPlaylist:
title = "Playlist";
break;
case csBrowser:
title = "Browse: ";
break;
case csTagEditor:
# ifdef HAVE_TAGLIB_H
title = "Tag editor";
# else
title = "Tag info";
# endif
break;
case csSearcher:
title = "Search engine";
}
if (title_allowed)
{
wHeader->Bold(1);
wHeader->WriteXY(0, 0, title, 1);
wHeader->Bold(0);
}
else
wHeader->WriteXY(0, 0, "[b]1:[/b]Help [b]2:[/b]Playlist [b]3:[/b]Browse [b]4:[/b]Search", 1);
wHeader->SetColor(Config.volume_color);
wHeader->WriteXY(max_allowed_title_length, 0, volume_state);
wHeader->SetColor(Config.header_color);
if (current_screen == csBrowser)
{
int max_length_without_scroll = wHeader->GetWidth()-volume_state.length()-title.length();
ncmpcpp_string_t wbrowseddir = NCMPCPP_TO_WSTRING(browsed_dir);
wHeader->Bold(1);
if (browsed_dir.length() > max_length_without_scroll)
string title;
int max_allowed_title_length = wHeader->GetWidth()-volume_state.length();
switch (current_screen)
{
# ifdef UTF8_ENABLED
wbrowseddir += L" ** ";
case csHelp:
title = "Help";
break;
case csPlaylist:
title = "Playlist";
break;
case csBrowser:
title = "Browse: ";
break;
case csTagEditor:
# ifdef HAVE_TAGLIB_H
title = "Tag editor";
# else
wbrowseddir += " ** ";
title = "Tag info";
# endif
const int scrollsize = max_length_without_scroll;
ncmpcpp_string_t part = wbrowseddir.substr(browsed_dir_scroll_begin++, scrollsize);
if (part.length() < scrollsize)
part += wbrowseddir.substr(0, scrollsize-part.length());
wHeader->WriteXY(8, 0, part);
if (browsed_dir_scroll_begin >= wbrowseddir.length())
browsed_dir_scroll_begin = 0;
break;
case csSearcher:
title = "Search engine";
}
if (title_allowed)
{
wHeader->Bold(1);
wHeader->WriteXY(0, 0, title, 1);
wHeader->Bold(0);
}
else
wHeader->WriteXY(8, 0, browsed_dir);
wHeader->Bold(0);
wHeader->WriteXY(0, 0, "[b]1:[/b]Help [b]2:[/b]Playlist [b]3:[/b]Browse [b]4:[/b]Search", 1);
wHeader->SetColor(Config.volume_color);
wHeader->WriteXY(max_allowed_title_length, 0, volume_state);
wHeader->SetColor(Config.header_color);
if (current_screen == csBrowser)
{
int max_length_without_scroll = wHeader->GetWidth()-volume_state.length()-title.length();
ncmpcpp_string_t wbrowseddir = NCMPCPP_TO_WSTRING(browsed_dir);
wHeader->Bold(1);
if (browsed_dir.length() > max_length_without_scroll)
{
# ifdef UTF8_ENABLED
wbrowseddir += L" ** ";
# else
wbrowseddir += " ** ";
# endif
const int scrollsize = max_length_without_scroll;
ncmpcpp_string_t part = wbrowseddir.substr(browsed_dir_scroll_begin++, scrollsize);
if (part.length() < scrollsize)
part += wbrowseddir.substr(0, scrollsize-part.length());
wHeader->WriteXY(8, 0, part);
if (browsed_dir_scroll_begin >= wbrowseddir.length())
browsed_dir_scroll_begin = 0;
}
else
wHeader->WriteXY(8, 0, browsed_dir);
wHeader->Bold(0);
}
}
wCurrent->Refresh();
@@ -346,15 +367,25 @@ int main(int argc, char *argv[])
return 1;
}
sHelp->Resize(COLS, LINES-4);
sHelp->Timeout(ncmpcpp_window_timeout);
mPlaylist->Resize(COLS, LINES-4);
mBrowser->Resize(COLS, LINES-4);
mTagEditor->Resize(COLS, LINES-4);
mSearcher->Resize(COLS, LINES-4);
main_height = LINES-4;
if (!Config.header_visibility)
main_height += 2;
if (!Config.statusbar_visibility)
main_height++;
wHeader->Resize(COLS, wHeader->GetHeight());
wFooter->MoveTo(0, LINES-2);
sHelp->Resize(COLS, main_height);
sHelp->Timeout(ncmpcpp_window_timeout);
mPlaylist->Resize(COLS, main_height);
mBrowser->Resize(COLS, main_height);
mTagEditor->Resize(COLS, main_height);
mSearcher->Resize(COLS, main_height);
if (Config.header_visibility)
wHeader->Resize(COLS, wHeader->GetHeight());
footer_start_y = LINES-(Config.statusbar_visibility ? 2 : 1);
wFooter->MoveTo(0, footer_start_y);
wFooter->Resize(COLS, wFooter->GetHeight());
if (wCurrent != sHelp)

View File

@@ -38,6 +38,8 @@ void DefaultConfiguration(ncmpcpp_config &conf)
conf.main_color = clYellow;
conf.progressbar_color = clDefault;
conf.statusbar_color = clDefault;
conf.header_visibility = true;
conf.statusbar_visibility = true;
conf.set_window_title = true;
conf.mpd_connection_timeout = 5;
conf.crossfade_time = 5;
@@ -161,8 +163,11 @@ void ReadConfiguration(ncmpcpp_config &conf)
if (!v.empty())
conf.song_status_format = v;
if (it->find("enable_window_title") != string::npos)
conf.set_window_title = v == "yes";
if (it->find("header_visibility") != string::npos)
conf.header_visibility = v == "yes";
if (it->find("statusbar_visibility") != string::npos)
conf.statusbar_visibility = v == "yes";
if (it->find("song_window_title_format") != string::npos)
if (!v.empty())

View File

@@ -44,6 +44,8 @@ struct ncmpcpp_config
COLOR statusbar_color;
bool set_window_title;
bool header_visibility;
bool statusbar_visibility;
int mpd_connection_timeout;
int crossfade_time;

View File

@@ -93,7 +93,12 @@ void TraceMpdStatus()
if (!block_statusbar_update_delay)
{
block_statusbar_update_delay = -1;
block_statusbar_update = !allow_statusbar_unblock;
if (Config.statusbar_visibility)
block_statusbar_update = !allow_statusbar_unblock;
else
block_progressbar_update = !allow_statusbar_unblock;
switch (mpd_player_get_state(conn))
{
case MPD_PLAYER_STOP:
@@ -253,7 +258,7 @@ void NcmpcppStatusChanged(MpdObj *conn, ChangedStatusType what)
break;
}
}
if (!block_statusbar_update)
if (!block_statusbar_update && Config.statusbar_visibility)
wFooter->WriteXY(0, 1, player_state, player_state.empty());
}
if ((what & MPD_CST_ELAPSED_TIME))
@@ -265,7 +270,7 @@ void NcmpcppStatusChanged(MpdObj *conn, ChangedStatusType what)
int elapsed = mpd_status_get_elapsed_song_time(conn);
if (!block_statusbar_update)
if (!block_statusbar_update && Config.statusbar_visibility)
{
string tracklength;
if (s.GetTotalLength() > 0)
@@ -312,7 +317,7 @@ void NcmpcppStatusChanged(MpdObj *conn, ChangedStatusType what)
}
else
{
if (!block_statusbar_update)
if (!block_statusbar_update && Config.statusbar_visibility)
wFooter->WriteXY(0, 1, "", 1);
}
}
@@ -342,7 +347,7 @@ void NcmpcppStatusChanged(MpdObj *conn, ChangedStatusType what)
ShowMessage(mpd_db_updating.empty() ? "Database update finished!" : "Database update started!");
header_update_status = 1;
}
if (header_update_status)
if (header_update_status && Config.header_visibility)
{
switch_state = mpd_repeat + mpd_random + mpd_crossfade + mpd_db_updating;
@@ -381,7 +386,7 @@ void NcmpcppStatusChanged(MpdObj *conn, ChangedStatusType what)
}
playing_song_scroll_begin = 0;
}
if (what & MPD_CST_VOLUME)
if ((what & MPD_CST_VOLUME) && Config.header_visibility)
{
int vol = mpd_status_get_volume(conn);
volume_state = " Volume: " + IntoStr(vol) + "%";

View File

@@ -221,8 +221,8 @@ void Window::Clear()
void Window::Hide(char x) const
{
for (int i = GetStartY(); i <= GetHeight()+1; i++)
mvhline(i, GetStartX(), x, GetWidth());
for (int i = 0; i < GetHeight(); i++)
mvhline(i+GetStartY(), GetStartX(), x, GetWidth());
refresh();
}