Pimcommon

needupdatecheckexistingnewversionjob.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 "needupdatecheckexistingnewversionjob.h"
8#include "needupdateparsehtmljob.h"
9#include "needupdateparsehtmlutil.h"
10#include "pimcommon_debug.h"
11#include <QDate>
12using namespace PimCommon;
13NeedUpdateCheckExistingNewVersionJob::NeedUpdateCheckExistingNewVersionJob(QObject *parent)
14 : QObject{parent}
15{
16}
17
18NeedUpdateCheckExistingNewVersionJob::~NeedUpdateCheckExistingNewVersionJob() = default;
19
20void NeedUpdateCheckExistingNewVersionJob::start()
21{
22 if (!canStart()) {
23 qCWarning(PIMCOMMON_LOG) << "Impossible to start NeedUpdateCheckExistingNewVersionJob";
24 Q_EMIT foundNewVersion(false);
26 return;
27 }
28 auto job = new NeedUpdateParseHtmlJob(this);
29 job->setUrl(mUrl);
30 connect(job, &NeedUpdateParseHtmlJob::downLoadDone, this, &NeedUpdateCheckExistingNewVersionJob::slotDownloadDone);
31 job->start();
32}
33
34void NeedUpdateCheckExistingNewVersionJob::slotDownloadDone(const QString &str)
35{
36 const QString compileDateStr = NeedUpdateParseHtmlUtil::extractDate(str);
37 if (compileDateStr.isEmpty()) {
38 Q_EMIT foundNewVersion(false);
40 return;
41 }
42
43 qCDebug(PIMCOMMON_LOG) << " currentCompiledDate " << mCompileDate;
44
45 const QDate dateFromUrl = QDate::fromString(compileDateStr, QStringLiteral("yyyy-MM-dd"));
46 qCDebug(PIMCOMMON_LOG) << " dateFromUrl " << dateFromUrl << " original " << compileDateStr;
47
48 if (dateFromUrl > mCompileDate) {
49 Q_EMIT foundNewVersion(true);
50 } else {
51 Q_EMIT foundNewVersion(false);
52 }
54}
55
56QUrl NeedUpdateCheckExistingNewVersionJob::url() const
57{
58 return mUrl;
59}
60
61void NeedUpdateCheckExistingNewVersionJob::setUrl(const QUrl &newUrl)
62{
63 mUrl = newUrl;
64}
65
66bool NeedUpdateCheckExistingNewVersionJob::canStart() const
67{
68 return !mUrl.isEmpty() && mCompileDate.isValid();
69}
70
71QDate NeedUpdateCheckExistingNewVersionJob::compileDate() const
72{
73 return mCompileDate;
74}
75
76void NeedUpdateCheckExistingNewVersionJob::setCompileDate(const QDate &newCompileDate)
77{
78 mCompileDate = newCompileDate;
79}
80
81#include "moc_needupdatecheckexistingnewversionjob.cpp"
folderdialogacltab.h
QDate fromString(QStringView string, QStringView format, QCalendar cal)
Q_EMITQ_EMIT
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
void deleteLater()
bool isEmpty() const const
bool isEmpty() const const
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.