Commit efd80c51 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Add timer to update database

parent 9919a40f
......@@ -30,6 +30,7 @@
#include <QSqlQuery>
#include <QDebug>
#include <QDir>
#include <QTimer>
using namespace WebEngineViewer;
......@@ -49,6 +50,7 @@ inline QString sqlFileName() {
LocalDataBaseManager::LocalDataBaseManager(QObject *parent)
: QObject(parent),
mRegularCheckDataBaseTimer(Q_NULLPTR),
mDataBaseOk(false),
mDownloadProgress(false)
{
......@@ -122,6 +124,22 @@ void LocalDataBaseManager::initialize()
} else {
qCWarning(WEBENGINEVIEWER_LOG) << "Database already initialized.";
}
if (mDataBaseOk) {
if (!mRegularCheckDataBaseTimer) {
mRegularCheckDataBaseTimer = new QTimer(this);
mRegularCheckDataBaseTimer->setSingleShot(true);
mRegularCheckDataBaseTimer->setInterval(60*1000*60*5); //Each 5 hours //Perhaps improve it.
connect(mRegularCheckDataBaseTimer, &QTimer::timeout, this, &LocalDataBaseManager::slotCheckDataBase);
mRegularCheckDataBaseTimer->start();
}
}
}
void LocalDataBaseManager::slotCheckDataBase()
{
if (mDataBaseOk && !mDownloadProgress) {
downloadPartialDataBase();
}
}
void LocalDataBaseManager::slotDownloadDataBaseFinished(const WebEngineViewer::UpdateDataBaseInfo &infoDataBase,
......@@ -161,6 +179,10 @@ void LocalDataBaseManager::slotDownloadDataBaseFinished(const WebEngineViewer::U
}
}
mDownloadProgress = false;
//We finish to download restart timer if necessary
if (mRegularCheckDataBaseTimer && !mRegularCheckDataBaseTimer->isActive()) {
mRegularCheckDataBaseTimer->start();
}
}
LocalDataBaseManager *LocalDataBaseManager::self()
......
......@@ -25,6 +25,7 @@
#include <QSqlDatabase>
#include <QUrl>
#include "createphishingurldatabasejob.h"
class QTimer;
namespace WebEngineViewer
{
class WEBENGINEVIEWER_EXPORT LocalDataBaseManager : public QObject
......@@ -60,9 +61,12 @@ private:
void saveConfig();
void slotDownloadDataBaseFinished(const WebEngineViewer::UpdateDataBaseInfo &infoDataBase, WebEngineViewer::CreatePhishingUrlDataBaseJob::DataBaseDownloadResult status);
void slotCheckDataBase();
bool initializeDataBase();
bool createTable();
QSqlDatabase mDataBase;
QTimer *mRegularCheckDataBaseTimer;
bool mDataBaseOk;
bool mDownloadProgress;
};
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment