mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-02-02 18:04:32 +00:00
Use QThread::requestInterruption() instead of m_abort flag
This commit is contained in:
parent
60524348f0
commit
7e87eeb2d4
@ -58,14 +58,13 @@ TorrentCreatorThread::TorrentCreatorThread(QObject *parent)
|
|||||||
: QThread(parent)
|
: QThread(parent)
|
||||||
, m_private(false)
|
, m_private(false)
|
||||||
, m_pieceSize(0)
|
, m_pieceSize(0)
|
||||||
, m_abort(false)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
TorrentCreatorThread::~TorrentCreatorThread()
|
TorrentCreatorThread::~TorrentCreatorThread()
|
||||||
{
|
{
|
||||||
m_abort = true;
|
requestInterruption();
|
||||||
wait();
|
wait(1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TorrentCreatorThread::create(const QString &inputPath, const QString &savePath, const QStringList &trackers,
|
void TorrentCreatorThread::create(const QString &inputPath, const QString &savePath, const QStringList &trackers,
|
||||||
@ -80,7 +79,6 @@ void TorrentCreatorThread::create(const QString &inputPath, const QString &saveP
|
|||||||
m_comment = comment;
|
m_comment = comment;
|
||||||
m_private = isPrivate;
|
m_private = isPrivate;
|
||||||
m_pieceSize = pieceSize;
|
m_pieceSize = pieceSize;
|
||||||
m_abort = false;
|
|
||||||
|
|
||||||
start();
|
start();
|
||||||
}
|
}
|
||||||
@ -90,11 +88,6 @@ void TorrentCreatorThread::sendProgressSignal(int numHashes, int numPieces)
|
|||||||
emit updateProgress(static_cast<int>((numHashes * 100.) / numPieces));
|
emit updateProgress(static_cast<int>((numHashes * 100.) / numPieces));
|
||||||
}
|
}
|
||||||
|
|
||||||
void TorrentCreatorThread::abortCreation()
|
|
||||||
{
|
|
||||||
m_abort = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void TorrentCreatorThread::run()
|
void TorrentCreatorThread::run()
|
||||||
{
|
{
|
||||||
emit updateProgress(0);
|
emit updateProgress(0);
|
||||||
@ -104,7 +97,8 @@ void TorrentCreatorThread::run()
|
|||||||
libt::file_storage fs;
|
libt::file_storage fs;
|
||||||
// Adding files to the torrent
|
// Adding files to the torrent
|
||||||
libt::add_files(fs, Utils::Fs::toNativePath(m_inputPath).toStdString(), fileFilter);
|
libt::add_files(fs, Utils::Fs::toNativePath(m_inputPath).toStdString(), fileFilter);
|
||||||
if (m_abort) return;
|
|
||||||
|
if (isInterruptionRequested()) return;
|
||||||
|
|
||||||
libt::create_torrent t(fs, m_pieceSize);
|
libt::create_torrent t(fs, m_pieceSize);
|
||||||
|
|
||||||
@ -125,7 +119,8 @@ void TorrentCreatorThread::run()
|
|||||||
t.add_tracker(tracker.trimmed().toStdString(), tier);
|
t.add_tracker(tracker.trimmed().toStdString(), tier);
|
||||||
newline = false;
|
newline = false;
|
||||||
}
|
}
|
||||||
if (m_abort) return;
|
|
||||||
|
if (isInterruptionRequested()) return;
|
||||||
|
|
||||||
// calculate the hash for all pieces
|
// calculate the hash for all pieces
|
||||||
const QString parentPath = Utils::Fs::branchPath(m_inputPath) + "/";
|
const QString parentPath = Utils::Fs::branchPath(m_inputPath) + "/";
|
||||||
@ -136,7 +131,8 @@ void TorrentCreatorThread::run()
|
|||||||
t.set_comment(m_comment.toUtf8().constData());
|
t.set_comment(m_comment.toUtf8().constData());
|
||||||
// Is private ?
|
// Is private ?
|
||||||
t.set_priv(m_private);
|
t.set_priv(m_private);
|
||||||
if (m_abort) return;
|
|
||||||
|
if (isInterruptionRequested()) return;
|
||||||
|
|
||||||
// create the torrent and print it to out
|
// create the torrent and print it to out
|
||||||
qDebug("Saving to %s", qPrintable(m_savePath));
|
qDebug("Saving to %s", qPrintable(m_savePath));
|
||||||
@ -152,6 +148,8 @@ void TorrentCreatorThread::run()
|
|||||||
if (outfile.fail())
|
if (outfile.fail())
|
||||||
throw std::exception();
|
throw std::exception();
|
||||||
|
|
||||||
|
if (isInterruptionRequested()) return;
|
||||||
|
|
||||||
libt::bencode(std::ostream_iterator<char>(outfile), t.generate());
|
libt::bencode(std::ostream_iterator<char>(outfile), t.generate());
|
||||||
outfile.close();
|
outfile.close();
|
||||||
|
|
||||||
|
@ -46,7 +46,6 @@ namespace BitTorrent
|
|||||||
|
|
||||||
void create(const QString &inputPath, const QString &savePath, const QStringList &trackers,
|
void create(const QString &inputPath, const QString &savePath, const QStringList &trackers,
|
||||||
const QStringList &urlSeeds, const QString &comment, bool isPrivate, int pieceSize);
|
const QStringList &urlSeeds, const QString &comment, bool isPrivate, int pieceSize);
|
||||||
void abortCreation();
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void run();
|
void run();
|
||||||
@ -66,7 +65,6 @@ namespace BitTorrent
|
|||||||
QString m_comment;
|
QString m_comment;
|
||||||
bool m_private;
|
bool m_private;
|
||||||
int m_pieceSize;
|
int m_pieceSize;
|
||||||
bool m_abort;
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,16 +86,8 @@ TorrentCreatorDlg::~TorrentCreatorDlg()
|
|||||||
{
|
{
|
||||||
saveSettings();
|
saveSettings();
|
||||||
|
|
||||||
// End torrent creation thread
|
if (m_creatorThread)
|
||||||
if (m_creatorThread) {
|
|
||||||
if (m_creatorThread->isRunning()) {
|
|
||||||
m_creatorThread->abortCreation();
|
|
||||||
m_creatorThread->terminate();
|
|
||||||
// Wait for termination
|
|
||||||
m_creatorThread->wait();
|
|
||||||
}
|
|
||||||
delete m_creatorThread;
|
delete m_creatorThread;
|
||||||
}
|
|
||||||
|
|
||||||
delete m_ui;
|
delete m_ui;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user