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{
show(); show();
// Paste clipboard if there is an URL in it // Paste clipboard if there is an URL in it
QString clip_txt = qApp->clipboard()->text(); 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)) { QStringList clip_txt_list = clip_txt.split(QString::fromUtf8("\n"));
textUrls->setText(clip_txt); 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() {} ~downloadFromURL() {}

2
src/downloadfromurldlg.ui

@ -52,7 +52,7 @@
</font> </font>
</property> </property>
<property name="text"> <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> </property>
</widget> </widget>
</item> </item>

9
src/mainwindow.cpp

@ -1182,13 +1182,20 @@ void MainWindow::downloadFromURLList(const QStringList& url_list) {
qDebug("Converting bc link to magnet link"); qDebug("Converting bc link to magnet link");
url = misc::bcLinkToMagnet(url); 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 (url.startsWith("magnet:", Qt::CaseInsensitive)) {
if (useTorrentAdditionDialog) if (useTorrentAdditionDialog)
AddNewTorrentDialog::showMagnet(url); AddNewTorrentDialog::showMagnet(url);
else else
QBtSession::instance()->addMagnetUri(url); 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); QBtSession::instance()->downloadFromUrl(url);
}
} }
} }

Loading…
Cancel
Save