summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMontel Laurent <montel@kde.org>2016-11-17 07:58:19 (GMT)
committerMontel Laurent <montel@kde.org>2016-11-17 07:58:19 (GMT)
commite358ef84a032813a61642c8ba28921a1eaa84cfe (patch)
treefaa814167040e99839748355fd9211db6ac05c3e
parent336e8ca490ef5c6d50a65806b675264b48250d45 (diff)
improve create database
-rw-r--r--webengineviewer/src/checkphishingurl/localdatabasemanager.cpp31
-rw-r--r--webengineviewer/src/checkphishingurl/localdatabasemanager.h5
2 files changed, 26 insertions, 10 deletions
diff --git a/webengineviewer/src/checkphishingurl/localdatabasemanager.cpp b/webengineviewer/src/checkphishingurl/localdatabasemanager.cpp
index 5cf98b0..58570ae 100644
--- a/webengineviewer/src/checkphishingurl/localdatabasemanager.cpp
+++ b/webengineviewer/src/checkphishingurl/localdatabasemanager.cpp
@@ -17,7 +17,9 @@
Boston, MA 02110-1301, USA.
*/
#include "localdatabasemanager.h"
+#include "webengineviewer_debug.h"
+#include <QStandardPaths>
#include <QSqlDatabase>
#include <QSqlError>
@@ -26,9 +28,11 @@ using namespace WebEngineViewer;
Q_GLOBAL_STATIC(LocalDataBaseManager, s_localDataBaseManager)
LocalDataBaseManager::LocalDataBaseManager(QObject *parent)
- : QObject(parent)
+ : QObject(parent),
+ mDataBaseOk(false)
{
- initializeDataBase();
+
+ mDataBaseOk = initializeDataBase();
}
LocalDataBaseManager::~LocalDataBaseManager()
@@ -47,24 +51,33 @@ LocalDataBaseManager *LocalDataBaseManager::self()
return s_localDataBaseManager;
}
-void LocalDataBaseManager::initializeDataBase()
+bool LocalDataBaseManager::initializeDataBase()
{
+ const QSqlError err = initDb();
+ if (err.type() != QSqlError::NoError) {
+ qCWarning(WEBENGINEVIEWER_LOG) << "Impossible to open DataBase: " << err.text();
+ return false;
+ }
+ return true;
}
QSqlError LocalDataBaseManager::initDb()
{
- QSqlDatabase db = QSqlDatabase::addDatabase(QStringLiteral("QSQLITE"));
- db.setDatabaseName(QStringLiteral(":phishingurl:"));
-
- if (!db.open()) {
- return db.lastError();
+ mDataBase = QSqlDatabase::addDatabase(QStringLiteral("QSQLITE"));
+ mDataBase.setDatabaseName(localDataBasePath());
+ if (!mDataBase.open()) {
+ return mDataBase.lastError();
}
- //TODO
return QSqlError();
}
void LocalDataBaseManager::checkUrl(const QUrl &url)
{
+ if (mDataBaseOk) {
+
+ } else {
+
+ }
//TODO
}
diff --git a/webengineviewer/src/checkphishingurl/localdatabasemanager.h b/webengineviewer/src/checkphishingurl/localdatabasemanager.h
index 626757e..36fedaa 100644
--- a/webengineviewer/src/checkphishingurl/localdatabasemanager.h
+++ b/webengineviewer/src/checkphishingurl/localdatabasemanager.h
@@ -21,6 +21,7 @@
#define LOCALDATABASEMANAGER_H
#include <QObject>
+#include <QSqlDatabase>
#include <QUrl>
class QSqlError;
namespace WebEngineViewer
@@ -37,8 +38,10 @@ public:
void checkUrl(const QUrl &url);
private:
QSqlError initDb();
- void initializeDataBase();
+ bool initializeDataBase();
QString localDataBasePath() const;
+ QSqlDatabase mDataBase;
+ bool mDataBaseOk;
};
}