put local functions into unnamed namespaces
This commit is contained in:
105
src/help.cpp
105
src/help.cpp
@@ -23,62 +23,65 @@
|
|||||||
|
|
||||||
extern ncmpcpp_keys Key;
|
extern ncmpcpp_keys Key;
|
||||||
|
|
||||||
string DisplayKeys(int *key, int size = 2)
|
namespace
|
||||||
{
|
{
|
||||||
bool backspace = 1;
|
string DisplayKeys(int *key, int size = 2)
|
||||||
string result = "\t";
|
|
||||||
for (int i = 0; i < size; i++)
|
|
||||||
{
|
{
|
||||||
if (key[i] == null_key);
|
bool backspace = 1;
|
||||||
else if (key[i] == 259)
|
string result = "\t";
|
||||||
result += "Up";
|
for (int i = 0; i < size; i++)
|
||||||
else if (key[i] == 258)
|
|
||||||
result += "Down";
|
|
||||||
else if (key[i] == 339)
|
|
||||||
result += "Page Up";
|
|
||||||
else if (key[i] == 338)
|
|
||||||
result += "Page Down";
|
|
||||||
else if (key[i] == 262)
|
|
||||||
result += "Home";
|
|
||||||
else if (key[i] == 360)
|
|
||||||
result += "End";
|
|
||||||
else if (key[i] == 32)
|
|
||||||
result += "Space";
|
|
||||||
else if (key[i] == 10)
|
|
||||||
result += "Enter";
|
|
||||||
else if (key[i] == 330)
|
|
||||||
result += "Delete";
|
|
||||||
else if (key[i] == 261)
|
|
||||||
result += "Right";
|
|
||||||
else if (key[i] == 260)
|
|
||||||
result += "Left";
|
|
||||||
else if (key[i] == 9)
|
|
||||||
result += "Tab";
|
|
||||||
else if (key[i] >= 1 && key[i] <= 26)
|
|
||||||
{
|
{
|
||||||
result += "Ctrl-";
|
if (key[i] == null_key);
|
||||||
result += key[i]+64;
|
else if (key[i] == 259)
|
||||||
|
result += "Up";
|
||||||
|
else if (key[i] == 258)
|
||||||
|
result += "Down";
|
||||||
|
else if (key[i] == 339)
|
||||||
|
result += "Page Up";
|
||||||
|
else if (key[i] == 338)
|
||||||
|
result += "Page Down";
|
||||||
|
else if (key[i] == 262)
|
||||||
|
result += "Home";
|
||||||
|
else if (key[i] == 360)
|
||||||
|
result += "End";
|
||||||
|
else if (key[i] == 32)
|
||||||
|
result += "Space";
|
||||||
|
else if (key[i] == 10)
|
||||||
|
result += "Enter";
|
||||||
|
else if (key[i] == 330)
|
||||||
|
result += "Delete";
|
||||||
|
else if (key[i] == 261)
|
||||||
|
result += "Right";
|
||||||
|
else if (key[i] == 260)
|
||||||
|
result += "Left";
|
||||||
|
else if (key[i] == 9)
|
||||||
|
result += "Tab";
|
||||||
|
else if (key[i] >= 1 && key[i] <= 26)
|
||||||
|
{
|
||||||
|
result += "Ctrl-";
|
||||||
|
result += key[i]+64;
|
||||||
|
}
|
||||||
|
else if (key[i] >= 265 && key[i] <= 276)
|
||||||
|
{
|
||||||
|
result += "F";
|
||||||
|
result += key[i]-216;
|
||||||
|
}
|
||||||
|
else if ((key[i] == 263 || key[i] == 127) && !backspace);
|
||||||
|
else if ((key[i] == 263 || key[i] == 127) && backspace)
|
||||||
|
{
|
||||||
|
result += "Backspace";
|
||||||
|
backspace = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
result += key[i];
|
||||||
|
result += " ";
|
||||||
}
|
}
|
||||||
else if (key[i] >= 265 && key[i] <= 276)
|
if (result.length() > 12)
|
||||||
{
|
result = result.substr(0, 12);
|
||||||
result += "F";
|
for (int i = result.length(); i <= 12; result += " ", i++);
|
||||||
result += key[i]-216;
|
result += ": ";
|
||||||
}
|
return result;
|
||||||
else if ((key[i] == 263 || key[i] == 127) && !backspace);
|
|
||||||
else if ((key[i] == 263 || key[i] == 127) && backspace)
|
|
||||||
{
|
|
||||||
result += "Backspace";
|
|
||||||
backspace = 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
result += key[i];
|
|
||||||
result += " ";
|
|
||||||
}
|
}
|
||||||
if (result.length() > 12)
|
|
||||||
result = result.substr(0, 12);
|
|
||||||
for (int i = result.length(); i <= 12; result += " ", i++);
|
|
||||||
result += ": ";
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
string GetKeybindings()
|
string GetKeybindings()
|
||||||
|
|||||||
@@ -32,30 +32,33 @@ pthread_mutex_t curl = PTHREAD_MUTEX_INITIALIZER;
|
|||||||
bool data_ready = 0;
|
bool data_ready = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
size_t write_data(char *buffer, size_t size, size_t nmemb, string data)
|
namespace
|
||||||
{
|
{
|
||||||
int result = 0;
|
size_t write_data(char *buffer, size_t size, size_t nmemb, string data)
|
||||||
if (buffer)
|
|
||||||
{
|
{
|
||||||
data += buffer;
|
int result = 0;
|
||||||
result = size*nmemb;
|
if (buffer)
|
||||||
|
{
|
||||||
|
data += buffer;
|
||||||
|
result = size*nmemb;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
void EscapeHtml(string &str)
|
void EscapeHtml(string &str)
|
||||||
{
|
|
||||||
for (int i = str.find("<"); i != string::npos; i = str.find("<"))
|
|
||||||
{
|
{
|
||||||
int j = str.find(">")+1;
|
for (int i = str.find("<"); i != string::npos; i = str.find("<"))
|
||||||
str.replace(i, j-i, "");
|
{
|
||||||
|
int j = str.find(">")+1;
|
||||||
|
str.replace(i, j-i, "");
|
||||||
|
}
|
||||||
|
for (int i = str.find("'"); i != string::npos; i = str.find("'"))
|
||||||
|
str.replace(i, 6, "'");
|
||||||
|
for (int i = str.find("""); i != string::npos; i = str.find("""))
|
||||||
|
str.replace(i, 6, "\"");
|
||||||
|
for (int i = str.find("&"); i != string::npos; i = str.find("&"))
|
||||||
|
str.replace(i, 5, "&");
|
||||||
}
|
}
|
||||||
for (int i = str.find("'"); i != string::npos; i = str.find("'"))
|
|
||||||
str.replace(i, 6, "'");
|
|
||||||
for (int i = str.find("""); i != string::npos; i = str.find("""))
|
|
||||||
str.replace(i, 6, "\"");
|
|
||||||
for (int i = str.find("&"); i != string::npos; i = str.find("&"))
|
|
||||||
str.replace(i, 5, "&");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_CURL_CURL_H
|
#ifdef HAVE_CURL_CURL_H
|
||||||
|
|||||||
@@ -30,7 +30,6 @@
|
|||||||
void * GetArtistInfo(void *);
|
void * GetArtistInfo(void *);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void EscapeHtml(string &);
|
|
||||||
void * GetLyrics(void *);
|
void * GetLyrics(void *);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
133
src/settings.cpp
133
src/settings.cpp
@@ -197,29 +197,6 @@ void DefaultConfiguration(ncmpcpp_config &conf)
|
|||||||
conf.message_delay_time = 4;
|
conf.message_delay_time = 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GetKeys(string line, int *key)
|
|
||||||
{
|
|
||||||
int i = line.find("=")+1;
|
|
||||||
line = line.substr(i, line.length()-i);
|
|
||||||
i = 0;
|
|
||||||
if (line[i] == ' ')
|
|
||||||
while (line[++i] == ' ');
|
|
||||||
line = line.substr(i, line.length()-i);
|
|
||||||
i = line.find(" ");
|
|
||||||
string one;
|
|
||||||
string two;
|
|
||||||
if (i != string::npos)
|
|
||||||
{
|
|
||||||
one = line.substr(0, i);
|
|
||||||
i++;
|
|
||||||
two = line.substr(i, line.length()-i);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
one = line;
|
|
||||||
key[0] = !one.empty() && one[0] == '\'' ? one[1] : (atoi(one.c_str()) == 0 ? null_key : atoi(one.c_str()));
|
|
||||||
key[1] = !two.empty() && two[0] == '\'' ? two[1] : (atoi(two.c_str()) == 0 ? null_key : atoi(two.c_str()));
|
|
||||||
}
|
|
||||||
|
|
||||||
string GetLineValue(const string &line, char a, char b)
|
string GetLineValue(const string &line, char a, char b)
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
@@ -240,54 +217,80 @@ string GetLineValue(const string &line, char a, char b)
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
string IntoStr(Color color)
|
namespace
|
||||||
{
|
{
|
||||||
string result;
|
void GetKeys(string line, int *key)
|
||||||
|
{
|
||||||
|
int i = line.find("=")+1;
|
||||||
|
line = line.substr(i, line.length()-i);
|
||||||
|
i = 0;
|
||||||
|
if (line[i] == ' ')
|
||||||
|
while (line[++i] == ' ');
|
||||||
|
line = line.substr(i, line.length()-i);
|
||||||
|
i = line.find(" ");
|
||||||
|
string one;
|
||||||
|
string two;
|
||||||
|
if (i != string::npos)
|
||||||
|
{
|
||||||
|
one = line.substr(0, i);
|
||||||
|
i++;
|
||||||
|
two = line.substr(i, line.length()-i);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
one = line;
|
||||||
|
key[0] = !one.empty() && one[0] == '\'' ? one[1] : (atoi(one.c_str()) == 0 ? null_key : atoi(one.c_str()));
|
||||||
|
key[1] = !two.empty() && two[0] == '\'' ? two[1] : (atoi(two.c_str()) == 0 ? null_key : atoi(two.c_str()));
|
||||||
|
}
|
||||||
|
|
||||||
if (color == clDefault)
|
string IntoStr(Color color)
|
||||||
result = "default";
|
{
|
||||||
else if (color == clBlack)
|
string result;
|
||||||
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;
|
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";
|
||||||
|
|
||||||
Color IntoColor(const string &color)
|
return result;
|
||||||
{
|
}
|
||||||
Color result = clDefault;
|
|
||||||
|
|
||||||
if (color == "black")
|
Color IntoColor(const string &color)
|
||||||
result = clBlack;
|
{
|
||||||
else if (color == "red")
|
Color result = clDefault;
|
||||||
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;
|
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 ReadKeys(ncmpcpp_keys &keys)
|
void ReadKeys(ncmpcpp_keys &keys)
|
||||||
|
|||||||
@@ -147,12 +147,10 @@ struct ncmpcpp_config
|
|||||||
|
|
||||||
void DefaultKeys(ncmpcpp_keys &);
|
void DefaultKeys(ncmpcpp_keys &);
|
||||||
void DefaultConfiguration(ncmpcpp_config &);
|
void DefaultConfiguration(ncmpcpp_config &);
|
||||||
void GetKeys(string, int *);
|
|
||||||
string GetLineValue(const string &, char = '"', char = '"');
|
|
||||||
string IntoStr(Color);
|
|
||||||
Color IntoColor(const string &);
|
|
||||||
void ReadKeys(ncmpcpp_keys &);
|
void ReadKeys(ncmpcpp_keys &);
|
||||||
void ReadConfiguration(ncmpcpp_config &);
|
void ReadConfiguration(ncmpcpp_config &);
|
||||||
|
|
||||||
|
string GetLineValue(const string &, char = '"', char = '"');
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -189,98 +189,101 @@ bool WriteTags(Song &s)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
SongSetFunction IntoSetFunction(char c)
|
namespace
|
||||||
{
|
{
|
||||||
switch (c)
|
SongSetFunction IntoSetFunction(char c)
|
||||||
{
|
{
|
||||||
case 'a':
|
switch (c)
|
||||||
return &Song::SetArtist;
|
|
||||||
case 't':
|
|
||||||
return &Song::SetTitle;
|
|
||||||
case 'b':
|
|
||||||
return &Song::SetAlbum;
|
|
||||||
case 'y':
|
|
||||||
return &Song::SetYear;
|
|
||||||
case 'n':
|
|
||||||
return &Song::SetTrack;
|
|
||||||
case 'g':
|
|
||||||
return &Song::SetGenre;
|
|
||||||
case 'c':
|
|
||||||
return &Song::SetComposer;
|
|
||||||
case 'p':
|
|
||||||
return &Song::SetPerformer;
|
|
||||||
case 'd':
|
|
||||||
return &Song::SetDisc;
|
|
||||||
case 'C':
|
|
||||||
return &Song::SetComment;
|
|
||||||
default:
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
string GenerateFilename(const Song &s, string &pattern)
|
|
||||||
{
|
|
||||||
const string unallowed_chars = "\"*/:<>?\\|";
|
|
||||||
string result = Window::OmitBBCodes(DisplaySong(s, &pattern));
|
|
||||||
for (string::const_iterator it = unallowed_chars.begin(); it != unallowed_chars.end(); it++)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < result.length(); i++)
|
|
||||||
{
|
{
|
||||||
if (result[i] == *it)
|
case 'a':
|
||||||
result.erase(result.begin()+i);
|
return &Song::SetArtist;
|
||||||
|
case 't':
|
||||||
|
return &Song::SetTitle;
|
||||||
|
case 'b':
|
||||||
|
return &Song::SetAlbum;
|
||||||
|
case 'y':
|
||||||
|
return &Song::SetYear;
|
||||||
|
case 'n':
|
||||||
|
return &Song::SetTrack;
|
||||||
|
case 'g':
|
||||||
|
return &Song::SetGenre;
|
||||||
|
case 'c':
|
||||||
|
return &Song::SetComposer;
|
||||||
|
case 'p':
|
||||||
|
return &Song::SetPerformer;
|
||||||
|
case 'd':
|
||||||
|
return &Song::SetDisc;
|
||||||
|
case 'C':
|
||||||
|
return &Song::SetComment;
|
||||||
|
default:
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
string ParseFilename(Song &s, string mask, bool preview)
|
string GenerateFilename(const Song &s, string &pattern)
|
||||||
{
|
|
||||||
std::stringstream result;
|
|
||||||
vector<string> separators;
|
|
||||||
vector< std::pair<char, string> > tags;
|
|
||||||
string file = s.GetName().substr(0, s.GetName().find_last_of("."));
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
for (int i = mask.find("%"); i != string::npos; i = mask.find("%"))
|
const string unallowed_chars = "\"*/:<>?\\|";
|
||||||
|
string result = Window::OmitBBCodes(DisplaySong(s, &pattern));
|
||||||
|
for (string::const_iterator it = unallowed_chars.begin(); it != unallowed_chars.end(); it++)
|
||||||
{
|
{
|
||||||
tags.push_back(make_pair(mask.at(i+1), ""));
|
for (int i = 0; i < result.length(); i++)
|
||||||
mask = mask.substr(i+2);
|
{
|
||||||
i = mask.find("%");
|
if (result[i] == *it)
|
||||||
if (!mask.empty())
|
result.erase(result.begin()+i);
|
||||||
separators.push_back(mask.substr(0, i));
|
}
|
||||||
}
|
}
|
||||||
int i = 0;
|
return result;
|
||||||
for (vector<string>::const_iterator it = separators.begin(); it != separators.end(); it++, i++)
|
|
||||||
{
|
|
||||||
int j = file.find(*it);
|
|
||||||
tags.at(i).second = file.substr(0, j);
|
|
||||||
file = file.substr(j+it->length());
|
|
||||||
}
|
|
||||||
if (!file.empty())
|
|
||||||
tags.at(i).second = file;
|
|
||||||
}
|
|
||||||
catch (std::out_of_range)
|
|
||||||
{
|
|
||||||
return "Error while parsing filename!";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (vector< std::pair<char, string> >::iterator it = tags.begin(); it != tags.end(); it++)
|
string ParseFilename(Song &s, string mask, bool preview)
|
||||||
{
|
{
|
||||||
for (string::iterator j = it->second.begin(); j != it->second.end(); j++)
|
std::stringstream result;
|
||||||
if (*j == '_')
|
vector<string> separators;
|
||||||
*j = ' ';
|
vector< std::pair<char, string> > tags;
|
||||||
|
string file = s.GetName().substr(0, s.GetName().find_last_of("."));
|
||||||
|
|
||||||
if (!preview)
|
try
|
||||||
{
|
{
|
||||||
SongSetFunction set = IntoSetFunction(it->first);
|
for (int i = mask.find("%"); i != string::npos; i = mask.find("%"))
|
||||||
if (set)
|
{
|
||||||
(s.*set)(it->second);
|
tags.push_back(make_pair(mask.at(i+1), ""));
|
||||||
|
mask = mask.substr(i+2);
|
||||||
|
i = mask.find("%");
|
||||||
|
if (!mask.empty())
|
||||||
|
separators.push_back(mask.substr(0, i));
|
||||||
|
}
|
||||||
|
int i = 0;
|
||||||
|
for (vector<string>::const_iterator it = separators.begin(); it != separators.end(); it++, i++)
|
||||||
|
{
|
||||||
|
int j = file.find(*it);
|
||||||
|
tags.at(i).second = file.substr(0, j);
|
||||||
|
file = file.substr(j+it->length());
|
||||||
|
}
|
||||||
|
if (!file.empty())
|
||||||
|
tags.at(i).second = file;
|
||||||
}
|
}
|
||||||
else
|
catch (std::out_of_range)
|
||||||
result << "%" << it->first << ": " << it->second << "\n";
|
{
|
||||||
|
return "Error while parsing filename!";
|
||||||
|
}
|
||||||
|
|
||||||
|
for (vector< std::pair<char, string> >::iterator it = tags.begin(); it != tags.end(); it++)
|
||||||
|
{
|
||||||
|
for (string::iterator j = it->second.begin(); j != it->second.end(); j++)
|
||||||
|
if (*j == '_')
|
||||||
|
*j = ' ';
|
||||||
|
|
||||||
|
if (!preview)
|
||||||
|
{
|
||||||
|
SongSetFunction set = IntoSetFunction(it->first);
|
||||||
|
if (set)
|
||||||
|
(s.*set)(it->second);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
result << "%" << it->first << ": " << it->second << "\n";
|
||||||
|
}
|
||||||
|
return result.str();
|
||||||
}
|
}
|
||||||
return result.str();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void __deal_with_filenames(SongList &v)
|
void __deal_with_filenames(SongList &v)
|
||||||
|
|||||||
@@ -41,8 +41,6 @@ string DisplayTag(const Song &, void *, const Menu<Song> *);
|
|||||||
bool GetSongTags(Song &);
|
bool GetSongTags(Song &);
|
||||||
bool WriteTags(Song &);
|
bool WriteTags(Song &);
|
||||||
|
|
||||||
string GenerateFilename(const Song &, string &);
|
|
||||||
string ParseFilename(Song &, string, bool);
|
|
||||||
void __deal_with_filenames(SongList &);
|
void __deal_with_filenames(SongList &);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user