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-qt5.h>
22 
23 #include <QtWidgets/QTableWidget>
24 
EmbeddedFilesDock(QWidget * parent)25 EmbeddedFilesDock::EmbeddedFilesDock(QWidget *parent) : AbstractInfoDock(parent)
26 {
27     m_table = new QTableWidget(this);
28     setWidget(m_table);
29     setWindowTitle(tr("Embedded files"));
30     m_table->setColumnCount(6);
31     m_table->setHorizontalHeaderLabels(QStringList() << tr("Name") << tr("Description") << tr("Size") << tr("Creation date") << tr("Modification date") << tr("Checksum"));
32     m_table->setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel);
33 }
34 
~EmbeddedFilesDock()35 EmbeddedFilesDock::~EmbeddedFilesDock() { }
36 
fillInfo()37 void EmbeddedFilesDock::fillInfo()
38 {
39     m_table->setHorizontalHeaderLabels(QStringList() << tr("Name") << tr("Description") << tr("Size") << tr("Creation date") << tr("Modification date") << tr("Checksum"));
40     if (!document()->hasEmbeddedFiles()) {
41         m_table->setItem(0, 0, new QTableWidgetItem(tr("No files")));
42         return;
43     }
44 
45     const QList<Poppler::EmbeddedFile *> files = document()->embeddedFiles();
46     m_table->setRowCount(files.count());
47     int i = 0;
48     Q_FOREACH (Poppler::EmbeddedFile *file, files) {
49         m_table->setItem(i, 0, new QTableWidgetItem(file->name()));
50         m_table->setItem(i, 1, new QTableWidgetItem(file->description()));
51         m_table->setItem(i, 2, new QTableWidgetItem(QString::number(file->size())));
52         m_table->setItem(i, 3, new QTableWidgetItem(file->createDate().toString(Qt::SystemLocaleDate)));
53         m_table->setItem(i, 4, new QTableWidgetItem(file->modDate().toString(Qt::SystemLocaleDate)));
54         const QByteArray checksum = file->checksum();
55         const QString checksumString = !checksum.isEmpty() ? QString::fromLatin1(checksum.toHex()) : QStringLiteral("n/a");
56         m_table->setItem(i, 5, new QTableWidgetItem(checksumString));
57         ++i;
58     }
59 }
60 
documentLoaded()61 void EmbeddedFilesDock::documentLoaded()
62 {
63     if (document()->pageMode() == Poppler::Document::UseAttach) {
64         show();
65     }
66 }
67 
documentClosed()68 void EmbeddedFilesDock::documentClosed()
69 {
70     m_table->clear();
71     m_table->setRowCount(0);
72     AbstractInfoDock::documentClosed();
73 }
74