Browse Source

Allow to enter only info-hashes in the download dialog.

adaptive-webui-19844
sledgehammer999 11 years ago
parent
commit
0ea8fd6996
  1. 22
      src/downloadfromurldlg.h
  2. 2
      src/downloadfromurldlg.ui
  3. 9
      src/mainwindow.cpp

22
src/downloadfromurldlg.h

@ -50,9 +50,27 @@ class downloadFromURL : public QDialog, private Ui::downloadFromURL{ @@ -50,9 +50,27 @@ class downloadFromURL : public QDialog, private Ui::downloadFromURL{
show();
// Paste clipboard if there is an URL in it
QString clip_txt = qApp->clipboard()->text();
if (clip_txt.startsWith("http://", Qt::CaseInsensitive) || clip_txt.startsWith("https://", Qt::CaseInsensitive) || clip_txt.startsWith("ftp://", Qt::CaseInsensitive) || clip_txt.startsWith("magnet:", Qt::CaseInsensitive) || clip_txt.startsWith("bc://bt/", Qt::CaseInsensitive)) {
textUrls->setText(clip_txt);
QStringList clip_txt_list = clip_txt.split(QString::fromUtf8("\n"));
clip_txt.clear();
QStringList clip_txt_list_cleaned;
foreach (clip_txt, clip_txt_list) {
clip_txt = clip_txt.trimmed();
if (!clip_txt.isEmpty()) {
if (clip_txt_list_cleaned.indexOf(QRegExp(clip_txt, Qt::CaseInsensitive, QRegExp::FixedString)) < 0) {
if (clip_txt.startsWith("http://", Qt::CaseInsensitive)
|| clip_txt.startsWith("https://", Qt::CaseInsensitive)
|| clip_txt.startsWith("ftp://", Qt::CaseInsensitive)
|| clip_txt.startsWith("magnet:", Qt::CaseInsensitive)
|| clip_txt.startsWith("bc://bt/", Qt::CaseInsensitive)
|| (clip_txt.size() == 40 && !clip_txt.contains(QRegExp("[^0-9A-Fa-f]")))
|| (clip_txt.size() == 32 && !clip_txt.contains(QRegExp("[^2-7A-Za-z]")))) {
clip_txt_list_cleaned << clip_txt;
}
}
}
}
if (clip_txt_list_cleaned.size() > 0)
textUrls->setText(clip_txt_list_cleaned.join("\n"));
}
~downloadFromURL() {}

2
src/downloadfromurldlg.ui

@ -52,7 +52,7 @@ @@ -52,7 +52,7 @@
</font>
</property>
<property name="text">
<string>Both HTTP and Magnet links are supported</string>
<string>One per line HTTP links, Magnet links and info-hashes are supported</string>
</property>
</widget>
</item>

9
src/mainwindow.cpp

@ -1182,13 +1182,20 @@ void MainWindow::downloadFromURLList(const QStringList& url_list) { @@ -1182,13 +1182,20 @@ void MainWindow::downloadFromURLList(const QStringList& url_list) {
qDebug("Converting bc link to magnet link");
url = misc::bcLinkToMagnet(url);
}
if ((url.size() == 40 && !url.contains(QRegExp("[^0-9A-Fa-f]")))
|| (url.size() == 32 && !url.contains(QRegExp("[^2-7A-Za-z]")))) {
url = "magnet:?xt=urn:btih:" + url;
}
if (url.startsWith("magnet:", Qt::CaseInsensitive)) {
if (useTorrentAdditionDialog)
AddNewTorrentDialog::showMagnet(url);
else
QBtSession::instance()->addMagnetUri(url);
} else
}
else if (url.startsWith("http://", Qt::CaseInsensitive) || startsWith("https://", Qt::CaseInsensitive)
|| url.startsWith("ftp://", Qt::CaseInsensitive)) {
QBtSession::instance()->downloadFromUrl(url);
}
}
}

Loading…
Cancel
Save