mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
refactor(profile): display files that could not be deleted in prompt
This commit is contained in:
parent
78fd245e4c
commit
56e15aeab1
|
@ -483,12 +483,12 @@ bool Profile::isEncrypted(QString name)
|
||||||
return tox_is_data_encrypted(data);
|
return tox_is_data_encrypted(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Profile::remove()
|
QVector<QString> Profile::remove()
|
||||||
{
|
{
|
||||||
if (isRemoved)
|
if (isRemoved)
|
||||||
{
|
{
|
||||||
qWarning() << "Profile " << name << " is already removed!";
|
qWarning() << "Profile " << name << " is already removed!";
|
||||||
return true;
|
return {};
|
||||||
}
|
}
|
||||||
isRemoved = true;
|
isRemoved = true;
|
||||||
|
|
||||||
|
@ -509,27 +509,27 @@ bool Profile::remove()
|
||||||
QFile historyLegacyUnencrypted {HistoryKeeper::getHistoryPath(name, 0)};
|
QFile historyLegacyUnencrypted {HistoryKeeper::getHistoryPath(name, 0)};
|
||||||
QFile historyLegacyEncrypted {HistoryKeeper::getHistoryPath(name, 1)};
|
QFile historyLegacyEncrypted {HistoryKeeper::getHistoryPath(name, 1)};
|
||||||
|
|
||||||
bool isDeleted = true;
|
QVector<QString> ret;
|
||||||
|
|
||||||
if(!profileMain.remove() && profileMain.exists())
|
if(!profileMain.remove() && profileMain.exists())
|
||||||
{
|
{
|
||||||
isDeleted = false;
|
ret.push_back(profileMain.fileName());
|
||||||
qWarning() << "Could not remove file " << profileMain.fileName();
|
qWarning() << "Could not remove file " << profileMain.fileName();
|
||||||
}
|
}
|
||||||
if(!profileConfig.remove() && profileConfig.exists())
|
if(!profileConfig.remove() && profileConfig.exists())
|
||||||
{
|
{
|
||||||
isDeleted = false;
|
ret.push_back(profileConfig.fileName());
|
||||||
qWarning() << "Could not remove file " << profileConfig.fileName();
|
qWarning() << "Could not remove file " << profileConfig.fileName();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!historyLegacyUnencrypted.remove() && historyLegacyUnencrypted.exists())
|
if(!historyLegacyUnencrypted.remove() && historyLegacyUnencrypted.exists())
|
||||||
{
|
{
|
||||||
isDeleted = false;
|
ret.push_back(historyLegacyUnencrypted.fileName());
|
||||||
qWarning() << "Could not remove file " << historyLegacyUnencrypted.fileName();
|
qWarning() << "Could not remove file " << historyLegacyUnencrypted.fileName();
|
||||||
}
|
}
|
||||||
if(!historyLegacyEncrypted.remove() && historyLegacyEncrypted.exists())
|
if(!historyLegacyEncrypted.remove() && historyLegacyEncrypted.exists())
|
||||||
{
|
{
|
||||||
isDeleted = false;
|
ret.push_back(historyLegacyEncrypted.fileName());
|
||||||
qWarning() << "Could not remove file " << historyLegacyUnencrypted.fileName();
|
qWarning() << "Could not remove file " << historyLegacyUnencrypted.fileName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -537,13 +537,13 @@ bool Profile::remove()
|
||||||
{
|
{
|
||||||
if(!history->remove() && QFile::exists(History::getDbPath(name)))
|
if(!history->remove() && QFile::exists(History::getDbPath(name)))
|
||||||
{
|
{
|
||||||
isDeleted = false;
|
ret.push_back(History::getDbPath(name));
|
||||||
qWarning() << "Could not remove file " << History::getDbPath(name);
|
qWarning() << "Could not remove file " << History::getDbPath(name);
|
||||||
}
|
}
|
||||||
history.release();
|
history.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
return isDeleted;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Profile::rename(QString newName)
|
bool Profile::rename(QString newName)
|
||||||
|
|
|
@ -78,8 +78,8 @@ public:
|
||||||
/// Removes the profile permanently
|
/// Removes the profile permanently
|
||||||
/// It is invalid to call loadToxSave or saveToxSave on a deleted profile
|
/// It is invalid to call loadToxSave or saveToxSave on a deleted profile
|
||||||
/// Updates the profiles vector
|
/// Updates the profiles vector
|
||||||
/// Returns true if the underlying profile files were removed, false otherwise.
|
/// Returns a vector of filenames that could not be removed.
|
||||||
bool remove();
|
QVector<QString> remove();
|
||||||
|
|
||||||
/// Tries to rename the profile
|
/// Tries to rename the profile
|
||||||
bool rename(QString newName);
|
bool rename(QString newName);
|
||||||
|
|
|
@ -362,9 +362,20 @@ void ProfileForm::onDeleteClicked()
|
||||||
{
|
{
|
||||||
Nexus& nexus = Nexus::getInstance();
|
Nexus& nexus = Nexus::getInstance();
|
||||||
|
|
||||||
if(!nexus.getProfile()->remove())
|
QVector<QString> manualDeleteFiles = nexus.getProfile()->remove();
|
||||||
|
|
||||||
|
if(!manualDeleteFiles.empty())
|
||||||
{
|
{
|
||||||
GUI::showError(tr("Files could not be deleted!"), tr("Some files could not be deleted, please manually remove them."));
|
QString message = tr("The following files could not be deleted:", "deletion failed text part 1") + "\n\n";
|
||||||
|
|
||||||
|
for(auto& file : manualDeleteFiles)
|
||||||
|
{
|
||||||
|
message = message + file + "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
message = message + "\n" + tr("Please manually remove them.", "deletion failed text part 2");
|
||||||
|
|
||||||
|
GUI::showError(tr("Files could not be deleted!", "deletion failed title"), message);
|
||||||
}
|
}
|
||||||
|
|
||||||
nexus.showLogin();
|
nexus.showLogin();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user