summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Makefile.am10
-rw-r--r--src/browser.cpp32
-rw-r--r--src/browser.h2
-rw-r--r--src/clock.cpp3
-rw-r--r--src/clock.h2
-rw-r--r--src/display.cpp548
-rw-r--r--src/display.h55
-rw-r--r--src/helpers.cpp501
-rw-r--r--src/helpers.h23
-rw-r--r--src/lyrics.cpp4
-rw-r--r--src/misc.cpp126
-rw-r--r--src/misc.h16
-rw-r--r--src/ncmpcpp.cpp61
-rw-r--r--src/ncmpcpp.h2
-rw-r--r--src/search_engine.cpp17
-rw-r--r--src/search_engine.h3
-rw-r--r--src/settings.cpp92
-rw-r--r--src/settings.h5
-rw-r--r--src/song.cpp1
-rw-r--r--src/song.h153
-rw-r--r--src/tag_editor.cpp50
-rw-r--r--src/tag_editor.h15
22 files changed, 896 insertions, 825 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 66ac02b8..008292ac 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,6 +1,6 @@
bin_PROGRAMS = ncmpcpp
-ncmpcpp_SOURCES = browser.cpp charset.cpp clock.cpp help.cpp helpers.cpp \
- libmpdclient.c lyrics.cpp misc.cpp mpdpp.cpp ncmpcpp.cpp scrollpad.cpp \
+ncmpcpp_SOURCES = browser.cpp charset.cpp clock.cpp display.cpp help.cpp \
+ helpers.cpp libmpdclient.c lyrics.cpp misc.cpp mpdpp.cpp ncmpcpp.cpp scrollpad.cpp \
search_engine.cpp settings.cpp song.cpp status_checker.cpp str_pool.c tag_editor.cpp \
window.cpp
@@ -9,6 +9,6 @@ INCLUDES= $(all_includes)
# the library search path.
ncmpcpp_LDFLAGS = $(all_libraries)
-noinst_HEADERS = browser.h charset.h clock.h help.h helpers.h lyrics.h menu.h \
- mpdpp.h scrollpad.h search_engine.h settings.h song.h status_checker.h \
- tag_editor.h window.h
+noinst_HEADERS = browser.h charset.h clock.h display.h help.h helpers.h \
+ lyrics.h menu.h mpdpp.h scrollpad.h search_engine.h settings.h song.h \
+ status_checker.h tag_editor.h window.h
diff --git a/src/browser.cpp b/src/browser.cpp
index 444a8d07..605a8cdf 100644
--- a/src/browser.cpp
+++ b/src/browser.cpp
@@ -24,6 +24,7 @@
#include "browser.h"
#include "charset.h"
+#include "display.h"
#include "helpers.h"
#include "settings.h"
#ifdef HAVE_TAGLIB_H
@@ -128,37 +129,6 @@ void UpdateItemList(Menu<Item> *menu)
menu->Refresh();
}
-void DisplayItem(const Item &item, void *, Menu<Item> *menu)
-{
- switch (item.type)
- {
- case itDirectory:
- {
- if (item.song)
- {
- *menu << "[..]";
- return;
- }
- size_t slash = item.name.rfind("/");
- *menu << "[" << (slash != string::npos ? item.name.substr(slash+1) : item.name) << "]";
- return;
- }
- case itSong:
- !Config.columns_in_browser
- ?
- DisplaySong(*item.song, &Config.song_list_format, reinterpret_cast<Menu<Song> *>(menu))
- :
- DisplaySongInColumns(*item.song, &Config.song_columns_list_format, reinterpret_cast<Menu<Song> *>(menu))
- ;
- return;
- case itPlaylist:
- *menu << Config.browser_playlist_prefix << item.name;
- return;
- default:
- return;
- }
-}
-
void GetDirectory(string dir, string subdir)
{
if (dir.empty())
diff --git a/src/browser.h b/src/browser.h
index 89fedb43..dd3e9142 100644
--- a/src/browser.h
+++ b/src/browser.h
@@ -26,8 +26,6 @@
void UpdateItemList(Menu<MPD::Item> *);
-void DisplayItem(const MPD::Item &, void *, Menu<MPD::Item> *);
-
void GetDirectory(std::string, std::string = "/");
#endif
diff --git a/src/clock.cpp b/src/clock.cpp
index 2dce2372..b20876fe 100644
--- a/src/clock.cpp
+++ b/src/clock.cpp
@@ -21,6 +21,7 @@
/// NOTICE: Major part of this code is ported from ncmpc's clock screen
#include "clock.h"
+#include "display.h"
#ifdef ENABLE_CLOCK
@@ -56,7 +57,7 @@ void InitClock()
older[i] = newer[i] = next[i] = 0;
}
-void DisplayClock(Window &w, const tm *time)
+void Display::Clock(Window &w, const tm *time)
{
mask = 0;
set(time->tm_sec % 10, 0);
diff --git a/src/clock.h b/src/clock.h
index 532e3ebd..f62d80a8 100644
--- a/src/clock.h
+++ b/src/clock.h
@@ -33,8 +33,6 @@
void InitClock();
-void DisplayClock(Window &, const tm *);
-
#endif // ENABLE_CLOCK
#endif
diff --git a/src/display.cpp b/src/display.cpp
new file mode 100644
index 00000000..46f5fbc3
--- /dev/null
+++ b/src/display.cpp
@@ -0,0 +1,548 @@
+/***************************************************************************
+ * Copyright (C) 2008-2009 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 "display.h"
+#include "helpers.h"
+
+using MPD::Song;
+using std::string;
+
+string Display::Columns(string st)
+{
+ string result;
+ size_t where = 0;
+
+ for (int width = StrToInt(GetLineValue(st, '(', ')', 1)); width; width = StrToInt(GetLineValue(st, '(', ')', 1)))
+ {
+ width *= COLS/100.0;
+ char type = GetLineValue(st, '{', '}', 1)[0];
+
+ switch (type)
+ {
+ case 'l':
+ result += "Time";
+ break;
+ case 'f':
+ result += "Filename";
+ break;
+ case 'F':
+ result += "Full filename";
+ break;
+ case 'a':
+ result += "Artist";
+ break;
+ case 't':
+ result += "Title";
+ break;
+ case 'b':
+ result += "Album";
+ break;
+ case 'y':
+ result += "Year";
+ break;
+ case 'n':
+ result += "Track";
+ break;
+ case 'g':
+ result += "Genre";
+ break;
+ case 'c':
+ result += "Composer";
+ break;
+ case 'p':
+ result += "Performer";
+ break;
+ case 'd':
+ result += "Disc";
+ break;
+ case 'C':
+ result += "Comment";
+ break;
+ default:
+ break;
+ }
+ where += width;
+
+ if (result.length() > where)
+ result = result.substr(0, where);
+ else
+ for (size_t i = result.length(); i <= where && i < size_t(COLS); i++, result += ' ') { }
+ }
+ return result;
+}
+
+void Display::TotalPlaylistLength(Window &w)
+{
+ extern Menu<MPD::Song> *mPlaylist;
+
+ const int MINUTE = 60;
+ const int HOUR = 60*MINUTE;
+ const int DAY = 24*HOUR;
+ const int YEAR = 365*DAY;
+ int length = 0;
+
+ for (size_t i = 0; i < mPlaylist->Size(); i++)
+ length += mPlaylist->at(i).GetTotalLength();
+
+ w << '(' << mPlaylist->Size() << (mPlaylist->Size() == 1 ? " item" : " items");
+
+ if (length)
+ {
+ w << ", length: ";
+ int years = length/YEAR;
+ if (years)
+ {
+ w << years << (years == 1 ? " year" : " years");
+ length -= years*YEAR;
+ if (length)
+ w << ", ";
+ }
+ int days = length/DAY;
+ if (days)
+ {
+ w << days << (days == 1 ? " day" : " days");
+ length -= days*DAY;
+ if (length)
+ w << ", ";
+ }
+ int hours = length/HOUR;
+ if (hours)
+ {
+ w << hours << (hours == 1 ? " hour" : " hours");
+ length -= hours*HOUR;
+ if (length)
+ w << ", ";
+ }
+ int minutes = length/MINUTE;
+ if (minutes)
+ {
+ w << minutes << (minutes == 1 ? " minute" : " minutes");
+ length -= minutes*MINUTE;
+ if (length)
+ w << ", ";
+ }
+ if (length)
+ w << length << (length == 1 ? " second" : " seconds");
+ }
+ w << ')';
+ w.Refresh();
+}
+
+void Display::StringPairs(const string_pair &pair, void *, Menu<string_pair> *menu)
+{
+ *menu << pair.first;
+}
+
+void Display::SongsInColumns(const MPD::Song &s, void *s_template, Menu<MPD::Song> *menu)
+{
+ string st = s_template ? *static_cast<string *>(s_template) : "";
+ size_t where = 0;
+ Color color;
+
+ for (int width = StrToInt(GetLineValue(st, '(', ')', 1)); width; width = StrToInt(GetLineValue(st, '(', ')', 1)))
+ {
+ 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;
+
+ switch (type)
+ {
+ case 'l':
+ get = &Song::GetLength;
+ break;
+ case 'F':
+ get = &Song::GetFile;
+ break;
+ case 'f':
+ get = &Song::GetName;
+ break;
+ case 'a':
+ get = &Song::GetArtist;
+ break;
+ case 'b':
+ get = &Song::GetAlbum;
+ break;
+ case 'y':
+ get = &Song::GetYear;
+ break;
+ case 'n':
+ get = &Song::GetTrack;
+ break;
+ case 'g':
+ get = &Song::GetGenre;
+ break;
+ case 'c':
+ get = &Song::GetComposer;
+ break;
+ case 'p':
+ get = &Song::GetPerformer;
+ break;
+ case 'd':
+ get = &Song::GetDisc;
+ break;
+ case 'C':
+ get = &Song::GetComment;
+ break;
+ case 't':
+ if (!s.GetTitle().empty())
+ get = &Song::GetTitle;
+ else
+ get = &Song::GetName;
+ break;
+ default:
+ break;
+ }
+ 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;
+ }
+ if (color != clDefault)
+ *menu << clEnd;
+}
+
+void Display::Songs(const MPD::Song &s, void *data, Menu<MPD::Song> *menu)
+{
+ if (!s.Localized())
+ const_cast<MPD::Song *>(&s)->Localize();
+
+ const string &song_template = data ? *static_cast<string *>(data) : "";
+ basic_buffer<my_char_t> buf;
+ bool right = 0;
+
+ string::const_iterator goto_pos, prev_pos;
+
+ for (string::const_iterator it = song_template.begin(); it != song_template.end(); it++)
+ {
+ CHECK_LINKED_TAGS:;
+ if (*it == '{')
+ {
+ prev_pos = it;
+ string (Song::*get)() const = 0;
+ for (; *it != '}'; it++)
+ {
+ if (*it == '%')
+ {
+ switch (*++it)
+ {
+ case 'l':
+ get = &Song::GetLength;
+ break;
+ case 'F':
+ get = &Song::GetFile;
+ break;
+ case 'f':
+ get = &Song::GetName;
+ break;
+ case 'a':
+ get = &Song::GetArtist;
+ break;
+ case 'b':
+ get = &Song::GetAlbum;
+ break;
+ case 'y':
+ get = &Song::GetYear;
+ break;
+ case 'n':
+ get = &Song::GetTrack;
+ break;
+ case 'g':
+ get = &Song::GetGenre;
+ break;
+ case 'c':
+ get = &Song::GetComposer;
+ break;
+ case 'p':
+ get = &Song::GetPerformer;
+ break;
+ case 'd':
+ get = &Song::GetDisc;
+ break;
+ case 'C':
+ get = &Song::GetComment;
+ break;
+ case 't':
+ get = &Song::GetTitle;
+ break;
+ default:
+ break;
+ }
+ if (get == &Song::GetLength)
+ {
+ if (!s.GetTotalLength())
+ break;
+ }
+ else if (get)
+ {
+ if ((s.*get)().empty())
+ break;
+ }
+ }
+ }
+ if (*it == '}')
+ {
+ while (1)
+ {
+ if (*it == '}' && *(it+1) != '|')
+ break;
+ it++;
+ }
+ goto_pos = ++it;
+ it = ++prev_pos;
+ }
+ else
+ {
+ for (; *it != '}'; it++) { }
+ it++;
+ if (it == song_template.end())
+ break;
+ if (*it == '{' || *it == '|')
+ {
+ if (*it == '|')
+ it++;
+ goto CHECK_LINKED_TAGS;
+ }
+ }
+ }
+
+ if (*it == '}')
+ {
+ if (goto_pos == song_template.end())
+ break;
+ it = goto_pos;
+ if (*it == '{')
+ goto CHECK_LINKED_TAGS;
+ }
+
+ if (*it != '%' && *it != '$')
+ {
+ if (!right)
+ *menu << *it;
+ else
+ buf << *it;
+ }
+ else if (*it == '%')
+ {
+ switch (*++it)
+ {
+ case 'l':
+ if (!right)
+ *menu << s.GetLength();
+ else
+ buf << TO_WSTRING(s.GetLength());
+ break;
+ case 'F':
+ if (!right)
+ *menu << s.GetFile();
+ else
+ buf << TO_WSTRING(s.GetFile());
+ break;
+ case 'f':
+ if (!right)
+ *menu << s.GetName();
+ else
+ buf << TO_WSTRING(s.GetName());
+ break;
+ case 'a':
+ if (!right)
+ *menu << s.GetArtist();
+ else
+ buf << TO_WSTRING(s.GetArtist());
+ break;
+ case 'b':
+ if (!right)
+ *menu << s.GetAlbum();
+ else
+ buf << TO_WSTRING(s.GetAlbum());
+ break;
+ case 'y':
+ if (!right)
+ *menu << s.GetYear();
+ else
+ buf << TO_WSTRING(s.GetYear());
+ break;
+ case 'n':
+ if (!right)
+ *menu << s.GetTrack();
+ else
+ buf << TO_WSTRING(s.GetTrack());
+ break;
+ case 'g':
+ if (!right)
+ *menu << s.GetGenre();
+ else
+ buf << TO_WSTRING(s.GetGenre());
+ break;
+ case 'c':
+ if (!right)
+ *menu << s.GetComposer();
+ else
+ buf << TO_WSTRING(s.GetComposer());
+ break;
+ case 'p':
+ if (!right)
+ *menu << s.GetPerformer();
+ else
+ buf << TO_WSTRING(s.GetPerformer());
+ break;
+ case 'd':
+ if (!right)
+ *menu << s.GetDisc();
+ else
+ buf << TO_WSTRING(s.GetDisc());
+ break;
+ case 'C':
+ if (!right)
+ *menu << s.GetComment();
+ else
+ buf << TO_WSTRING(s.GetComment());
+ break;
+ case 't':
+ if (!right)
+ *menu << s.GetTitle();
+ else
+ buf << TO_WSTRING(s.GetTitle());
+ break;
+ case 'r':
+ right = 1;
+ break;
+ default:
+ break;
+ }
+ }
+ else
+ {
+ it++;
+ if (!right)
+ *menu << Color(*it-'0');
+ else
+ buf << Color(*it-'0');
+ }
+ }
+ if (right)
+ {
+ menu->GotoXY(menu->GetWidth()-buf.Str().length(), menu->Y());
+ *menu << buf;
+ }
+}
+
+void Display::Tags(const MPD::Song &s, void *data, Menu<MPD::Song> *menu)
+{
+ switch (static_cast<Menu<string> *>(data)->Choice())
+ {
+ case 0:
+ *menu << ShowTag(s.GetTitle());
+ return;
+ case 1:
+ *menu << ShowTag(s.GetArtist());
+ return;
+ case 2:
+ *menu << ShowTag(s.GetAlbum());
+ return;
+ case 3:
+ *menu << ShowTag(s.GetYear());
+ return;
+ case 4:
+ *menu << ShowTag(s.GetTrack());
+ return;
+ case 5:
+ *menu << ShowTag(s.GetGenre());
+ return;
+ case 6:
+ *menu << ShowTag(s.GetComposer());
+ return;
+ case 7:
+ *menu << ShowTag(s.GetPerformer());
+ return;
+ case 8:
+ *menu << ShowTag(s.GetDisc());
+ return;
+ case 9:
+ *menu << ShowTag(s.GetComment());
+ return;
+ case 11:
+ if (s.GetNewName().empty())
+ *menu << s.GetName();
+ else
+ *menu << s.GetName() << Config.color2 << " -> " << clEnd << s.GetNewName();
+ return;
+ default:
+ return;
+ }
+}
+
+void Display::Items(const MPD::Item &item, void *, Menu<MPD::Item> *menu)
+{
+ switch (item.type)
+ {
+ case MPD::itDirectory:
+ {
+ if (item.song)
+ {
+ *menu << "[..]";
+ return;
+ }
+ size_t slash = item.name.rfind("/");
+ *menu << "[" << (slash != string::npos ? item.name.substr(slash+1) : item.name) << "]";
+ return;
+ }
+ case MPD::itSong:
+ if (!Config.columns_in_browser)
+ Display::Songs(*item.song, &Config.song_list_format, reinterpret_cast<Menu<MPD::Song> *>(menu));
+ else
+ Display::SongsInColumns(*item.song, &Config.song_columns_list_format, reinterpret_cast<Menu<MPD::Song> *>(menu));
+ return;
+ case MPD::itPlaylist:
+ *menu << Config.browser_playlist_prefix << item.name;
+ return;
+ default:
+ return;
+ }
+}
+
+void Display::SearchEngine(const std::pair<Buffer *, Song *> &pair, void *, Menu< std::pair<Buffer *, Song *> > *menu)
+{
+ if (pair.second)
+ {
+ if (!Config.columns_in_search_engine)
+ Display::Songs(*pair.second, &Config.song_list_format, reinterpret_cast<Menu<Song> *>(menu));
+ else
+ Display::SongsInColumns(*pair.second, &Config.song_columns_list_format, reinterpret_cast<Menu<Song> *>(menu));
+ }
+
+ else
+ *menu << *pair.first;
+}
+
diff --git a/src/display.h b/src/display.h
new file mode 100644
index 00000000..06c2227f
--- /dev/null
+++ b/src/display.h
@@ -0,0 +1,55 @@
+/***************************************************************************
+ * Copyright (C) 2008-2009 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 _DISPLAY_H
+#define _DISPLAY_H
+
+#include "ncmpcpp.h"
+#include "menu.h"
+#include "mpdpp.h"
+
+namespace Display
+{
+ std::string Columns(std::string);
+
+ template <class T> void Generic(const T &t, void *, Menu<T> *menu)
+ {
+ *menu << t;
+ }
+
+ void TotalPlaylistLength(Window &);
+
+ void StringPairs(const string_pair &, void *, Menu<string_pair> *);
+
+ void SongsInColumns(const MPD::Song &, void *, Menu<MPD::Song> *);
+
+ void Songs(const MPD::Song &, void *, Menu<MPD::Song> *);
+
+ void Tags(const MPD::Song &, void *, Menu<MPD::Song> *);
+
+ void SearchEngine(const std::pair<Buffer *, MPD::Song *> &, void *, Menu< std::pair<Buffer *, MPD::Song *> > *);
+
+ void Items(const MPD::Item &, void *, Menu<MPD::Item> *);
+
+ void Clock(Window &, const tm *);
+}
+
+#endif
+
diff --git a/src/helpers.cpp b/src/helpers.cpp
index 4197d0d7..31486ec5 100644
--- a/src/helpers.cpp
+++ b/src/helpers.cpp
@@ -266,22 +266,6 @@ void WindowTitle(const string &status)
std::cout << "\033]0;" << status << "\7";
}
-void EscapeUnallowedChars(string &s)
-{
- const string unallowed_chars = "\"*/:<>?\\|";
- for (string::const_iterator it = unallowed_chars.begin(); it != unallowed_chars.end(); it++)
- {
- for (size_t i = 0; i < s.length(); i++)
- {
- if (s[i] == *it)
- {
- s.erase(s.begin()+i);
- i--;
- }
- }
- }
-}
-
Window &operator<<(Window &w, mpd_TagItems tag)
{
switch (tag)
@@ -325,37 +309,6 @@ Window &operator<<(Window &w, mpd_TagItems tag)
return w;
}
-string IntoStr(mpd_TagItems tag) // this is only for left column's title in media library
-{
- switch (tag)
- {
- case MPD_TAG_ITEM_ARTIST:
- return "Artist";
- case MPD_TAG_ITEM_ALBUM:
- return "Album";
- case MPD_TAG_ITEM_TITLE:
- return "Title";
- case MPD_TAG_ITEM_TRACK:
- return "Track";
- case MPD_TAG_ITEM_GENRE:
- return "Genre";
- case MPD_TAG_ITEM_DATE:
- return "Year";
- case MPD_TAG_ITEM_COMPOSER:
- return "Composer";
- case MPD_TAG_ITEM_PERFORMER:
- return "Performer";
- case MPD_TAG_ITEM_COMMENT:
- return "Comment";
- case MPD_TAG_ITEM_DISC:
- return "Disc";
- case MPD_TAG_ITEM_FILENAME:
- return "Filename";
- default:
- return "";
- }
-}
-
string FindSharedDir(const string &one, const string &two)
{
if (one == two)
@@ -369,438 +322,6 @@ string FindSharedDir(const string &one, const string &two)
return i != string::npos ? result.substr(0, i) : "/";
}
-void DisplayTotalPlaylistLength(Window &w)
-{
- const int MINUTE = 60;
- const int HOUR = 60*MINUTE;
- const int DAY = 24*HOUR;
- const int YEAR = 365*DAY;
- int length = 0;
-
- for (size_t i = 0; i < mPlaylist->Size(); i++)
- length += mPlaylist->at(i).GetTotalLength();
-
- w << '(' << mPlaylist->Size() << (mPlaylist->Size() == 1 ? " item" : " items");
-
- if (length)
- {
- w << ", length: ";
- int years = length/YEAR;
- if (years)
- {
- w << years << (years == 1 ? " year" : " years");
- length -= years*YEAR;
- if (length)
- w << ", ";
- }
- int days = length/DAY;
- if (days)
- {
- w << days << (days == 1 ? " day" : " days");
- length -= days*DAY;
- if (length)
- w << ", ";
- }
- int hours = length/HOUR;
- if (hours)
- {
- w << hours << (hours == 1 ? " hour" : " hours");
- length -= hours*HOUR;
- if (length)
- w << ", ";
- }
- int minutes = length/MINUTE;
- if (minutes)
- {
- w << minutes << (minutes == 1 ? " minute" : " minutes");
- length -= minutes*MINUTE;
- if (length)
- w << ", ";
- }
- if (length)
- w << length << (length == 1 ? " second" : " seconds");
- }
- w << ')';
- w.Refresh();
-}
-
-void DisplayStringPair(const StringPair &pair, void *, Menu<StringPair> *menu)
-{
- *menu << pair.first;
-}
-
-string DisplayColumns(string st)
-{
- string result;
- size_t where = 0;
-
- for (int width = StrToInt(GetLineValue(st, '(', ')', 1)); width; width = StrToInt(GetLineValue(st, '(', ')', 1)))
- {
- width *= COLS/100.0;
- char type = GetLineValue(st, '{', '}', 1)[0];
-
- switch (type)
- {
- case 'l':
- result += "Time";
- break;
- case 'f':
- result += "Filename";
- break;
- case 'F':
- result += "Full filename";
- break;
- case 'a':
- result += "Artist";
- break;
- case 't':
- result += "Title";
- break;
- case 'b':
- result += "Album";
- break;
- case 'y':
- result += "Year";
- break;
- case 'n':
- result += "Track";
- break;
- case 'g':
- result += "Genre";
- break;
- case 'c':
- result += "Composer";
- break;
- case 'p':
- result += "Performer";
- break;
- case 'd':
- result += "Disc";
- break;
- case 'C':
- result += "Comment";
- break;
- default:
- break;
- }
- where += width;
-
- if (result.length() > where)
- result = result.substr(0, where);
- else
- for (size_t i = result.length(); i <= where && i < size_t(COLS); i++, result += ' ') { }
- }
- return result;
-}
-
-void DisplaySongInColumns(const Song &s, void *s_template, Menu<Song> *menu)
-{
- string st = s_template ? *static_cast<string *>(s_template) : "";
- size_t where = 0;
- Color color;
-
- for (int width = StrToInt(GetLineValue(st, '(', ')', 1)); width; width = StrToInt(GetLineValue(st, '(', ')', 1)))
- {
- 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;
-
- switch (type)
- {
- case 'l':
- get = &Song::GetLength;
- break;
- case 'F':
- get = &Song::GetFile;
- break;
- case 'f':
- get = &Song::GetName;
- break;
- case 'a':
- get = &Song::GetArtist;
- break;
- case 'b':
- get = &Song::GetAlbum;
- break;
- case 'y':
- get = &Song::GetYear;
- break;
- case 'n':
- get = &Song::GetTrack;
- break;
- case 'g':
- get = &Song::GetGenre;
- break;
- case 'c':
- get = &Song::GetComposer;
- break;
- case 'p':
- get = &Song::GetPerformer;
- break;
- case 'd':
- get = &Song::GetDisc;
- break;
- case 'C':
- get = &Song::GetComment;
- break;
- case 't':
- if (!s.GetTitle().empty())
- get = &Song::GetTitle;
- else
- get = &Song::GetName;
- break;
- default:
- break;
- }
- 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;
- }
- if (color != clDefault)
- *menu << clEnd;
-}
-
-void DisplaySong(const Song &s, void *data, Menu<Song> *menu)
-{
- if (!s.Localized())
- const_cast<Song *>(&s)->Localize();
-
- const string &song_template = data ? *static_cast<string *>(data) : "";
- basic_buffer<my_char_t> buf;
- bool right = 0;
-
- string::const_iterator goto_pos, prev_pos;
-
- for (string::const_iterator it = song_template.begin(); it != song_template.end(); it++)
- {
- CHECK_LINKED_TAGS:;
- if (*it == '{')
- {
- prev_pos = it;
- string (Song::*get)() const = 0;
- for (; *it != '}'; it++)
- {
- if (*it == '%')
- {
- switch (*++it)
- {
- case 'l':
- get = &Song::GetLength;
- break;
- case 'F':
- get = &Song::GetFile;
- break;
- case 'f':
- get = &Song::GetName;
- break;
- case 'a':
- get = &Song::GetArtist;
- break;
- case 'b':
- get = &Song::GetAlbum;
- break;
- case 'y':
- get = &Song::GetYear;
- break;
- case 'n':
- get = &Song::GetTrack;
- break;
- case 'g':
- get = &Song::GetGenre;
- break;
- case 'c':
- get = &Song::GetComposer;
- break;
- case 'p':
- get = &Song::GetPerformer;
- break;
- case 'd':
- get = &Song::GetDisc;
- break;
- case 'C':
- get = &Song::GetComment;
- break;
- case 't':
- get = &Song::GetTitle;
- break;
- default:
- break;
- }
- if (get == &Song::GetLength)
- {
- if (!s.GetTotalLength())
- break;
- }
- else if (get)
- {
- if ((s.*get)().empty())
- break;
- }
- }
- }
- if (*it == '}')
- {
- while (1)
- {
- if (*it == '}' && *(it+1) != '|')
- break;
- it++;
- }
- goto_pos = ++it;
- it = ++prev_pos;
- }
- else
- {
- for (; *it != '}'; it++) { }
- it++;
- if (it == song_template.end())
- break;
- if (*it == '{' || *it == '|')
- {
- if (*it == '|')
- it++;
- goto CHECK_LINKED_TAGS;
- }
- }
- }
-
- if (*it == '}')
- {
- if (goto_pos == song_template.end())
- break;
- it = goto_pos;
- if (*it == '{')
- goto CHECK_LINKED_TAGS;
- }
-
- if (*it != '%' && *it != '$')
- {
- if (!right)
- *menu << *it;
- else
- buf << *it;
- }
- else if (*it == '%')
- {
- switch (*++it)
- {
- case 'l':
- if (!right)
- *menu << s.GetLength();
- else
- buf << TO_WSTRING(s.GetLength());
- break;
- case 'F':
- if (!right)
- *menu << s.GetFile();
- else
- buf << TO_WSTRING(s.GetFile());
- break;
- case 'f':
- if (!right)
- *menu << s.GetName();
- else
- buf << TO_WSTRING(s.GetName());
- break;
- case 'a':
- if (!right)
- *menu << s.GetArtist();
- else
- buf << TO_WSTRING(s.GetArtist());
- break;
- case 'b':
- if (!right)
- *menu << s.GetAlbum();
- else
- buf << TO_WSTRING(s.GetAlbum());
- break;
- case 'y':
- if (!right)
- *menu << s.GetYear();
- else
- buf << TO_WSTRING(s.GetYear());
- break;
- case 'n':
- if (!right)
- *menu << s.GetTrack();
- else
- buf << TO_WSTRING(s.GetTrack());
- break;
- case 'g':
- if (!right)
- *menu << s.GetGenre();
- else
- buf << TO_WSTRING(s.GetGenre());
- break;
- case 'c':
- if (!right)
- *menu << s.GetComposer();
- else
- buf << TO_WSTRING(s.GetComposer());
- break;
- case 'p':
- if (!right)
- *menu << s.GetPerformer();
- else
- buf << TO_WSTRING(s.GetPerformer());
- break;
- case 'd':
- if (!right)
- *menu << s.GetDisc();
- else
- buf << TO_WSTRING(s.GetDisc());
- break;
- case 'C':
- if (!right)
- *menu << s.GetComment();
- else
- buf << TO_WSTRING(s.GetComment());
- break;
- case 't':
- if (!right)
- *menu << s.GetTitle();
- else
- buf << TO_WSTRING(s.GetTitle());
- break;
- case 'r':
- right = 1;
- break;
- default:
- break;
- }
- }
- else
- {
- it++;
- if (!right)
- *menu << Color(*it-'0');
- else
- buf << Color(*it-'0');
- }
- }
- if (right)
- {
- menu->GotoXY(menu->GetWidth()-buf.Str().length(), menu->Y());
- *menu << buf;
- }
-}
-
void GetInfo(Song &s, Scrollpad &info)
{
# ifdef HAVE_TAGLIB_H
@@ -838,6 +359,28 @@ void GetInfo(Song &s, Scrollpad &info)
info << fmtBold << "\nComment: " << fmtBoldEnd << ShowTagInInfoScreen(s.GetComment());
}
+string GetLineValue(string &line, char a, char b, bool once)
+{
+ int i = 0;
+ int begin = -1, end = -1;
+ 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
+ end = i;
+ }
+ }
+ if (begin >= 0 && end >= 0)
+ return line.substr(begin, end-begin);
+ else
+ return "";
+}
+
Window &Statusbar()
{
wFooter->GotoXY(0, Config.statusbar_visibility);
diff --git a/src/helpers.h b/src/helpers.h
index 38f00aaa..6483e35d 100644
--- a/src/helpers.h
+++ b/src/helpers.h
@@ -32,34 +32,25 @@ class CaseInsensitiveSorting
{
public:
bool operator()(std::string, std::string);
- bool operator()(Song *, Song *);
+ bool operator()(MPD::Song *, MPD::Song *);
bool operator()(const MPD::Item &, const MPD::Item &);
};
-template <class T> void GenericDisplayer(const T &t, void *, Menu<T> *menu)
-{
- *menu << t;
-}
-
-bool SortSongsByTrack(Song *, Song *);
+bool SortSongsByTrack(MPD::Song *, MPD::Song *);
-void UpdateSongList(Menu<Song> *);
+void UpdateSongList(Menu<MPD::Song> *);
bool Keypressed(int, const int *);
void WindowTitle(const std::string &);
-void EscapeUnallowedChars(std::string &);
Window &operator<<(Window &, mpd_TagItems);
-std::string IntoStr(mpd_TagItems);
std::string FindSharedDir(const std::string &, const std::string &);
-void DisplayTotalPlaylistLength(Window &);
-void DisplayStringPair(const StringPair &, void *, Menu<StringPair> *);
-std::string DisplayColumns(std::string);
-void DisplaySongInColumns(const Song &, void *, Menu<Song> *);
-void DisplaySong(const Song &, void * = &Config.song_list_format, Menu<Song> * = NULL);
-void GetInfo(Song &, Scrollpad &);
+
+void GetInfo(MPD::Song &, Scrollpad &);
+
+std::string GetLineValue(std::string &, char = '"', char = '"', bool = 0);
Window &Statusbar();
diff --git a/src/lyrics.cpp b/src/lyrics.cpp
index f496fc36..5641ec18 100644
--- a/src/lyrics.cpp
+++ b/src/lyrics.cpp
@@ -318,8 +318,8 @@ const char *GetLyricsPluginName(int offset)
void *GetLyrics(void *song)
{
- string artist = static_cast<Song *>(song)->GetArtist();
- string title = static_cast<Song *>(song)->GetTitle();
+ string artist = static_cast<MPD::Song *>(song)->GetArtist();
+ string title = static_cast<MPD::Song *>(song)->GetTitle();
locale_to_utf(artist);
locale_to_utf(title);
diff --git a/src/misc.cpp b/src/misc.cpp
index 19ab8b18..cecca44a 100644
--- a/src/misc.cpp
+++ b/src/misc.cpp
@@ -23,17 +23,17 @@
#include "misc.h"
-/*int Abs(int num)
+namespace
{
- return (num < 0 ? -num : num);
-}*/
+ const std::string unallowed_chars = "\"*/:<>?\\|";
+}
void ToLower(std::string &s)
{
transform(s.begin(), s.end(), s.begin(), tolower);
}
-int StrToInt(std::string str)
+int StrToInt(const std::string &str)
{
return atoi(str.c_str());
}
@@ -45,10 +45,118 @@ std::string IntoStr(int l)
return ss.str();
}
-/*string IntoStr(double l, int precision)
+std::string IntoStr(mpd_TagItems tag) // this is only for left column's title in media library
{
- std::stringstream ss;
- ss << std::fixed << std::setprecision(precision) << l;
- return ss.str();
-}*/
+ switch (tag)
+ {
+ case MPD_TAG_ITEM_ARTIST:
+ return "Artist";
+ case MPD_TAG_ITEM_ALBUM:
+ return "Album";
+ case MPD_TAG_ITEM_TITLE:
+ return "Title";
+ case MPD_TAG_ITEM_TRACK:
+ return "Track";
+ case MPD_TAG_ITEM_GENRE:
+ return "Genre";
+ case MPD_TAG_ITEM_DATE:
+ return "Year";
+ case MPD_TAG_ITEM_COMPOSER:
+ return "Composer";
+ case MPD_TAG_ITEM_PERFORMER:
+ return "Performer";
+ case MPD_TAG_ITEM_COMMENT:
+ return "Comment";
+ case MPD_TAG_ITEM_DISC:
+ return "Disc";
+ case MPD_TAG_ITEM_FILENAME:
+ return "Filename";
+ default:
+ return "";
+ }
+}
+
+std::string IntoStr(Color color)
+{
+ std::string result;
+
+ if (color == clDefault)
+ result = "default";
+ else if (color == clBlack)
+ result = "black";
+ else if (color == clRed)
+ result = "red";
+ else if (color == clGreen)
+ result = "green";
+ else if (color == clYellow)
+ result = "yellow";
+ else if (color == clBlue)
+ result = "blue";
+ else if (color == clMagenta)
+ result = "magenta";
+ else if (color == clCyan)
+ result = "cyan";
+ else if (color == clWhite)
+ result = "white";
+
+ return result;
+}
+
+Color IntoColor(const std::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;
+}
+
+mpd_TagItems IntoTagItem(char c)
+{
+ switch (c)
+ {
+ case 'a':
+ return MPD_TAG_ITEM_ARTIST;
+ case 'y':
+ return MPD_TAG_ITEM_DATE;
+ case 'g':
+ return MPD_TAG_ITEM_GENRE;
+ case 'c':
+ return MPD_TAG_ITEM_COMPOSER;
+ case 'p':
+ return MPD_TAG_ITEM_PERFORMER;
+ default:
+ return MPD_TAG_ITEM_ARTIST;
+ }
+}
+
+void EscapeUnallowedChars(std::string &s)
+{
+ for (std::string::const_iterator it = unallowed_chars.begin(); it != unallowed_chars.end(); it++)
+ {
+ for (size_t i = 0; i < s.length(); i++)
+ {
+ if (s[i] == *it)
+ {
+ s.erase(s.begin()+i);
+ i--;
+ }
+ }
+ }
+}
diff --git a/src/misc.h b/src/misc.h
index a4defcdc..c20dc72f 100644
--- a/src/misc.h
+++ b/src/misc.h
@@ -23,14 +23,24 @@
#include <string>
-//int Abs(int);
+#include "window.h"
+#include "libmpdclient.h"
void ToLower(std::string &);
-int StrToInt(std::string);
+int StrToInt(const std::string &);
std::string IntoStr(int);
-//string IntoStr(double, int);
+
+std::string IntoStr(mpd_TagItems);
+
+std::string IntoStr(Color);
+
+Color IntoColor(const std::string &);
+
+mpd_TagItems IntoTagItem(char);
+
+void EscapeUnallowedChars(std::string &);
#endif
diff --git a/src/ncmpcpp.cpp b/src/ncmpcpp.cpp
index 89e35e75..7c18736e 100644
--- a/src/ncmpcpp.cpp
+++ b/src/ncmpcpp.cpp
@@ -33,6 +33,7 @@
#include "browser.h"
#include "charset.h"
#include "clock.h"
+#include "display.h"
#include "help.h"
#include "helpers.h"
#include "lyrics.h"
@@ -105,17 +106,17 @@ Menu< std::pair<Buffer *, Song *> > *mSearcher;
Window *wLibActiveCol;
Menu<string> *mLibArtists;
-Menu<StringPair> *mLibAlbums;
+Menu<string_pair> *mLibAlbums;
Menu<Song> *mLibSongs;
#ifdef HAVE_TAGLIB_H
Window *wTagEditorActiveCol;
Menu<Buffer> *mTagEditor;
-Menu<StringPair> *mEditorAlbums;
-Menu<StringPair> *mEditorDirs;
+Menu<string_pair> *mEditorAlbums;
+Menu<string_pair> *mEditorDirs;
#endif // HAVE_TAGLIB_H
// blah, I use below in conditionals.
-Menu<StringPair> *mEditorLeftCol;
+Menu<string_pair> *mEditorLeftCol;
Menu<string> *mEditorTagTypes;
Menu<Song> *mEditorTags;
@@ -226,12 +227,12 @@ int main(int argc, char *argv[])
if (!Config.statusbar_visibility)
main_height++;
- mPlaylist = new Menu<Song>(0, main_start_y, COLS, main_height, Config.columns_in_playlist ? DisplayColumns(Config.song_columns_list_format) : "", Config.main_color, brNone);
+ mPlaylist = new Menu<Song>(0, main_start_y, COLS, main_height, Config.columns_in_playlist ? Display::Columns(Config.song_columns_list_format) : "", Config.main_color, brNone);
mPlaylist->SetTimeout(ncmpcpp_window_timeout);
mPlaylist->HighlightColor(Config.main_highlight_color);
mPlaylist->SetSelectPrefix(&Config.selected_item_prefix);
mPlaylist->SetSelectSuffix(&Config.selected_item_suffix);
- mPlaylist->SetItemDisplayer(Config.columns_in_playlist ? DisplaySongInColumns : DisplaySong);
+ mPlaylist->SetItemDisplayer(Config.columns_in_playlist ? Display::SongsInColumns : Display::Songs);
mPlaylist->SetItemDisplayerUserData(Config.columns_in_playlist ? &Config.song_columns_list_format : &Config.song_list_format);
mBrowser = new Menu<Item>(0, main_start_y, COLS, main_height, "", Config.main_color, brNone);
@@ -239,12 +240,12 @@ int main(int argc, char *argv[])
mBrowser->SetTimeout(ncmpcpp_window_timeout);
mBrowser->SetSelectPrefix(&Config.selected_item_prefix);
mBrowser->SetSelectSuffix(&Config.selected_item_suffix);
- mBrowser->SetItemDisplayer(DisplayItem);
+ mBrowser->SetItemDisplayer(Display::Items);
mSearcher = new Menu< std::pair<Buffer *, Song *> >(0, main_start_y, COLS, main_height, "", Config.main_color, brNone);
mSearcher->HighlightColor(Config.main_highlight_color);
mSearcher->SetTimeout(ncmpcpp_window_timeout);
- mSearcher->SetItemDisplayer(SearchEngineDisplayer);
+ mSearcher->SetItemDisplayer(Display::SearchEngine);
mSearcher->SetSelectPrefix(&Config.selected_item_prefix);
mSearcher->SetSelectSuffix(&Config.selected_item_suffix);
@@ -257,26 +258,26 @@ int main(int argc, char *argv[])
mLibArtists = new Menu<string>(0, main_start_y, left_col_width, main_height, IntoStr(Config.media_lib_primary_tag) + "s", Config.main_color, brNone);
mLibArtists->HighlightColor(Config.active_column_color);
mLibArtists->SetTimeout(ncmpcpp_window_timeout);
- mLibArtists->SetItemDisplayer(GenericDisplayer);
+ mLibArtists->SetItemDisplayer(Display::Generic);
- mLibAlbums = new Menu<StringPair>(middle_col_startx, main_start_y, middle_col_width, main_height, "Albums", Config.main_color, brNone);
+ mLibAlbums = new Menu<string_pair>(middle_col_startx, main_start_y, middle_col_width, main_height, "Albums", Config.main_color, brNone);
mLibAlbums->HighlightColor(Config.main_highlight_color);
mLibAlbums->SetTimeout(ncmpcpp_window_timeout);
- mLibAlbums->SetItemDisplayer(DisplayStringPair);
+ mLibAlbums->SetItemDisplayer(Display::StringPairs);
mLibSongs = new Menu<Song>(right_col_startx, main_start_y, right_col_width, main_height, "Songs", Config.main_color, brNone);
mLibSongs->HighlightColor(Config.main_highlight_color);
mLibSongs->SetTimeout(ncmpcpp_window_timeout);
mLibSongs->SetSelectPrefix(&Config.selected_item_prefix);
mLibSongs->SetSelectSuffix(&Config.selected_item_suffix);
- mLibSongs->SetItemDisplayer(DisplaySong);
+ mLibSongs->SetItemDisplayer(Display::Songs);
mLibSongs->SetItemDisplayerUserData(&Config.song_library_format);
# ifdef HAVE_TAGLIB_H
mTagEditor = new Menu<Buffer>(0, main_start_y, COLS, main_height, "", Config.main_color, brNone);
mTagEditor->HighlightColor(Config.main_highlight_color);
mTagEditor->SetTimeout(ncmpcpp_window_timeout);
- mTagEditor->SetItemDisplayer(GenericDisplayer);
+ mTagEditor->SetItemDisplayer(Display::Generic);
size_t tagedit_middle_col_width = 26;
size_t tagedit_left_col_width = COLS/2-tagedit_middle_col_width/2;
@@ -284,42 +285,42 @@ int main(int argc, char *argv[])
size_t tagedit_right_col_width = COLS-tagedit_left_col_width-tagedit_middle_col_width-2;
size_t tagedit_right_col_startx = tagedit_left_col_width+tagedit_middle_col_width+2;
- mEditorAlbums = new Menu<StringPair>(0, main_start_y, tagedit_left_col_width, main_height, "Albums", Config.main_color, brNone);
+ mEditorAlbums = new Menu<string_pair>(0, main_start_y, tagedit_left_col_width, main_height, "Albums", Config.main_color, brNone);
mEditorAlbums->HighlightColor(Config.active_column_color);
mEditorAlbums->SetTimeout(ncmpcpp_window_timeout);
- mEditorAlbums->SetItemDisplayer(DisplayStringPair);
+ mEditorAlbums->SetItemDisplayer(Display::StringPairs);
- mEditorDirs = new Menu<StringPair>(0, main_start_y, tagedit_left_col_width, main_height, "Directories", Config.main_color, brNone);
+ mEditorDirs = new Menu<string_pair>(0, main_start_y, tagedit_left_col_width, main_height, "Directories", Config.main_color, brNone);
mEditorDirs->HighlightColor(Config.active_column_color);
mEditorDirs->SetTimeout(ncmpcpp_window_timeout);
- mEditorDirs->SetItemDisplayer(DisplayStringPair);
+ mEditorDirs->SetItemDisplayer(Display::StringPairs);
mEditorLeftCol = Config.albums_in_tag_editor ? mEditorAlbums : mEditorDirs;
mEditorTagTypes = new Menu<string>(tagedit_middle_col_startx, main_start_y, tagedit_middle_col_width, main_height, "Tag types", Config.main_color, brNone);
mEditorTagTypes->HighlightColor(Config.main_highlight_color);
mEditorTagTypes->SetTimeout(ncmpcpp_window_timeout);
- mEditorTagTypes->SetItemDisplayer(GenericDisplayer);
+ mEditorTagTypes->SetItemDisplayer(Display::Generic);
mEditorTags = new Menu<Song>(tagedit_right_col_startx, main_start_y, tagedit_right_col_width, main_height, "Tags", Config.main_color, brNone);
mEditorTags->HighlightColor(Config.main_highlight_color);
mEditorTags->SetTimeout(ncmpcpp_window_timeout);
mEditorTags->SetSelectPrefix(&Config.selected_item_prefix);
mEditorTags->SetSelectSuffix(&Config.selected_item_suffix);
- mEditorTags->SetItemDisplayer(DisplayTag);
+ mEditorTags->SetItemDisplayer(Display::Tags);
mEditorTags->SetItemDisplayerUserData(mEditorTagTypes);
# endif // HAVE_TAGLIB_H
mPlaylistList = new Menu<string>(0, main_start_y, left_col_width, main_height, "Playlists", Config.main_color, brNone);
mPlaylistList->HighlightColor(Config.active_column_color);
mPlaylistList->SetTimeout(ncmpcpp_window_timeout);
- mPlaylistList->SetItemDisplayer(GenericDisplayer);
+ mPlaylistList->SetItemDisplayer(Display::Generic);
mPlaylistEditor = new Menu<Song>(middle_col_startx, main_start_y, middle_col_width+right_col_width+1, main_height, "Playlist's content", Config.main_color, brNone);
mPlaylistEditor->HighlightColor(Config.main_highlight_color);
mPlaylistEditor->SetTimeout(ncmpcpp_window_timeout);
mPlaylistEditor->SetSelectPrefix(&Config.selected_item_prefix);
mPlaylistEditor->SetSelectSuffix(&Config.selected_item_suffix);
- mPlaylistEditor->SetItemDisplayer(DisplaySong);
+ mPlaylistEditor->SetItemDisplayer(Display::Songs);
mPlaylistEditor->SetItemDisplayerUserData(&Config.song_list_format);
// set default active columns
@@ -466,7 +467,7 @@ int main(int argc, char *argv[])
if (current_screen == csPlaylist)
{
- DisplayTotalPlaylistLength(*wHeader);
+ Display::TotalPlaylistLength(*wHeader);
}
else if (current_screen == csBrowser)
{
@@ -805,7 +806,7 @@ int main(int argc, char *argv[])
time_t rawtime;
time(&rawtime);
tm *t = localtime(&rawtime);
- DisplayClock(*wClock, t);
+ Display::Clock(*wClock, t);
}
else
{
@@ -964,7 +965,7 @@ int main(int argc, char *argv[])
sHelp->Resize(COLS, main_height);
mPlaylist->Resize(COLS, main_height);
- mPlaylist->SetTitle(Config.columns_in_playlist ? DisplayColumns(Config.song_columns_list_format) : "");
+ mPlaylist->SetTitle(Config.columns_in_playlist ? Display::Columns(Config.song_columns_list_format) : "");
mBrowser->Resize(COLS, main_height);
mSearcher->Resize(COLS, main_height);
sInfo->Resize(COLS, main_height);
@@ -1383,7 +1384,7 @@ int main(int argc, char *argv[])
if (!mSearcher->Back().first)
{
if (Config.columns_in_search_engine)
- mSearcher->SetTitle(DisplayColumns(Config.song_columns_list_format));
+ mSearcher->SetTitle(Display::Columns(Config.song_columns_list_format));
size_t found = mSearcher->Size()-search_engine_static_options;
found += 3; // don't count options inserted below
mSearcher->InsertSeparator(search_engine_reset_button+1);
@@ -2565,22 +2566,22 @@ int main(int argc, char *argv[])
{
Config.columns_in_playlist = !Config.columns_in_playlist;
ShowMessage("Playlist display mode: %s", Config.columns_in_playlist ? "Columns" : "Classic");
- mPlaylist->SetItemDisplayer(Config.columns_in_playlist ? DisplaySongInColumns : DisplaySong);
+ mPlaylist->SetItemDisplayer(Config.columns_in_playlist ? Display::SongsInColumns : Display::Songs);
mPlaylist->SetItemDisplayerUserData(Config.columns_in_playlist ? &Config.song_columns_list_format : &Config.song_list_format);
- mPlaylist->SetTitle(Config.columns_in_playlist ? DisplayColumns(Config.song_columns_list_format) : "");
+ mPlaylist->SetTitle(Config.columns_in_playlist ? Display::Columns(Config.song_columns_list_format) : "");
}
else if (wCurrent == mBrowser)
{
Config.columns_in_browser = !Config.columns_in_browser;
ShowMessage("Browser display mode: %s", Config.columns_in_browser ? "Columns" : "Classic");
- mBrowser->SetTitle(Config.columns_in_browser ? DisplayColumns(Config.song_columns_list_format) : "");
+ mBrowser->SetTitle(Config.columns_in_browser ? Display::Columns(Config.song_columns_list_format) : "");
}
else if (wCurrent == mSearcher)
{
Config.columns_in_search_engine = !Config.columns_in_search_engine;
ShowMessage("Search engine display mode: %s", Config.columns_in_search_engine ? "Columns" : "Classic");
if (mSearcher->Size() > search_engine_static_options)
- mSearcher->SetTitle(Config.columns_in_search_engine ? DisplayColumns(Config.song_columns_list_format) : "");
+ mSearcher->SetTitle(Config.columns_in_search_engine ? Display::Columns(Config.song_columns_list_format) : "");
}
// redraw_screen = 1;
}
@@ -3041,7 +3042,7 @@ int main(int argc, char *argv[])
size_t dialog_height = LINES*0.6;
Menu<string> *mDialog = new Menu<string>((COLS-dialog_width)/2, (LINES-dialog_height)/2, dialog_width, dialog_height, "Add selected items to...", Config.main_color, Config.window_border);
mDialog->SetTimeout(ncmpcpp_window_timeout);
- mDialog->SetItemDisplayer(GenericDisplayer);
+ mDialog->SetItemDisplayer(Display::Generic);
bool playlists_not_active = current_screen == csBrowser && Config.local_browser;
diff --git a/src/ncmpcpp.h b/src/ncmpcpp.h
index b9b3f019..e65b3e80 100644
--- a/src/ncmpcpp.h
+++ b/src/ncmpcpp.h
@@ -26,7 +26,7 @@
#include "scrollpad.h"
#include "misc.h"
-typedef std::pair<std::string, std::string> StringPair;
+typedef std::pair<std::string, std::string> string_pair;
enum NcmpcppScreen
{
diff --git a/src/search_engine.cpp b/src/search_engine.cpp
index 721f3697..6d9a5b5f 100644
--- a/src/search_engine.cpp
+++ b/src/search_engine.cpp
@@ -18,6 +18,7 @@
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
+#include "display.h"
#include "helpers.h"
#include "search_engine.h"
#include "settings.h"
@@ -35,22 +36,6 @@ bool search_case_sensitive = 0;
const char *search_mode_normal = "Match if tag contains searched phrase";
const char *search_mode_strict = "Match only if both values are the same";
-void SearchEngineDisplayer(const std::pair<Buffer *, Song *> &pair, void *, Menu< std::pair<Buffer *, Song *> > *menu)
-{
- if (pair.second)
- {
- !Config.columns_in_search_engine
- ?
- DisplaySong(*pair.second, &Config.song_list_format, reinterpret_cast<Menu<Song> *>(menu))
- :
- DisplaySongInColumns(*pair.second, &Config.song_columns_list_format, reinterpret_cast<Menu<Song> *>(menu))
- ;
- }
-
- else
- *menu << *pair.first;
-}
-
void UpdateFoundList()
{
bool bold = 0;
diff --git a/src/search_engine.h b/src/search_engine.h
index 441c6c37..0c03d4ca 100644
--- a/src/search_engine.h
+++ b/src/search_engine.h
@@ -24,7 +24,7 @@
#include "mpdpp.h"
#include "ncmpcpp.h"
-class SearchPattern : public Song
+class SearchPattern : public MPD::Song
{
public:
const std::string &Any() { return itsAnyField; }
@@ -41,7 +41,6 @@ const size_t search_engine_static_options = 20;
const size_t search_engine_search_button = 15;
const size_t search_engine_reset_button = 16;
-void SearchEngineDisplayer(const std::pair<Buffer *, Song *> &, void *, Menu< std::pair<Buffer *, Song *> > *);
void UpdateFoundList();
void PrepareSearchEngine(SearchPattern &s);
void Search(SearchPattern);
diff --git a/src/settings.cpp b/src/settings.cpp
index e1407313..d78d8ecb 100644
--- a/src/settings.cpp
+++ b/src/settings.cpp
@@ -21,6 +21,7 @@
#include <sys/stat.h>
#include <fstream>
+#include "helpers.h"
#include "settings.h"
using std::ifstream;
@@ -71,30 +72,6 @@ namespace
}
}
-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);
@@ -291,73 +268,6 @@ void DefaultConfiguration(ncmpcpp_config &conf)
conf.lyrics_db = 0;
}
-string GetLineValue(string &line, char a, char b, bool once)
-{
- int i = 0;
- int begin = -1, end = -1;
- 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
- end = i;
- }
- }
- if (begin >= 0 && end >= 0)
- return line.substr(begin, end-begin);
- else
- return "";
-}
-
-string IntoStr(Color color)
-{
- string result;
-
- if (color == clDefault)
- result = "default";
- else if (color == clBlack)
- result = "black";
- else if (color == clRed)
- result = "red";
- else if (color == clGreen)
- result = "green";
- else if (color == clYellow)
- result = "yellow";
- else if (color == clBlue)
- result = "blue";
- else if (color == clMagenta)
- result = "magenta";
- else if (color == clCyan)
- result = "cyan";
- else if (color == clWhite)
- result = "white";
-
- return result;
-}
-
-mpd_TagItems IntoTagItem(char c)
-{
- switch (c)
- {
- case 'a':
- return MPD_TAG_ITEM_ARTIST;
- case 'y':
- return MPD_TAG_ITEM_DATE;
- case 'g':
- return MPD_TAG_ITEM_GENRE;
- case 'c':
- return MPD_TAG_ITEM_COMPOSER;
- case 'p':
- return MPD_TAG_ITEM_PERFORMER;
- default:
- return MPD_TAG_ITEM_ARTIST;
- }
-}
-
void ReadKeys(ncmpcpp_keys &keys)
{
ifstream f(keys_config_file.c_str());
diff --git a/src/settings.h b/src/settings.h
index 393f8094..a73c62b1 100644
--- a/src/settings.h
+++ b/src/settings.h
@@ -170,10 +170,5 @@ void DefaultConfiguration(ncmpcpp_config &);
void ReadKeys(ncmpcpp_keys &);
void ReadConfiguration(ncmpcpp_config &);
-Color IntoColor(const std::string &);
-std::string IntoStr(Color);
-mpd_TagItems IntoTagItem(char);
-std::string GetLineValue(std::string &, char = '"', char = '"', bool = 0);
-
#endif
diff --git a/src/song.cpp b/src/song.cpp
index 1cfea3e1..447a3fd3 100644
--- a/src/song.cpp
+++ b/src/song.cpp
@@ -29,6 +29,7 @@
#include "charset.h"
#include "song.h"
+using MPD::Song;
using std::string;
Song::Song(mpd_Song *s, bool copy_ptr) : itsSong(s ? s : mpd_newSong()),
diff --git a/src/song.h b/src/song.h
index e9073c5a..0c65243e 100644
--- a/src/song.h
+++ b/src/song.h
@@ -26,83 +26,86 @@
#include "misc.h"
#include "libmpdclient.h"
-class Song
+namespace MPD
{
- public:
- Song() : itsSlash(std::string::npos), itsHash(0), copyPtr(0), isStream(0), isLocalised(0) { itsSong = mpd_newSong(); }
- Song(mpd_Song *, bool = 0);
- Song(const Song &);
- ~Song();
-
- std::string GetFile() const;
- std::string GetName() const;
- std::string GetDirectory() const;
- std::string GetArtist() const;
- std::string GetTitle() const;
- std::string GetAlbum() const;
- std::string GetTrack() const;
- std::string GetYear() const;
- std::string GetGenre() const;
- std::string GetComposer() const;
- std::string GetPerformer() const;
- std::string GetDisc() const;
- std::string GetComment() const;
- std::string GetLength() const;
- const long long &GetHash() const { return itsHash; }
- int GetTotalLength() const { return itsSong->time < 0 ? 0 : itsSong->time; }
- int GetPosition() const { return itsSong->pos; }
- int GetID() const { return itsSong->id; }
-
- void SetFile(const std::string &);
- void SetArtist(const std::string &);
- void SetTitle(const std::string &);
- void SetAlbum(const std::string &);
- void SetTrack(const std::string &);
- void SetTrack(int);
- void SetYear(const std::string &);
- void SetYear(int);
- void SetGenre(const std::string &);
- void SetComposer(const std::string &);
- void SetPerformer(const std::string &);
- void SetDisc(const std::string &);
- void SetComment(const std::string &);
- void SetPosition(int);
-
- void SetNewName(const std::string &name) { itsNewName = name == GetName() ? "" : name; }
- std::string GetNewName() const { return itsNewName; }
-
- std::string toString(const std::string &) const;
-
- void NullMe() { itsSong = 0; }
- void CopyPtr(bool copy) { copyPtr = copy; }
-
- //void GetEmptyFields(bool get) { itsGetEmptyFields = get; }
- void Localize();
- //void Delocalize();
- void Clear();
- bool Empty() const;
- bool IsFromDB() const;
- bool IsStream() const { return isStream; }
- bool Localized() const { return isLocalised; }
-
- Song & operator=(const Song &);
- bool operator==(const Song &) const;
- bool operator!=(const Song &) const;
- bool operator<(const Song &rhs) const;
-
- static std::string ShowTime(int);
- private:
- void __Count_Last_Slash_Position();
-
- mpd_Song *itsSong;
- std::string itsNewName;
- size_t itsSlash;
- long long itsHash;
- bool copyPtr;
- bool isStream;
- bool isLocalised;
+ class Song
+ {
+ public:
+ Song() : itsSlash(std::string::npos), itsHash(0), copyPtr(0), isStream(0), isLocalised(0) { itsSong = mpd_newSong(); }
+ Song(mpd_Song *, bool = 0);
+ Song(const Song &);
+ ~Song();
+
+ std::string GetFile() const;
+ std::string GetName() const;
+ std::string GetDirectory() const;
+ std::string GetArtist() const;
+ std::string GetTitle() const;
+ std::string GetAlbum() const;
+ std::string GetTrack() const;
+ std::string GetYear() const;
+ std::string GetGenre() const;
+ std::string GetComposer() const;
+ std::string GetPerformer() const;
+ std::string GetDisc() const;
+ std::string GetComment() const;
+ std::string GetLength() const;
+ const long long &GetHash() const { return itsHash; }
+ int GetTotalLength() const { return itsSong->time < 0 ? 0 : itsSong->time; }
+ int GetPosition() const { return itsSong->pos; }
+ int GetID() const { return itsSong->id; }
+
+ void SetFile(const std::string &);
+ void SetArtist(const std::string &);
+ void SetTitle(const std::string &);
+ void SetAlbum(const std::string &);
+ void SetTrack(const std::string &);
+ void SetTrack(int);
+ void SetYear(const std::string &);
+ void SetYear(int);
+ void SetGenre(const std::string &);
+ void SetComposer(const std::string &);
+ void SetPerformer(const std::string &);
+ void SetDisc(const std::string &);
+ void SetComment(const std::string &);
+ void SetPosition(int);
+
+ void SetNewName(const std::string &name) { itsNewName = name == GetName() ? "" : name; }
+ std::string GetNewName() const { return itsNewName; }
+
+ std::string toString(const std::string &) const;
+
+ void NullMe() { itsSong = 0; }
+ void CopyPtr(bool copy) { copyPtr = copy; }
+
+ //void GetEmptyFields(bool get) { itsGetEmptyFields = get; }
+ void Localize();
+ //void Delocalize();
+ void Clear();
+ bool Empty() const;
+ bool IsFromDB() const;
+ bool IsStream() const { return isStream; }
+ bool Localized() const { return isLocalised; }
+
+ Song & operator=(const Song &);
+ bool operator==(const Song &) const;
+ bool operator!=(const Song &) const;
+ bool operator<(const Song &rhs) const;
+
+ static std::string ShowTime(int);
+ private:
+ void __Count_Last_Slash_Position();
+
+ mpd_Song *itsSong;
+ std::string itsNewName;
+ size_t itsSlash;
+ long long itsHash;
+ bool copyPtr;
+ bool isStream;
+ bool isLocalised;
//bool itsGetEmptyFields;
-};
+ };
+}
#endif
diff --git a/src/tag_editor.cpp b/src/tag_editor.cpp
index 9e6915d3..56535414 100644
--- a/src/tag_editor.cpp
+++ b/src/tag_editor.cpp
@@ -30,6 +30,7 @@
#include "mpegfile.h"
#include "charset.h"
+#include "display.h"
#include "helpers.h"
#include "status_checker.h"
@@ -238,51 +239,6 @@ string FindSharedDir(const SongList &v)
return result;
}
-void DisplayTag(const Song &s, void *data, Menu<Song> *menu)
-{
- switch (static_cast<Menu<string> *>(data)->Choice())
- {
- case 0:
- *menu << ShowTag(s.GetTitle());
- return;
- case 1:
- *menu << ShowTag(s.GetArtist());
- return;
- case 2:
- *menu << ShowTag(s.GetAlbum());
- return;
- case 3:
- *menu << ShowTag(s.GetYear());
- return;
- case 4:
- *menu << ShowTag(s.GetTrack());
- return;
- case 5:
- *menu << ShowTag(s.GetGenre());
- return;
- case 6:
- *menu << ShowTag(s.GetComposer());
- return;
- case 7:
- *menu << ShowTag(s.GetPerformer());
- return;
- case 8:
- *menu << ShowTag(s.GetDisc());
- return;
- case 9:
- *menu << ShowTag(s.GetComment());
- return;
- case 11:
- if (s.GetNewName().empty())
- *menu << s.GetName();
- else
- *menu << s.GetName() << Config.color2 << " -> " << clEnd << s.GetNewName();
- return;
- default:
- return;
- }
-}
-
void ReadTagsFromFile(mpd_Song *s)
{
TagLib::FileRef f(s->file);
@@ -469,7 +425,7 @@ void __deal_with_filenames(SongList &v)
Menu<string> *Main = new Menu<string>((COLS-width)/2, (LINES-height)/2, width, height, "", Config.main_color, Config.window_border);
Main->SetTimeout(ncmpcpp_window_timeout);
- Main->SetItemDisplayer(GenericDisplayer);
+ Main->SetItemDisplayer(Display::Generic);
Main->AddOption("Get tags from filename");
Main->AddOption("Rename files");
Main->AddSeparator();
@@ -529,7 +485,7 @@ void __deal_with_filenames(SongList &v)
Main = new Menu<string>((COLS-width)/2, (LINES-height)/2, one_width, height, "", Config.main_color, Config.active_window_border);
Main->SetTimeout(ncmpcpp_window_timeout);
- Main->SetItemDisplayer(GenericDisplayer);
+ Main->SetItemDisplayer(Display::Generic);
if (!patterns_list.empty())
Config.pattern = patterns_list.front();
diff --git a/src/tag_editor.h b/src/tag_editor.h
index bd885f59..10675e98 100644
--- a/src/tag_editor.h
+++ b/src/tag_editor.h
@@ -32,23 +32,22 @@
#include "mpdpp.h"
#include "settings.h"
-typedef void (Song::*SongSetFunction)(const std::string &);
-typedef std::string (Song::*SongGetFunction)() const;
+typedef void (MPD::Song::*SongSetFunction)(const std::string &);
+typedef std::string (MPD::Song::*SongGetFunction)() const;
-std::string FindSharedDir(Menu<Song> *);
+std::string FindSharedDir(Menu<MPD::Song> *);
std::string FindSharedDir(const MPD::SongList &);
-void DisplayTag(const Song &, void *, Menu<Song> *);
SongSetFunction IntoSetFunction(mpd_TagItems);
void ReadTagsFromFile(mpd_Song *);
-bool GetSongTags(Song &);
-bool WriteTags(Song &);
+bool GetSongTags(MPD::Song &);
+bool WriteTags(MPD::Song &);
void __deal_with_filenames(MPD::SongList &);
-void CapitalizeFirstLetters(Song &);
-void LowerAllLetters(Song &);
+void CapitalizeFirstLetters(MPD::Song &);
+void LowerAllLetters(MPD::Song &);
#endif