diff options
author | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
---|---|---|
committer | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
commit | 460c52653ab0dcca6f19a4f492ed2c5e4e963ab0 (patch) | |
tree | 67208f7c145782a7e90b123b982ca78d88cc2c87 /kitchensync/opensyncdbus | |
download | tdepim-460c52653ab0dcca6f19a4f492ed2c5e4e963ab0.tar.gz tdepim-460c52653ab0dcca6f19a4f492ed2c5e4e963ab0.zip |
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdepim@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kitchensync/opensyncdbus')
-rw-r--r-- | kitchensync/opensyncdbus/Makefile.am | 10 | ||||
-rw-r--r-- | kitchensync/opensyncdbus/README | 5 | ||||
-rw-r--r-- | kitchensync/opensyncdbus/dbusclient.cpp | 273 | ||||
-rw-r--r-- | kitchensync/opensyncdbus/dbusclient.h | 56 |
4 files changed, 344 insertions, 0 deletions
diff --git a/kitchensync/opensyncdbus/Makefile.am b/kitchensync/opensyncdbus/Makefile.am new file mode 100644 index 000000000..9b1721f6e --- /dev/null +++ b/kitchensync/opensyncdbus/Makefile.am @@ -0,0 +1,10 @@ +INCLUDES = -I/usr/local/include/dbus-1.0/qt3 $(all_includes) \ + -I$(top_srcdir)/kitchensync + +bin_PROGRAMS = opensyncdbus + +opensyncdbus_SOURCES = dbusclient.cpp +opensyncdbus_LDADD = $(top_builddir)/kitchensync/libqopensync/libqopensync.la +opensyncdbus_LDFLAGS = -ldbus-1-qt3 -ldbus-1 $(all_libraries) $(KDE_RPATH) + +METASOURCES = AUTO diff --git a/kitchensync/opensyncdbus/README b/kitchensync/opensyncdbus/README new file mode 100644 index 000000000..e1aa1e3ce --- /dev/null +++ b/kitchensync/opensyncdbus/README @@ -0,0 +1,5 @@ +This directory contains opensyncdbus, a D-BUS frontend for OpenSync. It's a +daemon which provides a D-BUS interface for controlling OpenSync. + +To compile opensyncdbus you need the Qt3 bindings for D-BUS. +They are in SVN under branches/work/dbus-qt4-qt3backport/ diff --git a/kitchensync/opensyncdbus/dbusclient.cpp b/kitchensync/opensyncdbus/dbusclient.cpp new file mode 100644 index 000000000..fcf6eda30 --- /dev/null +++ b/kitchensync/opensyncdbus/dbusclient.cpp @@ -0,0 +1,273 @@ +/* + This file is part of KDE. + + Copyright (c) 2006 Cornelius Schumacher <schumacher@kde.org> + + 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 "dbusclient.h" + +#include <libqopensync/environment.h> +#include <libqopensync/group.h> + +#include <dbus/qdbuserror.h> +#include <dbus/qdbusconnection.h> +#include <dbus/qdbusmessage.h> +#include <dbus/qdbusproxy.h> + +#include <qapplication.h> +#include <qtimer.h> + +#include <iostream> + +OpenSyncService::OpenSyncService() + : mConnection( 0 ) +{ +} + +void OpenSyncService::setConnection( QDBusConnection *connection ) +{ + mConnection = connection; + mConnection->registerObject( "/ABC", this ); +} + +bool OpenSyncService::handleMethodCall( const QDBusMessage &message ) +{ + qDebug( "OpenSyncService::handleMethodCall()" ); + + qDebug( " Interface: %s", message.interface().latin1() ); + qDebug( " Path: %s", message.path().latin1() ); + qDebug( " Member: %s", message.member().latin1() ); + qDebug( " Sender: %s", message.sender().latin1() ); + + if ( message.interface() != "org.opensync.SyncEngine" ) return false; + + QDBusMessage reply; + + QString function = message.member(); + if ( function == "hello" ) { + reply = hello( message ); + } else if ( function == "randomNumber" ) { + reply = randomNumber( message ); + } else if ( function == "listGroups" ) { + reply = listGroups( message ); + } else if ( function == "listPlugins" ) { + reply = listPlugins( message ); + } else if ( function == "showGroup" ) { + reply = showGroup( message ); + } else if ( function == "showMember" ) { + reply = showMember( message ); + } else { + return false; + } + + mConnection->send( reply ); + + return true; +} + +QDBusMessage OpenSyncService::showMember( const QDBusMessage &message ) +{ + if ( message.count() != 2 ) { + return error( message, "arg_count", + QString("Wrong number of arguments. Expected 2, got %1.") + .arg( message.count() ) ); + } + + QString groupName = message[ 0 ].toString(); + if ( groupName.isEmpty() ) { + return error( message, "missing_arg", "Missing argument: group name." ); + } + + bool ok; + int memberId = message[ 1 ].toInt( &ok ); + if ( !ok ) { + return error( message, "missing_arg", "Missing argument: member id." ); + } + + QDBusMessage reply; + + QSync::Environment env; + QSync::Result result = env.initialize(); + if ( result.isError() ) { + return error( message, result.name(), result.message() ); + } else { + reply = QDBusMessage::methodReply( message ); + + QSync::Group group = env.groupByName( groupName ); + if ( !group.isValid() ) { + return error( message, "group_name", QString("Unknown group '%1'.") + .arg( groupName ) ); + } + + QSync::Member member = group.memberById( memberId ); + if ( !member.isValid() ) { + return error( message, "member_id", + QString("Unknown member id '%1' in group '%2'.").arg( groupName ) + .arg( memberId ) ); + } + + reply.append( memberId ); + reply.append( member.pluginName() ); + + env.finalize(); + } + + return reply; +} + + +QDBusMessage OpenSyncService::showGroup( const QDBusMessage &message ) +{ + if ( message.count() != 1 ) { + return error( message, "arg_count", + QString("Wrong number of arguments. Expected 1, got %1") + .arg( message.count() ) ); + } + + QString groupName = message[ 0 ].toString(); + if ( groupName.isEmpty() ) { + return error( message, "missing_arg", "Missing argument group name." ); + } + + QDBusMessage reply; + + QSync::Environment env; + QSync::Result result = env.initialize(); + if ( result.isError() ) { + return error( message, result.name(), result.message() ); + } else { + reply = QDBusMessage::methodReply( message ); + + QSync::Group group = env.groupByName( groupName ); + if ( !group.isValid() ) { + return error( message, "group_name", QString("Unknown group '%1'") + .arg( groupName ) ); + } + + QSync::Group::Iterator it( &group ); + for( it = group.begin(); it != group.end(); ++it ) { + QSync::Member member = *it; + reply.append( QVariant( member.id() ) ); + } + + env.finalize(); + } + + return reply; +} + +QDBusMessage OpenSyncService::error( const QDBusMessage &message, + const QString &errorCode, + const QString &errorMessage ) +{ + QDBusError error( "org.opensync." + errorCode, errorMessage ); + return QDBusMessage::methodError( message, error ); +} + +QDBusMessage OpenSyncService::listPlugins( const QDBusMessage &message ) +{ + QDBusMessage reply; + + QSync::Environment env; + QSync::Result result = env.initialize(); + if ( result.isError() ) { + QDBusError error( result.name(), result.message() ); + reply = QDBusMessage::methodError( message, error ); + } else { + reply = QDBusMessage::methodReply( message ); + + QSync::Environment::PluginIterator it( env.pluginBegin() ); + for ( ; it != env.pluginEnd(); ++it ) { + reply.append( QVariant( (*it).name() ) ); + } + + env.finalize(); + } + + return reply; +} + +QDBusMessage OpenSyncService::listGroups( const QDBusMessage &message ) +{ + QDBusMessage reply; + + QSync::Environment env; + QSync::Result result = env.initialize(); + if ( result.isError() ) { + QDBusError error( result.name(), result.message() ); + reply = QDBusMessage::methodError( message, error ); + } else { + reply = QDBusMessage::methodReply( message ); + + QSync::Environment::GroupIterator it( env.groupBegin() ); + for ( ; it != env.groupEnd(); ++it ) { + reply.append( QVariant( (*it).name() ) ); + } + + env.finalize(); + } + + return reply; +} + +QDBusMessage OpenSyncService::hello( const QDBusMessage &message ) +{ + QDBusMessage reply = QDBusMessage::methodReply( message ); + +// QDBusError error; +// reply = QDBusMessage::methodError( message, error ); + + reply.append( QVariant( QString( "Hello!" ) ) ); + + return reply; +} + +QDBusMessage OpenSyncService::randomNumber( const QDBusMessage &message ) +{ + QDBusMessage reply = QDBusMessage::methodReply( message ); + + int number = rand(); + + reply.append( QVariant( number ) ); + + return reply; +} + +int main( int argc, char *argv[] ) +{ + QApplication app(argc, argv); + + std::cout << "Hello" << std::endl; + + QDBusConnection connection = QDBusConnection::addConnection( + QDBusConnection::SessionBus ); + + if ( !connection.isConnected() ) { + qFatal("Cannot connect to session bus"); + } + + connection.requestName( "org.opensync.SyncEngine", + QDBusConnection::NoReplace ); + + OpenSyncService service; + service.setConnection( &connection ); + + return app.exec(); +} + +//#include "dbusclient.moc" diff --git a/kitchensync/opensyncdbus/dbusclient.h b/kitchensync/opensyncdbus/dbusclient.h new file mode 100644 index 000000000..5cd6635f7 --- /dev/null +++ b/kitchensync/opensyncdbus/dbusclient.h @@ -0,0 +1,56 @@ +/* + This file is part of KDE. + + Copyright (c) 2006 Cornelius Schumacher <schumacher@kde.org> + + 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 DBUSCLIENT_H +#define DBUSCLIENT_H + +#include <qobject.h> + +#include <dbus/qdbusobject.h> + +class QDBusMessage; +class QDBusConnection; + +class OpenSyncService : public QDBusObjectBase +{ + public: + OpenSyncService(); + + void setConnection( QDBusConnection *connection ); + + protected: + virtual bool handleMethodCall( const QDBusMessage &message ); + + QDBusMessage hello( const QDBusMessage & ); + QDBusMessage randomNumber( const QDBusMessage & ); + + QDBusMessage listGroups( const QDBusMessage &message ); + QDBusMessage listPlugins( const QDBusMessage &message ); + QDBusMessage showGroup( const QDBusMessage &message ); + QDBusMessage showMember( const QDBusMessage &message ); + + QDBusMessage error( const QDBusMessage &, const QString &errorCode, + const QString &errorMessage ); + + private: + QDBusConnection *mConnection; +}; + +#endif |