summaryrefslogtreecommitdiff
path: root/src/helpers.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/helpers.cpp')
-rw-r--r--src/helpers.cpp501
1 files changed, 22 insertions, 479 deletions
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);