[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: =?utf-8?q?=5Bplasma-mediacenter=5D_dataengines/mediacentercontro?=
From: Sinny Kumari <ksinny () gmail ! com>
Date: 2011-05-31 19:49:37
Message-ID: 20110531194937.A8A98A60A4 () git ! kde ! org
[Download RAW message or body]
Git commit 68f6ff6405d52406e19cdacfc7280aef70273603 by Sinny Kumari.
Committed on 31/05/2011 at 21:43.
Pushed by sinnykumari into branch 'master'.
Adding plasma:service, plasma:serviceJob in dataengine and few other functons to be \
accesed like play, pause, etc
M +7 -3 dataengines/mediacentercontrol/CMakeLists.txt
A +136 -0 dataengines/mediacentercontrol/media.cpp [License: GPL (v2+)]
A +63 -0 dataengines/mediacentercontrol/media.h [License: GPL (v2+)]
M +3 -0 dataengines/mediacentercontrol/mediacentercontrol.cpp
M +1 -0 dataengines/mediacentercontrol/mediacentercontrol.h
A +10 -0 dataengines/mediacentercontrol/mediacentercontrol.operations
M +16 -2 dataengines/mediacentercontrol/mediacontainer.cpp
M +6 -2 dataengines/mediacentercontrol/mediacontainer.h
A +119 -0 dataengines/mediacentercontrol/mediajob.cpp [License: GPL \
(v2+)] A +40 -0 dataengines/mediacentercontrol/mediajob.h [License: GPL \
(v2+)] A +53 -0 dataengines/mediacentercontrol/mediaservice.cpp \
[License: GPL (v2+)] A +42 -0 dataengines/mediacentercontrol/mediaservice.h \
[License: GPL (v2+)]
http://commits.kde.org/plasma-mediacenter/68f6ff6405d52406e19cdacfc7280aef70273603
diff --git a/dataengines/mediacentercontrol/CMakeLists.txt \
b/dataengines/mediacentercontrol/CMakeLists.txt index 128dc5b..6351527 100644
--- a/dataengines/mediacentercontrol/CMakeLists.txt
+++ b/dataengines/mediacentercontrol/CMakeLists.txt
@@ -12,13 +12,16 @@ include_directories(
${KDE4_INCLUDES}
)
-# We add our source code here
+# Adding source code here
set(mediacentercontrol_SRCS
mediacentercontrol.cpp
mediacontainer.cpp
+ media.cpp
+ mediaservice.cpp
+ mediajob.cpp
)
-# Now make sure all files get to the right place
+# Make sure that all files get to the right place
kde4_add_plugin(plasma_engine_mediacentercontrol ${mediacentercontrol_SRCS})
target_link_libraries(plasma_engine_mediacentercontrol
${KDE4_KDECORE_LIBS}
@@ -28,4 +31,5 @@ install(TARGETS plasma_engine_mediacentercontrol
DESTINATION ${PLUGIN_INSTALL_DIR})
install(FILES plasma-engine-mediacentercontrol.desktop
- DESTINATION ${SERVICES_INSTALL_DIR})
\ No newline at end of file
+ DESTINATION ${SERVICES_INSTALL_DIR})
+install(FILES mediacentercontrol.operations DESTINATION \
${DATA_INSTALL_DIR}/plasma/services) \ No newline at end of file
diff --git a/dataengines/mediacentercontrol/media.cpp \
b/dataengines/mediacentercontrol/media.cpp new file mode 100644
index 0000000..d45b8a0
--- /dev/null
+++ b/dataengines/mediacentercontrol/media.cpp
@@ -0,0 +1,136 @@
+/***************************************************************************
+ * Copyright 2011 by Sinny Kumari <ksinny@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 "media.h"
+#include "kdebug.h"
+
+Media::Media()
+{
+
+}
+
+QString Media::name() const
+{
+ Q_ASSERT(!m_name.isEmpty());
+ return m_name;
+}
+
+Media::State Media::state()
+{
+ m_state = Playing;
+ return m_state;
+}
+
+int Media::length()
+{
+ return 60;
+}
+
+int Media::position()
+{
+ return 20;
+}
+
+float Media::volume()
+{
+ return 24;
+}
+
+bool Media::canPlay()
+{
+ kDebug() << "yes";
+ return true;
+}
+
+void Media::play()
+{
+ kDebug() << "play";
+}
+
+bool Media::canPause()
+{
+ kDebug() << "yes";
+ return true;
+}
+
+void Media::pause()
+{
+ kDebug() <<" Pause";
+}
+
+bool Media::canStop()
+{
+ kDebug() << "yes";
+ return true;
+}
+
+void Media::stop()
+{
+ kDebug() << "stop";
+}
+
+bool Media::canGoPrevious()
+{
+ kDebug() << "yes";
+ return true;
+}
+
+void Media::previous()
+{
+ kDebug() << "previous";
+}
+
+bool Media::canGoNext()
+{
+ kDebug() << "yes";
+ return true;
+}
+
+void Media::next()
+{
+ kDebug() << "next";
+}
+
+bool Media::canSetVolume()
+{
+ kDebug() << "yes";
+ return true;
+}
+
+void Media::setVolume(qreal)
+{
+ kDebug() << "volumeSet";
+}
+
+bool Media::canSeek()
+{
+ kDebug() << "yes";
+ return true;
+}
+
+void Media::seek(int)
+{
+ kDebug() << "seek";
+}
+
+void Media::setName(const QString& name)
+{
+ m_name = name;
+}
+
+#include "media.moc"
\ No newline at end of file
diff --git a/dataengines/mediacentercontrol/media.h \
b/dataengines/mediacentercontrol/media.h new file mode 100644
index 0000000..075719f
--- /dev/null
+++ b/dataengines/mediacentercontrol/media.h
@@ -0,0 +1,63 @@
+/***************************************************************************
+ * Copyright 2011 by Sinny Kumari <ksinny@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 . *
+ ***************************************************************************/
+#ifndef MEDIA_H
+#define MEDIA_H
+
+#include <QString>
+
+class Media
+{
+public:
+ Media();
+ QString name() const;
+ enum State {
+ Playing,
+ Paused,
+ Stopped
+ };
+ int length();
+ bool isRunning();
+ State state();
+ int position();
+ float volume();
+ bool canPlay();
+ void play();
+ bool canPause();
+ void pause();
+ bool canStop();
+ void stop();
+ bool canGoPrevious();
+ void previous();
+ bool canGoNext();
+ void next();
+ bool canSetVolume();
+ void setVolume(qreal volume);
+ bool canSeek();
+ void seek(int time);
+
+protected:
+ void setName(const QString& name);
+
+private:
+ QString m_name;
+ Media::State m_state;
+};
+
+#endif // MEDIA_H
+
\ No newline at end of file
diff --git a/dataengines/mediacentercontrol/mediacentercontrol.cpp \
b/dataengines/mediacentercontrol/mediacentercontrol.cpp index abe5003..47a2434 100644
--- a/dataengines/mediacentercontrol/mediacentercontrol.cpp
+++ b/dataengines/mediacentercontrol/mediacentercontrol.cpp
@@ -18,6 +18,8 @@
***************************************************************************/
#include "mediacentercontrol.h"
#include "mediacontainer.h"
+#include "media.h"
+#include "mediaservice.h"
MediaCenterControl::MediaCenterControl(QObject *parent, const QVariantList &args)
: Plasma::DataEngine(parent, args)
@@ -34,4 +36,5 @@ void MediaCenterControl::init()
}
K_EXPORT_PLASMA_DATAENGINE(org.kde.mediacentercontrol, MediaCenterControl)
+
#include "mediacentercontrol.moc"
\ No newline at end of file
diff --git a/dataengines/mediacentercontrol/mediacentercontrol.h \
b/dataengines/mediacentercontrol/mediacentercontrol.h index 5cd24a4..17639d7 100644
--- a/dataengines/mediacentercontrol/mediacentercontrol.h
+++ b/dataengines/mediacentercontrol/mediacentercontrol.h
@@ -28,6 +28,7 @@ class MediaCenterControl : public Plasma::DataEngine
public:
MediaCenterControl(QObject* parent, const QVariantList& args);
+ // Plasma::Service* serviceForSource(const QString& source);
void init();
};
diff --git a/dataengines/mediacentercontrol/mediacentercontrol.operations \
b/dataengines/mediacentercontrol/mediacentercontrol.operations new file mode 100644
index 0000000..2649d3e
--- /dev/null
+++ b/dataengines/mediacentercontrol/mediacentercontrol.operations
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE kcfg SYSTEM
+ "http://www.kde.org/standards/kcfg/1.0/kcfg.xsd">
+<kcfg>
+ <group name="play"/>
+ <group name="pause"/>
+ <group name="stop"/>
+ <group name="previous"/>
+ <group name="next"/>
+</kcfg>
\ No newline at end of file
diff --git a/dataengines/mediacentercontrol/mediacontainer.cpp \
b/dataengines/mediacentercontrol/mediacontainer.cpp index e9d920c..07c9a29 100644
--- a/dataengines/mediacentercontrol/mediacontainer.cpp
+++ b/dataengines/mediacentercontrol/mediacontainer.cpp
@@ -17,6 +17,7 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
***************************************************************************/
#include "mediacontainer.h"
+#include "mediaservice.h"
MediaContainer::MediaContainer(QObject *parent)
: Plasma::DataContainer(parent)
@@ -26,8 +27,21 @@ MediaContainer::MediaContainer(QObject *parent)
void MediaContainer::updateData()
{
- setData("State","Playing");
- setData("Progress",20);
+ Media* m_media=new Media;
+ switch(m_media->state()) {
+ case Media::Playing:
+ setData("State", "playing");
+ break;
+ case Media::Paused:
+ setData("State", "paused");
+ break;
+ case Media::Stopped:
+ setData("State", "stopped");
+ break;
+ }
+ setData("Progress",m_media->position());
setData("MediaType", "Audio");
setData("Url","/home/Music/sintel.mp3");
}
+
+#include "mediacontainer.moc"
\ No newline at end of file
diff --git a/dataengines/mediacentercontrol/mediacontainer.h \
b/dataengines/mediacentercontrol/mediacontainer.h index a1de911..0a6df0b 100644
--- a/dataengines/mediacentercontrol/mediacontainer.h
+++ b/dataengines/mediacentercontrol/mediacontainer.h
@@ -20,6 +20,7 @@
#define MEDIACONTAINER_H
#include <Plasma/DataContainer>
+#include "media.h"
class MediaContainer : public Plasma::DataContainer
{
@@ -28,9 +29,12 @@ class MediaContainer : public Plasma::DataContainer
public:
MediaContainer(QObject *parent = 0);
-protected:
+public slots:
void updateData();
-
+
+private:
+ Media* m_media;
+
};
#endif
\ No newline at end of file
diff --git a/dataengines/mediacentercontrol/mediajob.cpp \
b/dataengines/mediacentercontrol/mediajob.cpp new file mode 100644
index 0000000..e02c32d
--- /dev/null
+++ b/dataengines/mediacentercontrol/mediajob.cpp
@@ -0,0 +1,119 @@
+/***************************************************************************
+ * Copyright 2011 by Sinny Kumari <ksinny@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 "mediajob.h"
+#include "kdebug.h"
+
+MediaJob::MediaJob(Media* media,
+ const QString &destination, const QString &operation, const QMap<QString, \
QVariant> ¶meters, + QObject *parent) : Plasma::ServiceJob(destination, \
operation, parameters, parent), + m_media(media)
+{
+
+}
+
+void MediaJob::start()
+{
+ if (!m_media) {
+ setErrorText(i18n("'%1' cannot be found.", destination()));
+ setError(-1);
+ emitResult();
+ return;
+ }
+
+ const QString operation(operationName());
+ if (operation == "play") {
+ if (m_media->canPlay()) {
+ m_media->play();
+ } else {
+ setErrorText(i18n("'%1' cannot perform the action 'play'.", \
m_media->name())); + setError(-1);
+ }
+ } else if (operation == "pause") {
+ if (m_media->canPause()) {
+ m_media->pause();
+ } else {
+ setErrorText(i18n("'%1' cannot perform the action 'pause'.", \
m_media->name())); + setError(-1);
+ }
+ } else if (operation == "stop") {
+ if (m_media->canStop()) {
+ m_media->stop();
+ } else {
+ setErrorText(i18n("'%1' cannot perform the action 'stop'.", \
m_media->name())); + setError(-1);
+ }
+ } else if (operation == "previous") {
+ if (m_media->canGoPrevious()) {
+ m_media->previous();
+ } else {
+ setErrorText(i18n("'%1' cannot perform the action 'previous'.", \
m_media->name())); + setError(-1);
+ }
+ } else if (operation == "next") {
+ if (m_media->canGoNext()) {
+ m_media->next();
+ } else {
+ setErrorText(i18n("'%1' cannot perform the action 'next'.", \
m_media->name())); + setError(-1);
+ }
+ } else if (operation == "volume") {
+ if (m_media->canSetVolume()) {
+ if (parameters().contains("level")) {
+ qreal volume = parameters()["level"].toDouble();
+ if (volume >= 0.0 && volume <= 1.0) {
+ m_media->setVolume(volume);
+ } else {
+ setErrorText(i18n("The 'level' argument to the 'volume' command \
must be between 0 and 1.")); + setError(-2);
+ }
+ } else {
+ setErrorText(i18n("The 'volume' command requires a 'level' \
argument.")); + setError(-2);
+ }
+ } else {
+ setErrorText(i18n("'%1' cannot perform the action 'volume'.", \
m_media->name())); + setError(-1);
+ }
+ } else if (operation == "seek") {
+ if (m_media->canSeek()) {
+ if (parameters().contains("seconds")) {
+ qreal time = parameters()["seconds"].toInt();
+ if (time >= 0 && time <= m_media->length()) {
+ m_media->seek(time);
+ } else {
+ setErrorText(i18n("The 'seconds' argument to the 'seek' command \
must be " + "between 0 and the length of the \
track.")); + setError(-2);
+ }
+ } else {
+ setErrorText(i18n("The 'seek' command requires a 'seconds' \
argument.")); + setError(-2);
+ }
+ } else {
+ setErrorText(i18n("'%1' cannot perform the action 'seek'.", \
m_media->name())); + setError(-1);
+ }
+ }
+ if (error()) {
+ kDebug() << "Failed with error" << errorText();
+ }
+ emitResult();
+}
+
+#include "mediajob.moc"
diff --git a/dataengines/mediacentercontrol/mediajob.h \
b/dataengines/mediacentercontrol/mediajob.h new file mode 100644
index 0000000..1fd479d
--- /dev/null
+++ b/dataengines/mediacentercontrol/mediajob.h
@@ -0,0 +1,40 @@
+/***************************************************************************
+ * Copyright 2011 by Sinny Kumari <ksinny@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 . *
+ ***************************************************************************/
+
+#ifndef MEDIAJOB_H
+#define MEDIAJOB_H
+
+#include <Plasma/ServiceJob>
+#include <QMap>
+#include "media.h"
+
+class MediaJob : public Plasma::ServiceJob
+{
+ Q_OBJECT
+
+public:
+ MediaJob(Media* media, const QString& destination,
+ const QString& operation, const QMap< QString, QVariant >& parameters, \
QObject* parent = 0); + void start();
+
+private:
+ Media* m_media;
+};
+
+#endif // MEDIAJOB_H
\ No newline at end of file
diff --git a/dataengines/mediacentercontrol/mediaservice.cpp \
b/dataengines/mediacentercontrol/mediaservice.cpp new file mode 100644
index 0000000..88abcfe
--- /dev/null
+++ b/dataengines/mediacentercontrol/mediaservice.cpp
@@ -0,0 +1,53 @@
+/***************************************************************************
+ * Copyright 2011 by Sinny Kumari <ksinny@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 "mediaservice.h"
+#include "mediajob.h"
+
+MediaService::MediaService(Media* media, QObject* parent)
+ : Plasma::Service(parent), m_media(media)
+{
+ setObjectName("media controller");
+ setName("media");
+ if (m_media) {
+ setDestination(m_media->name());
+ }
+ enableMediaOperations();
+}
+
+void MediaService::enableMediaOperations()
+{
+ if (m_media) {
+ setOperationEnabled("play", m_media->canPlay());
+ setOperationEnabled("pause", m_media->canPause());
+ setOperationEnabled("stop", m_media->canStop());
+ setOperationEnabled("next", m_media->canGoNext());
+ setOperationEnabled("previous", m_media->canGoPrevious());
+ setOperationEnabled("volume", m_media->canSetVolume());
+ setOperationEnabled("seek", m_media->canSeek());
+ }
+
+}
+
+Plasma::ServiceJob* MediaService::createJob(const QString &operation, QMap<QString, \
QVariant> ¶meters) +{
+ return new MediaJob(m_media, destination(), operation, parameters, this);
+}
+
+
+#include "mediaservice.moc"
\ No newline at end of file
diff --git a/dataengines/mediacentercontrol/mediaservice.h \
b/dataengines/mediacentercontrol/mediaservice.h new file mode 100644
index 0000000..0ecf83e
--- /dev/null
+++ b/dataengines/mediacentercontrol/mediaservice.h
@@ -0,0 +1,42 @@
+/***************************************************************************
+ * Copyright 2011 by Sinny Kumari <ksinny@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 . *
+ ***************************************************************************/
+#ifndef MEDIASERVICE_H
+#define MEDIASERVICE_H
+
+#include <Plasma/Service>
+#include "media.h"
+
+class MediaService : public Plasma::Service
+{
+ Q_OBJECT
+
+public:
+ MediaService(Media* media, QObject* parent);
+
+public slots:
+ void enableMediaOperations();
+
+protected:
+ Plasma::ServiceJob* createJob(const QString &operation, QMap<QString, QVariant> \
¶meters); +
+private:
+ Media* m_media;
+};
+
+#endif // MEDIASERVICE_H
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic