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:
parent
840fd7dc40
commit
933dce485d
|
@ -5,10 +5,10 @@
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
|
#include <QSaveFile>
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
QVector<QString> Profile::profiles;
|
QVector<QString> Profile::profiles;
|
||||||
|
|
||||||
Profile::Profile(QString name, QString password, bool isNewProfile)
|
Profile::Profile(QString name, QString password, bool isNewProfile)
|
||||||
|
@ -184,6 +184,36 @@ fail:
|
||||||
return data;
|
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)
|
bool Profile::profileExists(QString name)
|
||||||
{
|
{
|
||||||
QString path = Settings::getSettingsDirPath() + QDir::separator() + name;
|
QString path = Settings::getSettingsDirPath() + QDir::separator() + name;
|
||||||
|
|
|
@ -27,6 +27,7 @@ public:
|
||||||
void startCore(); ///< Starts the Core thread
|
void startCore(); ///< Starts the Core thread
|
||||||
bool isNewProfile();
|
bool isNewProfile();
|
||||||
QByteArray loadToxSave(); ///< Loads the profile's .tox save from file, unencrypted
|
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
|
/// Scan for profile, automatically importing them if needed
|
||||||
/// NOT thread-safe
|
/// NOT thread-safe
|
||||||
|
|
|
@ -14,8 +14,12 @@ LoginScreen::LoginScreen(QWidget *parent) :
|
||||||
connect(ui->newProfilePgbtn, &QPushButton::clicked, this, &LoginScreen::onNewProfilePageClicked);
|
connect(ui->newProfilePgbtn, &QPushButton::clicked, this, &LoginScreen::onNewProfilePageClicked);
|
||||||
connect(ui->loginPgbtn, &QPushButton::clicked, this, &LoginScreen::onLoginPageClicked);
|
connect(ui->loginPgbtn, &QPushButton::clicked, this, &LoginScreen::onLoginPageClicked);
|
||||||
connect(ui->createAccountButton, &QPushButton::clicked, this, &LoginScreen::onCreateNewProfile);
|
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->loginButton, &QPushButton::clicked, this, &LoginScreen::onLogin);
|
||||||
connect(ui->loginUsernames, &QComboBox::currentTextChanged, this, &LoginScreen::onLoginUsernameSelected);
|
connect(ui->loginUsernames, &QComboBox::currentTextChanged, this, &LoginScreen::onLoginUsernameSelected);
|
||||||
|
connect(ui->loginPassword, &QLineEdit::returnPressed, this, &LoginScreen::onLogin);
|
||||||
|
|
||||||
reset();
|
reset();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user