[graphics/krita] libs/resourcewidgets: Add KisResourceOverwriteDialog in a common area

Agata Cacko null at kde.org
Sat Aug 7 13:46:58 BST 2021


Git commit c7f5e50280b41d59cef730fab8be178ccf935b15 by Agata Cacko.
Committed on 07/08/2021 at 12:46.
Pushed by tymond into branch 'master'.

Add KisResourceOverwriteDialog in a common area

Before this commit, all places where the user is asked
whether they want to overwrite a resource or not
would have to have their own dialogs.
This commit adds a common function to call to get the same
dialog.
It also adds a convenient function to check if the resource
is in the resource folder.
Since it's not a definitive, generic function (it doesn't
check bundles and other storages, only the folder storage)
it's just a helper function, hence it's here, and not in
the ResourceLocator.

CCMAIL:kde-i18n-doc at kde.org

M  +1    -0    libs/resourcewidgets/CMakeLists.txt
A  +30   -0    libs/resourcewidgets/KisResourceOverwriteDialog.cpp     [License: LGPL(v2.0+)]
A  +26   -0    libs/resourcewidgets/KisResourceOverwriteDialog.h     [License: LGPL(v2.0+)]

https://invent.kde.org/graphics/krita/commit/c7f5e50280b41d59cef730fab8be178ccf935b15

diff --git a/libs/resourcewidgets/CMakeLists.txt b/libs/resourcewidgets/CMakeLists.txt
index ae3f1bc44e..16cce1dfa8 100644
--- a/libs/resourcewidgets/CMakeLists.txt
+++ b/libs/resourcewidgets/CMakeLists.txt
@@ -15,6 +15,7 @@ set(kritaresourcewidgets_LIB_SRCS
     KisResourceTaggingManager.cpp
     KisStorageChooserWidget.cpp
     TagActions.cpp
+    KisResourceOverwriteDialog.cpp
 )
 
 add_library(kritaresourcewidgets SHARED ${kritaresourcewidgets_LIB_SRCS})
diff --git a/libs/resourcewidgets/KisResourceOverwriteDialog.cpp b/libs/resourcewidgets/KisResourceOverwriteDialog.cpp
new file mode 100644
index 0000000000..1f2a7dcc5f
--- /dev/null
+++ b/libs/resourcewidgets/KisResourceOverwriteDialog.cpp
@@ -0,0 +1,30 @@
+/*
+ *    This file is part of the KDE project
+ *    SPDX-FileCopyrightText: 2021 Agata Cacko <cacko.azh at gmail.com>
+ *
+ *    SPDX-License-Identifier: LGPL-2.0-or-later
+ */
+
+#include "KisResourceOverwriteDialog.h"
+
+#include <QMessageBox>
+#include <QFileInfo>
+
+#include <klocalizedstring.h>
+
+#include <KisResourceLocator.h>
+
+bool KisResourceOverwriteDialog::userAllowsOverwrite(QWidget* widgetParent, QString resourceFilepath)
+{
+    return QMessageBox::question(widgetParent, i18nc("Dialog title", "Overwrite the file?"),
+                          i18nc("Question in a dialog/messagebox", "This resource file already exists in the resource folder. Do you want to overwrite it?\nResource filename: %1", QFileInfo(resourceFilepath).fileName()),
+                                 QMessageBox::Yes | QMessageBox::Cancel, QMessageBox::Cancel) != QMessageBox::Cancel;
+}
+
+bool KisResourceOverwriteDialog::resourceExistsInResourceFolder(QString resourceType, QString filepath)
+{
+    QString resourceLocationBase = KisResourceLocator::instance()->resourceLocationBase();
+    QString newFilepath = resourceLocationBase + "/" + resourceType + "/" + QFileInfo(filepath).fileName();
+    QFileInfo fi(newFilepath);
+    return fi.exists();
+}
diff --git a/libs/resourcewidgets/KisResourceOverwriteDialog.h b/libs/resourcewidgets/KisResourceOverwriteDialog.h
new file mode 100644
index 0000000000..ab125e95b0
--- /dev/null
+++ b/libs/resourcewidgets/KisResourceOverwriteDialog.h
@@ -0,0 +1,26 @@
+/*
+ * SPDX-FileCopyrightText: 2021 Agata Cacko <cacko.azh at gmail.com>
+ *
+ * SPDX-License-Identifier: LGPL-2.0-or-later
+ */
+
+#ifndef KIS_RESOURCE_OVERWRITE_DIALOG_H
+#define KIS_RESOURCE_OVERWRITE_DIALOG_H
+
+#include <QWidget>
+#include "kritaresourcewidgets_export.h"
+
+
+class KRITARESOURCEWIDGETS_EXPORT KisResourceOverwriteDialog
+{
+
+public:
+    static bool userAllowsOverwrite(QWidget* widgetParent, QString resourceFilepath);
+    static bool resourceExistsInResourceFolder(QString resourceType, QString filepath);
+
+
+
+
+};
+
+#endif // KIS_RESOURCE_OVERWRITE_DIALOG_H



More information about the kde-i18n-doc mailing list