1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 02:36:34 +01:00

AdBlockPlugin: Support unloading plugin

This commit is contained in:
David Rosca 2018-02-24 14:16:28 +01:00
parent 3984beda67
commit b86b385d98
No known key found for this signature in database
GPG Key ID: EBC3FC294452C6D8
2 changed files with 25 additions and 1 deletions

View File

@ -42,16 +42,27 @@ DesktopFile AdBlockPlugin::metaData() const
void AdBlockPlugin::init(InitState state, const QString &settingsPath)
{
Q_UNUSED(settingsPath)
Q_ASSERT(state == StartupInitState);
connect(mApp, &MainApplication::aboutToQuit, AdBlockManager::instance(), &AdBlockManager::save);
connect(mApp->plugins(), &PluginProxy::webPageCreated, this, &AdBlockPlugin::webPageCreated);
connect(mApp->plugins(), &PluginProxy::webPageDeleted, this, &AdBlockPlugin::webPageDeleted);
connect(mApp->plugins(), &PluginProxy::mainWindowCreated, this, &AdBlockPlugin::mainWindowCreated);
connect(mApp->plugins(), &PluginProxy::mainWindowDeleted, this, &AdBlockPlugin::mainWindowDeleted);
if (state == LateInitState) {
const auto windows = mApp->windows();
for (BrowserWindow *window : windows) {
mainWindowCreated(window);
}
}
}
void AdBlockPlugin::unload()
{
const auto windows = mApp->windows();
for (BrowserWindow *window : windows) {
mainWindowDeleted(window);
}
}
bool AdBlockPlugin::testPlugin()
@ -87,10 +98,19 @@ void AdBlockPlugin::webPageDeleted(WebPage *page)
void AdBlockPlugin::mainWindowCreated(BrowserWindow *window)
{
AdBlockIcon *icon = new AdBlockIcon(window);
m_icons[window] = icon;
window->statusBar()->addButton(icon);
window->navigationBar()->addToolButton(icon);
}
void AdBlockPlugin::mainWindowDeleted(BrowserWindow *window)
{
AdBlockIcon *icon = m_icons.take(window);
window->statusBar()->removeButton(icon);
window->navigationBar()->removeToolButton(icon);
delete icon;
}
bool AdBlockPlugin::acceptNavigationRequest(WebPage *page, const QUrl &url, QWebEnginePage::NavigationType type, bool isMainFrame)
{
Q_UNUSED(type)

View File

@ -22,6 +22,8 @@
class WebPage;
class BrowserWindow;
class AdBlockIcon;
class AdBlockPlugin : public QObject, public PluginInterface
{
Q_OBJECT
@ -39,6 +41,8 @@ private:
void webPageCreated(WebPage *page);
void webPageDeleted(WebPage *page);
void mainWindowCreated(BrowserWindow *window);
void mainWindowDeleted(BrowserWindow *window);
bool acceptNavigationRequest(WebPage *page, const QUrl &url, QWebEnginePage::NavigationType type, bool isMainFrame) override;
QHash<BrowserWindow*, AdBlockIcon*> m_icons;
};