File indexing completed on 2023-05-30 11:30:46
0001 /** 0002 * Copyright (C) 2003-2004 Scott Wheeler <wheeler@kde.org> 0003 * 0004 * This program is free software; you can redistribute it and/or modify it under 0005 * the terms of the GNU General Public License as published by the Free Software 0006 * Foundation; either version 2 of the License, or (at your option) any later 0007 * version. 0008 * 0009 * This program is distributed in the hope that it will be useful, but WITHOUT ANY 0010 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 0011 * PARTICULAR PURPOSE. See the GNU General Public License for more details. 0012 * 0013 * You should have received a copy of the GNU General Public License along with 0014 * this program. If not, see <http://www.gnu.org/licenses/>. 0015 */ 0016 0017 #ifndef DYNAMICPLAYLIST_H 0018 #define DYNAMICPLAYLIST_H 0019 0020 #include "playlist.h" 0021 0022 #include <QVector> 0023 #include <QPointer> 0024 0025 class PlaylistDirtyObserver; 0026 0027 using GuardedPlaylist = QPointer<Playlist>; 0028 0029 /** 0030 * A Playlist that is a union of other playlists that is created dynamically. 0031 * Normally seen when you select multiple playlists at once (which is, or was, 0032 * something you can do). 0033 */ 0034 0035 class DynamicPlaylist : public Playlist 0036 { 0037 Q_OBJECT 0038 public: 0039 /** 0040 * Creates a dynamic playlist based on lists. 0041 */ 0042 DynamicPlaylist(const PlaylistList &lists, 0043 PlaylistCollection *collection, 0044 const QString &name = QString(), 0045 const QString &iconName = "audio-midi", 0046 bool setupPlaylist = true, 0047 bool synchronizePlaying = false); 0048 0049 virtual ~DynamicPlaylist(); 0050 0051 virtual bool canReload() const override { return false; } 0052 0053 void setPlaylists(const PlaylistList &playlists); 0054 0055 public slots: 0056 /** 0057 * Reimplemented so that it will reload all of the playlists that are 0058 * associated with the dynamic list. 0059 */ 0060 virtual void slotReload() override; 0061 void slotSetDirty() { m_dirty = true; } 0062 0063 /** 0064 * This is called when lowering the widget from the widget stack so that 0065 * it can synchronize the playing item with the one that playlist it was 0066 * create from. 0067 */ 0068 void lower(QWidget *top = 0); 0069 0070 protected: 0071 /** 0072 * Returns true if this list's items need to be updated the next time it's 0073 * shown. 0074 */ 0075 bool dirty() const { return m_dirty; } 0076 0077 /** 0078 * Return a list of the items in this playlist. For example in a search 0079 * list this should return only the matched items. By default it returns 0080 * all of the items in the playlists associated with this dynamic list. 0081 */ 0082 virtual PlaylistItemList items() override; 0083 0084 /** 0085 * Reimplemented from QWidget. Here it updates the list of items (when 0086 * appropriate) as the widget is shown. 0087 */ 0088 virtual void showEvent(QShowEvent *e) override; 0089 0090 virtual void paintEvent(QPaintEvent *e) override; 0091 0092 /** 0093 * Updates the items (unconditionally). This should be reimplemented in 0094 * subclasses to refresh the items in the dynamic list (i.e. running a 0095 * search). 0096 */ 0097 virtual void updateItems(); 0098 0099 bool synchronizePlaying() const; 0100 0101 private: 0102 /** 0103 * Checks to see if the current list of items is "dirty" and if so updates 0104 * this dynamic playlist's items to be in sync with the lists that it is a 0105 * wrapper around. 0106 */ 0107 void checkUpdateItems(); 0108 0109 private: 0110 PlaylistItemList m_siblings; 0111 QVector<GuardedPlaylist> m_playlists; 0112 bool m_dirty; 0113 bool m_synchronizePlaying; 0114 }; 0115 0116 #endif 0117 0118 // vim: set et sw=4 tw=0 sta: