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