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=545966remotes/origin/old/work/newpageview
parent
91dc3ef06c
commit
13dde4096f
11 changed files with 210 additions and 4 deletions
@ -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" |
||||
@ -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 new issue