Browse Source

Refactor function

adaptive-webui-19844
Chocobo1 7 years ago
parent
commit
ee202b721d
No known key found for this signature in database
GPG Key ID: 210D9C873253A68C
  1. 25
      src/gui/downloadfromurldialog.cpp

25
src/gui/downloadfromurldialog.cpp

@ -31,7 +31,7 @@ @@ -31,7 +31,7 @@
#include <QClipboard>
#include <QMessageBox>
#include <QPushButton>
#include <QRegExp>
#include <QRegularExpression>
#include <QSet>
#include <QString>
#include <QStringList>
@ -39,6 +39,20 @@ @@ -39,6 +39,20 @@
#include "ui_downloadfromurldialog.h"
#include "utils.h"
namespace
{
bool isDownloadable(const QString &str)
{
return (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(QRegularExpression("[^0-9A-Fa-f]")))
|| ((str.size() == 32) && !str.contains(QRegularExpression("[^2-7A-Za-z]"))));
}
}
DownloadFromURLDialog::DownloadFromURLDialog(QWidget *parent)
: QDialog(parent)
, m_ui(new Ui::DownloadFromURLDialog)
@ -61,16 +75,9 @@ DownloadFromURLDialog::DownloadFromURLDialog(QWidget *parent) @@ -61,16 +75,9 @@ DownloadFromURLDialog::DownloadFromURLDialog(QWidget *parent)
str = str.trimmed();
if (str.isEmpty()) continue;
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]")))) {
if (isDownloadable(str))
uniqueURLs << str;
}
}
m_ui->textUrls->setText(uniqueURLs.toList().join('\n'));
Utils::Gui::resize(this);

Loading…
Cancel
Save