change version to 0.7.3
[ncmpcpp.git] / src / lastfm.h
blob8903447d7a714eaa9c3c3d53e9521dc281206aba
1 /***************************************************************************
2 * Copyright (C) 2008-2014 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 bool isLockable() OVERRIDE { return false; }
49 virtual bool isMergable() OVERRIDE { return true; }
51 template <typename ServiceT>
52 void queueJob(ServiceT *service)
54 auto old_service = dynamic_cast<ServiceT *>(m_service.get());
55 // if the same service and arguments were used, leave old info
56 if (old_service != nullptr && *old_service == *service)
57 return;
59 m_service = std::shared_ptr<ServiceT>(service);
60 m_worker = boost::async(boost::launch::async, std::bind(&LastFm::Service::fetch, m_service));
62 w.clear();
63 w << "Fetching information...";
64 w.flush();
65 m_title = ToWString(m_service->name());
68 private:
69 void getResult();
71 std::wstring m_title;
73 std::shared_ptr<LastFm::Service> m_service;
74 boost::future<LastFm::Service::Result> m_worker;
77 extern Lastfm *myLastfm;
79 #endif // HAVE_CURL_CURL_H
81 #endif // NCMPCPP_LASTFM_H