From 91f9a68249d33dba25a2763ea89e73a219f8ad67 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Sat, 29 Sep 2018 12:17:35 +0200 Subject: ProfileEditor plugin: fix delete button --- lib/web/profilemanager.cpp | 10 +++++++++- lib/web/profilemanager.h | 31 ++++++++++++++++++++++--------- 2 files changed, 31 insertions(+), 10 deletions(-) (limited to 'lib/web') diff --git a/lib/web/profilemanager.cpp b/lib/web/profilemanager.cpp index 960a03a..feaf347 100644 --- a/lib/web/profilemanager.cpp +++ b/lib/web/profilemanager.cpp @@ -90,6 +90,14 @@ WebProfile *ProfileManager::loadProfile(const QString &path) return m_profiles.at(id)->profile; } +void ProfileManager::deleteProfile(const QString &id) +{ + if(m_profiles.count(id) > 0) { + auto profileData = m_profiles.extract(id); + profileData.mapped()->deleteSelf = true; + } +} + QMenu *ProfileManager::createProfileMenu(std::function callback, QWidget *parent) const { QMenu *menu = new QMenu(parent); @@ -112,7 +120,7 @@ const QStringList ProfileManager::idList() const return ids; } -const QString ProfileManager::id(WebProfile *profile) const +const QString ProfileManager::id(const WebProfile *profile) const { for(auto it = m_profiles.cbegin(); it != m_profiles.cend(); ++it) { if(it->second->profile == profile) diff --git a/lib/web/profilemanager.h b/lib/web/profilemanager.h index 500f090..7e987a8 100644 --- a/lib/web/profilemanager.h +++ b/lib/web/profilemanager.h @@ -9,13 +9,16 @@ #ifndef SMOLBOTE_PROFILEMANAGER_H #define SMOLBOTE_PROFILEMANAGER_H -#include +#include "webprofile.h" +#include +#include #include +#include +#include #include +#include #include #include -#include -#include #define profileManager ProfileManager::instance() @@ -30,26 +33,36 @@ public: static ProfileManager *instance(); WebProfile *loadProfile(const QString &path); + void deleteProfile(const QString &id); QMenu *createProfileMenu(std::function callback, QWidget *parent = nullptr) const; const QStringList idList() const; - const QString id(WebProfile *profile) const; + const QString id(const WebProfile *profile) const; WebProfile *profile(const QString &id) const; const QString configurationPath(const QString &id) const; private: - struct ProfileData - { - ProfileData(const QString &path = QString()) : settings(path, QSettings::IniFormat) { + struct ProfileData { + explicit ProfileData(const QString &path = QString()) + : settings(path, QSettings::IniFormat) + { this->path = path; } - ~ProfileData() { - this->settings.sync(); + ~ProfileData() + { + if(!deleteSelf) + this->settings.sync(); + else { + QFile(path).remove(); + QDir(profile->persistentStoragePath()).removeRecursively(); + QDir(profile->cachePath()).removeRecursively(); + } } WebProfile *profile = nullptr; + bool deleteSelf = false; QSettings settings; QString path; }; -- cgit v1.2.1