Initial commit. corresponds to 1.0-1 release
[flashstrobe] / src / musicplayer.h
1 /*
2   Copyright (C) 2010 by Juan Carlos Torres <jucato@kdemail.net>
3
4   This program is free software; you can redistribute it and/or
5   modify it under the terms of the GNU General Public License as
6   published by the Free Software Foundation; either version 2 of
7   the License or (at your option) version 3 or any later version
8   accepted by the membership of KDE e.V. (or its successor appro-
9   ved by the membership of KDE e.V.), which shall act as a proxy
10   defined in Section 14 of version 3 of the license.
11
12   This program is distributed in the hope that it will be useful,
13   but WITHOUT ANY WARRANTY; without even the implied warranty of
14   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15   GNU General Public License for more details.
16
17   You should have received a copy of the GNU General Public License
18   along with this program. If not, see http://www.gnu.org/licenses/.
19 */
20
21
22 #ifndef MUSICPLAYER_H
23 #define MUSICPLAYER_H
24
25 #include <QWidget>
26 #include <QIcon>
27
28 class QPushButton;
29 class QIcon;
30 class QLineEdit;
31
32 namespace Phonon
33 {
34     class MediaObject;
35     class AudioOutput;
36     class VolumeSlider;
37 }
38
39 /**
40  * @brief A simple Phonon-based music player widget
41  *
42  * This class implements a very simple widget for playing music
43  * using Phonon. Features include opening a file, playing/pausing,
44  * rewinding, and adjusting the volume.
45  */
46 class MusicPlayer : public QWidget
47 {
48     Q_OBJECT
49
50     public:
51         MusicPlayer(QWidget* parent = 0, Qt::WindowFlags flags = 0);
52         virtual ~MusicPlayer();
53
54         /**
55          * Returns the current volume level.
56          *
57          * @return @c qreal Volume level, between 0 and 1.0
58          */
59         qreal volume() const;
60
61     public slots:
62         /**
63          * Calls a QFileDialog for opening a file, initially
64          * from the platform's Music directory.
65          */
66         void openFile();
67
68         /**
69          * Plays or pauses the file currently contained in the
70          * selection. Also updates the player buttons to the
71          * appropriate state. For example, the Play button
72          * displays a pause icon if the file is currently playing,
73          * and a play icon if the file is paused.
74          *
75          * @param checked Determines whether to play (@c true) or
76          *                pause (@false) the file
77          */
78         void playOrPause(bool checked);
79
80         /**
81          * Rewinds the current audio file to teh beginning.
82          */
83         void rewind();
84
85         /**
86          * Updates the state of the controls in the player depending on
87          * the state of the line edit indicating the audio file to play.
88          * If the line edit is not empty, the controls are enabled. Otherwise
89          * they are disabled.
90          *
91          * @param filename A string containing the contents of the line edit
92          */
93         void enableButtons(QString filename);
94
95         /**
96          * Sets the current volume level.
97          *
98          * @param volume Volume level, between 0 and 1.0
99          */
100         void setVolume(qreal volume);
101
102     private:
103         Phonon::MediaObject* m_player;
104         Phonon::AudioOutput* m_audio;
105
106         QPushButton* m_playButton;
107         QPushButton* m_rewindButton;
108
109         QIcon m_playIcon;
110         QIcon m_pauseIcon;
111
112         QLineEdit* m_filenameEdit;
113 };
114
115 #endif