File indexing completed on 2024-11-24 04:31:15
0001 /* 0002 SPDX-FileCopyrightText: 2009 Joris Guisson <joris.guisson@gmail.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "preallocationjob.h" 0008 #include "chunkmanager.h" 0009 #include "preallocationthread.h" 0010 #include <torrent/torrentcontrol.h> 0011 #include <util/log.h> 0012 0013 namespace bt 0014 { 0015 PreallocationJob::PreallocationJob(ChunkManager *cman, TorrentControl *tc) 0016 : Job(false, tc) 0017 , cman(cman) 0018 , prealloc_thread(nullptr) 0019 { 0020 } 0021 0022 PreallocationJob::~PreallocationJob() 0023 { 0024 } 0025 0026 void PreallocationJob::start() 0027 { 0028 prealloc_thread = new PreallocationThread(); 0029 cman->preparePreallocation(prealloc_thread); 0030 connect(prealloc_thread, &PreallocationThread::finished, this, &PreallocationJob::finished, Qt::QueuedConnection); 0031 prealloc_thread->start(QThread::IdlePriority); 0032 } 0033 0034 void PreallocationJob::kill(bool quietly) 0035 { 0036 if (prealloc_thread) { 0037 prealloc_thread->stop(); 0038 prealloc_thread->wait(); 0039 prealloc_thread->deleteLater(); 0040 prealloc_thread = nullptr; 0041 } 0042 bt::Job::kill(quietly); 0043 } 0044 0045 void PreallocationJob::finished() 0046 { 0047 if (prealloc_thread) { 0048 torrent()->preallocFinished(prealloc_thread->errorMessage(), !prealloc_thread->isStopped()); 0049 prealloc_thread->deleteLater(); 0050 prealloc_thread = nullptr; 0051 } else 0052 torrent()->preallocFinished(QString(), false); 0053 0054 setError(0); 0055 emitResult(); 0056 } 0057 0058 } 0059 0060 #include "moc_preallocationjob.cpp"