Krita is a free and open source cross-platform application that offers an end-to-end solution for creating digital art files from scratch built on the KDE and Qt frameworks.
C++
Create a wrapper to add a do-not-ask checkbox to a messagebox
Halla Remptc97cd6525ebe
diff --git a/libs/global/CMakeLists.txt b/libs/global/CMakeLists.txtindex 8822dc4d41..21a809c5bc 100644--- a/libs/global/CMakeLists.txt+++ b/libs/global/CMakeLists.txt@@ -44,6 +44,7 @@ set(kritaglobal_LIB_SRCSKisSampleRectIterator.cppKisCursorOverrideLock.cppkis_random_source.cpp+ KisMessageBoxWrapper.cpp)if(WIN32)@@ -67,6 +68,12 @@ endif()kis_add_library(kritaglobal SHARED ${kritaglobal_LIB_SRCS})++target_sources(kritaglobal+ PRIVATE+ KisMessageBoxWrapper.h+ KisMessageBoxWrapper.cpp+)generate_export_header(kritaglobal BASE_NAME kritaglobal)target_link_libraries(kritaglobal@@ -77,6 +84,7 @@ target_link_libraries(kritaglobalQt${QT_MAJOR_VERSION}::WidgetsQt${QT_MAJOR_VERSION}::XmlKF${KF_MAJOR}::I18n+ KF${KF_MAJOR}::ConfigCoreBoost::boostzuglagerdiff --git a/libs/global/KisMessageBoxWrapper.cpp b/libs/global/KisMessageBoxWrapper.cppnew file mode 100644index 0000000000..23492d2bb4--- /dev/null+++ b/libs/global/KisMessageBoxWrapper.cpp@@ -0,0 +1,36 @@+/*+ * SPDX-FileCopyrightText: 2025 Halla Rempt <[email protected]>+ *+ * SPDX-License-Identifier: LGPL-2.0-or-later+ */++#include <KisMessageBoxWrapper.h>+#include <QMessageBox>+#include <QString>+#include <QCheckBox>++#include <kconfig.h>+#include <kconfiggroup.h>+#include <ksharedconfig.h>+#include <klocalizedstring.h>++namespace KisMessageBoxWrapper {++int doNotAskAgainMessageBoxWrapper(QMessageBox *messageBox, const QString &identifier)+{+ KConfigGroup cfg(KSharedConfig::openConfig(), "DoNotAskAgain");+ bool showMessage = cfg.readEntry(identifier, true);+ if (showMessage) {+ QCheckBox *cb = new QCheckBox(i18n("Don't ask this again"));+ messageBox->setCheckBox(cb);+ const int res = messageBox->exec();+ cfg.writeEntry(identifier, cb->checkState() == Qt::CheckState::Unchecked);+ return res;+ }+ else {+ return QMessageBox::Yes;+ }+}+++}diff --git a/libs/global/KisMessageBoxWrapper.h b/libs/global/KisMessageBoxWrapper.hnew file mode 100644index 0000000000..66dcaae64b--- /dev/null+++ b/libs/global/KisMessageBoxWrapper.h@@ -0,0 +1,36 @@+/*+ * SPDX-FileCopyrightText: 2025 Halla Rempt <[email protected]>+ *+ * SPDX-License-Identifier: LGPL-2.0-or-later+ */++#ifndef KISMESSAGEBOXWRAPPER_H+#define KISMESSAGEBOXWRAPPER_H++class QMessageBox;+class QString;++#include "kritaglobal_export.h"++/**+ * Wrap a QMessageBox+ */+namespace KisMessageBoxWrapper {+++/**+ * @brief doNotAskAgainMessageBoxWrapper takes a messagebox and an identifier and+ * adds a Do Not Ask Again checkbox to the messagebox; then runs the checkbox and+ * returns the return balue+ * @param messageBox the wrapped messagebox+ * @param identifier a unique identifier that is used to store the the check+ * in the config file+ * @return the result of running the messagebox. If the messagebox is not shown,+ * the return value is QMessageBox::Yes+ */+KRITAGLOBAL_EXPORT int doNotAskAgainMessageBoxWrapper(QMessageBox *messageBox, const QString &identifier);+++}++#endif // KISMESSAGEBOXWRAPPER_Hdiff --git a/libs/ui/KisRemoteFileFetcher.cpp b/libs/ui/KisRemoteFileFetcher.cppindex 8c78480e39..16e3de846c 100644--- a/libs/ui/KisRemoteFileFetcher.cpp+++ b/libs/ui/KisRemoteFileFetcher.cpp@@ -16,6 +16,8 @@#include <klocalizedstring.h>+#include <KisMessageBoxWrapper.h>+KisRemoteFileFetcher::KisRemoteFileFetcher(QObject *parent): QObject(parent), m_request(nullptr)@@ -44,7 +46,7 @@ bool KisRemoteFileFetcher::fetchFile(const QUrl &remote, QIODevice *io)msgBox.setDetailedText(remote.toDisplayString());msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);msgBox.setDefaultButton(QMessageBox::No);- const int res = msgBox.exec();+ const int res = KisMessageBoxWrapper::doNotAskAgainMessageBoxWrapper(&msgBox, "KisRemoteFileFetcher");if (res != QMessageBox::Yes) {return false;