format: shorten date by simple truncation
[ncmpcpp.git] / src / lastfm.h
blob0998d3cec604798e89dfd3b8e1a4ca681796794d
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 { }
50 virtual bool isLockable() OVERRIDE { return false; }
51 virtual bool isMergable() OVERRIDE { return true; }
53 template <typename ServiceT>
54 void 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;
61 m_service = std::shared_ptr<ServiceT>(service);
62 m_worker = boost::async(boost::launch::async, std::bind(&LastFm::Service::fetch, m_service));
64 w.clear();
65 w << "Fetching information...";
66 w.flush();
67 m_title = ToWString(m_service->name());
70 private:
71 void getResult();
73 std::wstring m_title;
75 std::shared_ptr<LastFm::Service> m_service;
76 boost::future<LastFm::Service::Result> m_worker;
79 extern Lastfm *myLastfm;
81 #endif // HAVE_CURL_CURL_H
83 #endif // NCMPCPP_LASTFM_H