1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 10:46:35 +01:00

Plugins: Fixed crash when unloading with settings dialog opened.

- also it is now possible to open only one settings dialog at time
This commit is contained in:
nowrep 2012-09-11 11:31:28 +02:00
parent 0704236d3e
commit 92b18f5466
16 changed files with 94 additions and 37 deletions

View File

@ -36,7 +36,7 @@ PluginSpec AKN_Plugin::pluginSpec()
spec.name = "Access Keys Navigation";
spec.info = "Access keys navigation for QupZilla";
spec.description = "Provides support for navigating in webpages by keyboard shortcuts";
spec.version = "0.4.1";
spec.version = "0.4.2";
spec.author = "David Rosca <nowrep@gmail.com>";
spec.icon = QPixmap(":/accesskeysnavigation/data/icon.png");
spec.hasSettings = true;
@ -53,6 +53,8 @@ void AKN_Plugin::init(const QString &sPath)
void AKN_Plugin::unload()
{
delete m_settings.data();
m_handler->deleteLater();
}
@ -72,10 +74,12 @@ QTranslator* AKN_Plugin::getTranslator(const QString &locale)
void AKN_Plugin::showSettings(QWidget* parent)
{
AKN_Settings* settings = new AKN_Settings(m_handler, parent);
settings->setAttribute(Qt::WA_DeleteOnClose);
if (!m_settings) {
m_settings = new AKN_Settings(m_handler, parent);
}
settings->show();
m_settings.data()->show();
m_settings.data()->raise();
}
bool AKN_Plugin::keyPress(const Qz::ObjectName &type, QObject* obj, QKeyEvent* event)

View File

@ -18,9 +18,12 @@
#ifndef AKN_PLUGIN_H
#define AKN_PLUGIN_H
#include <QWeakPointer>
#include "plugininterface.h"
class AKN_Handler;
class AKN_Settings;
class AKN_Plugin : public QObject, public PluginInterface
{
@ -41,6 +44,7 @@ public:
bool keyPress(const Qz::ObjectName &type, QObject* obj, QKeyEvent* event);
private:
QWeakPointer<AKN_Settings> m_settings;
AKN_Handler* m_handler;
};

View File

@ -30,6 +30,7 @@ AKN_Settings::AKN_Settings(AKN_Handler* handler, QWidget* parent)
, m_handler(handler)
, m_settingsFile(handler->settingsFile())
{
setAttribute(Qt::WA_DeleteOnClose);
ui->setupUi(this);
QSettings settings(m_settingsFile, QSettings::IniFormat);

View File

@ -40,8 +40,12 @@ GM_Manager::GM_Manager(const QString &sPath, QObject* parent)
void GM_Manager::showSettings(QWidget* parent)
{
GM_Settings settings(this, parent);
settings.exec();
if (!m_settings) {
m_settings = new GM_Settings(this, parent);
}
m_settings.data()->show();
m_settings.data()->raise();
}
void GM_Manager::downloadScript(const QNetworkRequest &request)
@ -81,11 +85,15 @@ QString GM_Manager::requireScripts(const QStringList &urlList) const
return script;
}
void GM_Manager::saveSettings()
void GM_Manager::unloadPlugin()
{
// Save settings
QSettings settings(m_settingsPath + "extensions.ini", QSettings::IniFormat);
settings.beginGroup("GreaseMonkey");
settings.setValue("disabledScripts", m_disabledScripts);
settings.endGroup();
delete m_settings.data();
}
QList<GM_Script*> GM_Manager::allScripts() const

View File

@ -20,11 +20,13 @@
#include <QObject>
#include <QStringList>
#include <QWeakPointer>
class QUrl;
class QNetworkRequest;
class GM_Script;
class GM_Settings;
class GM_Manager : public QObject
{
@ -39,7 +41,7 @@ public:
QString scriptsDirectory() const;
QString requireScripts(const QStringList &urlList) const;
void saveSettings();
void unloadPlugin();
QList<GM_Script*> allScripts() const;
bool containsScript(const QString &fullName) const;
@ -66,6 +68,7 @@ private slots:
private:
QString m_settingsPath;
QString m_bootstrap;
QWeakPointer<GM_Settings> m_settings;
QStringList m_disabledScripts;
QList<GM_Script*> m_endScripts;

View File

@ -38,7 +38,7 @@ PluginSpec GM_Plugin::pluginSpec()
spec.name = "GreaseMonkey";
spec.info = "Userscripts for QupZilla";
spec.description = "Provides support for userscripts (www.userscripts.org)";
spec.version = "0.2.2";
spec.version = "0.2.3";
spec.author = "David Rosca <nowrep@gmail.com>";
spec.icon = QPixmap(":gm/data/icon.png");
spec.hasSettings = true;
@ -56,7 +56,7 @@ void GM_Plugin::init(const QString &sPath)
void GM_Plugin::unload()
{
m_manager->saveSettings();
m_manager->unloadPlugin();
delete m_manager;
}

View File

@ -31,6 +31,7 @@ GM_Settings::GM_Settings(GM_Manager* manager, QWidget* parent)
, ui(new Ui::GM_Settings)
, m_manager(manager)
{
setAttribute(Qt::WA_DeleteOnClose);
ui->setupUi(this);
connect(ui->listWidget, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(showItemInfo(QListWidgetItem*)));

View File

@ -107,8 +107,17 @@ bool MouseGestures::mouseMove(QObject* obj, QMouseEvent* event)
void MouseGestures::showSettings(QWidget* parent)
{
MouseGesturesSettingsDialog* d = new MouseGesturesSettingsDialog(parent);
d->show();
if (!m_settings) {
m_settings = new MouseGesturesSettingsDialog(parent);
}
m_settings.data()->show();
m_settings.data()->raise();
}
void MouseGestures::unloadPlugin()
{
delete m_settings.data();
}
void MouseGestures::upGestured()
@ -192,7 +201,7 @@ void MouseGestures::upLeftGestured()
}
if (QApplication::isRightToLeft()) {
view->tabWidget()->nextTab();
view->tabWidget()->nextTab();
}
else {
view->tabWidget()->previousTab();
@ -210,7 +219,7 @@ void MouseGestures::upRightGestured()
view->tabWidget()->previousTab();
}
else {
view->tabWidget()->nextTab();
view->tabWidget()->nextTab();
}
}

View File

@ -25,6 +25,7 @@ class QMouseEvent;
class WebView;
class QjtMouseGestureFilter;
class MouseGesturesSettingsDialog;
class MouseGestures : public QObject
{
@ -38,6 +39,7 @@ public:
bool mouseMove(QObject* obj, QMouseEvent* event);
void showSettings(QWidget* parent);
void unloadPlugin();
private slots:
void upGestured();
@ -54,8 +56,8 @@ private slots:
private:
QjtMouseGestureFilter* m_filter;
QWeakPointer<MouseGesturesSettingsDialog> m_settings;
QWeakPointer<WebView> m_view;
};
#endif // MOUSEGESTURES_H

View File

@ -35,7 +35,7 @@ PluginSpec MouseGesturesPlugin::pluginSpec()
spec.name = "Mouse Gestures";
spec.info = "Mouse gestures for QupZilla";
spec.description = "Provides support for navigating in webpages by mouse gestures";
spec.version = "0.3.2";
spec.version = "0.3.3";
spec.author = "David Rosca <nowrep@gmail.com>";
spec.icon = QPixmap(":/mousegestures/data/icon.png");
spec.hasSettings = true;
@ -56,6 +56,7 @@ void MouseGesturesPlugin::init(const QString &sPath)
void MouseGesturesPlugin::unload()
{
m_gestures->unloadPlugin();
m_gestures->deleteLater();
}
@ -78,7 +79,6 @@ void MouseGesturesPlugin::showSettings(QWidget* parent)
m_gestures->showSettings(parent);
}
bool MouseGesturesPlugin::mousePress(const Qz::ObjectName &type, QObject* obj, QMouseEvent* event)
{
if (type == Qz::ON_WebView) {

View File

@ -25,6 +25,7 @@ MouseGesturesSettingsDialog::MouseGesturesSettingsDialog(QWidget* parent)
: QDialog(parent)
, ui(new Ui::MouseGesturesSettingsDialog)
{
setAttribute(Qt::WA_DeleteOnClose);
ui->setupUi(this);
if (QApplication::isRightToLeft()) {

View File

@ -89,10 +89,14 @@ void PIM_Handler::loadSettings()
void PIM_Handler::showSettings(QWidget* parent)
{
PIM_Settings* settings = new PIM_Settings(m_settingsFile, parent);
settings->show();
if (!m_settings) {
m_settings = new PIM_Settings(m_settingsFile, parent);
connect(settings, SIGNAL(accepted()), this, SLOT(loadSettings()));
connect(m_settings.data(), SIGNAL(accepted()), this, SLOT(loadSettings()));
}
m_settings.data()->show();
m_settings.data()->raise();
}
void PIM_Handler::populateWebViewMenu(QMenu* menu, WebView* view, const QWebHitTestResult &hitTest)
@ -159,6 +163,11 @@ bool PIM_Handler::keyPress(WebView* view, QKeyEvent* event)
return true;
}
void PIM_Handler::unloadPlugin()
{
delete m_settings.data();
}
void PIM_Handler::webPageCreated(WebPage* page)
{
connect(page, SIGNAL(loadFinished(bool)), this, SLOT(pageLoadFinished()));

View File

@ -30,6 +30,8 @@
class WebView;
class WebPage;
class PIM_Settings;
class PIM_Handler : public QObject
{
Q_OBJECT
@ -39,6 +41,8 @@ public:
void populateWebViewMenu(QMenu* menu, WebView* view, const QWebHitTestResult &hitTest);
bool keyPress(WebView* view, QKeyEvent* event);
void unloadPlugin();
signals:
public slots:
@ -77,6 +81,7 @@ private:
QHash<PI_Type, QStringList> m_infoMatches;
QHash<PI_Type, QString> m_translations;
QWeakPointer<PIM_Settings> m_settings;
QWeakPointer<WebView> m_view;
QWebElement m_element;

View File

@ -38,7 +38,7 @@ PluginSpec PIM_Plugin::pluginSpec()
spec.name = "PIM";
spec.info = "Personal Information Manager";
spec.description = "Adds ability for Qupzilla to store some personal data";
spec.version = "0.1.1";
spec.version = "0.1.2";
spec.author = QString::fromUtf8("Mladen Pejaković <pejakm@gmail.com>");
spec.icon = QPixmap(":/PIM/data/PIM.png");
spec.hasSettings = true;
@ -57,6 +57,7 @@ void PIM_Plugin::init(const QString &sPath)
void PIM_Plugin::unload()
{
m_handler->unloadPlugin();
m_handler->deleteLater();
}

View File

@ -43,7 +43,7 @@ PluginSpec TestPlugin::pluginSpec()
spec.name = "Example Plugin";
spec.info = "Example minimal plugin";
spec.description = "Very simple minimal plugin example";
spec.version = "0.1.5";
spec.version = "0.1.6";
spec.author = "David Rosca <nowrep@gmail.com>";
spec.icon = QPixmap(":qupzilla.png");
spec.hasSettings = true;
@ -81,6 +81,9 @@ void TestPlugin::unload()
// Removing sidebar from application
SideBarManager::removeSidebar("testplugin-sidebar");
// Deleting settings dialog if opened
delete m_settings.data();
}
bool TestPlugin::testPlugin()
@ -107,24 +110,27 @@ void TestPlugin::showSettings(QWidget* parent)
// This function will be called from Preferences after clicking on Settings button.
// Settings button will be enabled if PluginSpec.hasSettings == true
QDialog* dialog = new QDialog(parent);
QPushButton* b = new QPushButton("Example Plugin v0.0.1");
QPushButton* closeButton = new QPushButton(tr("Close"));
QLabel* label = new QLabel();
label->setPixmap(QPixmap(":icons/other/about.png"));
if (!m_settings) {
m_settings = new QDialog(parent);
QPushButton* b = new QPushButton("Example Plugin v0.0.1");
QPushButton* closeButton = new QPushButton(tr("Close"));
QLabel* label = new QLabel();
label->setPixmap(QPixmap(":icons/other/about.png"));
QVBoxLayout* l = new QVBoxLayout(dialog);
l->addWidget(label);
l->addWidget(b);
l->addWidget(closeButton);
dialog->setLayout(l);
QVBoxLayout* l = new QVBoxLayout(m_settings.data());
l->addWidget(label);
l->addWidget(b);
l->addWidget(closeButton);
m_settings.data()->setLayout(l);
dialog->setAttribute(Qt::WA_DeleteOnClose);
dialog->setWindowTitle(tr("Example Plugin Settings"));
dialog->setWindowIcon(QIcon(":qupzilla.png"));
connect(closeButton, SIGNAL(clicked()), dialog, SLOT(close()));
m_settings.data()->setAttribute(Qt::WA_DeleteOnClose);
m_settings.data()->setWindowTitle(tr("Example Plugin Settings"));
m_settings.data()->setWindowIcon(QIcon(":qupzilla.png"));
connect(closeButton, SIGNAL(clicked()), m_settings.data(), SLOT(close()));
}
dialog->show();
m_settings.data()->show();
m_settings.data()->raise();
}
void TestPlugin::populateWebViewMenu(QMenu* menu, WebView* view, const QWebHitTestResult &r)

View File

@ -31,6 +31,7 @@
#include <QMessageBox>
#include <QWebElement>
#include <QVBoxLayout>
#include <QWeakPointer>
class TestPlugin : public QObject, public PluginInterface
{
@ -56,6 +57,8 @@ private slots:
void actionSlot();
private:
QWeakPointer<QDialog> m_settings;
WebView* m_view;
QString m_settingsPath;
};