bindinds: add support for alt/ctrl/shift modifiers and escape key
[ncmpcpp.git] / src / lastfm.h
blob7ece2b9c55a1eb22de344f1e27d14f1fd5e56740
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 void enterPressed() OVERRIDE { }
49 virtual void spacePressed() OVERRIDE { }
51 virtual bool isLockable() OVERRIDE { return false; }
52 virtual bool isMergable() OVERRIDE { return true; }
54 template <typename ServiceT>
55 void queueJob(ServiceT &&service)
57 typedef typename std::remove_reference<ServiceT>::type ServiceNoRef;
59 auto old_service = dynamic_cast<ServiceNoRef *>(m_service.get());
60 // if the same service and arguments were used, leave old info
61 if (old_service != nullptr && *old_service == service)
62 return;
64 m_service = std::make_shared<ServiceNoRef>(std::forward<ServiceT>(service));
65 m_worker = boost::async(boost::launch::async, std::bind(&LastFm::Service::fetch, m_service.get()));
67 w.clear();
68 w << "Fetching information...";
69 w.flush();
70 m_title = ToWString(m_service->name());
73 private:
74 void getResult();
76 std::wstring m_title;
78 std::shared_ptr<LastFm::Service> m_service;
79 boost::future<LastFm::Service::Result> m_worker;
82 extern Lastfm *myLastfm;
84 #endif // HAVE_CURL_CURL_H
86 #endif // NCMPCPP_LASTFM_H