Fixed bug #9.

This commit is contained in:
Martin Rotter 2014-03-09 11:45:36 +01:00
parent d6571bf60c
commit 031af3e436
9 changed files with 191 additions and 23 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

View File

@ -8,6 +8,7 @@ Fixed:
Added:
<ul>
<li>User can enable/disable web browser javascript, external plugins and images auto-loading (bug #9).</li>
<li>Custom counts of messages in feed list (issue #14) are now changeable.</li>
<li>Feed list categories expand status is now persistent.</li>
<li>System-wide external web browser can now be used.</li>

View File

@ -1,18 +1,67 @@
#include "core/webfactory.h"
#include "core/defs.h"
#include "core/settings.h"
#include <QApplication>
#include <QRegExp>
#include <QWebSettings>
QPointer<WebFactory> WebFactory::s_instance;
WebFactory::WebFactory(QObject *parent) : QObject(parent) {
m_globalSettings = QWebSettings::globalSettings();
}
WebFactory::~WebFactory() {
qDebug("Destroying WebFactory instance.");
}
void WebFactory::loadState() {
Settings *settings = Settings::instance();
switchJavascript(settings->value(APP_CFG_BROWSER, "enable_javascript", true).toBool(),
false);
switchImages(settings->value(APP_CFG_BROWSER, "enable_images", true).toBool(),
false);
switchPlugins(settings->value(APP_CFG_BROWSER, "enable_plugins", false).toBool(),
false);
}
void WebFactory::switchJavascript(bool enable, bool save_settings) {
if (save_settings) {
Settings::instance()->setValue(APP_CFG_BROWSER,
"enable_javascript",
enable);
}
m_globalSettings->setAttribute(QWebSettings::JavascriptEnabled, enable);
emit javascriptSwitched(enable);
}
void WebFactory::switchPlugins(bool enable, bool save_settings) {
if (save_settings) {
Settings::instance()->setValue(APP_CFG_BROWSER,
"enable_plugins",
enable);
}
m_globalSettings->setAttribute(QWebSettings::PluginsEnabled, enable);
emit pluginsSwitched(enable);
}
void WebFactory::switchImages(bool enable, bool save_settings) {
if (save_settings) {
Settings::instance()->setValue(APP_CFG_BROWSER,
"enable_images",
enable);
}
m_globalSettings->setAttribute(QWebSettings::AutoLoadImages, enable);
emit imagesLoadingSwitched(enable);
}
WebFactory *WebFactory::instance() {
if (s_instance.isNull()) {
s_instance = new WebFactory(qApp);
@ -21,6 +70,18 @@ WebFactory *WebFactory::instance() {
return s_instance;
}
bool WebFactory::javascriptEnabled() const {
return m_globalSettings->testAttribute(QWebSettings::JavascriptEnabled);
}
bool WebFactory::pluginsEnabled() const {
return m_globalSettings->testAttribute(QWebSettings::PluginsEnabled);
}
bool WebFactory::autoloadImages() const {
return m_globalSettings->testAttribute(QWebSettings::AutoLoadImages);
}
QString WebFactory::stripTags(QString text) {
return text.remove(QRegExp("<[^>]*>"));
}

View File

@ -6,6 +6,8 @@
#include <QMap>
class QWebSettings;
class WebFactory : public QObject {
Q_OBJECT
@ -13,6 +15,11 @@ class WebFactory : public QObject {
// Destructor.
virtual ~WebFactory();
// Loads the web settings directly from
// application settings and notifies the rest of
// the world about current situation.
void loadState();
// Strips "<....>" (HTML, XML) tags from given text.
QString stripTags(QString text);
@ -24,6 +31,16 @@ class WebFactory : public QObject {
// Singleton getter.
static WebFactory *instance();
public slots:
// Operations.
bool javascriptEnabled() const;
bool pluginsEnabled() const;
bool autoloadImages() const;
void switchJavascript(bool enable, bool save_settings = true);
void switchPlugins(bool enable, bool save_settings = true);
void switchImages(bool enable, bool save_settings = true);
signals:
void javascriptSwitched(bool enabled);
void pluginsSwitched(bool enabled);
@ -37,6 +54,8 @@ class WebFactory : public QObject {
QMap<QString, QString> generetaEscapes();
QMap<QString, QString> generateDeescapes();
QWebSettings *m_globalSettings;
// Singleton.
static QPointer<WebFactory> s_instance;
};

View File

@ -21,6 +21,7 @@
#include "core/settings.h"
#include "core/systemfactory.h"
#include "core/databasefactory.h"
#include "core/webfactory.h"
#include "gui/formabout.h"
#include "gui/formsettings.h"
#include "gui/feedsview.h"
@ -71,8 +72,12 @@ FormMain::FormMain(QWidget *parent)
// Prepare tabs.
m_ui->m_tabWidget->initializeTabs();
// Setup some appearance of the window.
setupIcons();
loadSize();
// Initialize the web factory.
WebFactory::instance()->loadState();
}
FormMain::~FormMain() {
@ -271,6 +276,10 @@ void FormMain::setupIcons() {
m_ui->m_actionCloseCurrentTab->setIcon(icon_theme_factory->fromTheme("list-remove"));
m_ui->m_actionCloseAllTabs->setIcon(icon_theme_factory->fromTheme("list-remove"));
m_ui->m_menuCurrentTab->setIcon(icon_theme_factory->fromTheme("list-current"));
m_ui->m_menuWebSettings->setIcon(icon_theme_factory->fromTheme("application-settings"));
m_ui->m_actionWebAutoloadImages->setIcon(icon_theme_factory->fromTheme("image-generic"));
m_ui->m_actionWebEnableExternalPlugins->setIcon(icon_theme_factory->fromTheme("web-flash"));
m_ui->m_actionWebEnableJavascript->setIcon(icon_theme_factory->fromTheme("web-javascript"));
// Feeds/messages.
m_ui->m_menuAddItem->setIcon(icon_theme_factory->fromTheme("item-new"));
@ -381,6 +390,18 @@ void FormMain::createConnections() {
m_ui->m_tabWidget, SLOT(addEmptyBrowser()));
connect(m_ui->m_actionCloseAllTabs, SIGNAL(triggered()),
m_ui->m_tabWidget, SLOT(closeAllTabsExceptCurrent()));
connect(WebFactory::instance(), SIGNAL(imagesLoadingSwitched(bool)),
m_ui->m_actionWebAutoloadImages, SLOT(setChecked(bool)));
connect(WebFactory::instance(), SIGNAL(javascriptSwitched(bool)),
m_ui->m_actionWebEnableJavascript, SLOT(setChecked(bool)));
connect(WebFactory::instance(), SIGNAL(pluginsSwitched(bool)),
m_ui->m_actionWebEnableExternalPlugins, SLOT(setChecked(bool)));
connect(m_ui->m_actionWebAutoloadImages, SIGNAL(toggled(bool)),
WebFactory::instance(), SLOT(switchImages(bool)));
connect(m_ui->m_actionWebEnableExternalPlugins, SIGNAL(toggled(bool)),
WebFactory::instance(), SLOT(switchPlugins(bool)));
connect(m_ui->m_actionWebEnableJavascript, SIGNAL(toggled(bool)),
WebFactory::instance(), SLOT(switchJavascript(bool)));
}
void FormMain::loadWebBrowserMenu(int index) {

View File

@ -15,16 +15,7 @@
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<property name="margin">
<number>0</number>
</property>
<item>
@ -48,7 +39,7 @@
<x>0</x>
<y>0</y>
<width>979</width>
<height>21</height>
<height>20</height>
</rect>
</property>
<widget class="QMenu" name="m_menuFile">
@ -90,10 +81,19 @@
<string>&amp;Current tab</string>
</property>
</widget>
<widget class="QMenu" name="m_menuWebSettings">
<property name="title">
<string>Settings</string>
</property>
<addaction name="m_actionWebEnableJavascript"/>
<addaction name="m_actionWebEnableExternalPlugins"/>
<addaction name="m_actionWebAutoloadImages"/>
</widget>
<addaction name="m_actionAddBrowser"/>
<addaction name="m_actionCloseCurrentTab"/>
<addaction name="m_actionCloseAllTabs"/>
<addaction name="separator"/>
<addaction name="m_menuWebSettings"/>
<addaction name="m_menuCurrentTab"/>
</widget>
<widget class="QMenu" name="m_menuFeeds">
@ -425,6 +425,30 @@
<string>Hides or displays the main menu.</string>
</property>
</action>
<action name="m_actionWebEnableJavascript">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Enable JavaScript</string>
</property>
</action>
<action name="m_actionWebEnableExternalPlugins">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Enable external plugins</string>
</property>
</action>
<action name="m_actionWebAutoloadImages">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Auto-load images</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>

View File

@ -22,6 +22,7 @@
#include "core/databasefactory.h"
#include "core/localization.h"
#include "core/systemfactory.h"
#include "core/webfactory.h"
#include "core/feeddownloader.h"
#include "core/dynamicshortcuts.h"
#include "core/webbrowsernetworkaccessmanager.h"
@ -362,6 +363,9 @@ void FormSettings::loadBrowser() {
m_ui->m_grpCustomExternalBrowser->setChecked(settings->value(APP_CFG_BROWSER,
"custom_external_browser",
false).toBool());
m_ui->m_checkAutoLoadImages->setChecked(WebFactory::instance()->autoloadImages());
m_ui->m_checkEnableJavascript->setChecked(WebFactory::instance()->javascriptEnabled());
m_ui->m_checkEnablePlugins->setChecked(WebFactory::instance()->pluginsEnabled());
}
void FormSettings::saveBrowser() {
@ -384,6 +388,10 @@ void FormSettings::saveBrowser() {
"queue_tabs",
m_ui->m_checkQueueTabs->isChecked());
WebFactory::instance()->switchImages(m_ui->m_checkAutoLoadImages->isChecked());
WebFactory::instance()->switchJavascript(m_ui->m_checkEnableJavascript->isChecked());
WebFactory::instance()->switchPlugins(m_ui->m_checkEnablePlugins->isChecked());
settings->setValue(APP_CFG_BROWSER,
"external_browser_executable",
m_ui->m_txtExternalBrowserExecutable->text());

View File

@ -17,7 +17,7 @@
<item row="0" column="1">
<widget class="QStackedWidget" name="m_stackedSettings">
<property name="currentIndex">
<number>6</number>
<number>0</number>
</property>
<widget class="QWidget" name="m_pageGeneral">
<layout class="QFormLayout" name="formLayout_5">
@ -286,8 +286,8 @@ Authors of this application are NOT responsible for lost data.</string>
<rect>
<x>0</x>
<y>0</y>
<width>100</width>
<height>30</height>
<width>564</width>
<height>364</height>
</rect>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_4">
@ -364,8 +364,8 @@ Authors of this application are NOT responsible for lost data.</string>
<rect>
<x>0</x>
<y>0</y>
<width>209</width>
<height>245</height>
<width>560</width>
<height>336</height>
</rect>
</property>
<layout class="QFormLayout" name="formLayout">
@ -643,15 +643,15 @@ Authors of this application are NOT responsible for lost data.</string>
<property name="fieldGrowthPolicy">
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
</property>
<item row="3" column="0" colspan="2">
<item row="6" column="0" colspan="2">
<widget class="QLabel" name="m_lblMouseGestures">
<property name="text">
<string>Mouse gestures work with middle mouse button. Possible gestures are:
&lt;ul&gt;
&lt;li&gt;previous web page (drag mouse left)&lt;/li&gt;
&lt;li&gt;next web page (drag mouse right)&lt;/li&gt;
&lt;li&gt;reload current web page (drag mouse up)&lt;/li&gt;
&lt;li&gt;open new web browser tab (drag mouse down)&lt;/li&gt;
&lt;li&gt;previous web page (drag mouse left),&lt;/li&gt;
&lt;li&gt;next web page (drag mouse right),&lt;/li&gt;
&lt;li&gt;reload current web page (drag mouse up),&lt;/li&gt;
&lt;li&gt;open new web browser tab (drag mouse down).&lt;/li&gt;
&lt;/ul&gt;</string>
</property>
<property name="textFormat">
@ -662,7 +662,7 @@ Authors of this application are NOT responsible for lost data.</string>
</property>
</widget>
</item>
<item row="2" column="0" colspan="2">
<item row="5" column="0" colspan="2">
<widget class="QCheckBox" name="m_checkMouseGestures">
<property name="text">
<string>Enable mouse gestures</string>
@ -706,6 +706,27 @@ Authors of this application are NOT responsible for lost data.</string>
</item>
</layout>
</item>
<item row="2" column="0">
<widget class="QCheckBox" name="m_checkEnableJavascript">
<property name="text">
<string>Enable JavaScript</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QCheckBox" name="m_checkEnablePlugins">
<property name="text">
<string>Enable external plugins based on NPAPI</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QCheckBox" name="m_checkAutoLoadImages">
<property name="text">
<string>Auto-load images</string>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="m_tabExternalBrowser">
@ -1049,13 +1070,26 @@ Authors of this application are NOT responsible for lost data.</string>
<item row="3" column="1">
<widget class="QComboBox" name="m_cmbCountsFeedList">
<property name="toolTip">
<string>Enter format for count of messages displayed next to each feed/category in feed list. Use &quot;%all&quot; and &quot;%unread&quot; placeholders.</string>
<string notr="true"/>
</property>
<property name="editable">
<bool>true</bool>
</property>
</widget>
</item>
<item row="4" column="0" colspan="2">
<widget class="QLabel" name="label_9">
<property name="text">
<string>Enter format for count of messages displayed next to each feed/category in feed list. Use &quot;%all&quot; and &quot;%unread&quot; strings which are placeholders for the actual count of all (or unread) messages.</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="m_tabMessages">