Skip to content

Commit

Permalink
Log: remove the notion of an invalid LogDocument.
Browse files Browse the repository at this point in the history
Previously, the invalid state for a LogDocument that contained images
that Mumble deemed invalid.

For example, if Mumble was configured to not download external iamges,
a LogDocument that contained references to external images would be
marked as invalid, and would not show up in the user's log. Instead,
the whole message would be shown as "[[ No valid image ]]".

With this change, Mumble will instead show the message, but replace
the images with a 'broken image' marker (currently, Qt shows a 1x1
black image.)

This makes the 'Disable image download' option in Mumble more usable.
Before, messages that contained external (i.e, HTTP/HTTPS) images would
not be shown at all. This was not desirable, since such messages could
potentially contain messages alongside the images.
  • Loading branch information
mkrautz committed Jul 9, 2017
1 parent a4e859e commit ab783c7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 37 deletions.
44 changes: 8 additions & 36 deletions src/mumble/Log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,6 @@ QString Log::imageToImg(QImage img) {
QString Log::validHtml(const QString &html, bool allowReplacement, QTextCursor *tc) {
QDesktopWidget dw;
LogDocument qtd;
bool valid = false;

qtd.setAllowHTTPResources(allowReplacement);
qtd.setOnlyLoadDataURLs(true);
Expand All @@ -382,7 +381,6 @@ QString Log::validHtml(const QString &html, bool allowReplacement, QTextCursor *
// data URL images to run.
(void) qtd.documentLayout();
qtd.setHtml(html);
valid = qtd.isValid();

QStringList qslAllowed = allowedSchemes();
for (QTextBlock qtb = qtd.begin(); qtb != qtd.end(); qtb = qtb.next()) {
Expand All @@ -400,22 +398,6 @@ QString Log::validHtml(const QString &html, bool allowReplacement, QTextCursor *
qtbi = qtb.begin();
}
}
if (qcf.isImageFormat()) {
QTextImageFormat qtif = qcf.toImageFormat();
QUrl url(qtif.name());
if (! qtif.name().isEmpty() && ! url.isValid())
valid = false;
}
}
}

if (!valid) {
QString errorImageMessage = tr("[[ No valid image ]]");
if (tc) {
tc->insertText(errorImageMessage);
return QString();
} else {
return errorImageMessage;
}
}

Expand Down Expand Up @@ -594,26 +576,25 @@ void Log::postQtNotification(MsgType mt, const QString &plain) {
LogDocument::LogDocument(QObject *p)
: QTextDocument(p)
, m_allowHTTPResources(true)
, m_valid(true)
, m_onlyLoadDataURLs(false) {
}

QVariant LogDocument::loadResource(int type, const QUrl &url) {
// Ignore requests for all external resources
// that aren't images. We don't support any of them.
if (type != QTextDocument::ImageResource) {
m_valid = false;
return QLatin1String("No external resources allowed.");
}

if (url.scheme() != QLatin1String("data") && g.s.iMaxImageSize <= 0) {
m_valid = false;
return QLatin1String("Image download disabled.");
addResource(type, url, QByteArray());
return QByteArray();
}

QImage qi(1, 1, QImage::Format_Mono);
addResource(type, url, qi);

if (url.scheme() != QLatin1String("data") && g.s.iMaxImageSize <= 0) {
return qi;
}

if (! url.isValid() || url.isRelative()) {
m_valid = false;
return qi;
}

Expand All @@ -625,7 +606,6 @@ QVariant LogDocument::loadResource(int type, const QUrl &url) {
}

if (!allowedSchemes.contains(url.scheme())) {
m_valid = false;
return qi;
}

Expand Down Expand Up @@ -658,10 +638,6 @@ void LogDocument::setOnlyLoadDataURLs(bool onlyLoadDataURLs) {
m_onlyLoadDataURLs = onlyLoadDataURLs;
}

bool LogDocument::isValid() {
return m_valid;
}

void LogDocument::receivedHead() {
QNetworkReply *rep = qobject_cast<QNetworkReply *>(sender());
if (rep->url().scheme() != QLatin1String("data")) {
Expand Down Expand Up @@ -708,12 +684,8 @@ void LogDocument::finished() {
e = new LogDocumentResourceAddedEvent();
QApplication::postEvent(qte, e);
}
} else {
m_valid = false;
}
}
} else {
m_valid = false;
}
}

Expand Down
1 change: 0 additions & 1 deletion src/mumble/Log.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ class LogDocument : public QTextDocument {
QVariant loadResource(int, const QUrl &) Q_DECL_OVERRIDE;
void setAllowHTTPResources(bool allowHttpResources);
void setOnlyLoadDataURLs(bool onlyLoadDataURLs);
bool isValid();
public slots:
void receivedHead();
void finished();
Expand Down

0 comments on commit ab783c7

Please sign in to comment.