| 1 | // SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. |
| 2 | // |
| 3 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 4 | |
| 5 | #include "aboutdialog.h" |
| 6 | #include "common/common.h" |
| 7 | |
| 8 | #include <QGridLayout> |
| 9 | #include <QLabel> |
| 10 | #include <QPushButton> |
| 11 | #include <QLatin1String> |
| 12 | #include <QDateTime> |
| 13 | #include <QDesktopServices> |
| 14 | |
| 15 | const QString ICON_LOGO_128PX = ":/core/images/unioncode@128.png" ; |
| 16 | |
| 17 | AboutDialog::AboutDialog(QDialog *parent) |
| 18 | : QDialog(parent) |
| 19 | { |
| 20 | setupUi(); |
| 21 | } |
| 22 | |
| 23 | AboutDialog::~AboutDialog() |
| 24 | { |
| 25 | |
| 26 | } |
| 27 | |
| 28 | void AboutDialog::setupUi() |
| 29 | { |
| 30 | setWindowTitle(tr("About Deepin Union Code" )); |
| 31 | |
| 32 | QLabel *logoLabel = new QLabel; |
| 33 | logoLabel->setPixmap(QPixmap(ICON_LOGO_128PX)); |
| 34 | |
| 35 | QString buildDateInfo = tr("<br/>Built on %1 %2 in %3<br/>" ) |
| 36 | .arg(QLatin1String(__DATE__), QLatin1String(__TIME__), ProcessUtil::localPlatform()); |
| 37 | |
| 38 | const QString description = tr( |
| 39 | "<h3>Deepin Union Code %1</h3>" |
| 40 | "%2<br/>" |
| 41 | "Copyright 2019-%3 UnionTech Software Technology Co., Ltd. All rights reserved.<br/><br/>" |
| 42 | "This program is released under <a href=\"https://www.gnu.org/licenses/gpl-3.0.html\">GPL-3.0-or-later</a>; \ |
| 43 | we hope that the scheme will be useful, \ |
| 44 | but we do not guarantee that it will be of economic value or fit for a particular purpose. \ |
| 45 | For more information, see the GNU General Public License. <br/>\ |
| 46 | Thanks to all the <a href=\"opensourcesoftware\">open source software</a> used." |
| 47 | "<br/>" ) |
| 48 | .arg(version(), |
| 49 | buildDateInfo, |
| 50 | QString::number(QDateTime::currentDateTime().date().year())); |
| 51 | |
| 52 | QLabel *copyRightLabel = new QLabel(description); |
| 53 | copyRightLabel->setWordWrap(true); |
| 54 | copyRightLabel->setTextInteractionFlags(Qt::TextBrowserInteraction); |
| 55 | connect(copyRightLabel, &QLabel::linkActivated, this, &AboutDialog::handleLinkActivated); |
| 56 | |
| 57 | QHBoxLayout *layoutButtons = new QHBoxLayout(); |
| 58 | QPushButton *closeButton = new QPushButton(QPushButton::tr("Close" )); |
| 59 | connect(closeButton , &QPushButton::clicked, this, &QDialog::reject); |
| 60 | layoutButtons->addStretch(); |
| 61 | layoutButtons->addWidget(closeButton); |
| 62 | |
| 63 | auto vLayout = new QVBoxLayout(this); |
| 64 | auto detailLayout = new QGridLayout(this); |
| 65 | detailLayout->setSizeConstraint(QLayout::SetFixedSize); |
| 66 | detailLayout->addWidget(logoLabel , 1, 0, 1, 1); |
| 67 | detailLayout->addWidget(copyRightLabel, 0, 4, 4, 5); |
| 68 | detailLayout->addLayout(layoutButtons, 4, 4, 1, 5); |
| 69 | vLayout->addLayout(detailLayout); |
| 70 | } |
| 71 | |
| 72 | void AboutDialog::handleLinkActivated(const QString& link) |
| 73 | { |
| 74 | if (link == "opensourcesoftware" && !bExpand) { |
| 75 | QFile file("/usr/share/doc/deepin-unioncode/copyright" ); |
| 76 | if (file.open(QIODevice::ReadOnly | QIODevice::Text)) { |
| 77 | QTextEdit* textEdit = new QTextEdit(this); |
| 78 | layout()->addWidget(textEdit); |
| 79 | |
| 80 | QTextStream stream(&file); |
| 81 | QString fileContent = stream.readAll(); |
| 82 | textEdit->setPlainText(fileContent); |
| 83 | setFixedHeight(height() * 2); |
| 84 | bExpand = true; |
| 85 | } else { |
| 86 | QMessageBox::critical(this, tr("Error" ), tr("Failed to open the file." )); |
| 87 | } |
| 88 | } else { |
| 89 | QDesktopServices::openUrl(QUrl(link)); |
| 90 | } |
| 91 | } |
| 92 | |