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 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
|
/*
SPDX-FileCopyrightText: 2025-2026 Laurent Montel <montel@kde.org>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "needupdatecheckexistingnewversionjob.h"
#include "needupdateparsehtmljob.h"
#include "needupdateparsehtmlutil.h"
#include "textaddonswidgets_debug.h"
using namespace TextAddonsWidgets;
NeedUpdateCheckExistingNewVersionJob::NeedUpdateCheckExistingNewVersionJob(QObject *parent)
: QObject{parent}
{
}
NeedUpdateCheckExistingNewVersionJob::~NeedUpdateCheckExistingNewVersionJob() = default;
void NeedUpdateCheckExistingNewVersionJob::start()
{
if (!canStart()) {
qCWarning(TEXTADDONSWIDGETS_LOG) << "Impossible to start NeedUpdateCheckExistingNewVersionJob";
Q_EMIT foundNewVersion(false);
deleteLater();
return;
}
auto job = new NeedUpdateParseHtmlJob(this);
job->setUrl(mUrl);
connect(job, &NeedUpdateParseHtmlJob::downLoadDone, this, &NeedUpdateCheckExistingNewVersionJob::slotDownloadDone);
job->start();
}
void NeedUpdateCheckExistingNewVersionJob::slotDownloadDone(const QString &str)
{
const QString compileDateStr = NeedUpdateParseHtmlUtil::extractDate(str);
if (compileDateStr.isEmpty()) {
Q_EMIT foundNewVersion(false);
deleteLater();
return;
}
qCDebug(TEXTADDONSWIDGETS_LOG) << " currentCompiledDate " << mCompileDate;
const QDate dateFromUrl = QDate::fromString(compileDateStr, QStringLiteral("yyyy-MM-dd"));
qCDebug(TEXTADDONSWIDGETS_LOG) << " dateFromUrl " << dateFromUrl << " original " << compileDateStr;
if (dateFromUrl > mCompileDate) {
Q_EMIT foundNewVersion(true);
} else {
Q_EMIT foundNewVersion(false);
}
deleteLater();
}
QUrl NeedUpdateCheckExistingNewVersionJob::url() const
{
return mUrl;
}
void NeedUpdateCheckExistingNewVersionJob::setUrl(const QUrl &newUrl)
{
mUrl = newUrl;
}
bool NeedUpdateCheckExistingNewVersionJob::canStart() const
{
return !mUrl.isEmpty() && mCompileDate.isValid();
}
QDate NeedUpdateCheckExistingNewVersionJob::compileDate() const
{
return mCompileDate;
}
void NeedUpdateCheckExistingNewVersionJob::setCompileDate(const QDate &newCompileDate)
{
mCompileDate = newCompileDate;
}
#include "moc_needupdatecheckexistingnewversionjob.cpp"
|