Sayonara Player
AbstractLibrary.h
1 /* AbstractLibrary.h */
2 
3 /* Copyright (C) 2011-2017 Lucio Carreras
4  *
5  * This file is part of sayonara player
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11 
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16 
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 #ifndef ABSTRACTLIBRARY_H
22 #define ABSTRACTLIBRARY_H
23 
24 
25 #include "Utils/Library/LibraryNamespaces.h"
26 #include "Utils/Library/Filter.h"
27 #include "Utils/Settings/SayonaraClass.h"
28 #include "Utils/Pimpl.h"
29 #include "Utils/Set.h"
30 
31 #include "Utils/MetaData/Artist.h"
32 #include "Utils/MetaData/Album.h"
33 #include "Utils/MetaData/MetaDataList.h"
34 
35 #include "Utils/Library/Sorting.h"
36 
37 #include <QFile>
38 
39 #define prepare_tracks_for_playlist_files static_cast<void (AbstractLibrary::*) (const QStringList&)>(&AbstractLibrary::psl_prepare_tracks_for_playlist)
40 #define prepare_tracks_for_playlist_idxs static_cast<void (AbstractLibrary::*) (const IdxList&)>(&AbstractLibrary::psl_prepare_tracks_for_playlist)
41 
42 namespace Tagging
43 {
44  class Editor;
45 }
46 
48  public QObject,
49  public SayonaraClass
50 {
51  Q_OBJECT
52  PIMPL(AbstractLibrary)
53 
54 public:
55 
56  explicit AbstractLibrary(QObject *parent=nullptr);
57  virtual ~AbstractLibrary();
58 
59  Library::Sortings sortorder() const;
60  Library::Filter filter() const;
61  // calls fetch_by_filter and emits
62  void change_filter(Library::Filter, bool force=false);
63 
64  const MetaDataList& tracks() const;
65  const AlbumList& albums() const;
66  const ArtistList& artists() const;
67  const MetaDataList& current_tracks() const;
68 
69  const SP::Set<TrackID>& selected_tracks() const;
70  const SP::Set<AlbumId>& selected_albums() const;
71  const SP::Set<ArtistId>& selected_artists() const;
72 
73 signals:
74  void sig_track_mime_data_available();
75  void sig_all_tracks_loaded ();
76  void sig_all_albums_loaded();
77  void sig_all_artists_loaded();
78 
79  void sig_reloading_library(const QString& message, int progress);
80  void sig_reloading_library_finished();
81 
82  void sig_delete_answer(QString);
83  void sig_import_dialog_requested();
84 
85 
86 public slots:
87 
88  virtual void load();
89  bool is_loaded() const;
90 
91  virtual void reload_library(bool clear_first, Library::ReloadQuality quality)=0;
92 
93  /* Clears all filters and searchstrings and fetches everything again */
94  virtual void refetch();
95 
96 
97  /* refetches everything from database as it is, keeping selected elements,
98  the user won't recognize anything at all */
99  virtual void refresh();
100 
101 
102  /* selection changed */
103  virtual void selected_artists_changed(const IndexSet& indexes);
104  virtual void selected_albums_changed(const IndexSet& indexes);
105  virtual void selected_tracks_changed(const IndexSet& indexes);
106 
107  // Those two functions are identical (1) calls (2)
108  virtual void prepare_current_tracks_for_playlist(bool new_playlist);
109  virtual void prepare_fetched_tracks_for_playlist(bool new_playlist);
110  void prepare_tracks_for_playlist(const QStringList& file_paths, bool new_playlist);
111 
112 
113  /* append tracks after current played track in playlist */
114  virtual void play_next_fetched_tracks();
115  virtual void play_next_current_tracks();
116 
117 
118  /* append tracks after last track in playlist */
119  virtual void append_fetched_tracks();
120  virtual void append_current_tracks();
121 
122  /* triggered by tagedit */
123  virtual void metadata_id3_changed(const MetaDataList&, const MetaDataList&);
124 
125  /* a searchfilter has been entered, nothing is emitted */
126  virtual void fetch_by_filter(Library::Filter filter, bool force);
127  virtual void fetch_tracks_by_paths(const QStringList& paths);
128 
129  virtual void delete_tracks(const MetaDataList& v_md, Library::TrackDeletionMode mode)=0;
130  virtual void delete_tracks_by_idx(const IndexSet& indexes, Library::TrackDeletionMode mode);
131 
132  virtual void delete_fetched_tracks(Library::TrackDeletionMode mode);
133  virtual void delete_current_tracks(Library::TrackDeletionMode mode);
134  virtual void delete_all_tracks();
135 
136  virtual void insert_tracks(const MetaDataList& v_md);
137  virtual void import_files(const QStringList& files);
138 
139  /* write new rating to database */
140  virtual void change_track_rating(int idx, int rating);
141  virtual void change_album_rating(int idx, int rating);
142 
143  virtual void change_track_sortorder(Library::SortOrder s);
144  virtual void change_album_sortorder(Library::SortOrder s);
145  virtual void change_artist_sortorder(Library::SortOrder s);
146 
147  virtual void add_genre(const IdSet ids, const Genre& genre);
148  virtual void delete_genre(const Genre& genre);
149  virtual void rename_genre(const Genre& genre, const Genre& new_genre);
150 
151  /* Check for current selected artist if out of date and
152  * fetch new data */
153  virtual void refresh_artist()=0;
154  virtual void refresh_albums()=0;
155  virtual void refresh_tracks()=0;
156 
157 protected:
158  /* Emit 3 signals with shown artists, shown album, shown tracks */
159  virtual void emit_stuff();
160 
161  virtual void get_all_artists(ArtistList& artists)=0;
162  virtual void get_all_artists_by_searchstring(Library::Filter filter, ArtistList& artists)=0;
163 
164  virtual void get_all_albums(AlbumList& albums)=0;
165  virtual void get_all_albums_by_artist(IdList artist_ids, AlbumList& albums, Library::Filter filter)=0;
166  virtual void get_all_albums_by_searchstring(Library::Filter filter, AlbumList& albums)=0;
167 
168  virtual void get_all_tracks(MetaDataList& v_md)=0;
169  virtual void get_all_tracks(const QStringList& paths, MetaDataList& v_md)=0;
170  virtual void get_all_tracks_by_artist(IdList artist_ids, MetaDataList& v_md, Library::Filter filter)=0;
171  virtual void get_all_tracks_by_album(IdList album_ids, MetaDataList& v_md, Library::Filter filter)=0;
172  virtual void get_all_tracks_by_searchstring(Library::Filter filter, MetaDataList& v_md)=0;
173 
174  virtual void get_album_by_id(int album_id, Album& album)=0;
175  virtual void get_artist_by_id(int artist_id, Artist& artist)=0;
176 
177  virtual void update_track(const MetaData& md)=0;
178  virtual void update_tracks(const MetaDataList& v_md);
179  virtual void update_album(const Album& album)=0;
180 
181  Tagging::Editor* tag_edit();
182 
183 
184  MetaDataList _tracks;
185  AlbumList _albums;
186  ArtistList _artists;
187 
188 
189 private:
190 
191  void tag_edit_commit();
192  void set_playlist_action_after_double_click();
193 
194  void change_track_selection(const IndexSet& indexes);
195  void change_artist_selection(const IndexSet& indexes);
196  void change_album_selection(const IndexSet& indexes);
197 };
198 
199 #endif // ABSTRACTLIBRARY_H
TrackDeletionMode
The TrackDeletionMode enum.
Definition: LibraryNamespaces.h:35
The SayonaraClass class provides access to Settings and notifications.
Definition: SayonaraClass.h:29
ReloadQuality
The ReloadQuality enum.
Definition: LibraryNamespaces.h:46
The Sortings class.
Definition: Sorting.h:33
The MetaData class.
Definition: MetaData.h:48
Definition: AbstractLibrary.h:47
The Filter class.
Definition: Filter.h:44
The MetaDataList class.
Definition: MetaDataList.h:38
The GUI_TagEdit class.
Definition: AbstractLibrary.h:42
The AlbumList class.
Definition: Album.h:85
ArtistList.
Definition: Artist.h:69
Definition: Genre.h:27
The Album class.
Definition: Album.h:38
The Artist class.
Definition: Artist.h:35
A set structure. Inherited from std::set with some useful methods. For integer and String this set is...
Definition: AbstractPlaylist.h:36
The TagEdit class Metadata has to be added using the set_metadata(const MetaDataList&) method...
Definition: Editor.h:44