playermanager.h 3.61 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/**
 * Copyright (C) 2004 Scott Wheeler <wheeler@kde.org>
 * Copyright (C) 2007 Matthias Kretz <kretz@kde.org>
 * Copyright (C) 2008 Michael Pyne <mpyne@kde.org>
 *
 * 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) any later
 * version.
 *
 * 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 <http://www.gnu.org/licenses/>.
 */
18

19 20
#ifndef JUK_PLAYERMANAGER_H
#define JUK_PLAYERMANAGER_H
21

22
#include <QObject>
23

24
#include "filehandle.h"
25

26
#include <Phonon/Global>
27
#include <Phonon/Path>
28

29
class PlaylistInterface;
30
class QPixmap;
31

32 33 34 35
namespace Phonon
{
    class AudioOutput;
    class MediaObject;
36
    class MediaSource;
37 38
}

39 40 41 42 43
/**
 * This class serves as a proxy to the Player interface and handles managing
 * the actions from the top-level mainwindow.
 */

44
class PlayerManager : public QObject
45 46 47
{
    Q_OBJECT

48
public:
49 50
    PlayerManager();

51 52
    bool playing() const;
    bool paused() const;
53
    bool muted() const;
54
    float volume() const;
55
    int status() const;
56 57 58 59

    // These two have been part of the prior public DBus interface so they have
    // been retained. You should use the MSecs versions below. These return in units
    // of seconds instead.
Scott Wheeler's avatar
Scott Wheeler committed
60 61
    int totalTime() const;
    int currentTime() const;
62 63 64 65

    int totalTimeMSecs() const;
    int currentTimeMSecs() const;

66
    bool seekable() const;
67
    //int position() const;
68

69 70
    QStringList trackProperties();
    QString trackProperty(const QString &property) const;
Michael Pyne's avatar
Michael Pyne committed
71
    QPixmap trackCover(const QString &size) const;
72

73
    FileHandle playingFile() const;
74 75
    QString playingString() const;

76
    void setPlaylistInterface(PlaylistInterface *interface);
77

Michael Pyne's avatar
Michael Pyne committed
78 79
    QString randomPlayMode() const;

80
public slots:
Scott Wheeler's avatar
Scott Wheeler committed
81
    void play(const FileHandle &file);
82
    void play(const QString &file);
83
    void play(); // start or restart playback
84 85 86
    void pause();
    void stop();
    void setVolume(float volume = 1.0);
Scott Wheeler's avatar
Scott Wheeler committed
87
    void seek(int seekTime);
88
    //void seekPosition(int position);
89 90 91
    void seekForward();
    void seekBack();
    void playPause();
92 93
    void forward();
    void back();
94 95
    void volumeUp();
    void volumeDown();
96 97
    void setMuted(bool m);
    bool mute();
98

99 100 101
    void trackHasChanged(const Phonon::MediaSource &newSource);
    void trackAboutToFinish();

Michael Pyne's avatar
Michael Pyne committed
102 103
    void setRandomPlayMode(const QString &randomMode);

104
signals:
105 106
    void tick(qint64 /* time_msec */);
    void totalTimeChanged(qint64 /* time_msec */);
107 108 109 110
    void mutedChanged(bool muted);
    void volumeChanged(float volume);
    void seeked(int newPos);
    void seekableChanged(bool muted);
111

112 113 114
    void signalPlay();
    void signalPause();
    void signalStop();
115
    void signalItemChanged(const FileHandle &file);
116

117
private:
118
    void setupAudio();
119

120
private slots:
121
    void slotFinished();
122
    void slotLength(qint64);
123
    void slotTick(qint64);
124
    void slotStateChanged(Phonon::State, Phonon::State);
125 126 127
    void slotSeekableChanged(bool);
    void slotMutedChanged(bool);
    void slotVolumeChanged(qreal);
128 129

private:
130
    FileHandle m_file;
131
    PlaylistInterface *m_playlistInterface;
132
    bool m_muted;
133
    bool m_setup;
134 135

    static const int m_pollInterval = 800;
136

137 138
    Phonon::AudioOutput *m_output;
    Phonon::MediaObject *m_media;
139
    Phonon::Path m_audioPath;
140 141 142
};

#endif
143 144

// vim: set et sw=4 tw=0 sta: