1
mirror of https://invent.kde.org/network/falkon.git synced 2024-09-21 09:42:10 +02:00

Added new plugin: StatusBar Icons.

This plugins add extra icons into statusbar with various
functionality.
Currently, only Images icon is present, which enable changing
image load settings per-site and globally.
This commit is contained in:
nowrep 2013-05-26 15:46:21 +02:00
parent f2945f14bf
commit 3259abef09
16 changed files with 537 additions and 13 deletions

View File

@ -7,6 +7,8 @@ Version 1.5.0
* added possibility to remove EasyList from AdBlock
* added inline domain completion to urlbar
* added KWallet password backend plugin
* added Gnome-Keyring password backend plugin
* added StatusBar Icons plugin that adds extra icons to statusbar
* proxy exceptions now supports wildcards (*, ?)
* cancel upload when trying to upload non-readable files
* GreaseMonkey: added support for GM_Settings

View File

@ -351,10 +351,10 @@ void QupZilla::setupUi()
m_ipLabel->setObjectName("statusbar-ip-label");
m_ipLabel->setToolTip(tr("IP Address of current page"));
statusBar()->insertPermanentWidget(0, m_progressBar);
statusBar()->insertPermanentWidget(1, m_ipLabel);
statusBar()->insertPermanentWidget(2, m_privateBrowsing);
statusBar()->insertPermanentWidget(3, m_adblockIcon);
statusBar()->addPermanentWidget(m_progressBar);
statusBar()->addPermanentWidget(m_ipLabel);
statusBar()->addPermanentWidget(m_privateBrowsing);
statusBar()->addPermanentWidget(m_adblockIcon);
// Workaround for Oxygen tooltips not having transparent background
QPalette pal = QToolTip::palette();

View File

@ -85,6 +85,9 @@ public:
void showNavigationBar(QWidget* bar);
WebTab* weTab();
WebTab* weTab(int index);
TabBar* getTabBar() const;
ClosedTabsManager* closedTabsManager() const;
QList<WebTab*> allTabs(bool withPinned = true);
@ -138,9 +141,6 @@ private:
void resizeEvent(QResizeEvent* e);
WebTab* weTab();
WebTab* weTab(int index);
bool m_hideTabBarWithOneTab;
bool m_dontQuitWithOneTab;
bool m_closedInsteadOpened;

View File

@ -4,7 +4,7 @@
<context>
<name>GnomeKeyringPlugin</name>
<message>
<location filename="../gnomekeyringpasswordbackend.cpp" line="92"/>
<location filename="../gnomekeyringpasswordbackend.cpp" line="85"/>
<source>Gnome Keyring</source>
<translation type="unfinished"></translation>
</message>

View File

@ -0,0 +1,15 @@
include(../../defines.pri)
TARGET = $$qtLibraryTarget(StatusBarIcons)
SOURCES += statusbariconsplugin.cpp \
sbi_iconsmanager.cpp \
sbi_imagesicon.cpp
HEADERS += statusbariconsplugin.h \
sbi_iconsmanager.h \
sbi_imagesicon.h
RESOURCES += statusbaricons.qrc
include(../../plugins.pri)

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 659 B

View File

@ -0,0 +1,99 @@
/* ============================================================
* StatusBarIcons - Extra icons in statusbar for QupZilla
* Copyright (C) 2013 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* ============================================================ */
#include "sbi_iconsmanager.h"
#include "sbi_imagesicon.h"
#include "qupzilla.h"
#include <QDebug>
#include <QSettings>
#include <QStatusBar>
SBI_IconsManager::SBI_IconsManager(const QString &settingsPath, QObject* parent)
: QObject(parent)
, m_settingsPath(settingsPath)
, m_showImagesIcon(false)
, m_showJavaScriptIcon(false)
, m_showNetworkIcon(false)
{
loadSettings();
}
void SBI_IconsManager::loadSettings()
{
QSettings settings(m_settingsPath + "extensions.ini", QSettings::IniFormat);
settings.beginGroup("StatusBarIcons");
m_showImagesIcon = settings.value("showImagesIcon", true).toBool();
m_showJavaScriptIcon = settings.value("showJavaScriptIcon", true).toBool();
m_showNetworkIcon = settings.value("showNetworkIcon", true).toBool();
settings.endGroup();
}
void SBI_IconsManager::reloadIcons()
{
QHashIterator<QupZilla*, QWidgetList> it(m_windows);
while (it.hasNext()) {
it.next();
mainWindowDeleted(it.key());
mainWindowCreated(it.key());
}
}
void SBI_IconsManager::destroyIcons()
{
QHashIterator<QupZilla*, QWidgetList> it(m_windows);
while (it.hasNext()) {
it.next();
mainWindowDeleted(it.key());
}
}
void SBI_IconsManager::mainWindowCreated(QupZilla* window)
{
typedef QWidget SBI_JavaScriptIcon;
typedef QWidget SBI_NetworkIcon;
if (m_showImagesIcon) {
SBI_ImagesIcon* w = new SBI_ImagesIcon(window, m_settingsPath);
window->statusBar()->addPermanentWidget(w);
m_windows[window].append(w);
}
if (m_showJavaScriptIcon) {
SBI_JavaScriptIcon* w = new SBI_JavaScriptIcon;
window->statusBar()->addPermanentWidget(w);
m_windows[window].append(w);
}
if (m_showNetworkIcon) {
SBI_NetworkIcon* w = new SBI_NetworkIcon;
window->statusBar()->addPermanentWidget(w);
m_windows[window].append(w);
}
}
void SBI_IconsManager::mainWindowDeleted(QupZilla* window)
{
foreach (QWidget* w, m_windows[window]) {
window->statusBar()->removeWidget(w);
delete w;
}
m_windows[window].clear();
}

View File

@ -0,0 +1,52 @@
/* ============================================================
* StatusBarIcons - Extra icons in statusbar for QupZilla
* Copyright (C) 2013 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* ============================================================ */
#ifndef SBI_ICONSMANAGER_H
#define SBI_ICONSMANAGER_H
#include <QWidget>
#include <QHash>
class QupZilla;
class SBI_IconsManager : public QObject
{
Q_OBJECT
public:
explicit SBI_IconsManager(const QString &settingsPath, QObject* parent = 0);
void loadSettings();
void reloadIcons();
void destroyIcons();
signals:
public slots:
void mainWindowCreated(QupZilla* window);
void mainWindowDeleted(QupZilla* window);
private:
QString m_settingsPath;
bool m_showImagesIcon;
bool m_showJavaScriptIcon;
bool m_showNetworkIcon;
QHash<QupZilla*, QWidgetList> m_windows;
};
#endif // SBI_ICONSMANAGER_H

View File

@ -0,0 +1,127 @@
/* ============================================================
* StatusBarIcons - Extra icons in statusbar for QupZilla
* Copyright (C) 2013 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* ============================================================ */
#include "sbi_imagesicon.h"
#include "mainapplication.h"
#include "qupzilla.h"
#include "tabwidget.h"
#include "tabbedwebview.h"
#include "webpage.h"
#include <QGraphicsColorizeEffect>
#include <QWebSettings>
#include <QSettings>
#include <QMenu>
SBI_ImagesIcon::SBI_ImagesIcon(QupZilla* window, const QString &settingsPath)
: ClickableLabel(window)
, p_QupZilla(window)
, m_settingsFile(settingsPath + "extensions.ini")
{
setCursor(Qt::PointingHandCursor);
setToolTip(tr("Modify images loading settings per-site and globally"));
m_icon = QIcon::fromTheme("image-x-genericsss", QIcon(":sbi/data/images.png"));
setPixmap(m_icon.pixmap(16));
QSettings settings(m_settingsFile, QSettings::IniFormat);
settings.beginGroup("StatusBarIcons_Images");
m_loadingImages = settings.value("LoadImages", true).toBool();
settings.endGroup();
mApp->webSettings()->setAttribute(QWebSettings::AutoLoadImages, m_loadingImages);
updateIcon();
connect(p_QupZilla->tabWidget(), SIGNAL(currentChanged(int)), this, SLOT(updateIcon()));
connect(this, SIGNAL(clicked(QPoint)), this, SLOT(showMenu(QPoint)));
}
void SBI_ImagesIcon::showMenu(const QPoint &point)
{
QFont boldFont = font();
boldFont.setBold(true);
QMenu menu;
menu.addAction(m_icon, tr("Current page settings"))->setFont(boldFont);
if (currentPageSettings()->testAttribute(QWebSettings::AutoLoadImages)) {
menu.addAction(tr("Disable loading images (temporarily)"), this, SLOT(toggleLoadingImages()));
}
else {
menu.addAction(tr("Enable loading images (temporarily)"), this, SLOT(toggleLoadingImages()));
}
menu.addSeparator();
menu.addAction(m_icon, tr("Global settings"))->setFont(boldFont);
QAction* act = menu.addAction(tr("Automatically load images"));
act->setCheckable(true);
act->setChecked(m_loadingImages);
connect(act, SIGNAL(toggled(bool)), this, SLOT(setGlobalLoadingImages(bool)));
menu.exec(point);
}
void SBI_ImagesIcon::toggleLoadingImages()
{
bool current = currentPageSettings()->testAttribute(QWebSettings::AutoLoadImages);
currentPageSettings()->setAttribute(QWebSettings::AutoLoadImages, !current);
// We should reload page on disabling images
if (current) {
p_QupZilla->tabWidget()->weTab()->reload();
}
updateIcon();
}
void SBI_ImagesIcon::setGlobalLoadingImages(bool enable)
{
// Save it permanently
QSettings settings(m_settingsFile, QSettings::IniFormat);
settings.beginGroup("StatusBarIcons_Images");
settings.setValue("LoadImages", enable);
settings.endGroup();
// Switch it in websettings
mApp->webSettings()->setAttribute(QWebSettings::AutoLoadImages, enable);
updateIcon();
// We should reload page on disabling images
if (!enable) {
p_QupZilla->tabWidget()->weTab()->reload();
}
}
QWebSettings* SBI_ImagesIcon::currentPageSettings()
{
return p_QupZilla->tabWidget()->weTab()->view()->page()->settings();
}
void SBI_ImagesIcon::updateIcon()
{
if (currentPageSettings()->testAttribute(QWebSettings::AutoLoadImages)) {
setGraphicsEffect(0);
}
else {
QGraphicsColorizeEffect* effect = new QGraphicsColorizeEffect(this);
effect->setColor(Qt::gray);
setGraphicsEffect(effect);
}
}

View File

@ -0,0 +1,53 @@
/* ============================================================
* StatusBarIcons - Extra icons in statusbar for QupZilla
* Copyright (C) 2013 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* ============================================================ */
#ifndef SBI_IMAGESICON_H
#define SBI_IMAGESICON_H
#include <QIcon>
#include "clickablelabel.h"
class QWebSettings;
class QupZilla;
class SBI_ImagesIcon : public ClickableLabel
{
Q_OBJECT
public:
explicit SBI_ImagesIcon(QupZilla* window, const QString &settingsPath);
private slots:
void showMenu(const QPoint &point);
void updateIcon();
void toggleLoadingImages();
void setGlobalLoadingImages(bool enable);
private:
QWebSettings* currentPageSettings();
QupZilla* p_QupZilla;
QString m_settingsFile;
QIcon m_icon;
bool m_loadingImages;
};
#endif // SBI_IMAGESICON_H

View File

@ -0,0 +1,6 @@
<RCC>
<qresource prefix="/sbi">
<file>data/icon.png</file>
<file>data/images.png</file>
</qresource>
</RCC>

View File

@ -0,0 +1,84 @@
/* ============================================================
* StatusBarIcons - Extra icons in statusbar for QupZilla
* Copyright (C) 2013 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* ============================================================ */
#include "statusbariconsplugin.h"
#include "sbi_iconsmanager.h"
#include "pluginproxy.h"
#include "qupzilla.h"
#include <QTranslator>
StatusBarIconsPlugin::StatusBarIconsPlugin()
: QObject()
, m_manager(0)
{
}
PluginSpec StatusBarIconsPlugin::pluginSpec()
{
PluginSpec spec;
spec.name = "StatusBar Icons";
spec.info = "Icons in statusbar providing various actions";
spec.description = "Adds additional icons to statusbar";
spec.version = "0.1.0";
spec.author = "David Rosca <nowrep@gmail.com>";
spec.icon = QPixmap(":sbi/data/icon.png");
spec.hasSettings = false;
return spec;
}
void StatusBarIconsPlugin::init(InitState state, const QString &settingsPath)
{
m_manager = new SBI_IconsManager(settingsPath);
connect(mApp->plugins(), SIGNAL(mainWindowCreated(QupZilla*)), m_manager, SLOT(mainWindowCreated(QupZilla*)));
connect(mApp->plugins(), SIGNAL(mainWindowDeleted(QupZilla*)), m_manager, SLOT(mainWindowDeleted(QupZilla*)));
// Make sure icons are added also to already created windows
if (state == LateInitState) {
foreach (QupZilla* window, mApp->mainWindows()) {
m_manager->mainWindowCreated(window);
}
}
}
void StatusBarIconsPlugin::unload()
{
// Make sure icons are properly removed when unloading plugin (but not when closing app)
if (!mApp->isClosing()) {
foreach (QupZilla* window, mApp->mainWindows()) {
m_manager->mainWindowDeleted(window);
}
delete m_manager;
}
}
bool StatusBarIconsPlugin::testPlugin()
{
return (QupZilla::VERSION == QLatin1String("1.5.0"));
}
void StatusBarIconsPlugin::showSettings(QWidget* parent)
{
Q_UNUSED(parent)
}
#if QT_VERSION < 0x050000
Q_EXPORT_PLUGIN2(StatusBarIcons, StatusBarIconsPlugin)
#endif

View File

@ -0,0 +1,49 @@
/* ============================================================
* StatusBarIcons - Extra icons in statusbar for QupZilla
* Copyright (C) 2013 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* ============================================================ */
#ifndef STATUSBARICONSPLUGIN_H
#define STATUSBARICONSPLUGIN_H
#include "plugininterface.h"
class SBI_IconsManager;
class StatusBarIconsPlugin : public QObject, public PluginInterface
{
Q_OBJECT
Q_INTERFACES(PluginInterface)
#if QT_VERSION >= 0x050000
Q_PLUGIN_METADATA(IID "QupZilla.Browser.plugin.StatusBarIcons")
#endif
public:
explicit StatusBarIconsPlugin();
PluginSpec pluginSpec();
void init(InitState state, const QString &settingsPath);
void unload();
bool testPlugin();
void showSettings(QWidget* parent = 0);
private:
SBI_IconsManager* m_manager;
};
#endif // STATUSBARICONSPLUGIN_H

View File

@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.0">
<context>
<name>SBI_ImagesIcon</name>
<message>
<location filename="../sbi_imagesicon.cpp" line="37"/>
<source>Modify images loading settings per-site and globally</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../sbi_imagesicon.cpp" line="57"/>
<source>Current page settings</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../sbi_imagesicon.cpp" line="60"/>
<source>Disable loading images (temporarily)</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../sbi_imagesicon.cpp" line="63"/>
<source>Enable loading images (temporarily)</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../sbi_imagesicon.cpp" line="67"/>
<source>Global settings</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../sbi_imagesicon.cpp" line="69"/>
<source>Automatically load images</source>
<translation type="unfinished"></translation>
</message>
</context>
</TS>

View File

@ -4,27 +4,27 @@
<context>
<name>TestPlugin</name>
<message>
<location filename="../testplugin.cpp" line="116"/>
<location filename="../testplugin.cpp" line="121"/>
<source>Close</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../testplugin.cpp" line="127"/>
<location filename="../testplugin.cpp" line="132"/>
<source>Example Plugin Settings</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../testplugin.cpp" line="155"/>
<location filename="../testplugin.cpp" line="160"/>
<source>My first plugin action</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../testplugin.cpp" line="170"/>
<location filename="../testplugin.cpp" line="175"/>
<source>Hello</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../testplugin.cpp" line="170"/>
<location filename="../testplugin.cpp" line="175"/>
<source>First plugin action works :-)</source>
<translation type="unfinished"></translation>
</message>