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