[graphics/kphotoalbum/remove_workaround] ImportExport: Remove zip export limit for new karchive

Randall Rude <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit 11f5fa714ed91d6c05929e354765fc75c2f411b6 by Randall Rude.
Committed on 18/08/2026 at 16:37.
Pushed by rsquared into branch 'remove_workaround'.

Remove zip export limit for new karchive

M  +31   -2    ImportExport/Export.cpp
M  +4    -3    ImportExport/Export.h

https://invent.kde.org/graphics/kphotoalbum/-/commit/11f5fa714ed91d6c05929e354765fc75c2f411b6

diff --git a/ImportExport/Export.cpp b/ImportExport/Export.cpp
index b3878f733..2b7178900 100644
--- a/ImportExport/Export.cpp
+++ b/ImportExport/Export.cpp
@@ -30,6 +30,7 @@
 #include <kpabase/FileNameList.h>
 #include <kpabase/FileNameUtil.h>
 #include <kpabase/FileUtil.h>
+#include <karchive_version.h>
 
 #include <KConfigGroup>
 #include <KHelpClient>
@@ -62,7 +63,18 @@ bool isRAW(const DB::FileName &fileName)
 
 void Export::imageExport(const DB::FileNameList &list)
 {
-    ExportConfig config(list.size());
+    quint64 totalSize = 0;
+    for (const auto &fileName : list) {
+        const auto fileInfo = QFileInfo(fileName.absolute());
+        const auto size = fileInfo.size();
+        if (size == 0) {
+            qCWarning(ImportExportLog) << "Can't determine size for"
+                                       << fileName.relative();
+        }
+        totalSize += size;
+    }
+
+    ExportConfig config(list.size(), totalSize);
     if (config.exec() == QDialog::Rejected)
         return;
 
@@ -89,7 +101,7 @@ void Export::imageExport(const DB::FileNameList &list)
 }
 
 // PENDING(blackie) add warning if images are to be copied into a non empty directory.
-ExportConfig::ExportConfig(qsizetype numberOfFiles)
+ExportConfig::ExportConfig(qsizetype numberOfFiles, quint64 totalSizeInBytes)
 {
     setWindowTitle(i18nc("@title:window", "Export Metadata / Copy Files"));
     QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel | QDialogButtonBox::Help);
@@ -121,6 +133,23 @@ ExportConfig::ExportConfig(qsizetype numberOfFiles)
     boxLay->addWidget(m_link);
     boxLay->addWidget(m_symlink);
 
+#if (KARCHIVE_VERSION < QT_VERSION_CHECK(6,29,0))
+    // KZip silently creates an broken zip file if the zip file size exceeds
+    // 4GB.  This limit prevents the user from exporting a broken zip file.
+    // We can't predict the zip file size without creating it so keep the limit
+    // lower than 4GB.
+    const quint64 MAX_INLINE_BYTES = 4ULL * 1024 * 1024 * 1024 - // 4 GB
+                                     100 * 1024 * 1024;          // 100 MB
+
+    qCWarning(ImportExportLog) << "totalSizeInBytes=" << totalSizeInBytes
+                               << "MAX_INLINE_BYTES=" << MAX_INLINE_BYTES;
+
+    if (totalSizeInBytes > MAX_INLINE_BYTES) {
+        m_include->setEnabled(false);
+        m_include->setToolTip(i18n("The exported files are too large to fit in the .kim file."));
+    }
+#endif
+
     // Compress
     mp_compress = new QCheckBox(i18n("Compress export file"), top);
     lay1->addWidget(mp_compress);
diff --git a/ImportExport/Export.h b/ImportExport/Export.h
index afba9e046..efbe67967 100644
--- a/ImportExport/Export.h
+++ b/ImportExport/Export.h
@@ -1,6 +1,6 @@
-// SPDX-FileCopyrightText: 2003 - 2010 Jesper K. Pedersen <[email protected]>
+// SPDX-FileCopyrightText: 2003-2010 Jesper K. Pedersen <[email protected]>
 // SPDX-FileCopyrightText: 2022 Johannes Zarl-Zierl <[email protected]>
-// SPDX-FileCopyrightText: 2025 - 2026 Randall Rude <[email protected]>
+// SPDX-FileCopyrightText: 2025 Randall Rude <[email protected]>
 //
 // SPDX-License-Identifier: GPL-2.0-or-later
 
@@ -80,8 +80,9 @@ class ExportConfig : public QDialog
 public:
     /**
      * @param numberOfFiles is the number of media files to export
+     * @param totalSizeInBytes is the combined size of the media files
      */
-    ExportConfig(qsizetype numberOfFiles);
+    ExportConfig(qsizetype numberOfFiles, quint64 totalSizeInBytes);
     QCheckBox *mp_compress;
     QCheckBox *mp_generateThumbnails;
     QCheckBox *mp_enforeMaxSize;
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.