File indexing completed on 2025-01-19 03:57:40
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2018-07-30 0007 * Description : stand alone test application for plugin 0008 * loader and generic tools. 0009 * 0010 * SPDX-FileCopyrightText: 2018-2024 by Gilles Caulier <caulier dot gilles at gmail dot com> 0011 * 0012 * SPDX-License-Identifier: GPL-2.0-or-later 0013 * 0014 * ============================================================ */ 0015 0016 // Qt Includes 0017 0018 #include <QApplication> 0019 #include <QCommandLineParser> 0020 #include <QUrl> 0021 #include <QIcon> 0022 #include <QLibraryInfo> 0023 0024 // Local includes 0025 0026 #include "metaengine.h" 0027 #include "dmetainfoiface.h" 0028 #include "dpluginloader.h" 0029 #include "dplugingeneric.h" 0030 #include "digikam_debug.h" 0031 0032 using namespace Digikam; 0033 0034 int main(int argc, char* argv[]) 0035 { 0036 QApplication app(argc, argv); 0037 0038 #if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) 0039 0040 qCDebug(DIGIKAM_TESTS_LOG) << QLibraryInfo::path(QLibraryInfo::LibrariesPath); 0041 qCDebug(DIGIKAM_TESTS_LOG) << QLibraryInfo::path(QLibraryInfo::LibraryExecutablesPath); 0042 qCDebug(DIGIKAM_TESTS_LOG) << QLibraryInfo::path(QLibraryInfo::PluginsPath); 0043 0044 #else 0045 0046 qCDebug(DIGIKAM_TESTS_LOG) << QLibraryInfo::location(QLibraryInfo::LibrariesPath); 0047 qCDebug(DIGIKAM_TESTS_LOG) << QLibraryInfo::location(QLibraryInfo::LibraryExecutablesPath); 0048 qCDebug(DIGIKAM_TESTS_LOG) << QLibraryInfo::location(QLibraryInfo::PluginsPath); 0049 0050 #endif 0051 0052 QCommandLineParser parser; 0053 parser.addHelpOption(); 0054 parser.setApplicationDescription(QLatin1String("Test application to run digiKam generic plugins as stand alone\n" 0055 "Example: ./loadandrun_generic -l \"org.kde.digikam.plugin.generic.TimeAdjust\" -a \"timeadjust_edit\" /mnt/photo/*.jpg")); 0056 0057 parser.addOption(QCommandLineOption(QStringList() << QLatin1String("list"), QLatin1String("List all available plugins"))); 0058 parser.addOption(QCommandLineOption(QStringList() << QLatin1String("l"), QLatin1String("Unique name ID of the plugin to use"), QLatin1String("Plugin IID"))); 0059 parser.addOption(QCommandLineOption(QStringList() << QLatin1String("a"), QLatin1String("Plugin internal action name to run"), QLatin1String("Internal Action Name"))); 0060 parser.addOption(QCommandLineOption(QStringList() << QLatin1String("w"), QLatin1String("Wait until plugin non-modal dialog is closed"))); 0061 parser.addPositionalArgument(QLatin1String("files"), QLatin1String("File(s) to open"), QLatin1String("+[file(s)]")); 0062 parser.process(app); 0063 0064 QList<QUrl> urlList; 0065 const QStringList args = parser.positionalArguments(); 0066 0067 for (auto& arg : args) 0068 { 0069 urlList.append(QUrl::fromLocalFile(arg)); 0070 } 0071 0072 DMetaInfoIface iface(qApp, urlList); 0073 DPluginLoader* const dpl = DPluginLoader::instance(); 0074 dpl->init(); 0075 dpl->registerGenericPlugins(&iface); 0076 0077 bool found = false; 0078 0079 if (parser.isSet(QString::fromLatin1("list"))) 0080 { 0081 Q_FOREACH (DPlugin* const p, dpl->allPlugins()) 0082 { 0083 DPluginGeneric* const gene = dynamic_cast<DPluginGeneric*>(p); 0084 0085 if (gene) 0086 { 0087 qCDebug(DIGIKAM_TESTS_LOG) << "--------------------------------------------"; 0088 qCDebug(DIGIKAM_TESTS_LOG) << "IID :" << p->iid(); 0089 qCDebug(DIGIKAM_TESTS_LOG) << "Name :" << p->name(); 0090 qCDebug(DIGIKAM_TESTS_LOG) << "Version:" << p->version(); 0091 qCDebug(DIGIKAM_TESTS_LOG) << "Desc :" << p->description(); 0092 0093 QString authors; 0094 0095 Q_FOREACH (const DPluginAuthor& au, p->authors()) 0096 { 0097 authors.append(au.toString()); 0098 authors.append(QLatin1String(" ; ")); 0099 } 0100 0101 qCDebug(DIGIKAM_TESTS_LOG) << "Authors:" << authors; 0102 0103 QString actions; 0104 0105 Q_FOREACH (DPluginAction* const ac, gene->actions(&iface)) 0106 { 0107 actions.append(ac->toString()); 0108 actions.append(QLatin1String(" ; ")); 0109 } 0110 0111 qCDebug(DIGIKAM_TESTS_LOG) << "Actions:" << actions; 0112 } 0113 } 0114 0115 return 0; 0116 } 0117 else if (parser.isSet(QString::fromLatin1("l"))) 0118 { 0119 const QString name = parser.value(QString::fromLatin1("l")); 0120 QString action; 0121 0122 if (parser.isSet(QString::fromLatin1("a"))) 0123 { 0124 action = parser.value(QString::fromLatin1("a")); 0125 } 0126 else 0127 { 0128 qCDebug(DIGIKAM_TESTS_LOG) << "Plugin action name to run is missing..."; 0129 qCDebug(DIGIKAM_TESTS_LOG) << "Use --help option for details."; 0130 return -1; 0131 } 0132 0133 MetaEngine::initializeExiv2(); 0134 0135 Q_FOREACH (DPlugin* const p, dpl->allPlugins()) 0136 { 0137 if (p->iid() == name) 0138 { 0139 DPluginGeneric* const gene = dynamic_cast<DPluginGeneric*>(p); 0140 0141 if (gene) 0142 { 0143 found = true; 0144 DPluginAction* const ac = gene->findActionByName(action, &iface); 0145 0146 if (ac) 0147 { 0148 ac->trigger(); 0149 0150 if (parser.isSet(QString::fromLatin1("w"))) 0151 { 0152 app.exec(); 0153 } 0154 } 0155 else 0156 { 0157 qCDebug(DIGIKAM_TESTS_LOG) << action << "action not found in plugin!"; 0158 0159 QString actions; 0160 0161 Q_FOREACH (DPluginAction* const gac, gene->actions(&iface)) 0162 { 0163 actions.append(gac->toString()); 0164 actions.append(QLatin1String(" ; ")); 0165 } 0166 0167 qCDebug(DIGIKAM_TESTS_LOG) << "Available Actions:" << actions; 0168 } 0169 0170 break; 0171 } 0172 } 0173 } 0174 } 0175 else 0176 { 0177 qCDebug(DIGIKAM_TESTS_LOG) << "Command line option not recognized..."; 0178 qCDebug(DIGIKAM_TESTS_LOG) << "Use --help option for details."; 0179 return -1; 0180 } 0181 0182 if (!found) 0183 { 0184 qCDebug(DIGIKAM_TESTS_LOG) << "Plugin not found!"; 0185 return -1; 0186 } 0187 0188 return 0; 0189 }