1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
|
/*
SPDX-FileCopyrightText: 2025-2026 Laurent Montel <montel@kde.org>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "checknewversionwidget.h"
#include "needupdateversion/needupdatecheckexistingnewversionjob.h"
#include "needupdateversion/needupdateversionutils.h"
#include "textaddonswidgets_debug.h"
#include <KLocalizedString>
#include <QDesktopServices>
#include <QLabel>
#include <QVBoxLayout>
using namespace TextAddonsWidgets;
CheckNewVersionWidget::CheckNewVersionWidget(QWidget *parent)
: QWidget{parent}
, mCheckVersionResultLabel(new QLabel(this))
{
auto mainLayout = new QVBoxLayout(this);
mainLayout->setObjectName(QStringLiteral("mainLayout"));
mainLayout->setContentsMargins({});
mCheckVersionResultLabel->setObjectName(QStringLiteral("mCheckVersionResultLabel"));
mCheckVersionResultLabel->setWordWrap(true);
mCheckVersionResultLabel->setOpenExternalLinks(true);
mCheckVersionResultLabel->setTextFormat(Qt::RichText);
mainLayout->addWidget(mCheckVersionResultLabel);
}
CheckNewVersionWidget::~CheckNewVersionWidget() = default;
void CheckNewVersionWidget::checkNewVersion()
{
auto job = new NeedUpdateCheckExistingNewVersionJob(this);
job->setUrl(mUrl);
job->setCompileDate(NeedUpdateVersionUtils::compileDate());
connect(job, &NeedUpdateCheckExistingNewVersionJob::foundNewVersion, this, &CheckNewVersionWidget::slotFoundNewVersion);
job->start();
}
void CheckNewVersionWidget::setUrl(const QUrl &url)
{
mUrl = url;
}
void CheckNewVersionWidget::slotFoundNewVersion(bool found)
{
Q_ASSERT(!mUrl.isEmpty());
if (found) {
mCheckVersionResultLabel->setText(i18n("A new version found. Click <a href=\"%1\">here</a> for downloading it.", mUrl.toString()));
} else {
mCheckVersionResultLabel->setText(i18n("No new version found. Build can be found <a href=\"%1\">here</a>.", mUrl.toString()));
}
connect(mCheckVersionResultLabel, &QLabel::linkActivated, this, [](const QString &url) {
if (!QDesktopServices::openUrl(QUrl(url))) {
qCWarning(TEXTADDONSWIDGETS_LOG) << "Impossible to open url: " << url;
}
});
}
#include "moc_checknewversionwidget.cpp"
|