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 }
00060 return mSelf;
00061 }
00062
00063 namespace {
00064
00065 template <typename T_Enableable>
00066 class QDisabler {
00067 const QPointer<T_Enableable> o;
00068 const bool wasEnabled;
00069 public:
00070 explicit QDisabler( T_Enableable * t ) : o( t ), wasEnabled( o && o->isEnabled() ) { if ( t ) t->setEnabled( false ); }
00071 ~QDisabler() { if ( o ) o->setEnabled( wasEnabled ); }
00072 };
00073 }
00074
00075 void QGpgME::EventLoopInteractor::slotWriteActivity( int socket ) {
00076
00077
00078
00079
00080 const QDisabler<QSocketNotifier> disabled( qobject_cast<QSocketNotifier*>( sender() ) );
00081 actOn( socket , Write );
00082 }
00083
00084 void QGpgME::EventLoopInteractor::slotReadActivity( int socket ) {
00085 const QDisabler<QSocketNotifier> disabled( qobject_cast<QSocketNotifier*>( sender() ) );
00086 actOn( socket , Read );
00087 }
00088
00089 void QGpgME::EventLoopInteractor::nextTrustItemEvent( GpgME::Context * context, const GpgME::TrustItem & item ) {
00090 emit nextTrustItemEventSignal( context, item );
00091 }
00092
00093 void QGpgME::EventLoopInteractor::nextKeyEvent( GpgME::Context * context, const GpgME::Key & key ) {
00094 emit nextKeyEventSignal( context, key );
00095 }
00096
00097 void QGpgME::EventLoopInteractor::operationDoneEvent( GpgME::Context * context, const GpgME::Error & e ) {
00098 emit operationDoneEventSignal( context, e );
00099 }
00100
00101 void QGpgME::EventLoopInteractor::operationStartEvent( GpgME::Context * context ) {
00102 emit operationStartEventSignal( context );
00103 }
00104
00105 #include "eventloopinteractor.moc"