File indexing completed on 2024-05-19 04:49:50
0001 /**************************************************************************************** 0002 * Copyright (c) 2008 Nikolaj Hald Nielsen <nhn@kde.org> * 0003 * Copyright (c) 2008 Soren Harward <stharward@gmail.com> * 0004 * Copyright (c) 2010 Nanno Langstraat <langstr@gmail.com> * 0005 * * 0006 * This program is free software; you can redistribute it and/or modify it under * 0007 * the terms of the GNU General Public License as published by the Free Software * 0008 * Foundation; either version 2 of the License, or (at your option) version 3 or * 0009 * any later version accepted by the membership of KDE e.V. (or its successor approved * 0010 * by the membership of KDE e.V.), which shall act as a proxy defined in Section 14 of * 0011 * version 3 of the license. * 0012 * * 0013 * This program is distributed in the hope that it will be useful, but WITHOUT ANY * 0014 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * 0015 * PARTICULAR PURPOSE. See the GNU General Public License for more details. * 0016 * * 0017 * You should have received a copy of the GNU General Public License along with * 0018 * this program. If not, see <http://www.gnu.org/licenses/>. * 0019 ****************************************************************************************/ 0020 0021 #ifndef ALBUMNAVIGATOR_H 0022 #define ALBUMNAVIGATOR_H 0023 0024 #include "NonlinearTrackNavigator.h" 0025 0026 #include "core/meta/forward_declarations.h" 0027 0028 #include <QList> 0029 #include <QSet> 0030 0031 namespace Playlist 0032 { 0033 /** 0034 * Base class that offers some standard services for album-oriented navigators. 0035 */ 0036 class AlbumNavigator : public NonlinearTrackNavigator 0037 { 0038 Q_OBJECT 0039 0040 public: 0041 AlbumNavigator() { } 0042 0043 protected: 0044 //! Overrides from 'NonlinearTrackNavigator' 0045 void notifyItemsInserted( const QSet<quint64> &insertedItems ) override; 0046 void notifyItemsRemoved( const QSet<quint64> &removedItems ) override; 0047 0048 typedef QString AlbumId; // Not Meta::AlbumPtr but QString '->name()'. Reason: Meta::AlbumPtr doesn't work for meta types that use private album pointers. 0049 0050 /** 0051 * The album of an item. Opaque key for bookkeeping. 0052 */ 0053 AlbumId albumForItem( const quint64 &item ); 0054 0055 /** 0056 * Empty notification callback for child classes: new albums have been inserted. 0057 */ 0058 virtual void notifyAlbumsInserted( const QList<AlbumId> &insertedAlbums ) = 0; 0059 0060 /** 0061 * Convenience function: the album of 'currentItem()'. 0062 */ 0063 AlbumId currentAlbum() { return currentItem() ? albumForItem( currentItem() ) : AlbumId(); } 0064 0065 QHash<AlbumId, ItemList> m_itemsPerAlbum; //!< For use by child classes. Maintained automatically. 0066 QList<AlbumId> m_plannedAlbums; //!< For use by child classes. Cleared automatically. 0067 0068 private: 0069 static bool itemLessThan( const quint64 &left, const quint64 &right ); 0070 0071 /** 0072 * Cache the album for each playlist item. The reasons: 0073 * - By the time 'notifyItemsRemoved()' is called, the items are usually 0074 * already gone from the playlist model. 0075 * - Currently we don't get a notification when the item's '->track()->album()' 0076 * changes. We need to do all bookkeeping with the same value that we saw 0077 * during insertion. 0078 */ 0079 QHash<quint64, AlbumId> m_albumForItem; 0080 }; 0081 } 0082 0083 #endif