• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepimlibs API Reference
  • KDE Home
  • Contact Us
 

qgpgme

  • sources
  • kde-4.14
  • kdepimlibs
  • qgpgme
eventloopinteractor_win.cpp
1 /* qeventloopinteractor.cpp
2  Copyright (C) 2003 Klarälvdalens Datakonsult AB
3 
4  This file is part of QGPGME.
5 
6  QGPGME is free software; you can redistribute it and/or modify it
7  under the terms of the GNU Library General Public License as published
8  by the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10 
11  QGPGME is distributed in the hope that it will be useful, but
12  WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU Library General Public License for more details.
15 
16  You should have received a copy of the GNU Library General Public License
17  along with QGPGME; see the file COPYING.LIB. If not, write to the
18  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  Boston, MA 02110-1301, USA. */
20 
21 // -*- c++ -*-
22 
23 #include <qgpgme/eventloopinteractor.h>
24 
25 #include <gpgme++/global.h>
26 
27 #include <QIODevice>
28 #include <QSignalMapper>
29 
30 Q_GLOBAL_STATIC( QSignalMapper, readSignalMapper )
31 Q_GLOBAL_STATIC( QSignalMapper, writeSignalMapper )
32 
33 static QSignalMapper * setupReadSignalMapper( QObject * o ) {
34  QSignalMapper * sm = readSignalMapper();
35  o->connect( sm, SIGNAL(mapped(int)), SLOT(slotReadActivity(int)) );
36  return sm;
37 }
38 
39 static QSignalMapper * setupWriteSignalMapper( QObject * o ) {
40  QSignalMapper * sm = writeSignalMapper();
41  o->connect( sm, SIGNAL(mapped(int)), SLOT(slotWriteActivity(int)) );
42  return sm;
43 }
44 
45 namespace {
46  struct IO {
47  QIODevice * device;
48  QGpgME::EventLoopInteractor::Direction direction;
49  };
50 }
51 
52 void * QGpgME::EventLoopInteractor::registerWatcher( int fd, Direction dir, bool & ok ) {
53  QIODevice * const iod = GpgME::getQIODevice( fd );
54  if ( !iod ) {
55  ok = false;
56  return 0;
57  }
58  if ( dir == Read ) {
59  static QSignalMapper * rsm = setupReadSignalMapper( this );
60  if ( !rsm->mapping( fd ) ) {
61  rsm->setMapping( iod, fd );
62  connect( iod, SIGNAL(readyRead()), rsm, SLOT(map()) );
63  } else {
64  // if this fd is already registered, gpgme registers an additional
65  // callback for the same fd.
66  // if there is already something to read when registering the new
67  // callback, gpgme expects the new callback to be called, so we
68  // trigger it"
69  QMetaObject::invokeMethod( this, "slotReadActivity", Qt::QueuedConnection, Q_ARG( int, fd ) );
70  }
71  } else {
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()) );
76  } else {
77  // if this fd is already registered, gpgme registers an additional
78  // callback for the same fd.
79  // if the device is writable when registering the new
80  // callback, gpgme expects the new callback to be called, so we
81  // trigger it:
82  QMetaObject::invokeMethod( this, "slotWriteActivity", Qt::QueuedConnection, Q_ARG( int, fd ) );
83  }
84  }
85 
86  ok = true;
87  IO * const io = new IO;
88  io->device = iod;
89  io->direction = dir;
90  iod->bytesAvailable(); //HACK: tell KDPipeIODevices to start their threads
91  iod->bytesToWrite();
92  return io;
93 }
94 
95 void QGpgME::EventLoopInteractor::unregisterWatcher( void * tag ) {
96  if ( !tag ) {
97  return;
98  }
99  const IO * const io = static_cast<IO*>( tag );
100  if ( io->direction == Read ) {
101  // no setupReadSignalMapper here, since registerWatcher,
102  // called before us, is guaranteed to have set it up
103  static QSignalMapper * rsm = readSignalMapper();
104  disconnect( io->device, SIGNAL(readyRead()), rsm, SLOT(map()) );
105  } else {
106  static QSignalMapper * wsm = writeSignalMapper();
107  disconnect( io->device, SIGNAL(bytesWritten(qint64)), wsm, SLOT(map()) );
108  }
109  delete io;
110 }
QIODevice
QIODevice::bytesToWrite
virtual qint64 bytesToWrite() const
QSignalMapper::setMapping
void setMapping(QObject *sender, int id)
QObject
QtConcurrent::map
QFuture< void > map(Sequence &sequence, MapFunction function)
QIODevice::bytesAvailable
virtual qint64 bytesAvailable() const
QMetaObject::invokeMethod
bool invokeMethod(QObject *obj, const char *member, Qt::ConnectionType type, QGenericReturnArgument ret, QGenericArgument val0, QGenericArgument val1, QGenericArgument val2, QGenericArgument val3, QGenericArgument val4, QGenericArgument val5, QGenericArgument val6, QGenericArgument val7, QGenericArgument val8, QGenericArgument val9)
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QSignalMapper
QtConcurrent::mapped
QFuture< T > mapped(const Sequence &sequence, MapFunction function)
QSignalMapper::mapping
QObject * mapping(int id) const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:37:43 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

qgpgme

Skip menu "qgpgme"
  • Main Page
  • File List

kdepimlibs API Reference

Skip menu "kdepimlibs API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal