keepassxc

Форк
0
/
LayeredStream.cpp 
85 строк · 2.5 Кб
1
/*
2
 *  Copyright (C) 2010 Felix Geyer <debfx@fobos.de>
3
 *
4
 *  This program is free software: you can redistribute it and/or modify
5
 *  it under the terms of the GNU General Public License as published by
6
 *  the Free Software Foundation, either version 2 or (at your option)
7
 *  version 3 of the License.
8
 *
9
 *  This program is distributed in the hope that it will be useful,
10
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 *  GNU General Public License for more details.
13
 *
14
 *  You should have received a copy of the GNU General Public License
15
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
 */
17

18
#include "LayeredStream.h"
19

20
LayeredStream::LayeredStream(QIODevice* baseDevice)
21
    : QIODevice(baseDevice)
22
    , m_baseDevice(baseDevice)
23
{
24
    connect(baseDevice, SIGNAL(aboutToClose()), SLOT(closeStream()));
25
}
26

27
LayeredStream::~LayeredStream()
28
{
29
    QIODevice::close();
30
}
31

32
bool LayeredStream::isSequential() const
33
{
34
    return true;
35
}
36

37
bool LayeredStream::open(QIODevice::OpenMode mode)
38
{
39
    if (isOpen()) {
40
        qWarning("LayeredStream::open: Device is already open.");
41
        return false;
42
    }
43

44
    bool readMode = (mode & QIODevice::ReadOnly);
45
    bool writeMode = (mode & QIODevice::WriteOnly);
46

47
    if (readMode && writeMode) {
48
        qWarning("LayeredStream::open: Reading and writing at the same time is not supported.");
49
        return false;
50
    } else if (!readMode && !writeMode) {
51
        qWarning("LayeredStream::open: Must be opened in read or write mode.");
52
        return false;
53
    } else if ((readMode && !m_baseDevice->isReadable()) || (writeMode && !m_baseDevice->isWritable())) {
54
        qWarning("LayeredStream::open: Base device is not opened correctly.");
55
        return false;
56
    } else {
57
        if (mode & QIODevice::Append) {
58
            qWarning("LayeredStream::open: QIODevice::Append is not supported.");
59
            mode = mode & ~QIODevice::Append;
60
        }
61
        if (mode & QIODevice::Truncate) {
62
            qWarning("LayeredStream::open: QIODevice::Truncate is not supported.");
63
            mode = mode & ~QIODevice::Truncate;
64
        }
65

66
        mode = mode | QIODevice::Unbuffered;
67

68
        return QIODevice::open(mode);
69
    }
70
}
71

72
qint64 LayeredStream::readData(char* data, qint64 maxSize)
73
{
74
    return m_baseDevice->read(data, maxSize);
75
}
76

77
qint64 LayeredStream::writeData(const char* data, qint64 maxSize)
78
{
79
    return m_baseDevice->write(data, maxSize);
80
}
81

82
void LayeredStream::closeStream()
83
{
84
    close();
85
}
86

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.