File indexing completed on 2024-04-28 05:26:46
0001 /* 0002 * SPDX-FileCopyrightText: 2013 Aleix Pol Gonzalez <aleixpol@blue-systems.com> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0005 */ 0006 0007 #include "BackendNotifierFactory.h" 0008 #include <BackendNotifierModule.h> 0009 #include <QCoreApplication> 0010 #include <QDebug> 0011 #include <QDir> 0012 #include <QPluginLoader> 0013 0014 BackendNotifierFactory::BackendNotifierFactory() = default; 0015 0016 QList<BackendNotifierModule *> BackendNotifierFactory::allBackends() const 0017 { 0018 QList<BackendNotifierModule *> ret; 0019 0020 const auto libraryPaths = QCoreApplication::instance()->libraryPaths(); 0021 for (const QString &path : libraryPaths) { 0022 QDir dir(path + QStringLiteral("/discover-notifier/")); 0023 const auto files = dir.entryList(QDir::Files); 0024 for (const QString &file : files) { 0025 QString fullPath = dir.absoluteFilePath(file); 0026 QPluginLoader loader(fullPath); 0027 loader.load(); 0028 ret += qobject_cast<BackendNotifierModule *>(loader.instance()); 0029 if (ret.last() == nullptr) { 0030 qWarning() << "couldn't load" << fullPath << "because" << loader.errorString(); 0031 ret.removeLast(); 0032 } 0033 } 0034 } 0035 if (ret.isEmpty()) 0036 qWarning() << "couldn't find any notifier backend" << QCoreApplication::instance()->libraryPaths(); 0037 0038 return ret; 0039 }