Browse Source

Add Utils::String::toHtmlEscaped

adaptive-webui-19844
Chocobo1 8 years ago committed by sledgehammer999
parent
commit
6ca3e4f094
No known key found for this signature in database
GPG Key ID: 6E4A2D025B7CC9A2
  1. 5
      src/base/logger.cpp
  2. 9
      src/base/utils/string.cpp
  3. 2
      src/base/utils/string.h
  4. 5
      src/gui/deletionconfirmationdlg.h
  5. 4
      src/gui/properties/peerlistwidget.cpp
  6. 4
      src/gui/properties/propertieswidget.cpp

5
src/base/logger.cpp

@ -1,6 +1,7 @@
#include "logger.h" #include "logger.h"
#include <QDateTime> #include <QDateTime>
#include "base/utils/string.h"
Logger* Logger::m_instance = 0; Logger* Logger::m_instance = 0;
@ -36,7 +37,7 @@ void Logger::addMessage(const QString &message, const Log::MsgType &type)
{ {
QWriteLocker locker(&lock); QWriteLocker locker(&lock);
Log::Msg temp = { msgCounter++, QDateTime::currentMSecsSinceEpoch(), type, message }; Log::Msg temp = { msgCounter++, QDateTime::currentMSecsSinceEpoch(), type, Utils::String::toHtmlEscaped(message) };
m_messages.push_back(temp); m_messages.push_back(temp);
if (m_messages.size() >= MAX_LOG_MESSAGES) if (m_messages.size() >= MAX_LOG_MESSAGES)
@ -49,7 +50,7 @@ void Logger::addPeer(const QString &ip, bool blocked, const QString &reason)
{ {
QWriteLocker locker(&lock); QWriteLocker locker(&lock);
Log::Peer temp = { peerCounter++, QDateTime::currentMSecsSinceEpoch(), ip, blocked, reason }; Log::Peer temp = { peerCounter++, QDateTime::currentMSecsSinceEpoch(), Utils::String::toHtmlEscaped(ip), blocked, Utils::String::toHtmlEscaped(reason) };
m_peers.push_back(temp); m_peers.push_back(temp);
if (m_peers.size() >= MAX_LOG_MESSAGES) if (m_peers.size() >= MAX_LOG_MESSAGES)

9
src/base/utils/string.cpp

@ -211,3 +211,12 @@ bool Utils::String::slowEquals(const QByteArray &a, const QByteArray &b)
return (diff == 0); return (diff == 0);
} }
QString Utils::String::toHtmlEscaped(const QString &str)
{
#ifdef QBT_USES_QT5
return str.toHtmlEscaped();
#else
return Qt::escape(str);
#endif
}

2
src/base/utils/string.h

@ -47,6 +47,8 @@ namespace Utils
// Taken from https://crackstation.net/hashing-security.htm // Taken from https://crackstation.net/hashing-security.htm
bool slowEquals(const QByteArray &a, const QByteArray &b); bool slowEquals(const QByteArray &a, const QByteArray &b);
QString toHtmlEscaped(const QString &str);
bool naturalCompareCaseSensitive(const QString &left, const QString &right); bool naturalCompareCaseSensitive(const QString &left, const QString &right);
bool naturalCompareCaseInsensitive(const QString &left, const QString &right); bool naturalCompareCaseInsensitive(const QString &left, const QString &right);
} }

5
src/gui/deletionconfirmationdlg.h

@ -35,8 +35,9 @@
#include <QPushButton> #include <QPushButton>
#include "ui_confirmdeletiondlg.h" #include "ui_confirmdeletiondlg.h"
#include "base/preferences.h" #include "base/preferences.h"
#include "guiiconprovider.h"
#include "base/utils/misc.h" #include "base/utils/misc.h"
#include "base/utils/string.h"
#include "guiiconprovider.h"
class DeletionConfirmationDlg : public QDialog, private Ui::confirmDeletionDlg { class DeletionConfirmationDlg : public QDialog, private Ui::confirmDeletionDlg {
Q_OBJECT Q_OBJECT
@ -45,7 +46,7 @@ class DeletionConfirmationDlg : public QDialog, private Ui::confirmDeletionDlg {
DeletionConfirmationDlg(QWidget *parent, const int &size, const QString &name, bool defaultDeleteFiles): QDialog(parent) { DeletionConfirmationDlg(QWidget *parent, const int &size, const QString &name, bool defaultDeleteFiles): QDialog(parent) {
setupUi(this); setupUi(this);
if (size == 1) if (size == 1)
label->setText(tr("Are you sure you want to delete '%1' from the transfer list?", "Are you sure you want to delete 'ubuntu-linux-iso' from the transfer list?").arg(name)); label->setText(tr("Are you sure you want to delete '%1' from the transfer list?", "Are you sure you want to delete 'ubuntu-linux-iso' from the transfer list?").arg(Utils::String::toHtmlEscaped(name)));
else else
label->setText(tr("Are you sure you want to delete these %1 torrents from the transfer list?", "Are you sure you want to delete these 5 torrents from the transfer list?").arg(QString::number(size))); label->setText(tr("Are you sure you want to delete these %1 torrents from the transfer list?", "Are you sure you want to delete these 5 torrents from the transfer list?").arg(QString::number(size)));
// Icons // Icons

4
src/gui/properties/peerlistwidget.cpp

@ -401,7 +401,7 @@ QStandardItem* PeerListWidget::addPeer(const QString& ip, BitTorrent::TorrentHan
m_listModel->setData(m_listModel->index(row, PeerListDelegate::CONNECTION), peer.connectionType()); m_listModel->setData(m_listModel->index(row, PeerListDelegate::CONNECTION), peer.connectionType());
m_listModel->setData(m_listModel->index(row, PeerListDelegate::FLAGS), peer.flags()); m_listModel->setData(m_listModel->index(row, PeerListDelegate::FLAGS), peer.flags());
m_listModel->setData(m_listModel->index(row, PeerListDelegate::FLAGS), peer.flagsDescription(), Qt::ToolTipRole); m_listModel->setData(m_listModel->index(row, PeerListDelegate::FLAGS), peer.flagsDescription(), Qt::ToolTipRole);
m_listModel->setData(m_listModel->index(row, PeerListDelegate::CLIENT), peer.client()); m_listModel->setData(m_listModel->index(row, PeerListDelegate::CLIENT), Utils::String::toHtmlEscaped(peer.client()));
m_listModel->setData(m_listModel->index(row, PeerListDelegate::PROGRESS), peer.progress()); m_listModel->setData(m_listModel->index(row, PeerListDelegate::PROGRESS), peer.progress());
m_listModel->setData(m_listModel->index(row, PeerListDelegate::DOWN_SPEED), peer.payloadDownSpeed()); m_listModel->setData(m_listModel->index(row, PeerListDelegate::DOWN_SPEED), peer.payloadDownSpeed());
m_listModel->setData(m_listModel->index(row, PeerListDelegate::UP_SPEED), peer.payloadUpSpeed()); m_listModel->setData(m_listModel->index(row, PeerListDelegate::UP_SPEED), peer.payloadUpSpeed());
@ -432,7 +432,7 @@ void PeerListWidget::updatePeer(const QString &ip, BitTorrent::TorrentHandle *co
m_listModel->setData(m_listModel->index(row, PeerListDelegate::PORT), peer.address().port); m_listModel->setData(m_listModel->index(row, PeerListDelegate::PORT), peer.address().port);
m_listModel->setData(m_listModel->index(row, PeerListDelegate::FLAGS), peer.flags()); m_listModel->setData(m_listModel->index(row, PeerListDelegate::FLAGS), peer.flags());
m_listModel->setData(m_listModel->index(row, PeerListDelegate::FLAGS), peer.flagsDescription(), Qt::ToolTipRole); m_listModel->setData(m_listModel->index(row, PeerListDelegate::FLAGS), peer.flagsDescription(), Qt::ToolTipRole);
m_listModel->setData(m_listModel->index(row, PeerListDelegate::CLIENT), peer.client()); m_listModel->setData(m_listModel->index(row, PeerListDelegate::CLIENT), Utils::String::toHtmlEscaped(peer.client()));
m_listModel->setData(m_listModel->index(row, PeerListDelegate::PROGRESS), peer.progress()); m_listModel->setData(m_listModel->index(row, PeerListDelegate::PROGRESS), peer.progress());
m_listModel->setData(m_listModel->index(row, PeerListDelegate::DOWN_SPEED), peer.payloadDownSpeed()); m_listModel->setData(m_listModel->index(row, PeerListDelegate::DOWN_SPEED), peer.payloadDownSpeed());
m_listModel->setData(m_listModel->index(row, PeerListDelegate::UP_SPEED), peer.payloadUpSpeed()); m_listModel->setData(m_listModel->index(row, PeerListDelegate::UP_SPEED), peer.payloadUpSpeed());

4
src/gui/properties/propertieswidget.cpp

@ -314,12 +314,12 @@ void PropertiesWidget::loadTorrentInfos(BitTorrent::TorrentHandle *const torrent
label_total_size_val->setText(Utils::Misc::friendlyUnit(m_torrent->totalSize())); label_total_size_val->setText(Utils::Misc::friendlyUnit(m_torrent->totalSize()));
// Comment // Comment
comment_text->setText(Utils::Misc::parseHtmlLinks(m_torrent->comment())); comment_text->setText(Utils::Misc::parseHtmlLinks(Utils::String::toHtmlEscaped(m_torrent->comment())));
// URL seeds // URL seeds
loadUrlSeeds(); loadUrlSeeds();
label_created_by_val->setText(m_torrent->creator()); label_created_by_val->setText(Utils::String::toHtmlEscaped(m_torrent->creator()));
// List files in torrent // List files in torrent
PropListModel->model()->setupModelData(m_torrent->info()); PropListModel->model()->setupModelData(m_torrent->info());

Loading…
Cancel
Save