Debian Codegraph @

src/playlist/navigators/AlbumNavigator.h

raw
1 /****************************************************************************************
2 * Copyright (c) 2008 Nikolaj Hald Nielsen <[email protected]> *
3 * Copyright (c) 2008 Soren Harward <[email protected]> *
4 * Copyright (c) 2010 Nanno Langstraat <[email protected]> *
5 * *
6 * This program is free software; you can redistribute it and/or modify it under *
7 * the terms of the GNU General Public License as published by the Free Software *
8 * Foundation; either version 2 of the License, or (at your option) version 3 or *
9 * any later version accepted by the membership of KDE e.V. (or its successor approved *
10 * by the membership of KDE e.V.), which shall act as a proxy defined in Section 14 of *
11 * version 3 of the license. *
12 * *
13 * This program is distributed in the hope that it will be useful, but WITHOUT ANY *
14 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A *
15 * PARTICULAR PURPOSE. See the GNU General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU General Public License along with *
18 * this program. If not, see <http://www.gnu.org/licenses/>. *
19 ****************************************************************************************/
20
21 #ifndef ALBUMNAVIGATOR_H
22 #define ALBUMNAVIGATOR_H
23
24 #include "NonlinearTrackNavigator.h"
25
26 #include "core/meta/forward_declarations.h"
27
28 #include <QList>
29 #include <QSet>
30
31 namespace Playlist
32 {
33 /**
34 * Base class that offers some standard services for album-oriented navigators.
35 */
36 class AlbumNavigator : public NonlinearTrackNavigator
37 {
38 Q_OBJECT
39
40 public:
41 AlbumNavigator() { }
42
43 protected:
44 //! Overrides from 'NonlinearTrackNavigator'
45 void notifyItemsInserted( const QSet<quint64> &insertedItems ) override;
46 void notifyItemsRemoved( const QSet<quint64> &removedItems ) override;
47
48 typedef QString AlbumId; // Not Meta::AlbumPtr but QString '->name()'. Reason: Meta::AlbumPtr doesn't work for meta types that use private album pointers.
49
50 /**
51 * The album of an item. Opaque key for bookkeeping.
52 */
53 AlbumId albumForItem( const quint64 &item );
54
55 /**
56 * Empty notification callback for child classes: new albums have been inserted.
57 */
58 virtual void notifyAlbumsInserted( const QList<AlbumId> &insertedAlbums ) = 0;
59
60 /**
61 * Convenience function: the album of 'currentItem()'.
62 */
63 AlbumId currentAlbum() { return currentItem() ? albumForItem( currentItem() ) : AlbumId(); }
64
65 QHash<AlbumId, ItemList> m_itemsPerAlbum; //!< For use by child classes. Maintained automatically.
66 QList<AlbumId> m_plannedAlbums; //!< For use by child classes. Cleared automatically.
67
68 private:
69 static bool itemLessThan( const quint64 &left, const quint64 &right );
70
71 /**
72 * Cache the album for each playlist item. The reasons:
73 * - By the time 'notifyItemsRemoved()' is called, the items are usually
74 * already gone from the playlist model.
75 * - Currently we don't get a notification when the item's '->track()->album()'
76 * changes. We need to do all bookkeeping with the same value that we saw
77 * during insertion.
78 */
79 QHash<quint64, AlbumId> m_albumForItem;
80 };
81 }
82
83 #endif