Messagelib

downloadlocaldatabasethread.cpp
1 /*
2  SPDX-FileCopyrightText: 2016-2021 Laurent Montel <[email protected]>
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"
10 using namespace WebEngineViewer;
11 
12 DownloadLocalDatabaseThread::DownloadLocalDatabaseThread(QObject *parent)
13  : QThread(parent)
14 {
15  qCDebug(WEBENGINEVIEWER_LOG) << "DownloadLocalDatabaseThread::DownloadLocalDatabaseThread " << this;
16 }
17 
18 DownloadLocalDatabaseThread::~DownloadLocalDatabaseThread()
19 {
20  qCDebug(WEBENGINEVIEWER_LOG) << "DownloadLocalDatabaseThread::~DownloadLocalDatabaseThread " << this;
21 }
22 
23 void DownloadLocalDatabaseThread::setDataBaseState(const QString &value)
24 {
25  mCurrentDataBaseState = value;
26 }
27 
28 void DownloadLocalDatabaseThread::run()
29 {
30  if (mDatabaseFullPath.isEmpty()) {
31  qCWarning(WEBENGINEVIEWER_LOG) << "Database full path is empty";
32  Q_EMIT createDataBaseFailed();
33  deleteLater();
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 
46 void 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 
87 void DownloadLocalDatabaseThread::setDatabaseFullPath(const QString &databaseFullPath)
88 {
89  mDatabaseFullPath = databaseFullPath;
90 }
91 
92 void 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 
101 void DownloadLocalDatabaseThread::slotCreateDataBaseFileNameFinished(bool success, const QString &newClientState, const QString &minimumWaitDurationStr)
102 {
103  Q_EMIT createDataBaseFinished(success, newClientState, minimumWaitDurationStr);
104  quit();
105 }
void moveToThread(QThread *targetThread)
The CreatePhishingUrlDataBaseJob class.
The CreateDatabaseFileJob class.
const QList< QKeySequence > & quit()
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sun Nov 28 2021 23:05:43 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.