From 8e9b0d97ec52888f087ff6cfcc0c03f3ca5bf739 Mon Sep 17 00:00:00 2001 From: "Vladimir Golovnev (Glassez)" Date: Thu, 14 Apr 2016 11:06:34 +0300 Subject: [PATCH 1/4] Fix torrent adding with existing data --- src/base/bittorrent/session.cpp | 5 +---- src/base/bittorrent/torrenthandle.cpp | 23 +++++++++++++---------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/base/bittorrent/session.cpp b/src/base/bittorrent/session.cpp index e781b15a6..d0fdd4c44 100644 --- a/src/base/bittorrent/session.cpp +++ b/src/base/bittorrent/session.cpp @@ -1331,10 +1331,7 @@ bool Session::addTorrent_impl(AddTorrentData addData, const MagnetUri &magnetUri p.max_uploads = pref->getMaxUploadsPerTorrent(); QString savePath; - // Set actual save path (e.g. temporary folder) - if (isTempPathEnabled() && !addData.disableTempPath && !addData.hasSeedStatus) - savePath = m_tempPath; - else if (addData.savePath.isEmpty()) // using Advanced mode + if (addData.savePath.isEmpty()) // using Advanced mode savePath = categorySavePath(addData.category); else // using Simple mode savePath = addData.savePath; diff --git a/src/base/bittorrent/torrenthandle.cpp b/src/base/bittorrent/torrenthandle.cpp index 7fd86e9cc..8aa4ce317 100644 --- a/src/base/bittorrent/torrenthandle.cpp +++ b/src/base/bittorrent/torrenthandle.cpp @@ -215,15 +215,9 @@ TorrentHandle::TorrentHandle(Session *session, const libtorrent::torrent_handle updateStatus(); m_hash = InfoHash(m_nativeStatus.info_hash); - adjustActualSavePath(); - if (!data.resumed) { + if (!data.resumed) setSequentialDownload(data.sequential); - if (hasMetadata()) { - if (m_session->isAppendExtensionEnabled()) - appendExtensionsToIncompleteFiles(); - } - } } TorrentHandle::~TorrentHandle() {} @@ -1475,6 +1469,7 @@ void TorrentHandle::handleTorrentCheckedAlert(libtorrent::torrent_checked_alert m_hasSeedStatus = true; adjustActualSavePath(); + appendExtensionsToIncompleteFiles(); if (m_pauseAfterRecheck) { m_pauseAfterRecheck = false; @@ -1727,14 +1722,22 @@ void TorrentHandle::appendExtensionsToIncompleteFiles() { QVector fp = filesProgress(); for (int i = 0; i < filesCount(); ++i) { + QString name = filePath(i); if ((fileSize(i) > 0) && (fp[i] < 1)) { - const QString name = filePath(i); if (!name.endsWith(QB_EXT)) { const QString newName = name + QB_EXT; - qDebug("Renaming %s to %s", qPrintable(name), qPrintable(newName)); + qDebug() << "Renaming" << name << "to" << newName; renameFile(i, newName); } } + else { + if (name.endsWith(QB_EXT)) { + const QString oldName = name; + name.chop(QString(QB_EXT).size()); + qDebug() << "Renaming" << oldName << "to" << name; + renameFile(i, name); + } + } } } @@ -1770,7 +1773,7 @@ void TorrentHandle::adjustActualSavePath_impl() else { // Moving all downloading torrents to temporary save path path = m_session->tempPath(); - qDebug("Moving torrent to its temp save path: %s", qPrintable(path)); + qDebug() << "Moving torrent to its temp save path:" << path; } moveStorage(Utils::Fs::toNativePath(path)); From e0d9ae3116ce5595192f60d28cb4e9491fe57138 Mon Sep 17 00:00:00 2001 From: "Vladimir Golovnev (Glassez)" Date: Tue, 19 Apr 2016 09:54:48 +0300 Subject: [PATCH 2/4] Try to find incomplete files for new torrent --- src/base/bittorrent/session.cpp | 130 +++++++++++++++++++------- src/base/bittorrent/session.h | 3 +- src/base/bittorrent/torrenthandle.cpp | 8 +- src/base/bittorrent/torrenthandle.h | 2 + 4 files changed, 102 insertions(+), 41 deletions(-) diff --git a/src/base/bittorrent/session.cpp b/src/base/bittorrent/session.cpp index d0fdd4c44..267109e49 100644 --- a/src/base/bittorrent/session.cpp +++ b/src/base/bittorrent/session.cpp @@ -28,63 +28,63 @@ * exception statement from your version. */ +#include "session.h" + +#include +#include #include #include -#include -#include -#include -#include +#include #include #include -#include +#include #include -#include -#include #include +#include +#include +#include +#include #include #include #include -#include -#include +#include #include #include -#include -#include -#include -#include -#include #include #include #include #include -//#include +#include +#include +#include +#include +#include +#include -#include "base/utils/misc.h" -#include "base/utils/fs.h" -#include "base/utils/string.h" -#include "base/unicodestrings.h" #include "base/logger.h" -#include "base/settingsstorage.h" -#include "base/preferences.h" -#include "base/torrentfilter.h" -#include "base/net/downloadmanager.h" #include "base/net/downloadhandler.h" +#include "base/net/downloadmanager.h" #include "base/net/portforwarder.h" +#include "base/preferences.h" +#include "base/settingsstorage.h" +#include "base/torrentfilter.h" +#include "base/unicodestrings.h" +#include "base/utils/misc.h" +#include "base/utils/fs.h" #include "base/utils/string.h" +#include "cachestatus.h" +#include "magneturi.h" #include "private/filterparserthread.h" #include "private/statistics.h" #include "private/bandwidthscheduler.h" #include "private/resumedatasavingmanager.h" -#include "trackerentry.h" -#include "tracker.h" -#include "magneturi.h" -#include "cachestatus.h" #include "sessionstatus.h" #include "torrenthandle.h" -#include "session.h" +#include "tracker.h" +#include "trackerentry.h" static const char PEER_ID[] = "qB"; static const char RESUME_FOLDER[] = "BT_backup"; @@ -155,6 +155,16 @@ namespace return expanded; } + + QStringList findAllFiles(const QString &dirPath) + { + QStringList files; + QDirIterator it(dirPath, QDir::Files, QDirIterator::Subdirectories); + while (it.hasNext()) + files << it.next(); + + return files; + } } // Session @@ -1225,7 +1235,7 @@ bool Session::addTorrent(const TorrentInfo &torrentInfo, const AddTorrentParams // Add a torrent to the BitTorrent session bool Session::addTorrent_impl(AddTorrentData addData, const MagnetUri &magnetUri, - const TorrentInfo &torrentInfo, const QByteArray &fastresumeData) + TorrentInfo torrentInfo, const QByteArray &fastresumeData) { addData.savePath = normalizeSavePath( addData.savePath, @@ -1243,6 +1253,12 @@ bool Session::addTorrent_impl(AddTorrentData addData, const MagnetUri &magnetUri std::vector buf(fastresumeData.constData(), fastresumeData.constData() + fastresumeData.size()); std::vector filePriorities; + QString savePath; + if (addData.savePath.isEmpty()) // using Advanced mode + savePath = categorySavePath(addData.category); + else // using Simple mode + savePath = addData.savePath; + bool fromMagnetUri = magnetUri.isValid(); if (fromMagnetUri) { hash = magnetUri.hash(); @@ -1271,6 +1287,8 @@ bool Session::addTorrent_impl(AddTorrentData addData, const MagnetUri &magnetUri } else if (torrentInfo.isValid()) { // Metadata + if (!addData.resumed && !addData.hasSeedStatus) + findIncompleteFiles(torrentInfo, savePath); p.ti = torrentInfo.nativeInfo(); hash = torrentInfo.hash(); } @@ -1329,13 +1347,6 @@ bool Session::addTorrent_impl(AddTorrentData addData, const MagnetUri &magnetUri Preferences *const pref = Preferences::instance(); p.max_connections = pref->getMaxConnecsPerTorrent(); p.max_uploads = pref->getMaxUploadsPerTorrent(); - - QString savePath; - if (addData.savePath.isEmpty()) // using Advanced mode - savePath = categorySavePath(addData.category); - else // using Simple mode - savePath = addData.savePath; - p.save_path = Utils::String::toStdString(Utils::Fs::toNativePath(savePath)); // Check if save path exists, creating it otherwise if (!QDir(savePath).exists()) @@ -1347,6 +1358,53 @@ bool Session::addTorrent_impl(AddTorrentData addData, const MagnetUri &magnetUri return true; } +bool Session::findIncompleteFiles(TorrentInfo &torrentInfo, QString &savePath) const +{ + auto findInDir = [](const QString &dirPath, TorrentInfo &torrentInfo) -> bool + { + bool found = false; + if (torrentInfo.filesCount() == 1) { + const QString filePath = dirPath + torrentInfo.filePath(0); + if (QFile(filePath).exists()) { + found = true; + } + else if (QFile(filePath + QB_EXT).exists()) { + found = true; + torrentInfo.renameFile(0, torrentInfo.filePath(0) + QB_EXT); + } + } + else { + QSet allFiles; + int dirPathSize = dirPath.size(); + foreach (const QString &file, findAllFiles(dirPath + torrentInfo.name())) + allFiles << file.mid(dirPathSize); + for (int i = 0; i < torrentInfo.filesCount(); ++i) { + QString filePath = torrentInfo.filePath(i); + if (allFiles.contains(filePath)) { + found = true; + } + else { + filePath += QB_EXT; + if (allFiles.contains(filePath)) { + found = true; + torrentInfo.renameFile(i, filePath); + } + } + } + } + + return found; + }; + + bool found = findInDir(savePath, torrentInfo); + if (!found && isTempPathEnabled()) { + savePath = m_tempPath; + found = findInDir(savePath, torrentInfo); + } + + return found; +} + // Add a torrent to the BitTorrent session in hidden mode // and force it to load its metadata bool Session::loadMetadata(const MagnetUri &magnetUri) diff --git a/src/base/bittorrent/session.h b/src/base/bittorrent/session.h index 072e478bd..4b9e30a1c 100644 --- a/src/base/bittorrent/session.h +++ b/src/base/bittorrent/session.h @@ -356,8 +356,9 @@ namespace BitTorrent void startUpTorrents(); bool addTorrent_impl(AddTorrentData addData, const MagnetUri &magnetUri, - const TorrentInfo &torrentInfo = TorrentInfo(), + TorrentInfo torrentInfo = TorrentInfo(), const QByteArray &fastresumeData = QByteArray()); + bool findIncompleteFiles(TorrentInfo &torrentInfo, QString &savePath) const; void updateRatioTimer(); void exportTorrentFile(TorrentHandle *const torrent, TorrentExportFolder folder = TorrentExportFolder::Regular); diff --git a/src/base/bittorrent/torrenthandle.cpp b/src/base/bittorrent/torrenthandle.cpp index 8aa4ce317..2db90d8c6 100644 --- a/src/base/bittorrent/torrenthandle.cpp +++ b/src/base/bittorrent/torrenthandle.cpp @@ -60,7 +60,7 @@ #include "trackerentry.h" #include "torrenthandle.h" -static const char QB_EXT[] = ".!qB"; +const QString QB_EXT {".!qB"}; namespace libt = libtorrent; using namespace BitTorrent; @@ -1611,7 +1611,7 @@ void TorrentHandle::handleFileCompletedAlert(libtorrent::file_completed_alert *p QString name = filePath(p->index); if (name.endsWith(QB_EXT)) { const QString oldName = name; - name.chop(QString(QB_EXT).size()); + name.chop(QB_EXT.size()); qDebug("Renaming %s to %s", qPrintable(oldName), qPrintable(name)); renameFile(p->index, name); } @@ -1733,7 +1733,7 @@ void TorrentHandle::appendExtensionsToIncompleteFiles() else { if (name.endsWith(QB_EXT)) { const QString oldName = name; - name.chop(QString(QB_EXT).size()); + name.chop(QB_EXT.size()); qDebug() << "Renaming" << oldName << "to" << name; renameFile(i, name); } @@ -1747,7 +1747,7 @@ void TorrentHandle::removeExtensionsFromIncompleteFiles() QString name = filePath(i); if (name.endsWith(QB_EXT)) { const QString oldName = name; - name.chop(QString(QB_EXT).size()); + name.chop(QB_EXT.size()); qDebug("Renaming %s to %s", qPrintable(oldName), qPrintable(name)); renameFile(i, name); } diff --git a/src/base/bittorrent/torrenthandle.h b/src/base/bittorrent/torrenthandle.h index fef582b00..a956d6576 100644 --- a/src/base/bittorrent/torrenthandle.h +++ b/src/base/bittorrent/torrenthandle.h @@ -54,6 +54,8 @@ class QBitArray; class QStringList; template struct QPair; +extern const QString QB_EXT; + namespace libtorrent { class alert; From 2fb6bb00bf65151b111131f69ffa4d34105acc5c Mon Sep 17 00:00:00 2001 From: "Vladimir Golovnev (Glassez)" Date: Wed, 20 Apr 2016 11:36:07 +0300 Subject: [PATCH 3/4] Fix rechecking after torrent is finished --- src/base/bittorrent/torrenthandle.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/base/bittorrent/torrenthandle.cpp b/src/base/bittorrent/torrenthandle.cpp index 2db90d8c6..db006aefe 100644 --- a/src/base/bittorrent/torrenthandle.cpp +++ b/src/base/bittorrent/torrenthandle.cpp @@ -1491,13 +1491,19 @@ void TorrentHandle::handleTorrentFinishedAlert(libtorrent::torrent_finished_aler m_hasSeedStatus = true; adjustActualSavePath(); - if (Preferences::instance()->recheckTorrentsOnCompletion()) - forceRecheck(); + appendExtensionsToIncompleteFiles(); - if (isMoveInProgress() || m_renameCount > 0) + const bool recheckTorrentsOnCompletion = Preferences::instance()->recheckTorrentsOnCompletion(); + if (isMoveInProgress() || m_renameCount > 0) { + if (recheckTorrentsOnCompletion) + m_moveFinishedTriggers.append(boost::bind(&TorrentHandle::forceRecheck, this)); m_moveFinishedTriggers.append(boost::bind(&Session::handleTorrentFinished, m_session, this)); - else + } + else { + if (recheckTorrentsOnCompletion) + forceRecheck(); m_session->handleTorrentFinished(this); + } } void TorrentHandle::handleTorrentPausedAlert(libtorrent::torrent_paused_alert *p) From 599166ed0f434e299285fcc0ef1dc10d8fa0dcb3 Mon Sep 17 00:00:00 2001 From: "Vladimir Golovnev (Glassez)" Date: Wed, 20 Apr 2016 12:00:47 +0300 Subject: [PATCH 4/4] Delete Import Torrent Dialog --- src/gui/gui.pri | 3 - src/gui/mainwindow.cpp | 7 - src/gui/mainwindow.h | 1 - src/gui/mainwindow.ui | 11 +- src/gui/torrentimportdlg.cpp | 270 ----------------------------------- src/gui/torrentimportdlg.h | 86 ----------- src/gui/torrentimportdlg.ui | 139 ------------------ 7 files changed, 1 insertion(+), 516 deletions(-) delete mode 100644 src/gui/torrentimportdlg.cpp delete mode 100644 src/gui/torrentimportdlg.h delete mode 100644 src/gui/torrentimportdlg.ui diff --git a/src/gui/gui.pri b/src/gui/gui.pri index 7c6fcfb8e..a9318344c 100644 --- a/src/gui/gui.pri +++ b/src/gui/gui.pri @@ -28,7 +28,6 @@ HEADERS += \ $$PWD/downloadfromurldlg.h \ $$PWD/trackerlogin.h \ $$PWD/hidabletabwidget.h \ - $$PWD/torrentimportdlg.h \ $$PWD/executionlog.h \ $$PWD/guiiconprovider.h \ $$PWD/updownratiodlg.h \ @@ -65,7 +64,6 @@ SOURCES += \ $$PWD/torrentcontentmodelfile.cpp \ $$PWD/torrentcontentfiltermodel.cpp \ $$PWD/torrentcontenttreeview.cpp \ - $$PWD/torrentimportdlg.cpp \ $$PWD/executionlog.cpp \ $$PWD/speedlimitdlg.cpp \ $$PWD/previewselect.cpp \ @@ -108,7 +106,6 @@ FORMS += \ $$PWD/updownratiodlg.ui \ $$PWD/confirmdeletiondlg.ui \ $$PWD/shutdownconfirmdlg.ui \ - $$PWD/torrentimportdlg.ui \ $$PWD/executionlog.ui \ $$PWD/addnewtorrentdialog.ui \ $$PWD/autoexpandabledialog.ui \ diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index 6eb6d1c61..563ac1732 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -72,7 +72,6 @@ #include "torrentcreatordlg.h" #include "downloadfromurldlg.h" #include "addnewtorrentdialog.h" -#include "torrentimportdlg.h" #include "statsdialog.h" #include "cookiesdialog.h" #include "speedlimitdlg.h" @@ -163,7 +162,6 @@ MainWindow::MainWindow(QWidget *parent) m_ui->actionPauseAll->setIcon(GuiIconProvider::instance()->getIcon("media-playback-pause")); m_ui->actionStart->setIcon(GuiIconProvider::instance()->getIcon("media-playback-start")); m_ui->actionStartAll->setIcon(GuiIconProvider::instance()->getIcon("media-playback-start")); - m_ui->actionImportTorrent->setIcon(GuiIconProvider::instance()->getIcon("document-import")); m_ui->menuAutoShutdownOnDownloadsCompletion->setIcon(GuiIconProvider::instance()->getIcon("application-exit")); m_ui->actionManageCookies->setIcon(GuiIconProvider::instance()->getIcon("preferences-web-browser-cookies")); @@ -1512,11 +1510,6 @@ void MainWindow::on_actionSearchWidget_triggered() displaySearchTab(m_ui->actionSearchWidget->isChecked()); } -void MainWindow::on_actionImportTorrent_triggered() -{ - TorrentImportDlg::importTorrent(); -} - /***************************************************** * * * HTTP Downloader * diff --git a/src/gui/mainwindow.h b/src/gui/mainwindow.h index ff489d6f6..0d81b821f 100644 --- a/src/gui/mainwindow.h +++ b/src/gui/mainwindow.h @@ -144,7 +144,6 @@ private slots: void on_actionRSSReader_triggered(); void on_actionSpeedInTitleBar_triggered(); void on_actionTopToolBar_triggered(); - void on_actionImportTorrent_triggered(); void on_actionDonateMoney_triggered(); void on_actionExecutionLogs_triggered(bool checked); void on_actionNormalMessages_triggered(bool checked); diff --git a/src/gui/mainwindow.ui b/src/gui/mainwindow.ui index 44d616920..79120c396 100644 --- a/src/gui/mainwindow.ui +++ b/src/gui/mainwindow.ui @@ -35,7 +35,7 @@ 0 0 914 - 23 + 21 @@ -88,7 +88,6 @@ - @@ -327,14 +326,6 @@ Ctrl+L - - - &Import Existing Torrent... - - - Import Torrent... - - Do&nate! diff --git a/src/gui/torrentimportdlg.cpp b/src/gui/torrentimportdlg.cpp deleted file mode 100644 index 8fa90a1e1..000000000 --- a/src/gui/torrentimportdlg.cpp +++ /dev/null @@ -1,270 +0,0 @@ -/* - * Bittorrent Client using Qt4 and libtorrent. - * Copyright (C) 2010 Christophe Dumez - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * In addition, as a special exception, the copyright holders give permission to - * link this program with the OpenSSL project's "OpenSSL" library (or with - * modified versions of it that use the same license as the "OpenSSL" library), - * and distribute the linked executables. You must obey the GNU General Public - * License in all respects for all of the code used other than "OpenSSL". If you - * modify file(s), you may extend this exception to your version of the file(s), - * but you are not obligated to do so. If you do not wish to do so, delete this - * exception statement from your version. - * - * Contact : chris@qbittorrent.org - */ - -#include -#include -#include - -#include "torrentimportdlg.h" -#include "ui_torrentimportdlg.h" -#include "base/preferences.h" -#include "base/bittorrent/infohash.h" -#include "base/bittorrent/session.h" -#include "guiiconprovider.h" -#include "base/utils/fs.h" - -TorrentImportDlg::TorrentImportDlg(QWidget *parent): - QDialog(parent), - ui(new Ui::TorrentImportDlg) -{ - ui->setupUi(this); - // Icons - ui->lbl_info->setPixmap(GuiIconProvider::instance()->getIcon("dialog-information").pixmap(ui->lbl_info->height())); - ui->lbl_info->setFixedWidth(ui->lbl_info->height()); - ui->importBtn->setIcon(GuiIconProvider::instance()->getIcon("document-import")); - // Libtorrent < 0.15 does not support skipping file checking - loadSettings(); -} - -TorrentImportDlg::~TorrentImportDlg() -{ - delete ui; -} - -void TorrentImportDlg::on_browseTorrentBtn_clicked() -{ - const QString default_dir = Preferences::instance()->getMainLastDir(); - // Ask for a torrent file - m_torrentPath = QFileDialog::getOpenFileName(this, tr("Torrent file to import"), default_dir, tr("Torrent files") + QString(" (*.torrent)")); - if (!m_torrentPath.isEmpty()) - loadTorrent(m_torrentPath); - else - ui->lineTorrent->clear(); -} - -void TorrentImportDlg::on_browseContentBtn_clicked() -{ - const QString default_dir = Preferences::instance()->getTorImportLastContentDir(); - bool multifile = (m_torrentInfo.filesCount() > 1); - QString filePath = Utils::Fs::fromNativePath(m_torrentInfo.filePath(0)); - if (!multifile && (filePath.indexOf('/') != -1)) - multifile = true; - - if (!multifile) { - // Single file torrent - const QString file_name = Utils::Fs::fileName(filePath); - qDebug("Torrent has only one file: %s", qPrintable(file_name)); - QString extension = Utils::Fs::fileExtension(file_name); - qDebug("File extension is : %s", qPrintable(extension)); - QString filter; - if (!extension.isEmpty()) { - extension = extension.toUpper(); - filter = tr("'%1' Files", "%1 is a file extension (e.g. PDF)").arg(extension) + " (*." + extension + ")"; - } - m_contentPath = QFileDialog::getOpenFileName(this, tr("Please provide the location of '%1'", "%1 is a file name").arg(file_name), default_dir, filter); - if (m_contentPath.isEmpty() || !QFile(m_contentPath).exists()) { - m_contentPath = QString::null; - ui->importBtn->setEnabled(false); - ui->checkSkipCheck->setEnabled(false); - return; - } - // Update display - ui->lineContent->setText(Utils::Fs::toNativePath(m_contentPath)); - // Check file size - const qint64 file_size = QFile(m_contentPath).size(); - if (m_torrentInfo.fileSize(0) == file_size) { - qDebug("The file size matches, allowing fast seeding..."); - ui->checkSkipCheck->setEnabled(true); - } - else { - qDebug("The file size does not match, forbidding fast seeding..."); - ui->checkSkipCheck->setChecked(false); - ui->checkSkipCheck->setEnabled(false); - } - // Handle file renaming - QStringList parts = m_contentPath.split("/"); - QString new_file_name = parts.takeLast(); - if (new_file_name != file_name) { - qDebug("The file has been renamed"); - QStringList new_parts = m_filesPath.first().split("/"); - new_parts.replace(new_parts.count() - 1, new_file_name); - m_filesPath.replace(0, new_parts.join("/")); - } - m_contentPath = parts.join("/"); - } - else { - // multiple files torrent - m_contentPath = QFileDialog::getExistingDirectory(this, tr("Please point to the location of the torrent: %1").arg(m_torrentInfo.name()), - default_dir); - if (m_contentPath.isEmpty() || !QDir(m_contentPath).exists()) { - m_contentPath = QString::null; - ui->importBtn->setEnabled(false); - ui->checkSkipCheck->setEnabled(false); - return; - } - // Update the display - ui->lineContent->setText(Utils::Fs::toNativePath(m_contentPath)); - bool size_mismatch = false; - QDir content_dir(m_contentPath); - content_dir.cdUp(); - // Check file sizes - for (int i = 0; i < m_torrentInfo.filesCount(); ++i) { - const QString rel_path = m_torrentInfo.filePath(i); - if (QFile(Utils::Fs::expandPath(content_dir.absoluteFilePath(rel_path))).size() != m_torrentInfo.fileSize(i)) { - qDebug("%s is %lld", - qPrintable(Utils::Fs::expandPath(content_dir.absoluteFilePath(rel_path))), (long long int) QFile(Utils::Fs::expandPath(content_dir.absoluteFilePath(rel_path))).size()); - qDebug("%s is %lld", - qPrintable(rel_path), (long long int)m_torrentInfo.fileSize(i)); - size_mismatch = true; - break; - } - } - if (size_mismatch) { - qDebug("The file size does not match, forbidding fast seeding..."); - ui->checkSkipCheck->setChecked(false); - ui->checkSkipCheck->setEnabled(false); - } - else { - qDebug("The file size matches, allowing fast seeding..."); - ui->checkSkipCheck->setEnabled(true); - } - } - // Enable the import button - ui->importBtn->setEnabled(true); -} - -void TorrentImportDlg::on_importBtn_clicked() -{ - saveSettings(); - // Has to be accept() and not close() - // or the torrent won't be imported - accept(); -} - -QString TorrentImportDlg::getTorrentPath() const -{ - return m_torrentPath; -} - -QString TorrentImportDlg::getContentPath() const -{ - return m_contentPath; -} - -void TorrentImportDlg::importTorrent() -{ - qDebug() << Q_FUNC_INFO << "ENTER"; - TorrentImportDlg dlg; - if (dlg.exec()) { - BitTorrent::AddTorrentParams params; - qDebug() << "Loading the torrent file..."; - BitTorrent::TorrentInfo torrentInfo = dlg.torrent(); - if (!torrentInfo.isValid()) return; - - QString torrentPath = dlg.getTorrentPath(); - QString contentPath = dlg.getContentPath(); - if (torrentPath.isEmpty() || contentPath.isEmpty() || !QFile(torrentPath).exists()) { - qWarning() << "Incorrect input, aborting." << torrentPath << contentPath; - return; - } - - const QString hash = torrentInfo.hash(); - qDebug() << "Torrent hash is" << hash; - params.savePath = contentPath; - params.skipChecking = dlg.skipFileChecking(); - params.disableTempPath = true; - qDebug("Adding the torrent to the session..."); - BitTorrent::Session::instance()->addTorrent(torrentInfo, params); - // Remember the last opened folder - Preferences* const pref = Preferences::instance(); - pref->setMainLastDir(Utils::Fs::fromNativePath(torrentPath)); - pref->setTorImportLastContentDir(Utils::Fs::fromNativePath(contentPath)); - return; - } - qDebug() << Q_FUNC_INFO << "EXIT"; - return; -} - -void TorrentImportDlg::loadTorrent(const QString &torrentPath) -{ - // Load the torrent file - m_torrentInfo = BitTorrent::TorrentInfo::loadFromFile(torrentPath); - if (!m_torrentInfo.isValid()) { - ui->browseContentBtn->setEnabled(false); - ui->lineTorrent->clear(); - QMessageBox::warning(this, tr("Invalid torrent file"), tr("This is not a valid torrent file.")); - } - else { - // Update display - ui->lineTorrent->setText(Utils::Fs::toNativePath(torrentPath)); - ui->browseContentBtn->setEnabled(true); - // Load the file names - initializeFilesPath(); - } -} - -void TorrentImportDlg::initializeFilesPath() -{ - // Loads files path in the torrent - m_filesPath = m_torrentInfo.filePaths(); -} - -bool TorrentImportDlg::fileRenamed() const -{ - return m_fileRenamed; -} - - -BitTorrent::TorrentInfo TorrentImportDlg::torrent() const -{ - return m_torrentInfo; -} - -bool TorrentImportDlg::skipFileChecking() const -{ - return ui->checkSkipCheck->isChecked(); -} - -void TorrentImportDlg::loadSettings() -{ - restoreGeometry(Preferences::instance()->getTorImportGeometry()); -} - -void TorrentImportDlg::saveSettings() -{ - Preferences::instance()->setTorImportGeometry(saveGeometry()); -} - -void TorrentImportDlg::closeEvent(QCloseEvent *event) -{ - qDebug() << Q_FUNC_INFO; - saveSettings(); - QDialog::closeEvent(event); -} diff --git a/src/gui/torrentimportdlg.h b/src/gui/torrentimportdlg.h deleted file mode 100644 index 780d38bf1..000000000 --- a/src/gui/torrentimportdlg.h +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Bittorrent Client using Qt4 and libtorrent. - * Copyright (C) 2010 Christophe Dumez - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * In addition, as a special exception, the copyright holders give permission to - * link this program with the OpenSSL project's "OpenSSL" library (or with - * modified versions of it that use the same license as the "OpenSSL" library), - * and distribute the linked executables. You must obey the GNU General Public - * License in all respects for all of the code used other than "OpenSSL". If you - * modify file(s), you may extend this exception to your version of the file(s), - * but you are not obligated to do so. If you do not wish to do so, delete this - * exception statement from your version. - * - * Contact : chris@qbittorrent.org - */ - -#ifndef TORRENTIMPORTDLG_H -#define TORRENTIMPORTDLG_H - -#include -#include - -#include "base/bittorrent/torrentinfo.h" - -namespace Ui -{ - class TorrentImportDlg; -} - -class TorrentImportDlg: public QDialog -{ - Q_OBJECT - -public: - explicit TorrentImportDlg(QWidget *parent = 0); - ~TorrentImportDlg(); - - static void importTorrent(); - - QString getTorrentPath() const; - QString getContentPath() const; - bool fileRenamed() const; - BitTorrent::TorrentInfo torrent() const; - bool skipFileChecking() const; - -protected slots: - void loadTorrent(const QString &torrentPath); - void initializeFilesPath(); - -private slots: - void on_browseTorrentBtn_clicked(); - void on_browseContentBtn_clicked(); - void on_importBtn_clicked(); - -protected: - void closeEvent(QCloseEvent *event); - -private: - void loadSettings(); - void saveSettings(); - -private: - Ui::TorrentImportDlg *ui; - BitTorrent::TorrentInfo m_torrentInfo; - // NOTE: Where do we use it? - QStringList m_filesPath; - QString m_contentPath; - QString m_torrentPath; - bool m_fileRenamed; -}; - -#endif // TORRENTIMPORTDLG_H diff --git a/src/gui/torrentimportdlg.ui b/src/gui/torrentimportdlg.ui deleted file mode 100644 index 497ec133e..000000000 --- a/src/gui/torrentimportdlg.ui +++ /dev/null @@ -1,139 +0,0 @@ - - - TorrentImportDlg - - - - 0 - 0 - 464 - 236 - - - - Torrent Import - - - - - - - - - 32 - 32 - - - - - 38 - 38 - - - - - 38 - 38 - - - - - - - - - - - - 0 - 0 - - - - This assistant will help you share with qBittorrent a torrent that you have already downloaded. - - - true - - - - - - - - - Torrent file to import: - - - - - - - - - false - - - - - - - ... - - - - - - - - - Content location: - - - - - - - - - false - - - - - - - false - - - ... - - - - - - - - - false - - - Skip the data checking stage and start seeding immediately - - - - - - - false - - - Import - - - - - - - -