Pimcommon

checknewversionwidget.cpp
1/*
2 SPDX-FileCopyrightText: 2025 Laurent Montel <montel@kde.org>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#include "checknewversionwidget.h"
8#include "needupdateversion/needupdatecheckexistingnewversionjob.h"
9#include "needupdateversion/needupdateversionutils.h"
10#include "pimcommon_debug.h"
11#include <KLocalizedString>
12#include <QDesktopServices>
13#include <QLabel>
14#include <QVBoxLayout>
15
16using namespace PimCommon;
17CheckNewVersionWidget::CheckNewVersionWidget(QWidget *parent)
18 : QWidget{parent}
19 , mCheckVersionResultLabel(new QLabel(this))
20{
21 auto mainLayout = new QVBoxLayout(this);
22 mainLayout->setObjectName(QStringLiteral("mainLayout"));
23 mainLayout->setContentsMargins({});
24
25 mCheckVersionResultLabel->setObjectName(QStringLiteral("mCheckVersionResultLabel"));
26 mCheckVersionResultLabel->setWordWrap(true);
27 mCheckVersionResultLabel->setOpenExternalLinks(true);
28 mainLayout->addWidget(mCheckVersionResultLabel);
29}
30
31CheckNewVersionWidget::~CheckNewVersionWidget() = default;
32
33void CheckNewVersionWidget::checkNewVersion()
34{
35 auto job = new NeedUpdateCheckExistingNewVersionJob(this);
36 job->setUrl(mUrl);
37 job->setCompileDate(NeedUpdateVersionUtils::compileDate());
38 connect(job, &NeedUpdateCheckExistingNewVersionJob::foundNewVersion, this, &CheckNewVersionWidget::slotFoundNewVersion);
39 job->start();
40}
41
42void CheckNewVersionWidget::setUrl(const QUrl &url)
43{
44 mUrl = url;
45}
46
47void CheckNewVersionWidget::slotFoundNewVersion(bool found)
48{
49 if (found) {
50 mCheckVersionResultLabel->setTextFormat(Qt::RichText);
51 mCheckVersionResultLabel->setText(i18n("A new version found. Click <a href=\"%1\">here</a> for downloading it.", mUrl.toString()));
52 connect(mCheckVersionResultLabel, &QLabel::linkActivated, this, [](const QString &url) {
53 if (!QDesktopServices::openUrl(QUrl(url))) {
54 qCWarning(PIMCOMMON_LOG) << "Impossible to open url: " << url;
55 }
56 });
57 } else {
58 mCheckVersionResultLabel->setText(i18n("No new version found."));
59 }
60}
61
62#include "moc_checknewversionwidget.cpp"
QString i18n(const char *text, const TYPE &arg...)
folderdialogacltab.h
bool openUrl(const QUrl &url)
void linkActivated(const QString &link)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
RichText
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Jan 24 2025 11:47:24 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.