23#include <qgpgme/eventloopinteractor.h>
25#include <gpgme++/global.h>
28#include <QSignalMapper>
30Q_GLOBAL_STATIC( QSignalMapper, readSignalMapper )
31Q_GLOBAL_STATIC( QSignalMapper, writeSignalMapper )
33static QSignalMapper * setupReadSignalMapper( QObject * o ) {
34 QSignalMapper * sm = readSignalMapper();
35 o->connect( sm, SIGNAL(mapped(
int)), SLOT(slotReadActivity(
int)) );
39static QSignalMapper * setupWriteSignalMapper( QObject * o ) {
40 QSignalMapper * sm = writeSignalMapper();
41 o->connect( sm, SIGNAL(mapped(
int)), SLOT(slotWriteActivity(
int)) );
48 QGpgME::EventLoopInteractor::Direction direction;
52void * QGpgME::EventLoopInteractor::registerWatcher(
int fd, Direction dir,
bool & ok ) {
53 QIODevice *
const iod = GpgME::getQIODevice( fd );
59 static QSignalMapper * rsm = setupReadSignalMapper(
this );
60 if ( !rsm->mapping( fd ) ) {
61 rsm->setMapping( iod, fd );
62 connect( iod, SIGNAL(readyRead()), rsm, SLOT(map()) );
69 QMetaObject::invokeMethod(
this,
"slotReadActivity", Qt::QueuedConnection, Q_ARG(
int, fd ) );
72 static QSignalMapper * wsm = setupWriteSignalMapper(
this );
73 if ( !wsm->mapping( fd ) ) {
74 wsm->setMapping( iod, fd );
75 connect( iod, SIGNAL(bytesWritten(qint64)), wsm, SLOT(map()) );
82 QMetaObject::invokeMethod(
this,
"slotWriteActivity", Qt::QueuedConnection, Q_ARG(
int, fd ) );
87 IO *
const io =
new IO;
90 iod->bytesAvailable();
95void QGpgME::EventLoopInteractor::unregisterWatcher(
void * tag ) {
99 const IO *
const io =
static_cast<IO*
>( tag );
100 if ( io->direction == Read ) {
103 static QSignalMapper * rsm = readSignalMapper();
104 disconnect( io->device, SIGNAL(readyRead()), rsm, SLOT(map()) );
106 static QSignalMapper * wsm = writeSignalMapper();
107 disconnect( io->device, SIGNAL(bytesWritten(qint64)), wsm, SLOT(map()) );