1 /*
2 * Copyright (C) 2008, Pino Toscano <pino@kde.org>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2, or (at your option)
7 * any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
17 */
18
19 #include "embeddedfiles.h"
20
21 #include <poppler-qt4.h>
22
23 #include <QtGui/QTableWidget>
24
EmbeddedFilesDock(QWidget * parent)25 EmbeddedFilesDock::EmbeddedFilesDock(QWidget *parent)
26 : AbstractInfoDock(parent)
27 {
28 m_table = new QTableWidget(this);
29 setWidget(m_table);
30 setWindowTitle(tr("Embedded files"));
31 m_table->setColumnCount(6);
32 m_table->setHorizontalHeaderLabels(
33 QStringList() << tr("Name") << tr("Description") << tr("Size") << tr("Creation date")
34 << tr("Modification date") << tr("Checksum"));
35 m_table->setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel);
36 }
37
~EmbeddedFilesDock()38 EmbeddedFilesDock::~EmbeddedFilesDock()
39 {
40 }
41
fillInfo()42 void EmbeddedFilesDock::fillInfo()
43 {
44 m_table->setHorizontalHeaderLabels(
45 QStringList() << tr("Name") << tr("Description") << tr("Size") << tr("Creation date")
46 << tr("Modification date") << tr("Checksum"));
47 if (!document()->hasEmbeddedFiles()) {
48 m_table->setItem(0, 0, new QTableWidgetItem(tr("No files")));
49 return;
50 }
51
52 const QList<Poppler::EmbeddedFile*> files = document()->embeddedFiles();
53 m_table->setRowCount(files.count());
54 int i = 0;
55 Q_FOREACH(Poppler::EmbeddedFile *file, files) {
56 m_table->setItem(i, 0, new QTableWidgetItem(file->name()));
57 m_table->setItem(i, 1, new QTableWidgetItem(file->description()));
58 m_table->setItem(i, 2, new QTableWidgetItem(QString::number(file->size())));
59 m_table->setItem(i, 3, new QTableWidgetItem(file->createDate().toString(Qt::SystemLocaleDate)));
60 m_table->setItem(i, 4, new QTableWidgetItem(file->modDate().toString(Qt::SystemLocaleDate)));
61 const QByteArray checksum = file->checksum();
62 const QString checksumString = !checksum.isEmpty() ? QString::fromAscii(checksum.toHex()) : QString::fromLatin1("n/a");
63 m_table->setItem(i, 5, new QTableWidgetItem(checksumString));
64 ++i;
65 }
66 }
67
documentLoaded()68 void EmbeddedFilesDock::documentLoaded()
69 {
70 if ( document()->pageMode() == Poppler::Document::UseAttach ) {
71 show();
72 }
73 }
74
documentClosed()75 void EmbeddedFilesDock::documentClosed()
76 {
77 m_table->clear();
78 m_table->setRowCount(0);
79 AbstractInfoDock::documentClosed();
80 }
81
82 #include "embeddedfiles.moc"
83