From cc55c0ad02708c577146d317ba132ff9de3cd61d Mon Sep 17 00:00:00 2001 From: David Rosca Date: Wed, 24 Jan 2018 20:30:55 +0100 Subject: [PATCH] FlashCookieManager: Port icon to AbstractButtonInterface It is now available from both NavigationBar and StatusBar --- src/plugins/FlashCookieManager/fcm_plugin.cpp | 44 ++++++++++++++----- src/plugins/FlashCookieManager/fcm_plugin.h | 6 ++- 2 files changed, 36 insertions(+), 14 deletions(-) diff --git a/src/plugins/FlashCookieManager/fcm_plugin.cpp b/src/plugins/FlashCookieManager/fcm_plugin.cpp index ab6f7283b..d8495aa75 100644 --- a/src/plugins/FlashCookieManager/fcm_plugin.cpp +++ b/src/plugins/FlashCookieManager/fcm_plugin.cpp @@ -21,12 +21,13 @@ #include "pluginproxy.h" #include "mainapplication.h" #include "fcm_dialog.h" -#include "clickablelabel.h" +#include "abstractbuttoninterface.h" #include "tabbedwebview.h" #include "fcm_notification.h" #include "datapaths.h" #include "../config.h" #include "statusbar.h" +#include "navigationbar.h" #include #include @@ -40,6 +41,25 @@ const int refreshInterval = 60 * 1000; +class FCM_Button : public AbstractButtonInterface +{ +public: + explicit FCM_Button(QObject *parent = nullptr) + : AbstractButtonInterface(parent) + { + } + + QString id() const override + { + return QSL("fcm-icon"); + } + + QString name() const override + { + return tr("Flash Cookie Manager button"); + } +}; + FCM_Plugin::FCM_Plugin() : QObject() { @@ -97,9 +117,7 @@ void FCM_Plugin::unload() } foreach (BrowserWindow* window, mApp->windows()) { - window->statusBar()->removeWidget(m_statusBarIcons.value(window)); - delete m_statusBarIcons.value(window); - m_statusBarIcons.remove(window); + mainWindowDeleted(window); } delete m_fcmDialog; @@ -312,7 +330,8 @@ void FCM_Plugin::showFlashCookieManager() void FCM_Plugin::mainWindowCreated(BrowserWindow *window) { - window->statusBar()->addPermanentWidget(createStatusBarIcon(window)); + window->statusBar()->addButton(createStatusBarIcon(window)); + window->navigationBar()->addToolButton(createStatusBarIcon(window)); } void FCM_Plugin::mainWindowDeleted(BrowserWindow *window) @@ -325,7 +344,9 @@ void FCM_Plugin::mainWindowDeleted(BrowserWindow *window) m_fcmDialog->setParent(0); } - window->statusBar()->removeWidget(m_statusBarIcons.value(window)); + window->statusBar()->removeButton(m_statusBarIcons.value(window)); + window->navigationBar()->removeToolButton(m_statusBarIcons.value(window)); + delete m_statusBarIcons.value(window); m_statusBarIcons.remove(window); } @@ -346,18 +367,17 @@ void FCM_Plugin::startStopTimer() } } -QWidget* FCM_Plugin::createStatusBarIcon(BrowserWindow* mainWindow) +AbstractButtonInterface* FCM_Plugin::createStatusBarIcon(BrowserWindow* mainWindow) { if (m_statusBarIcons.contains(mainWindow)) { return m_statusBarIcons.value(mainWindow); } - ClickableLabel* icon = new ClickableLabel(mainWindow); - icon->setCursor(Qt::PointingHandCursor); - icon->setPixmap(QIcon(QSL(":/flashcookiemanager/data/flash-cookie-manager.png")).pixmap(16)); + FCM_Button* icon = new FCM_Button(this); + icon->setIcon(QIcon(QSL(":/flashcookiemanager/data/flash-cookie-manager.png"))); + icon->setTitle(tr("Flash Cookie Manager")); icon->setToolTip(tr("Show Flash Cookie Manager")); - - connect(icon, SIGNAL(clicked(QPoint)), this, SLOT(showFlashCookieManager())); + connect(icon, &AbstractButtonInterface::clicked, this, &FCM_Plugin::showFlashCookieManager); m_statusBarIcons.insert(mainWindow, icon); diff --git a/src/plugins/FlashCookieManager/fcm_plugin.h b/src/plugins/FlashCookieManager/fcm_plugin.h index 5fc2b8d3e..600d9ebbd 100644 --- a/src/plugins/FlashCookieManager/fcm_plugin.h +++ b/src/plugins/FlashCookieManager/fcm_plugin.h @@ -1,6 +1,7 @@ /* ============================================================ * FlashCookieManager plugin for Falkon * Copyright (C) 2014 S. Razi Alavizadeh +* Copyright (C) 2018 David Rosca * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -26,6 +27,7 @@ class BrowserWindow; class FCM_Dialog; class QTimer; +class AbstractButtonInterface; struct FlashCookie { QString name; @@ -79,7 +81,7 @@ private slots: void startStopTimer(); private: - QWidget* createStatusBarIcon(BrowserWindow* mainWindow); + AbstractButtonInterface* createStatusBarIcon(BrowserWindow* mainWindow); void loadFlashCookies(); void loadFlashCookies(QString path); void insertFlashCookie(QString path); @@ -89,7 +91,7 @@ private: void removeAllButWhitelisted(); QString sharedObjectDirName() const; - QHash m_statusBarIcons; + QHash m_statusBarIcons; QPointer m_fcmDialog; QString m_settingsPath;