File indexing completed on 2025-01-19 03:55:35
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2018-12-31 0007 * Description : digiKam plugin about dialog 0008 * 0009 * SPDX-FileCopyrightText: 2018-2024 by Gilles Caulier <caulier dot gilles at gmail dot com> 0010 * 0011 * SPDX-License-Identifier: GPL-2.0-or-later 0012 * 0013 * ============================================================ */ 0014 0015 #include "dpluginaboutdlg.h" 0016 0017 // Qt includes 0018 0019 #include <QMap> 0020 #include <QStringList> 0021 #include <QString> 0022 #include <QLabel> 0023 #include <QTextBrowser> 0024 #include <QGridLayout> 0025 #include <QTabWidget> 0026 #include <QApplication> 0027 #include <QStyle> 0028 #include <QDialogButtonBox> 0029 #include <QVBoxLayout> 0030 #include <QPushButton> 0031 #include <QTreeWidget> 0032 #include <QListWidget> 0033 #include <QHeaderView> 0034 #include <QFileInfo> 0035 #include <QLocale> 0036 #include <QDateTime> 0037 0038 // KDE includes 0039 0040 #include <klocalizedstring.h> 0041 0042 // Local includes 0043 0044 #include "digikam_globals.h" 0045 #include "itempropertiestab.h" 0046 0047 namespace Digikam 0048 { 0049 0050 DPluginAboutDlg::DPluginAboutDlg(DPlugin* const tool, QWidget* const parent) 0051 : QDialog(parent), 0052 m_tool (tool) 0053 { 0054 setWindowFlags((windowFlags() & ~Qt::Dialog) | 0055 Qt::Window | 0056 Qt::WindowCloseButtonHint | 0057 Qt::WindowMinMaxButtonsHint); 0058 0059 setModal(true); 0060 setWindowTitle(i18nc("@title:window", "About %1 Plugin", tool->name())); 0061 0062 QDialogButtonBox* const buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Help, this); 0063 buttons->button(QDialogButtonBox::Ok)->setDefault(true); 0064 0065 QWidget* const page = new QWidget(this); 0066 QGridLayout* const grid = new QGridLayout(page); 0067 0068 // -------------------------------------------------------- 0069 0070 QLabel* const logo = new QLabel(page); 0071 logo->setPixmap(tool->icon().pixmap(QSize(48, 48))); 0072 0073 // -------------------------------------------------------- 0074 0075 QLabel* const header = new QLabel(page); 0076 header->setWordWrap(true); 0077 header->setText(QString::fromUtf8("<font size=\"5\">%1</font><br/>" 0078 "<b>%2 %3</b>" 0079 "<p>%4</p>") 0080 .arg(tool->name()) 0081 .arg(i18nc("@label", "Version")) 0082 .arg(tool->version()) 0083 .arg(tool->description())); 0084 0085 QTabWidget* const tab = new QTabWidget(page); 0086 0087 // -------------------------------------------------------- 0088 0089 QTextBrowser* const details = new QTextBrowser(tab); 0090 details->setOpenExternalLinks(true); 0091 details->setOpenLinks(false); 0092 details->setFocusPolicy(Qt::NoFocus); 0093 details->setTextInteractionFlags(Qt::LinksAccessibleByMouse); 0094 0095 QString txtDetails = tool->details(); 0096 txtDetails.replace(QLatin1String("\n"), QLatin1String("<br/>")); 0097 details->setText(txtDetails); 0098 0099 tab->addTab(details, i18nc("@title", "Details")); 0100 0101 // -------------------------------------------------------- 0102 0103 QTextBrowser* const authors = new QTextBrowser(tab); 0104 authors->setOpenExternalLinks(false); 0105 authors->setOpenLinks(false); 0106 authors->setFocusPolicy(Qt::NoFocus); 0107 0108 QString alist; 0109 0110 Q_FOREACH (const DPluginAuthor& auth, tool->authors()) 0111 { 0112 alist += QString::fromUtf8("<b>%1</b><ul>" 0113 "<li><i>%2</i></li>" 0114 "<li>%3</li>" 0115 "<li>%4</li></ul><br/>") 0116 .arg(auth.name) 0117 .arg(auth.email) 0118 .arg(auth.years) 0119 .arg(auth.roles); 0120 } 0121 0122 authors->setText(alist); 0123 0124 tab->addTab(authors, i18nc("@title", "Authors")); 0125 0126 // -------------------------------------------------------- 0127 0128 QTreeWidget* const props = new QTreeWidget(tab); 0129 props->setSortingEnabled(false); 0130 props->setRootIsDecorated(false); 0131 props->setSelectionMode(QAbstractItemView::SingleSelection); 0132 props->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); 0133 props->setAllColumnsShowFocus(true); 0134 props->setColumnCount(2); 0135 props->setHeaderLabels(QStringList() << i18nc("@title: DPlugin properties", "Name") 0136 << i18nc("@title: DPlugin properties", "Value")); 0137 0138 new QTreeWidgetItem(props, QStringList() << i18nc("@item", "Interface ID") << tool->ifaceIid()); 0139 new QTreeWidgetItem(props, QStringList() << i18nc("@item", "Tool ID") << tool->iid()); 0140 new QTreeWidgetItem(props, QStringList() << i18nc("@item", "Library") << tool->libraryFileName()); 0141 0142 QFileInfo fi(tool->libraryFileName()); 0143 0144 new QTreeWidgetItem(props, QStringList() << i18nc("@item", "File Size") << ItemPropertiesTab::humanReadableBytesCount(fi.size())); 0145 new QTreeWidgetItem(props, QStringList() << i18nc("@item", "File Date") << QLocale().toString(fi.lastModified(), QLocale::ShortFormat)); 0146 new QTreeWidgetItem(props, QStringList() << i18nc("@item", "File Owner") << fi.owner()); 0147 new QTreeWidgetItem(props, QStringList() << i18nc("@item", "File Group") << fi.group()); 0148 0149 tab->addTab(props, i18nc("@title", "Properties")); 0150 0151 // -------------------------------------------------------- 0152 0153 QMap<QString, QStringList> list = tool->extraAboutData(); 0154 0155 if (!list.isEmpty()) 0156 { 0157 QTreeWidget* const extra = new QTreeWidget(tab); 0158 extra->setSortingEnabled(false); 0159 extra->setRootIsDecorated(false); 0160 extra->setSelectionMode(QAbstractItemView::SingleSelection); 0161 extra->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); 0162 extra->setAllColumnsShowFocus(true); 0163 QStringList titles = tool->extraAboutDataRowTitles(); 0164 extra->setColumnCount(titles.count()); 0165 extra->setHeaderLabels(titles); 0166 0167 for (QMap<QString, QStringList>::const_iterator it = list.constBegin() ; it != list.constEnd() ; ++it) 0168 { 0169 new QTreeWidgetItem(extra, QStringList() << it.key() << it.value()); 0170 } 0171 0172 tab->addTab(extra, tool->extraAboutDataTitle()); 0173 } 0174 0175 // -------------------------------------------------------- 0176 0177 grid->addWidget(logo, 0, 0, 1, 1); 0178 grid->addWidget(header, 0, 1, 1, 1); 0179 grid->addWidget(tab, 2, 0, 1, -1); 0180 grid->setColumnStretch(1, 10); 0181 grid->setRowStretch(2, 10); 0182 grid->setContentsMargins(QMargins()); 0183 grid->setSpacing(qMin(QApplication::style()->pixelMetric(QStyle::PM_LayoutHorizontalSpacing), 0184 QApplication::style()->pixelMetric(QStyle::PM_LayoutVerticalSpacing))); 0185 0186 QVBoxLayout* const vbx = new QVBoxLayout(this); 0187 vbx->addWidget(page); 0188 vbx->addWidget(buttons); 0189 setLayout(vbx); 0190 0191 // -------------------------------------------------------- 0192 0193 connect(buttons->button(QDialogButtonBox::Ok), SIGNAL(clicked()), 0194 this, SLOT(accept())); 0195 0196 connect(buttons->button(QDialogButtonBox::Help), SIGNAL(clicked()), 0197 this, SLOT(slotOnlineHandbook())); 0198 0199 resize(400, 500); 0200 } 0201 0202 DPluginAboutDlg::~DPluginAboutDlg() 0203 { 0204 } 0205 0206 void DPluginAboutDlg::slotOnlineHandbook() 0207 { 0208 openOnlineDocumentation(m_tool->handbookSection(), m_tool->handbookChapter(), m_tool->handbookReference()); 0209 } 0210 0211 } // namespace Digikam 0212 0213 #include "moc_dpluginaboutdlg.cpp"