UI: StatManager: Remove m_filePath.

This commit is contained in:
Nodir Temirkhodjaev 2019-10-20 15:32:38 +05:00
parent 63b2fc2573
commit 71c5790124
4 changed files with 20 additions and 18 deletions

View File

@ -9,8 +9,9 @@
#include <sqlite3.h>
SqliteDb::SqliteDb() :
m_db(nullptr)
SqliteDb::SqliteDb(const QString &filePath) :
m_db(nullptr),
m_filePath(filePath)
{
sqlite3_initialize();
}
@ -24,8 +25,11 @@ SqliteDb::~SqliteDb()
bool SqliteDb::open(const QString &filePath)
{
m_filePath = filePath;
return sqlite3_open16(filePath.utf16(), &m_db) == SQLITE_OK;
if (!filePath.isEmpty()) {
m_filePath = filePath;
}
return sqlite3_open16(m_filePath.utf16(), &m_db) == SQLITE_OK;
}
void SqliteDb::close()

View File

@ -14,17 +14,19 @@ using SQLITEDB_MIGRATE_FUNC = bool (*)(SqliteDb *db, int version, void *context)
class SqliteDb
{
public:
explicit SqliteDb();
explicit SqliteDb(const QString &filePath = QString());
~SqliteDb();
CLASS_DEFAULT_COPY_MOVE(SqliteDb)
bool open(const QString &filePath);
struct sqlite3 *db() const { return m_db; }
QString filePath() const { return m_filePath; }
bool open(const QString &filePath = QString());
void close();
bool recreateDb();
struct sqlite3 *db() const { return m_db; }
bool execute(const char *sql);
bool execute16(const ushort *sql);
bool executeStr(const QString &sql);

View File

@ -67,10 +67,9 @@ StatManager::StatManager(const QString &filePath,
m_lastTrafDay(0),
m_lastTrafMonth(0),
m_lastTick(0),
m_filePath(filePath),
m_quotaManager(quotaManager),
m_conf(nullptr),
m_sqliteDb(new SqliteDb())
m_sqliteDb(new SqliteDb(filePath))
{
}
@ -97,9 +96,9 @@ bool StatManager::initialize()
{
m_lastTrafHour = m_lastTrafDay = m_lastTrafMonth = 0;
if (!m_sqliteDb->open(m_filePath)) {
if (!m_sqliteDb->open()) {
qCritical(CLOG_STAT_MANAGER()) << "File open error:"
<< m_filePath
<< m_sqliteDb->filePath()
<< m_sqliteDb->errorMessage();
return false;
}
@ -108,7 +107,8 @@ bool StatManager::initialize()
if (!m_sqliteDb->migrate(":/stat/migrations", DATABASE_USER_VERSION,
false, &migrateFunc)) {
qCritical(CLOG_STAT_MANAGER()) << "Migration error" << m_filePath;
qCritical(CLOG_STAT_MANAGER()) << "Migration error"
<< m_sqliteDb->filePath();
return false;
}
@ -155,7 +155,7 @@ void StatManager::clear()
m_sqliteDb->close();
FileUtil::removeFile(m_filePath);
FileUtil::removeFile(m_sqliteDb->filePath());
initialize();

View File

@ -27,8 +27,6 @@ public:
const FirewallConf *firewallConf() const { return m_conf; }
void setFirewallConf(const FirewallConf *conf);
SqliteDb *sqliteDb() const { return m_sqliteDb; }
bool initialize();
void logProcNew(quint32 pid, const QString &appPath);
@ -105,8 +103,6 @@ private:
qint32 m_lastTick;
QString m_filePath;
QuotaManager *m_quotaManager;
const FirewallConf *m_conf;