mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-08-20 21:33:27 -07:00
Refactor function
This commit is contained in:
parent
46aa631d2b
commit
86767c9ab4
1 changed files with 16 additions and 9 deletions
|
@ -31,7 +31,7 @@
|
||||||
#include <QClipboard>
|
#include <QClipboard>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
#include <QRegExp>
|
#include <QRegularExpression>
|
||||||
#include <QSet>
|
#include <QSet>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
|
@ -39,6 +39,20 @@
|
||||||
#include "ui_downloadfromurldialog.h"
|
#include "ui_downloadfromurldialog.h"
|
||||||
#include "utils.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)
|
DownloadFromURLDialog::DownloadFromURLDialog(QWidget *parent)
|
||||||
: QDialog(parent)
|
: QDialog(parent)
|
||||||
, m_ui(new Ui::DownloadFromURLDialog)
|
, m_ui(new Ui::DownloadFromURLDialog)
|
||||||
|
@ -61,15 +75,8 @@ DownloadFromURLDialog::DownloadFromURLDialog(QWidget *parent)
|
||||||
str = str.trimmed();
|
str = str.trimmed();
|
||||||
if (str.isEmpty()) continue;
|
if (str.isEmpty()) continue;
|
||||||
|
|
||||||
if (str.startsWith("http://", Qt::CaseInsensitive)
|
if (isDownloadable(str))
|
||||||
|| 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;
|
uniqueURLs << str;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
m_ui->textUrls->setText(uniqueURLs.toList().join('\n'));
|
m_ui->textUrls->setText(uniqueURLs.toList().join('\n'));
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue