File indexing completed on 2025-01-19 03:53:16

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2019-09-08
0007  * Description : a Raw Import plugin based on LibRaw.
0008  *
0009  * SPDX-FileCopyrightText: 2020-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0010  *
0011  * SPDX-License-Identifier: GPL-2.0-or-later
0012  *
0013  * ============================================================ */
0014 
0015 #include "rawimportnativeplugin.h"
0016 
0017 // Qt includes
0018 
0019 #include <QPointer>
0020 #include <QString>
0021 #include <QApplication>
0022 
0023 // KDE includes
0024 
0025 #include <klocalizedstring.h>
0026 
0027 // Local includes
0028 
0029 #include "digikam_debug.h"
0030 #include "rawimport.h"
0031 #include "editorcore.h"
0032 #include "editortooliface.h"
0033 
0034 namespace DigikamRawImportNativePlugin
0035 {
0036 
0037 RawImportNativePlugin::RawImportNativePlugin(QObject* const parent)
0038     : DPluginRawImport(parent)
0039 {
0040 }
0041 
0042 RawImportNativePlugin::~RawImportNativePlugin()
0043 {
0044 }
0045 
0046 QString RawImportNativePlugin::name() const
0047 {
0048     return i18n("Import Raw Using Libraw");
0049 }
0050 
0051 QString RawImportNativePlugin::iid() const
0052 {
0053     return QLatin1String(DPLUGIN_IID);
0054 }
0055 
0056 QIcon RawImportNativePlugin::icon() const
0057 {
0058     return QIcon::fromTheme(QLatin1String("image-x-adobe-dng"));
0059 }
0060 
0061 QString RawImportNativePlugin::description() const
0062 {
0063     return i18n("A tool to import Raw images using Libraw engine");
0064 }
0065 
0066 QString RawImportNativePlugin::details() const
0067 {
0068     return i18n("<p>This Image Editor tool import Raw images using Libraw engine as decoder.</p>"
0069                 "<p>This is the <b>native</b> Raw Import tool included in core application. "
0070                 "It does not require any external engine to work.</p>"
0071                 "<p>See Libraw web site for details: <a href='https://www.libraw.org/'>https://www.libraw.org/</a></p>");
0072 }
0073 
0074 QString RawImportNativePlugin::handbookSection() const
0075 {
0076     return QLatin1String("setup_application");
0077 }
0078 
0079 QString RawImportNativePlugin::handbookChapter() const
0080 {
0081     return QLatin1String("editor_settings");
0082 }
0083 
0084 QString RawImportNativePlugin::handbookReference() const
0085 {
0086     return QLatin1String("setup-raw");
0087 }
0088 
0089 QList<DPluginAuthor> RawImportNativePlugin::authors() const
0090 {
0091     return QList<DPluginAuthor>()
0092             << DPluginAuthor(QString::fromUtf8("Gilles Caulier"),
0093                              QString::fromUtf8("caulier dot gilles at gmail dot com"),
0094                              QString::fromUtf8("(C) 2008-2022"))
0095             ;
0096 }
0097 
0098 void RawImportNativePlugin::setup(QObject* const)
0099 {
0100 }
0101 
0102 bool RawImportNativePlugin::run(const QString& filePath, const DRawDecoding& def)
0103 {
0104     m_filePath                 = filePath;
0105     m_defaultSettings          = def;
0106     EditorCore* const core     = EditorCore::defaultInstance();
0107     RawImport* const rawImport = new RawImport(QUrl::fromLocalFile(filePath), core);
0108     rawImport->setProperty("DPluginIId",      iid());
0109     rawImport->setProperty("DPluginIfaceIId", ifaceIid());
0110     rawImport->setPlugin(this);
0111 
0112     EditorToolIface::editorToolIface()->loadTool(rawImport);
0113 
0114     connect(rawImport, SIGNAL(okClicked()),
0115             this, SLOT(slotLoadRawFromTool()));
0116 
0117     connect(rawImport, SIGNAL(cancelClicked()),
0118             this, SLOT(slotLoadRaw()));
0119 
0120     return true;
0121 }
0122 
0123 void RawImportNativePlugin::slotLoadRawFromTool()
0124 {
0125     RawImport* const rawImport = dynamic_cast<RawImport*>(EditorToolIface::editorToolIface()->currentTool());
0126 
0127     if (!rawImport)
0128         return;
0129 
0130     LoadingDescription props(m_filePath, LoadingDescription::ConvertForEditor);
0131     props.rawDecodingSettings = rawImport->rawDecodingSettings();
0132     props.rawDecodingHint     = LoadingDescription::RawDecodingCustomSettings;
0133 
0134     if (rawImport->hasPostProcessedImage())
0135     {
0136         // Image was previously decoded in Import tool: load pre-decoded image as well in editor.
0137         Q_EMIT signalDecodedImage(props, rawImport->postProcessedImage());
0138     }
0139     else
0140     {
0141         // Image was not previously decoded in Import tool: as to editor to post-process image and load it.
0142         Q_EMIT signalLoadRaw(props);
0143     }
0144 }
0145 
0146 void RawImportNativePlugin::slotLoadRaw()
0147 {
0148     // Cancel pressed: we load Raw with image editor default Raw decoding settings.
0149     Q_EMIT signalLoadRaw(LoadingDescription(m_filePath,
0150                                           m_defaultSettings,
0151                                           LoadingDescription::RawDecodingGlobalSettings,
0152                                           LoadingDescription::ConvertForEditor));
0153 }
0154 
0155 } // namespace DigikamRawImportNativePlugin
0156 
0157 #include "moc_rawimportnativeplugin.cpp"