diff --git a/src/lib/webview/tabwidget.h b/src/lib/webview/tabwidget.h index 8df8d75a0..05f8e5881 100644 --- a/src/lib/webview/tabwidget.h +++ b/src/lib/webview/tabwidget.h @@ -85,9 +85,6 @@ public: void showNavigationBar(QWidget* bar); - WebTab* weTab(); - WebTab* weTab(int index); - TabBar* getTabBar() const; ClosedTabsManager* closedTabsManager() const; QList allTabs(bool withPinned = true); @@ -134,6 +131,9 @@ private slots: void tabMoved(int before, int after); private: + WebTab* weTab(); + WebTab* weTab(int index); + inline bool validIndex(int index) const { return index >= 0 && index < count(); } void tabInserted(int index); diff --git a/src/plugins/StatusBarIcons/StatusBarIcons.pro b/src/plugins/StatusBarIcons/StatusBarIcons.pro index b9a816424..5c132167f 100644 --- a/src/plugins/StatusBarIcons/StatusBarIcons.pro +++ b/src/plugins/StatusBarIcons/StatusBarIcons.pro @@ -4,11 +4,13 @@ TARGET = $$qtLibraryTarget(StatusBarIcons) SOURCES += statusbariconsplugin.cpp \ sbi_iconsmanager.cpp \ - sbi_imagesicon.cpp + sbi_imagesicon.cpp \ + sbi_javascripticon.cpp HEADERS += statusbariconsplugin.h \ sbi_iconsmanager.h \ - sbi_imagesicon.h + sbi_imagesicon.h \ + sbi_javascripticon.h RESOURCES += statusbaricons.qrc diff --git a/src/plugins/StatusBarIcons/data/javascript.png b/src/plugins/StatusBarIcons/data/javascript.png new file mode 100644 index 000000000..00e7c9998 Binary files /dev/null and b/src/plugins/StatusBarIcons/data/javascript.png differ diff --git a/src/plugins/StatusBarIcons/sbi_iconsmanager.cpp b/src/plugins/StatusBarIcons/sbi_iconsmanager.cpp index 70ced13fe..6b4523890 100644 --- a/src/plugins/StatusBarIcons/sbi_iconsmanager.cpp +++ b/src/plugins/StatusBarIcons/sbi_iconsmanager.cpp @@ -17,6 +17,7 @@ * ============================================================ */ #include "sbi_iconsmanager.h" #include "sbi_imagesicon.h" +#include "sbi_javascripticon.h" #include "qupzilla.h" #include @@ -66,7 +67,6 @@ void SBI_IconsManager::destroyIcons() void SBI_IconsManager::mainWindowCreated(QupZilla* window) { - typedef QWidget SBI_JavaScriptIcon; typedef QWidget SBI_NetworkIcon; if (m_showImagesIcon) { @@ -76,7 +76,7 @@ void SBI_IconsManager::mainWindowCreated(QupZilla* window) } if (m_showJavaScriptIcon) { - SBI_JavaScriptIcon* w = new SBI_JavaScriptIcon; + SBI_JavaScriptIcon* w = new SBI_JavaScriptIcon(window); window->statusBar()->addPermanentWidget(w); m_windows[window].append(w); } diff --git a/src/plugins/StatusBarIcons/sbi_imagesicon.cpp b/src/plugins/StatusBarIcons/sbi_imagesicon.cpp index 6b5c23a34..03ad8f7d6 100644 --- a/src/plugins/StatusBarIcons/sbi_imagesicon.cpp +++ b/src/plugins/StatusBarIcons/sbi_imagesicon.cpp @@ -57,7 +57,6 @@ void SBI_ImagesIcon::showMenu(const QPoint &point) boldFont.setBold(true); QMenu menu; - menu.addAction(m_icon, tr("Current page settings"))->setFont(boldFont); if (currentPageSettings()->testAttribute(QWebSettings::AutoLoadImages)) { @@ -85,7 +84,7 @@ void SBI_ImagesIcon::toggleLoadingImages() // We should reload page on disabling images if (current) { - p_QupZilla->tabWidget()->weTab()->reload(); + p_QupZilla->weView()->reload(); } updateIcon(); @@ -105,13 +104,13 @@ void SBI_ImagesIcon::setGlobalLoadingImages(bool enable) // We should reload page on disabling images if (!enable) { - p_QupZilla->tabWidget()->weTab()->reload(); + p_QupZilla->weView()->reload(); } } QWebSettings* SBI_ImagesIcon::currentPageSettings() { - return p_QupZilla->tabWidget()->weTab()->view()->page()->settings(); + return p_QupZilla->weView()->page()->settings(); } void SBI_ImagesIcon::updateIcon() diff --git a/src/plugins/StatusBarIcons/sbi_javascripticon.cpp b/src/plugins/StatusBarIcons/sbi_javascripticon.cpp new file mode 100644 index 000000000..6ab715c87 --- /dev/null +++ b/src/plugins/StatusBarIcons/sbi_javascripticon.cpp @@ -0,0 +1,95 @@ +/* ============================================================ +* StatusBarIcons - Extra icons in statusbar for QupZilla +* Copyright (C) 2013 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 +* 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 . +* ============================================================ */ +#include "sbi_javascripticon.h" +#include "qupzilla.h" +#include "tabwidget.h" +#include "tabbedwebview.h" +#include "webpage.h" +#include "jsoptions.h" + +#include +#include +#include + +SBI_JavaScriptIcon::SBI_JavaScriptIcon(QupZilla* window) + : ClickableLabel(window) + , p_QupZilla(window) +{ + setCursor(Qt::PointingHandCursor); + setToolTip(tr("Modify JavaScript settings per-site and globally")); + + m_icon = QIcon::fromTheme("application-x-javascript", QIcon(":sbi/data/javascript.png")); + setPixmap(m_icon.pixmap(16)); + + connect(p_QupZilla->tabWidget(), SIGNAL(currentChanged(int)), this, SLOT(updateIcon())); + connect(this, SIGNAL(clicked(QPoint)), this, SLOT(showMenu(QPoint))); +} + +void SBI_JavaScriptIcon::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::JavascriptEnabled)) { + menu.addAction(tr("Disable JavaScript (temporarily)"), this, SLOT(toggleJavaScript())); + } + else { + menu.addAction(tr("Enable JavaScript (temporarily)"), this, SLOT(toggleJavaScript())); + } + + menu.addSeparator(); + menu.addAction(m_icon, tr("Global settings"))->setFont(boldFont); + menu.addAction(tr("Manage JavaScript settings"), this, SLOT(openJavaScriptSettings())); + menu.exec(point); +} + +void SBI_JavaScriptIcon::updateIcon() +{ + if (currentPageSettings()->testAttribute(QWebSettings::JavascriptEnabled)) { + setGraphicsEffect(0); + } + else { + QGraphicsColorizeEffect* effect = new QGraphicsColorizeEffect(this); + effect->setColor(Qt::gray); + setGraphicsEffect(effect); + } +} + +void SBI_JavaScriptIcon::toggleJavaScript() +{ + bool current = currentPageSettings()->testAttribute(QWebSettings::JavascriptEnabled); + currentPageSettings()->setAttribute(QWebSettings::JavascriptEnabled, !current); + + p_QupZilla->weView()->reload(); + + updateIcon(); +} + +void SBI_JavaScriptIcon::openJavaScriptSettings() +{ + JsOptions dialog(p_QupZilla); + dialog.exec(); +} + +QWebSettings* SBI_JavaScriptIcon::currentPageSettings() +{ + return p_QupZilla->weView()->page()->settings(); +} diff --git a/src/plugins/StatusBarIcons/sbi_javascripticon.h b/src/plugins/StatusBarIcons/sbi_javascripticon.h new file mode 100644 index 000000000..f0ed20f2c --- /dev/null +++ b/src/plugins/StatusBarIcons/sbi_javascripticon.h @@ -0,0 +1,50 @@ +/* ============================================================ +* StatusBarIcons - Extra icons in statusbar for QupZilla +* Copyright (C) 2013 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 +* 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 . +* ============================================================ */ +#ifndef SBI_JAVASCRIPTICON_H +#define SBI_JAVASCRIPTICON_H + +#include + +#include "clickablelabel.h" + +class QWebSettings; + +class QupZilla; + +class SBI_JavaScriptIcon : public ClickableLabel +{ + Q_OBJECT + +public: + explicit SBI_JavaScriptIcon(QupZilla* window); + +private slots: + void showMenu(const QPoint &point); + void updateIcon(); + + void toggleJavaScript(); + void openJavaScriptSettings(); + +private: + QWebSettings* currentPageSettings(); + + QupZilla* p_QupZilla; + QIcon m_icon; +}; + +#endif // SBI_JAVASCRIPTICON_H diff --git a/src/plugins/StatusBarIcons/statusbaricons.qrc b/src/plugins/StatusBarIcons/statusbaricons.qrc index 1ba7940a3..8572f4abc 100644 --- a/src/plugins/StatusBarIcons/statusbaricons.qrc +++ b/src/plugins/StatusBarIcons/statusbaricons.qrc @@ -2,5 +2,6 @@ data/icon.png data/images.png + data/javascript.png diff --git a/src/plugins/StatusBarIcons/statusbariconsplugin.cpp b/src/plugins/StatusBarIcons/statusbariconsplugin.cpp index d7dfcd64a..56a1890c4 100644 --- a/src/plugins/StatusBarIcons/statusbariconsplugin.cpp +++ b/src/plugins/StatusBarIcons/statusbariconsplugin.cpp @@ -34,7 +34,7 @@ PluginSpec StatusBarIconsPlugin::pluginSpec() 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.version = "0.1.5"; spec.author = "David Rosca "; spec.icon = QPixmap(":sbi/data/icon.png"); spec.hasSettings = false; diff --git a/src/plugins/StatusBarIcons/translations/empty.ts b/src/plugins/StatusBarIcons/translations/empty.ts index 6f430b8eb..8b55ec7cd 100644 --- a/src/plugins/StatusBarIcons/translations/empty.ts +++ b/src/plugins/StatusBarIcons/translations/empty.ts @@ -4,34 +4,67 @@ SBI_ImagesIcon - + Modify images loading settings per-site and globally - + Current page settings - + Disable loading images (temporarily) - + Enable loading images (temporarily) - + Global settings - + Automatically load images + + SBI_JavaScriptIcon + + + Modify JavaScript settings per-site and globally + + + + + Current page settings + + + + + Disable JavaScript (temporarily) + + + + + Enable JavaScript (temporarily) + + + + + Global settings + + + + + Manage JavaScript settings + + +