/**************************************************************************************** * Copyright (c) 2008 Nikolaj Hald Nielsen * * Copyright (c) 2008 Soren Harward * * Copyright (c) 2010 Nanno Langstraat * * * * This program is free software; you can redistribute it and/or modify it under * * the terms of the GNU General Public License as published by the Free Software * * Foundation; either version 2 of the License, or (at your option) version 3 or * * any later version accepted by the membership of KDE e.V. (or its successor approved * * by the membership of KDE e.V.), which shall act as a proxy defined in Section 14 of * * version 3 of the license. * * * * This program is distributed in the hope that it will be useful, but WITHOUT ANY * * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * * PARTICULAR PURPOSE. See the GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License along with * * this program. If not, see . * ****************************************************************************************/ #ifndef ALBUMNAVIGATOR_H #define ALBUMNAVIGATOR_H #include "NonlinearTrackNavigator.h" #include "core/meta/forward_declarations.h" #include #include namespace Playlist { /** * Base class that offers some standard services for album-oriented navigators. */ class AlbumNavigator : public NonlinearTrackNavigator { Q_OBJECT public: AlbumNavigator() { } protected: //! Overrides from 'NonlinearTrackNavigator' void notifyItemsInserted( const QSet &insertedItems ) override; void notifyItemsRemoved( const QSet &removedItems ) override; typedef QString AlbumId; // Not Meta::AlbumPtr but QString '->name()'. Reason: Meta::AlbumPtr doesn't work for meta types that use private album pointers. /** * The album of an item. Opaque key for bookkeeping. */ AlbumId albumForItem( const quint64 &item ); /** * Empty notification callback for child classes: new albums have been inserted. */ virtual void notifyAlbumsInserted( const QList &insertedAlbums ) = 0; /** * Convenience function: the album of 'currentItem()'. */ AlbumId currentAlbum() { return currentItem() ? albumForItem( currentItem() ) : AlbumId(); } QHash m_itemsPerAlbum; //!< For use by child classes. Maintained automatically. QList m_plannedAlbums; //!< For use by child classes. Cleared automatically. private: static bool itemLessThan( const quint64 &left, const quint64 &right ); /** * Cache the album for each playlist item. The reasons: * - By the time 'notifyItemsRemoved()' is called, the items are usually * already gone from the playlist model. * - Currently we don't get a notification when the item's '->track()->album()' * changes. We need to do all bookkeeping with the same value that we saw * during insertion. */ QHash m_albumForItem; }; } #endif