mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-20 18:56:34 +01:00
[StatusBarIcons] Fixed crash when restoring session
All icons have now same parent SBI_Icon
This commit is contained in:
parent
d2528417d1
commit
9fda55d86d
@ -10,7 +10,8 @@ SOURCES += statusbariconsplugin.cpp \
|
||||
sbi_proxywidget.cpp \
|
||||
sbi_networkicondialog.cpp \
|
||||
sbi_networkmanager.cpp \
|
||||
sbi_settingsdialog.cpp
|
||||
sbi_settingsdialog.cpp \
|
||||
sbi_icon.cpp
|
||||
|
||||
HEADERS += statusbariconsplugin.h \
|
||||
sbi_iconsmanager.h \
|
||||
@ -21,7 +22,8 @@ HEADERS += statusbariconsplugin.h \
|
||||
sbi_proxywidget.h \
|
||||
sbi_networkicondialog.h \
|
||||
sbi_networkmanager.h \
|
||||
sbi_settingsdialog.h
|
||||
sbi_settingsdialog.h \
|
||||
sbi_icon.h
|
||||
|
||||
RESOURCES += statusbaricons.qrc
|
||||
|
||||
|
59
src/plugins/StatusBarIcons/sbi_icon.cpp
Normal file
59
src/plugins/StatusBarIcons/sbi_icon.cpp
Normal file
@ -0,0 +1,59 @@
|
||||
/* ============================================================
|
||||
* StatusBarIcons - Extra icons in statusbar for QupZilla
|
||||
* Copyright (C) 2014 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_icon.h"
|
||||
#include "browserwindow.h"
|
||||
#include "tabbedwebview.h"
|
||||
#include "webpage.h"
|
||||
|
||||
SBI_Icon::SBI_Icon(BrowserWindow* window, const QString &settingsPath)
|
||||
: ClickableLabel(window)
|
||||
, m_window(window)
|
||||
, m_settingsFile(settingsPath + QLatin1String("extensions.ini"))
|
||||
{
|
||||
}
|
||||
|
||||
bool SBI_Icon::testCurrentPageWebAttribute(QWebSettings::WebAttribute attr) const
|
||||
{
|
||||
return currentPageSettings() && currentPageSettings()->testAttribute(attr);
|
||||
}
|
||||
|
||||
void SBI_Icon::setCurrentPageWebAttribute(QWebSettings::WebAttribute attr, bool value)
|
||||
{
|
||||
if (currentPageSettings()) {
|
||||
currentPageSettings()->setAttribute(attr, value);
|
||||
}
|
||||
}
|
||||
|
||||
QWebSettings* SBI_Icon::currentPageSettings() const
|
||||
{
|
||||
if (!m_window->weView()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return m_window->weView()->page()->settings();
|
||||
}
|
||||
|
||||
WebPage* SBI_Icon::currentPage() const
|
||||
{
|
||||
if (!m_window->weView()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return m_window->weView()->page();
|
||||
}
|
||||
|
46
src/plugins/StatusBarIcons/sbi_icon.h
Normal file
46
src/plugins/StatusBarIcons/sbi_icon.h
Normal file
@ -0,0 +1,46 @@
|
||||
/* ============================================================
|
||||
* StatusBarIcons - Extra icons in statusbar for QupZilla
|
||||
* Copyright (C) 2014 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_ICON_H
|
||||
#define SBI_ICON_H
|
||||
|
||||
#include <QWebSettings>
|
||||
|
||||
#include "clickablelabel.h"
|
||||
|
||||
class BrowserWindow;
|
||||
class WebPage;
|
||||
|
||||
class SBI_Icon : public ClickableLabel
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit SBI_Icon(BrowserWindow* window, const QString &settingsPath = QString());
|
||||
|
||||
protected:
|
||||
bool testCurrentPageWebAttribute(QWebSettings::WebAttribute attr) const;
|
||||
void setCurrentPageWebAttribute(QWebSettings::WebAttribute attr, bool value);
|
||||
|
||||
QWebSettings* currentPageSettings() const;
|
||||
WebPage* currentPage() const;
|
||||
|
||||
BrowserWindow* m_window;
|
||||
QString m_settingsFile;
|
||||
};
|
||||
|
||||
#endif // SBI_ICON_H
|
@ -22,14 +22,11 @@
|
||||
#include "webpage.h"
|
||||
|
||||
#include <QGraphicsColorizeEffect>
|
||||
#include <QWebSettings>
|
||||
#include <QSettings>
|
||||
#include <QMenu>
|
||||
|
||||
SBI_ImagesIcon::SBI_ImagesIcon(BrowserWindow* window, const QString &settingsPath)
|
||||
: ClickableLabel(window)
|
||||
, m_window(window)
|
||||
, m_settingsFile(settingsPath + "extensions.ini")
|
||||
: SBI_Icon(window, settingsPath)
|
||||
{
|
||||
setCursor(Qt::PointingHandCursor);
|
||||
setToolTip(tr("Modify images loading settings per-site and globally"));
|
||||
@ -58,7 +55,7 @@ void SBI_ImagesIcon::showMenu(const QPoint &point)
|
||||
QMenu menu;
|
||||
menu.addAction(m_icon, tr("Current page settings"))->setFont(boldFont);
|
||||
|
||||
if (currentPageSettings()->testAttribute(QWebSettings::AutoLoadImages)) {
|
||||
if (testCurrentPageWebAttribute(QWebSettings::AutoLoadImages)) {
|
||||
menu.addAction(tr("Disable loading images (temporarily)"), this, SLOT(toggleLoadingImages()));
|
||||
}
|
||||
else {
|
||||
@ -78,8 +75,8 @@ void SBI_ImagesIcon::showMenu(const QPoint &point)
|
||||
|
||||
void SBI_ImagesIcon::toggleLoadingImages()
|
||||
{
|
||||
bool current = currentPageSettings()->testAttribute(QWebSettings::AutoLoadImages);
|
||||
currentPageSettings()->setAttribute(QWebSettings::AutoLoadImages, !current);
|
||||
bool current = testCurrentPageWebAttribute(QWebSettings::AutoLoadImages);
|
||||
setCurrentPageWebAttribute(QWebSettings::AutoLoadImages, !current);
|
||||
|
||||
// We should reload page on disabling images
|
||||
if (current) {
|
||||
@ -108,14 +105,9 @@ void SBI_ImagesIcon::setGlobalLoadingImages(bool enable)
|
||||
}
|
||||
}
|
||||
|
||||
QWebSettings* SBI_ImagesIcon::currentPageSettings()
|
||||
{
|
||||
return m_window->weView()->page()->settings();
|
||||
}
|
||||
|
||||
void SBI_ImagesIcon::updateIcon()
|
||||
{
|
||||
if (currentPageSettings()->testAttribute(QWebSettings::AutoLoadImages)) {
|
||||
if (testCurrentPageWebAttribute(QWebSettings::AutoLoadImages)) {
|
||||
setGraphicsEffect(0);
|
||||
}
|
||||
else {
|
||||
|
@ -20,13 +20,9 @@
|
||||
|
||||
#include <QIcon>
|
||||
|
||||
#include "clickablelabel.h"
|
||||
#include "sbi_icon.h"
|
||||
|
||||
class QWebSettings;
|
||||
|
||||
class BrowserWindow;
|
||||
|
||||
class SBI_ImagesIcon : public ClickableLabel
|
||||
class SBI_ImagesIcon : public SBI_Icon
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@ -41,11 +37,6 @@ private slots:
|
||||
void setGlobalLoadingImages(bool enable);
|
||||
|
||||
private:
|
||||
QWebSettings* currentPageSettings();
|
||||
|
||||
BrowserWindow* m_window;
|
||||
QString m_settingsFile;
|
||||
|
||||
QIcon m_icon;
|
||||
bool m_loadingImages;
|
||||
};
|
||||
|
@ -27,8 +27,7 @@
|
||||
#include <QMenu>
|
||||
|
||||
SBI_JavaScriptIcon::SBI_JavaScriptIcon(BrowserWindow* window)
|
||||
: ClickableLabel(window)
|
||||
, m_window(window)
|
||||
: SBI_Icon(window)
|
||||
{
|
||||
setCursor(Qt::PointingHandCursor);
|
||||
setToolTip(tr("Modify JavaScript settings per-site and globally"));
|
||||
@ -48,7 +47,7 @@ void SBI_JavaScriptIcon::showMenu(const QPoint &point)
|
||||
QMenu menu;
|
||||
menu.addAction(m_icon, tr("Current page settings"))->setFont(boldFont);
|
||||
|
||||
if (currentPageSettings()->testAttribute(QWebSettings::JavascriptEnabled)) {
|
||||
if (testCurrentPageWebAttribute(QWebSettings::JavascriptEnabled)) {
|
||||
menu.addAction(tr("Disable JavaScript (temporarily)"), this, SLOT(toggleJavaScript()));
|
||||
}
|
||||
else {
|
||||
@ -56,7 +55,7 @@ void SBI_JavaScriptIcon::showMenu(const QPoint &point)
|
||||
}
|
||||
|
||||
// JavaScript needs to be always enabled for qupzilla: sites
|
||||
if (currentPage()->url().scheme() == QLatin1String("qupzilla")) {
|
||||
if (currentPage() && currentPage()->url().scheme() == QLatin1String("qupzilla")) {
|
||||
menu.actions().at(1)->setEnabled(false);
|
||||
}
|
||||
|
||||
@ -68,7 +67,7 @@ void SBI_JavaScriptIcon::showMenu(const QPoint &point)
|
||||
|
||||
void SBI_JavaScriptIcon::updateIcon()
|
||||
{
|
||||
if (currentPageSettings()->testAttribute(QWebSettings::JavascriptEnabled)) {
|
||||
if (testCurrentPageWebAttribute(QWebSettings::JavascriptEnabled)) {
|
||||
setGraphicsEffect(0);
|
||||
}
|
||||
else {
|
||||
@ -80,7 +79,12 @@ void SBI_JavaScriptIcon::updateIcon()
|
||||
|
||||
void SBI_JavaScriptIcon::toggleJavaScript()
|
||||
{
|
||||
bool current = currentPageSettings()->testAttribute(QWebSettings::JavascriptEnabled);
|
||||
if (!currentPage()) {
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
bool current = testCurrentPageWebAttribute(QWebSettings::JavascriptEnabled);
|
||||
currentPage()->setJavaScriptEnabled(!current);
|
||||
|
||||
m_window->weView()->reload();
|
||||
@ -93,13 +97,3 @@ void SBI_JavaScriptIcon::openJavaScriptSettings()
|
||||
JsOptions dialog(m_window);
|
||||
dialog.exec();
|
||||
}
|
||||
|
||||
WebPage* SBI_JavaScriptIcon::currentPage()
|
||||
{
|
||||
return m_window->weView()->page();
|
||||
}
|
||||
|
||||
QWebSettings* SBI_JavaScriptIcon::currentPageSettings()
|
||||
{
|
||||
return currentPage()->settings();
|
||||
}
|
||||
|
@ -20,14 +20,9 @@
|
||||
|
||||
#include <QIcon>
|
||||
|
||||
#include "clickablelabel.h"
|
||||
#include "sbi_icon.h"
|
||||
|
||||
class QWebSettings;
|
||||
|
||||
class BrowserWindow;
|
||||
class WebPage;
|
||||
|
||||
class SBI_JavaScriptIcon : public ClickableLabel
|
||||
class SBI_JavaScriptIcon : public SBI_Icon
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@ -42,10 +37,6 @@ private slots:
|
||||
void openJavaScriptSettings();
|
||||
|
||||
private:
|
||||
WebPage* currentPage();
|
||||
QWebSettings* currentPageSettings();
|
||||
|
||||
BrowserWindow* m_window;
|
||||
QIcon m_icon;
|
||||
};
|
||||
|
||||
|
@ -29,8 +29,7 @@
|
||||
#include <QNetworkConfigurationManager>
|
||||
|
||||
SBI_NetworkIcon::SBI_NetworkIcon(BrowserWindow* window)
|
||||
: ClickableLabel(window)
|
||||
, m_window(window)
|
||||
: SBI_Icon(window)
|
||||
, m_networkConfiguration(new QNetworkConfigurationManager(this))
|
||||
{
|
||||
setCursor(Qt::PointingHandCursor);
|
||||
@ -140,5 +139,5 @@ void SBI_NetworkIcon::enterEvent(QEvent* event)
|
||||
{
|
||||
updateToolTip();
|
||||
|
||||
ClickableLabel::enterEvent(event);
|
||||
SBI_Icon::enterEvent(event);
|
||||
}
|
||||
|
@ -20,13 +20,11 @@
|
||||
|
||||
#include <QNetworkAccessManager>
|
||||
|
||||
#include "clickablelabel.h"
|
||||
#include "sbi_icon.h"
|
||||
|
||||
class QNetworkConfigurationManager;
|
||||
|
||||
class BrowserWindow;
|
||||
|
||||
class SBI_NetworkIcon : public ClickableLabel
|
||||
class SBI_NetworkIcon : public SBI_Icon
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@ -44,7 +42,6 @@ private:
|
||||
void updateToolTip();
|
||||
void enterEvent(QEvent* event);
|
||||
|
||||
BrowserWindow* m_window;
|
||||
QNetworkConfigurationManager* m_networkConfiguration;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user