1 | /* poppler-base-converter.cc: qt interface to poppler |
2 | * Copyright (C) 2007, 2009, Albert Astals Cid <aacid@kde.org> |
3 | * Copyright (C) 2008, Pino Toscano <pino@kde.org> |
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-qt6.h" |
21 | |
22 | #include "poppler-converter-private.h" |
23 | |
24 | #include <QtCore/QFile> |
25 | |
26 | namespace Poppler { |
27 | |
28 | BaseConverterPrivate::BaseConverterPrivate() : document(nullptr), iodev(nullptr), ownIodev(true) { } |
29 | |
30 | BaseConverterPrivate::~BaseConverterPrivate() { } |
31 | |
32 | QIODevice *BaseConverterPrivate::openDevice() |
33 | { |
34 | if (!iodev) { |
35 | Q_ASSERT(!outputFileName.isEmpty()); |
36 | QFile *f = new QFile(outputFileName); |
37 | iodev = f; |
38 | ownIodev = true; |
39 | } |
40 | Q_ASSERT(iodev); |
41 | if (!iodev->isOpen()) { |
42 | if (!iodev->open(mode: QIODevice::WriteOnly)) { |
43 | if (ownIodev) { |
44 | delete iodev; |
45 | iodev = nullptr; |
46 | } else { |
47 | return nullptr; |
48 | } |
49 | } |
50 | } |
51 | return iodev; |
52 | } |
53 | |
54 | void BaseConverterPrivate::closeDevice() |
55 | { |
56 | if (ownIodev) { |
57 | iodev->close(); |
58 | delete iodev; |
59 | iodev = nullptr; |
60 | } |
61 | } |
62 | |
63 | BaseConverter::BaseConverter(BaseConverterPrivate &dd) : d_ptr(&dd) { } |
64 | |
65 | BaseConverter::~BaseConverter() |
66 | { |
67 | delete d_ptr; |
68 | } |
69 | |
70 | void BaseConverter::setOutputFileName(const QString &outputFileName) |
71 | { |
72 | Q_D(BaseConverter); |
73 | d->outputFileName = outputFileName; |
74 | } |
75 | |
76 | void BaseConverter::setOutputDevice(QIODevice *device) |
77 | { |
78 | Q_D(BaseConverter); |
79 | d->iodev = device; |
80 | d->ownIodev = false; |
81 | } |
82 | |
83 | BaseConverter::Error BaseConverter::lastError() const |
84 | { |
85 | Q_D(const BaseConverter); |
86 | return d->lastError; |
87 | } |
88 | |
89 | } |
90 | |