[calligra] krita/ui: Ask user for a file when a File Layer doesn't exist

Boudewijn Rempt boud at valdyas.org
Fri May 9 07:12:42 UTC 2014


There's api for that:

KoDocument.h:    bool saveInBatchMode() const;

On Monday 05 May 2014 May 13:44:08 Dmitry Kazakov wrote:
> Git commit 4b96de279603d93edf8d9a76cd433898c21a201a by Dmitry Kazakov.
> Committed on 05/05/2014 at 13:43.
> Pushed by dkazakov into branch 'master'.
> 
> Ask user for a file when a File Layer doesn't exist
> 
> TODO: we need to be able to check whether we are running inside
>       of a calligraconverter or in a gui mode. Firing up message boxes
>       might not be the best idea for a calligraconverter :(
> 
> BUG:333326
> CCMAIL:kimageshop at kde.org
> 
> M  +1    -1    krita/ui/kis_doc2.cc
> M  +7    -0    krita/ui/kis_file_layer.cpp
> M  +37   -1    krita/ui/kra/kis_kra_loader.cpp
> 
> http://commits.kde.org/calligra/4b96de279603d93edf8d9a76cd433898c21a201a
> 
> diff --git a/krita/ui/kis_doc2.cc b/krita/ui/kis_doc2.cc
> index 1f3e332..ee9fea6 100644
> --- a/krita/ui/kis_doc2.cc
> +++ b/krita/ui/kis_doc2.cc
> @@ -251,7 +251,7 @@ QDomDocument KisDoc2::saveXML()
>  
>      root.appendChild(m_d->kraSaver->saveXML(doc, m_d->image));
>      if (!m_d->kraSaver->errorMessages().isEmpty()) {
> -        setErrorMessage(m_d->kraLoader->errorMessages().join(".\n"));
> +        setErrorMessage(m_d->kraSaver->errorMessages().join(".\n"));
>      }
>  
>      return doc;
> diff --git a/krita/ui/kis_file_layer.cpp b/krita/ui/kis_file_layer.cpp
> index 5b86e4e..5eb7170 100644
> --- a/krita/ui/kis_file_layer.cpp
> +++ b/krita/ui/kis_file_layer.cpp
> @@ -34,6 +34,13 @@ KisFileLayer::KisFileLayer(KisImageWSP image, const QString &basePath, const QSt
>      , m_filename(filename)
>      , m_scalingMethod(scaleToImageResolution)
>  {
> +    /**
> +     * Set default paint device for a layer. It will be used is case
> +     * the file does not exist anymore. Or course, this can happen only
> +     * in the failing execution path.
> +     */
> +    m_image = new KisPaintDevice(image->colorSpace());
> +
>      connect(&m_loader, SIGNAL(loadingFinished()), SLOT(slotLoadingFinished()));
>      m_loader.setPath(path());
>      m_loader.reloadImage();
> diff --git a/krita/ui/kra/kis_kra_loader.cpp b/krita/ui/kra/kis_kra_loader.cpp
> index 0027b7b..874e4f0 100644
> --- a/krita/ui/kra/kis_kra_loader.cpp
> +++ b/krita/ui/kra/kis_kra_loader.cpp
> @@ -19,12 +19,17 @@
>  
>  #include "kra/kis_kra_loader.h"
>  
> +#include <QApplication>
>  #include <QStringList>
>  
> +#include <kmessagebox.h>
> +
>  #include <KoStore.h>
>  #include <KoColorSpaceRegistry.h>
>  #include <KoColorProfile.h>
>  #include <KoDocumentInfo.h>
> +#include <KoFileDialog.h>
> +#include <KoFilterManager.h>
>  
>  #include <filter/kis_filter.h>
>  #include <filter/kis_filter_registry.h>
> @@ -585,7 +590,38 @@ KisNodeSP KisKraLoader::loadFileLayer(const KoXmlElement& element, KisImageWSP i
>          documentPath = m_d->document->url().toLocalFile();
>      }
>      QFileInfo info(documentPath);
> -    KisLayer *layer = new KisFileLayer(image, info.absolutePath(), filename, (KisFileLayer::ScalingMethod)scalingMethod, name, opacity);
> +    QString basePath = info.absolutePath();
> +
> +    QString fullPath = basePath + QDir::separator() + filename;
> +
> +    if (!QFileInfo(fullPath).exists()) {
> +        QString msg = i18nc(
> +            "@info",
> +            "The file associated to a file layer with the name \"%1\" is not found.<nl/><nl/>"
> +            "Expected path:<nl/>"
> +            "%2<nl/><nl/>"
> +            "Do you want to locate it manually?", name, fullPath);
> +
> +        int result = KMessageBox::warningYesNo(0, msg,
> +                                               i18n("File not found"));
> +
> +        if (result == KMessageBox::Yes) {
> +
> +            KoFileDialog dialog(0, KoFileDialog::OpenFile, "OpenDocument");
> +            dialog.setMimeTypeFilters(KoFilterManager::mimeFilter("application/x-krita", KoFilterManager::Import));
> +            dialog.setDefaultDir(basePath);
> +            QString url = dialog.url();
> +
> +            if (!QFileInfo(basePath).exists()) {
> +                filename = url;
> +            } else {
> +                QDir d(basePath);
> +                filename = d.relativeFilePath(url);
> +            }
> +        }
> +    }
> +
> +    KisLayer *layer = new KisFileLayer(image, basePath, filename, (KisFileLayer::ScalingMethod)scalingMethod, name, opacity);
>      Q_CHECK_PTR(layer);
>  
>      return layer;
> _______________________________________________
> Krita mailing list
> kimageshop at kde.org
> https://mail.kde.org/mailman/listinfo/kimageshop

-- 
Boudewijn Rempt
http://www.valdyas.org, http://www.krita.org, http://www.boudewijnrempt.nl



More information about the kimageshop mailing list