[graphics/kphotoalbum/import_requires_an_image] ImportExport: Disable next button if no images are selected

Randall Rude <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit 0b98c2d3790f14b2ed5e199f13fc5827ed5da34f by Randall Rude.
Committed on 16/08/2026 at 22:32.
Pushed by rsquared into branch 'import_requires_an_image'.

Disable next button if no images are selected

M  +22   -6    ImportExport/ImportDialog.cpp
M  +4    -2    ImportExport/ImportDialog.h

https://invent.kde.org/graphics/kphotoalbum/-/commit/0b98c2d3790f14b2ed5e199f13fc5827ed5da34f

diff --git a/ImportExport/ImportDialog.cpp b/ImportExport/ImportDialog.cpp
index 5b8f65659..5760ede34 100644
--- a/ImportExport/ImportDialog.cpp
+++ b/ImportExport/ImportDialog.cpp
@@ -1,6 +1,7 @@
-// SPDX-FileCopyrightText: 2003-2020 The KPhotoAlbum Development Team
-// SPDX-FileCopyrightText: 2022-2023 Johannes Zarl-Zierl <[email protected]>
+// SPDX-FileCopyrightText: 2003 - 2020 The KPhotoAlbum Development Team
+// SPDX-FileCopyrightText: 2022 - 2023 Johannes Zarl-Zierl <[email protected]>
 // SPDX-FileCopyrightText: 2024 Tobias Leupold <[email protected]>
+// SPDX-FileCopyrightText: 2026 Randall Rude <[email protected]>
 //
 // SPDX-License-Identifier: GPL-2.0-or-later
 
@@ -170,6 +171,19 @@ void ImportDialog::createImagesPage()
         DB::ImageInfoPtr info = *it;
         ImageRow *ir = new ImageRow(info, this, m_kimFileReader, container);
         lay3->addWidget(ir->m_checkbox, row, 0);
+        connect(ir->m_checkbox, &QPushButton::clicked, this, [=, this]() {
+                bool valid = false;
+
+                for (ImageRow *row : std::as_const(m_imagesSelect)) {
+                    if (row->m_checkbox->isChecked()) {
+                        valid = true;
+                        break;
+                    }
+                }
+
+                // Disable the Next button unless at least one image is selected.
+                setValid(m_selectImagesPage, valid);
+            });
 
         QPixmap pixmap = m_kimFileReader->loadThumbnail(info->fileName().relative());
         if (!pixmap.isNull()) {
@@ -188,7 +202,7 @@ void ImportDialog::createImagesPage()
         m_imagesSelect.append(ir);
     }
 
-    addPage(top, i18n("Select Which Images to Import"));
+    m_selectImagesPage = addPage(top, i18n("Select Which Images to Import"));
 }
 
 void ImportDialog::createDestination()
@@ -333,15 +347,17 @@ void ImportDialog::next()
 
 void ImportDialog::slotSelectAll()
 {
-    selectImage(true);
+    selectImages(true);
+    setValid(m_selectImagesPage, true);
 }
 
 void ImportDialog::slotSelectNone()
 {
-    selectImage(false);
+    selectImages(false);
+    setValid(m_selectImagesPage, false);
 }
 
-void ImportDialog::selectImage(bool on)
+void ImportDialog::selectImages(bool on)
 {
     for (ImageRow *row : std::as_const(m_imagesSelect)) {
         row->m_checkbox->setChecked(on);
diff --git a/ImportExport/ImportDialog.h b/ImportExport/ImportDialog.h
index fb612c134..fc90abdaf 100644
--- a/ImportExport/ImportDialog.h
+++ b/ImportExport/ImportDialog.h
@@ -1,5 +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: 2026 Randall Rude <[email protected]>
 //
 // SPDX-License-Identifier: GPL-2.0-or-later
 
@@ -51,7 +52,7 @@ protected:
     void createDestination();
     void createCategoryPages();
     ImportMatcher *createCategoryPage(const QString &myCategory, const QString &otherCategory);
-    void selectImage(bool on);
+    void selectImages(bool on);
     DB::ImageInfoList selectedImages() const;
     void possiblyAddMD5CheckPage();
 
@@ -71,6 +72,7 @@ private:
     QLineEdit *m_destinationEdit = nullptr;
     KPageWidgetItem *m_destinationPage = nullptr;
     KPageWidgetItem *m_categoryMatcherPage = nullptr;
+    KPageWidgetItem *m_selectImagesPage = nullptr;
     KPageWidgetItem *m_dummy = nullptr;
     ImportMatcher *m_categoryMatcher = nullptr;
     ImportMatchers m_matchers;
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.