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