finally kill NC::List
[ncmpcpp.git] / src / lyrics.h
blobf71efc07dd28b04679b39b833c2ee2b3089b8b31
1 /***************************************************************************
2 * Copyright (C) 2008-2012 by Andrzej Rybczak *
3 * electricityispower@gmail.com *
4 * *
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. *
9 * *
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. *
14 * *
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 ***************************************************************************/
21 #ifndef _LYRICS_H
22 #define _LYRICS_H
24 #include <pthread.h>
25 #include <queue>
27 #include "mpdpp.h"
28 #include "screen.h"
29 #include "lyrics_fetcher.h"
31 class Lyrics : public Screen<NC::Scrollpad>
33 public:
34 Lyrics() : ReloadNP(0),
35 # ifdef HAVE_CURL_CURL_H
36 isReadyToTake(0), isDownloadInProgress(0),
37 # endif // HAVE_CURL_CURL_H
38 itsScrollBegin(0) { }
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; }
52 void Edit();
54 # ifdef HAVE_CURL_CURL_H
55 void Refetch();
57 static void ToggleFetcher();
58 static void DownloadInBackground(const MPD::Song *s);
59 # endif // HAVE_CURL_CURL_H
61 bool ReloadNP;
63 protected:
64 virtual void Init();
65 virtual bool isLockable() { return false; }
67 private:
68 void Load();
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;
83 void *Download();
84 static void *DownloadWrapper(void *);
85 static void Save(const std::string &filename, const std::string &lyrics);
87 void Take();
88 bool isReadyToTake;
89 bool isDownloadInProgress;
90 pthread_t itsDownloader;
92 static LyricsFetcher **itsFetcher;
93 # endif // HAVE_CURL_CURL_H
95 size_t itsScrollBegin;
96 MPD::Song itsSong;
97 std::string itsFilename;
99 static std::string GenerateFilename(const MPD::Song &s);
102 extern Lyrics *myLyrics;
104 #endif