support for opening lyrics in external editor

This commit is contained in:
Andrzej Rybczak
2009-02-17 20:17:37 +01:00
parent 330fdb4759
commit 70f48dd454
6 changed files with 35 additions and 3 deletions

View File

@@ -163,6 +163,8 @@
#
#lyrics_database = "1"
#
#external_editor = ""
#
##### colors definitions #####
#
#colors_enabled = "yes"

View File

@@ -45,6 +45,8 @@ const std::string Lyrics::Folder = home_folder + "/.lyrics";
bool Lyrics::Reload = 0;
std::string Lyrics::Filename;
#ifdef HAVE_CURL_CURL_H
pthread_mutex_t Global::curl = PTHREAD_MUTEX_INITIALIZER;
@@ -157,11 +159,11 @@ void *Lyrics::Get(void *song)
string filename = artist + " - " + title + ".txt";
EscapeUnallowedChars(filename);
const string fullpath = Folder + "/" + filename;
Filename = Folder + "/" + filename;
mkdir(Folder.c_str(), 0755);
std::ifstream input(fullpath.c_str());
std::ifstream input(Filename.c_str());
if (input.is_open())
{
@@ -237,7 +239,7 @@ void *Lyrics::Get(void *song)
*myLyrics->Main() << utf_to_locale_cpy(result);
std::ofstream output(fullpath.c_str());
std::ofstream output(Filename.c_str());
if (output.is_open())
{
output << result;
@@ -252,6 +254,21 @@ void *Lyrics::Get(void *song)
# endif
}
void Lyrics::Edit()
{
if (myScreen != this)
return;
if (Config.external_editor.empty())
{
ShowMessage("External editor is not set!");
return;
}
ShowMessage("Opening lyrics in external editor...");
system(("nohup " + Config.external_editor + " \"" + Filename + "\" > /dev/null 2>&1 &").c_str());
}
#ifdef HAVE_CURL_CURL_H
void Lyrics::Take()

View File

@@ -58,6 +58,8 @@ class Lyrics : public Screen<Scrollpad>
virtual List *GetList() { return 0; }
void Edit();
static bool Reload;
# ifdef HAVE_CURL_CURL_H
@@ -67,6 +69,7 @@ class Lyrics : public Screen<Scrollpad>
protected:
static void *Get(void *);
static std::string Filename;
static const std::string Folder;
# ifdef HAVE_CURL_CURL_H

View File

@@ -1126,6 +1126,10 @@ int main(int argc, char *argv[])
}
else
# endif // HAVE_TAGLIB_H
if (myScreen == myLyrics)
{
myLyrics->Edit();
}
if (myScreen == myBrowser && myBrowser->Main()->Current().type == itDirectory)
{
string old_dir = myBrowser->Main()->Current().name;

View File

@@ -508,6 +508,11 @@ void ReadConfiguration(ncmpcpp_config &conf)
if (!v.empty())
conf.tag_editor_album_format = v;
}
else if (cl.find("external_editor") != string::npos)
{
if (!v.empty())
conf.external_editor = v;
}
else if (cl.find("browser_playlist_prefix") != string::npos)
{
if (!v.empty())

View File

@@ -109,6 +109,7 @@ struct ncmpcpp_config
std::string song_library_format;
std::string media_lib_album_format;
std::string tag_editor_album_format;
std::string external_editor;
std::string pattern;