configure: require boost.thread v3
[ncmpcpp.git] / src / lastfm.h
blob712609944a482668bafc02fa1ea93e20c0075fa7
1 /***************************************************************************
2 * Copyright (C) 2008-2013 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 NCMPCPP_LASTFM_H
22 #define NCMPCPP_LASTFM_H
24 #include "config.h"
26 #ifdef HAVE_CURL_CURL_H
28 #include <memory>
29 #include <boost/thread/future.hpp>
31 #include "interfaces.h"
32 #include "lastfm_service.h"
33 #include "screen.h"
34 #include "utility/wide_string.h"
36 struct Lastfm: Screen<NC::Scrollpad>, Tabbable
38 Lastfm();
40 virtual void switchTo() OVERRIDE;
41 virtual void resize() OVERRIDE;
43 virtual std::wstring title() OVERRIDE;
44 virtual ScreenType type() OVERRIDE { return ScreenType::Lastfm; }
46 virtual void update() OVERRIDE;
48 virtual void enterPressed() OVERRIDE { }
49 virtual void spacePressed() OVERRIDE { }
51 virtual bool isMergable() OVERRIDE { return true; }
53 template <typename ServiceT>
54 bool queueJob(ServiceT service)
56 auto old_service = dynamic_cast<ServiceT *>(m_service.get());
57 // if the same service and arguments were used, leave old info
58 if (old_service != nullptr && *old_service == service)
59 return true;
61 // download in progress
62 if (m_worker.valid() && !m_worker.is_ready())
63 return false;
65 m_service = std::make_shared<ServiceT>(std::forward<ServiceT>(service));
66 m_worker = boost::async(boost::launch::async, boost::bind(&LastFm::Service::fetch, m_service.get()));
68 w.clear();
69 w << "Fetching information...";
70 w.flush();
71 m_title = ToWString(m_service->name());
73 return true;
76 protected:
77 virtual bool isLockable() OVERRIDE { return false; }
79 private:
80 void getResult();
82 std::wstring m_title;
84 std::shared_ptr<LastFm::Service> m_service;
85 boost::future<LastFm::Service::Result> m_worker;
88 extern Lastfm *myLastfm;
90 #endif // HAVE_CURL_CURL_H
92 #endif // NCMPCPP_LASTFM_H