Commit d6da7f5b authored by Karel Slaný's avatar Karel Slaný

Classes AccountDb and ZfoDb are now derived from SQLiteDbSingle.

parent 7def327b
......@@ -87,6 +87,7 @@ SOURCES += \
src/auxiliaries/attachment_helper.cpp \
src/auxiliaries/email_helper.cpp \
src/datovka_shared/io/sqlite/db.cpp \
src/datovka_shared/io/sqlite/db_single.cpp \
src/datovka_shared/io/sqlite/table.cpp \
src/dialogues/dialogues.cpp \
src/dialogues/qml_dialogue_helper.cpp \
......@@ -148,6 +149,7 @@ HEADERS += \
src/auxiliaries/email_helper.h \
src/common.h \
src/datovka_shared/io/sqlite/db.h \
src/datovka_shared/io/sqlite/db_single.h \
src/datovka_shared/io/sqlite/table.h \
src/dialogues/dialogues.h \
src/dialogues/qml_dialogue_helper.h \
......
......@@ -37,6 +37,7 @@
#include "src/dialogues/dialogues.h"
#include "src/files.h"
#include "src/locker.h"
#include "src/log/log.h"
#include "src/net/isds_wrapper.h"
#include "src/models/accountmodel.h"
#include "src/models/databoxmodel.h"
......@@ -346,12 +347,11 @@ int main(int argc, char *argv[])
msgZfoTbl.reloadLocalisedDescription();
/* init and open account database */
AccountDb globAccountDb("ACCOUNTS");
AccountDb globAccountDb("ACCOUNTS", false);
globAccountDbPtr = &globAccountDb;
/* true = account db store in disk, false = to memory */
if (!globAccountDbPtr->openDb(ACNT_DB_NAME, true)) {
qDebug() << "ERROR: account db not found!";
if (!globAccountDbPtr->openDb(ACNT_DB_NAME, SQLiteDb::CREATE_MISSING)) {
logErrorNL("%s", "Account database not found!");
return EXIT_FAILURE;
}
......@@ -364,7 +364,7 @@ int main(int argc, char *argv[])
globFileDbsPtr = &globFileDb;
/* init zfo db database */
ZfoDb globZfoDb("ZFOS");
ZfoDb globZfoDb("ZFOS", false);
globZfoDbPtr = &globZfoDb;
/* Load accounts from settings to account model. */
......
......@@ -50,11 +50,6 @@ const QVector<QString> AccountDb::userPrintedAttribs = {"firmName", "ic",
"biDate", "caStreet", "caCity", "caZipCode", "caState",
"userType", "userPrivils", "_pwdExpirDate"};
AccountDb::AccountDb(const QString &connectionName)
: SQLiteDb(connectionName)
{
}
const QString AccountDb::dbId(const QString &userName,
const QString &defaultValue) const
{
......@@ -113,24 +108,6 @@ fail:
return false;
}
bool AccountDb::openDb(const QString &fileName, bool storeToDisk)
{
QString dirName(existingWritableLocation(
QStandardPaths::AppDataLocation));
if (storeToDisk && dirName.isEmpty()) {
Q_ASSERT(0);
return false;
}
SQLiteDb::OpenFlags flags = SQLiteDb::CREATE_MISSING;
flags |= storeToDisk ? SQLiteDb::NO_OPTIONS : SQLiteDb::FORCE_IN_MEMORY;
return SQLiteDb::openDb(
dirName + QDir::separator() + QDir::toNativeSeparators(fileName),
flags);
}
const QString AccountDb::senderNameGuess(const QString &userName,
const QString &defaultValue) const
{
......
......@@ -27,16 +27,17 @@
#include <QList>
#include <QString>
#include "src/datovka_shared/io/sqlite/db.h"
#include "src/datovka_shared/io/sqlite/db_single.h"
#include "src/net/db_wrapper.h"
/*!
* @brief Encapsulates account database.
*/
class AccountDb : public SQLiteDb {
class AccountDb : public SQLiteDbSingle {
public:
explicit AccountDb(const QString &connectionName);
/* Use parent class constructor. */
using SQLiteDbSingle::SQLiteDbSingle;
/*!
* @brief Return data box identifier.
......@@ -68,7 +69,7 @@ public:
* @brief Delete user info from db.
*
* @param[in] userName Account user name.
* @return List of user info. * @return True on success.
* @return True on success.
*/
bool deleteUserInfoFromDb(const QString &userName) const;
......@@ -104,15 +105,6 @@ public:
*/
bool insertUserInfoIntoDb(const DbWrapper::UserInfo &userData);
/*!
* @brief Open database file.
*
* @param[in] fileName File name.
* @param[in] storeToDisk True if db is store on the local storage.
* @return True on success.
*/
bool openDb(const QString &fileName, bool storeToDisk);
/*!
* @brief Return sender name guess.
*
......
......@@ -36,11 +36,6 @@
#include "src/sqlite/dbs.h"
#include "src/sqlite/zfo_db.h"
ZfoDb::ZfoDb(const QString &connectionName)
: SQLiteDb(connectionName)
{
}
bool ZfoDb::openDb(const QString &fileName, bool storeToDisk)
{
QString dirName(existingWritableLocation(
......
......@@ -27,7 +27,7 @@
#include <QList>
#include <QString>
#include "src/datovka_shared/io/sqlite/db.h"
#include "src/datovka_shared/io/sqlite/db_single.h"
/* Zfo db filename */
#define ZFO_DB_NAME "zfo.db"
......@@ -35,10 +35,11 @@
/*!
* @brief Encapsulates zfo database.
*/
class ZfoDb : public SQLiteDb {
class ZfoDb : public SQLiteDbSingle {
public:
explicit ZfoDb(const QString &connectionName);
/* Use parent class constructor. */
using SQLiteDbSingle::SQLiteDbSingle;
/*!
* @brief Delete zfo from database.
......
Markdown is supported
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