File indexing completed on 2024-05-05 04:48:36

0001 /****************************************************************************************
0002  * Copyright (c) 2013 Matěj Laitl <matej@laitl.cz>                                      *
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 DELAYEDDOERS_H
0018 #define DELAYEDDOERS_H
0019 
0020 #include "amarok_export.h"
0021 
0022 #include <phonon/Global>
0023 
0024 #include <QObject>
0025 #include <QSet>
0026 
0027 namespace Phonon {
0028     class MediaObject;
0029     class MediaController;
0030 }
0031 
0032 /**
0033  * Abstract base helper class for helpers that do something with Phonon objects once
0034  * MediaObject transitions to appropriate state. Then it auto-deletes itself.
0035  */
0036 class AMAROK_EXPORT DelayedDoer : public QObject
0037 {
0038     Q_OBJECT
0039 
0040     public:
0041         explicit DelayedDoer( Phonon::MediaObject *mediaObject,
0042                               const QSet<Phonon::State> &applicableStates );
0043 
0044     protected:
0045         /**
0046          * This method gets called when MediaObject transitions to the right state.
0047          */
0048         virtual void performAction() = 0;
0049 
0050     private Q_SLOTS:
0051         void slotStateChanged( Phonon::State newState );
0052 
0053     protected:
0054         Phonon::MediaObject *m_mediaObject;
0055 
0056     private:
0057         QSet<Phonon::State> m_applicableStates;
0058 };
0059 
0060 /**
0061  * Helper class that calls seek() followed by play() on Phonon::MediaObject after it
0062  * emits stateChanged() with suitable new state and then auto-destructs itself.
0063  */
0064 class AMAROK_EXPORT DelayedSeeker : public DelayedDoer
0065 {
0066     Q_OBJECT
0067 
0068     public:
0069         DelayedSeeker( Phonon::MediaObject *mediaObject, qint64 seekTo, bool startPaused );
0070 
0071     Q_SIGNALS:
0072         void trackPositionChanged( qint64 position, bool userSeek );
0073 
0074     protected:
0075         void performAction() override;
0076 
0077         qint64 m_seekTo;
0078         bool m_startPaused;
0079 };
0080 
0081 class AMAROK_EXPORT DelayedTrackChanger : public DelayedSeeker
0082 {
0083     Q_OBJECT
0084 
0085     public:
0086         explicit DelayedTrackChanger( Phonon::MediaObject *mediaObject,
0087                                       Phonon::MediaController *mediaController,
0088                                       int trackNumber, qint64 seekTo, bool startPaused );
0089 
0090     protected:
0091         void performAction() override;
0092 
0093     private:
0094         Phonon::MediaController *m_mediaController;
0095         int m_trackNumber;
0096 };
0097 
0098 #endif // DELAYEDDOERS_H