1
/***************************************************************************
2
* Copyright (C) 2004-2010 by Thomas Fischer *
3
* fischer@unix-ag.uni-kl.de *
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 of the License, or *
8
* (at your option) any later version. *
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. *
15
* You should have received a copy of the GNU General Public License *
16
* along with this program; if not, write to the *
17
* Free Software Foundation, Inc., *
18
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19
***************************************************************************/
24
#include <kio/netaccess.h>
26
#include <poppler-qt4.h>
28
#include "fileimporterpdf.h"
30
#include <fileimporterbibtex.h>
32
FileImporterPDF::FileImporterPDF()
34
m_bibTeXimporter = new FileImporterBibTeX();
37
FileImporterPDF::~FileImporterPDF()
39
delete m_bibTeXimporter;
42
File* FileImporterPDF::load(QIODevice *iodevice)
46
QByteArray buffer = iodevice->readAll();
48
Poppler::Document *doc = Poppler::Document::loadFromData(buffer);
50
kWarning() << "Could not load PDF document";
54
if (doc->hasEmbeddedFiles()) {
55
foreach(Poppler::EmbeddedFile *file, doc->embeddedFiles())
56
if (file->name().endsWith(".bib")) {
57
kDebug() << "filename is " << file->name();
58
QByteArray data = file->data();
59
QBuffer buffer(&data);
60
FileImporterBibTeX bibTeXimporter;
61
connect(&bibTeXimporter, SIGNAL(progress(int, int)), this, SIGNAL(progress(int, int)));
62
buffer.open(QIODevice::ReadOnly);
63
result = bibTeXimporter.load(&buffer);
67
kDebug() << "result = " << result->count() << " " << data.size() << " " << buffer.size();
69
kDebug() << "result is empty";
78
bool FileImporterPDF::guessCanDecode(const QString &)
83
void FileImporterPDF::cancel()
86
m_bibTeXimporter->cancel();
89
bool FileImporterPDF::containsBibTeXData(const KUrl &url)
94
if (KIO::NetAccess::download(url, tmpFile, NULL)) {
95
Poppler::Document *doc = Poppler::Document::load(tmpFile);
97
if (doc->hasEmbeddedFiles())
98
foreach(Poppler::EmbeddedFile *file, doc->embeddedFiles())
99
if (file->name().endsWith(".bib")) {
105
KIO::NetAccess::removeTempFile(tmpFile);