File indexing completed on 2025-01-05 05:23:46

0001 /*
0002     This file is part of the Okteta Kasten Framework, made within the KDE community.
0003 
0004     SPDX-FileCopyrightText: 2022 Friedrich W. H. Kossebau <kossebau@kde.org>
0005 
0006     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0007 */
0008 
0009 #include "aboutstructuredialog.hpp"
0010 
0011 // tool
0012 #include "licensedialog.hpp"
0013 // KF
0014 #include <KTitleWidget>
0015 #include <KLocalizedString>
0016 #include <KAboutData>
0017 // Qt
0018 #include <QGuiApplication>
0019 #include <QTabWidget>
0020 #include <QToolBar>
0021 #include <QCheckBox>
0022 #include <QDialogButtonBox>
0023 #include <QIcon>
0024 #include <QLabel>
0025 #include <QVBoxLayout>
0026 #include <QAction>
0027 #include <QDesktopServices>
0028 #include <QUrl>
0029 
0030 
0031 AboutStructureDialog::AboutStructureDialog(const StructureMetaData& structureMetaData, QWidget* parent)
0032     : QDialog(parent)
0033     , m_structureMetaData(structureMetaData)
0034 {
0035     setAttribute(Qt::WA_DeleteOnClose);
0036     setWindowTitle(i18nc("@title:window", "About %1", m_structureMetaData.name()));
0037 
0038     auto* mainLayout = new QVBoxLayout(this);
0039 
0040     // title
0041     const QIcon titleIcon = m_structureMetaData.hasIconName() ? QIcon::fromTheme(m_structureMetaData.iconName()) : qApp->windowIcon();
0042     auto* titleWidget = new KTitleWidget(this);
0043 
0044     const QString titleText = QLatin1String("<font size=\"5\">") + m_structureMetaData.name() + QLatin1String("</font><br />") + i18nc("Version version-number", "Version %1", m_structureMetaData.version());
0045     titleWidget->setIconSize(QSize(48, 48));
0046     titleWidget->setIcon(titleIcon, KTitleWidget::ImageLeft);
0047     titleWidget->setText(titleText);
0048     mainLayout->addWidget(titleWidget);
0049 
0050     // tab bar
0051     auto* tabWidget = new QTabWidget;
0052     tabWidget->setUsesScrollButtons(false);
0053 
0054     // About page
0055     auto* aboutWidget = new QWidget(this);
0056     auto* aboutLayout = new QVBoxLayout(aboutWidget);
0057 
0058     aboutLayout->addStretch();
0059 
0060     QString aboutPageText = m_structureMetaData.comment().trimmed();
0061 
0062     if (m_structureMetaData.hasWebsite()) {
0063         if (!aboutPageText.isEmpty()) {
0064             aboutPageText += QLatin1String("<br /><br />");
0065         }
0066         aboutPageText += QLatin1String("<a href=\"%1\">") + m_structureMetaData.website() + QLatin1String("</a>");
0067     }
0068 
0069     if (!aboutPageText.isEmpty()) {
0070         auto* aboutLabel = new QLabel;
0071         aboutLabel->setWordWrap(true);
0072         aboutLabel->setOpenExternalLinks(true);
0073         aboutLabel->setText(aboutPageText.replace(QLatin1Char('\n'), QStringLiteral("<br />")));
0074         aboutLabel->setTextInteractionFlags(Qt::TextBrowserInteraction);
0075 
0076         aboutLayout->addWidget(aboutLabel);
0077     }
0078 
0079     auto* showLicenseLabel = new QLabel;
0080     if (m_structureMetaData.license().key() != KAboutLicense::Unknown) {
0081         const QString licenseLabelText = QLatin1String("<a href=\"showlicense\">") + i18n("License: %1", m_structureMetaData.license().name(KAboutLicense::FullName)) + QLatin1String("</a>");
0082         showLicenseLabel->setText(licenseLabelText);
0083         showLicenseLabel->setTextInteractionFlags(Qt::TextBrowserInteraction);
0084         connect(showLicenseLabel, &QLabel::linkActivated, this, &AboutStructureDialog::showLicenseDialog);
0085     } else {
0086         showLicenseLabel->setText(i18n("License: %1", m_structureMetaData.license().name(KAboutLicense::FullName)));
0087     }
0088     aboutLayout->addWidget(showLicenseLabel);
0089 
0090     aboutLayout->addStretch();
0091 
0092     tabWidget->addTab(aboutWidget, i18nc("@title:tab", "About"));
0093 
0094     // author page
0095     if (m_structureMetaData.hasAuthorName())  {
0096         auto* authorWidget = new QWidget(this);
0097         auto* authorLayout = new QVBoxLayout(authorWidget);
0098 
0099         const QString nameMarkup = QLatin1String("<b>") + m_structureMetaData.authorName() + QLatin1String("</b>");
0100         auto* nameLabel = new QLabel(nameMarkup);
0101         authorLayout->addWidget(nameLabel);
0102 
0103         if (m_structureMetaData.hasAuthorEmailAddress()) {
0104             auto* contactToolBar = new QToolBar(this);
0105             auto* emailAction = new QAction(this);
0106             emailAction->setIcon(QIcon::fromTheme(QStringLiteral("mail-send")));
0107             emailAction->setToolTip(i18nc("@info:tooltip Send an email to the author", "Email author\n%1", m_structureMetaData.authorEmailAddress()));
0108             connect(emailAction, &QAction::triggered, this, &AboutStructureDialog::emailAuthor);
0109             contactToolBar->addAction(emailAction);
0110 
0111             authorLayout->addWidget(contactToolBar);
0112         }
0113 
0114         authorLayout->addStretch();
0115 
0116         tabWidget->addTab(authorWidget, i18nc("@title:tab", "Author"));
0117     }
0118     mainLayout->addWidget(tabWidget);
0119 
0120     auto* buttonBox = new QDialogButtonBox(this);
0121     buttonBox->setStandardButtons(QDialogButtonBox::Close);
0122     connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
0123     connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
0124 
0125     mainLayout->addWidget(buttonBox);
0126 }
0127 
0128 void AboutStructureDialog::showLicenseDialog()
0129 {
0130     auto* dialog = new LicenseDialog(m_structureMetaData.license(), this);
0131     dialog->show();
0132 }
0133 
0134 void AboutStructureDialog::emailAuthor()
0135 {
0136     const QUrl mailToUrl(QLatin1String("mailto:") + m_structureMetaData.authorEmailAddress());
0137     QDesktopServices::openUrl(mailToUrl);
0138 }
0139 
0140 #include "moc_aboutstructuredialog.cpp"