make it compile under mingw32 --with-curl
This commit is contained in:
@@ -75,15 +75,14 @@ dnl =================================
|
||||
dnl = checking for curl and pthread =
|
||||
dnl =================================
|
||||
if test "$curl" = "yes" ; then
|
||||
AC_CHECK_LIB(pthread, pthread_create, LDFLAGS="$LDFLAGS -lpthread", AC_MSG_ERROR([pthread library is required]))
|
||||
AC_CHECK_HEADERS([pthread.h], , AC_MSG_ERROR([missing pthread.h header]))
|
||||
AC_CHECK_HEADERS([pthread.h], AC_CHECK_LIB(pthread, pthread_create, LDFLAGS="$LDFLAGS -lpthread", AC_MSG_ERROR([pthread library is required])), )
|
||||
AC_PATH_PROG(CURL_CONFIG, curl-config)
|
||||
if test "$CURL_CONFIG" != "" ; then
|
||||
CPPFLAGS="$CPPFLAGS `$CURL_CONFIG --cflags`"
|
||||
AC_CHECK_LIB(curl, curl_easy_init, LDFLAGS="$LDFLAGS `$CURL_CONFIG --libs`", AC_MSG_ERROR([curl library is required]))
|
||||
AC_CHECK_HEADERS([curl/curl.h], , AC_MSG_ERROR([missing curl.h header]))
|
||||
else
|
||||
AC_MSG_ERROR([curl-config executable is missing])
|
||||
AC_CHECK_LIB(curl, curl_easy_init, LDFLAGS="$LDFLAGS -lcurl", AC_MSG_ERROR([curl library is required]))
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
@@ -38,9 +38,9 @@ namespace Global
|
||||
extern size_t MainStartY;
|
||||
extern size_t MainHeight;
|
||||
|
||||
# ifdef HAVE_CURL_CURL_H
|
||||
# ifdef HAVE_PTHREAD_H
|
||||
extern pthread_mutex_t CurlLock;
|
||||
# endif
|
||||
# endif // HAVE_PTHREAD_H
|
||||
|
||||
extern bool BlockItemListUpdate;
|
||||
|
||||
|
||||
23
src/info.cpp
23
src/info.cpp
@@ -27,7 +27,9 @@
|
||||
# else
|
||||
# include <sys/stat.h>
|
||||
# endif // WIN32
|
||||
# include <pthread.h>
|
||||
# ifdef HAVE_PTHREAD_H
|
||||
# include <pthread.h>
|
||||
# endif
|
||||
# include "curl/curl.h"
|
||||
# include "helpers.h"
|
||||
#endif
|
||||
@@ -49,8 +51,12 @@ using std::vector;
|
||||
#ifdef HAVE_CURL_CURL_H
|
||||
const std::string Info::Folder = home_folder + "/.ncmpcpp/artists";
|
||||
bool Info::ArtistReady = 0;
|
||||
|
||||
#ifdef HAVE_PTHREAD_H
|
||||
pthread_t Info::Downloader = 0;
|
||||
#endif
|
||||
#endif // HAVE_PTHREAD_H
|
||||
|
||||
#endif // HAVE_CURL_CURL_H
|
||||
|
||||
Info *myInfo = new Info;
|
||||
|
||||
@@ -71,9 +77,9 @@ std::string Info::Title()
|
||||
return itsTitle;
|
||||
}
|
||||
|
||||
#ifdef HAVE_PTHREAD_H
|
||||
void Info::Update()
|
||||
{
|
||||
# ifdef HAVE_CURL_CURL_H
|
||||
if (!ArtistReady)
|
||||
return;
|
||||
|
||||
@@ -81,8 +87,8 @@ void Info::Update()
|
||||
w->Flush();
|
||||
Downloader = 0;
|
||||
ArtistReady = 0;
|
||||
# endif // HAVE_CURL_CURL_H
|
||||
}
|
||||
#endif // HAVE_PTHREAD_H
|
||||
|
||||
void Info::GetSong()
|
||||
{
|
||||
@@ -121,6 +127,7 @@ void Info::GetArtist()
|
||||
}
|
||||
else
|
||||
{
|
||||
# ifdef HAVE_PTHREAD_H
|
||||
if (Downloader && !ArtistReady)
|
||||
{
|
||||
ShowMessage("Artist's info is being downloaded...");
|
||||
@@ -128,6 +135,7 @@ void Info::GetArtist()
|
||||
}
|
||||
else if (ArtistReady)
|
||||
Update();
|
||||
# endif // HAVE_PTHREAD_H
|
||||
|
||||
string *artist = new string();
|
||||
|
||||
@@ -148,10 +156,13 @@ void Info::GetArtist()
|
||||
itsTitle = "Artist's info - " + *artist;
|
||||
w->Clear();
|
||||
static_cast<Window &>(*w) << "Fetching artist's info...";
|
||||
# ifdef HAVE_PTHREAD_H
|
||||
if (!Downloader)
|
||||
{
|
||||
pthread_create(&Downloader, NULL, PrepareArtist, artist);
|
||||
}
|
||||
# else
|
||||
PrepareArtist(&artist);
|
||||
w->Flush();
|
||||
# endif // HAVE_PTHREAD_H
|
||||
}
|
||||
else
|
||||
delete artist;
|
||||
|
||||
@@ -34,7 +34,9 @@ class Info : public Screen<Scrollpad>
|
||||
|
||||
virtual std::string Title();
|
||||
|
||||
# ifdef HAVE_PTHREAD_H
|
||||
virtual void Update();
|
||||
# endif // HAVE_PTHREAD_H
|
||||
|
||||
virtual void EnterPressed() { }
|
||||
virtual void SpacePressed() { }
|
||||
@@ -57,7 +59,11 @@ class Info : public Screen<Scrollpad>
|
||||
|
||||
static const std::string Folder;
|
||||
static bool ArtistReady;
|
||||
|
||||
# ifdef HAVE_PTHREAD_H
|
||||
static pthread_t Downloader;
|
||||
# endif // HAVE_PTHREAD_H
|
||||
|
||||
# endif // HAVE_CURL_CURL_H
|
||||
|
||||
std::string itsTitle;
|
||||
|
||||
@@ -49,15 +49,14 @@ using std::string;
|
||||
const std::string Lyrics::Folder = home_folder + "/.lyrics";
|
||||
|
||||
bool Lyrics::Reload = 0;
|
||||
bool Lyrics::Ready = 0;
|
||||
|
||||
std::string Lyrics::Filename;
|
||||
|
||||
#ifdef HAVE_CURL_CURL_H
|
||||
#ifdef HAVE_PTHREAD_H
|
||||
pthread_t Lyrics::Downloader = 0;
|
||||
pthread_mutex_t Global::CurlLock = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
bool Lyrics::Ready = 0;
|
||||
#endif
|
||||
#endif // HAVE_PTHREAD_H
|
||||
|
||||
Lyrics *myLyrics = new Lyrics;
|
||||
|
||||
@@ -75,10 +74,10 @@ void Lyrics::Resize()
|
||||
|
||||
void Lyrics::Update()
|
||||
{
|
||||
# ifdef HAVE_CURL_CURL_H
|
||||
# ifdef HAVE_PTHREAD_H
|
||||
if (myLyrics->Ready)
|
||||
myLyrics->Take();
|
||||
# endif // HAVE_CURL_CURL_H
|
||||
# endif // HAVE_PTHREAD_H
|
||||
|
||||
if (!Reload)
|
||||
return;
|
||||
@@ -98,7 +97,7 @@ void Lyrics::SwitchTo()
|
||||
}
|
||||
else
|
||||
{
|
||||
# ifdef HAVE_CURL_CURL_H
|
||||
# ifdef HAVE_PTHREAD_H
|
||||
if (Downloader && !Ready)
|
||||
{
|
||||
ShowMessage("Lyrics are being downloaded...");
|
||||
@@ -109,7 +108,7 @@ void Lyrics::SwitchTo()
|
||||
Take();
|
||||
return;
|
||||
}
|
||||
# endif
|
||||
# endif // HAVE_PTHREAD_H
|
||||
|
||||
const MPD::Song *s = Reload ? myPlaylist->NowPlayingSong() : myScreen->CurrentSong();
|
||||
|
||||
@@ -132,14 +131,14 @@ void Lyrics::SwitchTo()
|
||||
w->Clear();
|
||||
# ifdef HAVE_CURL_CURL_H
|
||||
static_cast<Window &>(*w) << "Fetching lyrics...";
|
||||
# endif // HAVE_CURL_CURL_H
|
||||
# ifdef HAVE_PTHREAD_H
|
||||
if (!Downloader)
|
||||
{
|
||||
pthread_create(&Downloader, NULL, Get, &itsSong);
|
||||
}
|
||||
# else
|
||||
Get(&itsSong);
|
||||
w->Flush();
|
||||
# endif
|
||||
# endif // HAVE_PTHREAD_H
|
||||
}
|
||||
Reload = 0;
|
||||
}
|
||||
@@ -190,10 +189,8 @@ void *Lyrics::Get(void *song)
|
||||
*myLyrics->Main() << line;
|
||||
first = 0;
|
||||
}
|
||||
# ifdef HAVE_CURL_CURL_H
|
||||
Ready = 1;
|
||||
pthread_exit(NULL);
|
||||
# endif
|
||||
}
|
||||
# ifdef HAVE_CURL_CURL_H
|
||||
CURLcode code;
|
||||
@@ -295,6 +292,7 @@ void Lyrics::Edit()
|
||||
|
||||
#ifdef HAVE_CURL_CURL_H
|
||||
|
||||
#ifdef HAVE_PTHREAD_H
|
||||
void Lyrics::Take()
|
||||
{
|
||||
if (!Ready)
|
||||
@@ -304,6 +302,7 @@ void Lyrics::Take()
|
||||
Downloader = 0;
|
||||
Ready = 0;
|
||||
}
|
||||
#endif // HAVE_PTHREAD_H
|
||||
|
||||
const char *Lyrics::GetPluginName(int offset)
|
||||
{
|
||||
|
||||
10
src/lyrics.h
10
src/lyrics.h
@@ -26,7 +26,9 @@
|
||||
#include "screen.h"
|
||||
|
||||
#ifdef HAVE_CURL_CURL_H
|
||||
# include <pthread.h>
|
||||
# ifdef HAVE_PTHREAD_H
|
||||
# include <pthread.h>
|
||||
# endif
|
||||
# include "curl/curl.h"
|
||||
#endif
|
||||
|
||||
@@ -74,14 +76,20 @@ class Lyrics : public Screen<Scrollpad>
|
||||
static const std::string Folder;
|
||||
|
||||
# ifdef HAVE_CURL_CURL_H
|
||||
|
||||
# ifdef HAVE_PTHREAD_H
|
||||
void Take();
|
||||
# endif // HAVE_PTHREAD_H
|
||||
|
||||
static const Plugin *ChoosePlugin(int);
|
||||
static bool LyricWiki_NotFound(const std::string &);
|
||||
static bool LyricsPlugin_NotFound(const std::string &);
|
||||
|
||||
static bool Ready;
|
||||
|
||||
# ifdef HAVE_PTHREAD_H
|
||||
static pthread_t Downloader;
|
||||
# endif // HAVE_PTHREAD_H
|
||||
|
||||
static const char *PluginsList[];
|
||||
static const Plugin LyricWiki;
|
||||
|
||||
@@ -27,6 +27,12 @@
|
||||
#include "menu.h"
|
||||
#include "scrollpad.h"
|
||||
|
||||
#ifndef HAVE_PTHREAD_H
|
||||
# define pthread_mutex_lock(x);
|
||||
# define pthread_mutex_unlock(x);
|
||||
# define pthread_exit(x) return 0;
|
||||
#endif
|
||||
|
||||
using namespace NCurses;
|
||||
|
||||
typedef std::pair<std::string, std::string> string_pair;
|
||||
|
||||
Reference in New Issue
Block a user