not quite so much needs to be delayed to the init() function
[personal-kdebase.git] / workspace / plasma / dataengines / nowplaying / playeractionjob.cpp
blobbb1aee96f2cd66366751db30806ca9761f508ca2
1 /*
2 * Copyright 2008 Alex Merry <alex.merry@kdemail.net>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor,
17 * Boston, MA 02110-1301 USA
20 #include "playeractionjob.h"
22 #include <kdebug.h>
24 void PlayerActionJob::start()
26 kDebug() << "Trying to perform the action" << operationName();
27 if (!m_player) {
28 setErrorText(i18n("The player '%1' cannot be found", destination()));
29 setError(-1);
30 emitResult();
31 return;
34 const QString operation(operationName());
35 if (operation == "play") {
36 if (m_player->canPlay()) {
37 m_player->play();
38 } else {
39 setErrorText(i18n("The player '%1' cannot perform the action 'play'", m_player->name()));
40 setError(-1);
42 } else if (operation == "pause") {
43 if (m_player->canPause()) {
44 m_player->pause();
45 } else {
46 setErrorText(i18n("The player '%1' cannot perform the action 'pause'", m_player->name()));
47 setError(-1);
49 } else if (operation == "stop") {
50 if (m_player->canStop()) {
51 m_player->stop();
52 } else {
53 setErrorText(i18n("The player '%1' cannot perform the action 'stop'", m_player->name()));
54 setError(-1);
56 } else if (operation == "previous") {
57 if (m_player->canGoPrevious()) {
58 m_player->previous();
59 } else {
60 setErrorText(i18n("The player '%1' cannot perform the action 'previous'", m_player->name()));
61 setError(-1);
63 } else if (operation == "next") {
64 if (m_player->canGoNext()) {
65 m_player->next();
66 } else {
67 setErrorText(i18n("The player '%1' cannot perform the action 'next'", m_player->name()));
68 setError(-1);
70 } else if (operation == "volume") {
71 if (m_player->canSetVolume()) {
72 if (parameters().contains("level")) {
73 qreal volume = parameters()["level"].toDouble();
74 if (volume >= 0.0 && volume <= 1.0) {
75 m_player->setVolume(volume);
76 } else {
77 setErrorText(i18n("The 'level' argument to the 'volume' command must be between 0 and 1"));
78 setError(-2);
80 } else {
81 setErrorText(i18n("The 'volume' command requires a 'level' argument"));
82 setError(-2);
84 } else {
85 setErrorText(i18n("The player '%1' cannot perform the action 'volume'", m_player->name()));
86 setError(-1);
88 } else if (operation == "seek") {
89 if (m_player->canSeek()) {
90 if (parameters().contains("seconds")) {
91 qreal time = parameters()["seconds"].toInt();
92 if (time >= 0 && time <= m_player->length()) {
93 m_player->seek(time);
94 } else {
95 setErrorText(i18n("The 'seconds' argument to the 'seek' command must be "
96 "between 0 and the length of the track"));
97 setError(-2);
99 } else {
100 setErrorText(i18n("The 'seek' command requires a 'seconds' argument"));
101 setError(-2);
103 } else {
104 setErrorText(i18n("The player '%1' cannot perform the action 'seek'", m_player->name()));
105 setError(-1);
108 if (error()) {
109 kDebug() << "Failed with error" << errorText();
111 emitResult();
114 #include "playeractionjob.moc"
116 // vim: sw=4 sts=4 et tw=100