change version to 0.7.3
[ncmpcpp.git] / src / media_library.h
blobdbe17b37907fffde1a32fcbb787d8ef179ad0470
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 "regex_filter.h"
28 #include "screen.h"
29 #include "song_list.h"
31 struct MediaLibrary: Screen<NC::Window *>, HasColumns, HasSongs, Searchable, Tabbable
33 MediaLibrary();
35 virtual void switchTo() OVERRIDE;
36 virtual void resize() OVERRIDE;
38 virtual std::wstring title() OVERRIDE;
39 virtual ScreenType type() OVERRIDE { return ScreenType::MediaLibrary; }
41 virtual void refresh() OVERRIDE;
42 virtual void update() OVERRIDE;
44 virtual int windowTimeout() OVERRIDE;
46 virtual void mouseButtonPressed(MEVENT me) OVERRIDE;
48 virtual bool isLockable() OVERRIDE { return true; }
49 virtual bool isMergable() OVERRIDE { return true; }
51 // Searchable implementation
52 virtual bool allowsSearching() OVERRIDE;
53 virtual void setSearchConstraint(const std::string &constraint) OVERRIDE;
54 virtual void clearConstraint() OVERRIDE;
55 virtual bool find(SearchDirection direction, bool wrap, bool skip_current) OVERRIDE;
57 // HasSongs implementation
58 virtual bool itemAvailable() OVERRIDE;
59 virtual bool addItemToPlaylist(bool play) OVERRIDE;
60 virtual std::vector<MPD::Song> getSelectedSongs() OVERRIDE;
62 // HasColumns implementation
63 virtual bool previousColumnAvailable() OVERRIDE;
64 virtual void previousColumn() OVERRIDE;
66 virtual bool nextColumnAvailable() OVERRIDE;
67 virtual void nextColumn() OVERRIDE;
69 // private members
70 void updateTimer();
71 void toggleColumnsMode();
72 int Columns();
73 void LocateSong(const MPD::Song &);
74 void toggleSortMode();
76 void requestTagsUpdate() { m_tags_update_request = true; }
77 void requestAlbumsUpdate() { m_albums_update_request = true; }
78 void requestSongsUpdate() { m_songs_update_request = true; }
80 struct PrimaryTag
82 PrimaryTag() : m_mtime(0) { }
83 PrimaryTag(std::string tag_, time_t mtime_)
84 : m_tag(std::move(tag_)), m_mtime(mtime_) { }
86 const std::string &tag() const { return m_tag; }
87 time_t mtime() const { return m_mtime; }
89 private:
90 std::string m_tag;
91 time_t m_mtime;
94 struct Album
96 Album(std::string tag_, std::string album_, std::string date_, time_t mtime_)
97 : m_tag(std::move(tag_)), m_album(std::move(album_))
98 , m_date(std::move(date_)), m_mtime(mtime_) { }
100 const std::string &tag() const { return m_tag; }
101 const std::string &album() const { return m_album; }
102 const std::string &date() const { return m_date; }
103 time_t mtime() const { return m_mtime; }
105 private:
106 std::string m_tag;
107 std::string m_album;
108 std::string m_date;
109 time_t m_mtime;
112 struct AlbumEntry
114 AlbumEntry() : m_all_tracks_entry(false), m_album("", "", "", 0) { }
115 AlbumEntry(Album album_) : m_all_tracks_entry(false), m_album(album_) { }
117 const Album &entry() const { return m_album; }
118 bool isAllTracksEntry() const { return m_all_tracks_entry; }
120 static AlbumEntry mkAllTracksEntry(std::string tag) {
121 auto result = AlbumEntry(Album(tag, "", "", 0));
122 result.m_all_tracks_entry = true;
123 return result;
126 private:
127 bool m_all_tracks_entry;
128 Album m_album;
131 NC::Menu<PrimaryTag> Tags;
132 NC::Menu<AlbumEntry> Albums;
133 SongMenu Songs;
135 private:
136 bool m_tags_update_request;
137 bool m_albums_update_request;
138 bool m_songs_update_request;
140 boost::posix_time::ptime m_timer;
142 const int m_window_timeout;
143 const boost::posix_time::time_duration m_fetching_delay;
145 Regex::Filter<PrimaryTag> m_tags_search_predicate;
146 Regex::ItemFilter<AlbumEntry> m_albums_search_predicate;
147 Regex::Filter<MPD::Song> m_songs_search_predicate;
151 extern MediaLibrary *myLibrary;
153 #endif // NCMPCPP_MEDIA_LIBRARY_H