• Skip to content
  • Skip to link menu
KDE 4.7 API Reference
  • KDE API Reference
  • KDE-PIM Libraries
  • KDE Home
  • 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   }
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   // Make sure to disable the notifier while we are processing the event, as
00077   // it's easy to run into re-entrancy issues, if actOn causes things to return
00078   // to the event loop in some way (such as showing the passphrase dialog).
00079   // We use a qpointer as actOn will destroy the notifier, when it's done with the FD
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"

qgpgme

Skip menu "qgpgme"
  • Main Page
  • File List

KDE-PIM Libraries

Skip menu "KDE-PIM Libraries"
  • akonadi
  •   contact
  •   kmime
  • kabc
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  •   richtextbuilders
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Generated for KDE-PIM Libraries by doxygen 1.7.5
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