Implemented new features:
[someplayer] / src / player / player.cpp
index fb000d9..05d37cd 100644 (file)
@@ -1,8 +1,28 @@
+/*
+ * SomePlayer - An alternate music player for Maemo 5
+ * Copyright (C) 2010 Nikolay (somebody) Tischenko <niktischenko@gmail.com>
+ *
+ * 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
 #include "player.h"
 #include <phonon/MediaSource>
 
 using namespace SomePlayer::Playback;
 using namespace SomePlayer::DataObjects;
+using namespace SomePlayer::Storage;
 
 Player::Player(QObject *parent) :
     QObject(parent)
@@ -15,8 +35,8 @@ Player::Player(QObject *parent) :
        Phonon::createPath(_player, _output);
        int seed = reinterpret_cast<int> (_player);
        qsrand(seed);
-       _random = false;
-       _repeat = false;
+       _random = _config.getValue("playback/random").toBool();
+       _repeat = _config.getValue("playback/repeat").toBool();
        _current = -1;
 }
 
@@ -92,7 +112,7 @@ void Player::prev() {
        play();
 }
 
-void Player::_stateChanged(Phonon::State newState, Phonon::State oldState) {
+void Player::_stateChanged(Phonon::State newState, Phonon::State /*oldState*/) {
        switch (newState) {
        case Phonon::PlayingState:
                if (_state == PLAYER_LOADING) {
@@ -142,6 +162,8 @@ void Player::seek(int s) {
 }
 
 void Player::play() {
+       if (_playlist.tracks().isEmpty())
+               return;
        _state = PLAYER_PLAYING;
        emit stateChanged(_state);
        if (_current == -1) {
@@ -155,3 +177,17 @@ void Player::play() {
 void Player::enqueue(int id) {
        _queue.enqueue(id);
 }
+
+void Player::toggleRandom() {
+       _random = !_random;
+       _config.setValue("playback/random", _random);
+}
+
+void Player::toggleRepeat() {
+       _repeat = !_repeat;
+       _config.setValue("playback/repeat", _repeat);
+}
+
+void Player::setVolume(int v) {
+       _output->setVolume(v*0.01);
+}