mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
Implement profile deletion
This commit is contained in:
parent
f7546a731f
commit
21db31c215
|
@ -104,7 +104,13 @@ Core::~Core()
|
||||||
{
|
{
|
||||||
qDebug() << "Deleting Core";
|
qDebug() << "Deleting Core";
|
||||||
|
|
||||||
QMetaObject::invokeMethod(this, "stopTimers", Qt::BlockingQueuedConnection);
|
if (coreThread->isRunning())
|
||||||
|
{
|
||||||
|
if (QThread::currentThread() == coreThread)
|
||||||
|
stopTimers();
|
||||||
|
else
|
||||||
|
QMetaObject::invokeMethod(this, "stopTimers", Qt::BlockingQueuedConnection);
|
||||||
|
}
|
||||||
delete toxTimer;
|
delete toxTimer;
|
||||||
coreThread->exit(0);
|
coreThread->exit(0);
|
||||||
while (coreThread->isRunning())
|
while (coreThread->isRunning())
|
||||||
|
@ -781,7 +787,8 @@ void Core::setUsername(const QString& username)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
emit usernameSet(username);
|
emit usernameSet(username);
|
||||||
profile.saveToxSave();
|
if (ready)
|
||||||
|
profile.saveToxSave();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -845,7 +852,8 @@ void Core::setStatusMessage(const QString& message)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
profile.saveToxSave();
|
if (ready)
|
||||||
|
profile.saveToxSave();
|
||||||
emit statusMessageSet(message);
|
emit statusMessageSet(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#include "profilelocker.h"
|
#include "profilelocker.h"
|
||||||
#include "src/misc/settings.h"
|
#include "src/misc/settings.h"
|
||||||
#include "src/core/core.h"
|
#include "src/core/core.h"
|
||||||
|
#include "src/historykeeper.h"
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
|
@ -12,7 +13,8 @@
|
||||||
QVector<QString> Profile::profiles;
|
QVector<QString> Profile::profiles;
|
||||||
|
|
||||||
Profile::Profile(QString name, QString password, bool isNewProfile)
|
Profile::Profile(QString name, QString password, bool isNewProfile)
|
||||||
: name{name}, password{password}, newProfile{isNewProfile}
|
: name{name}, password{password},
|
||||||
|
newProfile{isNewProfile}, isRemoved{false}
|
||||||
{
|
{
|
||||||
coreThread = new QThread();
|
coreThread = new QThread();
|
||||||
coreThread->setObjectName("qTox Core");
|
coreThread->setObjectName("qTox Core");
|
||||||
|
@ -64,7 +66,8 @@ Profile* Profile::createProfile(QString name, QString password)
|
||||||
|
|
||||||
Profile::~Profile()
|
Profile::~Profile()
|
||||||
{
|
{
|
||||||
saveToxSave();
|
if (!isRemoved && core->isReady())
|
||||||
|
saveToxSave();
|
||||||
delete core;
|
delete core;
|
||||||
delete coreThread;
|
delete coreThread;
|
||||||
ProfileLocker::assertLock();
|
ProfileLocker::assertLock();
|
||||||
|
@ -130,6 +133,8 @@ bool Profile::isNewProfile()
|
||||||
|
|
||||||
QByteArray Profile::loadToxSave()
|
QByteArray Profile::loadToxSave()
|
||||||
{
|
{
|
||||||
|
assert(!isRemoved);
|
||||||
|
|
||||||
/// TODO: Cache the data, invalidate it only when we save
|
/// TODO: Cache the data, invalidate it only when we save
|
||||||
QByteArray data;
|
QByteArray data;
|
||||||
|
|
||||||
|
@ -188,11 +193,15 @@ fail:
|
||||||
|
|
||||||
void Profile::saveToxSave()
|
void Profile::saveToxSave()
|
||||||
{
|
{
|
||||||
saveToxSave(core->getToxSaveData());
|
assert(core->isReady());
|
||||||
|
QByteArray data = core->getToxSaveData();
|
||||||
|
assert(data.size());
|
||||||
|
saveToxSave(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Profile::saveToxSave(QByteArray data)
|
void Profile::saveToxSave(QByteArray data)
|
||||||
{
|
{
|
||||||
|
assert(!isRemoved);
|
||||||
ProfileLocker::assertLock();
|
ProfileLocker::assertLock();
|
||||||
assert(ProfileLocker::getCurLockName() == name);
|
assert(ProfileLocker::getCurLockName() == name);
|
||||||
|
|
||||||
|
@ -244,3 +253,22 @@ bool Profile::isProfileEncrypted(QString name)
|
||||||
|
|
||||||
return tox_is_data_encrypted(data);
|
return tox_is_data_encrypted(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Profile::remove()
|
||||||
|
{
|
||||||
|
if (isRemoved)
|
||||||
|
{
|
||||||
|
qWarning() << "Profile "<<name<<" is already removed!";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
isRemoved = true;
|
||||||
|
|
||||||
|
qDebug() << "Removing profile"<<name;
|
||||||
|
profiles.removeAll(name);
|
||||||
|
QString path = Settings::getSettingsDirPath() + QDir::separator() + name;
|
||||||
|
QFile::remove(path+".tox");
|
||||||
|
QFile::remove(path+".ini");
|
||||||
|
|
||||||
|
QFile::remove(HistoryKeeper::getHistoryPath(name, 0));
|
||||||
|
QFile::remove(HistoryKeeper::getHistoryPath(name, 1));
|
||||||
|
}
|
||||||
|
|
|
@ -27,8 +27,13 @@ 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(); ///< Saves the profile's .tox save, encrypted if needed
|
void saveToxSave(); ///< Saves the profile's .tox save, encrypted if needed. Invalid on deleted profiles.
|
||||||
void saveToxSave(QByteArray data); ///< Saves the profile's .tox save with this data, encrypted if needed
|
void saveToxSave(QByteArray data); ///< Write the .tox save, encrypted if needed. Invalid on deleted profiles.
|
||||||
|
|
||||||
|
/// Removes the profile permanently
|
||||||
|
/// It is invalid to call loadToxSave or saveToxSave on a deleted profile
|
||||||
|
/// Updates the profiles vector
|
||||||
|
void remove();
|
||||||
|
|
||||||
/// Scan for profile, automatically importing them if needed
|
/// Scan for profile, automatically importing them if needed
|
||||||
/// NOT thread-safe
|
/// NOT thread-safe
|
||||||
|
@ -51,8 +56,9 @@ private:
|
||||||
Core* core;
|
Core* core;
|
||||||
QThread* coreThread;
|
QThread* coreThread;
|
||||||
QString name, password;
|
QString name, password;
|
||||||
static QVector<QString> profiles;
|
|
||||||
bool newProfile; ///< True if this is a newly created profile, with no .tox save file yet.
|
bool newProfile; ///< True if this is a newly created profile, with no .tox save file yet.
|
||||||
|
bool isRemoved; ///< True if the profile has been removed by remove()
|
||||||
|
static QVector<QString> profiles;
|
||||||
/// How much data we need to read to check if the file is encrypted
|
/// How much data we need to read to check if the file is encrypted
|
||||||
/// Must be >= TOX_ENC_SAVE_MAGIC_LENGTH (8), which isn't publicly defined
|
/// Must be >= TOX_ENC_SAVE_MAGIC_LENGTH (8), which isn't publicly defined
|
||||||
static constexpr int encryptHeaderSize = 8;
|
static constexpr int encryptHeaderSize = 8;
|
||||||
|
|
|
@ -283,29 +283,13 @@ void ProfileForm::onExportClicked()
|
||||||
|
|
||||||
void ProfileForm::onDeleteClicked()
|
void ProfileForm::onDeleteClicked()
|
||||||
{
|
{
|
||||||
/** Add a delete function in profile
|
if (GUI::askQuestion(tr("Really delete profile?","deletion confirmation title"),
|
||||||
if (Settings::getInstance().getCurrentProfile() == bodyUI->profiles->currentText())
|
tr("Are you sure you want to delete this profile?","deletion confirmation text")))
|
||||||
{
|
{
|
||||||
GUI::showWarning(tr("Profile currently loaded","current profile deletion warning title"), tr("This profile is currently in use. Please load a different profile before deleting this one.","current profile deletion warning text"));
|
Nexus& nexus = Nexus::getInstance();
|
||||||
|
nexus.getProfile()->remove();
|
||||||
|
nexus.showLogin();
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
if (GUI::askQuestion(tr("Deletion imminent!","deletion confirmation title"),
|
|
||||||
tr("Are you sure you want to delete this profile?","deletion confirmation text")))
|
|
||||||
{
|
|
||||||
QString profile = bodyUI->profiles->currentText();
|
|
||||||
QDir dir(Settings::getSettingsDirPath());
|
|
||||||
|
|
||||||
QFile::remove(dir.filePath(profile + Core::TOX_EXT));
|
|
||||||
QFile::remove(dir.filePath(profile + ".ini"));
|
|
||||||
QFile::remove(HistoryKeeper::getHistoryPath(profile, 0));
|
|
||||||
QFile::remove(HistoryKeeper::getHistoryPath(profile, 1));
|
|
||||||
|
|
||||||
bodyUI->profiles->removeItem(bodyUI->profiles->currentIndex());
|
|
||||||
bodyUI->profiles->setCurrentText(Settings::getInstance().getCurrentProfile());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProfileForm::onLogoutClicked()
|
void ProfileForm::onLogoutClicked()
|
||||||
|
|
|
@ -281,7 +281,7 @@
|
||||||
<bool>true</bool>
|
<bool>true</bool>
|
||||||
</property>
|
</property>
|
||||||
<property name="currentIndex">
|
<property name="currentIndex">
|
||||||
<number>1</number>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QWidget" name="newPage">
|
<widget class="QWidget" name="newPage">
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout_5">
|
<layout class="QHBoxLayout" name="horizontalLayout_5">
|
||||||
|
@ -394,7 +394,11 @@ margin-bottom:45px;</string>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLineEdit" name="newPassConfirm"/>
|
<widget class="QLineEdit" name="newPassConfirm">
|
||||||
|
<property name="echoMode">
|
||||||
|
<enum>QLineEdit::Password</enum>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<spacer name="verticalSpacer">
|
<spacer name="verticalSpacer">
|
||||||
|
|
Loading…
Reference in New Issue
Block a user