From dfc7d80eefc73e0c5267b9bd5e1f8cb2105eac82 Mon Sep 17 00:00:00 2001 From: Kai Uwe Broulik Date: Sun, 20 Apr 2025 12:48:58 +0200 Subject: [PATCH] [PATCH] CopyJob: Inhibit suspend during copy operation Avoids the system going to sleep during a lengthy copy operation. BUG: 362542 Gbp-Pq: Name upstream_60191c04_CopyJob-Inhibit-suspend-during-copy-operation.patch --- src/core/copyjob.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/core/copyjob.cpp b/src/core/copyjob.cpp index c0cda13..80bfe9f 100644 --- a/src/core/copyjob.cpp +++ b/src/core/copyjob.cpp @@ -57,6 +57,7 @@ #include #include +#include #include #include @@ -65,6 +66,7 @@ Q_DECLARE_LOGGING_CATEGORY(KIO_COPYJOB_DEBUG) Q_LOGGING_CATEGORY(KIO_COPYJOB_DEBUG, "kf.kio.core.copyjob", QtWarningMsg) using namespace KIO; +using namespace std::literals::chrono_literals; // this will update the report dialog with 5 Hz, I think this is fast enough, aleXXX static constexpr int s_reportTimeout = 200; @@ -402,6 +404,8 @@ public: void slotReport(); + void doInhibitSuspend() override; + Q_DECLARE_PUBLIC(CopyJob) static inline CopyJob *newJob(const QList &src, const QUrl &dest, CopyJob::CopyMode mode, bool asMethod, JobFlags flags) @@ -496,6 +500,11 @@ void CopyJobPrivate::slotStart() } } + // Avoid DBus traffic for short-lived jobs. + QTimer::singleShot(10s, q, [this] { + doInhibitSuspend(); + }); + /** We call the functions directly instead of using signals. Calling a function via a signal takes approx. 65 times the time @@ -739,6 +748,18 @@ bool CopyJob::doResume() return Job::doResume(); } +void CopyJobPrivate::doInhibitSuspend() +{ + QString reason; + if (m_mode == CopyJob::Move) { + reason = i18nc("Reason why standby is blocked", "Files are being moved"); + } else { + reason = i18nc("Reason why standby is blocked", "Files are being copied"); + } + + inhibitSuspend(reason); +} + void CopyJobPrivate::slotReport() { Q_Q(CopyJob); -- 2.30.2