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. 61
      src/widget/form/settings/privacyform.cpp

15
src/historykeeper.cpp

@ -35,6 +35,12 @@ HistoryKeeper *HistoryKeeper::getInstance() @@ -35,6 +35,12 @@ HistoryKeeper *HistoryKeeper::getInstance()
{
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:");
GenericDdInterface *dbIntf;
@ -45,7 +51,7 @@ HistoryKeeper *HistoryKeeper::getInstance() @@ -45,7 +51,7 @@ HistoryKeeper *HistoryKeeper::getInstance()
if (encrypted)
{
path = getHistoryPath();
dbIntf = new EncryptedDb(path);
dbIntf = new EncryptedDb(path, initLst);
historyInstance = new HistoryKeeper(dbIntf);
return historyInstance;
@ -54,7 +60,7 @@ HistoryKeeper *HistoryKeeper::getInstance() @@ -54,7 +60,7 @@ HistoryKeeper *HistoryKeeper::getInstance()
}
}
dbIntf = new PlainDb(path);
dbIntf = new PlainDb(path, initLst);
historyInstance = new HistoryKeeper(dbIntf);
}
@ -102,11 +108,6 @@ HistoryKeeper::HistoryKeeper(GenericDdInterface *db_) : @@ -102,11 +108,6 @@ HistoryKeeper::HistoryKeeper(GenericDdInterface *db_) :
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();
updateAliases();
}

7
src/misc/db/encrypteddb.cpp

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

2
src/misc/db/encrypteddb.h

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

11
src/misc/db/plaindb.cpp

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

4
src/misc/db/plaindb.h

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

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

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