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

0001 /****************************************************************************************
0002  * Copyright (c) 2011 Ralf Engels <ralf-engels@gmx.de>                                  *
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) version 3 or        *
0007  * any later version accepted by the membership of KDE e.V. (or its successor approved  *
0008  * by the membership of KDE e.V.), which shall act as a proxy defined in Section 14 of  *
0009  * version 3 of the license.                                                            *
0010  *                                                                                      *
0011  * This program is distributed in the hope that it will be useful, but WITHOUT ANY      *
0012  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A      *
0013  * PARTICULAR PURPOSE. See the GNU General Public License for more details.             *
0014  *                                                                                      *
0015  * You should have received a copy of the GNU General Public License along with         *
0016  * this program.  If not, see <http://www.gnu.org/licenses/>.                           *
0017  ****************************************************************************************/
0018 
0019 #ifndef AMAROK_QUIZPLAY_BIAS_H
0020 #define AMAROK_QUIZPLAY_BIAS_H
0021 
0022 #include "dynamic/BiasFactory.h"
0023 #include "dynamic/biases/TagMatchBias.h"
0024 #include "widgets/MetaQueryWidget.h"
0025 
0026 namespace Dynamic
0027 {
0028     /** This bias will pick tracks that start with a character that the last track ended with. */
0029     class QuizPlayBias : public SimpleMatchBias
0030     {
0031         Q_OBJECT
0032 
0033         public:
0034             enum FollowType
0035             {
0036                 TitleToTitle,
0037                 ArtistToArtist,
0038                 AlbumToAlbum
0039             };
0040 
0041             QuizPlayBias();
0042 
0043             void fromXml( QXmlStreamReader *reader ) override;
0044             void toXml( QXmlStreamWriter *writer ) const override;
0045 
0046             static QString sName();
0047             QString name() const override;
0048             QString toString() const override;
0049 
0050             QWidget* widget( QWidget* parent = nullptr ) override;
0051 
0052             TrackSet matchingTracks( const Meta::TrackList& playlist,
0053                                              int contextCount, int finalCount,
0054                                              const TrackCollectionPtr &universe ) const override;
0055 
0056             bool trackMatches( int position,
0057                                        const Meta::TrackList& playlist,
0058                                        int contextCount ) const override;
0059 
0060             FollowType follow() const;
0061             void setFollow( FollowType value );
0062 
0063         public Q_SLOTS:
0064             void updateFinished() override;
0065             void invalidate() override;
0066 
0067         protected Q_SLOTS:
0068             void selectionChanged( int );
0069             void newQuery() override;
0070 
0071         protected:
0072             /** A smart function to compute the last character in the string.
0073                 It ignores braces and CD texts. */
0074             static QChar lastChar( const QString &str );
0075             static QString nameForFollow( FollowType match );
0076             static FollowType followForName( const QString &name );
0077 
0078             FollowType m_follow;
0079 
0080             mutable QChar m_currentCharacter;
0081             mutable QHash< QChar, TrackSet > m_characterTrackMap;
0082 
0083         private:
0084             Q_DISABLE_COPY(QuizPlayBias)
0085     };
0086 
0087 
0088     class AMAROK_EXPORT QuizPlayBiasFactory : public Dynamic::AbstractBiasFactory
0089     {
0090         public:
0091             QString i18nName() const override;
0092             QString name() const override;
0093             QString i18nDescription() const override;
0094             BiasPtr createBias() override;
0095     };
0096 
0097 }
0098 
0099 #endif
0100