Browse Source

Improve DownloadFromURL behavior

URL should be considered case sensitive.
adaptive-webui-19844
Chocobo1 7 years ago
parent
commit
727800ef2c
No known key found for this signature in database
GPG Key ID: 210D9C873253A68C
  1. 31
      src/gui/downloadfromurldialog.cpp

31
src/gui/downloadfromurldialog.cpp

@ -32,6 +32,7 @@
#include <QMessageBox> #include <QMessageBox>
#include <QPushButton> #include <QPushButton>
#include <QRegExp> #include <QRegExp>
#include <QSet>
#include <QString> #include <QString>
#include <QStringList> #include <QStringList>
@ -55,25 +56,22 @@ DownloadFromURLDialog::DownloadFromURLDialog(QWidget *parent)
// Paste clipboard if there is an URL in it // Paste clipboard if there is an URL in it
const QStringList clipboardList = qApp->clipboard()->text().split('\n'); const QStringList clipboardList = qApp->clipboard()->text().split('\n');
QStringList clipboardListCleaned; QSet<QString> uniqueURLs;
for (QString str : clipboardList) { for (QString str : clipboardList) {
str = str.trimmed(); str = str.trimmed();
if (str.isEmpty()) continue; if (str.isEmpty()) continue;
if (!clipboardListCleaned.contains(str, Qt::CaseInsensitive)) { if (str.startsWith("http://", Qt::CaseInsensitive)
if (str.startsWith("http://", Qt::CaseInsensitive) || str.startsWith("https://", Qt::CaseInsensitive)
|| str.startsWith("https://", Qt::CaseInsensitive) || str.startsWith("ftp://", Qt::CaseInsensitive)
|| str.startsWith("ftp://", Qt::CaseInsensitive) || str.startsWith("magnet:", Qt::CaseInsensitive)
|| str.startsWith("magnet:", Qt::CaseInsensitive) || str.startsWith("bc://bt/", Qt::CaseInsensitive)
|| str.startsWith("bc://bt/", Qt::CaseInsensitive) || ((str.size() == 40) && !str.contains(QRegExp("[^0-9A-Fa-f]")))
|| (str.size() == 40 && !str.contains(QRegExp("[^0-9A-Fa-f]"))) || ((str.size() == 32) && !str.contains(QRegExp("[^2-7A-Za-z]")))) {
|| (str.size() == 32 && !str.contains(QRegExp("[^2-7A-Za-z]")))) { uniqueURLs << str;
clipboardListCleaned << str;
}
} }
} }
if (!clipboardListCleaned.isEmpty()) m_ui->textUrls->setText(uniqueURLs.toList().join('\n'));
m_ui->textUrls->setText(clipboardListCleaned.join('\n'));
Utils::Gui::resize(this); Utils::Gui::resize(this);
show(); show();
@ -88,13 +86,12 @@ void DownloadFromURLDialog::downloadButtonClicked()
{ {
const QStringList urls = m_ui->textUrls->toPlainText().split('\n'); const QStringList urls = m_ui->textUrls->toPlainText().split('\n');
QStringList uniqueURLs; QSet<QString> uniqueURLs;
for (QString url : urls) { for (QString url : urls) {
url = url.trimmed(); url = url.trimmed();
if (url.isEmpty()) continue; if (url.isEmpty()) continue;
if (!uniqueURLs.contains(url, Qt::CaseInsensitive)) uniqueURLs << url;
uniqueURLs << url;
} }
if (uniqueURLs.isEmpty()) { if (uniqueURLs.isEmpty()) {
@ -102,6 +99,6 @@ void DownloadFromURLDialog::downloadButtonClicked()
return; return;
} }
emit urlsReadyToBeDownloaded(uniqueURLs); emit urlsReadyToBeDownloaded(uniqueURLs.toList());
accept(); accept();
} }

Loading…
Cancel
Save