File indexing completed on 2025-01-05 04:37:31
0001 /* 0002 SPDX-FileCopyrightText: 2005 Joris Guisson <joris.guisson@gmail.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 #include "waitjob.h" 0007 #include "log.h" 0008 #include <qtimer.h> 0009 #include <torrent/globals.h> 0010 0011 namespace bt 0012 { 0013 WaitJob::WaitJob(Uint32 millis) 0014 : KIO::Job(/*false*/) 0015 { 0016 QTimer::singleShot(millis, this, &WaitJob::timerDone); 0017 } 0018 0019 WaitJob::~WaitJob() 0020 { 0021 for (ExitOperation *op : std::as_const(exit_ops)) 0022 delete op; 0023 } 0024 0025 void WaitJob::kill(bool) 0026 { 0027 emitResult(); 0028 } 0029 0030 void WaitJob::timerDone() 0031 { 0032 emitResult(); 0033 } 0034 0035 void WaitJob::addExitOperation(ExitOperation *op) 0036 { 0037 exit_ops.append(op); 0038 connect(op, &ExitOperation::operationFinished, this, &WaitJob::operationFinished); 0039 } 0040 0041 void WaitJob::addExitOperation(KIO::Job *job) 0042 { 0043 addExitOperation(new ExitJobOperation(job)); 0044 } 0045 0046 void WaitJob::operationFinished(ExitOperation *op) 0047 { 0048 if (exit_ops.count() > 0) { 0049 exit_ops.removeAll(op); 0050 if (op->deleteAllowed()) 0051 op->deleteLater(); 0052 0053 if (exit_ops.count() == 0) 0054 timerDone(); 0055 } 0056 } 0057 0058 void WaitJob::execute(WaitJob *job) 0059 { 0060 job->exec(); 0061 } 0062 0063 void SynchronousWait(Uint32 millis) 0064 { 0065 Out(SYS_GEN | LOG_DEBUG) << "SynchronousWait" << endl; 0066 WaitJob *j = new WaitJob(millis); 0067 j->exec(); 0068 } 0069 0070 }