diff --git a/src/appdata/data-provider-manager.cpp b/src/appdata/data-provider-manager.cpp index f1f213b..63d87ea 100644 --- a/src/appdata/data-provider-manager.cpp +++ b/src/appdata/data-provider-manager.cpp @@ -42,7 +42,7 @@ void DataProviderManager::initProviders() auto *allProvider = new AllAppDataProvider; registerProvider(allProvider); - activateProvider(allProvider->name()); + activateProvider(allProvider->id()); allProvider->moveToThread(&m_worker); } @@ -53,14 +53,14 @@ void DataProviderManager::registerProvider(DataProviderPluginIFace *provider) return; } - if (m_providers.contains(provider->name())) { + if (m_providers.contains(provider->id())) { return; } - m_providers.insert(provider->name(), provider); + m_providers.insert(provider->id(), provider); connect(provider, &AllAppDataProvider::dataChanged, this, [this, provider](const QVector &data) { //qDebug() << "==DataProviderManager dataChanged:" << provider->name() << QThread::currentThreadId(); - if (m_activatedPlugin != provider->name()) { + if (m_activatedPlugin != provider->id()) { return; } @@ -83,14 +83,33 @@ QStringList DataProviderManager::providers() const return m_providers.keys(); } -void DataProviderManager::activateProvider(const QString &name) +QVector DataProviderManager::providers(PluginGroup::Group group) const { - if (!m_providers.contains(name)) { + QVector infos; + for (const auto &provider : m_providers) { + if (group == provider->group()) { + infos.append({ + provider->index(), + provider->id(), + provider->name(), + provider->icon(), + provider->title(), + provider->group() + }); + } + } + + return infos; +} + +void DataProviderManager::activateProvider(const QString &id) +{ + if (!m_providers.contains(id)) { return; } - m_activatedPlugin = name; - Q_EMIT pluginChanged(); + m_activatedPlugin = id; + Q_EMIT pluginChanged(m_activatedPlugin, m_providers.value(m_activatedPlugin)->group()); } DataProviderManager::~DataProviderManager() diff --git a/src/appdata/data-provider-manager.h b/src/appdata/data-provider-manager.h index 86cb1bf..1892fc0 100644 --- a/src/appdata/data-provider-manager.h +++ b/src/appdata/data-provider-manager.h @@ -27,6 +27,17 @@ namespace UkuiMenu { +class ProviderInfo +{ +public: + int index; + QString id; + QString name; + QString icon; + QString title; + PluginGroup::Group group; +}; + class DataProviderManager : public QObject { Q_OBJECT @@ -35,12 +46,13 @@ public: ~DataProviderManager() override; QStringList providers() const; + QVector providers(PluginGroup::Group group) const; QString activatedProvider() const; - void activateProvider(const QString &name); + void activateProvider(const QString &id); QVector data() const; Q_SIGNALS: - void pluginChanged(); + void pluginChanged(const QString &id, PluginGroup::Group group); void dataChanged(QVector data); private: diff --git a/src/appdata/data-provider-plugin-iface.h b/src/appdata/data-provider-plugin-iface.h index 87727e6..c507e72 100644 --- a/src/appdata/data-provider-plugin-iface.h +++ b/src/appdata/data-provider-plugin-iface.h @@ -34,7 +34,7 @@ class PluginGroup Q_GADGET public: enum Group { - Button, + Button = 0, SortMenuItem }; Q_ENUM(Group) @@ -46,6 +46,7 @@ class DataProviderPluginIFace : public QObject public: explicit DataProviderPluginIFace() : QObject(nullptr) {} virtual int index() = 0; + virtual QString id() = 0; virtual QString name() = 0; virtual QString icon() = 0; virtual QString title() = 0; diff --git a/src/appdata/plugin/all-app-data-provider.cpp b/src/appdata/plugin/all-app-data-provider.cpp index a8935cc..f8d53fc 100644 --- a/src/appdata/plugin/all-app-data-provider.cpp +++ b/src/appdata/plugin/all-app-data-provider.cpp @@ -40,6 +40,11 @@ int AllAppDataProvider::index() return 0; } +QString AllAppDataProvider::id() +{ + return "all"; +} + QString AllAppDataProvider::name() { return tr("All"); @@ -47,7 +52,7 @@ QString AllAppDataProvider::name() QString AllAppDataProvider::icon() { - return "text-plain"; + return "image://appicon/text-plain"; } QString AllAppDataProvider::title() diff --git a/src/appdata/plugin/all-app-data-provider.h b/src/appdata/plugin/all-app-data-provider.h index b2c9498..4aa3b1b 100644 --- a/src/appdata/plugin/all-app-data-provider.h +++ b/src/appdata/plugin/all-app-data-provider.h @@ -31,6 +31,7 @@ class AllAppDataProvider : public DataProviderPluginIFace public: explicit AllAppDataProvider(); int index() override; + QString id() override; QString name() override; QString icon() override; QString title() override;