[graphics/krita] plugins/extensions/resourcemanager: Ask to overwrite on importing duplicate resource file

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


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

Ask to overwrite on importing duplicate resource file

Before this commit, Krita wouldn't ask whether the user wants to
overwrite the resource or not. The import would just fail.
This commit adds a question dialog. However, the import
of the resource still fails because it needs changes in the
KisResourceModel too.

CCMAIL:kde-i18n-doc at kde.org

M  +13   -3    plugins/extensions/resourcemanager/ResourceImporter.cpp

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

diff --git a/plugins/extensions/resourcemanager/ResourceImporter.cpp b/plugins/extensions/resourcemanager/ResourceImporter.cpp
index 138c680112..06800acfa3 100644
--- a/plugins/extensions/resourcemanager/ResourceImporter.cpp
+++ b/plugins/extensions/resourcemanager/ResourceImporter.cpp
@@ -236,9 +236,7 @@ void ResourceImporter::importResources(QString startPath)
         }
     }
 
-
-
-
+    QString resourceLocationBase = KisResourceLocator::instance()->resourceLocationBase();
 
     QStringList resourceFiles = resourceTypePerFile.keys();
     for (int i = 0; i < resourceFiles.count(); i++) {
@@ -247,6 +245,18 @@ void ResourceImporter::importResources(QString startPath)
         if (m_resourceModelsForResourceType.contains(resourceType)) {
             if (debug) qCritical() << "We do have a resource model for that!";
             KisResourceModel* model = m_resourceModelsForResourceType[resourceType];
+            // check if the file already exists there
+            QString filepath = resourceLocationBase + "/" + resourceType + "/" + QFileInfo(resourceFiles[i]).fileName();
+            QFileInfo fi(filepath);
+            qCritical() << "Checking if the file: " << filepath << "exists: " << fi.exists();
+            if (fi.exists()) {
+                if(QMessageBox::question(m_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?"),
+                                         QMessageBox::Yes | QMessageBox::Cancel, QMessageBox::Cancel) == QMessageBox::Cancel) {
+                    continue;
+                }
+            }
+
             KoResourceSP res = model->importResourceFile(resourceFiles[i]);
             if (res.isNull()) {
                 if (debug) qCritical() << "But the resource is null :( ";



More information about the kde-i18n-doc mailing list