1/* dataprovider.h
2 Copyright (C) 2004 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#ifndef __QGPGME_DATAPROVIDER_H__
23#define __QGPGME_DATAPROVIDER_H__
24
25#include "qgpgme_export.h"
26#include <gpgme++/interfaces/dataprovider.h>
27
28#include <QtCore/QByteArray>
29
30#include <boost/shared_ptr.hpp>
31
32class QIODevice;
33
34namespace QGpgME {
35
36 class QGPGME_EXPORT QByteArrayDataProvider : public GpgME::DataProvider {
37 public:
38 QByteArrayDataProvider();
39 explicit QByteArrayDataProvider( const QByteArray & initialData );
40 ~QByteArrayDataProvider();
41
42 const QByteArray & data() const {
43 return mArray;
44 }
45
46 private:
47 // these shall only be accessed through the dataprovider
48 // interface, where they're public:
49 /*! \reimp */
50 bool isSupported( Operation ) const { return true; }
51 /*! \reimp */
52 ssize_t read( void * buffer, size_t bufSize );
53 /*! \reimp */
54 ssize_t write( const void * buffer, size_t bufSize );
55 /*! \reimp */
56 off_t seek( off_t offset, int whence );
57 /*! \reimp */
58 void release();
59
60 private:
61 QByteArray mArray;
62 off_t mOff;
63 };
64
65 class QGPGME_EXPORT QIODeviceDataProvider : public GpgME::DataProvider {
66 public:
67 explicit QIODeviceDataProvider( const boost::shared_ptr<QIODevice> & initialData );
68 ~QIODeviceDataProvider();
69
70 const boost::shared_ptr<QIODevice> & ioDevice() const {
71 return mIO;
72 }
73
74 private:
75 // these shall only be accessed through the dataprovider
76 // interface, where they're public:
77 /*! \reimp */
78 bool isSupported( Operation ) const;
79 /*! \reimp */
80 ssize_t read( void * buffer, size_t bufSize );
81 /*! \reimp */
82 ssize_t write( const void * buffer, size_t bufSize );
83 /*! \reimp */
84 off_t seek( off_t offset, int whence );
85 /*! \reimp */
86 void release();
87
88 private:
89 const boost::shared_ptr<QIODevice> mIO;
90 bool mErrorOccurred : 1;
91 bool mHaveQProcess : 1;
92 };
93
94} // namespace QGpgME
95
96#endif // __QGPGME_EVENTLOOPINTERACTOR_H__
97
98
99