[PATCH] CopyJob: Inhibit suspend during copy operation
authorKai Uwe Broulik <kde@privat.broulik.de>
Sun, 20 Apr 2025 10:48:58 +0000 (12:48 +0200)
committerAurélien COUDERC <coucouf@debian.org>
Sun, 8 Jun 2025 12:42:29 +0000 (14:42 +0200)
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

index c0cda134956012970412c29eb5eead917f90be59..80bfe9f80983b56b4f6a1466980658df28318afa 100644 (file)
@@ -57,6 +57,7 @@
 #include <KFileUtils>
 #include <KIO/FileSystemFreeSpaceJob>
 
+#include <chrono>
 #include <list>
 #include <set>
 
@@ -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<QUrl> &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);