rpms/knetworkmanager/devel knetworkmanager-dbus.patch, NONE, 1.1 .cvsignore, 1.2, 1.3 knetworkmanager.spec, 1.1, 1.2 sources, 1.2, 1.3

Dennis Gilmore (ausil) fedora-extras-commits at redhat.com
Fri Aug 11 02:22:32 UTC 2006


Author: ausil

Update of /cvs/extras/rpms/knetworkmanager/devel
In directory cvs-int.fedora.redhat.com:/tmp/cvs-serv32487

Modified Files:
	.cvsignore knetworkmanager.spec sources 
Added Files:
	knetworkmanager-dbus.patch 
Log Message:
patch in DBUS qt3  support


knetworkmanager-dbus.patch:

--- NEW FILE knetworkmanager-dbus.patch ---
diff -Nur knetworkmanager-orig/knetworkmanager/configure.in.in knetworkmanager/knetworkmanager/configure.in.in
--- knetworkmanager-orig/knetworkmanager/configure.in.in	2006-03-30 05:26:31.000000000 -0600
+++ knetworkmanager/knetworkmanager/configure.in.in	2006-08-10 20:30:08.000000000 -0500
@@ -36,10 +36,6 @@
   CPPFLAGS="$CPPFLAGS $PACKAGE_CFLAGS $all_includes"
   AC_LANG_SAVE
   AC_LANG_CPLUSPLUS
-  AC_CHECK_HEADER([dbus/connection.h],,[
-     AC_MSG_WARN([You need D-BUS/Qt3 bindings])
-     DO_NOT_COMPILE="$DO_NOT_COMPILE knetworkmanager"
-  ])
   CPPFLAGS=$safe_CPPFLAGS
   AC_LANG_RESTORE
 
diff -Nur knetworkmanager-orig/knetworkmanager/src/connection.cpp knetworkmanager/knetworkmanager/src/connection.cpp
--- knetworkmanager-orig/knetworkmanager/src/connection.cpp	1969-12-31 18:00:00.000000000 -0600
+++ knetworkmanager/knetworkmanager/src/connection.cpp	2006-08-10 20:28:53.000000000 -0500
@@ -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 <zack at kde.org>
+ *
+ * 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"
diff -Nur knetworkmanager-orig/knetworkmanager/src/connection.h knetworkmanager/knetworkmanager/src/connection.h
--- knetworkmanager-orig/knetworkmanager/src/connection.h	1969-12-31 18:00:00.000000000 -0600
+++ knetworkmanager/knetworkmanager/src/connection.h	2006-08-10 20:30:37.000000000 -0500
@@ -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 <zack at kde.org>
+ *
+ * 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 <qobject.h>
+#include <qstring.h>
+
+#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
diff -Nur knetworkmanager-orig/knetworkmanager/src/integrator.cpp knetworkmanager/knetworkmanager/src/integrator.cpp
--- knetworkmanager-orig/knetworkmanager/src/integrator.cpp	1969-12-31 18:00:00.000000000 -0600
+++ knetworkmanager/knetworkmanager/src/integrator.cpp	2006-08-10 20:29:05.000000000 -0500
@@ -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 <zack at kde.org>
+ *
+ * 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 <qtimer.h>
+#include <qsocketnotifier.h>
+#include <qintdict.h>
+#include <qptrlist.h>
+
+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<Integrator*>( data );
+  con->addWatch( watch );
+  return true;
+}
+void dbusRemoveWatch( DBusWatch *watch, void *data )
+{
+  Integrator *con = static_cast<Integrator*>( data );
+  con->removeWatch( watch );
+}
+
+void dbusToggleWatch( DBusWatch *watch, void *data )
+{
+  Integrator *itg = static_cast<Integrator*>( 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<Integrator*>( data );
+  itg->addTimeout( timeout );
+  return true;
+}
+
+void dbusRemoveTimeout( DBusTimeout *timeout, void *data )
+{
+  Integrator *itg = static_cast<Integrator*>( data );
+  itg->removeTimeout( timeout );
+}
+
+void dbusToggleTimeout( DBusTimeout *timeout, void *data )
+{
+  Integrator *itg = static_cast<Integrator*>( 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<Integrator*>( 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<DBusConnection*>( 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<Watch>	it( m_watches );
+  for ( ; it.current(); ++it )
+    dbus_watch_handle ( it.current()->watch, DBUS_WATCH_READABLE );
+
+  emit readReady();
+}
+
+void Integrator::slotWrite( int fd )
+{
+  QIntDictIterator<Watch>       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"
diff -Nur knetworkmanager-orig/knetworkmanager/src/integrator.h knetworkmanager/knetworkmanager/src/integrator.h
--- knetworkmanager-orig/knetworkmanager/src/integrator.h	1969-12-31 18:00:00.000000000 -0600
+++ knetworkmanager/knetworkmanager/src/integrator.h	2006-08-10 20:29:05.000000000 -0500
@@ -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 <zack at kde.org>
+ *
+ * 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 <qobject.h>
+
+#include <qintdict.h>
+#include <qptrdict.h>
+
+#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<Watch> m_watches;
+      QPtrDict<Timeout> m_timeouts;
+      DBusConnection *m_connection;
+      DBusServer *m_server;
+    };
+  }
+}
+
+#endif
diff -Nur knetworkmanager-orig/knetworkmanager/src/knetworkmanager-dbus.h knetworkmanager/knetworkmanager/src/knetworkmanager-dbus.h
--- knetworkmanager-orig/knetworkmanager/src/knetworkmanager-dbus.h	2006-03-29 08:56:52.000000000 -0600
+++ knetworkmanager/knetworkmanager/src/knetworkmanager-dbus.h	2006-08-10 20:31:08.000000000 -0500
@@ -27,7 +27,7 @@
 
 class KNetworkManager;
 
-#include <dbus/connection.h>
+#include <connection.h>
 #include <NetworkManager/NetworkManager.h>
 #include <NetworkManager/NetworkManagerVPN.h>
 
diff -Nur knetworkmanager-orig/knetworkmanager/src/knetworkmanager.la.cpp knetworkmanager/knetworkmanager/src/knetworkmanager.la.cpp
--- knetworkmanager-orig/knetworkmanager/src/knetworkmanager.la.cpp	1969-12-31 18:00:00.000000000 -0600
+++ knetworkmanager/knetworkmanager/src/knetworkmanager.la.cpp	2006-08-10 20:39:46.000000000 -0500
@@ -0,0 +1,2 @@
+extern "C" int kdemain(int argc, char* argv[]);
+int main(int argc, char* argv[]) { return kdemain(argc,argv); }
diff -Nur knetworkmanager-orig/knetworkmanager/src/Makefile.am knetworkmanager/knetworkmanager/src/Makefile.am
--- knetworkmanager-orig/knetworkmanager/src/Makefile.am	2006-08-10 20:26:11.000000000 -0500
+++ knetworkmanager/knetworkmanager/src/Makefile.am	2006-08-10 20:38:01.000000000 -0500
@@ -38,12 +38,16 @@
 	knetworkmanager-ui-networklistview.cpp \
 	knetworkmanager-vpn.cpp knetworkmanager-vpn_dbus.cpp serviceiface.stub networkstatuscommon.cpp
 
+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)
 
 kde_kcfg_DATA = knetworkmanager.kcfg
 
 knetworkmanager_la_LDFLAGS = -module $(KDE_RPATH) $(all_libraries) \
 	$(KDE_PLUGIN)
-knetworkmanager_la_LIBADD = -ldbus-qt-1 $(PACKAGE_LIBS) \
+knetworkmanager_la_LIBADD = $(DBUSQT3BINDING_LIB) $(PACKAGE_LIBS) \
 	$(LIB_KDEUI) -lkwalletclient -lkdeui -lkio
 
 # this is where the desktop file will go 
@@ -58,3 +62,4 @@
 mydatadir    = $(kde_datadir)/knetworkmanager
 mydata_DATA  = eventsrc
 
+noinst_LTLIBRARIES = $(DBUSQT3BINDING_LIB)
diff -Nur knetworkmanager-orig/knetworkmanager/src/message.cpp knetworkmanager/knetworkmanager/src/message.cpp
--- knetworkmanager-orig/knetworkmanager/src/message.cpp	1969-12-31 18:00:00.000000000 -0600
+++ knetworkmanager/knetworkmanager/src/message.cpp	2006-08-10 20:29:21.000000000 -0500
@@ -0,0 +1,551 @@
+/* -*- mode: C++; c-file-style: "gnu" -*- */
+/* message.cpp: Qt wrapper for DBusMessage
+ *
+ * Copyright (C) 2003  Zack Rusin <zack at kde.org>
+ *
+ * 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 <qmap.h>
+
+#include <cstdlib>
+
+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<DBusMessageIter *>( 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<QString, QVariant> 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
+}
+
+}
diff -Nur knetworkmanager-orig/knetworkmanager/src/message.h knetworkmanager/knetworkmanager/src/message.h
--- knetworkmanager-orig/knetworkmanager/src/message.h	1969-12-31 18:00:00.000000000 -0600
+++ knetworkmanager/knetworkmanager/src/message.h	2006-08-10 20:29:21.000000000 -0500
@@ -0,0 +1,132 @@
+/* -*- mode: C++; c-file-style: "gnu" -*- */
+/* message.h: Qt wrapper for DBusMessage
+ *
+ * Copyright (C) 2003  Zack Rusin <zack at kde.org>
+ *
+ * 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 <qvariant.h>
+#include <qstring.h>
+#include <qstringlist.h>
+
+#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


Index: .cvsignore
===================================================================
RCS file: /cvs/extras/rpms/knetworkmanager/devel/.cvsignore,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- .cvsignore	26 Jun 2006 17:30:11 -0000	1.2
+++ .cvsignore	11 Aug 2006 02:22:31 -0000	1.3
@@ -1 +1 @@
-knetworkmanager-svn20060625.tar.bz2
+knetworkmanager-svn20060809.tar.bz2


Index: knetworkmanager.spec
===================================================================
RCS file: /cvs/extras/rpms/knetworkmanager/devel/knetworkmanager.spec,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- knetworkmanager.spec	26 Jun 2006 17:30:11 -0000	1.1
+++ knetworkmanager.spec	11 Aug 2006 02:22:31 -0000	1.2
@@ -1,4 +1,4 @@
-%define		svn svn20060625
+%define		svn svn20060809
 
 Name:           knetworkmanager
 Version:        0.1
@@ -17,9 +17,12 @@
 Patch0:		http://aur.archlinux.org/packages/knetworkmanager-svn/knetworkmanager-svn/01-build-fix.patch
 # Suse Hard coded yast for dialup configuration. this patch calls System-config-network instead
 Patch1:		knetworkmanager-call-scn-not-yast.patch
+# Patch adds dbus support  as dbusqt3 is no longer in extras
+Patch2:		knetworkmanager-dbus.patch
+
 BuildRoot:      %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
 
-BuildRequires:  NetworkManager-devel >= 0.6.2 dbus-qt-devel autoconf automake
+BuildRequires:  NetworkManager-devel >= 0.6.2 dbus-devel autoconf automake
 BuildRequires:  desktop-file-utils kdebase-devel hal-devel
 
 %description
@@ -30,6 +33,7 @@
 %setup -q -n knetworkmanager
 %patch0 -p0 
 %patch1 -p1 -b .eww-yast
+%patch2 -p1 -b .dbus
 
 %build
 unset QTDIR || : ; . /etc/profile.d/qt.sh
@@ -46,6 +50,10 @@
 desktop-file-install \
 --dir $RPM_BUILD_ROOT%{_datadir}/applications \
 --vendor=fedora \
+--remove-category=Applet \
+--remove-category=Network \
+--add-category=Applications \
+--add-category=System \
 --add-category=X-Fedora \
 --delete-original \
 $RPM_BUILD_ROOT%{_datadir}/applications/kde/knetworkmanager.desktop
@@ -85,6 +93,9 @@
 
 
 %changelog
+* Thu Aug 10 2006 <dennis at ausil.us> - 0.1-0.3.svn20060809
+- patch in dbus support
+
 * Mon Jun 27 2006 <dennis at ausil.us> - 0.1-0.3.svn20060626
 - patch out call to yast and replace with 
 - system-config-network for dialup


Index: sources
===================================================================
RCS file: /cvs/extras/rpms/knetworkmanager/devel/sources,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- sources	26 Jun 2006 17:30:11 -0000	1.2
+++ sources	11 Aug 2006 02:22:31 -0000	1.3
@@ -1 +1 @@
-9576bce2cd34350d257e94a8b31efa86  knetworkmanager-svn20060625.tar.bz2
+b1beb9c583eddb48ac398e3b0262f2d1  knetworkmanager-svn20060809.tar.bz2




More information about the fedora-extras-commits mailing list