|
|
|
@ -275,20 +275,12 @@ void Profile::initCore(const QByteArray& toxsave, const ICoreSettings& s, bool i
@@ -275,20 +275,12 @@ void Profile::initCore(const QByteArray& toxsave, const ICoreSettings& s, bool i
|
|
|
|
|
Qt::ConnectionType::QueuedConnection); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Profile::Profile(const QString& name, const QString& password, bool isNewProfile, |
|
|
|
|
const QByteArray& toxsave, std::unique_ptr<ToxEncrypt> passkey) |
|
|
|
|
Profile::Profile(const QString& name, const QString& password, std::unique_ptr<ToxEncrypt> passkey) |
|
|
|
|
: name{name} |
|
|
|
|
, passkey{std::move(passkey)} |
|
|
|
|
, isRemoved{false} |
|
|
|
|
, encrypted{this->passkey != nullptr} |
|
|
|
|
{ |
|
|
|
|
Settings& s = Settings::getInstance(); |
|
|
|
|
// TODO(kriby): Move/refactor core initialization to remove settings dependency
|
|
|
|
|
// note to self: use slots/signals for this?
|
|
|
|
|
initCore(toxsave, s, isNewProfile); |
|
|
|
|
|
|
|
|
|
loadDatabase(password); |
|
|
|
|
} |
|
|
|
|
{} |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Locks and loads an existing profile and creates the associate Core* instance. |
|
|
|
@ -298,7 +290,7 @@ Profile::Profile(const QString& name, const QString& password, bool isNewProfile
@@ -298,7 +290,7 @@ Profile::Profile(const QString& name, const QString& password, bool isNewProfile
|
|
|
|
|
* |
|
|
|
|
* @note If the profile is already in use return nullptr. |
|
|
|
|
*/ |
|
|
|
|
Profile* Profile::loadProfile(const QString& name, const QString& password) |
|
|
|
|
Profile* Profile::loadProfile(const QString& name, const QString& password, const Settings& settings) |
|
|
|
|
{ |
|
|
|
|
if (ProfileLocker::hasLock()) { |
|
|
|
|
qCritical() << "Tried to load profile " << name << ", but another profile is already locked!"; |
|
|
|
@ -312,7 +304,7 @@ Profile* Profile::loadProfile(const QString& name, const QString& password)
@@ -312,7 +304,7 @@ Profile* Profile::loadProfile(const QString& name, const QString& password)
|
|
|
|
|
|
|
|
|
|
LoadToxDataError error; |
|
|
|
|
QByteArray toxsave = QByteArray(); |
|
|
|
|
QString path = Settings::getInstance().getSettingsDirPath() + name + ".tox"; |
|
|
|
|
QString path = settings.getSettingsDirPath() + name + ".tox"; |
|
|
|
|
std::unique_ptr<ToxEncrypt> tmpKey = loadToxData(password, path, toxsave, error); |
|
|
|
|
|
|
|
|
|
if (logLoadToxDataError(error, path)) { |
|
|
|
@ -320,7 +312,12 @@ Profile* Profile::loadProfile(const QString& name, const QString& password)
@@ -320,7 +312,12 @@ Profile* Profile::loadProfile(const QString& name, const QString& password)
|
|
|
|
|
return nullptr; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return new Profile(name, password, false, toxsave, std::move(tmpKey)); |
|
|
|
|
Profile* p = new Profile(name, password, std::move(tmpKey)); |
|
|
|
|
|
|
|
|
|
p->initCore(toxsave, settings, /*isNewProfile*/ false); |
|
|
|
|
p->loadDatabase(password); |
|
|
|
|
|
|
|
|
|
return p; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -331,7 +328,8 @@ Profile* Profile::loadProfile(const QString& name, const QString& password)
@@ -331,7 +328,8 @@ Profile* Profile::loadProfile(const QString& name, const QString& password)
|
|
|
|
|
* |
|
|
|
|
* @note If the profile is already in use return nullptr. |
|
|
|
|
*/ |
|
|
|
|
Profile* Profile::createProfile(const QString& userName, const QString& password) |
|
|
|
|
Profile* Profile::createProfile(const QString& userName, const QString& password, |
|
|
|
|
const Settings& settings) |
|
|
|
|
{ |
|
|
|
|
CreateToxDataError error; |
|
|
|
|
QString path = Settings::getInstance().getSettingsDirPath() + userName + ".tox"; |
|
|
|
@ -341,8 +339,10 @@ Profile* Profile::createProfile(const QString& userName, const QString& password
@@ -341,8 +339,10 @@ Profile* Profile::createProfile(const QString& userName, const QString& password
|
|
|
|
|
return nullptr; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Settings::getInstance().createPersonal(userName); |
|
|
|
|
Profile* p = new Profile(userName, password, true, QByteArray(), std::move(tmpKey)); |
|
|
|
|
settings.createPersonal(userName); |
|
|
|
|
Profile* p = new Profile(userName, password, std::move(tmpKey)); |
|
|
|
|
p->initCore(QByteArray(), settings, /*isNewProfile*/ true); |
|
|
|
|
p->loadDatabase(password); |
|
|
|
|
return p; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|