1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

Merge pull request #3213

initramfs (3):
      feat(profile): show warning on failure to delete profile
      feat(profile): add a dialog to indicate profile deletion error
      refactor(profile): display files that could not be deleted in prompt
This commit is contained in:
sudden6 2016-04-30 21:06:56 +02:00
commit 4432ab6398
No known key found for this signature in database
GPG Key ID: 279509B499E032B9
5 changed files with 64 additions and 16 deletions

View File

@ -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()

View File

@ -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<HistMessage> 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<RawDatabase::Query> generateNewMessageQueries(const QString& friendPk, const QString& message,
const QString& sender, const QDateTime &time, bool isSent, QString dispName,
std::function<void(int64_t)> insertIdCallback={});

View File

@ -483,16 +483,16 @@ bool Profile::isEncrypted(QString name)
return tox_is_data_encrypted(data);
}
void Profile::remove()
QVector<QString> Profile::remove()
{
if (isRemoved)
{
qWarning() << "Profile "<<name<<" is already removed!";
return;
qWarning() << "Profile " << name << " is already removed!";
return {};
}
isRemoved = true;
qDebug() << "Removing profile"<<name;
qDebug() << "Removing profile" << name;
for (int i=0; i<profiles.size(); i++)
{
if (profiles[i] == name)
@ -503,16 +503,47 @@ void Profile::remove()
}
QString path = Settings::getInstance().getSettingsDirPath() + name;
ProfileLocker::unlock();
QFile::remove(path+".tox");
QFile::remove(path+".ini");
QFile::remove(HistoryKeeper::getHistoryPath(name, 0));
QFile::remove(HistoryKeeper::getHistoryPath(name, 1));
QFile profileMain {path + ".tox"};
QFile profileConfig {path + ".ini"};
QFile historyLegacyUnencrypted {HistoryKeeper::getHistoryPath(name, 0)};
QFile historyLegacyEncrypted {HistoryKeeper::getHistoryPath(name, 1)};
QVector<QString> 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)

View File

@ -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<QString> remove();
/// Tries to rename the profile
bool rename(QString newName);

View File

@ -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<QString> 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();
}
}