Re: [kaffeine-devel] dbus support for kaffeine
Brought to you by:
hftom,
lasselindqvist
From: Christoph P. <chr...@gm...> - 2009-11-02 09:00:45
|
2009/10/30 Pascal Pollet <pa...@bo...>: > Hi, > > I sent an email to this mailing list with a patch attached one hour ago, > but now I looked at the mailing list archive > (http://sourceforge.net/mailarchive/forum.php?forum_name=kaffeine-devel), > and it seems that only the patch reached the mailing list, and not the > body of the email. Right, there seems to be a problem (I'll take care of it). > Is this maybe a sourceforge bug? So I send the mail > again, without the patch this time: > > > Hello guys, > > I am since the very beginning of kaffeine a great fan of this > application and use it for watching movies and TV. In the new version, I > miss a dbus interface to be able to use my remote control for watching > TV. As I know a little bit of C++ and Qt, I decided to implement the > dbus features for kaffeine, btw. giving me the occasion to learn how to > do this. Here is a small patch which makes two functions of dvbtab.cpp > available for dbus: previousChannel() and nextChannel(). It is just a > minimal proof of principle, to show you how I would implement the dbus > functionality. I would be really happy to contribute to this cool > project, so if you are interested in my code, please tell me. I would > add dbus support for all functions which should be accessible from the > outside world. I appreciate contributions (I have to code less; you learn something ;-). See below for a (short, I'm sorry) feedback. > For my developer background, I like to contribute with mostly small > patches to various open-source projects, and I am the guy from this > project: http://www.bongosoft.de (german page!). > Newly, I also started this one: > http://www.kde-look.org/content/show.php/Babeleo+translator?content=110491 > In "real life" I am about to finalize a Ph.D. in bioinformatics in the > nice town of Freiburg/Germany... > > I am both French and German, so you can talk to me in any of these > languages, naturally also in English. > > The patch is against revision 1042616 of the SVN tree. > > greetings, > Pascal > diff -Naur ../kaffeine_ori/src/CMakeLists.txt ./src/CMakeLists.txt > --- ../kaffeine_ori/src/CMakeLists.txt 2009-10-30 10:34:30.000000000 +0100 > +++ ./src/CMakeLists.txt 2009-10-30 11:08:47.000000000 +0100 > @@ -2,6 +2,7 @@ > dvb/dvbchannel.cpp > dvb/dvbchannelui.cpp > dvb/dvbconfigdialog.cpp > + dvb/dvbdbusadaptor.cpp please place the file in the src/ directory and call it dbusadaptor.cpp > dvb/dvbdevice.cpp > dvb/dvbepg.cpp > dvb/dvbmanager.cpp > diff -Naur ../kaffeine_ori/src/dvb/dvbdbusadaptor.h ./src/dvb/dvbdbusadaptor.h > --- ../kaffeine_ori/src/dvb/dvbdbusadaptor.h 1970-01-01 01:00:00.000000000 +0100 > +++ ./src/dvb/dvbdbusadaptor.h 2009-10-30 11:08:47.000000000 +0100 > @@ -0,0 +1,19 @@ use a header include guard = #ifndef DBUSADAPTOR_H #define DBUSADAPTOR_H ... #endif > +#include <QDBusAbstractAdaptor> > + > +class DvbTab; > + > +class dvbdbusadaptor: public QDBusAbstractAdaptor > +{ > + Q_OBJECT > + Q_CLASSINFO("D-Bus Interface", "org.kde.kaffeine") > + > +private: > + DvbTab* dtab; > + > +public: > + dvbdbusadaptor(QWidget* dvbTab); > + > +public slots: > + void nextTvChannel(); > + void previousTvChannel(); please call those slots previous() and next() > +}; > diff -Naur ../kaffeine_ori/src/dvb/dvbdbusadaptor.cpp ./src/dvb/dvbdbusadaptor.cpp > --- ../kaffeine_ori/src/dvb/dvbdbusadaptor.cpp 1970-01-01 01:00:00.000000000 +0100 > +++ ./src/dvb/dvbdbusadaptor.cpp 2009-10-30 11:08:47.000000000 +0100 > @@ -0,0 +1,19 @@ > +#include "dvbdbusadaptor.h" > +#include "dvbtab.h" > + > + > +dvbdbusadaptor::dvbdbusadaptor(QWidget* dvbtab) > +: QDBusAbstractAdaptor(dvbtab) > +{ > + dtab = dynamic_cast<DvbTab*>(dvbtab); avoid dynamic casts > +} > + > +Q_NOREPLY void dvbdbusadaptor::previousTvChannel() > +{ > + dtab->previousChannel(); call mediaWidget->previous() > +} > + > +Q_NOREPLY void dvbdbusadaptor::nextTvChannel() > +{ > + dtab->nextChannel(); call mediaWidget->next() > +} > diff -Naur ../kaffeine_ori/src/dvb/dvbtab.cpp ./src/dvb/dvbtab.cpp > --- ../kaffeine_ori/src/dvb/dvbtab.cpp 2009-10-30 10:34:30.000000000 +0100 > +++ ./src/dvb/dvbtab.cpp 2009-10-30 11:08:47.000000000 +0100 > @@ -21,6 +21,7 @@ > #include "dvbtab.h" > > #include <QBoxLayout> > +#include <QDBusConnection> > #include <QDir> > #include <QHeaderView> > #include <QPainter> > @@ -37,6 +38,7 @@ > #include "../osdwidget.h" > #include "dvbchannelui.h" > #include "dvbconfigdialog.h" > +#include "dvbdbusadaptor.h" > #include "dvbepg.h" > #include "dvbmanager.h" > #include "dvbrecording.h" > @@ -424,6 +426,10 @@ > > dvbOsdTimer = new QTimer(this); > connect(dvbOsdTimer, SIGNAL(timeout()), this, SLOT(osdTimeout())); > + > + new dvbdbusadaptor(this); > + QDBusConnection::sessionBus().registerObject("/DVB", this); > + QDBusConnection::sessionBus().registerService("org.kde.kaffeine"); initialise the adapter from Kaffeine::Kaffeine() > } > > DvbTab::~DvbTab() > diff -Naur ../kaffeine_ori/src/dvb/dvbtab.h ./src/dvb/dvbtab.h > --- ../kaffeine_ori/src/dvb/dvbtab.h 2009-10-30 10:34:30.000000000 +0100 > +++ ./src/dvb/dvbtab.h 2009-10-30 11:08:47.000000000 +0100 > @@ -42,6 +42,8 @@ > class DvbTab : public TabBase > { > Q_OBJECT > + friend class dvbdbusadaptor; > + > public: > DvbTab(KMenu *menu, KActionCollection *collection, MediaWidget *mediaWidget_); > ~DvbTab(); Thanks, Christoph |