mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-08-21 05:43:32 -07:00
commit
e59841d35c
12 changed files with 31 additions and 47 deletions
|
@ -246,8 +246,8 @@ QString PeerInfo::connectionType() const
|
||||||
|
|
||||||
void PeerInfo::calcRelevance(const TorrentHandle *torrent)
|
void PeerInfo::calcRelevance(const TorrentHandle *torrent)
|
||||||
{
|
{
|
||||||
const QBitArray &allPieces = torrent->pieces();
|
const QBitArray allPieces = torrent->pieces();
|
||||||
const QBitArray &peerPieces = pieces();
|
const QBitArray peerPieces = pieces();
|
||||||
|
|
||||||
int localMissing = 0;
|
int localMissing = 0;
|
||||||
int remoteHaves = 0;
|
int remoteHaves = 0;
|
||||||
|
|
|
@ -48,6 +48,20 @@ namespace
|
||||||
{
|
{
|
||||||
QString tr(const char *message);
|
QString tr(const char *message);
|
||||||
QString errorCodeToString(QNetworkReply::NetworkError status);
|
QString errorCodeToString(QNetworkReply::NetworkError status);
|
||||||
|
|
||||||
|
bool saveToFile(const QByteArray &replyData, QString &filePath)
|
||||||
|
{
|
||||||
|
QTemporaryFile tmpfile {Utils::Fs::tempPath() + "XXXXXX"};
|
||||||
|
tmpfile.setAutoRemove(false);
|
||||||
|
|
||||||
|
if (!tmpfile.open())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
filePath = tmpfile.fileName();
|
||||||
|
|
||||||
|
tmpfile.write(replyData);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Net::DownloadHandler::DownloadHandler(QNetworkReply *reply, DownloadManager *manager, const DownloadRequest &downloadRequest)
|
Net::DownloadHandler::DownloadHandler(QNetworkReply *reply, DownloadManager *manager, const DownloadRequest &downloadRequest)
|
||||||
|
@ -145,33 +159,6 @@ void Net::DownloadHandler::checkDownloadSize(qint64 bytesReceived, qint64 bytesT
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Net::DownloadHandler::saveToFile(const QByteArray &replyData, QString &filePath)
|
|
||||||
{
|
|
||||||
QTemporaryFile *tmpfile = new QTemporaryFile(Utils::Fs::tempPath() + "XXXXXX");
|
|
||||||
if (!tmpfile->open()) {
|
|
||||||
delete tmpfile;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
tmpfile->setAutoRemove(false);
|
|
||||||
filePath = tmpfile->fileName();
|
|
||||||
qDebug("Temporary filename is: %s", qUtf8Printable(filePath));
|
|
||||||
if (m_reply->isOpen() || m_reply->open(QIODevice::ReadOnly)) {
|
|
||||||
tmpfile->write(replyData);
|
|
||||||
tmpfile->close();
|
|
||||||
// XXX: tmpfile needs to be deleted on Windows before using the file
|
|
||||||
// or it will complain that the file is used by another process.
|
|
||||||
delete tmpfile;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
delete tmpfile;
|
|
||||||
Utils::Fs::forceRemove(filePath);
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Net::DownloadHandler::handleRedirection(QUrl newUrl)
|
void Net::DownloadHandler::handleRedirection(QUrl newUrl)
|
||||||
{
|
{
|
||||||
// Resolve relative urls
|
// Resolve relative urls
|
||||||
|
|
|
@ -66,7 +66,6 @@ namespace Net
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void assignNetworkReply(QNetworkReply *reply);
|
void assignNetworkReply(QNetworkReply *reply);
|
||||||
bool saveToFile(const QByteArray &replyData, QString &filePath);
|
|
||||||
void handleRedirection(QUrl newUrl);
|
void handleRedirection(QUrl newUrl);
|
||||||
|
|
||||||
QNetworkReply *m_reply;
|
QNetworkReply *m_reply;
|
||||||
|
|
|
@ -75,7 +75,7 @@ void ReverseResolution::resolve(const QString &ip)
|
||||||
|
|
||||||
void ReverseResolution::hostResolved(const QHostInfo &host)
|
void ReverseResolution::hostResolved(const QHostInfo &host)
|
||||||
{
|
{
|
||||||
const QString &ip = m_lookups.take(host.lookupId());
|
const QString ip = m_lookups.take(host.lookupId());
|
||||||
Q_ASSERT(!ip.isNull());
|
Q_ASSERT(!ip.isNull());
|
||||||
|
|
||||||
if (host.error() != QHostInfo::NoError) {
|
if (host.error() != QHostInfo::NoError) {
|
||||||
|
@ -83,7 +83,7 @@ void ReverseResolution::hostResolved(const QHostInfo &host)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const QString &hostname = host.hostName();
|
const QString hostname = host.hostName();
|
||||||
|
|
||||||
qDebug() << Q_FUNC_INFO << ip << QString("->") << hostname;
|
qDebug() << Q_FUNC_INFO << ip << QString("->") << hostname;
|
||||||
m_cache.insert(ip, new QString(hostname));
|
m_cache.insert(ip, new QString(hostname));
|
||||||
|
|
|
@ -212,11 +212,11 @@ ScanFoldersModel::PathStatus ScanFoldersModel::addPath(const QString &watchPath,
|
||||||
if (!watchDir.exists()) return DoesNotExist;
|
if (!watchDir.exists()) return DoesNotExist;
|
||||||
if (!watchDir.isReadable()) return CannotRead;
|
if (!watchDir.isReadable()) return CannotRead;
|
||||||
|
|
||||||
const QString &canonicalWatchPath = watchDir.canonicalPath();
|
const QString canonicalWatchPath = watchDir.canonicalPath();
|
||||||
if (findPathData(canonicalWatchPath) != -1) return AlreadyInList;
|
if (findPathData(canonicalWatchPath) != -1) return AlreadyInList;
|
||||||
|
|
||||||
QDir downloadDir(downloadPath);
|
QDir downloadDir(downloadPath);
|
||||||
const QString &canonicalDownloadPath = downloadDir.canonicalPath();
|
const QString canonicalDownloadPath = downloadDir.canonicalPath();
|
||||||
|
|
||||||
if (!m_fsWatcher) {
|
if (!m_fsWatcher) {
|
||||||
m_fsWatcher = new FileSystemWatcher(this);
|
m_fsWatcher = new FileSystemWatcher(this);
|
||||||
|
@ -236,12 +236,12 @@ ScanFoldersModel::PathStatus ScanFoldersModel::addPath(const QString &watchPath,
|
||||||
ScanFoldersModel::PathStatus ScanFoldersModel::updatePath(const QString &watchPath, const PathType &downloadType, const QString &downloadPath)
|
ScanFoldersModel::PathStatus ScanFoldersModel::updatePath(const QString &watchPath, const PathType &downloadType, const QString &downloadPath)
|
||||||
{
|
{
|
||||||
QDir watchDir(watchPath);
|
QDir watchDir(watchPath);
|
||||||
const QString &canonicalWatchPath = watchDir.canonicalPath();
|
const QString canonicalWatchPath = watchDir.canonicalPath();
|
||||||
int row = findPathData(canonicalWatchPath);
|
int row = findPathData(canonicalWatchPath);
|
||||||
if (row == -1) return DoesNotExist;
|
if (row == -1) return DoesNotExist;
|
||||||
|
|
||||||
QDir downloadDir(downloadPath);
|
QDir downloadDir(downloadPath);
|
||||||
const QString &canonicalDownloadPath = downloadDir.canonicalPath();
|
const QString canonicalDownloadPath = downloadDir.canonicalPath();
|
||||||
|
|
||||||
m_pathList.at(row)->downloadType = downloadType;
|
m_pathList.at(row)->downloadType = downloadType;
|
||||||
m_pathList.at(row)->downloadPath = Utils::Fs::toNativePath(canonicalDownloadPath);
|
m_pathList.at(row)->downloadPath = Utils::Fs::toNativePath(canonicalDownloadPath);
|
||||||
|
@ -256,7 +256,7 @@ void ScanFoldersModel::addToFSWatcher(const QStringList &watchPaths)
|
||||||
|
|
||||||
foreach (const QString &path, watchPaths) {
|
foreach (const QString &path, watchPaths) {
|
||||||
QDir watchDir(path);
|
QDir watchDir(path);
|
||||||
const QString &canonicalWatchPath = watchDir.canonicalPath();
|
const QString canonicalWatchPath = watchDir.canonicalPath();
|
||||||
m_fsWatcher->addPath(canonicalWatchPath);
|
m_fsWatcher->addPath(canonicalWatchPath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -110,7 +110,7 @@ bool Utils::Fs::smartRemoveEmptyFolderTree(const QString &path)
|
||||||
if (path.isEmpty() || !QDir(path).exists())
|
if (path.isEmpty() || !QDir(path).exists())
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
static const QStringList deleteFilesList = {
|
const QStringList deleteFilesList = {
|
||||||
// Windows
|
// Windows
|
||||||
"Thumbs.db",
|
"Thumbs.db",
|
||||||
"desktop.ini",
|
"desktop.ini",
|
||||||
|
|
|
@ -139,7 +139,7 @@ void Utils::Misc::shutdownComputer(const ShutdownDialogAction &action)
|
||||||
else
|
else
|
||||||
EventToSend = kAEShutDown;
|
EventToSend = kAEShutDown;
|
||||||
AEAddressDesc targetDesc;
|
AEAddressDesc targetDesc;
|
||||||
static const ProcessSerialNumber kPSNOfSystemProcess = {0, kSystemProcess};
|
const ProcessSerialNumber kPSNOfSystemProcess = {0, kSystemProcess};
|
||||||
AppleEvent eventReply = {typeNull, NULL};
|
AppleEvent eventReply = {typeNull, NULL};
|
||||||
AppleEvent appleEventToSend = {typeNull, NULL};
|
AppleEvent appleEventToSend = {typeNull, NULL};
|
||||||
|
|
||||||
|
|
|
@ -551,7 +551,7 @@ void AddNewTorrentDialog::renameSelectedFile()
|
||||||
if (!newPath.endsWith('/')) newPath += '/';
|
if (!newPath.endsWith('/')) newPath += '/';
|
||||||
// Check for overwriting
|
// Check for overwriting
|
||||||
for (int i = 0; i < m_torrentInfo.filesCount(); ++i) {
|
for (int i = 0; i < m_torrentInfo.filesCount(); ++i) {
|
||||||
const QString ¤tName = m_torrentInfo.filePath(i);
|
const QString currentName = m_torrentInfo.filePath(i);
|
||||||
#if defined(Q_OS_UNIX) || defined(Q_WS_QWS)
|
#if defined(Q_OS_UNIX) || defined(Q_WS_QWS)
|
||||||
if (currentName.startsWith(newPath, Qt::CaseSensitive)) {
|
if (currentName.startsWith(newPath, Qt::CaseSensitive)) {
|
||||||
#else
|
#else
|
||||||
|
@ -565,7 +565,7 @@ void AddNewTorrentDialog::renameSelectedFile()
|
||||||
}
|
}
|
||||||
// Replace path in all files
|
// Replace path in all files
|
||||||
for (int i = 0; i < m_torrentInfo.filesCount(); ++i) {
|
for (int i = 0; i < m_torrentInfo.filesCount(); ++i) {
|
||||||
const QString ¤tName = m_torrentInfo.filePath(i);
|
const QString currentName = m_torrentInfo.filePath(i);
|
||||||
if (currentName.startsWith(oldPath)) {
|
if (currentName.startsWith(oldPath)) {
|
||||||
QString newName = currentName;
|
QString newName = currentName;
|
||||||
newName.replace(0, oldPath.length(), newPath);
|
newName.replace(0, oldPath.length(), newPath);
|
||||||
|
|
|
@ -41,10 +41,10 @@
|
||||||
BanListOptionsDialog::BanListOptionsDialog(QWidget *parent)
|
BanListOptionsDialog::BanListOptionsDialog(QWidget *parent)
|
||||||
: QDialog(parent)
|
: QDialog(parent)
|
||||||
, m_ui(new Ui::BanListOptionsDialog)
|
, m_ui(new Ui::BanListOptionsDialog)
|
||||||
|
, m_model(new QStringListModel(BitTorrent::Session::instance()->bannedIPs(), this))
|
||||||
, m_modified(false)
|
, m_modified(false)
|
||||||
{
|
{
|
||||||
m_ui->setupUi(this);
|
m_ui->setupUi(this);
|
||||||
m_model = new QStringListModel(BitTorrent::Session::instance()->bannedIPs(), this);
|
|
||||||
|
|
||||||
m_sortFilter = new QSortFilterProxyModel(this);
|
m_sortFilter = new QSortFilterProxyModel(this);
|
||||||
m_sortFilter->setDynamicSortFilter(true);
|
m_sortFilter->setDynamicSortFilter(true);
|
||||||
|
|
|
@ -39,12 +39,11 @@
|
||||||
ExecutionLogWidget::ExecutionLogWidget(QWidget *parent, const Log::MsgTypes &types)
|
ExecutionLogWidget::ExecutionLogWidget(QWidget *parent, const Log::MsgTypes &types)
|
||||||
: QWidget(parent)
|
: QWidget(parent)
|
||||||
, m_ui(new Ui::ExecutionLogWidget)
|
, m_ui(new Ui::ExecutionLogWidget)
|
||||||
|
, m_msgList(new LogListWidget(MAX_LOG_MESSAGES, Log::MsgTypes(types)))
|
||||||
, m_peerList(new LogListWidget(MAX_LOG_MESSAGES))
|
, m_peerList(new LogListWidget(MAX_LOG_MESSAGES))
|
||||||
{
|
{
|
||||||
m_ui->setupUi(this);
|
m_ui->setupUi(this);
|
||||||
|
|
||||||
m_msgList = new LogListWidget(MAX_LOG_MESSAGES, Log::MsgTypes(types));
|
|
||||||
|
|
||||||
#ifndef Q_OS_MAC
|
#ifndef Q_OS_MAC
|
||||||
m_ui->tabConsole->setTabIcon(0, GuiIconProvider::instance()->getIcon("view-calendar-journal"));
|
m_ui->tabConsole->setTabIcon(0, GuiIconProvider::instance()->getIcon("view-calendar-journal"));
|
||||||
m_ui->tabConsole->setTabIcon(1, GuiIconProvider::instance()->getIcon("view-filter"));
|
m_ui->tabConsole->setTabIcon(1, GuiIconProvider::instance()->getIcon("view-filter"));
|
||||||
|
|
|
@ -751,7 +751,7 @@ void PropertiesWidget::renameSelectedFile()
|
||||||
if (!newPath.endsWith('/')) newPath += '/';
|
if (!newPath.endsWith('/')) newPath += '/';
|
||||||
// Check for overwriting
|
// Check for overwriting
|
||||||
for (int i = 0; i < m_torrent->filesCount(); ++i) {
|
for (int i = 0; i < m_torrent->filesCount(); ++i) {
|
||||||
const QString ¤tName = m_torrent->filePath(i);
|
const QString currentName = m_torrent->filePath(i);
|
||||||
#if defined(Q_OS_UNIX) || defined(Q_WS_QWS)
|
#if defined(Q_OS_UNIX) || defined(Q_WS_QWS)
|
||||||
if (currentName.startsWith(newPath, Qt::CaseSensitive)) {
|
if (currentName.startsWith(newPath, Qt::CaseSensitive)) {
|
||||||
#else
|
#else
|
||||||
|
|
|
@ -515,7 +515,7 @@ void TrackerFiltersList::torrentAboutToBeDeleted(BitTorrent::TorrentHandle *cons
|
||||||
QString TrackerFiltersList::trackerFromRow(int row) const
|
QString TrackerFiltersList::trackerFromRow(int row) const
|
||||||
{
|
{
|
||||||
Q_ASSERT(row > 1);
|
Q_ASSERT(row > 1);
|
||||||
const QString &tracker = item(row)->text();
|
const QString tracker = item(row)->text();
|
||||||
QStringList parts = tracker.split(' ');
|
QStringList parts = tracker.split(' ');
|
||||||
Q_ASSERT(parts.size() >= 2);
|
Q_ASSERT(parts.size() >= 2);
|
||||||
parts.removeLast(); // Remove trailing number
|
parts.removeLast(); // Remove trailing number
|
||||||
|
@ -561,7 +561,6 @@ QStringList TrackerFiltersList::getHashes(int row)
|
||||||
TransferListFiltersWidget::TransferListFiltersWidget(QWidget *parent, TransferListWidget *transferList)
|
TransferListFiltersWidget::TransferListFiltersWidget(QWidget *parent, TransferListWidget *transferList)
|
||||||
: QFrame(parent)
|
: QFrame(parent)
|
||||||
, m_transferList(transferList)
|
, m_transferList(transferList)
|
||||||
, m_trackerFilters(nullptr)
|
|
||||||
{
|
{
|
||||||
Preferences *const pref = Preferences::instance();
|
Preferences *const pref = Preferences::instance();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue