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..babf0c8b6 100644 --- a/src/persistence/profile.cpp +++ b/src/persistence/profile.cpp @@ -483,16 +483,16 @@ bool Profile::isEncrypted(QString name) return tox_is_data_encrypted(data); } -void Profile::remove() +QVector Profile::remove() { if (isRemoved) { - qWarning() << "Profile "< ret; + + if(!profileMain.remove() && profileMain.exists()) + { + ret.push_back(profileMain.fileName()); + qWarning() << "Could not remove file " << profileMain.fileName(); + } + if(!profileConfig.remove() && profileConfig.exists()) + { + ret.push_back(profileConfig.fileName()); + qWarning() << "Could not remove file " << profileConfig.fileName(); + } + + if(!historyLegacyUnencrypted.remove() && historyLegacyUnencrypted.exists()) + { + ret.push_back(historyLegacyUnencrypted.fileName()); + qWarning() << "Could not remove file " << historyLegacyUnencrypted.fileName(); + } + if(!historyLegacyEncrypted.remove() && historyLegacyEncrypted.exists()) + { + ret.push_back(historyLegacyEncrypted.fileName()); + qWarning() << "Could not remove file " << historyLegacyUnencrypted.fileName(); + } + if (history) { - history->remove(); + if(!history->remove() && QFile::exists(History::getDbPath(name))) + { + ret.push_back(History::getDbPath(name)); + qWarning() << "Could not remove file " << History::getDbPath(name); + } history.release(); } + + return ret; } bool Profile::rename(QString newName) diff --git a/src/persistence/profile.h b/src/persistence/profile.h index 0fa295d1a..f02a5a1d1 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 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 4e5d83dad..18f0824f8 100644 --- a/src/widget/form/profileform.cpp +++ b/src/widget/form/profileform.cpp @@ -361,7 +361,23 @@ void ProfileForm::onDeleteClicked() tr("Are you sure you want to delete this profile?", "deletion confirmation text"))) { Nexus& nexus = Nexus::getInstance(); - nexus.getProfile()->remove(); + + QVector manualDeleteFiles = nexus.getProfile()->remove(); + + if(!manualDeleteFiles.empty()) + { + 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(); } }