Warning, file /utilities/krusader/app/JobMan/krjob.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 SPDX-FileCopyrightText: 2016-2022 Krusader Krew <https://krusader.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 #ifndef KRJOB_H 0007 #define KRJOB_H 0008 0009 #include <KIO/CopyJob> 0010 #include <KIO/DropJob> 0011 #include <KIO/Job> 0012 0013 /** 0014 * Wrapper for KIO::Job cause it has limitations. 0015 * 0016 * KIO::Jobs cannot be started in pause mode (and pausing directly after creation is buggy). 0017 * Instead, a KrJob can be created which creates the KIO::Job on first start() call. 0018 * 0019 * Started jobs are recorded by KIO/FileUndoManager (if supported). 0020 * 0021 * KrJob is deleted after KIO::Job was deleted (which is after finished() call). Do not use 0022 * KIO::Job::finished() but KrJob::terminated() to be prepared for job deletion. 0023 */ 0024 class KrJob : public QObject 0025 { 0026 Q_OBJECT 0027 public: 0028 /** Supported job types. Add other types if needed.*/ 0029 enum Type { Copy, Move, Link, Trash, Delete }; 0030 0031 /** Create a new copy, move, or link job. */ 0032 static KrJob *createCopyJob(KIO::CopyJob::CopyMode mode, const QList<QUrl> &src, const QUrl &destination, KIO::JobFlags flags); 0033 /** Create a new trash or delete job. */ 0034 static KrJob *createDeleteJob(const QList<QUrl> &urls, bool moveToTrash); 0035 /** Create a drop job - the copy job is already started.*/ 0036 static KrJob *createDropJob(KIO::DropJob *dropJob, KIO::CopyJob *job); 0037 0038 /** Start or resume this job. If job was started started() is emitted. */ 0039 void start(); 0040 /** Cancel this job and mark for deletion. terminated() will be emitted.*/ 0041 void cancel(); 0042 /** Suspend job (if started). */ 0043 void pause(); 0044 0045 /** Return true if job was started and is not suspended(). */ 0046 bool isRunning() const 0047 { 0048 return m_job && !m_job->isSuspended(); 0049 } 0050 /** Return true if job was started and then paused by user. */ 0051 bool isPaused() const 0052 { 0053 return m_job && m_job->isSuspended(); 0054 } 0055 /** Return percent progress of job. */ 0056 int percent() const 0057 { 0058 return m_job ? static_cast<int>(m_job->percent()) : 0; 0059 } 0060 0061 /** Return (initial) job description. 0062 * The KIO::Job emits a more detailed description after start. 0063 */ 0064 QString description() const 0065 { 0066 return m_description; 0067 } 0068 0069 signals: 0070 /** Emitted if job was started. Parameter is the KIO::Job that was created. */ 0071 void started(KIO::Job *job); 0072 /** Emitted if job is finished or was canceled. Job will be deleted afterwards. */ 0073 void terminated(KrJob *krJob); 0074 0075 private: 0076 KrJob(Type type, 0077 const QList<QUrl> &urls, 0078 const QUrl &dest, 0079 KIO::JobFlags flags, 0080 const QString &description, 0081 KIO::CopyJob *copyJob = nullptr, 0082 KIO::DropJob *dropJob = nullptr); 0083 static KrJob *createKrCopyJob(KIO::CopyJob::CopyMode mode, 0084 const QList<QUrl> &src, 0085 const QUrl &destination, 0086 KIO::JobFlags flags, 0087 KIO::CopyJob *job = nullptr, 0088 KIO::DropJob *dropJob = nullptr); 0089 void connectStartedJob(); 0090 0091 const Type m_type; 0092 const QList<QUrl> m_urls; 0093 const QUrl m_dest; 0094 const KIO::JobFlags m_flags; 0095 const QString m_description; 0096 0097 KIO::Job *m_job; 0098 KIO::DropJob *m_dropJob; 0099 }; 0100 0101 #endif // KRJOB_H