From 727800ef2cf895f311400013e4e4628de5a2afce Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Wed, 23 May 2018 18:00:49 +0800 Subject: [PATCH] Improve DownloadFromURL behavior URL should be considered case sensitive. --- src/gui/downloadfromurldialog.cpp | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/src/gui/downloadfromurldialog.cpp b/src/gui/downloadfromurldialog.cpp index 28f09a262..8502e7000 100644 --- a/src/gui/downloadfromurldialog.cpp +++ b/src/gui/downloadfromurldialog.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include #include @@ -55,25 +56,22 @@ DownloadFromURLDialog::DownloadFromURLDialog(QWidget *parent) // Paste clipboard if there is an URL in it const QStringList clipboardList = qApp->clipboard()->text().split('\n'); - QStringList clipboardListCleaned; + QSet uniqueURLs; for (QString str : clipboardList) { str = str.trimmed(); if (str.isEmpty()) continue; - if (!clipboardListCleaned.contains(str, Qt::CaseInsensitive)) { - if (str.startsWith("http://", Qt::CaseInsensitive) - || str.startsWith("https://", Qt::CaseInsensitive) - || str.startsWith("ftp://", Qt::CaseInsensitive) - || str.startsWith("magnet:", Qt::CaseInsensitive) - || str.startsWith("bc://bt/", Qt::CaseInsensitive) - || (str.size() == 40 && !str.contains(QRegExp("[^0-9A-Fa-f]"))) - || (str.size() == 32 && !str.contains(QRegExp("[^2-7A-Za-z]")))) { - clipboardListCleaned << str; - } + if (str.startsWith("http://", Qt::CaseInsensitive) + || str.startsWith("https://", Qt::CaseInsensitive) + || str.startsWith("ftp://", Qt::CaseInsensitive) + || str.startsWith("magnet:", Qt::CaseInsensitive) + || str.startsWith("bc://bt/", Qt::CaseInsensitive) + || ((str.size() == 40) && !str.contains(QRegExp("[^0-9A-Fa-f]"))) + || ((str.size() == 32) && !str.contains(QRegExp("[^2-7A-Za-z]")))) { + uniqueURLs << str; } } - if (!clipboardListCleaned.isEmpty()) - m_ui->textUrls->setText(clipboardListCleaned.join('\n')); + m_ui->textUrls->setText(uniqueURLs.toList().join('\n')); Utils::Gui::resize(this); show(); @@ -88,13 +86,12 @@ void DownloadFromURLDialog::downloadButtonClicked() { const QStringList urls = m_ui->textUrls->toPlainText().split('\n'); - QStringList uniqueURLs; + QSet uniqueURLs; for (QString url : urls) { url = url.trimmed(); if (url.isEmpty()) continue; - if (!uniqueURLs.contains(url, Qt::CaseInsensitive)) - uniqueURLs << url; + uniqueURLs << url; } if (uniqueURLs.isEmpty()) { @@ -102,6 +99,6 @@ void DownloadFromURLDialog::downloadButtonClicked() return; } - emit urlsReadyToBeDownloaded(uniqueURLs); + emit urlsReadyToBeDownloaded(uniqueURLs.toList()); accept(); }