From c61c67b387f2a0304e074ba71b0005a2072543f7 Mon Sep 17 00:00:00 2001 From: hewenfei Date: Mon, 13 Feb 2023 20:17:29 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=92=E4=BB=B6=E6=8E=A5=E5=8F=A3=E6=96=B0?= =?UTF-8?q?=E5=A2=9Eid=E5=B1=9E=E6=80=A7=E4=BD=9C=E4=B8=BA=E5=94=AF?= =?UTF-8?q?=E4=B8=80=E6=A0=87=E8=AF=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/appdata/data-provider-manager.cpp | 35 +++++++++++++++----- src/appdata/data-provider-manager.h | 16 +++++++-- src/appdata/data-provider-plugin-iface.h | 3 +- src/appdata/plugin/all-app-data-provider.cpp | 7 +++- src/appdata/plugin/all-app-data-provider.h | 1 + 5 files changed, 50 insertions(+), 12 deletions(-) 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;