summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMontel Laurent <montel@kde.org>2016-11-18 07:02:46 (GMT)
committerMontel Laurent <montel@kde.org>2016-11-18 07:02:46 (GMT)
commit6e144aec8af7eb7cb18f977bc8e6c6406f98a425 (patch)
treedbd712eb3c9c8aa6874638b09d6bcfc7bb175100
parentefd80c513b30dc2fb7bd3d92b8fb5130ede5b4b7 (diff)
Check if we must update database
-rw-r--r--webengineviewer/src/checkphishingurl/localdatabasemanager.cpp41
-rw-r--r--webengineviewer/src/checkphishingurl/localdatabasemanager.h3
2 files changed, 31 insertions, 13 deletions
diff --git a/webengineviewer/src/checkphishingurl/localdatabasemanager.cpp b/webengineviewer/src/checkphishingurl/localdatabasemanager.cpp
index 9a8f448..10b09d6 100644
--- a/webengineviewer/src/checkphishingurl/localdatabasemanager.cpp
+++ b/webengineviewer/src/checkphishingurl/localdatabasemanager.cpp
@@ -54,6 +54,7 @@ LocalDataBaseManager::LocalDataBaseManager(QObject *parent)
mDataBaseOk(false),
mDownloadProgress(false)
{
+ readConfig();
}
LocalDataBaseManager::~LocalDataBaseManager()
@@ -76,27 +77,30 @@ void LocalDataBaseManager::closeDataBaseAndDeleteIt()
void LocalDataBaseManager::readConfig()
{
- //TODO
+ KConfig phishingurlKConfig(QStringLiteral("phishingurlrc"));
+ KConfigGroup grp = phishingurlKConfig.group(QStringLiteral("General"));
+ mNewClientState = grp.readEntry(QStringLiteral("DataBaseState"));
}
void LocalDataBaseManager::saveConfig()
{
+ KConfig phishingurlKConfig(QStringLiteral("phishingurlrc"));
//TODO
}
void LocalDataBaseManager::downloadPartialDataBase()
{
- mDownloadProgress = true;
+ setDownloadProgress(true);
WebEngineViewer::CreatePhishingUrlDataBaseJob *job = new WebEngineViewer::CreatePhishingUrlDataBaseJob(this);
job->setDataBaseDownloadNeeded(WebEngineViewer::CreatePhishingUrlDataBaseJob::UpdateDataBase);
- job->setDataBaseState(QString()); //TODO
+ job->setDataBaseState(mNewClientState);
connect(job, &CreatePhishingUrlDataBaseJob::finished, this, &LocalDataBaseManager::slotDownloadDataBaseFinished);
job->start();
}
void LocalDataBaseManager::downloadFullDataBase()
{
- mDownloadProgress = true;
+ setDownloadProgress(true);
WebEngineViewer::CreatePhishingUrlDataBaseJob *job = new WebEngineViewer::CreatePhishingUrlDataBaseJob(this);
job->setDataBaseDownloadNeeded(WebEngineViewer::CreatePhishingUrlDataBaseJob::FullDataBase);
connect(job, &CreatePhishingUrlDataBaseJob::finished, this, &LocalDataBaseManager::slotDownloadDataBaseFinished);
@@ -166,15 +170,21 @@ void LocalDataBaseManager::slotDownloadDataBaseFinished(const WebEngineViewer::U
break;
}
if (mDataBaseOk) {
- //qDebug() << "infoDataBase" << infoDataBase.additionList.count();
- Q_FOREACH(const Addition &add, infoDataBase.additionList) {
- //qDebug() << " add.size" << add.prefixSize;
- //qDebug() << " add.hash" << QByteArray::fromBase64(add.hashString).size();
- const QByteArray uncompressed = QByteArray::fromBase64(add.hashString);
- for (int i = 0; i < uncompressed.size();) {
- QByteArray m = uncompressed.mid(i, add.prefixSize);
- i += add.prefixSize;
- //qDebug() << "m " << m << " m.size" << m.size();
+ if ((infoDataBase.responseType == QLatin1String("PARTIAL_UPDATE")) &&
+ (mNewClientState == infoDataBase.newClientState)) {
+ qDebug() << "No update necessary ";
+ } else {
+ //Clear database ?
+ //qDebug() << "infoDataBase" << infoDataBase.additionList.count();
+ Q_FOREACH(const Addition &add, infoDataBase.additionList) {
+ //qDebug() << " add.size" << add.prefixSize;
+ //qDebug() << " add.hash" << QByteArray::fromBase64(add.hashString).size();
+ const QByteArray uncompressed = QByteArray::fromBase64(add.hashString);
+ for (int i = 0; i < uncompressed.size();) {
+ QByteArray m = uncompressed.mid(i, add.prefixSize);
+ i += add.prefixSize;
+ //qDebug() << "m " << m << " m.size" << m.size();
+ }
}
}
}
@@ -209,6 +219,11 @@ bool LocalDataBaseManager::createTable()
"hash varchar(32))").arg(tableName()));
}
+void LocalDataBaseManager::setDownloadProgress(bool downloadProgress)
+{
+ mDownloadProgress = downloadProgress;
+}
+
void LocalDataBaseManager::checkUrl(const QUrl &url)
{
if (mDataBaseOk) {
diff --git a/webengineviewer/src/checkphishingurl/localdatabasemanager.h b/webengineviewer/src/checkphishingurl/localdatabasemanager.h
index 03192f2..07cf6ba 100644
--- a/webengineviewer/src/checkphishingurl/localdatabasemanager.h
+++ b/webengineviewer/src/checkphishingurl/localdatabasemanager.h
@@ -49,10 +49,12 @@ public:
void closeDataBaseAndDeleteIt();
+
Q_SIGNALS:
void checkUrlFinished(const QUrl &url, WebEngineViewer::LocalDataBaseManager::UrlStatus status);
protected:
+ void setDownloadProgress(bool downloadProgress);
virtual void downloadFullDataBase();
virtual void downloadPartialDataBase();
@@ -66,6 +68,7 @@ private:
bool initializeDataBase();
bool createTable();
QSqlDatabase mDataBase;
+ QString mNewClientState;
QTimer *mRegularCheckDataBaseTimer;
bool mDataBaseOk;
bool mDownloadProgress;