--- kdebase-3.5.5/kioslave/media/configure.in.in.dbus 2006-10-01 19:31:54.000000000 +0200 +++ kdebase-3.5.5/kioslave/media/configure.in.in 2006-10-10 19:55:19.000000000 +0200 @@ -97,70 +97,6 @@ AC_SUBST(DBUS_INCS) AC_SUBST(DBUS_LIBS) - -########### Check for DBus-Qt3 bindings - - AC_MSG_CHECKING(for DBus-Qt3 bindings) - - dbusqt_inc=NOTFOUND - dbusqt_lib=NOTFOUND - dbusqt=NOTFOUND - - search_incs="$kde_includes $kde_extra_includes /usr/include /usr/include/dbus-1.0 /usr/local/include /usr/local/include/dbus-1.0" - AC_FIND_FILE(dbus/connection.h, $search_incs, dbusqt_incdir) - - if test -r $dbusqt_incdir/dbus/connection.h ; then - have_qt_patch=0 - grep dbus_connection_setup_with_qt_main $dbusqt_incdir/dbus/connection.h \ - > /dev/null 2>&1 && have_qt_patch=1 - if test $have_qt_patch = 1 ; then - DBUSQT_INCS="-I$dbusqt_incdir" - dbusqt_inc=FOUND - fi - fi - - search_libs="$kde_libraries $kde_extra_libs /usr/lib$kdelibsuff /usr/local/lib$kdelibsuff" - AC_FIND_FILE(libdbus-qt-1.so, $search_libs, dbusqt_libdir) - - if test -r $dbusqt_libdir/libdbus-qt-1.so ; then - DBUSQT_LIBS="-L$dbusqt_libdir -ldbus-qt-1" - dbusqt_lib=FOUND - fi - - if test $dbusqt_inc != FOUND || test $dbusqt_lib != FOUND ; then - - search_incs="`pkg-config --cflags dbus-1 |sed 's/-I//g'`" - AC_FIND_FILE(dbus/connection.h, $search_incs, dbusqt_incdir) - if test -r $dbusqt_incdir/dbus/connection.h ; then - have_qt_patch=0 - grep dbus_connection_setup_with_qt_main $dbusqt_incdir/dbus/connection.h \ - > /dev/null 2>&1 && have_qt_patch=1 - if test $have_qt_patch = 1 ; then - DBUSQT_INCS="-I$dbusqt_incdir" - dbusqt_inc=FOUND - fi - fi - - search_libs="`pkg-config --libs dbus-1 --libs-only-L | sed 's/-L//g'`" - AC_FIND_FILE(libdbus-qt-1.so, $search_libs, dbusqt_libdir) - - if test -r $dbusqt_libdir/libdbus-qt-1.so ; then - DBUSQT_LIBS="-L$dbusqt_libdir -ldbus-qt-1" - dbusqt_lib=FOUND - fi - - fi - - - if test $dbusqt_inc = FOUND && test $dbusqt_lib = FOUND ; then - AC_MSG_RESULT(headers $dbusqt_incdir libraries $dbusqt_libdir) - dbusqt=FOUND - else - AC_MSG_RESULT(searched but not found) - fi - - AC_SUBST(DBUSQT_INCS) - AC_SUBST(DBUSQT_LIBS) fi ########### Check if media HAL backend sould be compiled @@ -168,7 +104,7 @@ AC_MSG_CHECKING(if the HAL backend for media:/ should be compiled) HALBACKEND=no -if test "x$hal" = "xFOUND" && test "x$dbus" = "xFOUND" && test "x$dbusqt" = "xFOUND" ; then +if test "x$hal" = "xFOUND" && test "x$dbus" = "xFOUND" ; then AC_DEFINE_UNQUOTED([COMPILE_HALBACKEND],1, [media HAL backend compilation]) HALBACKEND=yes AC_SUBST(HALBACKEND) --- kdebase-3.5.5/kioslave/media/mediamanager/halbackend.h.dbus 2006-07-22 10:15:45.000000000 +0200 +++ kdebase-3.5.5/kioslave/media/mediamanager/halbackend.h 2006-10-10 17:41:42.000000000 +0200 @@ -40,7 +40,7 @@ /* We acknowledge the the dbus API is unstable */ #define DBUS_API_SUBJECT_TO_CHANGE /* DBus-Qt bindings */ -#include +#include /* HAL libraries */ #include #include --- /dev/null 2006-10-09 18:32:23.425560750 +0200 +++ kdebase-3.5.5/kioslave/media/mediamanager/connection.cpp 2006-10-10 17:41:42.000000000 +0200 @@ -0,0 +1,168 @@ +// -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; -*- +/* connection.cpp: Qt wrapper for DBusConnection + * + * Copyright (C) 2003 Zack Rusin + * + * Licensed under the Academic Free License version 2.0 + * + * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ +#include "connection.h" + +using namespace DBusQt; + +#include "integrator.h" +using Internal::Integrator; + +struct Connection::Private +{ + Private( Connection *qq ); + void setConnection( DBusConnection *c ); + DBusConnection *connection; + int connectionSlot; + DBusError error; + Integrator *integrator; + int timeout; + Connection *q; +}; + +Connection::Private::Private( Connection *qq ) + : connection( 0 ), connectionSlot( 0 ), integrator( 0 ), + timeout( -1 ), q( qq ) +{ + dbus_error_init( &error ); +} + +void Connection::Private::setConnection( DBusConnection *c ) +{ + if (!c) { + qDebug( "error: %s, %s", error.name, error.message ); + dbus_error_free( &error ); + return; + } + connection = c; + integrator = new Integrator( c, q ); + connect( integrator, SIGNAL(readReady()), q, SLOT(dispatchRead()) ); +} + +Connection::Connection( QObject *parent ) + : QObject( parent ) +{ + d = new Private( this ); +} + +Connection::Connection( const QString& host, QObject *parent ) + : QObject( parent ) +{ + d = new Private( this ); + + if ( !host.isEmpty() ) + init( host ); +} + +Connection::Connection( DBusBusType type, QObject* parent ) + : QObject( parent ) +{ + d = new Private( this ); + d->setConnection( dbus_bus_get(type, &d->error) ); +} + +void Connection::init( const QString& host ) +{ + d->setConnection( dbus_connection_open( host.ascii(), &d->error) ); + //dbus_connection_allocate_data_slot( &d->connectionSlot ); + //dbus_connection_set_data( d->connection, d->connectionSlot, 0, 0 ); +} + +bool Connection::isConnected() const +{ + return dbus_connection_get_is_connected( d->connection ); +} + +bool Connection::isAuthenticated() const +{ + return dbus_connection_get_is_authenticated( d->connection ); +} + +void Connection::open( const QString& host ) +{ + if ( host.isEmpty() ) return; + + init( host ); +} + +void Connection::close() +{ + dbus_connection_close( d->connection ); +} + +void Connection::flush() +{ + dbus_connection_flush( d->connection ); +} + +void Connection::dispatchRead() +{ + while ( dbus_connection_dispatch( d->connection ) == DBUS_DISPATCH_DATA_REMAINS ) + ; +} + +DBusConnection* Connection::connection() const +{ + return d->connection; +} + +Connection::Connection( DBusConnection *connection, QObject *parent ) + : QObject( parent ) +{ + d = new Private(this); + d->setConnection(connection); +} + +void Connection::send( const Message &m ) +{ + dbus_connection_send(d->connection, m.message(), 0); +} + +void Connection::sendWithReply( const Message& ) +{ +} + +Message Connection::sendWithReplyAndBlock( const Message &m ) +{ + DBusMessage *reply; + reply = dbus_connection_send_with_reply_and_block( d->connection, m.message(), d->timeout, &d->error ); + if (dbus_error_is_set(&d->error)) { + qDebug("error: %s, %s", d->error.name, d->error.message); + dbus_error_free(&d->error); + } + return Message( reply ); +} + +void* Connection::virtual_hook( int, void* ) +{ +} + +void Connection::dbus_connection_setup_with_qt_main (DBusConnection *connection) +{ + d->setConnection( connection ); +} + + + +///////////////////////////////////////////////////////// + +#include "connection.moc" --- /dev/null 2006-10-09 18:32:23.425560750 +0200 +++ kdebase-3.5.5/kioslave/media/mediamanager/connection.h 2006-10-10 17:41:42.000000000 +0200 @@ -0,0 +1,86 @@ +// -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; -*- +/* connection.h: Qt wrapper for DBusConnection + * + * Copyright (C) 2003 Zack Rusin + * + * Licensed under the Academic Free License version 2.1 + * + * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ +#ifndef DBUS_QT_CONNECTION_H +#define DBUS_QT_CONNECTION_H + +/* We acknowledge the the dbus API is unstable */ +#define DBUS_API_SUBJECT_TO_CHANGE + +#include "message.h" + +#include +#include + +#include "dbus/dbus.h" + +namespace DBusQt { + namespace Internal { + class Integrator; + } + + class Connection : public QObject + { + Q_OBJECT + public: + Connection( QObject *parent =0 ); + Connection( const QString& host, + QObject *parent = 0 ); + Connection( DBusBusType type, QObject* parent = 0 ); + + bool isConnected() const; + bool isAuthenticated() const; + + Message borrowMessage(); + Message popMessage(); + void stealBorrowMessage( const Message& ); + void dbus_connection_setup_with_qt_main (DBusConnection *connection); + + public slots: + void open( const QString& ); + void close(); + void flush(); + void send( const Message& ); + void sendWithReply( const Message& ); + Message sendWithReplyAndBlock( const Message& ); + + protected slots: + void dispatchRead(); + + protected: + void init( const QString& host ); + virtual void *virtual_hook( int id, void *data ); + + private: + friend class Internal::Integrator; + DBusConnection *connection() const; + Connection( DBusConnection *connection, QObject *parent ); + + private: + struct Private; + Private *d; + }; + +} + + +#endif --- /dev/null 2006-10-09 18:32:23.425560750 +0200 +++ kdebase-3.5.5/kioslave/media/mediamanager/message.h 2006-10-10 17:41:42.000000000 +0200 @@ -0,0 +1,132 @@ +/* -*- mode: C++; c-file-style: "gnu" -*- */ +/* message.h: Qt wrapper for DBusMessage + * + * Copyright (C) 2003 Zack Rusin + * + * Licensed under the Academic Free License version 2.1 + * + * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ +#ifndef DBUS_QT_MESSAGE_H +#define DBUS_QT_MESSAGE_H + +/* We acknowledge the the dbus API is unstable */ +#define DBUS_API_SUBJECT_TO_CHANGE + +#include +#include +#include + +#include "dbus/dbus.h" + +namespace DBusQt { + + class Message + { + public: + class iterator { + public: + iterator(); + iterator( const iterator& ); + iterator( DBusMessage* msg ); + ~iterator(); + + iterator& operator=( const iterator& ); + const QVariant& operator*() const; + QVariant& operator*(); + iterator& operator++(); + iterator operator++(int); + bool operator==( const iterator& it ); + bool operator!=( const iterator& it ); + + QVariant var() const; + protected: + QVariant marshallBaseType( DBusMessageIter* i ); + void fillVar(); + struct IteratorData; + IteratorData *d; + }; + + Message( int messageType ); + Message( DBusMessage * );//hide this one from the public implementation + Message( const QString& service, const QString& path, + const QString& interface, const QString& method ); + Message( const Message& replayingTo ); + Message( const QString& path, const QString& interface, + const QString& name ); + Message( const Message& replayingTo, const QString& errorName, + const QString& errorMessage ); + + Message operator=( const Message& other ); + + virtual ~Message(); + + int type() const; + + void setPath( const QString& ); + QString path() const; + + void setInterface( const QString& ); + QString interface() const; + + void setMember( const QString& ); + QString member() const; + + QString errorName() const; + + QString destination() const; + + bool setSender( const QString& sender ); + QString sender() const; + + QString signature() const; + + iterator begin() const; + iterator end() const; + + QVariant at( int i ); + + + public: + Message& operator<<( bool ); + Message& operator<<( Q_INT8 ); + Message& operator<<( Q_INT32 ); + Message& operator<<( Q_UINT32 ); + Message& operator<<( Q_INT64 ); + Message& operator<<( Q_UINT64 ); + Message& operator<<( double ); + Message& operator<<( const QString& ); + Message& operator<<( const QVariant& ); + //Message& operator<<(); + //Message& operator<<(); + //Message& operator<<(); + //Message& operator<<(); + //Message& operator<<(); + //Message& operator<<(); + //Message& operator<<(); + + protected: + friend class Connection; + DBusMessage* message() const; + + private: + struct Private; + Private *d; + }; + +} + +#endif --- /dev/null 2006-10-09 18:32:23.425560750 +0200 +++ kdebase-3.5.5/kioslave/media/mediamanager/integrator.h 2006-10-10 17:41:42.000000000 +0200 @@ -0,0 +1,95 @@ +// -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; -*- +/* integrator.h: integrates D-BUS into Qt event loop + * + * Copyright (C) 2003 Zack Rusin + * + * Licensed under the Academic Free License version 2.1 + * + * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ +#ifndef DBUS_QT_INTEGRATOR_H +#define DBUS_QT_INTEGRATOR_H + +/* We acknowledge the the dbus API is unstable */ +#define DBUS_API_SUBJECT_TO_CHANGE + +#include + +#include +#include + +#include "dbus/dbus.h" + +class QTimer; + +namespace DBusQt +{ + class Connection; + + namespace Internal + { + struct Watch; + + class Timeout : public QObject + { + Q_OBJECT + public: + Timeout( QObject *parent, DBusTimeout *t ); + public: + void start(); + signals: + void timeout( DBusTimeout* ); + protected slots: + void slotTimeout(); + private: + QTimer *m_timer; + DBusTimeout *m_timeout; + }; + + class Integrator : public QObject + { + Q_OBJECT + public: + Integrator( DBusConnection *connection, QObject *parent ); + Integrator( DBusServer *server, QObject *parent ); + + signals: + void readReady(); + void newConnection( Connection* ); + + protected slots: + void slotRead( int ); + void slotWrite( int ); + void slotTimeout( DBusTimeout *timeout ); + + public: + void addWatch( DBusWatch* ); + void removeWatch( DBusWatch* ); + + void addTimeout( DBusTimeout* ); + void removeTimeout( DBusTimeout* ); + + void handleConnection( DBusConnection* ); + private: + QIntDict m_watches; + QPtrDict m_timeouts; + DBusConnection *m_connection; + DBusServer *m_server; + }; + } +} + +#endif --- kdebase-3.5.5/kioslave/media/mediamanager/Makefile.am.dbus 2005-09-10 10:25:36.000000000 +0200 +++ kdebase-3.5.5/kioslave/media/mediamanager/Makefile.am 2006-10-10 17:41:42.000000000 +0200 @@ -1,17 +1,22 @@ kde_module_LTLIBRARIES = kded_mediamanager.la if include_media_halbackend -HALBACKEND_INCS = $(HAL_INCS) $(DBUS_INCS) $(DBUSQT_INCS) +HALBACKEND_INCS = $(HAL_INCS) $(DBUS_INCS) endif METASOURCES = AUTO INCLUDES = -I$(srcdir)/../libmediacommon -I../libmediacommon $(HALBACKEND_INCS) $(all_includes) +DBUSQT3BINDING_LIB = libdbusqt3.la +libdbusqt3_la_SOURCES = connection.cpp integrator.cpp message.cpp +libdbusqt3_la_LDFLAGS = -avoid-version $(all_libraries) -no-undefined +libdbusqt3_la_LIBADD = $(HAL_LIBS) $(DBUS_LIBS) + if include_media_halbackend HALBACKEND_LIB = libhalbackend.la libhalbackend_la_SOURCES = halbackend.cpp libhalbackend_la_LDFLAGS = -avoid-version $(all_libraries) -no-undefined -libhalbackend_la_LIBADD = $(HAL_LIBS) $(DBUS_LIBS) $(DBUSQT_LIBS) +libhalbackend_la_LIBADD = $(HAL_LIBS) $(DBUS_LIBS) $(DBUSQT3BINDING_LIB) endif if include_media_linuxcdpolling @@ -20,7 +25,7 @@ liblinuxcdpolling_la_LDFLAGS = -avoid-version $(all_libraries) -no-undefined endif -noinst_LTLIBRARIES = $(LINUXCDPOLLING_LIB) $(HALBACKEND_LIB) +noinst_LTLIBRARIES = $(LINUXCDPOLLING_LIB) $(HALBACKEND_LIB) $(DBUSQT3BINDING_LIB) kded_mediamanager_la_SOURCES = mediamanager.cpp mediamanager.skel medialist.cpp backendbase.cpp fstabbackend.cpp removablebackend.cpp mediadirnotify.cpp mediadirnotify.skel kded_mediamanager_la_LDFLAGS = $(all_libraries) -module -avoid-version --- /dev/null 2006-10-09 18:32:23.425560750 +0200 +++ kdebase-3.5.5/kioslave/media/mediamanager/message.cpp 2006-10-10 17:41:42.000000000 +0200 @@ -0,0 +1,551 @@ +/* -*- mode: C++; c-file-style: "gnu" -*- */ +/* message.cpp: Qt wrapper for DBusMessage + * + * Copyright (C) 2003 Zack Rusin + * + * Licensed under the Academic Free License version 2.0 + * + * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ +#include "message.h" + +#include + +#include + +namespace DBusQt { + +struct Message::iterator::IteratorData { + DBusMessageIter *iter; + QVariant var; + bool end; + DBusMessage *mesg; +}; + +/** + * Iterator. + */ +Message::iterator::iterator() +{ + d = new IteratorData; + d->iter = 0; d->end = true; +} + +/** + * Constructs iterator for the message. + * @param msg message whose fields we want to iterate + */ +Message::iterator::iterator( DBusMessage* msg ) +{ + d = new IteratorData; + d->mesg = msg; + d->iter = static_cast( malloc( sizeof(DBusMessageIter) ) ); + dbus_message_iter_init( d->mesg, d->iter ); + if ( !d->iter ) { + qDebug("No iterator??"); + } + fillVar(); + d->end = false; +} + +/** + * Copy constructor for the iterator. + * @param itr iterator + */ +Message::iterator::iterator( const iterator& itr ) +{ + d = new IteratorData; + d->iter = itr.d->iter; + d->var = itr.d->var; + d->end = itr.d->end; +} + +/** + * Destructor. + */ +Message::iterator::~iterator() +{ + free( d->iter ); + delete d; d=0; +} + +/** + * Creates an iterator equal to the @p itr iterator + * @param itr other iterator + * @return + */ +Message::iterator& +Message::iterator::operator=( const iterator& itr ) +{ + IteratorData *tmp = new IteratorData; + tmp->iter = itr.d->iter; + tmp->var = itr.d->var; + tmp->end = itr.d->end; + delete d; d=tmp; + return *this; +} + +/** + * Returns the constant QVariant held by the iterator. + * @return the constant reference to QVariant held by this iterator + */ +const QVariant& +Message::iterator::operator*() const +{ + return d->var; +} + +/** + * Returns the QVariant held by the iterator. + * @return reference to QVariant held by this iterator + */ +QVariant& +Message::iterator::operator*() +{ + return d->var; +} + +/** + * Moves to the next field and return a reference to itself after + * incrementing. + * @return reference to self after incrementing + */ +Message::iterator& +Message::iterator::operator++() +{ + if ( d->end ) + return *this; + + if ( dbus_message_iter_next( d->iter ) ) { + fillVar(); + } else { + d->end = true; + d->var = QVariant(); + } + return *this; +} + +/** + * Moves to the next field and returns self before incrementing. + * @return self before incrementing + */ +Message::iterator +Message::iterator::operator++(int) +{ + iterator itr( *this ); + operator++(); + return itr; +} + +/** + * Compares this iterator to @p it iterator. + * @param it the iterator to which we're comparing this one to + * @return true if they're equal, false otherwise + */ +bool +Message::iterator::operator==( const iterator& it ) +{ + if ( d->end == it.d->end ) { + if ( d->end == true ) { + return true; + } else { + return d->var == it.d->var; + } + } else + return false; +} + +/** + * Compares two iterators. + * @param it The other iterator. + * @return true if two iterators are not equal, false + * otherwise + */ +bool +Message::iterator::operator!=( const iterator& it ) +{ + return !operator==( it ); +} + +QVariant Message::iterator::marshallBaseType( DBusMessageIter* i ) +{ + QVariant ret; + switch (dbus_message_iter_get_arg_type(i)) { + case DBUS_TYPE_INT32: + { + dbus_int32_t v; + dbus_message_iter_get_basic (i, &v); + ret = QVariant( v ); + } + break; + case DBUS_TYPE_UINT32: + { + dbus_uint32_t v; + dbus_message_iter_get_basic (i, &v); + ret = QVariant( v ); + } + break; + case DBUS_TYPE_DOUBLE: + { + double v; + dbus_message_iter_get_basic (i, &v); + ret = QVariant( v ); + } + break; + case DBUS_TYPE_STRING: + { + const char *v; + dbus_message_iter_get_basic (i, &v); + ret = QVariant( v ); + } + break; + default: + ret = QVariant(); + break; + } + return ret; +} + +/** + * Fills QVariant based on what current DBusMessageIter helds. + */ +void +Message::iterator::fillVar() +{ + switch ( dbus_message_iter_get_arg_type( d->iter ) ) { + case DBUS_TYPE_INT32: + case DBUS_TYPE_UINT32: + case DBUS_TYPE_DOUBLE: + case DBUS_TYPE_STRING: + d->var = marshallBaseType( d->iter ); + break; + case DBUS_TYPE_ARRAY: { + switch ( dbus_message_iter_get_element_type( d->iter ) ) { + case DBUS_TYPE_STRING: { + QStringList tempList; + DBusMessageIter sub; + dbus_message_iter_recurse (d->iter, &sub); + while (dbus_message_iter_get_arg_type (&sub) != DBUS_TYPE_INVALID) + { + const char *v; + dbus_message_iter_get_basic (&sub, &v); + tempList.append( QString( v ) ); + dbus_message_iter_next (&sub); + } + d->var = QVariant( tempList ); + break; + } + default: + qDebug( "Array of type not implemented" ); + d->var = QVariant(); + break; + } + break; + } +#if 0 + /* DICT is gone for now, but expected to be reintroduced, or else + * reintroduced as a flag on the introspection data that can + * apply to array of struct of two fields + */ + case DBUS_TYPE_DICT: { + qDebug( "Got a hash!" ); + QMap tempMap; + DBusMessageIter dictIter; + dbus_message_iter_init_dict_iterator( d->iter, &dictIter ); + do { + char *key = dbus_message_iter_get_dict_key( &dictIter ); + tempMap[key] = marshallBaseType( &dictIter ); + dbus_free( key ); + dbus_message_iter_next( &dictIter ); + } while( dbus_message_iter_has_next( &dictIter ) ); + d->var = QVariant( tempMap ); + break; + qDebug( "Hash/Dict type not implemented" ); + d->var = QVariant(); + break; + } +#endif + default: + qDebug( "not implemented" ); + d->var = QVariant(); + break; + } +} + +/** + * Returns a QVariant help by this iterator. + * @return QVariant held by this iterator + */ +QVariant +Message::iterator::var() const +{ + return d->var; +} + +struct Message::Private { + DBusMessage *msg; +}; + +Message::Message( DBusMessage *m ) +{ + d = new Private; + d->msg = m; +} + +/** + * + */ +Message::Message( int messageType ) +{ + d = new Private; + d->msg = dbus_message_new( messageType ); +} + +/** + * Constructs a new Message with the given service and name. + * @param service service service that the message should be sent to + * @param name name of the message + */ +Message::Message( const QString& service, const QString& path, + const QString& interface, const QString& method ) +{ + d = new Private; + d->msg = dbus_message_new_method_call( service.latin1(), path.latin1(), + interface.latin1(), method.latin1() ); +} + +/** + * Constructs a message that is a reply to some other + * message. + * @param name the name of the message + * @param replayingTo original_message the message which the created + * message is a reply to. + */ +Message::Message( const Message& replayingTo ) +{ + d = new Private; + d->msg = dbus_message_new_method_return( replayingTo.d->msg ); +} + +Message:: Message( const QString& path, const QString& interface, + const QString& name ) +{ + d = new Private; + d->msg = dbus_message_new_signal( path.ascii(), interface.ascii(), + name.ascii() ); +} + +Message::Message( const Message& replayingTo, const QString& errorName, + const QString& errorMessage ) +{ + d = new Private; + d->msg = dbus_message_new_error( replayingTo.d->msg, errorName.utf8(), + errorMessage.utf8() ); +} + +Message Message::operator=( const Message& other ) +{ + //FIXME: ref the other.d->msg instead of copying it? +} +/** + * Destructs message. + */ +Message::~Message() +{ + if ( d->msg ) { + dbus_message_unref( d->msg ); + } + delete d; d=0; +} + +int Message::type() const +{ + return dbus_message_get_type( d->msg ); +} + +void Message::setPath( const QString& path ) +{ + dbus_message_set_path( d->msg, path.ascii() ); +} + +QString Message::path() const +{ + return dbus_message_get_path( d->msg ); +} + +void Message::setInterface( const QString& iface ) +{ + dbus_message_set_interface( d->msg, iface.ascii() ); +} + +QString Message::interface() const +{ + return dbus_message_get_interface( d->msg ); +} + +void Message::setMember( const QString& member ) +{ + dbus_message_set_member( d->msg, member.ascii() ); +} + +QString Message::member() const +{ + return dbus_message_get_member( d->msg ); +} + +QString Message::errorName() const +{ + return dbus_message_get_error_name( d->msg ); +} + +QString Message::destination() const +{ + return dbus_message_get_destination( d->msg ); +} + +/** + * Sets the message sender. + * @param sender the sender + * @return false if unsuccessful + */ +bool +Message::setSender( const QString& sender ) +{ + return dbus_message_set_sender( d->msg, sender.latin1() ); +} + +/** + * Returns sender of this message. + * @return sender + */ +QString +Message::sender() const +{ + return dbus_message_get_sender( d->msg ); +} + +QString Message::signature() const +{ + return dbus_message_get_signature( d->msg ); +} + + +/** + * Returns the starting iterator for the fields of this + * message. + * @return starting iterator + */ +Message::iterator +Message::begin() const +{ + return iterator( d->msg ); +} + +/** + * Returns the ending iterator for the fields of this + * message. + * @return ending iterator + */ +Message::iterator +Message::end() const +{ + return iterator(); +} + +/** + * Returns the field at position @p i + * @param i position of the wanted field + * @return QVariant at position @p i or an empty QVariant + */ +QVariant +Message::at( int i ) +{ + iterator itr( d->msg ); + + while ( i-- ) { + if ( itr == end() ) + return QVariant();//nothing there + ++itr; + } + return *itr; +} + +/** + * The underlying DBusMessage of this class. + * @return DBusMessage pointer. + */ +DBusMessage* +Message::message() const +{ + return d->msg; +} + +Message& Message::operator<<( bool b ) +{ + const dbus_bool_t right_size_bool = b; + dbus_message_append_args( d->msg, DBUS_TYPE_BOOLEAN, &right_size_bool, + DBUS_TYPE_INVALID ); +} + +Message& Message::operator<<( Q_INT8 byte ) +{ + dbus_message_append_args( d->msg, DBUS_TYPE_BYTE, &byte, + DBUS_TYPE_INVALID ); +} + +Message& Message::operator<<( Q_INT32 num ) +{ + dbus_message_append_args( d->msg, DBUS_TYPE_INT32, &num, + DBUS_TYPE_INVALID ); +} + +Message& Message::operator<<( Q_UINT32 num ) +{ + dbus_message_append_args( d->msg, DBUS_TYPE_UINT32, &num, + DBUS_TYPE_INVALID ); +} + +Message& Message::operator<<( Q_INT64 num ) +{ + dbus_message_append_args( d->msg, DBUS_TYPE_INT64, &num, + DBUS_TYPE_INVALID ); +} + +Message& Message::operator<<( Q_UINT64 num ) +{ + dbus_message_append_args( d->msg, DBUS_TYPE_UINT64, &num, + DBUS_TYPE_INVALID ); +} + +Message& Message::operator<<( double num ) +{ + dbus_message_append_args( d->msg, DBUS_TYPE_DOUBLE, &num, + DBUS_TYPE_INVALID ); +} + +Message& Message::operator<<( const QString& str ) +{ + const char *u = str.utf8(); + dbus_message_append_args( d->msg, DBUS_TYPE_STRING, &u, + DBUS_TYPE_INVALID ); +} + +Message& Message::operator<<( const QVariant& custom ) +{ + //FIXME: imeplement +} + +} --- /dev/null 2006-10-09 18:32:23.425560750 +0200 +++ kdebase-3.5.5/kioslave/media/mediamanager/integrator.cpp 2006-10-10 17:41:42.000000000 +0200 @@ -0,0 +1,244 @@ +// -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; -*- +/* integrator.h: integrates D-BUS into Qt event loop + * + * Copyright (C) 2003 Zack Rusin + * + * Licensed under the Academic Free License version 2.0 + * + * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ +#include "integrator.h" +#include "connection.h" + +#include +#include +#include +#include + +namespace DBusQt +{ +namespace Internal { + +struct Watch { + Watch(): readSocket( 0 ), writeSocket( 0 ) { } + + DBusWatch *watch; + QSocketNotifier *readSocket; + QSocketNotifier *writeSocket; +}; + +////////////////////////////////////////////////////////////// +dbus_bool_t dbusAddWatch( DBusWatch *watch, void *data ) +{ + Integrator *con = static_cast( data ); + con->addWatch( watch ); + return true; +} +void dbusRemoveWatch( DBusWatch *watch, void *data ) +{ + Integrator *con = static_cast( data ); + con->removeWatch( watch ); +} + +void dbusToggleWatch( DBusWatch *watch, void *data ) +{ + Integrator *itg = static_cast( data ); + if ( dbus_watch_get_enabled( watch ) ) + itg->addWatch( watch ); + else + itg->removeWatch( watch ); +} + +dbus_bool_t dbusAddTimeout( DBusTimeout *timeout, void *data ) +{ + if ( !dbus_timeout_get_enabled(timeout) ) + return true; + + Integrator *itg = static_cast( data ); + itg->addTimeout( timeout ); + return true; +} + +void dbusRemoveTimeout( DBusTimeout *timeout, void *data ) +{ + Integrator *itg = static_cast( data ); + itg->removeTimeout( timeout ); +} + +void dbusToggleTimeout( DBusTimeout *timeout, void *data ) +{ + Integrator *itg = static_cast( data ); + + if ( dbus_timeout_get_enabled( timeout ) ) + itg->addTimeout( timeout ); + else + itg->removeTimeout( timeout ); +} + +void dbusWakeupMain( void* ) +{ +} + +void dbusNewConnection( DBusServer *server, + DBusConnection *new_connection, + void *data ) +{ + Integrator *itg = static_cast( data ); + itg->handleConnection( new_connection ); +} +///////////////////////////////////////////////////////////// + +Timeout::Timeout( QObject *parent, DBusTimeout *t ) + : QObject( parent ), m_timeout( t ) +{ + m_timer = new QTimer( this ); + connect( m_timer, SIGNAL(timeout()), + SLOT(slotTimeout()) ); +} + +void Timeout::slotTimeout() +{ + emit timeout( m_timeout ); +} + +void Timeout::start() +{ + m_timer->start( dbus_timeout_get_interval( m_timeout ) ); +} + +Integrator::Integrator( DBusConnection *conn, QObject *parent ) + : QObject( parent ), m_connection( conn ) +{ + m_timeouts.setAutoDelete( true ); + + dbus_connection_set_watch_functions( m_connection, + dbusAddWatch, + dbusRemoveWatch, + dbusToggleWatch, + this, 0 ); + dbus_connection_set_timeout_functions( m_connection, + dbusAddTimeout, + dbusRemoveTimeout, + dbusToggleTimeout, + this, 0 ); + dbus_connection_set_wakeup_main_function( m_connection, + dbusWakeupMain, + this, 0 ); +} + +Integrator::Integrator( DBusServer *server, QObject *parent ) + : QObject( parent ), m_server( server ) +{ + m_connection = reinterpret_cast( m_server ); + m_timeouts.setAutoDelete( true ); + + dbus_server_set_watch_functions( m_server, + dbusAddWatch, + dbusRemoveWatch, + dbusToggleWatch, + this, 0 ); + dbus_server_set_timeout_functions( m_server, + dbusAddTimeout, + dbusRemoveTimeout, + dbusToggleTimeout, + this, 0 ); + dbus_server_set_new_connection_function( m_server, + dbusNewConnection, + this, 0 ); +} + +void Integrator::slotRead( int fd ) +{ + QIntDictIterator it( m_watches ); + for ( ; it.current(); ++it ) + dbus_watch_handle ( it.current()->watch, DBUS_WATCH_READABLE ); + + emit readReady(); +} + +void Integrator::slotWrite( int fd ) +{ + QIntDictIterator it( m_watches ); + for ( ; it.current(); ++it ) + dbus_watch_handle ( it.current()->watch, DBUS_WATCH_WRITABLE ); +} + +void Integrator::slotTimeout( DBusTimeout *timeout ) +{ + dbus_timeout_handle( timeout ); +} + +void Integrator::addWatch( DBusWatch *watch ) +{ + if ( !dbus_watch_get_enabled( watch ) ) + return; + + Watch *qtwatch = new Watch; + qtwatch->watch = watch; + + int flags = dbus_watch_get_flags( watch ); + int fd = dbus_watch_get_fd( watch ); + + if ( flags & DBUS_WATCH_READABLE ) { + qtwatch->readSocket = new QSocketNotifier( fd, QSocketNotifier::Read, this ); + QObject::connect( qtwatch->readSocket, SIGNAL(activated(int)), SLOT(slotRead(int)) ); + } + + if (flags & DBUS_WATCH_WRITABLE) { + qtwatch->writeSocket = new QSocketNotifier( fd, QSocketNotifier::Write, this ); + QObject::connect( qtwatch->writeSocket, SIGNAL(activated(int)), SLOT(slotWrite(int)) ); + } + + m_watches.insert( fd, qtwatch ); +} + +void Integrator::removeWatch( DBusWatch *watch ) +{ + int key = dbus_watch_get_fd( watch ); + + Watch *qtwatch = m_watches.take( key ); + + if ( qtwatch ) { + delete qtwatch->readSocket; qtwatch->readSocket = 0; + delete qtwatch->writeSocket; qtwatch->writeSocket = 0; + delete qtwatch; + } +} + +void Integrator::addTimeout( DBusTimeout *timeout ) +{ + Timeout *mt = new Timeout( this, timeout ); + m_timeouts.insert( timeout, mt ); + connect( mt, SIGNAL(timeout(DBusTimeout*)), + SLOT(slotTimeout(DBusTimeout*)) ); + mt->start(); +} + +void Integrator::removeTimeout( DBusTimeout *timeout ) +{ + m_timeouts.remove( timeout ); +} + +void Integrator::handleConnection( DBusConnection *c ) +{ + Connection *con = new Connection( c, this ); + emit newConnection( con ); +} + +}//end namespace Internal +}//end namespace DBusQt + +#include "integrator.moc"