[graphics/krita/krita/6.0] libs/global: [android] Allow copying content URI to temp file

Carsten Hartenfels <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit 5bff73566d25dc26f6398d039b48959d5803dbc2 by Carsten Hartenfels.
Committed on 27/07/2026 at 17:19.
Pushed by hartenfels into branch 'krita/6.0'.

[android] Allow copying content URI to temp file

Since that will be needed for a subsequent commit to support audio in
animations, MLT can't read from content URIs directly.

M  +56   -19   libs/global/KisAndroidUtils.cpp
M  +5    -0    libs/global/KisAndroidUtils.h

https://invent.kde.org/graphics/krita/-/commit/5bff73566d25dc26f6398d039b48959d5803dbc2

diff --git a/libs/global/KisAndroidUtils.cpp b/libs/global/KisAndroidUtils.cpp
index 2856695ca5a..a0b9e89e7f5 100644
--- a/libs/global/KisAndroidUtils.cpp
+++ b/libs/global/KisAndroidUtils.cpp
@@ -6,6 +6,7 @@
 #include <kis_debug.h>
 
 #include <QFile>
+#include <QTemporaryFile>
 
 #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
 #include <QJniEnvironment>
@@ -101,26 +102,14 @@ void setFullScreen(bool fullScreen)
     }
 }
 
-bool copyFile(const QString &inputPath, const QString &outputPath, QString *outErrorMessage)
+namespace
+{
+bool copyFileContents(const QString &inputPath,
+                      const QString &outputPath,
+                      QFile &inputFile,
+                      QFile &outputFile,
+                      QString *outErrorMessage)
 {
-    QFile inputFile(inputPath);
-    if (!inputFile.open(QIODevice::ReadOnly)) {
-        if (outErrorMessage) {
-            *outErrorMessage =
-                QStringLiteral("failed to open input file '%1': %2").arg(inputPath).arg(inputFile.errorString());
-        }
-        return false;
-    }
-
-    QFile outputFile(outputPath);
-    if (!outputFile.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
-        if (outErrorMessage) {
-            *outErrorMessage =
-                QStringLiteral("failed to open output file '%1': %2").arg(outputPath).arg(outputFile.errorString());
-        }
-        return false;
-    }
-
     QByteArray buffer;
     buffer.resize(BUFSIZ);
     while (true) {
@@ -169,5 +158,53 @@ bool copyFile(const QString &inputPath, const QString &outputPath, QString *outE
         }
     }
 }
+} // namespace
+
+bool copyFile(const QString &inputPath, const QString &outputPath, QString *outErrorMessage)
+{
+    QFile inputFile(inputPath);
+    if (!inputFile.open(QIODevice::ReadOnly)) {
+        if (outErrorMessage) {
+            *outErrorMessage =
+                QStringLiteral("failed to open input file '%1': %2").arg(inputPath).arg(inputFile.errorString());
+        }
+        return false;
+    }
+
+    QFile outputFile(outputPath);
+    if (!outputFile.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
+        if (outErrorMessage) {
+            *outErrorMessage =
+                QStringLiteral("failed to open output file '%1': %2").arg(outputPath).arg(outputFile.errorString());
+        }
+        return false;
+    }
+
+    return copyFileContents(inputPath, outputPath, inputFile, outputFile, outErrorMessage);
+}
+
+bool copyFileToTemporary(const QString &inputPath, QTemporaryFile &outputFile, QString *outErrorMessage)
+{
+    QFile inputFile(inputPath);
+    if (!inputFile.open(QIODevice::ReadOnly)) {
+        if (outErrorMessage) {
+            *outErrorMessage =
+                QStringLiteral("failed to open input file '%1': %2").arg(inputPath).arg(inputFile.errorString());
+        }
+        return false;
+    }
+
+    if (!outputFile.open()) {
+        if (outErrorMessage) {
+            *outErrorMessage = QStringLiteral("failed to open temporary output file: %1").arg(outputFile.errorString());
+        }
+        return false;
+    }
+
+    if (outErrorMessage) {
+        outErrorMessage->clear();
+    }
+    return copyFileContents(inputPath, outputFile.fileName(), inputFile, outputFile, outErrorMessage);
+}
 
 } // namespace KisAndroidUtils
diff --git a/libs/global/KisAndroidUtils.h b/libs/global/KisAndroidUtils.h
index 3bf828877d9..b90f08f4d45 100644
--- a/libs/global/KisAndroidUtils.h
+++ b/libs/global/KisAndroidUtils.h
@@ -7,6 +7,8 @@
 #include <QString>
 #include <kritaglobal_export.h>
 
+class QTemporaryFile;
+
 namespace KisAndroidUtils
 {
 
@@ -40,6 +42,9 @@ KRITAGLOBAL_EXPORT void setFullScreen(bool fullScreen);
 KRITAGLOBAL_EXPORT bool
 copyFile(const QString &inputPath, const QString &outputPath, QString *outErrorMessage = nullptr);
 
+KRITAGLOBAL_EXPORT bool
+copyFileToTemporary(const QString &inputPath, QTemporaryFile &outputFile, QString *outErrorMessage = nullptr);
+
 } // namespace KisAndroidUtils
 
 #endif // __KISANDROIDUTILS_H_
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.