From f71aad4b9cd73019638b631e292bde86a615730f Mon Sep 17 00:00:00 2001 From: Phenom Date: Tue, 9 Aug 2016 23:32:25 +0200 Subject: [PATCH 1/2] Add Chat Load Embedded Images Option like forum and message. --- retroshare-gui/src/gui/chat/ChatWidget.cpp | 8 +++++--- retroshare-gui/src/gui/chat/ChatWidget.ui | 16 ++++++++++++++++ retroshare-gui/src/gui/settings/ChatPage.cpp | 2 ++ retroshare-gui/src/gui/settings/ChatPage.ui | 7 +++++++ .../src/gui/settings/rsharesettings.cpp | 12 ++++++++++++ retroshare-gui/src/gui/settings/rsharesettings.h | 3 +++ 6 files changed, 45 insertions(+), 3 deletions(-) diff --git a/retroshare-gui/src/gui/chat/ChatWidget.cpp b/retroshare-gui/src/gui/chat/ChatWidget.cpp index 1540722bd..2fcf49f81 100644 --- a/retroshare-gui/src/gui/chat/ChatWidget.cpp +++ b/retroshare-gui/src/gui/chat/ChatWidget.cpp @@ -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("Find Previous
Ctrl+Shift+G")); @@ -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); diff --git a/retroshare-gui/src/gui/chat/ChatWidget.ui b/retroshare-gui/src/gui/chat/ChatWidget.ui index e1e5cf0b8..1b9f57b71 100644 --- a/retroshare-gui/src/gui/chat/ChatWidget.ui +++ b/retroshare-gui/src/gui/chat/ChatWidget.ui @@ -206,6 +206,16 @@ border-image: url(:/images/closepressed.png) + + + + + 0 + 0 + + + + @@ -1007,6 +1017,12 @@ border-image: url(:/images/closepressed.png) QTextEdit
gui/common/MimeTextEdit.h
+ + RSImageBlockWidget + QWidget +
gui/common/RSImageBlockWidget.h
+ 1 +
diff --git a/retroshare-gui/src/gui/settings/ChatPage.cpp b/retroshare-gui/src/gui/settings/ChatPage.cpp index a53d62293..e4e32abdf 100644 --- a/retroshare-gui/src/gui/settings/ChatPage.cpp +++ b/retroshare-gui/src/gui/settings/ChatPage.cpp @@ -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()); diff --git a/retroshare-gui/src/gui/settings/ChatPage.ui b/retroshare-gui/src/gui/settings/ChatPage.ui index 706339756..d9569af3f 100644 --- a/retroshare-gui/src/gui/settings/ChatPage.ui +++ b/retroshare-gui/src/gui/settings/ChatPage.ui @@ -218,6 +218,13 @@
+ + + + Load embedded images + + + diff --git a/retroshare-gui/src/gui/settings/rsharesettings.cpp b/retroshare-gui/src/gui/settings/rsharesettings.cpp index 4011f4a9b..530ffd766 100644 --- a/retroshare-gui/src/gui/settings/rsharesettings.cpp +++ b/retroshare-gui/src/gui/settings/rsharesettings.cpp @@ -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(); diff --git a/retroshare-gui/src/gui/settings/rsharesettings.h b/retroshare-gui/src/gui/settings/rsharesettings.h index a7719c6d0..a693deaf3 100644 --- a/retroshare-gui/src/gui/settings/rsharesettings.h +++ b/retroshare-gui/src/gui/settings/rsharesettings.h @@ -237,6 +237,9 @@ public: void setChatSearchFoundColor(QRgb rgbValue); QRgb getChatSearchFoundColor(); + bool getChatLoadEmbeddedImages(); + void setChatLoadEmbeddedImages(bool value); + enumToasterPosition getToasterPosition(); void setToasterPosition(enumToasterPosition position); From fcad9d99abdbd14b6592505f5756d58b12ceebff Mon Sep 17 00:00:00 2001 From: Phenom Date: Sat, 13 Aug 2016 10:42:42 +0200 Subject: [PATCH 2/2] Fix RSTextBrowser::loadResource if image comes from stylesheet. --- .../src/gui/common/RSTextBrowser.cpp | 50 +++++++++++-------- 1 file changed, 30 insertions(+), 20 deletions(-) diff --git a/retroshare-gui/src/gui/common/RSTextBrowser.cpp b/retroshare-gui/src/gui/common/RSTextBrowser.cpp index 87f77c437..edeaa473e 100644 --- a/retroshare-gui/src/gui/common/RSTextBrowser.cpp +++ b/retroshare-gui/src/gui/common/RSTextBrowser.cpp @@ -6,6 +6,8 @@ #include "RSTextBrowser.h" #include "RSImageBlockWidget.h" +#include //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 }