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

0001 /****************************************************************************************
0002  * Copyright (c) 2008-2012 Soren Harward <stharward@gmail.com>                          *
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) any later           *
0007  * version.                                                                             *
0008  *                                                                                      *
0009  * This program is distributed in the hope that it will be useful, but WITHOUT ANY      *
0010  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A      *
0011  * PARTICULAR PURPOSE. See the GNU General Public License for more details.             *
0012  *                                                                                      *
0013  * You should have received a copy of the GNU General Public License along with         *
0014  * this program.  If not, see <http://www.gnu.org/licenses/>.                           *
0015  ****************************************************************************************/
0016 
0017 #ifndef APG_CHECKPOINT_CONSTRAINT
0018 #define APG_CHECKPOINT_CONSTRAINT
0019 
0020 #include "ui_CheckpointEditWidget.h"
0021 
0022 #include "playlistgenerator/Constraint.h"
0023 
0024 #include "core/meta/forward_declarations.h"
0025 
0026 #include <QPointer>
0027 #include <QString>
0028 
0029 class ConstraintFactoryEntry;
0030 class QWidget;
0031 
0032 namespace ConstraintTypes {
0033 
0034     /* This constraint sets a "checkpoint": a specific track that will be
0035      * played at a specific time in the playlist */
0036 
0037     enum CheckpointType { CheckpointTrack, CheckpointAlbum, CheckpointArtist };
0038 
0039     class Checkpoint : public Constraint {
0040         Q_OBJECT
0041 
0042         public:
0043             static Constraint* createFromXml(QDomElement&, ConstraintNode*);
0044             static Constraint* createNew(ConstraintNode*);
0045             static ConstraintFactoryEntry* registerMe();
0046 
0047             QWidget* editWidget() const override;
0048             void toXml(QDomDocument&, QDomElement&) const override;
0049 
0050             QString getName() const override;
0051 
0052             double satisfaction( const Meta::TrackList& ) const override;
0053             quint32 suggestPlaylistSize() const override;
0054 
0055         private Q_SLOTS:
0056             void setPosition( const int );
0057             void setStrictness( const int );
0058             void setCheckpoint( const Meta::DataPtr& );
0059 
0060         private:
0061             /* support classes */
0062             class AbstractMatcher;
0063             class TrackMatcher;
0064             class ArtistMatcher;
0065             class AlbumMatcher;
0066 
0067             Checkpoint( QDomElement&, ConstraintNode* );
0068             explicit Checkpoint( ConstraintNode* );
0069             ~Checkpoint() override;
0070 
0071             // constraint parameters
0072             qint64 m_position;
0073             double m_strictness;
0074             Meta::DataPtr m_checkpointObject;
0075             CheckpointType m_checkpointType;
0076 
0077             // objects from the support classes
0078             QPointer<AbstractMatcher> m_matcher;
0079 
0080             // support functions
0081             double penalty( const qint64 ) const;
0082     };
0083 
0084     // ABC for Checkpoint handlers
0085     class Checkpoint::AbstractMatcher : public QObject {
0086         Q_OBJECT
0087         
0088         public:
0089             AbstractMatcher() {}
0090             ~AbstractMatcher() override {}
0091 
0092             virtual QList<int> find( const Meta::TrackList& ) const = 0;
0093             virtual bool match( const Meta::TrackPtr& ) const = 0;
0094     };
0095 
0096     // Handles Checkpoints for a specific track
0097     class Checkpoint::TrackMatcher : public AbstractMatcher {
0098         public:
0099             TrackMatcher( const Meta::TrackPtr& );
0100             ~TrackMatcher() override;
0101 
0102             QList<int> find( const Meta::TrackList& ) const override;
0103             bool match( const Meta::TrackPtr& ) const override;
0104 
0105         private:
0106             Meta::TrackPtr m_trackToMatch;
0107     };
0108 
0109     // Handles Checkpoints for an album (any track on this album satisfies the checkpoint)
0110     class Checkpoint::AlbumMatcher : public AbstractMatcher {
0111         public:
0112             AlbumMatcher( const Meta::AlbumPtr& );
0113             ~AlbumMatcher() override;
0114 
0115             QList<int> find( const Meta::TrackList& ) const override;
0116             bool match( const Meta::TrackPtr& ) const override;
0117 
0118         private:
0119             Meta::AlbumPtr m_albumToMatch;
0120     };
0121 
0122     // Handles Checkpoints for an artist (any track by this artist satisfies the checkpoint)
0123     class Checkpoint::ArtistMatcher : public AbstractMatcher {
0124         public:
0125             ArtistMatcher( const Meta::ArtistPtr& );
0126             ~ArtistMatcher() override;
0127 
0128             QList<int> find( const Meta::TrackList& ) const override;
0129             bool match( const Meta::TrackPtr& ) const override;
0130 
0131         private:
0132             Meta::ArtistPtr m_artistToMatch;
0133     };
0134 
0135     class CheckpointEditWidget : public QWidget {
0136         Q_OBJECT
0137 
0138         public:
0139             CheckpointEditWidget( const qint64, const int, const Meta::DataPtr& );
0140 
0141         Q_SIGNALS:
0142             void updated();
0143             void nameChanged( const QString& );
0144             void positionChanged( const int );
0145             void strictnessChanged( const int );
0146             void checkpointChanged( const Meta::DataPtr& );
0147 
0148         private Q_SLOTS:
0149             void on_timeEdit_Position_timeChanged( const QTime& );
0150             void on_slider_Strictness_valueChanged( const int );
0151             void on_trackSelector_selectionChanged( const Meta::DataPtr& );
0152 
0153         private:
0154             Ui::CheckpointEditWidget ui;
0155     };
0156 } // namespace ConstraintTypes
0157 
0158 #endif