@ -68,10 +68,10 @@ void Lyrics::Resize()
void Lyrics : : Update ( )
{
# ifdef HAVE_CURL_CURL_H
if ( ReadyToTake )
if ( is ReadyToTake)
Take ( ) ;
if ( DownloadInProgress )
if ( is DownloadInProgress)
{
w - > Flush ( ) ;
w - > Refresh ( ) ;
@ -104,22 +104,23 @@ void Lyrics::SwitchTo()
itsScrollBegin = 0 ;
myOldScreen = myScreen ;
myScreen = this ;
// for taking lyrics if they were downloaded
Update ( ) ;
// take lyrics if they were downloaded
if ( isReadyToTake )
Take ( ) ;
const MPD : : Song * s = myOldScreen - > CurrentSong ( ) ;
if ( s & & ! s - > GetArtist ( ) . empty ( ) & & ! s - > GetTitle ( ) . empty ( ) )
if ( const MPD : : Song * s = myScreen - > CurrentSong ( ) )
{
itsSong = * s ;
Load ( ) ;
myOldScreen = myScreen ;
myScreen = this ;
if ( ! s - > GetArtist ( ) . empty ( ) & & ! s - > GetTitle ( ) . empty ( ) )
{
itsSong = * s ;
Load ( ) ;
}
Global : : RedrawHeader = 1 ;
}
else
return myOldScreen - > SwitchTo ( ) ;
Global : : RedrawHeader = 1 ;
}
std : : basic_string < my_char_t > Lyrics : : Title ( )
@ -150,8 +151,8 @@ void *Lyrics::Download()
// if one of plugins is selected, try only this one,
// otherwise try all of them until one of them succeeds
bool fetcher_defined = Fetcher & & * Fetcher ;
for ( LyricsFetcher * * plugin = fetcher_defined ? Fetcher : lyricsPlugins ; * plugin ! = 0 ; + + plugin )
bool fetcher_defined = its Fetcher & & * its Fetcher;
for ( LyricsFetcher * * plugin = fetcher_defined ? its Fetcher : lyricsPlugins ; * plugin ! = 0 ; + + plugin )
{
* w < < " Fetching lyrics from " < < fmtBold < < ( * plugin ) - > name ( ) < < fmtBoldEnd < < " ... " ;
result = ( * plugin ) - > fetch ( artist , title ) ;
@ -174,7 +175,7 @@ void *Lyrics::Download()
else
* w < < " \n Lyrics weren't found. " ;
ReadyToTake = 1 ;
is ReadyToTake = 1 ;
pthread_exit ( 0 ) ;
}
# endif // HAVE_CURL_CURL_H
@ -182,7 +183,7 @@ void *Lyrics::Download()
void Lyrics : : Load ( )
{
# ifdef HAVE_CURL_CURL_H
if ( DownloadInProgress )
if ( is DownloadInProgress)
return ;
# endif // HAVE_CURL_CURL_H
@ -192,7 +193,7 @@ void Lyrics::Load()
itsSong . Localize ( ) ;
std : : string file = locale_to_utf_cpy ( itsSong . GetArtist ( ) ) + " - " + locale_to_utf_cpy ( itsSong . GetTitle ( ) ) + " .txt " ;
EscapeUnallowedChars ( file ) ;
itsFilenamePath = Folder + " / " + file ;
itsFilename = Folder + " / " + file ;
mkdir ( Folder . c_str ( )
# ifndef WIN32
@ -203,7 +204,7 @@ void Lyrics::Load()
w - > Clear ( ) ;
w - > Reset ( ) ;
std : : ifstream input ( itsFilenamePath . c_str ( ) ) ;
std : : ifstream input ( itsFilename . c_str ( ) ) ;
if ( input . is_open ( ) )
{
bool first = 1 ;
@ -223,8 +224,8 @@ void Lyrics::Load()
else
{
# ifdef HAVE_CURL_CURL_H
pthread_create ( & Downloader , 0 , DownloadWrapper , this ) ;
DownloadInProgress = 1 ;
pthread_create ( & its Downloader, 0 , DownloadWrapper , this ) ;
is DownloadInProgress = 1 ;
# else
* w < < " Local lyrics not found. As ncmpcpp has been compiled without curl support, you can put appropriate lyrics into " < < Folder < < " directory (file syntax is \" $ARTIST - $TITLE.txt \" ) or recompile ncmpcpp with curl support. " ;
w - > Flush ( ) ;
@ -247,7 +248,7 @@ void Lyrics::Edit()
if ( Config . use_console_editor )
{
system ( ( " /bin/sh -c \" " + Config . external_editor + " \\ \" " + itsFilenamePath + " \\ \" \" " ) . c_str ( ) ) ;
system ( ( " /bin/sh -c \" " + Config . external_editor + " \\ \" " + itsFilename + " \\ \" \" " ) . c_str ( ) ) ;
// below is needed as screen gets cleared, but apparently
// ncurses doesn't know about it, so we need to reload main screen
endwin ( ) ;
@ -255,12 +256,12 @@ void Lyrics::Edit()
curs_set ( 0 ) ;
}
else
system ( ( " nohup " + Config . external_editor + " \" " + itsFilenamePath + " \" > /dev/null 2>&1 & " ) . c_str ( ) ) ;
system ( ( " nohup " + Config . external_editor + " \" " + itsFilename + " \" > /dev/null 2>&1 & " ) . c_str ( ) ) ;
}
void Lyrics : : Save ( const std : : string & lyrics )
{
std : : ofstream output ( itsFilenamePath . c_str ( ) ) ;
std : : ofstream output ( itsFilename . c_str ( ) ) ;
if ( output . is_open ( ) )
{
output < < lyrics ;
@ -270,42 +271,38 @@ void Lyrics::Save(const std::string &lyrics)
void Lyrics : : Refetch ( )
{
std : : string file = locale_to_utf_cpy ( itsSong . GetArtist ( ) ) + " - " + locale_to_utf_cpy ( itsSong . GetTitle ( ) ) + " .txt " ;
EscapeUnallowedChars ( file ) ;
std : : string path = Folder + " / " + file ;
if ( ! remove ( path . c_str ( ) ) )
if ( ! remove ( itsFilename . c_str ( ) ) )
{
Load ( ) ;
}
else
{
static const char msg [ ] = " Couldn't remove \" %s \" : %s " ;
ShowMessage ( msg , Shorten ( TO_WSTRING ( path ) , COLS - static_strlen ( msg ) - 25 ) . c_str ( ) , strerror ( errno ) ) ;
ShowMessage ( msg , Shorten ( TO_WSTRING ( itsFilename ) , COLS - static_strlen ( msg ) - 25 ) . c_str ( ) , strerror ( errno ) ) ;
}
}
# ifdef HAVE_CURL_CURL_H
void Lyrics : : ToggleFetcher ( )
{
if ( Fetcher & & * Fetcher )
+ + Fetcher ;
if ( its Fetcher & & * its Fetcher)
+ + its Fetcher;
else
Fetcher = & lyricsPlugins [ 0 ] ;
if ( * Fetcher )
ShowMessage ( " Using lyrics database: %s " , ( * Fetcher ) - > name ( ) ) ;
its Fetcher = & lyricsPlugins [ 0 ] ;
if ( * its Fetcher)
ShowMessage ( " Using lyrics database: %s " , ( * its Fetcher) - > name ( ) ) ;
else
ShowMessage ( " Using all lyrics databases " ) ;
}
void Lyrics : : Take ( )
{
assert ( ReadyToTake ) ;
pthread_join ( Downloader , 0 ) ;
assert ( is ReadyToTake) ;
pthread_join ( its Downloader, 0 ) ;
w - > Flush ( ) ;
w - > Refresh ( ) ;
DownloadInProgress = 0 ;
ReadyToTake = 0 ;
is DownloadInProgress = 0 ;
is ReadyToTake = 0 ;
}
# endif // HAVE_CURL_CURL_H