1 /***************************************************************************
2 * Copyright (C) 2008-2012 by Andrzej Rybczak *
3 * electricityispower@gmail.com *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
19 ***************************************************************************/
29 #include "lyrics_fetcher.h"
31 class Lyrics
: public Screen
<NC::Scrollpad
>
34 Lyrics() : ReloadNP(0),
35 # ifdef HAVE_CURL_CURL_H
36 isReadyToTake(0), isDownloadInProgress(0),
37 # endif // HAVE_CURL_CURL_H
40 virtual void Resize();
41 virtual void SwitchTo();
43 virtual std::basic_string
<my_char_t
> Title();
45 virtual void Update();
47 virtual void EnterPressed() { }
48 virtual void SpacePressed();
50 virtual bool isMergable() { return true; }
54 # ifdef HAVE_CURL_CURL_H
57 static void ToggleFetcher();
58 static void DownloadInBackground(const MPD::Song
*s
);
59 # endif // HAVE_CURL_CURL_H
65 virtual bool isLockable() { return false; }
70 # ifdef HAVE_CURL_CURL_H
71 static void *DownloadInBackgroundImpl(void *);
72 static void DownloadInBackgroundImplHelper(MPD::Song
*);
73 // lock for allowing exclusive access to itsToDownload and itsWorkersNumber
74 static pthread_mutex_t itsDIBLock
;
75 // storage for songs for which lyrics are scheduled to be downloaded
76 static std::queue
<MPD::Song
*> itsToDownload
;
77 // current worker threads (ie. downloading lyrics)
78 static size_t itsWorkersNumber
;
79 // maximum number of worker threads. if it's reached, next lyrics requests
80 // are put into itsToDownload queue.
81 static const size_t itsMaxWorkersNumber
= 4;
84 static void *DownloadWrapper(void *);
85 static void Save(const std::string
&filename
, const std::string
&lyrics
);
89 bool isDownloadInProgress
;
90 pthread_t itsDownloader
;
92 static LyricsFetcher
**itsFetcher
;
93 # endif // HAVE_CURL_CURL_H
95 size_t itsScrollBegin
;
97 std::string itsFilename
;
99 static std::string
GenerateFilename(const MPD::Song
&s
);
102 extern Lyrics
*myLyrics
;