• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.9.4 API Reference
  • KDE Home
  • Contact Us
 

qgpgme

  • qgpgme
eventloopinteractor.cpp
1 /* qeventloopinteractor.cpp
2  Copyright (C) 2003, 2007 Klarälvdalens Datakonsult AB
3 
4  This file is part of QGPGME.
5 
6  QGPGME is free software; you can redistribute it and/or modify it
7  under the terms of the GNU Library General Public License as published
8  by the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10 
11  QGPGME is distributed in the hope that it will be useful, but
12  WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU Library General Public License for more details.
15 
16  You should have received a copy of the GNU Library General Public License
17  along with QGPGME; see the file COPYING.LIB. If not, write to the
18  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  Boston, MA 02110-1301, USA. */
20 
21 // -*- c++ -*-
22 
23 #include <qgpgme/eventloopinteractor.h>
24 #include <gpgme++/context.h>
25 
26 #include <QCoreApplication>
27 #include <QSocketNotifier>
28 #include <QPointer>
29 
30 using namespace GpgME;
31 
32 QGpgME::EventLoopInteractor::EventLoopInteractor( QObject * parent )
33  : QObject( parent ), GpgME::EventLoopInteractor()
34 {
35  setObjectName( QLatin1String( "QGpgME::EventLoopInteractor::instance()" ) );
36  if ( !parent )
37  if ( QCoreApplication * const app = QCoreApplication::instance() ) {
38  connect( app, SIGNAL(aboutToQuit()), SLOT(deleteLater()) );
39  connect( app, SIGNAL(aboutToQuit()), SIGNAL(aboutToDestroy()) );
40  }
41  mSelf = this;
42 }
43 
44 QGpgME::EventLoopInteractor::~EventLoopInteractor() {
45  emit aboutToDestroy();
46  mSelf = 0;
47 }
48 
49 QGpgME::EventLoopInteractor * QGpgME::EventLoopInteractor::mSelf = 0;
50 
51 QGpgME::EventLoopInteractor * QGpgME::EventLoopInteractor::instance() {
52  if ( !mSelf ) {
53 #ifndef NDEBUG
54  if ( !QCoreApplication::instance() )
55  qWarning( "QGpgME::EventLoopInteractor: Need a Q(Core)Application object before calling instance()!" );
56  else
57 #endif
58  (void)new EventLoopInteractor;
59  }
60  return mSelf;
61 }
62 
63 namespace {
64 
65  template <typename T_Enableable>
66  class QDisabler {
67  const QPointer<T_Enableable> o;
68  const bool wasEnabled;
69  public:
70  explicit QDisabler( T_Enableable * t ) : o( t ), wasEnabled( o && o->isEnabled() ) { if ( t ) t->setEnabled( false ); }
71  ~QDisabler() { if ( o ) o->setEnabled( wasEnabled ); }
72  };
73 }
74 
75 void QGpgME::EventLoopInteractor::slotWriteActivity( int socket ) {
76  // Make sure to disable the notifier while we are processing the event, as
77  // it's easy to run into re-entrancy issues, if actOn causes things to return
78  // to the event loop in some way (such as showing the passphrase dialog).
79  // We use a qpointer as actOn will destroy the notifier, when it's done with the FD
80  const QDisabler<QSocketNotifier> disabled( qobject_cast<QSocketNotifier*>( sender() ) );
81  actOn( socket , Write );
82 }
83 
84 void QGpgME::EventLoopInteractor::slotReadActivity( int socket ) {
85  const QDisabler<QSocketNotifier> disabled( qobject_cast<QSocketNotifier*>( sender() ) );
86  actOn( socket , Read );
87 }
88 
89 void QGpgME::EventLoopInteractor::nextTrustItemEvent( GpgME::Context * context, const GpgME::TrustItem & item ) {
90  emit nextTrustItemEventSignal( context, item );
91 }
92 
93 void QGpgME::EventLoopInteractor::nextKeyEvent( GpgME::Context * context, const GpgME::Key & key ) {
94  emit nextKeyEventSignal( context, key );
95 }
96 
97 void QGpgME::EventLoopInteractor::operationDoneEvent( GpgME::Context * context, const GpgME::Error & e ) {
98  emit operationDoneEventSignal( context, e );
99 }
100 
101 void QGpgME::EventLoopInteractor::operationStartEvent( GpgME::Context * context ) {
102  emit operationStartEventSignal( context );
103 }
104 
105 #include "eventloopinteractor.moc"
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Tue Dec 11 2012 12:13:54 by doxygen 1.8.1.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

qgpgme

Skip menu "qgpgme"
  • Main Page
  • File List

kdepimlibs-4.9.4 API Reference

Skip menu "kdepimlibs-4.9.4 API Reference"
  • akonadi
  •   contact
  •   kmime
  • kabc
  • kalarmcal
  • 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
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal