|
|
@ -1,5 +1,5 @@ |
|
|
|
/*
|
|
|
|
/*
|
|
|
|
Copyright © 2015 by The qTox Project |
|
|
|
Copyright © 2015-2016 by The qTox Project |
|
|
|
|
|
|
|
|
|
|
|
This file is part of qTox, a Qt-based graphical interface for Tox. |
|
|
|
This file is part of qTox, a Qt-based graphical interface for Tox. |
|
|
|
|
|
|
|
|
|
|
@ -18,23 +18,25 @@ |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "profile.h" |
|
|
|
#include <QDebug> |
|
|
|
#include "profilelocker.h" |
|
|
|
|
|
|
|
#include "src/persistence/settings.h" |
|
|
|
|
|
|
|
#include "src/persistence/historykeeper.h" |
|
|
|
|
|
|
|
#include "src/core/core.h" |
|
|
|
|
|
|
|
#include "src/widget/gui.h" |
|
|
|
|
|
|
|
#include "src/widget/widget.h" |
|
|
|
|
|
|
|
#include "src/nexus.h" |
|
|
|
|
|
|
|
#include <cassert> |
|
|
|
|
|
|
|
#include <QDir> |
|
|
|
#include <QDir> |
|
|
|
#include <QFileInfo> |
|
|
|
#include <QFileInfo> |
|
|
|
|
|
|
|
#include <QObject> |
|
|
|
#include <QSaveFile> |
|
|
|
#include <QSaveFile> |
|
|
|
#include <QThread> |
|
|
|
#include <QThread> |
|
|
|
#include <QObject> |
|
|
|
|
|
|
|
#include <QDebug> |
|
|
|
#include <cassert> |
|
|
|
#include <sodium.h> |
|
|
|
#include <sodium.h> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "profile.h" |
|
|
|
|
|
|
|
#include "profilelocker.h" |
|
|
|
|
|
|
|
#include "settings.h" |
|
|
|
|
|
|
|
#include "historykeeper.h" |
|
|
|
|
|
|
|
#include "src/core/core.h" |
|
|
|
|
|
|
|
#include "src/nexus.h" |
|
|
|
|
|
|
|
#include "src/widget/gui.h" |
|
|
|
|
|
|
|
#include "src/widget/widget.h" |
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @class Profile |
|
|
|
* @class Profile |
|
|
|
* @brief Manages user profiles. |
|
|
|
* @brief Manages user profiles. |
|
|
@ -52,25 +54,31 @@ |
|
|
|
|
|
|
|
|
|
|
|
QVector<QString> Profile::profiles; |
|
|
|
QVector<QString> Profile::profiles; |
|
|
|
|
|
|
|
|
|
|
|
Profile::Profile(QString name, const QString &password, bool isNewProfile) |
|
|
|
Profile::Profile(QString name, const QString& password, bool isNewProfile) |
|
|
|
: name{name}, password{password}, |
|
|
|
: name{name}, password{password} |
|
|
|
newProfile{isNewProfile}, isRemoved{false} |
|
|
|
, database(std::make_shared<RawDatabase>(getDbPath(name), password)) |
|
|
|
|
|
|
|
, newProfile{isNewProfile}, isRemoved{false} |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (!password.isEmpty()) |
|
|
|
if (!password.isEmpty()) |
|
|
|
|
|
|
|
{ |
|
|
|
passkey = *core->createPasskey(password); |
|
|
|
passkey = *core->createPasskey(password); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Settings& s = Settings::getInstance(); |
|
|
|
Settings& s = Settings::getInstance(); |
|
|
|
s.setCurrentProfile(name); |
|
|
|
s.setCurrentProfile(name); |
|
|
|
s.saveGlobal(); |
|
|
|
s.saveGlobal(); |
|
|
|
|
|
|
|
|
|
|
|
// At this point it's too early to load the personal settings (Nexus will do it), so we always load
|
|
|
|
// At this point it's too early to load the personal settings (Nexus will do
|
|
|
|
// the history, and if it fails we can't change the setting now, but we keep a nullptr
|
|
|
|
// it), so we always load the history, and if it fails we can't change the
|
|
|
|
history.reset(new History{name, password}); |
|
|
|
// setting now, but we keep a nullptr
|
|
|
|
if (!history->isValid()) |
|
|
|
if (database->isOpen()) |
|
|
|
{ |
|
|
|
{ |
|
|
|
qWarning() << "Failed to open history for profile"<<name; |
|
|
|
history.reset(new History(database)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
qWarning() << "Failed to open history for profile" << name; |
|
|
|
GUI::showError(QObject::tr("Error"), QObject::tr("qTox couldn't open your chat logs, they will be disabled.")); |
|
|
|
GUI::showError(QObject::tr("Error"), QObject::tr("qTox couldn't open your chat logs, they will be disabled.")); |
|
|
|
history.release(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
coreThread = new QThread(); |
|
|
|
coreThread = new QThread(); |
|
|
@ -88,7 +96,7 @@ Profile::Profile(QString name, const QString &password, bool isNewProfile) |
|
|
|
* |
|
|
|
* |
|
|
|
* @example If the profile is already in use return nullptr. |
|
|
|
* @example If the profile is already in use return nullptr. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
Profile* Profile::loadProfile(QString name, const QString &password) |
|
|
|
Profile* Profile::loadProfile(QString name, const QString& password) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (ProfileLocker::hasLock()) |
|
|
|
if (ProfileLocker::hasLock()) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -141,7 +149,7 @@ Profile* Profile::loadProfile(QString name, const QString &password) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
uint8_t salt[TOX_PASS_SALT_LENGTH]; |
|
|
|
uint8_t salt[TOX_PASS_SALT_LENGTH]; |
|
|
|
tox_get_salt(reinterpret_cast<uint8_t *>(data.data()), salt); |
|
|
|
tox_get_salt(reinterpret_cast<uint8_t*>(data.data()), salt); |
|
|
|
auto tmpkey = *Core::createPasskey(password, salt); |
|
|
|
auto tmpkey = *Core::createPasskey(password, salt); |
|
|
|
|
|
|
|
|
|
|
|
data = Core::decryptData(data, tmpkey); |
|
|
|
data = Core::decryptData(data, tmpkey); |
|
|
@ -155,13 +163,18 @@ Profile* Profile::loadProfile(QString name, const QString &password) |
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (!password.isEmpty()) |
|
|
|
if (!password.isEmpty()) |
|
|
|
|
|
|
|
{ |
|
|
|
qWarning() << "We have a password, but the tox save file is not encrypted"; |
|
|
|
qWarning() << "We have a password, but the tox save file is not encrypted"; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Profile* p = new Profile(name, password, false); |
|
|
|
Profile* p = new Profile(name, password, false); |
|
|
|
if (p->history && HistoryKeeper::isFileExist(!password.isEmpty())) |
|
|
|
if (p->history && HistoryKeeper::isFileExist(!password.isEmpty())) |
|
|
|
|
|
|
|
{ |
|
|
|
p->history->import(*HistoryKeeper::getInstance(*p)); |
|
|
|
p->history->import(*HistoryKeeper::getInstance(*p)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return p; |
|
|
|
return p; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -200,7 +213,10 @@ Profile* Profile::createProfile(QString name, QString password) |
|
|
|
Profile::~Profile() |
|
|
|
Profile::~Profile() |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (!isRemoved && core->isReady()) |
|
|
|
if (!isRemoved && core->isReady()) |
|
|
|
|
|
|
|
{ |
|
|
|
saveToxSave(); |
|
|
|
saveToxSave(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
delete core; |
|
|
|
delete core; |
|
|
|
delete coreThread; |
|
|
|
delete coreThread; |
|
|
|
if (!isRemoved) |
|
|
|
if (!isRemoved) |
|
|
@ -227,7 +243,10 @@ QVector<QString> Profile::getFilesByExt(QString extension) |
|
|
|
QFileInfoList list = dir.entryInfoList(); |
|
|
|
QFileInfoList list = dir.entryInfoList(); |
|
|
|
out.reserve(list.size()); |
|
|
|
out.reserve(list.size()); |
|
|
|
for (QFileInfo file : list) |
|
|
|
for (QFileInfo file : list) |
|
|
|
|
|
|
|
{ |
|
|
|
out += file.completeBaseName(); |
|
|
|
out += file.completeBaseName(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return out; |
|
|
|
return out; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -242,7 +261,10 @@ void Profile::scanProfiles() |
|
|
|
for (QString toxfile : toxfiles) |
|
|
|
for (QString toxfile : toxfiles) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (!inifiles.contains(toxfile)) |
|
|
|
if (!inifiles.contains(toxfile)) |
|
|
|
|
|
|
|
{ |
|
|
|
Settings::getInstance().createPersonal(toxfile); |
|
|
|
Settings::getInstance().createPersonal(toxfile); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
profiles.append(toxfile); |
|
|
|
profiles.append(toxfile); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -319,17 +341,21 @@ QByteArray Profile::loadToxSave() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
uint8_t salt[TOX_PASS_SALT_LENGTH]; |
|
|
|
uint8_t salt[TOX_PASS_SALT_LENGTH]; |
|
|
|
tox_get_salt(reinterpret_cast<uint8_t *>(data.data()), salt); |
|
|
|
tox_get_salt(reinterpret_cast<uint8_t*>(data.data()), salt); |
|
|
|
passkey = *core->createPasskey(password, salt); |
|
|
|
passkey = *core->createPasskey(password, salt); |
|
|
|
|
|
|
|
|
|
|
|
data = core->decryptData(data, passkey); |
|
|
|
data = core->decryptData(data, passkey); |
|
|
|
if (data.isEmpty()) |
|
|
|
if (data.isEmpty()) |
|
|
|
|
|
|
|
{ |
|
|
|
qCritical() << "Failed to decrypt the tox save file"; |
|
|
|
qCritical() << "Failed to decrypt the tox save file"; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (!password.isEmpty()) |
|
|
|
if (!password.isEmpty()) |
|
|
|
|
|
|
|
{ |
|
|
|
qWarning() << "We have a password, but the tox save file is not encrypted"; |
|
|
|
qWarning() << "We have a password, but the tox save file is not encrypted"; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fail: |
|
|
|
fail: |
|
|
@ -402,7 +428,7 @@ void Profile::saveToxSave(QByteArray data) |
|
|
|
* @param forceUnencrypted If true, return the path to the plaintext file even if this is an encrypted profile. |
|
|
|
* @param forceUnencrypted If true, return the path to the plaintext file even if this is an encrypted profile. |
|
|
|
* @return Path to the avatar. |
|
|
|
* @return Path to the avatar. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
QString Profile::avatarPath(const QString &ownerId, bool forceUnencrypted) |
|
|
|
QString Profile::avatarPath(const QString& ownerId, bool forceUnencrypted) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (password.isEmpty() || forceUnencrypted) |
|
|
|
if (password.isEmpty() || forceUnencrypted) |
|
|
|
return Settings::getInstance().getSettingsDirPath() + "avatars/" + ownerId + ".png"; |
|
|
|
return Settings::getInstance().getSettingsDirPath() + "avatars/" + ownerId + ".png"; |
|
|
@ -433,7 +459,7 @@ QPixmap Profile::loadAvatar() |
|
|
|
* @param ownerId Friend ID to load avatar. |
|
|
|
* @param ownerId Friend ID to load avatar. |
|
|
|
* @return Avatar as QPixmap. |
|
|
|
* @return Avatar as QPixmap. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
QPixmap Profile::loadAvatar(const QString &ownerId) |
|
|
|
QPixmap Profile::loadAvatar(const QString& ownerId) |
|
|
|
{ |
|
|
|
{ |
|
|
|
QPixmap pic; |
|
|
|
QPixmap pic; |
|
|
|
pic.loadFromData(loadAvatarData(ownerId)); |
|
|
|
pic.loadFromData(loadAvatarData(ownerId)); |
|
|
@ -445,7 +471,7 @@ QPixmap Profile::loadAvatar(const QString &ownerId) |
|
|
|
* @param ownerId Friend ID to load avatar. |
|
|
|
* @param ownerId Friend ID to load avatar. |
|
|
|
* @return Avatar as QByteArray. |
|
|
|
* @return Avatar as QByteArray. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
QByteArray Profile::loadAvatarData(const QString &ownerId) |
|
|
|
QByteArray Profile::loadAvatarData(const QString& ownerId) |
|
|
|
{ |
|
|
|
{ |
|
|
|
return loadAvatarData(ownerId, password); |
|
|
|
return loadAvatarData(ownerId, password); |
|
|
|
} |
|
|
|
} |
|
|
@ -456,7 +482,7 @@ QByteArray Profile::loadAvatarData(const QString &ownerId) |
|
|
|
* @param password Profile password to decrypt data. |
|
|
|
* @param password Profile password to decrypt data. |
|
|
|
* @return Avatar as QByteArray. |
|
|
|
* @return Avatar as QByteArray. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
QByteArray Profile::loadAvatarData(const QString &ownerId, const QString &password) |
|
|
|
QByteArray Profile::loadAvatarData(const QString& ownerId, const QString& password) |
|
|
|
{ |
|
|
|
{ |
|
|
|
QString path = avatarPath(ownerId); |
|
|
|
QString path = avatarPath(ownerId); |
|
|
|
bool encrypted = !password.isEmpty(); |
|
|
|
bool encrypted = !password.isEmpty(); |
|
|
@ -470,16 +496,19 @@ QByteArray Profile::loadAvatarData(const QString &ownerId, const QString &passwo |
|
|
|
|
|
|
|
|
|
|
|
QFile file(path); |
|
|
|
QFile file(path); |
|
|
|
if (!file.open(QIODevice::ReadOnly)) |
|
|
|
if (!file.open(QIODevice::ReadOnly)) |
|
|
|
|
|
|
|
{ |
|
|
|
return {}; |
|
|
|
return {}; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
QByteArray pic = file.readAll(); |
|
|
|
QByteArray pic = file.readAll(); |
|
|
|
if (encrypted && !pic.isEmpty()) |
|
|
|
if (encrypted && !pic.isEmpty()) |
|
|
|
{ |
|
|
|
{ |
|
|
|
uint8_t salt[TOX_PASS_SALT_LENGTH]; |
|
|
|
uint8_t salt[TOX_PASS_SALT_LENGTH]; |
|
|
|
tox_get_salt(reinterpret_cast<uint8_t *>(pic.data()), salt); |
|
|
|
tox_get_salt(reinterpret_cast<uint8_t*>(pic.data()), salt); |
|
|
|
auto passkey = core->createPasskey(password, salt); |
|
|
|
auto passkey = core->createPasskey(password, salt); |
|
|
|
pic = core->decryptData(pic, *passkey); |
|
|
|
pic = core->decryptData(pic, *passkey); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return pic; |
|
|
|
return pic; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -488,10 +517,12 @@ QByteArray Profile::loadAvatarData(const QString &ownerId, const QString &passwo |
|
|
|
* @param pic Picture to save. |
|
|
|
* @param pic Picture to save. |
|
|
|
* @param ownerId ID of avatar owner. |
|
|
|
* @param ownerId ID of avatar owner. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
void Profile::saveAvatar(QByteArray pic, const QString &ownerId) |
|
|
|
void Profile::saveAvatar(QByteArray pic, const QString& ownerId) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (!password.isEmpty() && !pic.isEmpty()) |
|
|
|
if (!password.isEmpty() && !pic.isEmpty()) |
|
|
|
|
|
|
|
{ |
|
|
|
pic = core->encryptData(pic, passkey); |
|
|
|
pic = core->encryptData(pic, passkey); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
QString path = avatarPath(ownerId); |
|
|
|
QString path = avatarPath(ownerId); |
|
|
|
QDir(Settings::getInstance().getSettingsDirPath()).mkdir("avatars"); |
|
|
|
QDir(Settings::getInstance().getSettingsDirPath()).mkdir("avatars"); |
|
|
@ -517,7 +548,7 @@ void Profile::saveAvatar(QByteArray pic, const QString &ownerId) |
|
|
|
* @param ownerId Friend ID to get hash. |
|
|
|
* @param ownerId Friend ID to get hash. |
|
|
|
* @return Avatar tox hash. |
|
|
|
* @return Avatar tox hash. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
QByteArray Profile::getAvatarHash(const QString &ownerId) |
|
|
|
QByteArray Profile::getAvatarHash(const QString& ownerId) |
|
|
|
{ |
|
|
|
{ |
|
|
|
QByteArray pic = loadAvatarData(ownerId); |
|
|
|
QByteArray pic = loadAvatarData(ownerId); |
|
|
|
QByteArray avatarHash(TOX_HASH_LENGTH, 0); |
|
|
|
QByteArray avatarHash(TOX_HASH_LENGTH, 0); |
|
|
@ -546,7 +577,7 @@ bool Profile::isHistoryEnabled() |
|
|
|
* @brief Get chat history. |
|
|
|
* @brief Get chat history. |
|
|
|
* @return May return a nullptr if the history failed to load. |
|
|
|
* @return May return a nullptr if the history failed to load. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
History *Profile::getHistory() |
|
|
|
History* Profile::getHistory() |
|
|
|
{ |
|
|
|
{ |
|
|
|
return history.get(); |
|
|
|
return history.get(); |
|
|
|
} |
|
|
|
} |
|
|
@ -555,7 +586,7 @@ History *Profile::getHistory() |
|
|
|
* @brief Removes a cached avatar. |
|
|
|
* @brief Removes a cached avatar. |
|
|
|
* @param ownerId Friend ID whose avater to delete. |
|
|
|
* @param ownerId Friend ID whose avater to delete. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
void Profile::removeAvatar(const QString &ownerId) |
|
|
|
void Profile::removeAvatar(const QString& ownerId) |
|
|
|
{ |
|
|
|
{ |
|
|
|
QFile::remove(avatarPath(ownerId)); |
|
|
|
QFile::remove(avatarPath(ownerId)); |
|
|
|
if (ownerId == core->getSelfId().publicKey) |
|
|
|
if (ownerId == core->getSelfId().publicKey) |
|
|
@ -656,15 +687,14 @@ QVector<QString> Profile::remove() |
|
|
|
qWarning() << "Could not remove file " << historyLegacyUnencrypted.fileName(); |
|
|
|
qWarning() << "Could not remove file " << historyLegacyUnencrypted.fileName(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (history) |
|
|
|
QString dbPath = getDbPath(name); |
|
|
|
|
|
|
|
if (database->isOpen() && !database->remove() && QFile::exists(dbPath)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (!history->remove() && QFile::exists(History::getDbPath(name))) |
|
|
|
ret.push_back(dbPath); |
|
|
|
{ |
|
|
|
qWarning() << "Could not remove file " << dbPath; |
|
|
|
ret.push_back(History::getDbPath(name)); |
|
|
|
|
|
|
|
qWarning() << "Could not remove file " << History::getDbPath(name); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
history.release(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
history.release(); |
|
|
|
|
|
|
|
database.reset(); |
|
|
|
|
|
|
|
|
|
|
|
return ret; |
|
|
|
return ret; |
|
|
|
} |
|
|
|
} |
|
|
@ -680,17 +710,24 @@ bool Profile::rename(QString newName) |
|
|
|
newPath = Settings::getInstance().getSettingsDirPath() + newName; |
|
|
|
newPath = Settings::getInstance().getSettingsDirPath() + newName; |
|
|
|
|
|
|
|
|
|
|
|
if (!ProfileLocker::lock(newName)) |
|
|
|
if (!ProfileLocker::lock(newName)) |
|
|
|
|
|
|
|
{ |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QFile::rename(path + ".tox", newPath + ".tox"); |
|
|
|
|
|
|
|
QFile::rename(path + ".ini", newPath + ".ini"); |
|
|
|
|
|
|
|
if (database) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
database->rename(newName); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
QFile::rename(path+".tox", newPath+".tox"); |
|
|
|
|
|
|
|
QFile::rename(path+".ini", newPath+".ini"); |
|
|
|
|
|
|
|
if (history) |
|
|
|
|
|
|
|
history->rename(newName); |
|
|
|
|
|
|
|
bool resetAutorun = Settings::getInstance().getAutorun(); |
|
|
|
bool resetAutorun = Settings::getInstance().getAutorun(); |
|
|
|
Settings::getInstance().setAutorun(false); |
|
|
|
Settings::getInstance().setAutorun(false); |
|
|
|
Settings::getInstance().setCurrentProfile(newName); |
|
|
|
Settings::getInstance().setCurrentProfile(newName); |
|
|
|
if (resetAutorun) |
|
|
|
if (resetAutorun) |
|
|
|
|
|
|
|
{ |
|
|
|
Settings::getInstance().setAutorun(true); // fixes -p flag in autostart command line
|
|
|
|
Settings::getInstance().setAutorun(true); // fixes -p flag in autostart command line
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
name = newName; |
|
|
|
name = newName; |
|
|
|
return true; |
|
|
|
return true; |
|
|
@ -703,7 +740,9 @@ bool Profile::rename(QString newName) |
|
|
|
bool Profile::checkPassword() |
|
|
|
bool Profile::checkPassword() |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (isRemoved) |
|
|
|
if (isRemoved) |
|
|
|
|
|
|
|
{ |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return !loadToxSave().isEmpty(); |
|
|
|
return !loadToxSave().isEmpty(); |
|
|
|
} |
|
|
|
} |
|
|
@ -725,7 +764,10 @@ void Profile::restartCore() |
|
|
|
{ |
|
|
|
{ |
|
|
|
GUI::setEnabled(false); // Core::reset re-enables it
|
|
|
|
GUI::setEnabled(false); // Core::reset re-enables it
|
|
|
|
if (!isRemoved && core->isReady()) |
|
|
|
if (!isRemoved && core->isReady()) |
|
|
|
|
|
|
|
{ |
|
|
|
saveToxSave(); |
|
|
|
saveToxSave(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
QMetaObject::invokeMethod(core, "reset"); |
|
|
|
QMetaObject::invokeMethod(core, "reset"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -733,7 +775,7 @@ void Profile::restartCore() |
|
|
|
* @brief Changes the encryption password and re-saves everything with it |
|
|
|
* @brief Changes the encryption password and re-saves everything with it |
|
|
|
* @param newPassword Password for encryption. |
|
|
|
* @param newPassword Password for encryption. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
void Profile::setPassword(const QString &newPassword) |
|
|
|
void Profile::setPassword(const QString& newPassword) |
|
|
|
{ |
|
|
|
{ |
|
|
|
QByteArray avatar = loadAvatarData(core->getSelfId().publicKey); |
|
|
|
QByteArray avatar = loadAvatarData(core->getSelfId().publicKey); |
|
|
|
QString oldPassword = password; |
|
|
|
QString oldPassword = password; |
|
|
@ -741,11 +783,12 @@ void Profile::setPassword(const QString &newPassword) |
|
|
|
passkey = *core->createPasskey(password); |
|
|
|
passkey = *core->createPasskey(password); |
|
|
|
saveToxSave(); |
|
|
|
saveToxSave(); |
|
|
|
|
|
|
|
|
|
|
|
if (history) |
|
|
|
if (database) |
|
|
|
{ |
|
|
|
{ |
|
|
|
history->setPassword(newPassword); |
|
|
|
database->setPassword(newPassword); |
|
|
|
Nexus::getDesktopGUI()->reloadHistory(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Nexus::getDesktopGUI()->reloadHistory(); |
|
|
|
saveAvatar(avatar, core->getSelfId().publicKey); |
|
|
|
saveAvatar(avatar, core->getSelfId().publicKey); |
|
|
|
|
|
|
|
|
|
|
|
QVector<uint32_t> friendList = core->getFriendList(); |
|
|
|
QVector<uint32_t> friendList = core->getFriendList(); |
|
|
@ -756,3 +799,13 @@ void Profile::setPassword(const QString &newPassword) |
|
|
|
saveAvatar(loadAvatarData(friendPublicKey,oldPassword),friendPublicKey); |
|
|
|
saveAvatar(loadAvatarData(friendPublicKey,oldPassword),friendPublicKey); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @brief Retrieves the path to the database file for a given profile. |
|
|
|
|
|
|
|
* @param profileName Profile name. |
|
|
|
|
|
|
|
* @return Path to database. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
QString Profile::getDbPath(const QString& profileName) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return Settings::getInstance().getSettingsDirPath() + profileName + ".db"; |
|
|
|
|
|
|
|
} |
|
|
|