qgpgme
eventloopinteractor.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include <qgpgme/eventloopinteractor.h>
00024 #include <gpgme++/context.h>
00025
00026 #include <QCoreApplication>
00027 #include <QSocketNotifier>
00028 #include <QPointer>
00029
00030 using namespace GpgME;
00031
00032 QGpgME::EventLoopInteractor::EventLoopInteractor( QObject * parent )
00033 : QObject( parent ), GpgME::EventLoopInteractor()
00034 {
00035 setObjectName( QLatin1String( "QGpgME::EventLoopInteractor::instance()" ) );
00036 if ( !parent )
00037 if ( QCoreApplication * const app = QCoreApplication::instance() ) {
00038 connect( app, SIGNAL(aboutToQuit()), SLOT(deleteLater()) );
00039 connect( app, SIGNAL(aboutToQuit()), SIGNAL(aboutToDestroy()) );
00040 }
00041 mSelf = this;
00042 }
00043
00044 QGpgME::EventLoopInteractor::~EventLoopInteractor() {
00045 emit aboutToDestroy();
00046 mSelf = 0;
00047 }
00048
00049 QGpgME::EventLoopInteractor * QGpgME::EventLoopInteractor::mSelf = 0;
00050
00051 QGpgME::EventLoopInteractor * QGpgME::EventLoopInteractor::instance() {
00052 if ( !mSelf )
00053 #ifndef NDEBUG
00054 if ( !QCoreApplication::instance() )
00055 qWarning( "QGpgME::EventLoopInteractor: Need a Q(Core)Application object before calling instance()!" );
00056 else
00057 #endif
00058 (void)new EventLoopInteractor;
00059 return mSelf;
00060 }
00061
00062 namespace {
00063
00064 template <typename T_Enableable>
00065 class QDisabler {
00066 const QPointer<T_Enableable> o;
00067 const bool wasEnabled;
00068 public:
00069 explicit QDisabler( T_Enableable * t ) : o( t ), wasEnabled( o && o->isEnabled() ) { if ( t ) t->setEnabled( false ); }
00070 ~QDisabler() { if ( o ) o->setEnabled( wasEnabled ); }
00071 };
00072 }
00073
00074 void QGpgME::EventLoopInteractor::slotWriteActivity( int socket ) {
00075
00076
00077
00078
00079 const QDisabler<QSocketNotifier> disabled( qobject_cast<QSocketNotifier*>( sender() ) );
00080 actOn( socket , Write );
00081 }
00082
00083 void QGpgME::EventLoopInteractor::slotReadActivity( int socket ) {
00084 const QDisabler<QSocketNotifier> disabled( qobject_cast<QSocketNotifier*>( sender() ) );
00085 actOn( socket , Read );
00086 }
00087
00088 void QGpgME::EventLoopInteractor::nextTrustItemEvent( GpgME::Context * context, const GpgME::TrustItem & item ) {
00089 emit nextTrustItemEventSignal( context, item );
00090 }
00091
00092 void QGpgME::EventLoopInteractor::nextKeyEvent( GpgME::Context * context, const GpgME::Key & key ) {
00093 emit nextKeyEventSignal( context, key );
00094 }
00095
00096 void QGpgME::EventLoopInteractor::operationDoneEvent( GpgME::Context * context, const GpgME::Error & e ) {
00097 emit operationDoneEventSignal( context, e );
00098 }
00099
00100 void QGpgME::EventLoopInteractor::operationStartEvent( GpgME::Context * context ) {
00101 emit operationStartEventSignal( context );
00102 }
00103
00104 #include "eventloopinteractor.moc"