improve handling playlist stats (btw several other improvements)
This commit is contained in:
@@ -358,57 +358,59 @@ string FindSharedDir(const string &one, const string &two)
|
||||
return i != string::npos ? result.substr(0, i) : "/";
|
||||
}
|
||||
|
||||
string TotalPlaylistLength()
|
||||
void DisplayTotalPlaylistLength(Window &w)
|
||||
{
|
||||
const int MINUTE = 60;
|
||||
const int HOUR = 60*MINUTE;
|
||||
const int DAY = 24*HOUR;
|
||||
const int YEAR = 365*DAY;
|
||||
string result;
|
||||
int length = 0;
|
||||
|
||||
for (size_t i = 0; i < mPlaylist->Size(); i++)
|
||||
length += mPlaylist->at(i).GetTotalLength();
|
||||
|
||||
if (!length)
|
||||
return result;
|
||||
w << '(' << mPlaylist->Size() << (mPlaylist->Size() == 1 ? " item" : " items");
|
||||
|
||||
result += ", length: ";
|
||||
|
||||
int years = length/YEAR;
|
||||
if (years)
|
||||
{
|
||||
result += IntoStr(years) + (years == 1 ? " year" : " years");
|
||||
length -= years*YEAR;
|
||||
if (length)
|
||||
result += ", ";
|
||||
}
|
||||
int days = length/DAY;
|
||||
if (days)
|
||||
{
|
||||
result += IntoStr(days) + (days == 1 ? " day" : " days");
|
||||
length -= days*DAY;
|
||||
if (length)
|
||||
result += ", ";
|
||||
}
|
||||
int hours = length/HOUR;
|
||||
if (hours)
|
||||
{
|
||||
result += IntoStr(hours) + (hours == 1 ? " hour" : " hours");
|
||||
length -= hours*HOUR;
|
||||
if (length)
|
||||
result += ", ";
|
||||
}
|
||||
int minutes = length/MINUTE;
|
||||
if (minutes)
|
||||
{
|
||||
result += IntoStr(minutes) + (minutes == 1 ? " minute" : " minutes");
|
||||
length -= minutes*MINUTE;
|
||||
if (length)
|
||||
result += ", ";
|
||||
}
|
||||
if (length)
|
||||
result += IntoStr(length) + (length == 1 ? " second" : " seconds");
|
||||
return result;
|
||||
{
|
||||
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)
|
||||
|
||||
@@ -57,7 +57,7 @@ Window &operator<<(Window &, mpd_TagItems);
|
||||
|
||||
string IntoStr(mpd_TagItems);
|
||||
string FindSharedDir(const string &, const string &);
|
||||
string TotalPlaylistLength();
|
||||
void DisplayTotalPlaylistLength(Window &);
|
||||
void DisplayStringPair(const StringPair &, void *, Menu<StringPair> *);
|
||||
string DisplayColumns(string);
|
||||
void DisplaySongInColumns(const Song &, void *, Menu<Song> *);
|
||||
|
||||
@@ -173,7 +173,6 @@ int main(int argc, char *argv[])
|
||||
DefaultKeys(Key);
|
||||
ReadConfiguration(Config);
|
||||
ReadKeys(Key);
|
||||
DefineEmptyTags();
|
||||
|
||||
Mpd = new Connection;
|
||||
|
||||
@@ -181,8 +180,6 @@ int main(int argc, char *argv[])
|
||||
Mpd->SetHostname(getenv("MPD_HOST"));
|
||||
if (getenv("MPD_PORT"))
|
||||
Mpd->SetPort(atoi(getenv("MPD_PORT")));
|
||||
if (getenv("MPD_PASSWORD"))
|
||||
Mpd->SetPassword(getenv("MPD_PASSWORD"));
|
||||
|
||||
if (Config.mpd_host != "localhost")
|
||||
Mpd->SetHostname(Config.mpd_host);
|
||||
@@ -425,8 +422,8 @@ int main(int argc, char *argv[])
|
||||
wHeader->WriteXY(0, 0, 1, "%s", title.c_str());
|
||||
wHeader->Bold(0);
|
||||
|
||||
if (current_screen == csPlaylist && !playlist_stats.empty())
|
||||
wHeader->WriteXY(title.length(), 0, 0, "%s", playlist_stats.c_str());
|
||||
if (current_screen == csPlaylist)
|
||||
DisplayTotalPlaylistLength(*wHeader);
|
||||
else if (current_screen == csBrowser)
|
||||
{
|
||||
size_t max_length_without_scroll = wHeader->GetWidth()-volume_state.length()-title.length();
|
||||
|
||||
@@ -23,12 +23,7 @@
|
||||
|
||||
extern ncmpcpp_config Config;
|
||||
|
||||
string EMPTY_TAG;
|
||||
|
||||
void DefineEmptyTags()
|
||||
{
|
||||
EMPTY_TAG = "<empty>";
|
||||
}
|
||||
string EMPTY_TAG = "<empty>";
|
||||
|
||||
Song::Song(mpd_Song *s, bool copy_ptr) : itsSong(s),
|
||||
itsSlash(string::npos),
|
||||
|
||||
@@ -31,8 +31,6 @@
|
||||
|
||||
using std::string;
|
||||
|
||||
void DefineEmptyTags();
|
||||
|
||||
class Song
|
||||
{
|
||||
public:
|
||||
|
||||
@@ -67,7 +67,7 @@ int old_playing;
|
||||
|
||||
time_t time_of_statusbar_lock;
|
||||
|
||||
string playlist_stats;
|
||||
//string playlist_stats;
|
||||
string volume_state;
|
||||
string switch_state;
|
||||
|
||||
@@ -208,12 +208,9 @@ void NcmpcppStatusChanged(Connection *Mpd, StatusChanges changed, void *)
|
||||
|
||||
if (mPlaylist->Empty())
|
||||
{
|
||||
playlist_stats.clear();
|
||||
mPlaylist->Reset();
|
||||
ShowMessage("Cleared playlist!");
|
||||
}
|
||||
else
|
||||
playlist_stats = "(" + IntoStr(mPlaylist->Size()) + (mPlaylist->Size() == 1 ? " item" : " items") + TotalPlaylistLength() + ")";
|
||||
|
||||
if (!block_item_list_update)
|
||||
{
|
||||
@@ -332,9 +329,19 @@ void NcmpcppStatusChanged(Connection *Mpd, StatusChanges changed, void *)
|
||||
{
|
||||
string tracklength;
|
||||
if (s.GetTotalLength())
|
||||
tracklength = " [" + Song::ShowTime(elapsed) + "/" + s.GetLength() + "]";
|
||||
{
|
||||
tracklength = " [";
|
||||
tracklength += Song::ShowTime(elapsed);
|
||||
tracklength += "/";
|
||||
tracklength += s.GetLength();
|
||||
tracklength += "]";
|
||||
}
|
||||
else
|
||||
tracklength = " [" + Song::ShowTime(elapsed) + "]";
|
||||
{
|
||||
tracklength = " [";
|
||||
tracklength += Song::ShowTime(elapsed);
|
||||
tracklength += "]";
|
||||
}
|
||||
my_string_t playing_song = TO_WSTRING(s.toString(Config.song_status_format));
|
||||
|
||||
const size_t max_length_without_scroll = wFooter->GetWidth()-player_state.length()-tracklength.length();
|
||||
@@ -444,7 +451,9 @@ void NcmpcppStatusChanged(Connection *Mpd, StatusChanges changed, void *)
|
||||
if ((changed.Volume) && Config.header_visibility)
|
||||
{
|
||||
int vol = Mpd->GetVolume();
|
||||
volume_state = " Volume: " + IntoStr(vol) + "%";
|
||||
volume_state = " Volume: ";
|
||||
volume_state += IntoStr(vol);
|
||||
volume_state += "%";
|
||||
wHeader->SetColor(Config.volume_color);
|
||||
wHeader->WriteXY(wHeader->GetWidth()-volume_state.length(), 0, 1, "%s", volume_state.c_str());
|
||||
wHeader->SetColor(Config.header_color);
|
||||
|
||||
Reference in New Issue
Block a user