set SIGWINCH handler before initializing ncurses to avoid races
[ncmpcpp.git] / src / lastfm.h
blob051dc8aae488a4c315125a52c2b4ca368bd14e9e
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 isMergable() OVERRIDE { return true; }
53 template <typename ServiceT>
54 void queueJob(ServiceT &&service)
56 typedef typename std::remove_reference<ServiceT>::type ServiceNoRef;
58 auto old_service = dynamic_cast<ServiceNoRef *>(m_service.get());
59 // if the same service and arguments were used, leave old info
60 if (old_service != nullptr && *old_service == service)
61 return;
63 m_service = std::make_shared<ServiceNoRef>(std::forward<ServiceT>(service));
64 m_worker = boost::async(boost::launch::async, boost::bind(&LastFm::Service::fetch, m_service.get()));
66 w.clear();
67 w << "Fetching information...";
68 w.flush();
69 m_title = ToWString(m_service->name());
72 protected:
73 virtual bool isLockable() OVERRIDE { return false; }
75 private:
76 void getResult();
78 std::wstring m_title;
80 std::shared_ptr<LastFm::Service> m_service;
81 boost::future<LastFm::Service::Result> m_worker;
84 extern Lastfm *myLastfm;
86 #endif // HAVE_CURL_CURL_H
88 #endif // NCMPCPP_LASTFM_H