Make it optional to display images.

This commit is contained in:
Michael Käufl 2014-09-28 21:20:06 +02:00
parent 93faf4279b
commit 9fa59da33d
5 changed files with 44 additions and 2 deletions

View file

@ -665,7 +665,12 @@
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/ttrss/sailfish/pages/Settings.qml" line="181"/>
<location filename="../qml/ttrss/sailfish/pages/Settings.qml" line="182"/>
<source>Display images</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/ttrss/sailfish/pages/Settings.qml" line="188"/>
<source>Strip invisible images</source>
<translation type="unfinished"></translation>
</message>

View file

@ -247,6 +247,15 @@ Page {
console.log("URL: " + url + " isImage: " + isImage)
var attachmentLabel = ""
if (isImage) {
if (!settings.displayImages) {
// Do not attach images if they should not be displayed.
continue
}
var re = new RegExp("<img\\s[^>]*src=\"" + url + "\"", "i")
if (data.content.match(re)) {
// Do not attach images which are part of the content.
continue
}
attachmentLabel = "<img src=\"" + url + "\" style=\"max-width: 100%; height: auto\"/>"
} else {
attachmentLabel = a.title ? a.title : url.replace(/^.*[\/]/g, '')
@ -265,7 +274,11 @@ Page {
var content = data.content.replace('target="_blank"', '')
if (settings.stripInvisibleImg) {
if (!settings.displayImages) {
// remove images
var image_regex = /<img\s[^>]*>/gi;
content = content.replace(image_regex, "")
} else if (settings.stripInvisibleImg) {
// remove images with a height or width of 0 or 1
var height_regex = /<img\s[^>]*height="[01]"[^>]*>/gi;
content = content.replace(height_regex, "")

View file

@ -176,10 +176,18 @@ Dialog {
font.pixelSize: Theme.fontSizeSmall;
}
TextSwitch {
id: displayImagesSetting
width: parent.width
text: qsTr('Display images')
checked: settings.displayImages
}
TextSwitch {
id: stripInvisibleImgSetting
text: qsTr('Strip invisible images')
checked: settings.stripInvisibleImg
enabled: displayImagesSetting.checked
}
}
}
@ -191,6 +199,7 @@ Dialog {
settings.whiteBackgroundOnIcons = showWhiteBackgroundSetting.checked
settings.useAllFeedsOnStartup = useAllFeedsOnStartupSetting.checked
settings.useAutologin = autoLoginSetting.checked
settings.displayImages = displayImagesSetting.checked
settings.stripInvisibleImg = stripInvisibleImgSetting.checked
settings.webviewFontSize = fontSizeSetting.value
}

View file

@ -159,6 +159,13 @@ void Settings::setShowAll(bool showAll) {
}
}
void Settings::setDisplayImages(bool displayImages) {
if (_displayImages != displayImages) {
_displayImages = displayImages;
m_settings->setValue("displayImages", _displayImages);
}
}
void Settings::setStripInvisibleImg(bool stripInvisibleImg) {
if (_stripInvisibleImg != stripInvisibleImg) {
_stripInvisibleImg = stripInvisibleImg;
@ -185,5 +192,6 @@ Settings::Settings(QObject *parent) : QObject(parent), m_settings(new QSettings(
_useAllFeedsOnStartup = m_settings->value("useAllFeedsOnStartup", false).toBool();
_whiteBackgroundOnIcons = m_settings->value("whiteBackgroundOnIcons", true).toBool();
_showAll = m_settings->value("showAll", false).toBool();
_displayImages = m_settings->value("displayImages", true).toBool();
_stripInvisibleImg = m_settings->value("stripInvisibleImg", false).toBool();
}

View file

@ -49,6 +49,7 @@ class Settings : public QObject
Q_PROPERTY(bool useAllFeedsOnStartup READ useAllFeedsOnStartup WRITE setUseAllFeedsOnStartup NOTIFY useAllFeedsOnStartupChanged)
Q_PROPERTY(bool whiteBackgroundOnIcons READ whiteBackgroundOnIcons WRITE setWhiteBackgroundOnIcons NOTIFY whiteBackgroundOnIconsChanged)
Q_PROPERTY(bool showAll READ showAll WRITE setShowAll NOTIFY showAllChanged)
Q_PROPERTY(bool displayImages READ displayImages WRITE setDisplayImages)
Q_PROPERTY(bool stripInvisibleImg READ stripInvisibleImg WRITE setStripInvisibleImg)
public:
static Settings *instance();
@ -133,6 +134,11 @@ public:
}
void setShowAll(bool showAll);
bool displayImages() const {
return this->_displayImages;
}
void setDisplayImages(bool displayImages);
bool stripInvisibleImg() const {
return this->_stripInvisibleImg;
}
@ -184,6 +190,7 @@ private:
bool _useAllFeedsOnStartup;
bool _whiteBackgroundOnIcons;
bool _showAll;
bool _displayImages;
bool _stripInvisibleImg;
};
#endif // SETTINGS_HH