|
|
@ -25,9 +25,10 @@ |
|
|
|
* but you are not obligated to do so. If you do not wish to do so, delete this |
|
|
|
* but you are not obligated to do so. If you do not wish to do so, delete this |
|
|
|
* exception statement from your version. |
|
|
|
* exception statement from your version. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
#include "trackersadditiondialog.h" |
|
|
|
#include "trackersadditiondialog.h" |
|
|
|
|
|
|
|
|
|
|
|
#include <QFile> |
|
|
|
#include <QBuffer> |
|
|
|
#include <QMessageBox> |
|
|
|
#include <QMessageBox> |
|
|
|
#include <QStringList> |
|
|
|
#include <QStringList> |
|
|
|
#include <QUrl> |
|
|
|
#include <QUrl> |
|
|
@ -70,25 +71,16 @@ QStringList TrackersAdditionDialog::newTrackers() const |
|
|
|
void TrackersAdditionDialog::on_uTorrentListButton_clicked() |
|
|
|
void TrackersAdditionDialog::on_uTorrentListButton_clicked() |
|
|
|
{ |
|
|
|
{ |
|
|
|
m_ui->uTorrentListButton->setEnabled(false); |
|
|
|
m_ui->uTorrentListButton->setEnabled(false); |
|
|
|
Net::DownloadHandler *handler = Net::DownloadManager::instance()->downloadUrl(m_ui->list_url->text(), true); |
|
|
|
Net::DownloadHandler *handler = Net::DownloadManager::instance()->download({m_ui->list_url->text()}); |
|
|
|
connect(handler, static_cast<void (Net::DownloadHandler::*)(const QString &, const QString &)>(&Net::DownloadHandler::downloadFinished) |
|
|
|
connect(handler, static_cast<void (Net::DownloadHandler::*)(const QString &, const QByteArray &)>(&Net::DownloadHandler::downloadFinished) |
|
|
|
, this, &TrackersAdditionDialog::parseUTorrentList); |
|
|
|
, this, &TrackersAdditionDialog::parseUTorrentList); |
|
|
|
connect(handler, &Net::DownloadHandler::downloadFailed, this, &TrackersAdditionDialog::getTrackerError); |
|
|
|
connect(handler, &Net::DownloadHandler::downloadFailed, this, &TrackersAdditionDialog::getTrackerError); |
|
|
|
// Just to show that it takes times
|
|
|
|
// Just to show that it takes times
|
|
|
|
setCursor(Qt::WaitCursor); |
|
|
|
setCursor(Qt::WaitCursor); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void TrackersAdditionDialog::parseUTorrentList(const QString &, const QString &path) |
|
|
|
void TrackersAdditionDialog::parseUTorrentList(const QString &, const QByteArray &data) |
|
|
|
{ |
|
|
|
{ |
|
|
|
QFile listFile(path); |
|
|
|
|
|
|
|
if (!listFile.open(QFile::ReadOnly)) { |
|
|
|
|
|
|
|
QMessageBox::warning(this, tr("I/O Error"), tr("Error while trying to open the downloaded file."), QMessageBox::Ok); |
|
|
|
|
|
|
|
setCursor(Qt::ArrowCursor); |
|
|
|
|
|
|
|
m_ui->uTorrentListButton->setEnabled(true); |
|
|
|
|
|
|
|
Utils::Fs::forceRemove(path); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Load from torrent handle
|
|
|
|
// Load from torrent handle
|
|
|
|
QList<BitTorrent::TrackerEntry> existingTrackers = m_torrent->trackers(); |
|
|
|
QList<BitTorrent::TrackerEntry> existingTrackers = m_torrent->trackers(); |
|
|
|
// Load from current user list
|
|
|
|
// Load from current user list
|
|
|
@ -103,19 +95,21 @@ void TrackersAdditionDialog::parseUTorrentList(const QString &, const QString &p |
|
|
|
if (!m_ui->trackers_list->toPlainText().isEmpty() && !m_ui->trackers_list->toPlainText().endsWith('\n')) |
|
|
|
if (!m_ui->trackers_list->toPlainText().isEmpty() && !m_ui->trackers_list->toPlainText().endsWith('\n')) |
|
|
|
m_ui->trackers_list->insertPlainText("\n"); |
|
|
|
m_ui->trackers_list->insertPlainText("\n"); |
|
|
|
int nb = 0; |
|
|
|
int nb = 0; |
|
|
|
while (!listFile.atEnd()) { |
|
|
|
QBuffer buffer; |
|
|
|
const QString line = listFile.readLine().trimmed(); |
|
|
|
buffer.setData(data); |
|
|
|
|
|
|
|
buffer.open(QBuffer::ReadOnly); |
|
|
|
|
|
|
|
while (!buffer.atEnd()) { |
|
|
|
|
|
|
|
const QString line = buffer.readLine().trimmed(); |
|
|
|
if (line.isEmpty()) continue; |
|
|
|
if (line.isEmpty()) continue; |
|
|
|
|
|
|
|
|
|
|
|
BitTorrent::TrackerEntry newTracker(line); |
|
|
|
BitTorrent::TrackerEntry newTracker(line); |
|
|
|
if (!existingTrackers.contains(newTracker)) { |
|
|
|
if (!existingTrackers.contains(newTracker)) { |
|
|
|
m_ui->trackers_list->insertPlainText(line + '\n'); |
|
|
|
m_ui->trackers_list->insertPlainText(line + '\n'); |
|
|
|
++nb; |
|
|
|
++nb; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
// Clean up
|
|
|
|
|
|
|
|
listFile.close(); |
|
|
|
// To restore the cursor ...
|
|
|
|
Utils::Fs::forceRemove(path); |
|
|
|
|
|
|
|
//To restore the cursor ...
|
|
|
|
|
|
|
|
setCursor(Qt::ArrowCursor); |
|
|
|
setCursor(Qt::ArrowCursor); |
|
|
|
m_ui->uTorrentListButton->setEnabled(true); |
|
|
|
m_ui->uTorrentListButton->setEnabled(true); |
|
|
|
// Display information message if necessary
|
|
|
|
// Display information message if necessary
|
|
|
|