23 #include <qgpgme/eventloopinteractor.h>
24 #include <gpgme++/context.h>
26 #include <QCoreApplication>
27 #include <QSocketNotifier>
30 using namespace GpgME;
32 QGpgME::EventLoopInteractor::EventLoopInteractor( QObject * parent )
33 : QObject( parent ), GpgME::EventLoopInteractor()
35 setObjectName( QLatin1String(
"QGpgME::EventLoopInteractor::instance()" ) );
37 if ( QCoreApplication *
const app = QCoreApplication::instance() ) {
38 connect( app, SIGNAL(aboutToQuit()), SLOT(deleteLater()) );
39 connect( app, SIGNAL(aboutToQuit()), SIGNAL(aboutToDestroy()) );
44 QGpgME::EventLoopInteractor::~EventLoopInteractor() {
45 emit aboutToDestroy();
49 QGpgME::EventLoopInteractor * QGpgME::EventLoopInteractor::mSelf = 0;
51 QGpgME::EventLoopInteractor * QGpgME::EventLoopInteractor::instance() {
54 if ( !QCoreApplication::instance() )
55 qWarning(
"QGpgME::EventLoopInteractor: Need a Q(Core)Application object before calling instance()!" );
58 (void)
new EventLoopInteractor;
65 template <
typename T_Enableable>
67 const QPointer<T_Enableable> o;
68 const bool wasEnabled;
70 explicit QDisabler( T_Enableable * t ) : o( t ), wasEnabled( o && o->isEnabled() ) {
if ( t ) t->setEnabled(
false ); }
71 ~QDisabler() {
if ( o ) o->setEnabled( wasEnabled ); }
75 void QGpgME::EventLoopInteractor::slotWriteActivity(
int socket ) {
80 const QDisabler<QSocketNotifier> disabled( qobject_cast<QSocketNotifier*>( sender() ) );
81 actOn( socket , Write );
84 void QGpgME::EventLoopInteractor::slotReadActivity(
int socket ) {
85 const QDisabler<QSocketNotifier> disabled( qobject_cast<QSocketNotifier*>( sender() ) );
86 actOn( socket , Read );
89 void QGpgME::EventLoopInteractor::nextTrustItemEvent( GpgME::Context * context,
const GpgME::TrustItem & item ) {
90 emit nextTrustItemEventSignal( context, item );
93 void QGpgME::EventLoopInteractor::nextKeyEvent( GpgME::Context * context,
const GpgME::Key & key ) {
94 emit nextKeyEventSignal( context, key );
97 void QGpgME::EventLoopInteractor::operationDoneEvent( GpgME::Context * context,
const GpgME::Error & e ) {
98 emit operationDoneEventSignal( context, e );
101 void QGpgME::EventLoopInteractor::operationStartEvent( GpgME::Context * context ) {
102 emit operationStartEventSignal( context );
105 #include "eventloopinteractor.moc"