aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/web/profilemanager.cpp10
-rw-r--r--lib/web/profilemanager.h31
-rw-r--r--plugins/ProfileEditor/forms/profilemanagerdialog.cpp6
-rw-r--r--plugins/ProfileEditor/forms/profilemanagerdialog.h4
-rw-r--r--plugins/ProfileEditor/profileeditorplugin.cpp6
-rw-r--r--plugins/interfaces.h2
-rw-r--r--src/browser.cpp4
-rw-r--r--src/browser.h2
8 files changed, 44 insertions, 21 deletions
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<void(WebProfile *)> 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 <QObject>
+#include "webprofile.h"
+#include <QDir>
+#include <QFile>
#include <QMap>
+#include <QMenu>
+#include <QObject>
#include <QSettings>
+#include <functional>
#include <map>
#include <memory>
-#include <functional>
-#include <QMenu>
#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<void(WebProfile *)> 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;
};
diff --git a/plugins/ProfileEditor/forms/profilemanagerdialog.cpp b/plugins/ProfileEditor/forms/profilemanagerdialog.cpp
index 72c56de..d660514 100644
--- a/plugins/ProfileEditor/forms/profilemanagerdialog.cpp
+++ b/plugins/ProfileEditor/forms/profilemanagerdialog.cpp
@@ -84,11 +84,7 @@ void ProfileManagerDialog::deleteProfile(QListWidgetItem *item)
auto profile = item->data(Qt::UserRole).value<QPointer<WebProfile>>();
Q_ASSERT(!profile.isNull());
- qDebug("deleting profile %s", qUtf8Printable(profile->name()));
- //qDebug("deleting %s: %s", qUtf8Printable(profile->configurationPath()), QFile(profile->configurationPath()).remove() ? "okay" : "failed");
- qDebug("deleting %s: %s", qUtf8Printable(profile->persistentStoragePath()), QDir(profile->persistentStoragePath()).removeRecursively() ? "okay" : "failed");
- qDebug("deleting %s: %s", qUtf8Printable(profile->cachePath()), QDir(profile->cachePath()).removeRecursively() ? "okay" : "failed");
+ emit removeProfile(profile);
delete item;
- delete profile.data();
}
diff --git a/plugins/ProfileEditor/forms/profilemanagerdialog.h b/plugins/ProfileEditor/forms/profilemanagerdialog.h
index ce38777..89e959a 100644
--- a/plugins/ProfileEditor/forms/profilemanagerdialog.h
+++ b/plugins/ProfileEditor/forms/profilemanagerdialog.h
@@ -18,11 +18,11 @@ class ProfileManagerDialog : public QDialog
public:
explicit ProfileManagerDialog(const ProfileManager *profiles, QWidget *parent = 0);
- ~ProfileManagerDialog();
+ ~ProfileManagerDialog() override;
signals:
void createProfile(const QString &id);
- void updateProfile(const QString &id);
+ void removeProfile(const WebProfile *profile);
public slots:
void addProfile(WebProfile *profile);
diff --git a/plugins/ProfileEditor/profileeditorplugin.cpp b/plugins/ProfileEditor/profileeditorplugin.cpp
index b158d6b..dcdd320 100644
--- a/plugins/ProfileEditor/profileeditorplugin.cpp
+++ b/plugins/ProfileEditor/profileeditorplugin.cpp
@@ -33,5 +33,11 @@ QDialog *ProfileEditorPlugin::createWidget(QWidget *parent)
auto newProfile = browser->loadProfile(id);
widget->addProfile(newProfile.second);
});
+
+ connect(widget, &ProfileManagerDialog::removeProfile, this, [this](const WebProfile *profile) {
+ const QString id = browser->getProfileManager()->id(profile);
+ browser->getProfileManager()->deleteProfile(id);
+ });
+
return widget;
}
diff --git a/plugins/interfaces.h b/plugins/interfaces.h
index 681a79e..b7c4091 100644
--- a/plugins/interfaces.h
+++ b/plugins/interfaces.h
@@ -27,7 +27,7 @@ public:
virtual Configuration *getConfiguration() const = 0;
virtual QPair<QString, WebProfile *> loadProfile(const QString &id) = 0;
- virtual const ProfileManager *getProfileManager() const = 0;
+ virtual ProfileManager *getProfileManager() = 0;
};
struct Plugin
diff --git a/src/browser.cpp b/src/browser.cpp
index ff78d0d..6cdfdab 100644
--- a/src/browser.cpp
+++ b/src/browser.cpp
@@ -74,9 +74,9 @@ Configuration *Browser::getConfiguration() const
return m_config.get();
}
-const ProfileManager *Browser::getProfileManager() const
+ProfileManager *Browser::getProfileManager()
{
- return const_cast<ProfileManager *>(ProfileManager::instance());
+ return ProfileManager::instance();
}
void Browser::registerPlugin(const Plugin &plugin)
diff --git a/src/browser.h b/src/browser.h
index 0547168..007b0a1 100644
--- a/src/browser.h
+++ b/src/browser.h
@@ -40,7 +40,7 @@ public:
// interface
Configuration *getConfiguration() const override;
- const ProfileManager *getProfileManager() const override;
+ ProfileManager *getProfileManager() override;
QPair<QString, WebProfile *> loadProfile(const QString &id) override;
void setConfiguration(std::unique_ptr<Configuration> &config);