mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-02-09 21:34:20 +00:00
Don't reorder URLs when copied from the clipboard
Also process URLs in the same order as from the text edit widget. Closes #17693. PR #17700.
This commit is contained in:
parent
257914b0d5
commit
6c60fa5161
@ -36,6 +36,7 @@
|
|||||||
#include <QSet>
|
#include <QSet>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
|
#include <QStringView>
|
||||||
|
|
||||||
#include "ui_downloadfromurldialog.h"
|
#include "ui_downloadfromurldialog.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
@ -76,19 +77,23 @@ DownloadFromURLDialog::DownloadFromURLDialog(QWidget *parent)
|
|||||||
const QString clipboardText = qApp->clipboard()->text();
|
const QString clipboardText = qApp->clipboard()->text();
|
||||||
const QList<QStringView> clipboardList = QStringView(clipboardText).split(u'\n');
|
const QList<QStringView> clipboardList = QStringView(clipboardText).split(u'\n');
|
||||||
|
|
||||||
QSet<QString> uniqueURLs;
|
// show urls in the original order as from the clipboard
|
||||||
for (QStringView strRef : clipboardList)
|
QStringList urls;
|
||||||
{
|
urls.reserve(clipboardList.size());
|
||||||
strRef = strRef.trimmed();
|
|
||||||
if (strRef.isEmpty()) continue;
|
|
||||||
|
|
||||||
const QString str = strRef.toString();
|
for (QStringView url : clipboardList)
|
||||||
if (isDownloadable(str))
|
{
|
||||||
uniqueURLs << str;
|
url = url.trimmed();
|
||||||
|
|
||||||
|
if (url.isEmpty())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (const QString urlString = url.toString(); isDownloadable(urlString))
|
||||||
|
urls << urlString;
|
||||||
}
|
}
|
||||||
|
|
||||||
const QString text = uniqueURLs.values().join(u'\n')
|
const QString text = urls.join(u'\n')
|
||||||
+ (!uniqueURLs.isEmpty() ? u"\n" : u"");
|
+ (!urls.isEmpty() ? u"\n" : u"");
|
||||||
|
|
||||||
m_ui->textUrls->setText(text);
|
m_ui->textUrls->setText(text);
|
||||||
m_ui->textUrls->moveCursor(QTextCursor::End);
|
m_ui->textUrls->moveCursor(QTextCursor::End);
|
||||||
@ -108,22 +113,32 @@ void DownloadFromURLDialog::onSubmit()
|
|||||||
const QString plainText = m_ui->textUrls->toPlainText();
|
const QString plainText = m_ui->textUrls->toPlainText();
|
||||||
const QList<QStringView> urls = QStringView(plainText).split(u'\n');
|
const QList<QStringView> urls = QStringView(plainText).split(u'\n');
|
||||||
|
|
||||||
QSet<QString> uniqueURLs;
|
// process urls in the original order as from the widget
|
||||||
|
QSet<QStringView> uniqueURLs;
|
||||||
|
QStringList urlList;
|
||||||
|
urlList.reserve(urls.size());
|
||||||
|
|
||||||
for (QStringView url : urls)
|
for (QStringView url : urls)
|
||||||
{
|
{
|
||||||
url = url.trimmed();
|
url = url.trimmed();
|
||||||
if (url.isEmpty()) continue;
|
|
||||||
|
|
||||||
uniqueURLs << url.toString();
|
if (url.isEmpty())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (!uniqueURLs.contains(url))
|
||||||
|
{
|
||||||
|
uniqueURLs.insert(url);
|
||||||
|
urlList << url.toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (uniqueURLs.isEmpty())
|
if (urlList.isEmpty())
|
||||||
{
|
{
|
||||||
QMessageBox::warning(this, tr("No URL entered"), tr("Please type at least one URL."));
|
QMessageBox::warning(this, tr("No URL entered"), tr("Please type at least one URL."));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
emit urlsReadyToBeDownloaded(uniqueURLs.values());
|
emit urlsReadyToBeDownloaded(urlList);
|
||||||
accept();
|
accept();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user