From 1dabbca94c172bf21f83e23400ef99e5be45c084 Mon Sep 17 00:00:00 2001 From: initramfs Date: Wed, 27 Apr 2016 10:44:52 +0800 Subject: [PATCH 1/3] feat(profile): show warning on failure to delete profile Adds a few qWarning() statements when files fail to delete. --- src/persistence/history.cpp | 4 ++-- src/persistence/history.h | 6 +++--- src/persistence/profile.cpp | 36 +++++++++++++++++++++++++++++------- 3 files changed, 34 insertions(+), 12 deletions(-) diff --git a/src/persistence/history.cpp b/src/persistence/history.cpp index 48864b567..7d395d48f 100644 --- a/src/persistence/history.cpp +++ b/src/persistence/history.cpp @@ -42,9 +42,9 @@ void History::rename(const QString &newName) db.rename(getDbPath(newName)); } -void History::remove() +bool History::remove() { - db.remove(); + return db.remove(); } void History::eraseHistory() diff --git a/src/persistence/history.h b/src/persistence/history.h index e2929aa2d..0b49e932e 100644 --- a/src/persistence/history.h +++ b/src/persistence/history.h @@ -47,7 +47,7 @@ public: /// Moves the database file on disk to match the new name void rename(const QString& newName); /// Deletes the on-disk database file - void remove(); + bool remove(); /// Erases all the chat history from the database void eraseHistory(); @@ -61,11 +61,11 @@ public: QList getChatHistory(const QString& friendPk, const QDateTime &from, const QDateTime &to); /// Marks a message as sent, removing it from the faux-offline pending messages list void markAsSent(qint64 id); - + /// Retrieves the path to the database file for a given profile. + static QString getDbPath(const QString& profileName); protected: /// Makes sure the history tables are created void init(); - static QString getDbPath(const QString& profileName); QVector generateNewMessageQueries(const QString& friendPk, const QString& message, const QString& sender, const QDateTime &time, bool isSent, QString dispName, std::function insertIdCallback={}); diff --git a/src/persistence/profile.cpp b/src/persistence/profile.cpp index d9c7077c2..f4ab23988 100644 --- a/src/persistence/profile.cpp +++ b/src/persistence/profile.cpp @@ -487,12 +487,12 @@ void Profile::remove() { if (isRemoved) { - qWarning() << "Profile "<remove(); + if(!history->remove() && QFile::exists(History::getDbPath(name))) + { + qWarning() << "Could not remove file " << History::getDbPath(name); + } history.release(); } } From 78fd245e4cb0a73570b5d6a24d612ac099dd16ef Mon Sep 17 00:00:00 2001 From: initramfs Date: Fri, 29 Apr 2016 13:38:15 +0800 Subject: [PATCH 2/3] 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. --- src/persistence/profile.cpp | 13 +++++++++++-- src/persistence/profile.h | 3 ++- src/widget/form/profileform.cpp | 7 ++++++- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/persistence/profile.cpp b/src/persistence/profile.cpp index f4ab23988..5189955bc 100644 --- a/src/persistence/profile.cpp +++ b/src/persistence/profile.cpp @@ -483,12 +483,12 @@ bool Profile::isEncrypted(QString name) return tox_is_data_encrypted(data); } -void Profile::remove() +bool Profile::remove() { if (isRemoved) { qWarning() << "Profile " << name << " is already removed!"; - return; + return true; } isRemoved = true; @@ -509,21 +509,27 @@ void Profile::remove() QFile historyLegacyUnencrypted {HistoryKeeper::getHistoryPath(name, 0)}; QFile historyLegacyEncrypted {HistoryKeeper::getHistoryPath(name, 1)}; + bool isDeleted = true; + if(!profileMain.remove() && profileMain.exists()) { + isDeleted = false; qWarning() << "Could not remove file " << profileMain.fileName(); } if(!profileConfig.remove() && profileConfig.exists()) { + isDeleted = false; qWarning() << "Could not remove file " << profileConfig.fileName(); } if(!historyLegacyUnencrypted.remove() && historyLegacyUnencrypted.exists()) { + isDeleted = false; qWarning() << "Could not remove file " << historyLegacyUnencrypted.fileName(); } if(!historyLegacyEncrypted.remove() && historyLegacyEncrypted.exists()) { + isDeleted = false; qWarning() << "Could not remove file " << historyLegacyUnencrypted.fileName(); } @@ -531,10 +537,13 @@ void Profile::remove() { if(!history->remove() && QFile::exists(History::getDbPath(name))) { + isDeleted = false; qWarning() << "Could not remove file " << History::getDbPath(name); } history.release(); } + + return isDeleted; } bool Profile::rename(QString newName) diff --git a/src/persistence/profile.h b/src/persistence/profile.h index 0fa295d1a..971134f16 100644 --- a/src/persistence/profile.h +++ b/src/persistence/profile.h @@ -78,7 +78,8 @@ public: /// Removes the profile permanently /// It is invalid to call loadToxSave or saveToxSave on a deleted profile /// Updates the profiles vector - void remove(); + /// Returns true if the underlying profile files were removed, false otherwise. + bool remove(); /// Tries to rename the profile bool rename(QString newName); diff --git a/src/widget/form/profileform.cpp b/src/widget/form/profileform.cpp index 4e5d83dad..24a981961 100644 --- a/src/widget/form/profileform.cpp +++ b/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"))) { 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(); } } From 56e15aeab1a72bd637fbd5649b2a0a72bd3f5dcc Mon Sep 17 00:00:00 2001 From: initramfs Date: Sat, 30 Apr 2016 05:10:21 +0800 Subject: [PATCH 3/3] refactor(profile): display files that could not be deleted in prompt --- src/persistence/profile.cpp | 18 +++++++++--------- src/persistence/profile.h | 4 ++-- src/widget/form/profileform.cpp | 15 +++++++++++++-- 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/src/persistence/profile.cpp b/src/persistence/profile.cpp index 5189955bc..babf0c8b6 100644 --- a/src/persistence/profile.cpp +++ b/src/persistence/profile.cpp @@ -483,12 +483,12 @@ bool Profile::isEncrypted(QString name) return tox_is_data_encrypted(data); } -bool Profile::remove() +QVector Profile::remove() { if (isRemoved) { qWarning() << "Profile " << name << " is already removed!"; - return true; + return {}; } isRemoved = true; @@ -509,27 +509,27 @@ bool Profile::remove() QFile historyLegacyUnencrypted {HistoryKeeper::getHistoryPath(name, 0)}; QFile historyLegacyEncrypted {HistoryKeeper::getHistoryPath(name, 1)}; - bool isDeleted = true; + QVector ret; if(!profileMain.remove() && profileMain.exists()) { - isDeleted = false; + ret.push_back(profileMain.fileName()); qWarning() << "Could not remove file " << profileMain.fileName(); } if(!profileConfig.remove() && profileConfig.exists()) { - isDeleted = false; + ret.push_back(profileConfig.fileName()); qWarning() << "Could not remove file " << profileConfig.fileName(); } if(!historyLegacyUnencrypted.remove() && historyLegacyUnencrypted.exists()) { - isDeleted = false; + ret.push_back(historyLegacyUnencrypted.fileName()); qWarning() << "Could not remove file " << historyLegacyUnencrypted.fileName(); } if(!historyLegacyEncrypted.remove() && historyLegacyEncrypted.exists()) { - isDeleted = false; + ret.push_back(historyLegacyEncrypted.fileName()); qWarning() << "Could not remove file " << historyLegacyUnencrypted.fileName(); } @@ -537,13 +537,13 @@ bool Profile::remove() { if(!history->remove() && QFile::exists(History::getDbPath(name))) { - isDeleted = false; + ret.push_back(History::getDbPath(name)); qWarning() << "Could not remove file " << History::getDbPath(name); } history.release(); } - return isDeleted; + return ret; } bool Profile::rename(QString newName) diff --git a/src/persistence/profile.h b/src/persistence/profile.h index 971134f16..f02a5a1d1 100644 --- a/src/persistence/profile.h +++ b/src/persistence/profile.h @@ -78,8 +78,8 @@ public: /// Removes the profile permanently /// It is invalid to call loadToxSave or saveToxSave on a deleted profile /// Updates the profiles vector - /// Returns true if the underlying profile files were removed, false otherwise. - bool remove(); + /// Returns a vector of filenames that could not be removed. + QVector remove(); /// Tries to rename the profile bool rename(QString newName); diff --git a/src/widget/form/profileform.cpp b/src/widget/form/profileform.cpp index 24a981961..18f0824f8 100644 --- a/src/widget/form/profileform.cpp +++ b/src/widget/form/profileform.cpp @@ -362,9 +362,20 @@ void ProfileForm::onDeleteClicked() { Nexus& nexus = Nexus::getInstance(); - if(!nexus.getProfile()->remove()) + QVector 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();