File indexing completed on 2025-03-09 03:58:50
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2008-11-24 0007 * Description : Batch Tools Factory. 0008 * 0009 * SPDX-FileCopyrightText: 2008-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 "batchtoolsfactory.h" 0016 0017 // Local includes 0018 0019 #include "digikam_config.h" 0020 #include "digikam_debug.h" 0021 #include "dpluginloader.h" 0022 #include "dpluginbqm.h" 0023 #include "dbinfoiface.h" 0024 0025 namespace Digikam 0026 { 0027 0028 class Q_DECL_HIDDEN BatchToolsFactory::Private 0029 { 0030 0031 public: 0032 0033 explicit Private() 0034 : iface(nullptr) 0035 { 0036 } 0037 0038 DBInfoIface* iface; 0039 0040 BatchToolsList toolsList; 0041 }; 0042 0043 // -------------------------------------------------------------------------------- 0044 0045 class Q_DECL_HIDDEN BatchToolsFactoryCreator 0046 { 0047 public: 0048 0049 BatchToolsFactory object; 0050 }; 0051 0052 Q_GLOBAL_STATIC(BatchToolsFactoryCreator, batchToolsManagerCreator) 0053 0054 // -------------------------------------------------------------------------------- 0055 0056 BatchToolsFactory* BatchToolsFactory::instance() 0057 { 0058 return &batchToolsManagerCreator->object; 0059 } 0060 0061 BatchToolsFactory::BatchToolsFactory() 0062 : d(new Private) 0063 { 0064 d->iface = new DBInfoIface(this); 0065 DPluginLoader* const dpl = DPluginLoader::instance(); 0066 bool hasJXLSupport = dpl->canExport(QLatin1String("JXL")); 0067 bool hasWEBPSupport = dpl->canExport(QLatin1String("WEBP")); 0068 bool hasAVIFSupport = dpl->canExport(QLatin1String("AVIF")); 0069 0070 Q_FOREACH (DPlugin* const p, dpl->allPlugins()) 0071 { 0072 DPluginBqm* const bqm = dynamic_cast<DPluginBqm*>(p); 0073 0074 if (bqm) 0075 { 0076 // NOTE: Do not load JXL convert BQM plugin if DImg do not have JXL support. 0077 0078 if ( 0079 (bqm->iid() == QLatin1String("org.kde.digikam.plugin.bqm.ConvertToJxl")) && 0080 !hasJXLSupport 0081 ) 0082 { 0083 continue; 0084 } 0085 0086 if ( 0087 (bqm->iid() == QLatin1String("org.kde.digikam.plugin.bqm.ConvertToWebp")) && 0088 !hasWEBPSupport 0089 ) 0090 { 0091 continue; 0092 } 0093 0094 if ( 0095 (bqm->iid() == QLatin1String("org.kde.digikam.plugin.bqm.ConvertToAvif")) && 0096 !hasAVIFSupport 0097 ) 0098 { 0099 continue; 0100 } 0101 0102 bqm->setup(this); 0103 /* 0104 qCDebug(DIGIKAM_GENERAL_LOG) << "BQM plugin named" << bqm->name() 0105 << "registered to" << this; 0106 */ 0107 Q_FOREACH (BatchTool* const t, bqm->tools(this)) 0108 { 0109 registerTool(t); 0110 } 0111 } 0112 } 0113 } 0114 0115 BatchToolsFactory::~BatchToolsFactory() 0116 { 0117 delete d; 0118 } 0119 0120 BatchToolsList BatchToolsFactory::toolsList() const 0121 { 0122 return d->toolsList; 0123 } 0124 0125 DInfoInterface* BatchToolsFactory::infoIface() const 0126 { 0127 return d->iface; 0128 } 0129 0130 void BatchToolsFactory::registerTool(BatchTool* const tool) 0131 { 0132 if (!tool) 0133 { 0134 return; 0135 } 0136 0137 d->toolsList.append(tool); 0138 } 0139 0140 BatchTool* BatchToolsFactory::findTool(const QString& name, BatchTool::BatchToolGroup group) const 0141 { 0142 Q_FOREACH (BatchTool* const tool, d->toolsList) 0143 { 0144 if ((tool->objectName() == name) && (tool->toolGroup() == group)) 0145 { // cppcheck-suppress useStlAlgorithm 0146 return tool; 0147 } 0148 } 0149 0150 return nullptr; 0151 } 0152 0153 } // namespace Digikam 0154 0155 #include "moc_batchtoolsfactory.cpp"