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

Add tox save loading/saving to Profile

This commit is contained in:
tux3 2015-06-04 10:56:48 +02:00
parent 840fd7dc40
commit 933dce485d
3 changed files with 36 additions and 1 deletions

View File

@ -5,10 +5,10 @@
#include <cassert>
#include <QDir>
#include <QFileInfo>
#include <QSaveFile>
#include <QThread>
#include <QObject>
#include <QDebug>
QVector<QString> Profile::profiles;
Profile::Profile(QString name, QString password, bool isNewProfile)
@ -184,6 +184,36 @@ fail:
return data;
}
void Profile::saveToxSave(QByteArray data)
{
ProfileLocker::assertLock();
assert(ProfileLocker::getCurLockName() == name);
QString path = Settings::getSettingsDirPath() + QDir::separator() + name + ".tox";
QSaveFile saveFile(path);
if (!saveFile.open(QIODevice::WriteOnly))
{
qCritical() << "Tox save file " << path << " couldn't be opened";
return;
}
if (!password.isEmpty())
{
core->setPassword(password, Core::ptMain);
data = core->encryptData(data, Core::ptMain);
if (data.isEmpty())
{
qCritical() << "Failed to encrypt, can't save!";
saveFile.cancelWriting();
return;
}
}
saveFile.write(data);
saveFile.commit();
newProfile = false;
}
bool Profile::profileExists(QString name)
{
QString path = Settings::getSettingsDirPath() + QDir::separator() + name;

View File

@ -27,6 +27,7 @@ public:
void startCore(); ///< Starts the Core thread
bool isNewProfile();
QByteArray loadToxSave(); ///< Loads the profile's .tox save from file, unencrypted
void saveToxSave(QByteArray data); ///< Saves the profile's .tox save, encrypted if needed
/// Scan for profile, automatically importing them if needed
/// NOT thread-safe

View File

@ -14,8 +14,12 @@ LoginScreen::LoginScreen(QWidget *parent) :
connect(ui->newProfilePgbtn, &QPushButton::clicked, this, &LoginScreen::onNewProfilePageClicked);
connect(ui->loginPgbtn, &QPushButton::clicked, this, &LoginScreen::onLoginPageClicked);
connect(ui->createAccountButton, &QPushButton::clicked, this, &LoginScreen::onCreateNewProfile);
connect(ui->newUsername, &QLineEdit::returnPressed, this, &LoginScreen::onCreateNewProfile);
connect(ui->newPass, &QLineEdit::returnPressed, this, &LoginScreen::onCreateNewProfile);
connect(ui->newPassConfirm, &QLineEdit::returnPressed, this, &LoginScreen::onCreateNewProfile);
connect(ui->loginButton, &QPushButton::clicked, this, &LoginScreen::onLogin);
connect(ui->loginUsernames, &QComboBox::currentTextChanged, this, &LoginScreen::onLoginUsernameSelected);
connect(ui->loginPassword, &QLineEdit::returnPressed, this, &LoginScreen::onLogin);
reset();
}