mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2024-10-22 10:46:04 +03:00
Fix handling of tags containing '&' character
PR #21024. Closes #20773.
This commit is contained in:
parent
4149609e78
commit
127d2d6f0b
4 changed files with 42 additions and 6 deletions
|
@ -1,6 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* Bittorrent Client using Qt and libtorrent.
|
* Bittorrent Client using Qt and libtorrent.
|
||||||
* Copyright (C) 2023 Vladimir Golovnev <glassez@yandex.ru>
|
* Copyright (C) 2023-2024 Vladimir Golovnev <glassez@yandex.ru>
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or
|
* This program is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU General Public License
|
* modify it under the terms of the GNU General Public License
|
||||||
|
@ -37,6 +37,7 @@
|
||||||
#include "base/global.h"
|
#include "base/global.h"
|
||||||
#include "autoexpandabledialog.h"
|
#include "autoexpandabledialog.h"
|
||||||
#include "flowlayout.h"
|
#include "flowlayout.h"
|
||||||
|
#include "utils.h"
|
||||||
|
|
||||||
#include "ui_torrenttagsdialog.h"
|
#include "ui_torrenttagsdialog.h"
|
||||||
|
|
||||||
|
@ -55,7 +56,7 @@ TorrentTagsDialog::TorrentTagsDialog(const TagSet &initialTags, QWidget *parent)
|
||||||
auto *tagsLayout = new FlowLayout(m_ui->scrollArea);
|
auto *tagsLayout = new FlowLayout(m_ui->scrollArea);
|
||||||
for (const Tag &tag : asConst(initialTags.united(BitTorrent::Session::instance()->tags())))
|
for (const Tag &tag : asConst(initialTags.united(BitTorrent::Session::instance()->tags())))
|
||||||
{
|
{
|
||||||
auto *tagWidget = new QCheckBox(tag.toString());
|
auto *tagWidget = new QCheckBox(Utils::Gui::tagToWidgetText(tag));
|
||||||
if (initialTags.contains(tag))
|
if (initialTags.contains(tag))
|
||||||
tagWidget->setChecked(true);
|
tagWidget->setChecked(true);
|
||||||
tagsLayout->addWidget(tagWidget);
|
tagsLayout->addWidget(tagWidget);
|
||||||
|
@ -83,7 +84,7 @@ TagSet TorrentTagsDialog::tags() const
|
||||||
{
|
{
|
||||||
const auto *tagWidget = static_cast<QCheckBox *>(layout->itemAt(i)->widget());
|
const auto *tagWidget = static_cast<QCheckBox *>(layout->itemAt(i)->widget());
|
||||||
if (tagWidget->isChecked())
|
if (tagWidget->isChecked())
|
||||||
tags.insert(Tag(tagWidget->text()));
|
tags.insert(Utils::Gui::widgetTextToTag(tagWidget->text()));
|
||||||
}
|
}
|
||||||
|
|
||||||
return tags;
|
return tags;
|
||||||
|
@ -113,7 +114,7 @@ void TorrentTagsDialog::addNewTag()
|
||||||
{
|
{
|
||||||
auto *layout = m_ui->scrollArea->layout();
|
auto *layout = m_ui->scrollArea->layout();
|
||||||
auto *btn = layout->takeAt(layout->count() - 1);
|
auto *btn = layout->takeAt(layout->count() - 1);
|
||||||
auto *tagWidget = new QCheckBox(tag.toString());
|
auto *tagWidget = new QCheckBox(Utils::Gui::tagToWidgetText(tag));
|
||||||
tagWidget->setChecked(true);
|
tagWidget->setChecked(true);
|
||||||
layout->addWidget(tagWidget);
|
layout->addWidget(tagWidget);
|
||||||
layout->addItem(btn);
|
layout->addItem(btn);
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* Bittorrent Client using Qt and libtorrent.
|
* Bittorrent Client using Qt and libtorrent.
|
||||||
* Copyright (C) 2023 Vladimir Golovnev <glassez@yandex.ru>
|
* Copyright (C) 2023-2024 Vladimir Golovnev <glassez@yandex.ru>
|
||||||
* Copyright (C) 2006 Christophe Dumez <chris@qbittorrent.org>
|
* Copyright (C) 2006 Christophe Dumez <chris@qbittorrent.org>
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or
|
* This program is free software; you can redistribute it and/or
|
||||||
|
@ -1191,7 +1191,7 @@ void TransferListWidget::displayListMenu()
|
||||||
const TagSet tags = BitTorrent::Session::instance()->tags();
|
const TagSet tags = BitTorrent::Session::instance()->tags();
|
||||||
for (const Tag &tag : asConst(tags))
|
for (const Tag &tag : asConst(tags))
|
||||||
{
|
{
|
||||||
auto *action = new TriStateAction(tag.toString(), tagsMenu);
|
auto *action = new TriStateAction(Utils::Gui::tagToWidgetText(tag), tagsMenu);
|
||||||
action->setCloseOnInteraction(false);
|
action->setCloseOnInteraction(false);
|
||||||
|
|
||||||
const Qt::CheckState initialState = tagsInAll.contains(tag) ? Qt::Checked
|
const Qt::CheckState initialState = tagsInAll.contains(tag) ? Qt::Checked
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* Bittorrent Client using Qt and libtorrent.
|
* Bittorrent Client using Qt and libtorrent.
|
||||||
|
* Copyright (C) 2024 Vladimir Golovnev <glassez@yandex.ru>
|
||||||
* Copyright (C) 2017 Mike Tzou
|
* Copyright (C) 2017 Mike Tzou
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or
|
* This program is free software; you can redistribute it and/or
|
||||||
|
@ -54,6 +55,7 @@
|
||||||
|
|
||||||
#include "base/global.h"
|
#include "base/global.h"
|
||||||
#include "base/path.h"
|
#include "base/path.h"
|
||||||
|
#include "base/tag.h"
|
||||||
#include "base/utils/fs.h"
|
#include "base/utils/fs.h"
|
||||||
#include "base/utils/version.h"
|
#include "base/utils/version.h"
|
||||||
|
|
||||||
|
@ -216,3 +218,29 @@ void Utils::Gui::openFolderSelect(const Path &path)
|
||||||
openPath(path.parentPath());
|
openPath(path.parentPath());
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString Utils::Gui::tagToWidgetText(const Tag &tag)
|
||||||
|
{
|
||||||
|
return tag.toString().replace(u'&', u"&&"_s);
|
||||||
|
}
|
||||||
|
|
||||||
|
Tag Utils::Gui::widgetTextToTag(const QString &text)
|
||||||
|
{
|
||||||
|
// replace pairs of '&' with single '&' and remove non-paired occurrences of '&'
|
||||||
|
QString cleanedText;
|
||||||
|
cleanedText.reserve(text.size());
|
||||||
|
bool amp = false;
|
||||||
|
for (const QChar c : text)
|
||||||
|
{
|
||||||
|
if (c == u'&')
|
||||||
|
{
|
||||||
|
amp = !amp;
|
||||||
|
if (amp)
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
cleanedText.append(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Tag(cleanedText);
|
||||||
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* Bittorrent Client using Qt and libtorrent.
|
* Bittorrent Client using Qt and libtorrent.
|
||||||
|
* Copyright (C) 2024 Vladimir Golovnev <glassez@yandex.ru>
|
||||||
* Copyright (C) 2017 Mike Tzou
|
* Copyright (C) 2017 Mike Tzou
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or
|
* This program is free software; you can redistribute it and/or
|
||||||
|
@ -34,8 +35,11 @@ class QIcon;
|
||||||
class QPixmap;
|
class QPixmap;
|
||||||
class QPoint;
|
class QPoint;
|
||||||
class QSize;
|
class QSize;
|
||||||
|
class QString;
|
||||||
class QWidget;
|
class QWidget;
|
||||||
|
|
||||||
|
class Tag;
|
||||||
|
|
||||||
namespace Utils::Gui
|
namespace Utils::Gui
|
||||||
{
|
{
|
||||||
bool isDarkTheme();
|
bool isDarkTheme();
|
||||||
|
@ -51,4 +55,7 @@ namespace Utils::Gui
|
||||||
|
|
||||||
void openPath(const Path &path);
|
void openPath(const Path &path);
|
||||||
void openFolderSelect(const Path &path);
|
void openFolderSelect(const Path &path);
|
||||||
|
|
||||||
|
QString tagToWidgetText(const Tag &tag);
|
||||||
|
Tag widgetTextToTag(const QString &text);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue