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 #ifndef BTWAITJOB_H
0007 #define BTWAITJOB_H
0008 
0009 #include <KIO/Job>
0010 #include <QList>
0011 
0012 #include "constants.h"
0013 #include <interfaces/exitoperation.h>
0014 #include <ktorrent_export.h>
0015 
0016 namespace bt
0017 {
0018 /**
0019  * @author Joris Guisson <joris.guisson@gmail.com>
0020  *
0021  * Job to wait for a certain amount of time or until one or more ExitOperation's have
0022  * finished.
0023  */
0024 class KTORRENT_EXPORT WaitJob : public KIO::Job
0025 {
0026 public:
0027     WaitJob(Uint32 millis);
0028     ~WaitJob() override;
0029 
0030     virtual void kill(bool quietly = true);
0031 
0032     /**
0033      * Add an ExitOperation;
0034      * @param op The operation
0035      */
0036     void addExitOperation(ExitOperation *op);
0037 
0038     /**
0039      * Add a KIO::Job to wait on;
0040      * @param job The job
0041      */
0042     void addExitOperation(KIO::Job *job);
0043 
0044     /**
0045      * Execute a WaitJob
0046      * @param job The Job
0047      */
0048     static void execute(WaitJob *job);
0049 
0050     /// Are there any ExitOperation's we need to wait for
0051     bool needToWait() const
0052     {
0053         return exit_ops.count() > 0;
0054     }
0055 
0056 private:
0057     void timerDone();
0058     void operationFinished(ExitOperation *op);
0059 
0060 private:
0061     QList<ExitOperation *> exit_ops;
0062 };
0063 
0064 KTORRENT_EXPORT void SynchronousWait(Uint32 millis);
0065 
0066 }
0067 
0068 #endif