Browse Source

various fixes

pull/423/head
apprb 11 years ago
parent
commit
eaa315eddb
No known key found for this signature in database
GPG Key ID: B001911B5B22FB9B
  1. 15
      src/historykeeper.cpp
  2. 7
      src/misc/db/encrypteddb.cpp
  3. 2
      src/misc/db/encrypteddb.h
  4. 11
      src/misc/db/plaindb.cpp
  5. 4
      src/misc/db/plaindb.h
  6. 59
      src/widget/form/settings/privacyform.cpp

15
src/historykeeper.cpp

@ -35,6 +35,12 @@ HistoryKeeper *HistoryKeeper::getInstance()
{ {
if (historyInstance == nullptr) if (historyInstance == nullptr)
{ {
QList<QString> initLst;
initLst.push_back(QString("CREATE TABLE IF NOT EXISTS history (id INTEGER PRIMARY KEY AUTOINCREMENT, timestamp INTEGER NOT NULL, ") +
QString("profile_id INTEGER NOT NULL, chat_id INTEGER NOT NULL, sender INTERGER NOT NULL, message TEXT NOT NULL);"));
initLst.push_back(QString("CREATE TABLE IF NOT EXISTS aliases (id INTEGER PRIMARY KEY AUTOINCREMENT, user_id TEXT UNIQUE NOT NULL);"));
initLst.push_back(QString("CREATE TABLE IF NOT EXISTS chats (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT UNIQUE NOT NULL, ctype INTEGER NOT NULL);"));
QString path(":memory:"); QString path(":memory:");
GenericDdInterface *dbIntf; GenericDdInterface *dbIntf;
@ -45,7 +51,7 @@ HistoryKeeper *HistoryKeeper::getInstance()
if (encrypted) if (encrypted)
{ {
path = getHistoryPath(); path = getHistoryPath();
dbIntf = new EncryptedDb(path); dbIntf = new EncryptedDb(path, initLst);
historyInstance = new HistoryKeeper(dbIntf); historyInstance = new HistoryKeeper(dbIntf);
return historyInstance; return historyInstance;
@ -54,7 +60,7 @@ HistoryKeeper *HistoryKeeper::getInstance()
} }
} }
dbIntf = new PlainDb(path); dbIntf = new PlainDb(path, initLst);
historyInstance = new HistoryKeeper(dbIntf); historyInstance = new HistoryKeeper(dbIntf);
} }
@ -102,11 +108,6 @@ HistoryKeeper::HistoryKeeper(GenericDdInterface *db_) :
message message
*/ */
db->exec(QString("CREATE TABLE IF NOT EXISTS history (id INTEGER PRIMARY KEY AUTOINCREMENT, timestamp INTEGER NOT NULL, ") +
QString("profile_id INTEGER NOT NULL, chat_id INTEGER NOT NULL, sender INTERGER NOT NULL, message TEXT NOT NULL);"));
db->exec(QString("CREATE TABLE IF NOT EXISTS aliases (id INTEGER PRIMARY KEY AUTOINCREMENT, user_id TEXT UNIQUE NOT NULL);"));
db->exec(QString("CREATE TABLE IF NOT EXISTS chats (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT UNIQUE NOT NULL, ctype INTEGER NOT NULL);"));
updateChatsID(); updateChatsID();
updateAliases(); updateAliases();
} }

7
src/misc/db/encrypteddb.cpp

@ -27,8 +27,8 @@
qint64 EncryptedDb::plainChunkSize = 1024; qint64 EncryptedDb::plainChunkSize = 1024;
qint64 EncryptedDb::encryptedChunkSize = EncryptedDb::plainChunkSize + tox_pass_encryption_extra_length(); qint64 EncryptedDb::encryptedChunkSize = EncryptedDb::plainChunkSize + tox_pass_encryption_extra_length();
EncryptedDb::EncryptedDb(const QString &fname) : EncryptedDb::EncryptedDb(const QString &fname, QList<QString> initList) :
PlainDb(":memory:"), encrFile(fname) PlainDb(":memory:", initList), encrFile(fname)
{ {
QByteArray fileContent; QByteArray fileContent;
if (pullFileContent()) if (pullFileContent())
@ -45,6 +45,7 @@ EncryptedDb::EncryptedDb(const QString &fname) :
encrFile.close(); encrFile.close();
encrFile.open(QIODevice::WriteOnly); encrFile.open(QIODevice::WriteOnly);
encrFile.write(fileContent); encrFile.write(fileContent);
encrFile.flush();
} }
EncryptedDb::~EncryptedDb() EncryptedDb::~EncryptedDb()
@ -55,7 +56,7 @@ EncryptedDb::~EncryptedDb()
QSqlQuery EncryptedDb::exec(const QString &query) QSqlQuery EncryptedDb::exec(const QString &query)
{ {
QSqlQuery retQSqlQuery = PlainDb::exec(query); QSqlQuery retQSqlQuery = PlainDb::exec(query);
if (query.startsWith("INSERT", Qt::CaseInsensitive) || query.startsWith("CREATE", Qt::CaseInsensitive)) if (query.startsWith("INSERT", Qt::CaseInsensitive))
appendToEncrypted(query); appendToEncrypted(query);
return retQSqlQuery; return retQSqlQuery;

2
src/misc/db/encrypteddb.h

@ -25,7 +25,7 @@
class EncryptedDb : public PlainDb class EncryptedDb : public PlainDb
{ {
public: public:
EncryptedDb(const QString& fname); EncryptedDb(const QString& fname, QList<QString> initList);
virtual ~EncryptedDb(); virtual ~EncryptedDb();
virtual QSqlQuery exec(const QString &query); virtual QSqlQuery exec(const QString &query);

11
src/misc/db/plaindb.cpp

@ -19,9 +19,7 @@
#include <QSqlQuery> #include <QSqlQuery>
#include <QString> #include <QString>
QList<QString> PlainDb::initCmd; PlainDb::PlainDb(const QString &db_name, QList<QString> initList)
PlainDb::PlainDb(const QString &db_name)
{ {
db = new QSqlDatabase(); db = new QSqlDatabase();
*db = QSqlDatabase::addDatabase("QSQLITE"); *db = QSqlDatabase::addDatabase("QSQLITE");
@ -34,7 +32,7 @@ PlainDb::PlainDb(const QString &db_name)
db->open(); db->open();
} }
for (const QString &cmd : initCmd) for (const QString &cmd : initList)
db->exec(cmd); db->exec(cmd);
} }
@ -51,8 +49,3 @@ QSqlQuery PlainDb::exec(const QString &query)
{ {
return db->exec(query); return db->exec(query);
} }
void PlainDb::setBDInitCommands(const QList<QString> &list)
{
initCmd = list;
}

4
src/misc/db/plaindb.h

@ -24,15 +24,13 @@
class PlainDb : public GenericDdInterface class PlainDb : public GenericDdInterface
{ {
public: public:
PlainDb(const QString &db_name); PlainDb(const QString &db_name, QList<QString> initList);
virtual ~PlainDb(); virtual ~PlainDb();
virtual QSqlQuery exec(const QString &query); virtual QSqlQuery exec(const QString &query);
static void setBDInitCommands(const QList<QString> &list);
private: private:
QSqlDatabase *db; QSqlDatabase *db;
static QList<QString> initCmd;
}; };
#endif // PLAINDB_H #endif // PLAINDB_H

59
src/widget/form/settings/privacyform.cpp

@ -35,8 +35,8 @@ PrivacyForm::PrivacyForm() :
connect(bodyUI->cbTypingNotification, SIGNAL(stateChanged(int)), this, SLOT(onTypingNotificationEnabledUpdated())); connect(bodyUI->cbTypingNotification, SIGNAL(stateChanged(int)), this, SLOT(onTypingNotificationEnabledUpdated()));
connect(bodyUI->cbKeepHistory, SIGNAL(stateChanged(int)), this, SLOT(onEnableLoggingUpdated())); connect(bodyUI->cbKeepHistory, SIGNAL(stateChanged(int)), this, SLOT(onEnableLoggingUpdated()));
connect(bodyUI->cbEncryptHistory, SIGNAL(stateChanged(int)), this, SLOT(onEncryptLogsUpdated())); connect(bodyUI->cbEncryptHistory, SIGNAL(clicked()), this, SLOT(onEncryptLogsUpdated()));
connect(bodyUI->cbEncryptTox, SIGNAL(stateChanged(int)), this, SLOT(onEncryptToxUpdated())); connect(bodyUI->cbEncryptTox, SIGNAL(clicked()), this, SLOT(onEncryptToxUpdated()));
} }
PrivacyForm::~PrivacyForm() PrivacyForm::~PrivacyForm()
@ -58,9 +58,9 @@ void PrivacyForm::onTypingNotificationEnabledUpdated()
void PrivacyForm::onEncryptLogsUpdated() void PrivacyForm::onEncryptLogsUpdated()
{ {
bool encpytionState = bodyUI->cbEncryptHistory->isChecked(); bool encrytionState = bodyUI->cbEncryptHistory->isChecked();
if (encpytionState) if (encrytionState)
{ {
if (!Core::getInstance()->isPasswordSet()) if (!Core::getInstance()->isPasswordSet())
{ {
@ -68,25 +68,50 @@ void PrivacyForm::onEncryptLogsUpdated()
if (dialog.exec()) if (dialog.exec())
{ {
QString pswd = dialog.getPassword(); QString pswd = dialog.getPassword();
if (pswd.size() > 0) if (pswd.size() == 0)
{ encrytionState = false;
Core::getInstance()->setPassword(pswd);
Settings::getInstance().setEncryptLogs(true);
return;
}
}
bodyUI->cbEncryptHistory->setChecked(false); Core::getInstance()->setPassword(pswd);
Settings::getInstance().setEncryptLogs(false);
} else { } else {
Settings::getInstance().setEncryptLogs(true); encrytionState = false;
Core::getInstance()->clearPassword();
}
} }
} else {
Settings::getInstance().setEncryptLogs(false);
} }
bodyUI->cbEncryptHistory->setChecked(encrytionState);
Settings::getInstance().setEncryptLogs(encrytionState);
if (!Settings::getInstance().getEncryptLogs() && !Settings::getInstance().getEncryptTox())
Core::getInstance()->clearPassword();
} }
void PrivacyForm::onEncryptToxUpdated() void PrivacyForm::onEncryptToxUpdated()
{ {
// bool encrytionState = bodyUI->cbEncryptTox->isChecked();
if (encrytionState)
{
if (!Core::getInstance()->isPasswordSet())
{
SetPasswordDialog dialog;
if (dialog.exec())
{
QString pswd = dialog.getPassword();
if (pswd.size() == 0)
encrytionState = false;
Core::getInstance()->setPassword(pswd);
} else {
encrytionState = false;
Core::getInstance()->clearPassword();
}
}
}
// bodyUI->cbEncryptTox->setChecked(encrytionState);
// Settings::getInstance().setEncryptTox(encrytionState);
if (!Settings::getInstance().getEncryptLogs() && !Settings::getInstance().getEncryptTox())
Core::getInstance()->clearPassword();
} }

Loading…
Cancel
Save