Merge pull request #468 from PhenomRetroShare/Add_ChatLoadEmbeddedImagesOption

Add Chat Load Embedded Images Option like forum and message.
This commit is contained in:
defnax 2016-08-13 13:16:35 +02:00 committed by GitHub
commit c01f5a31b2
7 changed files with 75 additions and 23 deletions

View File

@ -120,7 +120,7 @@ ChatWidget::ChatWidget(QWidget *parent) :
ui->actionSearchWithoutLimit->setText(tr("Don't stop to color after")+" "+QString::number(uiMaxSearchLimitColor)+" "+tr("items found (need more CPU)"));
ui->markButton->setVisible(false);
ui->markButton->setVisible(false);
ui->leSearch->setVisible(false);
ui->searchBefore->setVisible(false);
ui->searchBefore->setToolTip(tr("<b>Find Previous </b><br/><i>Ctrl+Shift+G</i>"));
@ -194,8 +194,10 @@ ChatWidget::ChatWidget(QWidget *parent) :
ui->pushtoolsButton->setMenu(menu);
menu->addMenu(fontmenu);
ui->actionSendAsPlainText->setChecked(Settings->getChatSendAsPlainTextByDef());
ui->actionSendAsPlainText->setChecked(Settings->getChatSendAsPlainTextByDef());
ui->textBrowser->resetImagesStatus(Settings->getChatLoadEmbeddedImages());
ui->textBrowser->setImageBlockWidget(ui->imageBlockWidget);
ui->textBrowser->installEventFilter(this);
ui->textBrowser->viewport()->installEventFilter(this);
ui->chatTextEdit->installEventFilter(this);

View File

@ -206,6 +206,16 @@ border-image: url(:/images/closepressed.png)
</layout>
</widget>
</item>
<item>
<widget class="RSImageBlockWidget" name="imageBlockWidget" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<widget class="QSplitter" name="chatVSplitter">
<property name="orientation">
@ -1007,6 +1017,12 @@ border-image: url(:/images/closepressed.png)
<extends>QTextEdit</extends>
<header location="global">gui/common/MimeTextEdit.h</header>
</customwidget>
<customwidget>
<class>RSImageBlockWidget</class>
<extends>QWidget</extends>
<header>gui/common/RSImageBlockWidget.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources>
<include location="../emojione.qrc"/>

View File

@ -6,6 +6,8 @@
#include "RSTextBrowser.h"
#include "RSImageBlockWidget.h"
#include <retroshare/rsinit.h> //To get RsAccounts
RSTextBrowser::RSTextBrowser(QWidget *parent) :
QTextBrowser(parent)
{
@ -74,29 +76,37 @@ void RSTextBrowser::paintEvent(QPaintEvent *event)
QVariant RSTextBrowser::loadResource(int type, const QUrl &name)
{
// case 1: always trust the image if it comes from an internal resource
if(name.scheme().compare("qrc",Qt::CaseInsensitive)==0 && type == QTextDocument::ImageResource)
return QTextBrowser::loadResource(type, name);
// case 2: only display if the user allows it. Data resources can be bad (svg bombs) but we filter them out globally at the network layer.
// It would be good to add here a home-made resource loader that only loads images and not svg crap, just in case.
if(name.scheme().compare("data",Qt::CaseInsensitive)==0 && mShowImages)
return QTextBrowser::loadResource(type, name);
// case 3: otherwise, do not display
std::cerr << "TEXTBROWSER: refusing load ressource request: type=" << type << " scheme=" << name.scheme().toStdString() << ", url=" << name.toString().toStdString() << std::endl;
if (mImageBlockWidget)
mImageBlockWidget->show();
// case 1: always trust the image if it comes from an internal resource.
//https://git.merproject.org/lbt/qtbase/commit/6d13e9f29597e0d557857e3f80173faba5368424
if(name.scheme().compare("qrc",Qt::CaseInsensitive)==0 && type == QTextDocument::ImageResource)
return QTextBrowser::loadResource(type, name);
// case 2: always trust the image if it comes from local Config or Data directories.
if(name.scheme().compare("file",Qt::CaseInsensitive)==0 && type == QTextDocument::ImageResource) {
if (name.path().startsWith(QString::fromUtf8(RsAccounts::ConfigDirectory().c_str()).prepend("/"),Qt::CaseInsensitive)
|| name.path().startsWith(QString::fromUtf8(RsAccounts::DataDirectory().c_str()).prepend("/"),Qt::CaseInsensitive))
return QTextBrowser::loadResource(type, name);
}
// case 3: only display if the user allows it. Data resources can be bad (svg bombs) but we filter them out globally at the network layer.
// It would be good to add here a home-made resource loader that only loads images and not svg crap, just in case.
if(name.scheme().compare("data",Qt::CaseInsensitive)==0 && mShowImages)
return QTextBrowser::loadResource(type, name);
// case 4: otherwise, do not display
std::cerr << "TEXTBROWSER: refusing load ressource request: type=" << type << " scheme=" << name.scheme().toStdString() << ", url=" << name.toString().toStdString() << std::endl;
if (mImageBlockWidget)
mImageBlockWidget->show();
//https://git.merproject.org/lbt/qtbase/commit/6d13e9f29597e0d557857e3f80173faba5368424
#if QT_VERSION >= QT_VERSION_CHECK (5, 0, 0)
return QPixmap(":/qt-project.org/styles/commonstyle/images/file-16.png");
return QPixmap(":/qt-project.org/styles/commonstyle/images/file-16.png");
#else
return QPixmap(":/trolltech/styles/commonstyle/images/file-16.png");
return QPixmap(":/trolltech/styles/commonstyle/images/file-16.png");
#endif
}

View File

@ -130,6 +130,7 @@ ChatPage::save(QString &/*errmsg*/)
Settings->setChatSendMessageWithCtrlReturn(ui.sendMessageWithCtrlReturn->isChecked());
Settings->setChatSendAsPlainTextByDef(ui.sendAsPlainTextByDef->isChecked());
Settings->setChatLoadEmbeddedImages(ui.loadEmbeddedImages->isChecked());
Settings->setChatSearchCharToStartSearch(ui.sbSearch_CharToStart->value());
Settings->setChatSearchCaseSensitively(ui.cbSearch_CaseSensitively->isChecked());
@ -238,6 +239,7 @@ ChatPage::load()
ui.sendMessageWithCtrlReturn->setChecked(Settings->getChatSendMessageWithCtrlReturn());
ui.sendAsPlainTextByDef->setChecked(Settings->getChatSendAsPlainTextByDef());
ui.loadEmbeddedImages->setChecked(Settings->getChatLoadEmbeddedImages());
ui.sbSearch_CharToStart->setValue(Settings->getChatSearchCharToStartSearch());
ui.cbSearch_CaseSensitively->setChecked(Settings->getChatSearchCaseSensitively());

View File

@ -218,6 +218,13 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="loadEmbeddedImages">
<property name="text">
<string>Load embedded images</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>

View File

@ -345,6 +345,8 @@ static QString getKeyForLastDir(RshareSettings::enumLastDir type)
return "Messages";
case RshareSettings::LASTDIR_SOUNDS:
return "SOUNDS";
case RshareSettings::LASTDIR_PLUGIN:
return "PLUGIN";
}
return "";
}
@ -601,6 +603,16 @@ QRgb RshareSettings::getChatSearchFoundColor()
return valueFromGroup("Chat", "SearchMaxSearchFoundColor", QString::number(QColor(255,255,150).rgba())).toUInt();
}
bool RshareSettings::getChatLoadEmbeddedImages()
{
return valueFromGroup("Chat", "LoadEmbeddedImages", true).toBool();
}
void RshareSettings::setChatLoadEmbeddedImages(bool value)
{
setValueToGroup("Chat", "LoadEmbeddedImages", value);
}
RshareSettings::enumToasterPosition RshareSettings::getToasterPosition()
{
return (enumToasterPosition) value("ToasterPosition", TOASTERPOS_BOTTOMRIGHT).toInt();

View File

@ -237,6 +237,9 @@ public:
void setChatSearchFoundColor(QRgb rgbValue);
QRgb getChatSearchFoundColor();
bool getChatLoadEmbeddedImages();
void setChatLoadEmbeddedImages(bool value);
enumToasterPosition getToasterPosition();
void setToasterPosition(enumToasterPosition position);