• Skip to content
  • Skip to link menu
KDE 4.3 API Reference
  • KDE API Reference
  • KDE-PIM Libraries
  • Sitemap
  • Contact Us
 

qgpgme

eventloopinteractor.cpp

00001 /* qeventloopinteractor.cpp
00002    Copyright (C) 2003, 2007 Klarälvdalens Datakonsult AB
00003 
00004    This file is part of QGPGME.
00005 
00006    QGPGME is free software; you can redistribute it and/or modify it
00007    under the terms of the GNU Library General Public License as published
00008    by the Free Software Foundation; either version 2 of the License, or
00009    (at your option) any later version.
00010 
00011    QGPGME is distributed in the hope that it will be useful, but
00012    WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014    GNU Library General Public License for more details.
00015 
00016    You should have received a copy of the GNU Library General Public License
00017    along with QGPGME; see the file COPYING.LIB.  If not, write to the
00018    Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00019    Boston, MA 02110-1301, USA. */
00020 
00021 // -*- c++ -*-
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   // Make sure to disable the notifier while we are processing the event, as
00076   // it's easy to run into re-entrancy issues, if actOn causes things to return
00077   // to the event loop in some way (such as showing the passphrase dialog).
00078   // We use a qpointer as actOn will destroy the notifier, when it's done with the FD
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"

qgpgme

Skip menu "qgpgme"
  • Main Page
  • File List

KDE-PIM Libraries

Skip menu "KDE-PIM Libraries"
  • akonadi
  • kabc
  • kblog
  • kcal
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  • kldap
  • kmime
  • kpimidentities
  • kpimtextedit
  •   richtextbuilders
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Generated for KDE-PIM Libraries by doxygen 1.5.8
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal