1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

finishing touches

This commit is contained in:
Dubslow 2014-12-04 10:55:14 -06:00
parent bac485400e
commit dccb0a9951
No known key found for this signature in database
GPG Key ID: 3DB8E05315C220AA
3 changed files with 24 additions and 38 deletions

View File

@ -138,12 +138,6 @@ HistoryKeeper::~HistoryKeeper()
delete db;
}
void HistoryKeeper::reencrypt(QString newpw)
{
// TODO: this needs to appropriately set the core password as well
// if newpw.isEmpty(), then use the other core password
}
qint64 HistoryKeeper::addChatEntry(const QString& chat, const QString& message, const QString& sender, const QDateTime &dt, bool isSent)
{
QList<QString> cmds = generateAddChatEntryCmd(chat, message, sender, dt, isSent);
@ -406,10 +400,18 @@ bool HistoryKeeper::isFileExist()
bool HistoryKeeper::removeHistory(int encrypted)
{
Q_UNUSED(encrypted);
resetInstance();
QString path = getHistoryPath();
QString path = getHistoryPath(QString(), encrypted);
QFile DbFile(path);
return DbFile.remove();
}
QList<HistoryKeeper::HistMessage> HistoryKeeper::exportMessagesDeleteFile(int encrypted)
{
auto msgs = getInstance()->exportMessages();
qDebug() << "HistoryKeeper: count" << msgs.size() << "messages exported";
if (!removeHistory(encrypted))
qWarning() << "HistoryKeeper: couldn't delete old log file!";
return msgs;
}

View File

@ -52,12 +52,12 @@ public:
static bool isFileExist();
static void renameHistory(QString from, QString to);
static bool removeHistory(int encrypted = -1);
static QList<HistMessage> exportMessagesDeleteFile(int encrypted = -1);
qint64 addChatEntry(const QString& chat, const QString& message, const QString& sender, const QDateTime &dt, bool isSent);
qint64 addGroupChatEntry(const QString& chat, const QString& message, const QString& sender, const QDateTime &dt);
QList<HistMessage> getChatHistory(ChatType ct, const QString &chat, const QDateTime &time_from, const QDateTime &time_to);
void markAsSent(int m_id);
void reencrypt(QString newpw);
QList<HistMessage> exportMessages();
void importMessages(const QList<HistoryKeeper::HistMessage> &lst);

View File

@ -77,24 +77,23 @@ bool PrivacyForm::setChatLogsPassword()
if (int r = dialog->exec())
{
QList<HistoryKeeper::HistMessage> oldMessages = HistoryKeeper::exportMessagesDeleteFile();
QString newpw = dialog->getPassword();
delete dialog;
if (!HistoryKeeper::checkPassword(true))
if (checkContinue(tr("Old encrypted chat logs", "title"),
tr("Would you like to re-encrypt your old chat logs?\nOtherwise they will be deleted.", "body")))
{
HistoryKeeper::getInstance()->reencrypt(r == 2 ? QString() : newpw);
// will set core and reset itself
return true;
}
// @apprb you resetInstance() in the old code but wouldn't that wipe out the current unencrypted history?
// current history should of course just become encrypted
if (r == 2)
core->useOtherPassword(Core::ptHistory);
else
core->setPassword(newpw, Core::ptHistory);
// HistoryKeeper::encryptPlain();
//if (!HistoryKeeper::checkPassword(true))
// if (checkContinue(tr("Old encrypted chat logs", "title"),
// tr("Would you like to re-encrypt your old chat logs?\nOtherwise they will be deleted.", "body")))
// for now, don't bother asking. Why wouldn't you want to reencrypt?
HistoryKeeper::getInstance()->importMessages(oldMessages);
return true;
}
else
@ -106,19 +105,7 @@ bool PrivacyForm::setChatLogsPassword()
void PrivacyForm::onEncryptLogsUpdated()
{
auto getOldMessages = []()
{
auto msgs = HistoryKeeper::getInstance()->exportMessages();
qDebug() << "Loaded messages:" << msgs.size();
bool delRet = HistoryKeeper::removeHistory();
if (!delRet)
qWarning() << "HistoryKeeper::removeHistory() returned FALSE";
HistoryKeeper::resetInstance(); // HistoryKeeper::removeHistory() invokes HistoryKeeper::removeHistory() but logic may be changed
return msgs;
};
Core* core = Core::getInstance();
QList<HistoryKeeper::HistMessage> oldMessages;
if (bodyUI->cbEncryptHistory->isChecked())
{
@ -126,14 +113,11 @@ void PrivacyForm::onEncryptLogsUpdated()
{
if (setChatLogsPassword())
{
oldMessages = getOldMessages();
Settings::getInstance().setEncryptLogs(true);
bodyUI->cbEncryptHistory->setChecked(true);
// not logically necessary, but more consistent (esp. if the logic changes)
bodyUI->changeLogsPwButton->setEnabled(true);
HistoryKeeper::getInstance()->importMessages(oldMessages);
return;
}
}
@ -142,14 +126,14 @@ void PrivacyForm::onEncryptLogsUpdated()
{
if (checkContinue(tr("Old encrypted chat logs", "title"), tr("Would you like to un-encrypt your chat logs?\nOtherwise they will be deleted.")))
{
oldMessages = getOldMessages();
QList<HistoryKeeper::HistMessage> oldMessages = HistoryKeeper::exportMessagesDeleteFile(true);
core->clearPassword(Core::ptHistory);
Settings::getInstance().setEncryptLogs(false);
HistoryKeeper::getInstance()->importMessages(oldMessages);
}
else
{
HistoryKeeper::resetInstance();
HistoryKeeper::removeHistory(true);
}
}