~ubuntu-branches/ubuntu/vivid/emscripten/vivid

« back to all changes in this revision

Viewing changes to tests/poppler/qt4/src/poppler-pdf-converter.cc

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2013-05-02 13:11:51 UTC
  • Revision ID: package-import@ubuntu.com-20130502131151-q8dvteqr1ef2x7xz
Tags: upstream-1.4.1~20130504~adb56cb
ImportĀ upstreamĀ versionĀ 1.4.1~20130504~adb56cb

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* poppler-pdf-converter.cc: qt4 interface to poppler
 
2
 * Copyright (C) 2008, Pino Toscano <pino@kde.org>
 
3
 * Copyright (C) 2008, 2009, Albert Astals Cid <aacid@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-qt4.h"
 
21
 
 
22
#include "poppler-private.h"
 
23
#include "poppler-converter-private.h"
 
24
#include "poppler-qiodeviceoutstream-private.h"
 
25
 
 
26
#include <QtCore/QFile>
 
27
 
 
28
#include <ErrorCodes.h>
 
29
 
 
30
namespace Poppler {
 
31
 
 
32
class PDFConverterPrivate : public BaseConverterPrivate
 
33
{
 
34
        public:
 
35
                PDFConverterPrivate();
 
36
 
 
37
                PDFConverter::PDFOptions opts;
 
38
};
 
39
 
 
40
PDFConverterPrivate::PDFConverterPrivate()
 
41
        : BaseConverterPrivate(), opts(0)
 
42
{
 
43
}
 
44
 
 
45
 
 
46
PDFConverter::PDFConverter(DocumentData *document)
 
47
        : BaseConverter(*new PDFConverterPrivate())
 
48
{
 
49
        Q_D(PDFConverter);
 
50
        d->document = document;
 
51
}
 
52
 
 
53
PDFConverter::~PDFConverter()
 
54
{
 
55
}
 
56
 
 
57
void PDFConverter::setPDFOptions(PDFConverter::PDFOptions options)
 
58
{
 
59
        Q_D(PDFConverter);
 
60
        d->opts = options;
 
61
}
 
62
 
 
63
PDFConverter::PDFOptions PDFConverter::pdfOptions() const
 
64
{
 
65
        Q_D(const PDFConverter);
 
66
        return d->opts;
 
67
}
 
68
 
 
69
bool PDFConverter::convert()
 
70
{
 
71
        Q_D(PDFConverter);
 
72
        d->lastError = NoError;
 
73
 
 
74
        if (d->document->locked)
 
75
        {
 
76
                d->lastError = FileLockedError;
 
77
                return false;
 
78
        }
 
79
 
 
80
        QIODevice *dev = d->openDevice();
 
81
        if (!dev)
 
82
        {
 
83
                d->lastError = OpenOutputError;
 
84
                return false;
 
85
        }
 
86
 
 
87
        bool deleteFile = false;
 
88
        if (QFile *file = qobject_cast<QFile*>(dev))
 
89
                deleteFile = !file->exists();
 
90
 
 
91
        int errorCode = errNone;
 
92
        QIODeviceOutStream stream(dev);
 
93
        if (d->opts & WithChanges)
 
94
        {
 
95
                errorCode = d->document->doc->saveAs(&stream);
 
96
        }
 
97
        else
 
98
        {
 
99
                errorCode = d->document->doc->saveWithoutChangesAs(&stream);
 
100
        }
 
101
        d->closeDevice();
 
102
        if (errorCode != errNone)
 
103
        {
 
104
                if (deleteFile)
 
105
                {
 
106
                        qobject_cast<QFile*>(dev)->remove();
 
107
                }
 
108
                if (errorCode == errOpenFile) d->lastError = OpenOutputError;
 
109
                else d->lastError = NotSupportedInputFileError;
 
110
        }
 
111
 
 
112
        return (errorCode == errNone);
 
113
}
 
114
 
 
115
}