Debian Codegraph @

qt6/src/poppler-base-converter.cc

raw
1 /* poppler-base-converter.cc: qt interface to poppler
2 * Copyright (C) 2007, 2009, 2025, Albert Astals Cid <[email protected]>
3 * Copyright (C) 2008, Pino Toscano <[email protected]>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
8 * any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19
20 #include "poppler-converter-private.h"
21
22 #include <QtCore/QFile>
23
24 namespace Poppler {
25
26 BaseConverterPrivate::BaseConverterPrivate() : document(nullptr), iodev(nullptr), ownIodev(true) { }
27
28 BaseConverterPrivate::~BaseConverterPrivate() = default;
29
30 QIODevice *BaseConverterPrivate::openDevice()
31 {
32 if (!iodev) {
33 Q_ASSERT(!outputFileName.isEmpty());
34 QFile *f = new QFile(outputFileName);
35 iodev = f;
36 ownIodev = true;
37 }
38 Q_ASSERT(iodev);
39 if (!iodev->isOpen()) {
40 if (!iodev->open(QIODevice::WriteOnly)) {
41 if (ownIodev) {
42 delete iodev;
43 iodev = nullptr;
44 } else {
45 return nullptr;
46 }
47 }
48 }
49 return iodev;
50 }
51
52 void BaseConverterPrivate::closeDevice()
53 {
54 if (ownIodev) {
55 iodev->close();
56 delete iodev;
57 iodev = nullptr;
58 }
59 }
60
61 BaseConverter::BaseConverter(BaseConverterPrivate &dd) : d_ptr(&dd) { }
62
63 BaseConverter::~BaseConverter()
64 {
65 delete d_ptr;
66 }
67
68 void BaseConverter::setOutputFileName(const QString &outputFileName)
69 {
70 Q_D(BaseConverter);
71 d->outputFileName = outputFileName;
72 }
73
74 void BaseConverter::setOutputDevice(QIODevice *device)
75 {
76 Q_D(BaseConverter);
77 d->iodev = device;
78 d->ownIodev = false;
79 }
80
81 BaseConverter::Error BaseConverter::lastError() const
82 {
83 Q_D(const BaseConverter);
84 return d->lastError;
85 }
86
87 }