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 | |
25 | #include <QSocketNotifier> |
26 | |
27 | void * QGpgME::EventLoopInteractor::registerWatcher( int fd, Direction dir, bool & ok ) { |
28 | QSocketNotifier * const sn = new QSocketNotifier( fd, dir == Read ? QSocketNotifier::Read : QSocketNotifier::Write ); |
29 | if ( dir == Read ) { |
30 | connect( sn, SIGNAL(activated(int)), this, SLOT(slotReadActivity(int)) ); |
31 | } else { |
32 | connect( sn, SIGNAL(activated(int)), this, SLOT(slotWriteActivity(int)) ); |
33 | } |
34 | ok = true; // Can above operations fails? |
35 | return sn; |
36 | } |
37 | |
38 | void QGpgME::EventLoopInteractor::unregisterWatcher( void * tag ) { |
39 | static_cast<QSocketNotifier*>( tag )->deleteLater(); |
40 | } |
41 | |