00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
#ifdef HAVE_CONFIG_H
00023
#include <config.h>
00024
#endif
00025
00026
#include <qgpgme/eventloopinteractor.h>
00027
00028
#include <gpgmepp/context.h>
00029
00030
#include <qsocketnotifier.h>
00031
#include <qapplication.h>
00032
00033
using namespace GpgME;
00034
00035 QGpgME::EventLoopInteractor::EventLoopInteractor(
QObject * parent,
const char * name )
00036 :
QObject( parent, name ), GpgME::EventLoopInteractor()
00037 {
00038
if ( !parent )
00039
if ( qApp ) {
00040 connect( qApp, SIGNAL(aboutToQuit()), SLOT(deleteLater()) );
00041 connect( qApp, SIGNAL(aboutToQuit()), SIGNAL(aboutToDestroy()) );
00042 }
00043 mSelf =
this;
00044 }
00045
00046 QGpgME::EventLoopInteractor::~EventLoopInteractor() {
00047 emit aboutToDestroy();
00048 mSelf = 0;
00049 }
00050
00051 QGpgME::EventLoopInteractor * QGpgME::EventLoopInteractor::mSelf = 0;
00052
00053 QGpgME::EventLoopInteractor * QGpgME::EventLoopInteractor::instance() {
00054
if ( !mSelf )
00055
#ifndef NDEBUG
00056
if ( !qApp )
00057 qWarning(
"QGpgME::EventLoopInteractor: Need a QApplication object before calling instance()!" );
00058
else
00059
#endif
00060
(
void)
new EventLoopInteractor( 0,
"QGpgME::EventLoopInteractor::instance()" );
00061
return mSelf;
00062 }
00063
00064
void * QGpgME::EventLoopInteractor::registerWatcher(
int fd, Direction dir,
bool & ok ) {
00065
QSocketNotifier * sn =
new QSocketNotifier( fd,
00066 dir == Read ? QSocketNotifier::Read : QSocketNotifier::Write );
00067
if ( dir == Read )
00068 connect( sn, SIGNAL(activated(
int)), SLOT(slotReadActivity(
int)) );
00069
else
00070 connect( sn, SIGNAL(activated(
int)), SLOT(slotWriteActivity(
int)) );
00071 ok =
true;
00072
return sn;
00073 }
00074
00075
void QGpgME::EventLoopInteractor::unregisterWatcher(
void * tag ) {
00076
delete static_cast<QSocketNotifier*>( tag );
00077 }
00078
00079
void QGpgME::EventLoopInteractor::slotWriteActivity(
int socket ) {
00080 actOn( socket , Write );
00081 }
00082
00083
void QGpgME::EventLoopInteractor::slotReadActivity(
int socket ) {
00084 actOn( socket , Read );
00085 }
00086
00087
void QGpgME::EventLoopInteractor::nextTrustItemEvent( GpgME::Context * context,
const GpgME::TrustItem & item ) {
00088 emit nextTrustItemEventSignal( context, item );
00089 }
00090
00091
void QGpgME::EventLoopInteractor::nextKeyEvent( GpgME::Context * context,
const GpgME::Key & key ) {
00092 emit nextKeyEventSignal( context, key );
00093 }
00094
00095
void QGpgME::EventLoopInteractor::operationDoneEvent( GpgME::Context * context,
const GpgME::Error & e ) {
00096 emit operationDoneEventSignal( context, e );
00097 }
00098
00099
#include "eventloopinteractor.moc"