45e140615ff405aea803c79a24d9c307823bc457
[ncmpc-debian.git] / src / screen_browser.hxx
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 SCREEN_BROWSER_H
21 #define SCREEN_BROWSER_H
22
23 #include "command.hxx"
24 #include "config.h"
25 #include "ncmpc_curses.h"
26 #include "ListPage.hxx"
27
28 struct mpdclient;
29 struct MpdQueue;
30 class ScreenManager;
31 class FileList;
32 struct FileListEntry;
33
34 class FileListPage : public ListPage {
35 protected:
36         ScreenManager &screen;
37
38         FileList *filelist = nullptr;
39         const char *const song_format;
40
41 public:
42         FileListPage(ScreenManager &_screen, WINDOW *_w,
43                      Size size,
44                      const char *_song_format)
45                 :ListPage(_w, size),
46                  screen(_screen),
47                  song_format(_song_format) {}
48
49         ~FileListPage() override;
50
51 protected:
52         gcc_pure
53         FileListEntry *GetSelectedEntry() const;
54
55         gcc_pure
56         const struct mpd_entity *GetSelectedEntity() const;
57
58         gcc_pure
59         const struct mpd_song *GetSelectedSong() const;
60
61         FileListEntry *GetIndex(unsigned i) const;
62
63 private:
64         bool HandleEnter(struct mpdclient &c);
65         bool HandleSelect(struct mpdclient &c);
66         bool HandleAdd(struct mpdclient &c);
67
68         void HandleSelectAll(struct mpdclient &c);
69
70         static void PaintRow(WINDOW *w, unsigned i,
71                              unsigned y, unsigned width,
72                              bool selected, const void *data);
73
74 public:
75         /* virtual methods from class Page */
76         void Paint() const override;
77         bool OnCommand(struct mpdclient &c, command_t cmd) override;
78
79 #ifdef HAVE_GETMOUSE
80         bool OnMouse(struct mpdclient &c, Point p,
81                      mmask_t bstate) override;
82 #endif
83 };
84
85 #ifndef NCMPC_MINI
86
87 void
88 screen_browser_sync_highlights(FileList *fl,
89                                const MpdQueue *playlist);
90
91 #else
92
93 static inline void
94 screen_browser_sync_highlights(gcc_unused FileList *fl,
95                                gcc_unused const MpdQueue *playlist)
96 {
97 }
98
99 #endif
100
101 void
102 screen_browser_paint_directory(WINDOW *w, unsigned width,
103                                bool selected, const char *name);
104
105 #endif