Initial commit. corresponds to 1.0-1 release
[flashstrobe] / src / musicplayer.h
diff --git a/src/musicplayer.h b/src/musicplayer.h
new file mode 100644 (file)
index 0000000..3965f97
--- /dev/null
@@ -0,0 +1,115 @@
+/*
+  Copyright (C) 2010 by Juan Carlos Torres <jucato@kdemail.net>
+
+  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) version 3 or any later version
+  accepted by the membership of KDE e.V. (or its successor appro-
+  ved by the membership of KDE e.V.), which shall act as a proxy
+  defined in Section 14 of version 3 of the license.
+
+  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/.
+*/
+
+
+#ifndef MUSICPLAYER_H
+#define MUSICPLAYER_H
+
+#include <QWidget>
+#include <QIcon>
+
+class QPushButton;
+class QIcon;
+class QLineEdit;
+
+namespace Phonon
+{
+    class MediaObject;
+    class AudioOutput;
+    class VolumeSlider;
+}
+
+/**
+ * @brief A simple Phonon-based music player widget
+ *
+ * This class implements a very simple widget for playing music
+ * using Phonon. Features include opening a file, playing/pausing,
+ * rewinding, and adjusting the volume.
+ */
+class MusicPlayer : public QWidget
+{
+    Q_OBJECT
+
+    public:
+        MusicPlayer(QWidget* parent = 0, Qt::WindowFlags flags = 0);
+        virtual ~MusicPlayer();
+
+        /**
+         * Returns the current volume level.
+         *
+         * @return @c qreal Volume level, between 0 and 1.0
+         */
+        qreal volume() const;
+
+    public slots:
+        /**
+         * Calls a QFileDialog for opening a file, initially
+         * from the platform's Music directory.
+         */
+        void openFile();
+
+        /**
+         * Plays or pauses the file currently contained in the
+         * selection. Also updates the player buttons to the
+         * appropriate state. For example, the Play button
+         * displays a pause icon if the file is currently playing,
+         * and a play icon if the file is paused.
+         *
+         * @param checked Determines whether to play (@c true) or
+         *                pause (@false) the file
+         */
+        void playOrPause(bool checked);
+
+        /**
+         * Rewinds the current audio file to teh beginning.
+         */
+        void rewind();
+
+        /**
+         * Updates the state of the controls in the player depending on
+         * the state of the line edit indicating the audio file to play.
+         * If the line edit is not empty, the controls are enabled. Otherwise
+         * they are disabled.
+         *
+         * @param filename A string containing the contents of the line edit
+         */
+        void enableButtons(QString filename);
+
+        /**
+         * Sets the current volume level.
+         *
+         * @param volume Volume level, between 0 and 1.0
+         */
+        void setVolume(qreal volume);
+
+    private:
+        Phonon::MediaObject* m_player;
+        Phonon::AudioOutput* m_audio;
+
+        QPushButton* m_playButton;
+        QPushButton* m_rewindButton;
+
+        QIcon m_playIcon;
+        QIcon m_pauseIcon;
+
+        QLineEdit* m_filenameEdit;
+};
+
+#endif