File indexing completed on 2024-05-19 04:49:41

0001 /****************************************************************************************
0002  * Copyright (c) 2008 Daniel Jones <danielcjones@gmail.com>                             *
0003  * Copyright (c) 2009 Leo Franchi <lfranchi@kde.org>                                    *
0004  * Copyright (c) 2010, 2011 Ralf Engels <ralf-engels@gmx.de>                            *
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 AMAROK_IFELSEBIAS_H
0022 #define AMAROK_IFELSEBIAS_H
0023 
0024 #include "dynamic/Bias.h"
0025 #include "dynamic/BiasFactory.h"
0026 
0027 namespace Dynamic
0028 {
0029 
0030     /** The if-else bias works like an or bias.
0031         If the first sub-bias doesn't return a valid result it will go to the second
0032         sub-bias and so on.
0033     */
0034     class IfElseBias : public OrBias
0035     {
0036         Q_OBJECT
0037 
0038         public:
0039             IfElseBias();
0040 
0041             static QString sName();
0042             QString name() const override;
0043             QString toString() const override;
0044 
0045             void paintOperator( QPainter* painter, const QRect &rect, Dynamic::AbstractBias* bias ) override;
0046 
0047             TrackSet matchingTracks( const Meta::TrackList& playlist,
0048                                              int contextCount, int finalCount,
0049                                              const TrackCollectionPtr &universe ) const override;
0050 
0051             void resultReceived( const Dynamic::TrackSet &tracks ) override;
0052 
0053         private:
0054             /** Removes duplicate tracks from m_tracks
0055                 Removes duplicate tracks (depending on m_position, m_playlist and
0056                 AmarokConfig::dynamicDuplicates()) from m_tracks
0057             */
0058             void removeDuplicate() const;
0059 
0060             // buffered by matchingTracks
0061             mutable Meta::TrackList m_playlist;
0062             mutable int m_contextCount;
0063             mutable int m_finalCount;
0064             mutable Dynamic::TrackCollectionPtr m_universe;
0065 
0066             Q_DISABLE_COPY(IfElseBias)
0067     };
0068 
0069 
0070     class AMAROK_EXPORT IfElseBiasFactory : public Dynamic::AbstractBiasFactory
0071     {
0072         public:
0073             QString i18nName() const override;
0074             QString name() const override;
0075             QString i18nDescription() const override;
0076             BiasPtr createBias() override;
0077     };
0078 
0079 }
0080 
0081 
0082 #endif
0083