Browse Source

feat(profile): add a dialog to indicate profile deletion error

This commit adds an error dialog box that pops up upon profile delete
error to inform users to manually delete files.
pull/3213/head
initramfs 9 years ago
parent
commit
78fd245e4c
No known key found for this signature in database
GPG Key ID: 78B8BDF87E9EF0AF
  1. 13
      src/persistence/profile.cpp
  2. 3
      src/persistence/profile.h
  3. 7
      src/widget/form/profileform.cpp

13
src/persistence/profile.cpp

@ -483,12 +483,12 @@ bool Profile::isEncrypted(QString name)
return tox_is_data_encrypted(data); return tox_is_data_encrypted(data);
} }
void Profile::remove() bool Profile::remove()
{ {
if (isRemoved) if (isRemoved)
{ {
qWarning() << "Profile " << name << " is already removed!"; qWarning() << "Profile " << name << " is already removed!";
return; return true;
} }
isRemoved = true; isRemoved = true;
@ -509,21 +509,27 @@ void 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;
if(!profileMain.remove() && profileMain.exists()) if(!profileMain.remove() && profileMain.exists())
{ {
isDeleted = false;
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;
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;
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;
qWarning() << "Could not remove file " << historyLegacyUnencrypted.fileName(); qWarning() << "Could not remove file " << historyLegacyUnencrypted.fileName();
} }
@ -531,10 +537,13 @@ void Profile::remove()
{ {
if(!history->remove() && QFile::exists(History::getDbPath(name))) if(!history->remove() && QFile::exists(History::getDbPath(name)))
{ {
isDeleted = false;
qWarning() << "Could not remove file " << History::getDbPath(name); qWarning() << "Could not remove file " << History::getDbPath(name);
} }
history.release(); history.release();
} }
return isDeleted;
} }
bool Profile::rename(QString newName) bool Profile::rename(QString newName)

3
src/persistence/profile.h

@ -78,7 +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
void remove(); /// Returns true if the underlying profile files were removed, false otherwise.
bool remove();
/// Tries to rename the profile /// Tries to rename the profile
bool rename(QString newName); bool rename(QString newName);

7
src/widget/form/profileform.cpp

@ -361,7 +361,12 @@ void ProfileForm::onDeleteClicked()
tr("Are you sure you want to delete this profile?", "deletion confirmation text"))) tr("Are you sure you want to delete this profile?", "deletion confirmation text")))
{ {
Nexus& nexus = Nexus::getInstance(); Nexus& nexus = Nexus::getInstance();
nexus.getProfile()->remove();
if(!nexus.getProfile()->remove())
{
GUI::showError(tr("Files could not be deleted!"), tr("Some files could not be deleted, please manually remove them."));
}
nexus.showLogin(); nexus.showLogin();
} }
} }

Loading…
Cancel
Save