QGpgME  2.1.0-unknown
Qt API for GpgME
dataprovider.h
1 /* dataprovider.h
2 
3  This file is part of qgpgme, the Qt API binding for gpgme
4  Copyright (C) 2004 Klarälvdalens Datakonsult AB
5  Copyright (c) 2016 by Bundesamt für Sicherheit in der Informationstechnik
6  Software engineering by Intevation GmbH
7 
8  QGpgME is free software; you can redistribute it and/or
9  modify it under the terms of the GNU General Public License as
10  published by the Free Software Foundation; either version 2 of the
11  License, or (at your option) any later version.
12 
13  QGpgME is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with this program; if not, write to the Free Software
20  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22 
23 // -*- c++ -*-
24 #ifndef __QGPGME_DATAPROVIDER_H__
25 #define __QGPGME_DATAPROVIDER_H__
26 
27 #include "qgpgme_export.h"
28 
29 #include <gpgme++/interfaces/dataprovider.h>
30 
31 #include <memory>
32 
33 #include <QtCore/QByteArray>
34 
35 
36 class QIODevice;
37 
38 namespace QGpgME
39 {
40 
41 class QGPGME_EXPORT QByteArrayDataProvider : public GpgME::DataProvider
42 {
43 public:
45  explicit QByteArrayDataProvider(const QByteArray &initialData);
47 
48  const QByteArray &data() const
49  {
50  return mArray;
51  }
52 
53 private:
54  // these shall only be accessed through the dataprovider
55  // interface, where they're public:
56  bool isSupported(Operation) const override
57  {
58  return true;
59  }
60 #ifdef _WIN32
61  gpgme_ssize_t read(void *buffer, size_t bufSize) override;
62  gpgme_ssize_t write(const void *buffer, size_t bufSize) override;
63  gpgme_off_t seek(gpgme_off_t offset, int whence) override;
64 #else
65  ssize_t read(void *buffer, size_t bufSize) override;
66  ssize_t write(const void *buffer, size_t bufSize) override;
67  off_t seek(off_t offset, int whence) override;
68 #endif
69  void release() override;
70 
71 private:
72  QByteArray mArray;
73 #ifdef _WIN32
74  gpgme_off_t mOff;
75 #else
76  off_t mOff;
77 #endif
78 };
79 
80 class QGPGME_EXPORT QIODeviceDataProvider : public GpgME::DataProvider
81 {
82 public:
83  explicit QIODeviceDataProvider(const std::shared_ptr<QIODevice> &initialData);
85 
86  const std::shared_ptr<QIODevice> &ioDevice() const
87  {
88  return mIO;
89  }
90 
91 private:
92  // these shall only be accessed through the dataprovider
93  // interface, where they're public:
94  bool isSupported(Operation) const override;
95 #ifdef _WIN32
96  gpgme_ssize_t read(void *buffer, size_t bufSize) override;
97  gpgme_ssize_t write(const void *buffer, size_t bufSize) override;
98  gpgme_off_t seek(gpgme_off_t offset, int whence) override;
99 #else
100  ssize_t read(void *buffer, size_t bufSize) override;
101  ssize_t write(const void *buffer, size_t bufSize) override;
102  off_t seek(off_t offset, int whence) override;
103 #endif
104  void release() override;
105 
106 private:
107  const std::shared_ptr<QIODevice> mIO;
108  bool mErrorOccurred : 1;
109  bool mHaveQProcess : 1;
110 };
111 
112 } // namespace QGpgME
113 
114 #endif
Definition: abstractimportjob.h:48
Definition: dataprovider.h:41
Definition: dataprovider.h:80