Messagelib

downloadlocaldatabasethread.cpp
1/*
2 SPDX-FileCopyrightText: 2016-2024 Laurent Montel <montel@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "downloadlocaldatabasethread.h"
8#include "createdatabasefilejob.h"
9#include "webengineviewer_debug.h"
10using namespace WebEngineViewer;
11
12DownloadLocalDatabaseThread::DownloadLocalDatabaseThread(QObject *parent)
13 : QThread(parent)
14{
15 qCDebug(WEBENGINEVIEWER_LOG) << "DownloadLocalDatabaseThread::DownloadLocalDatabaseThread " << this;
16}
17
18DownloadLocalDatabaseThread::~DownloadLocalDatabaseThread()
19{
20 qCDebug(WEBENGINEVIEWER_LOG) << "DownloadLocalDatabaseThread::~DownloadLocalDatabaseThread " << this;
21}
22
23void DownloadLocalDatabaseThread::setDataBaseState(const QString &value)
24{
25 mCurrentDataBaseState = value;
26}
27
28void DownloadLocalDatabaseThread::run()
29{
30 if (mDatabaseFullPath.isEmpty()) {
31 qCWarning(WEBENGINEVIEWER_LOG) << "Database full path is empty";
32 Q_EMIT createDataBaseFailed();
34 return;
35 }
37 job->moveToThread(this);
38 job->setDataBaseDownloadNeeded(mCurrentDataBaseState.isEmpty() ? WebEngineViewer::CreatePhishingUrlDataBaseJob::FullDataBase
39 : WebEngineViewer::CreatePhishingUrlDataBaseJob::UpdateDataBase);
40 job->setDataBaseState(mCurrentDataBaseState);
41 connect(job, &CreatePhishingUrlDataBaseJob::finished, this, &DownloadLocalDatabaseThread::slotDownloadDataBaseFinished);
42 job->start();
43 exec();
44}
45
46void DownloadLocalDatabaseThread::slotDownloadDataBaseFinished(const WebEngineViewer::UpdateDataBaseInfo &infoDataBase,
47 WebEngineViewer::CreatePhishingUrlDataBaseJob::DataBaseDownloadResult status)
48{
49 bool dataBaseOk = false;
50 switch (status) {
51 case CreatePhishingUrlDataBaseJob::InvalidData:
52 qCWarning(WEBENGINEVIEWER_LOG) << "Invalid Data.";
53 dataBaseOk = false;
54 break;
55 case CreatePhishingUrlDataBaseJob::ValidData:
56 qCDebug(WEBENGINEVIEWER_LOG) << "Valid Data.";
57 dataBaseOk = true;
58 break;
59 case CreatePhishingUrlDataBaseJob::UnknownError:
60 qCWarning(WEBENGINEVIEWER_LOG) << "Unknown data.";
61 dataBaseOk = false;
62 break;
63 case CreatePhishingUrlDataBaseJob::BrokenNetwork:
64 qCWarning(WEBENGINEVIEWER_LOG) << "Broken Networks.";
65 dataBaseOk = false;
66 break;
67 }
68 if (dataBaseOk) {
69 if (mCurrentDataBaseState == infoDataBase.newClientState) {
70 qCDebug(WEBENGINEVIEWER_LOG) << "No update necessary ";
71 } else {
72 switch (infoDataBase.responseType) {
73 case WebEngineViewer::UpdateDataBaseInfo::FullUpdate:
74 case WebEngineViewer::UpdateDataBaseInfo::PartialUpdate:
75 installNewDataBase(infoDataBase);
76 break;
77 case WebEngineViewer::UpdateDataBaseInfo::Unknown:
78 break;
79 }
80 }
81 } else {
82 Q_EMIT createDataBaseFailed();
83 quit();
84 }
85}
86
87void DownloadLocalDatabaseThread::setDatabaseFullPath(const QString &databaseFullPath)
88{
89 mDatabaseFullPath = databaseFullPath;
90}
91
92void DownloadLocalDatabaseThread::installNewDataBase(const WebEngineViewer::UpdateDataBaseInfo &infoDataBase)
93{
95 job->setFileName(mDatabaseFullPath);
96 job->setUpdateDataBaseInfo(infoDataBase);
97 connect(job, &CreateDatabaseFileJob::finished, this, &DownloadLocalDatabaseThread::slotCreateDataBaseFileNameFinished);
98 job->start();
99}
100
101void DownloadLocalDatabaseThread::slotCreateDataBaseFileNameFinished(bool success, const QString &newClientState, const QString &minimumWaitDurationStr)
102{
103 Q_EMIT createDataBaseFinished(success, newClientState, minimumWaitDurationStr);
104 quit();
105}
106
107#include "moc_downloadlocaldatabasethread.cpp"
The CreateDatabaseFileJob class.
Q_SCRIPTABLE CaptureState status()
Q_EMITQ_EMIT
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
void deleteLater()
void moveToThread(QThread *targetThread)
bool isEmpty() const const
int exec()
void quit()
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 29 2024 11:50:55 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.