ncmpc  0.30
AlbumListPage.hxx
Go to the documentation of this file.
1 /* ncmpc (Ncurses MPD Client)
2  * (c) 2004-2018 The Music Player Daemon Project
3  * Project homepage: http://musicpd.org
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 along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 #ifndef NCMPC_ALBUM_LIST_PAGE_HXX
21 #define NCMPC_ALBUM_LIST_PAGE_HXX
22 
23 #include "ListPage.hxx"
24 #include "ListRenderer.hxx"
25 #include "ListText.hxx"
26 
27 #include <vector>
28 #include <string>
29 
30 class ScreenManager;
31 
32 class AlbumListPage final : public ListPage, ListRenderer, ListText {
33  ScreenManager &screen;
34  std::vector<std::string> album_list;
35  std::string artist;
36 
37 public:
38  AlbumListPage(ScreenManager &_screen, WINDOW *_w, Size size)
39  :ListPage(_w, size), screen(_screen) {}
40 
41  template<typename A>
42  void SetArtist(A &&_artist) {
43  artist = std::forward<A>(_artist);
44  AddPendingEvents(~0u);
45  }
46 
47  const std::string &GetArtist() const {
48  return artist;
49  }
50 
51  bool IsShowAll() const {
52  return lw.selected == album_list.size() + 1;
53  }
54 
55  const char *GetSelectedValue() const {
56  return lw.selected >= 1 && lw.selected <= album_list.size()
57  ? album_list[lw.selected - 1].c_str()
58  : nullptr;
59  }
60 
61 private:
62  void LoadAlbumList(struct mpdclient &c);
63  void Reload(struct mpdclient &c);
64 
65 public:
66  /* virtual methods from class Page */
67  void Paint() const override;
68  void Update(struct mpdclient &c, unsigned events) override;
69  bool OnCommand(struct mpdclient &c, command_t cmd) override;
70  const char *GetTitle(char *s, size_t size) const override;
71 
72  /* virtual methods from class ListRenderer */
73  void PaintListItem(WINDOW *w, unsigned i, unsigned y, unsigned width,
74  bool selected) const override;
75 
76  /* virtual methods from class ListText */
77  const char *GetListItemText(char *buffer, size_t size,
78  unsigned i) const override;
79 };
80 
81 #endif
void Paint() const override
Definition: screen.hxx:43
void Update(struct mpdclient &c, unsigned events) override
Definition: ListPage.hxx:29
ListWindow lw
Definition: ListPage.hxx:31
const char * GetSelectedValue() const
Definition: AlbumListPage.hxx:55
Definition: mpdclient.hxx:17
Definition: AlbumListPage.hxx:32
const std::string & GetArtist() const
Definition: AlbumListPage.hxx:47
Definition: ListRenderer.hxx:25
Definition: Size.hxx:26
void AddPendingEvents(unsigned events)
Definition: Page.hxx:68
bool OnCommand(struct mpdclient &c, command_t cmd) override
const char * GetListItemText(char *buffer, size_t size, unsigned i) const override
ScreenManager * screen
AlbumListPage(ScreenManager &_screen, WINDOW *_w, Size size)
Definition: AlbumListPage.hxx:38
Definition: ListText.hxx:25
const char * GetTitle(char *s, size_t size) const override
void SetArtist(A &&_artist)
Definition: AlbumListPage.hxx:42
void PaintListItem(WINDOW *w, unsigned i, unsigned y, unsigned width, bool selected) const override
command_t
Definition: command.hxx:35
bool IsShowAll() const
Definition: AlbumListPage.hxx:51
unsigned selected
Definition: ListWindow.hxx:95