• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

Engines

playeractionjob.cpp

Go to the documentation of this file.
00001 /*
00002  * Copyright 2008  Alex Merry <alex.merry@kdemail.net>
00003  *
00004  * This library is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Lesser General Public
00006  * License as published by the Free Software Foundation; either
00007  * version 2.1 of the License, or (at your option) any later version.
00008  *
00009  * This library is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * Lesser General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU Lesser General Public
00015  * License along with this library; if not, write to the Free Software
00016  * Foundation, Inc., 51 Franklin St, Fifth Floor,
00017  * Boston, MA  02110-1301  USA
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 // vim: sw=4 sts=4 et tw=100

Engines

Skip menu "Engines"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

API Reference

Skip menu "API Reference"
  • KWin
  •   KWin Libraries
  • Libraries
  •   libkworkspace
  •   libsolidcontrol
  •   libtaskmanager
  • Plasma
  •   Animators
  •   Applets
  •   Engines
  • Solid Modules
Generated for API Reference by doxygen 1.5.7
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal