Plasma
playeractionjob.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "playeractionjob.h"
00021
00022 #include <kdebug.h>
00023
00024 void PlayerActionJob::start()
00025 {
00026 kDebug() << "Trying to perform the action" << operationName();
00027 if (!m_player) {
00028 setErrorText(i18n("The player '%1' cannot be found", destination()));
00029 setError(-1);
00030 emitResult();
00031 return;
00032 }
00033
00034 const QString operation(operationName());
00035 if (operation == "play") {
00036 if (m_player->canPlay()) {
00037 m_player->play();
00038 } else {
00039 setErrorText(i18n("The player '%1' cannot perform the action 'play'", m_player->name()));
00040 setError(-1);
00041 }
00042 } else if (operation == "pause") {
00043 if (m_player->canPause()) {
00044 m_player->pause();
00045 } else {
00046 setErrorText(i18n("The player '%1' cannot perform the action 'pause'", m_player->name()));
00047 setError(-1);
00048 }
00049 } else if (operation == "stop") {
00050 if (m_player->canStop()) {
00051 m_player->stop();
00052 } else {
00053 setErrorText(i18n("The player '%1' cannot perform the action 'stop'", m_player->name()));
00054 setError(-1);
00055 }
00056 } else if (operation == "previous") {
00057 if (m_player->canGoPrevious()) {
00058 m_player->previous();
00059 } else {
00060 setErrorText(i18n("The player '%1' cannot perform the action 'previous'", m_player->name()));
00061 setError(-1);
00062 }
00063 } else if (operation == "next") {
00064 if (m_player->canGoNext()) {
00065 m_player->next();
00066 } else {
00067 setErrorText(i18n("The player '%1' cannot perform the action 'next'", m_player->name()));
00068 setError(-1);
00069 }
00070 } else if (operation == "volume") {
00071 if (m_player->canSetVolume()) {
00072 if (parameters().contains("level")) {
00073 qreal volume = parameters()["level"].toDouble();
00074 if (volume >= 0.0 && volume <= 1.0) {
00075 m_player->setVolume(volume);
00076 } else {
00077 setErrorText(i18n("The 'level' argument to the 'volume' command must be between 0 and 1"));
00078 setError(-2);
00079 }
00080 } else {
00081 setErrorText(i18n("The 'volume' command requires a 'level' argument"));
00082 setError(-2);
00083 }
00084 } else {
00085 setErrorText(i18n("The player '%1' cannot perform the action 'volume'", m_player->name()));
00086 setError(-1);
00087 }
00088 } else if (operation == "seek") {
00089 if (m_player->canSeek()) {
00090 if (parameters().contains("seconds")) {
00091 qreal time = parameters()["seconds"].toInt();
00092 if (time >= 0 && time <= m_player->length()) {
00093 m_player->seek(time);
00094 } else {
00095 setErrorText(i18n("The 'seconds' argument to the 'seek' command must be "
00096 "between 0 and the length of the track"));
00097 setError(-2);
00098 }
00099 } else {
00100 setErrorText(i18n("The 'seek' command requires a 'seconds' argument"));
00101 setError(-2);
00102 }
00103 } else {
00104 setErrorText(i18n("The player '%1' cannot perform the action 'seek'", m_player->name()));
00105 setError(-1);
00106 }
00107 }
00108 if (error()) {
00109 kDebug() << "Failed with error" << errorText();
00110 }
00111 emitResult();
00112 }
00113
00114 #include "playeractionjob.moc"
00115
00116