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: Added:
<ul> <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>Custom counts of messages in feed list (issue #14) are now changeable.</li>
<li>Feed list categories expand status is now persistent.</li> <li>Feed list categories expand status is now persistent.</li>
<li>System-wide external web browser can now be used.</li> <li>System-wide external web browser can now be used.</li>

View file

@ -1,18 +1,67 @@
#include "core/webfactory.h" #include "core/webfactory.h"
#include "core/defs.h"
#include "core/settings.h"
#include <QApplication> #include <QApplication>
#include <QRegExp> #include <QRegExp>
#include <QWebSettings>
QPointer<WebFactory> WebFactory::s_instance; QPointer<WebFactory> WebFactory::s_instance;
WebFactory::WebFactory(QObject *parent) : QObject(parent) { WebFactory::WebFactory(QObject *parent) : QObject(parent) {
m_globalSettings = QWebSettings::globalSettings();
} }
WebFactory::~WebFactory() { WebFactory::~WebFactory() {
qDebug("Destroying WebFactory instance."); 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() { WebFactory *WebFactory::instance() {
if (s_instance.isNull()) { if (s_instance.isNull()) {
s_instance = new WebFactory(qApp); s_instance = new WebFactory(qApp);
@ -21,6 +70,18 @@ WebFactory *WebFactory::instance() {
return s_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) { QString WebFactory::stripTags(QString text) {
return text.remove(QRegExp("<[^>]*>")); return text.remove(QRegExp("<[^>]*>"));
} }

View file

@ -6,6 +6,8 @@
#include <QMap> #include <QMap>
class QWebSettings;
class WebFactory : public QObject { class WebFactory : public QObject {
Q_OBJECT Q_OBJECT
@ -13,6 +15,11 @@ class WebFactory : public QObject {
// Destructor. // Destructor.
virtual ~WebFactory(); 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. // Strips "<....>" (HTML, XML) tags from given text.
QString stripTags(QString text); QString stripTags(QString text);
@ -24,6 +31,16 @@ class WebFactory : public QObject {
// Singleton getter. // Singleton getter.
static WebFactory *instance(); 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: signals:
void javascriptSwitched(bool enabled); void javascriptSwitched(bool enabled);
void pluginsSwitched(bool enabled); void pluginsSwitched(bool enabled);
@ -37,6 +54,8 @@ class WebFactory : public QObject {
QMap<QString, QString> generetaEscapes(); QMap<QString, QString> generetaEscapes();
QMap<QString, QString> generateDeescapes(); QMap<QString, QString> generateDeescapes();
QWebSettings *m_globalSettings;
// Singleton. // Singleton.
static QPointer<WebFactory> s_instance; static QPointer<WebFactory> s_instance;
}; };

View file

@ -21,6 +21,7 @@
#include "core/settings.h" #include "core/settings.h"
#include "core/systemfactory.h" #include "core/systemfactory.h"
#include "core/databasefactory.h" #include "core/databasefactory.h"
#include "core/webfactory.h"
#include "gui/formabout.h" #include "gui/formabout.h"
#include "gui/formsettings.h" #include "gui/formsettings.h"
#include "gui/feedsview.h" #include "gui/feedsview.h"
@ -71,8 +72,12 @@ FormMain::FormMain(QWidget *parent)
// Prepare tabs. // Prepare tabs.
m_ui->m_tabWidget->initializeTabs(); m_ui->m_tabWidget->initializeTabs();
// Setup some appearance of the window.
setupIcons(); setupIcons();
loadSize(); loadSize();
// Initialize the web factory.
WebFactory::instance()->loadState();
} }
FormMain::~FormMain() { FormMain::~FormMain() {
@ -271,6 +276,10 @@ void FormMain::setupIcons() {
m_ui->m_actionCloseCurrentTab->setIcon(icon_theme_factory->fromTheme("list-remove")); 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_actionCloseAllTabs->setIcon(icon_theme_factory->fromTheme("list-remove"));
m_ui->m_menuCurrentTab->setIcon(icon_theme_factory->fromTheme("list-current")); 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. // Feeds/messages.
m_ui->m_menuAddItem->setIcon(icon_theme_factory->fromTheme("item-new")); m_ui->m_menuAddItem->setIcon(icon_theme_factory->fromTheme("item-new"));
@ -381,6 +390,18 @@ void FormMain::createConnections() {
m_ui->m_tabWidget, SLOT(addEmptyBrowser())); m_ui->m_tabWidget, SLOT(addEmptyBrowser()));
connect(m_ui->m_actionCloseAllTabs, SIGNAL(triggered()), connect(m_ui->m_actionCloseAllTabs, SIGNAL(triggered()),
m_ui->m_tabWidget, SLOT(closeAllTabsExceptCurrent())); 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) { void FormMain::loadWebBrowserMenu(int index) {

View file

@ -15,16 +15,7 @@
</property> </property>
<widget class="QWidget" name="centralwidget"> <widget class="QWidget" name="centralwidget">
<layout class="QHBoxLayout" name="horizontalLayout"> <layout class="QHBoxLayout" name="horizontalLayout">
<property name="leftMargin"> <property name="margin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number> <number>0</number>
</property> </property>
<item> <item>
@ -48,7 +39,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>979</width> <width>979</width>
<height>21</height> <height>20</height>
</rect> </rect>
</property> </property>
<widget class="QMenu" name="m_menuFile"> <widget class="QMenu" name="m_menuFile">
@ -90,10 +81,19 @@
<string>&amp;Current tab</string> <string>&amp;Current tab</string>
</property> </property>
</widget> </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_actionAddBrowser"/>
<addaction name="m_actionCloseCurrentTab"/> <addaction name="m_actionCloseCurrentTab"/>
<addaction name="m_actionCloseAllTabs"/> <addaction name="m_actionCloseAllTabs"/>
<addaction name="separator"/> <addaction name="separator"/>
<addaction name="m_menuWebSettings"/>
<addaction name="m_menuCurrentTab"/> <addaction name="m_menuCurrentTab"/>
</widget> </widget>
<widget class="QMenu" name="m_menuFeeds"> <widget class="QMenu" name="m_menuFeeds">
@ -425,6 +425,30 @@
<string>Hides or displays the main menu.</string> <string>Hides or displays the main menu.</string>
</property> </property>
</action> </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> </widget>
<customwidgets> <customwidgets>
<customwidget> <customwidget>

View file

@ -22,6 +22,7 @@
#include "core/databasefactory.h" #include "core/databasefactory.h"
#include "core/localization.h" #include "core/localization.h"
#include "core/systemfactory.h" #include "core/systemfactory.h"
#include "core/webfactory.h"
#include "core/feeddownloader.h" #include "core/feeddownloader.h"
#include "core/dynamicshortcuts.h" #include "core/dynamicshortcuts.h"
#include "core/webbrowsernetworkaccessmanager.h" #include "core/webbrowsernetworkaccessmanager.h"
@ -362,6 +363,9 @@ void FormSettings::loadBrowser() {
m_ui->m_grpCustomExternalBrowser->setChecked(settings->value(APP_CFG_BROWSER, m_ui->m_grpCustomExternalBrowser->setChecked(settings->value(APP_CFG_BROWSER,
"custom_external_browser", "custom_external_browser",
false).toBool()); 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() { void FormSettings::saveBrowser() {
@ -384,6 +388,10 @@ void FormSettings::saveBrowser() {
"queue_tabs", "queue_tabs",
m_ui->m_checkQueueTabs->isChecked()); 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, settings->setValue(APP_CFG_BROWSER,
"external_browser_executable", "external_browser_executable",
m_ui->m_txtExternalBrowserExecutable->text()); m_ui->m_txtExternalBrowserExecutable->text());

View file

@ -17,7 +17,7 @@
<item row="0" column="1"> <item row="0" column="1">
<widget class="QStackedWidget" name="m_stackedSettings"> <widget class="QStackedWidget" name="m_stackedSettings">
<property name="currentIndex"> <property name="currentIndex">
<number>6</number> <number>0</number>
</property> </property>
<widget class="QWidget" name="m_pageGeneral"> <widget class="QWidget" name="m_pageGeneral">
<layout class="QFormLayout" name="formLayout_5"> <layout class="QFormLayout" name="formLayout_5">
@ -286,8 +286,8 @@ Authors of this application are NOT responsible for lost data.</string>
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>100</width> <width>564</width>
<height>30</height> <height>364</height>
</rect> </rect>
</property> </property>
<layout class="QHBoxLayout" name="horizontalLayout_4"> <layout class="QHBoxLayout" name="horizontalLayout_4">
@ -364,8 +364,8 @@ Authors of this application are NOT responsible for lost data.</string>
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>209</width> <width>560</width>
<height>245</height> <height>336</height>
</rect> </rect>
</property> </property>
<layout class="QFormLayout" name="formLayout"> <layout class="QFormLayout" name="formLayout">
@ -643,15 +643,15 @@ Authors of this application are NOT responsible for lost data.</string>
<property name="fieldGrowthPolicy"> <property name="fieldGrowthPolicy">
<enum>QFormLayout::AllNonFixedFieldsGrow</enum> <enum>QFormLayout::AllNonFixedFieldsGrow</enum>
</property> </property>
<item row="3" column="0" colspan="2"> <item row="6" column="0" colspan="2">
<widget class="QLabel" name="m_lblMouseGestures"> <widget class="QLabel" name="m_lblMouseGestures">
<property name="text"> <property name="text">
<string>Mouse gestures work with middle mouse button. Possible gestures are: <string>Mouse gestures work with middle mouse button. Possible gestures are:
&lt;ul&gt; &lt;ul&gt;
&lt;li&gt;previous web page (drag mouse left)&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;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;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;open new web browser tab (drag mouse down).&lt;/li&gt;
&lt;/ul&gt;</string> &lt;/ul&gt;</string>
</property> </property>
<property name="textFormat"> <property name="textFormat">
@ -662,7 +662,7 @@ Authors of this application are NOT responsible for lost data.</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="2" column="0" colspan="2"> <item row="5" column="0" colspan="2">
<widget class="QCheckBox" name="m_checkMouseGestures"> <widget class="QCheckBox" name="m_checkMouseGestures">
<property name="text"> <property name="text">
<string>Enable mouse gestures</string> <string>Enable mouse gestures</string>
@ -706,6 +706,27 @@ Authors of this application are NOT responsible for lost data.</string>
</item> </item>
</layout> </layout>
</item> </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> </layout>
</widget> </widget>
<widget class="QWidget" name="m_tabExternalBrowser"> <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"> <item row="3" column="1">
<widget class="QComboBox" name="m_cmbCountsFeedList"> <widget class="QComboBox" name="m_cmbCountsFeedList">
<property name="toolTip"> <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>
<property name="editable"> <property name="editable">
<bool>true</bool> <bool>true</bool>
</property> </property>
</widget> </widget>
</item> </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> </layout>
</widget> </widget>
<widget class="QWidget" name="m_tabMessages"> <widget class="QWidget" name="m_tabMessages">