File indexing completed on 2024-05-12 16:27:40

0001 /*
0002    SPDX-FileCopyrightText: 2023-2024 Laurent Montel <montel.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 #include "whatsnewwidget.h"
0007 #include "whatsnewwidgettranslation.h"
0008 
0009 #include <QCryptographicHash>
0010 #include <QScrollArea>
0011 #include <QTextEdit>
0012 #include <QVBoxLayout>
0013 
0014 WhatsNewWidget::WhatsNewWidget(QWidget *parent)
0015     : QWidget{parent}
0016     , mLabelInfo(new QTextEdit(this))
0017     , mWhatsNewComboBoxWidget(new WhatsNewComboBoxWidget(this))
0018 {
0019     auto mainLayout = new QVBoxLayout(this);
0020     mainLayout->setObjectName(QStringLiteral("mainLayout"));
0021     mainLayout->setContentsMargins({});
0022 
0023     mWhatsNewComboBoxWidget->setObjectName(QStringLiteral("mWhatsNewComboBoxWidget"));
0024     mainLayout->addWidget(mWhatsNewComboBoxWidget);
0025 
0026     mLabelInfo->setObjectName(QStringLiteral("mLabelInfo"));
0027     mLabelInfo->setReadOnly(true);
0028     mLabelInfo->setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::LinksAccessibleByMouse);
0029     connect(mWhatsNewComboBoxWidget, &WhatsNewComboBoxWidget::versionChanged, this, &WhatsNewWidget::slotVersionChanged);
0030     mWhatsNewComboBoxWidget->initializeVersion(currentVersion());
0031     mainLayout->addWidget(mLabelInfo);
0032 }
0033 
0034 WhatsNewWidget::~WhatsNewWidget() = default;
0035 
0036 WhatsNewComboBoxWidget::VersionType WhatsNewWidget::currentVersion() const
0037 {
0038     return WhatsNewComboBoxWidget::Version2_1;
0039 }
0040 
0041 // static
0042 QString WhatsNewWidget::newFeaturesMD5()
0043 {
0044     QByteArray str;
0045     for (int i = 0; i < numRuqolaNewFeatures2_1; ++i) {
0046         str += ruqolaNewFeatures2_1[i].untranslatedText();
0047     }
0048     QCryptographicHash md5(QCryptographicHash::Md5);
0049     md5.addData(str);
0050     return QLatin1String(md5.result().toBase64());
0051 }
0052 
0053 void WhatsNewWidget::updateInformations()
0054 {
0055     slotVersionChanged(currentVersion());
0056 }
0057 
0058 QString WhatsNewWidget::generateStartEndHtml(const QString &str) const
0059 {
0060     QString message = QStringLiteral("<qt>");
0061     message += str;
0062     message += QStringLiteral("</qt>");
0063     return message;
0064 }
0065 
0066 void WhatsNewWidget::slotVersionChanged(WhatsNewComboBoxWidget::VersionType type)
0067 {
0068     if (type == WhatsNewComboBoxWidget::Version2_0) {
0069         const QString message = generateStartEndHtml(createVersionInformationsV2_0());
0070         mLabelInfo->setHtml(message);
0071     } else if (type == WhatsNewComboBoxWidget::Version2_1) {
0072         const QString message = generateStartEndHtml(createVersionInformationsV2_1());
0073         mLabelInfo->setHtml(message);
0074     } else if (type == WhatsNewComboBoxWidget::AllVersion) {
0075         QString message = generateVersionHeader(WhatsNewComboBoxWidget::Version2_1);
0076         message += createVersionInformationsV2_1();
0077         message += generateVersionHeader(WhatsNewComboBoxWidget::Version2_0);
0078         message += createVersionInformationsV2_0();
0079         mLabelInfo->setHtml(generateStartEndHtml(message));
0080     }
0081 }
0082 
0083 QString WhatsNewWidget::createVersionInformationsV2_0() const
0084 {
0085     QString message;
0086     if (numRuqolaChanges2_0 > 0) {
0087         message += QStringLiteral("<b>") + i18n("Important changes since last version:") + QStringLiteral("</b>");
0088         message += QStringLiteral("<ul>");
0089         for (int i = 0; i < numRuqolaChanges2_0; ++i) {
0090             message += QStringLiteral("<li>%1</li>").arg(ruqolaChangesV2_0[i].toString());
0091         }
0092         message += QStringLiteral("</ul>");
0093     }
0094     if (numRuqolaNewFeatures2_0 > 0) {
0095         message += QStringLiteral("<b>") + i18n("Some of the new features in this release of Ruqola include:") + QStringLiteral("</b>");
0096         message += QStringLiteral("<ul>");
0097         for (int i = 0; i < numRuqolaNewFeatures2_0; ++i) {
0098             message += QStringLiteral("<li>%1</li>").arg(ruqolaNewFeatures2_0[i].toString());
0099         }
0100         message += QStringLiteral("</ul>");
0101     }
0102     if (numRuqolaBugfixing2_0 > 0) {
0103         message += QStringLiteral("<b>") + i18n("Some bug fixing:") + QStringLiteral("</b>");
0104         message += QStringLiteral("<ul>");
0105         for (int i = 0; i < numRuqolaBugfixing2_0; ++i) {
0106             message += QStringLiteral("<li>%1</li>").arg(ruqolaBugfixing2_0[i].toString());
0107         }
0108         message += QStringLiteral("</ul>");
0109     }
0110     return message;
0111 }
0112 
0113 QString WhatsNewWidget::createVersionInformationsV2_1() const
0114 {
0115     QString message;
0116     if (numRuqolaNewFeatures2_1 > 0) {
0117         message += QStringLiteral("<b>") + i18n("Some of the new features in this release of Ruqola include:") + QStringLiteral("</b>");
0118         message += QStringLiteral("<ul>");
0119         for (int i = 0; i < numRuqolaNewFeatures2_1; ++i) {
0120             message += QStringLiteral("<li>%1</li>").arg(ruqolaNewFeatures2_1[i].toString());
0121         }
0122         message += QStringLiteral("</ul>");
0123     }
0124     if (numRuqolaBugfixing2_1 > 0) {
0125         message += QStringLiteral("<b>") + i18n("Some bug fixing:") + QStringLiteral("</b>");
0126         message += QStringLiteral("<ul>");
0127         for (int i = 0; i < numRuqolaBugfixing2_1; ++i) {
0128             message += QStringLiteral("<li>%1</li>").arg(ruqolaBugfixing2_1[i].toString());
0129         }
0130         message += QStringLiteral("</ul>");
0131     }
0132     return message;
0133 }
0134 
0135 QString WhatsNewWidget::generateVersionHeader(WhatsNewComboBoxWidget::VersionType type) const
0136 {
0137     switch (type) {
0138     case WhatsNewComboBoxWidget::VersionType::AllVersion:
0139         return {};
0140     case WhatsNewComboBoxWidget::VersionType::Version2_0:
0141     case WhatsNewComboBoxWidget::VersionType::Version2_1:
0142         return QStringLiteral("<h1><i> %1 </i></h1><hr/><br>").arg(WhatsNewComboBoxWidget::convertVersionEnumToString(type));
0143     }
0144     return {};
0145 }
0146 
0147 #include "moc_whatsnewwidget.cpp"