From 6f296e2419a9202e50b205404fdcb79f6f6d8da8 Mon Sep 17 00:00:00 2001 From: Andrzej Rybczak Date: Fri, 12 Dec 2008 21:14:22 +0100 Subject: [PATCH] update displaying playlist in column view --- src/helpers.cpp | 168 ++++++++++++++++++++--------------------------- src/ncmpcpp.cpp | 2 +- src/settings.cpp | 56 ++++++++-------- src/settings.h | 3 +- src/window.cpp | 3 + 5 files changed, 105 insertions(+), 127 deletions(-) diff --git a/src/helpers.cpp b/src/helpers.cpp index 8d0de1d4..0313ef5b 100644 --- a/src/helpers.cpp +++ b/src/helpers.cpp @@ -416,179 +416,151 @@ void DisplayStringPair(const StringPair &pair, void *, Menu *menu) *menu << pair.first; } -string DisplayColumns(string song_template) +string DisplayColumns(string st) { - vector cols; - for (size_t i = song_template.find(" "); i != string::npos; i = song_template.find(" ")) - { - cols.push_back(song_template.substr(0, i)); - song_template = song_template.substr(i+1); - } - cols.push_back(song_template); + string result; + size_t where = 0; - string result, v; - - for (vector::const_iterator it = cols.begin(); it != cols.end(); it++) + for (int width = StrToInt(GetLineValue(st, '(', ')', 1)); width; width = StrToInt(GetLineValue(st, '(', ')', 1))) { - int width = StrToInt(GetLineValue(*it, '(', ')')); - char type = GetLineValue(*it, '{', '}')[0]; - width *= COLS/100.0; + char type = GetLineValue(st, '{', '}', 1)[0]; switch (type) { case 'l': - v = "Time"; + result += "Time"; break; case 'f': - v = "Filename"; + result += "Filename"; break; case 'F': - v = "Full filename"; + result += "Full filename"; break; case 'a': - v = "Artist"; + result += "Artist"; break; case 't': - v = "Title"; + result += "Title"; break; case 'b': - v = "Album"; + result += "Album"; break; case 'y': - v = "Year"; + result += "Year"; break; case 'n': - v = "Track"; + result += "Track"; break; case 'g': - v = "Genre"; + result += "Genre"; break; case 'c': - v = "Composer"; + result += "Composer"; break; case 'p': - v = "Performer"; + result += "Performer"; break; case 'd': - v = "Disc"; + result += "Disc"; break; case 'C': - v = "Comment"; + result += "Comment"; break; default: break; } + where += width; - v = v.substr(0, width-1); - for (int i = v.length(); i < width; i++, v += " ") { } - result += v; + if (result.length() > where) + result = result.substr(0, where); + else + for (int i = result.length(); i <= where && i < COLS; i++, result += ' ') { } } - - return result.substr(0, COLS); + return result; } void DisplaySongInColumns(const Song &s, void *s_template, Menu *menu) { - /*string song_template = s_template ? *static_cast(s_template) : ""; + string st = s_template ? *static_cast(s_template) : ""; + size_t where = 0; + Color color; - vector cols; - for (size_t i = song_template.find(" "); i != string::npos; i = song_template.find(" ")) + for (int width = StrToInt(GetLineValue(st, '(', ')', 1)); width; width = StrToInt(GetLineValue(st, '(', ')', 1))) { - cols.push_back(song_template.substr(0, i)); - song_template = song_template.substr(i+1); - } - cols.push_back(song_template); - - my_string_t result, v; - -# ifdef _UTF8 - const wstring space = L" "; - const wstring open_col = L"[."; - const wstring close_col = L"]"; - const wstring close_col2 = L"[/red]"; -# else - const string space = " "; - const string open_col = "[."; - const string close_col = "]"; - const string close_col2 = "[/red]"; -# endif - - for (vector::const_iterator it = cols.begin(); it != cols.end(); it++) - { - int width = StrToInt(GetLineValue(*it, '(', ')')); - my_string_t color = TO_WSTRING(GetLineValue(*it, '[', ']')); - char type = GetLineValue(*it, '{', '}')[0]; + if (where) + { + menu->GotoXY(where, menu->Y()); + *menu << ' '; + if (color != clDefault) + *menu << clEnd; + } width *= COLS/100.0; + color = IntoColor(GetLineValue(st, '[', ']', 1)); + char type = GetLineValue(st, '{', '}', 1)[0]; + + string (Song::*get)() const = 0; - string ss; switch (type) { case 'l': - ss = s.GetLength(); - break; - case 'f': - ss = s.GetName(); + get = &Song::GetLength; break; case 'F': - ss = s.GetFile(); + get = &Song::GetFile; + break; + case 'f': + get = &Song::GetName; break; case 'a': - ss = s.GetArtist(); - break; - case 't': - if (s.GetTitle() != EMPTY_TAG) - ss = s.GetTitle(); - else - { - const string &file = s.GetName(); - ss = !s.IsStream() ? file.substr(0, file.find_last_of(".")) : file; - } + get = &Song::GetArtist; break; case 'b': - ss = s.GetAlbum(); + get = &Song::GetAlbum; break; case 'y': - ss = s.GetYear(); + get = &Song::GetYear; break; case 'n': - ss = s.GetTrack(); + get = &Song::GetTrack; break; case 'g': - ss = s.GetGenre(); + get = &Song::GetGenre; break; case 'c': - ss = s.GetComposer(); + get = &Song::GetComposer; break; case 'p': - ss = s.GetPerformer(); + get = &Song::GetPerformer; break; case 'd': - ss = s.GetDisc(); + get = &Song::GetDisc; break; case 'C': - ss = s.GetComment(); + get = &Song::GetComment; + break; + case 't': + if (!s.GetTitle().empty()) + get = &Song::GetTitle; + else + get = &Song::GetName; break; default: break; } - - v = TO_WSTRING(ss.substr(0, width-1)); - for (int i = v.length(); i < width; i++, v += space) { } - if (!color.empty()) - { - result += open_col; - result += color; - result += close_col; - } - result += v; - if (!color.empty()) - result += close_col2; + if (color != clDefault) + *menu << color; + whline(menu->Raw(), 32, menu->GetWidth()-where); + string tag = (s.*get)(); + if (!tag.empty()) + *menu << tag; + else + *menu << Config.empty_tag; + where += width; } - - return TO_STRING(result);*/ - *menu << "dupa"; + if (color != clDefault) + *menu << clEnd; } void DisplaySong(const Song &s, void *data, Menu *menu) diff --git a/src/ncmpcpp.cpp b/src/ncmpcpp.cpp index 7aa4d578..090b2c21 100644 --- a/src/ncmpcpp.cpp +++ b/src/ncmpcpp.cpp @@ -106,10 +106,10 @@ Menu *mLibSongs; Menu *mTagEditor; Menu *mEditorAlbums; Menu *mEditorDirs; -Menu *mEditorTagTypes; #endif // HAVE_TAGLIB_H // blah, I use them in conditionals, so just let them be. Menu *mEditorLeftCol = 0; +Menu *mEditorTagTypes; Menu *mEditorTags = 0; Menu *mPlaylistList; diff --git a/src/settings.cpp b/src/settings.cpp index dad990d4..1d7c1433 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -53,36 +53,36 @@ namespace key[1] = !two.empty() && two[0] == '\'' ? two[1] : (atoi(two.c_str()) == 0 ? null_key : atoi(two.c_str())); } - Color IntoColor(const string &color) - { - Color result = clDefault; - - if (color == "black") - result = clBlack; - else if (color == "red") - result = clRed; - else if (color == "green") - result = clGreen; - else if (color == "yellow") - result = clYellow; - else if (color == "blue") - result = clBlue; - else if (color == "magenta") - result = clMagenta; - else if (color == "cyan") - result = clCyan; - else if (color == "white") - result = clWhite; - - return result; - } - Border IntoBorder(const string &color) { return (Border) IntoColor(color); } } +Color IntoColor(const string &color) +{ + Color result = clDefault; + + if (color == "black") + result = clBlack; + else if (color == "red") + result = clRed; + else if (color == "green") + result = clGreen; + else if (color == "yellow") + result = clYellow; + else if (color == "blue") + result = clBlue; + else if (color == "magenta") + result = clMagenta; + else if (color == "cyan") + result = clCyan; + else if (color == "white") + result = clWhite; + + return result; +} + void CreateConfigDir() { mkdir(config_dir.c_str(), 0755); @@ -220,7 +220,7 @@ void DefaultConfiguration(ncmpcpp_config &conf) conf.mpd_host = "localhost"; conf.empty_tag = ""; conf.song_list_format = "{%a - }{%t}|{$8%f$9}%r{$3(%l)$9}"; - conf.song_columns_list_format = "(8)[green]{l} (25)[cyan]{a} (40){t} (30)[red]{b}"; + conf.song_columns_list_format = "(7)[green]{l} (25)[cyan]{a} (40)[]{t} (30)[red]{b}"; conf.song_status_format = "{(%l) }{%a - }{%t}|{%f}"; conf.song_window_title_format = "{%a - }{%t}|{%f}"; conf.song_library_format = "{%n - }{%t}|{%f}"; @@ -269,14 +269,16 @@ void DefaultConfiguration(ncmpcpp_config &conf) conf.message_delay_time = 4; } -string GetLineValue(const string &line, char a, char b) +string GetLineValue(string &line, char a, char b, bool once) { int i = 0; int begin = -1, end = -1; - for (string::const_iterator it = line.begin(); it != line.end(); i++, it++) + for (string::iterator it = line.begin(); it != line.end() && (begin == -1 || end == -1); i++, it++) { if (*it == a || *it == b) { + if (once) + *it = 0; if (begin < 0) begin = i+1; else diff --git a/src/settings.h b/src/settings.h index df6e7dad..7fc62f11 100644 --- a/src/settings.h +++ b/src/settings.h @@ -162,9 +162,10 @@ void DefaultConfiguration(ncmpcpp_config &); void ReadKeys(ncmpcpp_keys &); void ReadConfiguration(ncmpcpp_config &); +Color IntoColor(const string &); string IntoStr(Color); mpd_TagItems IntoTagItem(char); -string GetLineValue(const string &, char = '"', char = '"'); +string GetLineValue(string &, char = '"', char = '"', bool = 0); #endif diff --git a/src/window.cpp b/src/window.cpp index 763e2e25..a7b0d51c 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -127,6 +127,9 @@ Window::~Window() void Window::SetColor(Color col, Color background) { + if (col == clDefault) + col = itsBaseColor; + if (col != clDefault) wattron(itsWindow, COLOR_PAIR(background*8+col)); else