added: when there's no artist or title set, show the filename without directories and extension instead
This commit is contained in:
parent
dd0a4d3bba
commit
0c826cbe7b
2 changed files with 27 additions and 11 deletions
|
@ -85,6 +85,7 @@ bool CMpdClient::GetCurrentSong()
|
||||||
|
|
||||||
string artist;
|
string artist;
|
||||||
string title;
|
string title;
|
||||||
|
string file;
|
||||||
|
|
||||||
data.Clear();
|
data.Clear();
|
||||||
while(1)
|
while(1)
|
||||||
|
@ -112,24 +113,17 @@ bool CMpdClient::GetCurrentSong()
|
||||||
artist = tmpline.substr(1);
|
artist = tmpline.substr(1);
|
||||||
else if (word == "Title:")
|
else if (word == "Title:")
|
||||||
title = tmpline.substr(1);
|
title = tmpline.substr(1);
|
||||||
|
else if (word == "file:")
|
||||||
|
file = StripFilename(tmpline.substr(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (line == "OK")
|
if (line == "OK")
|
||||||
{
|
{
|
||||||
string songtext;
|
string songtext;
|
||||||
if (artist.empty() && title.empty())
|
if (artist.empty() || title.empty())
|
||||||
{
|
songtext = file;
|
||||||
songtext = "Wat? No title?";
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
if (artist.empty())
|
|
||||||
artist = "Unknown artist";
|
|
||||||
if (title.empty())
|
|
||||||
title = "Unknown title";
|
|
||||||
|
|
||||||
songtext = artist + " - " + title;
|
songtext = artist + " - " + title;
|
||||||
}
|
|
||||||
|
|
||||||
SetCurrentSong(songtext);
|
SetCurrentSong(songtext);
|
||||||
return true;
|
return true;
|
||||||
|
@ -262,3 +256,24 @@ bool CMpdClient::GetVolume(int& volume)
|
||||||
m_volumechanged = false;
|
m_volumechanged = false;
|
||||||
return changed;
|
return changed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string CMpdClient::StripFilename(const std::string& filename)
|
||||||
|
{
|
||||||
|
//strip any preceding directories
|
||||||
|
size_t start = filename.rfind('/');
|
||||||
|
if (start == string::npos)
|
||||||
|
start = 0;
|
||||||
|
else if (start < filename.length() - 1)
|
||||||
|
start++;
|
||||||
|
|
||||||
|
//strip the extension
|
||||||
|
size_t end = filename.rfind('.');
|
||||||
|
size_t nchars;
|
||||||
|
if (end == string::npos || end == 0 || end <= start)
|
||||||
|
nchars = string::npos;
|
||||||
|
else
|
||||||
|
nchars = end - start;
|
||||||
|
|
||||||
|
return filename.substr(start, nchars);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,7 @@ class CMpdClient : public CThread
|
||||||
bool GetPlayStatus();
|
bool GetPlayStatus();
|
||||||
void SetCurrentSong(const std::string& song);
|
void SetCurrentSong(const std::string& song);
|
||||||
void SetSockError();
|
void SetSockError();
|
||||||
|
std::string StripFilename(const std::string& filename);
|
||||||
|
|
||||||
int m_port;
|
int m_port;
|
||||||
std::string m_address;
|
std::string m_address;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue