summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMontel Laurent <montel@kde.org>2016-11-18 06:38:40 (GMT)
committerMontel Laurent <montel@kde.org>2016-11-18 06:38:40 (GMT)
commitefd80c513b30dc2fb7bd3d92b8fb5130ede5b4b7 (patch)
treedd9fa9bd0c3a5b59276cfa2a312e6a58b0ec24b9
parent9919a40f3217f42f9155231d9c21a30e6ca083fd (diff)
Add timer to update database
-rw-r--r--webengineviewer/src/checkphishingurl/localdatabasemanager.cpp22
-rw-r--r--webengineviewer/src/checkphishingurl/localdatabasemanager.h4
2 files changed, 26 insertions, 0 deletions
diff --git a/webengineviewer/src/checkphishingurl/localdatabasemanager.cpp b/webengineviewer/src/checkphishingurl/localdatabasemanager.cpp
index 2adb91b..9a8f448 100644
--- a/webengineviewer/src/checkphishingurl/localdatabasemanager.cpp
+++ b/webengineviewer/src/checkphishingurl/localdatabasemanager.cpp
@@ -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()
diff --git a/webengineviewer/src/checkphishingurl/localdatabasemanager.h b/webengineviewer/src/checkphishingurl/localdatabasemanager.h
index b8b3abc..03192f2 100644
--- a/webengineviewer/src/checkphishingurl/localdatabasemanager.h
+++ b/webengineviewer/src/checkphishingurl/localdatabasemanager.h
@@ -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;
};