File: BackendNotifierFactory.cpp

package info (click to toggle)
plasma-discover 6.5.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 14,288 kB
  • sloc: cpp: 30,576; xml: 2,710; python: 311; sh: 5; makefile: 5
file content (47 lines) | stat: -rw-r--r-- 1,701 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
 *   SPDX-FileCopyrightText: 2013 Aleix Pol Gonzalez <aleixpol@blue-systems.com>
 *
 *   SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
 */

#include "BackendNotifierFactory.h"
#include <BackendNotifierModule.h>
#include <QCoreApplication>
#include <QDebug>
#include <QDir>
#include <QPluginLoader>

using namespace Qt::StringLiterals;

BackendNotifierFactory::BackendNotifierFactory() = default;

QList<BackendNotifierModule *> BackendNotifierFactory::allBackends() const
{
    QList<BackendNotifierModule *> ret;

    const auto libraryPaths = QCoreApplication::instance()->libraryPaths();
    for (const QString &path : libraryPaths) {
        QDir dir(path + QStringLiteral("/discover-notifier/"));
        const auto files = dir.entryList(QDir::Files);
        for (const QString &file : files) {
            QString fullPath = dir.absoluteFilePath(file);
            QPluginLoader loader(fullPath);
            loader.load();

            if (const auto iid = loader.metaData().value("IID"_L1).toString(); iid != QLatin1StringView(DISCOVER_NOTIFIER_IID)) {
                qDebug() << "Plugin" << fullPath << "doesn't have the right IID" << iid << "expected" << DISCOVER_NOTIFIER_IID;
                continue;
            }

            ret += qobject_cast<BackendNotifierModule *>(loader.instance());
            if (ret.last() == nullptr) {
                qWarning() << "couldn't load" << fullPath << "because" << loader.errorString();
                ret.removeLast();
            }
        }
    }
    if (ret.isEmpty())
        qWarning() << "couldn't find any notifier backend" << QCoreApplication::instance()->libraryPaths();

    return ret;
}