make sure to include boost posix_time where needed
[ncmpcpp.git] / src / media_library.h
blob63ae0348a3821aa5e6cce97c2e0f324b861f3485
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_MEDIA_LIBRARY_H
22 #define NCMPCPP_MEDIA_LIBRARY_H
24 #include <boost/date_time/posix_time/posix_time_types.hpp>
26 #include "interfaces.h"
27 #include "screen.h"
29 struct MediaLibrary: Screen<NC::Window *>, Filterable, HasColumns, HasSongs, Searchable, Tabbable
31 MediaLibrary();
33 virtual void switchTo() OVERRIDE;
34 virtual void resize() OVERRIDE;
36 virtual std::wstring title() OVERRIDE;
37 virtual ScreenType type() OVERRIDE { return ScreenType::MediaLibrary; }
39 virtual void refresh() OVERRIDE;
40 virtual void update() OVERRIDE;
42 virtual int windowTimeout() OVERRIDE;
44 virtual void enterPressed() OVERRIDE;
45 virtual void spacePressed() OVERRIDE;
46 virtual void mouseButtonPressed(MEVENT me) OVERRIDE;
48 virtual bool isMergable() OVERRIDE { return true; }
50 // Filterable implementation
51 virtual bool allowsFiltering() OVERRIDE;
52 virtual std::string currentFilter() OVERRIDE;
53 virtual void applyFilter(const std::string &filter) OVERRIDE;
55 // Searchable implementation
56 virtual bool allowsSearching() OVERRIDE;
57 virtual bool search(const std::string &constraint) OVERRIDE;
58 virtual void nextFound(bool wrap) OVERRIDE;
59 virtual void prevFound(bool wrap) OVERRIDE;
61 // HasSongs implementation
62 virtual ProxySongList proxySongList() OVERRIDE;
64 virtual bool allowsSelection() OVERRIDE;
65 virtual void reverseSelection() OVERRIDE;
66 virtual MPD::SongList getSelectedSongs() OVERRIDE;
68 // HasColumns implementation
69 virtual bool previousColumnAvailable() OVERRIDE;
70 virtual void previousColumn() OVERRIDE;
72 virtual bool nextColumnAvailable() OVERRIDE;
73 virtual void nextColumn() OVERRIDE;
75 // private members
76 void updateTimer();
77 void toggleColumnsMode();
78 int Columns();
79 void LocateSong(const MPD::Song &);
80 ProxySongList songsProxyList();
81 void toggleSortMode();
83 void requestTagsUpdate() { m_tags_update_request = true; }
84 void requestAlbumsUpdate() { m_albums_update_request = true; }
85 void requestSongsUpdate() { m_songs_update_request = true; }
87 struct PrimaryTag
89 PrimaryTag() : m_mtime(0) { }
90 PrimaryTag(std::string tag_, time_t mtime_)
91 : m_tag(std::move(tag_)), m_mtime(mtime_) { }
93 const std::string &tag() const { return m_tag; }
94 time_t mtime() const { return m_mtime; }
96 private:
97 std::string m_tag;
98 time_t m_mtime;
101 struct Album
103 Album(std::string tag_, std::string album_, std::string date_, time_t mtime_)
104 : m_tag(std::move(tag_)), m_album(std::move(album_))
105 , m_date(std::move(date_)), m_mtime(mtime_) { }
107 const std::string &tag() const { return m_tag; }
108 const std::string &album() const { return m_album; }
109 const std::string &date() const { return m_date; }
110 time_t mtime() const { return m_mtime; }
112 private:
113 std::string m_tag;
114 std::string m_album;
115 std::string m_date;
116 time_t m_mtime;
119 struct AlbumEntry
121 AlbumEntry() : m_all_tracks_entry(false), m_album("", "", "", 0) { }
122 AlbumEntry(Album album_) : m_all_tracks_entry(false), m_album(album_) { }
124 const Album &entry() const { return m_album; }
125 bool isAllTracksEntry() const { return m_all_tracks_entry; }
127 static AlbumEntry mkAllTracksEntry(std::string tag) {
128 auto result = AlbumEntry(Album(tag, "", "", 0));
129 result.m_all_tracks_entry = true;
130 return result;
133 private:
134 bool m_all_tracks_entry;
135 Album m_album;
138 NC::Menu<PrimaryTag> Tags;
139 NC::Menu<AlbumEntry> Albums;
140 NC::Menu<MPD::Song> Songs;
142 protected:
143 virtual bool isLockable() OVERRIDE { return true; }
145 private:
146 void AddToPlaylist(bool);
148 bool m_tags_update_request;
149 bool m_albums_update_request;
150 bool m_songs_update_request;
152 boost::posix_time::ptime m_timer;
155 extern MediaLibrary *myLibrary;
157 #endif // NCMPCPP_MEDIA_LIBRARY_H