libkdenetwork Library API Documentation

qgpgme/eventloopinteractor.cpp

00001 /* qeventloopinteractor.cpp
00002    Copyright (C) 2003 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 General Public License as published by
00008    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 GNU
00014    General Public License for more details.
00015 
00016    You should have received a copy of the GNU General Public License
00017    along with QGPGME; if not, write to the Free Software Foundation,
00018    Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA.  */
00019 
00020 // -*- c++ -*-
00021 
00022 #ifdef HAVE_CONFIG_H
00023 #include <config.h>
00024 #endif
00025 
00026 #include <qgpgme/eventloopinteractor.h>
00027 
00028 #include <gpgmepp/context.h>
00029 
00030 #include <qsocketnotifier.h>
00031 #include <qapplication.h>
00032 
00033 using namespace GpgME;
00034 
00035 QGpgME::EventLoopInteractor::EventLoopInteractor( QObject * parent, const char * name )
00036  : QObject( parent, name ), GpgME::EventLoopInteractor()
00037 {
00038   if ( !parent )
00039     if ( qApp ) {
00040       connect( qApp, SIGNAL(aboutToQuit()), SLOT(deleteLater()) );
00041       connect( qApp, SIGNAL(aboutToQuit()), SIGNAL(aboutToDestroy()) );
00042     }
00043   mSelf = this;
00044 }
00045 
00046 QGpgME::EventLoopInteractor::~EventLoopInteractor() {
00047   emit aboutToDestroy();
00048   mSelf = 0;
00049 }
00050 
00051 QGpgME::EventLoopInteractor * QGpgME::EventLoopInteractor::mSelf = 0;
00052 
00053 QGpgME::EventLoopInteractor * QGpgME::EventLoopInteractor::instance() {
00054   if ( !mSelf )
00055 #ifndef NDEBUG
00056     if ( !qApp )
00057       qWarning( "QGpgME::EventLoopInteractor: Need a QApplication object before calling instance()!" );
00058     else
00059 #endif
00060       (void)new EventLoopInteractor( 0, "QGpgME::EventLoopInteractor::instance()" );
00061   return mSelf;
00062 }
00063 
00064 void * QGpgME::EventLoopInteractor::registerWatcher( int fd, Direction dir, bool & ok ) {
00065   QSocketNotifier * sn = new QSocketNotifier( fd, 
00066       dir == Read ? QSocketNotifier::Read : QSocketNotifier::Write );
00067   if ( dir == Read )
00068     connect( sn, SIGNAL(activated(int)), SLOT(slotReadActivity(int)) );
00069   else
00070     connect( sn, SIGNAL(activated(int)), SLOT(slotWriteActivity(int)) );
00071   ok = true; // Can above operations fails?
00072   return sn;
00073 }
00074 
00075 void QGpgME::EventLoopInteractor::unregisterWatcher( void * tag ) {
00076   delete static_cast<QSocketNotifier*>( tag );
00077 }
00078 
00079 void QGpgME::EventLoopInteractor::slotWriteActivity( int socket ) {
00080   actOn( socket , Write );
00081 }
00082 
00083 void QGpgME::EventLoopInteractor::slotReadActivity( int socket ) {
00084   actOn( socket , Read );
00085 }
00086 
00087 void QGpgME::EventLoopInteractor::nextTrustItemEvent( GpgME::Context * context, const GpgME::TrustItem & item ) {
00088   emit nextTrustItemEventSignal( context, item );
00089 }
00090 
00091 void QGpgME::EventLoopInteractor::nextKeyEvent( GpgME::Context * context, const GpgME::Key & key ) {
00092   emit nextKeyEventSignal( context, key );
00093 }
00094 
00095 void QGpgME::EventLoopInteractor::operationDoneEvent( GpgME::Context * context, const GpgME::Error & e ) {
00096   emit operationDoneEventSignal( context, e );
00097 }
00098 
00099 #include "eventloopinteractor.moc"
KDE Logo
This file is part of the documentation for libkdenetwork Library Version 3.3.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Mar 23 22:37:05 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003