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 "info.h" |
20 | |
21 | #include <poppler-qt6.h> |
22 | |
23 | #include <QtWidgets/QTableWidget> |
24 | |
25 | InfoDock::InfoDock(QWidget *parent) : AbstractInfoDock(parent) |
26 | { |
27 | m_table = new QTableWidget(this); |
28 | setWidget(m_table); |
29 | setWindowTitle(tr(s: "Information" )); |
30 | m_table->setColumnCount(2); |
31 | m_table->setHorizontalHeaderLabels(QStringList() << tr(s: "Key" ) << tr(s: "Value" )); |
32 | m_table->setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel); |
33 | } |
34 | |
35 | InfoDock::~InfoDock() { } |
36 | |
37 | void InfoDock::fillInfo() |
38 | { |
39 | QStringList keys = document()->infoKeys(); |
40 | m_table->setHorizontalHeaderLabels(QStringList() << tr(s: "Key" ) << tr(s: "Value" )); |
41 | m_table->setRowCount(keys.count()); |
42 | QStringList dateKeys; |
43 | dateKeys << QStringLiteral("CreationDate" ); |
44 | dateKeys << QStringLiteral("ModDate" ); |
45 | int i = 0; |
46 | Q_FOREACH (const QString &date, dateKeys) { |
47 | const int id = keys.indexOf(str: date); |
48 | if (id != -1) { |
49 | m_table->setItem(row: i, column: 0, item: new QTableWidgetItem(date)); |
50 | m_table->setItem(row: i, column: 1, item: new QTableWidgetItem(QLocale().toString(dateTime: document()->date(type: date), format: QLocale::ShortFormat))); |
51 | ++i; |
52 | keys.removeAt(i: id); |
53 | } |
54 | } |
55 | Q_FOREACH (const QString &key, keys) { |
56 | m_table->setItem(row: i, column: 0, item: new QTableWidgetItem(key)); |
57 | m_table->setItem(row: i, column: 1, item: new QTableWidgetItem(document()->info(type: key))); |
58 | ++i; |
59 | } |
60 | } |
61 | |
62 | void InfoDock::documentClosed() |
63 | { |
64 | m_table->clear(); |
65 | m_table->setRowCount(0); |
66 | AbstractInfoDock::documentClosed(); |
67 | } |
68 | |