1
mirror of https://invent.kde.org/network/falkon.git synced 2024-11-11 01:22:10 +01:00

FlashCookieManager: Port icon to AbstractButtonInterface

It is now available from both NavigationBar and StatusBar
This commit is contained in:
David Rosca 2018-01-24 20:30:55 +01:00
parent 7265c30aa8
commit cc55c0ad02
2 changed files with 36 additions and 14 deletions

View File

@ -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 <QTimer>
#include <QSettings>
@ -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);

View File

@ -1,6 +1,7 @@
/* ============================================================
* FlashCookieManager plugin for Falkon
* Copyright (C) 2014 S. Razi Alavizadeh <s.r.alavizadeh@gmail.com>
* Copyright (C) 2018 David Rosca <nowrep@gmail.com>
*
* 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<BrowserWindow*, QWidget*> m_statusBarIcons;
QHash<BrowserWindow*, AbstractButtonInterface*> m_statusBarIcons;
QPointer<FCM_Dialog> m_fcmDialog;
QString m_settingsPath;