mirror of
https://invent.kde.org/graphics/okular
synced 2024-08-24 18:35:37 +00:00
use the nice code brad wrote for poppler that allows you to extract embedded files from a pdf document.
svn path=/branches/work/kde4/playground/graphics/okular/; revision=545966
This commit is contained in:
parent
91dc3ef06c
commit
13dde4096f
|
@ -61,6 +61,7 @@ kde4_add_ui_files(oKularcore_SRCS
|
|||
)
|
||||
|
||||
set(oKularui_SRCS
|
||||
${CMAKE_SOURCE_DIR}/okular/ui/embeddedfilesdialog.cpp
|
||||
${CMAKE_SOURCE_DIR}/okular/ui/minibar.cpp
|
||||
${CMAKE_SOURCE_DIR}/okular/ui/newstuff.cpp
|
||||
${CMAKE_SOURCE_DIR}/okular/ui/pagepainter.cpp
|
||||
|
|
|
@ -484,6 +484,11 @@ const DocumentFonts * KPDFDocument::documentFonts() const
|
|||
return generator ? generator->generateDocumentFonts() : NULL;
|
||||
}
|
||||
|
||||
const QList<EmbeddedFile*> *KPDFDocument::embeddedFiles() const
|
||||
{
|
||||
return generator ? generator->embeddedFiles() : NULL;
|
||||
}
|
||||
|
||||
const KPDFPage * KPDFDocument::page( int n ) const
|
||||
{
|
||||
return ( n < pages_vector.count() ) ? pages_vector[n] : 0;
|
||||
|
@ -1790,4 +1795,14 @@ DocumentFonts::DocumentFonts()
|
|||
// void implementation, only subclassed for naming
|
||||
}
|
||||
|
||||
/** EmbeddedFile **/
|
||||
|
||||
EmbeddedFile::EmbeddedFile()
|
||||
{
|
||||
}
|
||||
|
||||
EmbeddedFile::~EmbeddedFile()
|
||||
{
|
||||
}
|
||||
|
||||
#include "document.moc"
|
||||
|
|
|
@ -28,6 +28,7 @@ class DocumentViewport;
|
|||
class DocumentInfo;
|
||||
class DocumentSynopsis;
|
||||
class DocumentFonts;
|
||||
class EmbeddedFile;
|
||||
class Generator;
|
||||
class PixmapRequest;
|
||||
class Annotation;
|
||||
|
@ -87,6 +88,7 @@ class OKULAR_EXPORT KPDFDocument : public QObject
|
|||
const DocumentInfo * documentInfo() const;
|
||||
const DocumentSynopsis * documentSynopsis() const;
|
||||
const DocumentFonts * documentFonts() const;
|
||||
const QList<EmbeddedFile*> *embeddedFiles() const;
|
||||
const KPDFPage * page( int page ) const;
|
||||
const DocumentViewport & viewport() const;
|
||||
uint currentPage() const;
|
||||
|
@ -269,4 +271,22 @@ class OKULAR_EXPORT DocumentFonts : public QDomDocument
|
|||
DocumentFonts();
|
||||
};
|
||||
|
||||
/**
|
||||
* @short An embedded file into the document, has name, description, dates and the data
|
||||
*/
|
||||
|
||||
class OKULAR_EXPORT EmbeddedFile
|
||||
{
|
||||
public:
|
||||
EmbeddedFile();
|
||||
virtual ~EmbeddedFile();
|
||||
|
||||
virtual QString name() const = 0;
|
||||
virtual QString description() const = 0;
|
||||
virtual QByteArray data() const = 0;
|
||||
virtual QDateTime modificationDate() const = 0;
|
||||
virtual QDateTime creationDate() const = 0;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -70,6 +70,7 @@ class OKULAR_EXPORT Generator : public QObject
|
|||
virtual const DocumentInfo * generateDocumentInfo() { return 0L; }
|
||||
virtual const DocumentSynopsis * generateDocumentSynopsis() { return 0L; }
|
||||
virtual const DocumentFonts * generateDocumentFonts() { return 0L; }
|
||||
virtual const QList<EmbeddedFile*> * embeddedFiles() { return 0L; }
|
||||
|
||||
// DRM handling
|
||||
virtual bool isAllowed( int /*Document::Permisison(s)*/ ) { return true; }
|
||||
|
|
|
@ -31,8 +31,41 @@
|
|||
#include <config.h>
|
||||
#include <config-okular.h>
|
||||
|
||||
// id for DATA_READY PDFPixmapGeneratorThread Event
|
||||
#define TGE_DATAREADY_ID 6969
|
||||
class PDFEmbeddedFile : public EmbeddedFile
|
||||
{
|
||||
public:
|
||||
PDFEmbeddedFile(Poppler::EmbeddedFile *f) : ef(f)
|
||||
{
|
||||
}
|
||||
|
||||
QString name() const
|
||||
{
|
||||
return ef->name();
|
||||
}
|
||||
|
||||
QString description() const
|
||||
{
|
||||
return ef->description();
|
||||
}
|
||||
|
||||
QByteArray data() const
|
||||
{
|
||||
return ef->data();
|
||||
}
|
||||
|
||||
QDateTime modificationDate() const
|
||||
{
|
||||
return ef->modDate();
|
||||
}
|
||||
|
||||
QDateTime creationDate() const
|
||||
{
|
||||
return ef->createDate();
|
||||
}
|
||||
|
||||
private:
|
||||
Poppler::EmbeddedFile *ef;
|
||||
};
|
||||
|
||||
static void fillViewportFromLinkDestination( DocumentViewport &viewport, const Poppler::LinkDestination &destination, const Poppler::Document *pdfdoc )
|
||||
{
|
||||
|
@ -153,7 +186,7 @@ KPDF_EXPORT_PLUGIN(PDFGenerator)
|
|||
PDFGenerator::PDFGenerator( KPDFDocument * doc )
|
||||
: Generator( doc ), pdfdoc( 0 ), ready( true ),
|
||||
pixmapRequest( 0 ), docInfoDirty( true ), docSynopsisDirty( true ),
|
||||
docFontsDirty( true )
|
||||
docFontsDirty( true ), docEmbeddedFilesDirty( true )
|
||||
{
|
||||
// generate kpdfOutputDev and cache page color
|
||||
reparseConfig();
|
||||
|
@ -490,6 +523,24 @@ const DocumentFonts * PDFGenerator::generateDocumentFonts()
|
|||
return &docFonts;
|
||||
}
|
||||
|
||||
const QList<EmbeddedFile*> *PDFGenerator::embeddedFiles()
|
||||
{
|
||||
if (docEmbeddedFilesDirty)
|
||||
{
|
||||
docLock.lock();
|
||||
const QList<Poppler::EmbeddedFile*> &popplerFiles = pdfdoc->embeddedFiles();
|
||||
foreach(Poppler::EmbeddedFile* pef, popplerFiles)
|
||||
{
|
||||
docEmbeddedFiles.append(new PDFEmbeddedFile(pef));
|
||||
}
|
||||
docLock.unlock();
|
||||
|
||||
docEmbeddedFilesDirty = false;
|
||||
}
|
||||
|
||||
return &docEmbeddedFiles;
|
||||
}
|
||||
|
||||
bool PDFGenerator::isAllowed( int permissions )
|
||||
{
|
||||
#if !OKULAR_FORCE_DRM
|
||||
|
|
|
@ -55,6 +55,7 @@ class PDFGenerator : public Generator
|
|||
const DocumentInfo * generateDocumentInfo();
|
||||
const DocumentSynopsis * generateDocumentSynopsis();
|
||||
const DocumentFonts * generateDocumentFonts();
|
||||
const QList<EmbeddedFile*> * embeddedFiles();
|
||||
|
||||
// [INHERITED] document information
|
||||
bool isAllowed( int permissions );
|
||||
|
@ -127,6 +128,8 @@ class PDFGenerator : public Generator
|
|||
DocumentSynopsis docSyn;
|
||||
bool docFontsDirty;
|
||||
DocumentFonts docFonts;
|
||||
bool docEmbeddedFilesDirty;
|
||||
QList<EmbeddedFile*> docEmbeddedFiles;
|
||||
};
|
||||
|
||||
|
||||
|
|
14
part.cpp
14
part.cpp
|
@ -67,6 +67,7 @@
|
|||
#include "ui/side_reviews.h"
|
||||
#include "ui/minibar.h"
|
||||
#include "ui/newstuff.h"
|
||||
#include "ui/embeddedfilesdialog.h"
|
||||
#include "ui/propertiesdialog.h"
|
||||
#include "ui/presentationwidget.h"
|
||||
#include "conf/preferencesdialog.h"
|
||||
|
@ -273,6 +274,10 @@ Part::Part(QWidget *parentWidget,
|
|||
m_showProperties = new KAction(KIcon("info"), i18n("&Properties"), ac, "properties");
|
||||
connect(m_showProperties, SIGNAL(triggered()), this, SLOT(slotShowProperties()));
|
||||
m_showProperties->setEnabled( false );
|
||||
|
||||
m_showEmbeddedFiles = new KAction(i18n("&Embedded Files"), ac, "embeddedFiles");
|
||||
connect(m_showEmbeddedFiles, SIGNAL(triggered()), this, SLOT(slotShowEmbeddedFiles()));
|
||||
m_showEmbeddedFiles->setEnabled( false );
|
||||
|
||||
m_showPresentation = new KAction( KIcon( "kpresenter_kpr" ), i18n("P&resentation"), ac, "presentation");
|
||||
connect(m_showPresentation, SIGNAL(triggered()), this, SLOT(slotShowPresentation()));
|
||||
|
@ -524,6 +529,7 @@ bool Part::openFile()
|
|||
m_saveAs->setEnabled( ok );
|
||||
m_printPreview->setEnabled( ok );
|
||||
m_showProperties->setEnabled( ok );
|
||||
m_showEmbeddedFiles->setEnabled( ok && m_document->embeddedFiles() && m_document->embeddedFiles()->count() > 0);
|
||||
m_showPresentation->setEnabled( ok );
|
||||
|
||||
// update viewing actions
|
||||
|
@ -584,6 +590,7 @@ bool Part::closeURL()
|
|||
m_saveAs->setEnabled( false );
|
||||
m_printPreview->setEnabled( false );
|
||||
m_showProperties->setEnabled( false );
|
||||
m_showEmbeddedFiles->setEnabled( false );
|
||||
m_showPresentation->setEnabled( false );
|
||||
emit setWindowCaption("");
|
||||
emit enablePrintAction(false);
|
||||
|
@ -997,6 +1004,13 @@ void Part::slotShowProperties()
|
|||
delete d;
|
||||
}
|
||||
|
||||
void Part::slotShowEmbeddedFiles()
|
||||
{
|
||||
EmbeddedFilesDialog *d = new EmbeddedFilesDialog(widget(), m_document);
|
||||
d->exec();
|
||||
delete d;
|
||||
}
|
||||
|
||||
void Part::slotShowPresentation()
|
||||
{
|
||||
if ( !m_presentationWidget )
|
||||
|
|
4
part.h
4
part.h
|
@ -112,6 +112,7 @@ protected slots:
|
|||
void slotPrintPreview();
|
||||
void slotShowMenu(const KPDFPage *page, const QPoint &point);
|
||||
void slotShowProperties();
|
||||
void slotShowEmbeddedFiles();
|
||||
void slotShowLeftPanel();
|
||||
void slotShowPresentation();
|
||||
void slotHidePresentation();
|
||||
|
@ -119,7 +120,7 @@ protected slots:
|
|||
void close();
|
||||
void cannotQuit();
|
||||
void setMimeTypes(KIO::Job *job);
|
||||
void saveSplitterSize();
|
||||
void saveSplitterSize();
|
||||
// can be connected to widget elements
|
||||
void updateViewActions();
|
||||
void enableTOC(bool enable);
|
||||
|
@ -170,6 +171,7 @@ private:
|
|||
KAction *m_saveAs;
|
||||
KAction *m_printPreview;
|
||||
KAction *m_showProperties;
|
||||
KAction *m_showEmbeddedFiles;
|
||||
KAction *m_showPresentation;
|
||||
KToggleAction* m_showMenuBarAction;
|
||||
KToggleAction* m_showLeftPanel;
|
||||
|
|
1
part.rc
1
part.rc
|
@ -8,6 +8,7 @@
|
|||
<Action name="file_print" group="file_print"/>
|
||||
<Action name="file_print_preview" group="file_print"/>
|
||||
<Action name="properties" group="file_print"/>
|
||||
<Action name="embeddedFiles" group="file_print"/>
|
||||
</Menu>
|
||||
<Menu name="edit"><text>&Edit</text>
|
||||
<Action name="find"/>
|
||||
|
|
67
ui/embeddedfilesdialog.cpp
Normal file
67
ui/embeddedfilesdialog.cpp
Normal file
|
@ -0,0 +1,67 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2006 by Albert Astals Cid <aacid@kde.org> *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
***************************************************************************/
|
||||
|
||||
#include <QDateTime>
|
||||
#include <QTreeWidget>
|
||||
|
||||
#include <kfiledialog.h>
|
||||
#include <klocale.h>
|
||||
#include <kmessagebox.h>
|
||||
|
||||
#include "core/document.h"
|
||||
#include "embeddedfilesdialog.h"
|
||||
|
||||
EmbeddedFilesDialog::EmbeddedFilesDialog(QWidget *parent, const KPDFDocument *document) : KDialog(parent, i18n("Embedded Files"), Close | User1, 0, i18n("Save"))
|
||||
{
|
||||
m_tw = new QTreeWidget(this);
|
||||
setMainWidget(m_tw);
|
||||
QStringList header;
|
||||
header.append(i18n("Name"));
|
||||
header.append(i18n("Description"));
|
||||
header.append(i18n("Created"));
|
||||
header.append(i18n("Modificated"));
|
||||
m_tw->setHeaderLabels(header);
|
||||
m_tw->setRootIsDecorated(false);
|
||||
|
||||
foreach(EmbeddedFile* ef, *document->embeddedFiles())
|
||||
{
|
||||
QTreeWidgetItem *twi = new QTreeWidgetItem();
|
||||
twi->setText(0, ef->name());
|
||||
twi->setText(1, ef->description());
|
||||
twi->setText(2, KGlobal::locale()->formatDateTime( ef->creationDate(), false, true ));
|
||||
twi->setText(3, KGlobal::locale()->formatDateTime( ef->modificationDate(), false, true ));
|
||||
m_tw->addTopLevelItem(twi);
|
||||
m_files.insert(twi, ef);
|
||||
}
|
||||
|
||||
connect(this, SIGNAL(user1Clicked()), this, SLOT(saveFile()));
|
||||
}
|
||||
|
||||
void EmbeddedFilesDialog::saveFile()
|
||||
{
|
||||
QList<QTreeWidgetItem *> selected = m_tw->selectedItems();
|
||||
foreach(QTreeWidgetItem *twi, selected)
|
||||
{
|
||||
EmbeddedFile* ef = m_files[twi];
|
||||
QString path = KFileDialog::getSaveFileName(ef->name(), QString(), this, i18n("Where do you want to save %1?", ef->name()));
|
||||
if (!path.isEmpty())
|
||||
{
|
||||
QFile f(path);
|
||||
if (!f.exists() || KMessageBox::warningContinueCancel( this, i18n("A file named \"%1\" already exists. Are you sure you want to overwrite it?", path), QString::null, i18n("Overwrite")) == KMessageBox::Continue)
|
||||
{
|
||||
f.open(QIODevice::WriteOnly);
|
||||
f.write(ef->data());
|
||||
f.close();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#include "embeddedfilesdialog.moc"
|
31
ui/embeddedfilesdialog.h
Normal file
31
ui/embeddedfilesdialog.h
Normal file
|
@ -0,0 +1,31 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2006 by Albert Astals Cid <aacid@kde.org> *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef _EMBEDDEDFILESDIALOG_H_
|
||||
#define _EMBEDDEDFILESDIALOG_H_
|
||||
|
||||
#include <kdialog.h>
|
||||
|
||||
class KPDFDocument;
|
||||
|
||||
class EmbeddedFilesDialog : public KDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
EmbeddedFilesDialog(QWidget *parent, const KPDFDocument *document);
|
||||
|
||||
private slots:
|
||||
void saveFile();
|
||||
|
||||
private:
|
||||
QTreeWidget *m_tw;
|
||||
QHash<QTreeWidgetItem *, EmbeddedFile*> m_files;
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Reference in a new issue