File indexing completed on 2025-11-09 04:06:40

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2008-07-11
0007  * Description : general info list dialog
0008  *
0009  * SPDX-FileCopyrightText: 2008-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0010  * SPDX-FileCopyrightText: 2009      by Andi Clemens <andi dot clemens at gmail dot com>
0011  *
0012  * SPDX-License-Identifier: GPL-2.0-or-later
0013  *
0014  * ============================================================ */
0015 
0016 #include "infodlg.h"
0017 
0018 // Qt includes
0019 
0020 #include <QStringList>
0021 #include <QString>
0022 #include <QLabel>
0023 #include <QGridLayout>
0024 #include <QHeaderView>
0025 #include <QMimeData>
0026 #include <QClipboard>
0027 #include <QApplication>
0028 #include <QStyle>
0029 #include <QStandardPaths>
0030 #include <QVBoxLayout>
0031 #include <QPushButton>
0032 
0033 // KDE includes
0034 
0035 #include <klocalizedstring.h>
0036 
0037 // Local includes
0038 
0039 #include "digikam_globals.h"
0040 #include "daboutdata.h"
0041 
0042 namespace Digikam
0043 {
0044 
0045 class Q_DECL_HIDDEN InfoDlg::Private
0046 {
0047 public:
0048 
0049     explicit Private()
0050       : listView(nullptr),
0051         page    (nullptr),
0052         buttons (nullptr),
0053         tabView (nullptr)
0054     {
0055     }
0056 
0057     QTreeWidget*      listView;
0058     QWidget*          page;
0059     QDialogButtonBox* buttons;
0060     QTabWidget*       tabView;
0061 };
0062 
0063 InfoDlg::InfoDlg(QWidget* const parent)
0064     : QDialog(parent),
0065       d      (new Private)
0066 {
0067     setModal(false);
0068     setWindowTitle(i18nc("@title:window", "Shared Libraries and Components Information"));
0069 
0070     d->buttons = new QDialogButtonBox(QDialogButtonBox::Help  |
0071                                       QDialogButtonBox::Apply |
0072                                       QDialogButtonBox::Ok, this);
0073     d->buttons->button(QDialogButtonBox::Ok)->setDefault(true);
0074     d->buttons->button(QDialogButtonBox::Apply)->setText(i18n("Copy to Clipboard"));
0075 
0076     d->page                 = new QWidget(this);
0077     QGridLayout* const grid = new QGridLayout(d->page);
0078 
0079     // --------------------------------------------------------
0080 
0081     QLabel* const logo      = new QLabel(d->page);
0082 
0083     if (QApplication::applicationName() == QLatin1String("digikam"))
0084     {
0085         logo->setPixmap(QIcon::fromTheme(QLatin1String("digikam")).pixmap(QSize(48,48)));
0086     }
0087     else
0088     {
0089         logo->setPixmap(QIcon::fromTheme(QLatin1String("showfoto")).pixmap(QSize(48,48)));
0090     }
0091 
0092     // --------------------------------------------------------
0093 
0094     QLabel* const header    = new QLabel(d->page);
0095     header->setWordWrap(true);
0096     header->setText(i18n("<font size=\"5\">%1</font><br/><b>Version %2</b>"
0097                          "<p>%3</p><p><i>%4</i></p>",
0098                          QApplication::applicationName(),
0099                          QApplication::applicationVersion(),
0100                          DAboutData::digiKamSlogan(),
0101                          DAboutData::digiKamFamily()));
0102 
0103     // --------------------------------------------------------
0104 
0105     d->tabView              = new QTabWidget(d->page);
0106 
0107     d->listView             = new QTreeWidget(d->page);
0108     d->listView->setSortingEnabled(false);
0109     d->listView->setRootIsDecorated(false);
0110     d->listView->setSelectionMode(QAbstractItemView::SingleSelection);
0111     d->listView->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
0112     d->listView->setAllColumnsShowFocus(true);
0113     d->listView->setColumnCount(2);
0114     d->listView->header()->setSectionResizeMode(QHeaderView::Stretch);
0115     d->listView->header()->setVisible(false);
0116 
0117     d->tabView->addTab(d->listView, i18n("Items List"));
0118     d->tabView->setTabBarAutoHide(true);
0119 
0120     // --------------------------------------------------------
0121 
0122     grid->addWidget(logo,        0, 0, 1, 1);
0123     grid->addWidget(header,      0, 1, 1, 1);
0124 
0125     // row 1 can be expanded by custom widgets in the subclassed dialog
0126 
0127     grid->addWidget(d->tabView,  2, 0, 1, -1);
0128     grid->setColumnStretch(1, 10);
0129     grid->setRowStretch(2, 10);
0130     grid->setContentsMargins(QMargins());
0131     grid->setSpacing(qMin(QApplication::style()->pixelMetric(QStyle::PM_LayoutHorizontalSpacing),
0132                              QApplication::style()->pixelMetric(QStyle::PM_LayoutVerticalSpacing)));
0133 
0134     QVBoxLayout* const vbx = new QVBoxLayout(this);
0135     vbx->addWidget(d->page);
0136     vbx->addWidget(d->buttons);
0137     setLayout(vbx);
0138 
0139     // --------------------------------------------------------
0140 
0141     connect(d->buttons->button(QDialogButtonBox::Ok), SIGNAL(clicked()),
0142             this, SLOT(accept()));
0143 
0144     connect(d->buttons->button(QDialogButtonBox::Help), SIGNAL(clicked()),
0145             this, SLOT(slotHelp()));
0146 
0147     // --- NOTE: use dynamic binding as slotCopy2ClipBoard() is a virtual slot which can be re-implemented in derived classes.
0148 
0149     connect(d->buttons->button(QDialogButtonBox::Apply), &QPushButton::clicked,
0150             this, &InfoDlg::slotCopy2ClipBoard);
0151 
0152     resize(400, 500);
0153 }
0154 
0155 InfoDlg::~InfoDlg()
0156 {
0157     delete d;
0158 }
0159 
0160 QTabWidget* InfoDlg::tabView() const
0161 {
0162     return d->tabView;
0163 }
0164 
0165 QTreeWidget* InfoDlg::listView() const
0166 {
0167     return d->listView;
0168 }
0169 
0170 QDialogButtonBox* InfoDlg::buttonBox() const
0171 {
0172     return d->buttons;
0173 }
0174 
0175 QWidget* InfoDlg::mainWidget() const
0176 {
0177     return d->page;
0178 }
0179 
0180 void InfoDlg::setInfoMap(const QMap<QString, QString>& list)
0181 {
0182     for (QMap<QString, QString>::const_iterator it = list.constBegin() ;
0183          it != list.constEnd() ; ++it)
0184     {
0185         new QTreeWidgetItem(d->listView, QStringList() << it.key() << it.value());
0186     }
0187 }
0188 
0189 void InfoDlg::slotCopy2ClipBoard()
0190 {
0191     QString textInfo;
0192 
0193     textInfo.append(QApplication::applicationName());
0194     textInfo.append(QLatin1String(" version "));
0195     textInfo.append(QApplication::applicationVersion());
0196     textInfo.append(QLatin1Char('\n'));
0197 
0198     QTreeWidgetItemIterator it(d->listView);
0199 
0200     while (*it)
0201     {
0202         textInfo.append((*it)->text(0));
0203         textInfo.append(QLatin1String(": "));
0204         textInfo.append((*it)->text(1));
0205         textInfo.append(QLatin1Char('\n'));
0206         ++it;
0207     }
0208 
0209     QMimeData* const mimeData = new QMimeData();
0210     mimeData->setText(textInfo);
0211     QApplication::clipboard()->setMimeData(mimeData, QClipboard::Clipboard);
0212 }
0213 
0214 void InfoDlg::slotHelp()
0215 {
0216     openOnlineDocumentation();
0217 }
0218 
0219 } // namespace Digikam
0220 
0221 #include "moc_infodlg.cpp"