1 /* ============================================================ 2 * 3 * This file is a part of digiKam project 4 * https://www.digikam.org 5 * 6 * Date : 2008-11-24 7 * Description : Batch Tools Factory. 8 * 9 * Copyright (C) 2008-2021 by Gilles Caulier <caulier dot gilles at gmail dot com> 10 * 11 * This program is free software; you can redistribute it 12 * and/or modify it under the terms of the GNU General 13 * Public License as published by the Free Software Foundation; 14 * either version 2, or (at your option) 15 * any later version. 16 * 17 * This program is distributed in the hope that it will be useful, 18 * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 * GNU General Public License for more details. 21 * 22 * ============================================================ */ 23 24 #include "batchtoolsfactory.h" 25 26 // Local includes 27 28 #include "digikam_config.h" 29 #include "digikam_debug.h" 30 #include "dpluginloader.h" 31 #include "dpluginbqm.h" 32 #include "dbinfoiface.h" 33 34 namespace Digikam 35 { 36 37 class Q_DECL_HIDDEN BatchToolsFactory::Private 38 { 39 40 public: 41 Private()42 explicit Private() 43 : iface(nullptr) 44 { 45 } 46 47 DBInfoIface* iface; 48 49 BatchToolsList toolsList; 50 }; 51 52 // -------------------------------------------------------------------------------- 53 54 class Q_DECL_HIDDEN BatchToolsFactoryCreator 55 { 56 public: 57 58 BatchToolsFactory object; 59 }; 60 Q_GLOBAL_STATIC(BatchToolsFactoryCreator,batchToolsManagerCreator)61Q_GLOBAL_STATIC(BatchToolsFactoryCreator, batchToolsManagerCreator) 62 63 // -------------------------------------------------------------------------------- 64 65 BatchToolsFactory* BatchToolsFactory::instance() 66 { 67 return &batchToolsManagerCreator->object; 68 } 69 BatchToolsFactory()70BatchToolsFactory::BatchToolsFactory() 71 : d(new Private) 72 { 73 d->iface = new DBInfoIface(this); 74 DPluginLoader* const dpl = DPluginLoader::instance(); 75 76 foreach (DPlugin* const p, dpl->allPlugins()) 77 { 78 DPluginBqm* const bqm = dynamic_cast<DPluginBqm*>(p); 79 80 if (bqm) 81 { 82 bqm->setup(this); 83 84 qCDebug(DIGIKAM_GENERAL_LOG) << "BQM plugin named" << bqm->name() 85 << "registered to" << this; 86 87 foreach (BatchTool* const t, bqm->tools(this)) 88 { 89 registerTool(t); 90 } 91 } 92 } 93 } 94 ~BatchToolsFactory()95BatchToolsFactory::~BatchToolsFactory() 96 { 97 delete d; 98 } 99 toolsList() const100BatchToolsList BatchToolsFactory::toolsList() const 101 { 102 return d->toolsList; 103 } 104 infoIface() const105DInfoInterface* BatchToolsFactory::infoIface() const 106 { 107 return d->iface; 108 } 109 registerTool(BatchTool * const tool)110void BatchToolsFactory::registerTool(BatchTool* const tool) 111 { 112 if (!tool) 113 { 114 return; 115 } 116 117 d->toolsList.append(tool); 118 } 119 findTool(const QString & name,BatchTool::BatchToolGroup group) const120BatchTool* BatchToolsFactory::findTool(const QString& name, BatchTool::BatchToolGroup group) const 121 { 122 foreach (BatchTool* const tool, d->toolsList) 123 { 124 if ((tool->objectName() == name) && (tool->toolGroup() == group)) 125 { 126 return tool; 127 } 128 } 129 130 return nullptr; 131 } 132 133 } // namespace Digikam 134