From c5a04aaef3ce4c8248fff4a0706e4ff29e786e47 Mon Sep 17 00:00:00 2001 From: gjq Date: Tue, 27 Feb 2024 10:12:56 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9A=E4=BF=AE=E5=A4=8D=E6=8F=92?= =?UTF-8?q?=E4=BB=B6=E8=B7=9F=E9=9A=8F=E5=BA=94=E7=94=A8=E5=A2=9E=E5=88=A0?= =?UTF-8?q?=E5=8F=98=E5=8C=96=E9=9C=80=E8=A6=81=E9=87=8D=E5=90=AF=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../applications-settings.cpp | 29 ++++--- .../applications-settings.h | 2 + .../settings-manager.cpp | 2 +- .../single-application-settings.cpp | 3 - .../notification-ukcc-plugin.cpp | 79 ++++++++++++++++--- .../notification-ukcc-plugin.h | 5 +- 6 files changed, 94 insertions(+), 26 deletions(-) diff --git a/libukui-notification/notification-settings/applications-settings.cpp b/libukui-notification/notification-settings/applications-settings.cpp index f807c28..2713ad5 100644 --- a/libukui-notification/notification-settings/applications-settings.cpp +++ b/libukui-notification/notification-settings/applications-settings.cpp @@ -48,7 +48,7 @@ ApplicationsSettings *UkuiNotification::ApplicationsSettings::self() ApplicationsSettings::ApplicationsSettings(QObject *parent) : QObject(parent), d(new ApplicationsSettingsPrivate) { d->m_settingsData = SettingsManager::self()->getAllAppSettings(); - connect(SettingsManager::self(), &SettingsManager::appUninstalled, this, &ApplicationsSettings::applicationUninstalled); + connect(SettingsManager::self(), &SettingsManager::appUninstalled, this, &ApplicationsSettings::onApplicationUninstalled); connect(SettingsManager::self(), &SettingsManager::settingsDataChanged, this, &ApplicationsSettings::settingsDataChanged); qmlRegisterUncreatableType("org.ukui.notification.client", 1, 0, "SingleApplicationSettings", ""); } @@ -63,14 +63,7 @@ ApplicationsSettings::~ApplicationsSettings() SingleApplicationSettings *ApplicationsSettings::creatSettings(const PopupNotification ¬ification) { - QString desktopEntry = notification.desktopEntry(); - if(desktopEntry.isEmpty()) { - desktopEntry = QStringLiteral("default"); - } - if(d->m_cache.contains(desktopEntry)) { - return d->m_cache[desktopEntry]; - } - return d->m_cache.insert(desktopEntry, new SingleApplicationSettings(desktopEntry)).value(); + return creatSettings(notification.desktopEntry()); } ApplicationsSettingsMap &ApplicationsSettings::getAllApplicationsSettings() @@ -127,4 +120,22 @@ void ApplicationsSettings::settingsDataChanged() Q_EMIT settingsUpdated(); } +void ApplicationsSettings::onApplicationUninstalled(const QString &desktopEntry) +{ + if (d->m_settingsData.contains(desktopEntry)) { + d->m_settingsData.remove(desktopEntry); + } + Q_EMIT applicationUninstalled(desktopEntry); +} +SingleApplicationSettings *ApplicationsSettings::creatSettings(QString desktopEntry) +{ + if(desktopEntry.isEmpty()) { + desktopEntry = QStringLiteral("default"); + } + if(d->m_cache.contains(desktopEntry)) { + return d->m_cache[desktopEntry]; + } else { + return d->m_cache.insert(desktopEntry, new SingleApplicationSettings(desktopEntry)).value(); + } +} diff --git a/libukui-notification/notification-settings/applications-settings.h b/libukui-notification/notification-settings/applications-settings.h index 647b967..e7673cd 100644 --- a/libukui-notification/notification-settings/applications-settings.h +++ b/libukui-notification/notification-settings/applications-settings.h @@ -43,6 +43,7 @@ public: * @return 返回的指针不需要使用者回收 */ SingleApplicationSettings *creatSettings(const PopupNotification ¬ification); + SingleApplicationSettings *creatSettings(QString desktopEntry); ApplicationsSettingsMap &getAllApplicationsSettings(); /** * @brief getAppSettings @@ -61,6 +62,7 @@ private Q_SLOTS: private: ApplicationsSettings(QObject *parent = nullptr); void settingsDataChanged(); + void onApplicationUninstalled(const QString &desktopEntry); ApplicationsSettingsPrivate *d = nullptr; }; } diff --git a/libukui-notification/notification-settings/settings-manager.cpp b/libukui-notification/notification-settings/settings-manager.cpp index 246cdd8..c644e86 100644 --- a/libukui-notification/notification-settings/settings-manager.cpp +++ b/libukui-notification/notification-settings/settings-manager.cpp @@ -55,7 +55,7 @@ void SettingsManagerPrivate::init() connect(m_watcher, &QFileSystemWatcher::fileChanged, this, &SettingsManagerPrivate::checkAndLoad); //TODO 应用数据服务接口更新中 m_applicationInfo = new UkuiSearch::ApplicationInfo(this); - if (qApp->property("IS_UKUI_NOTIFICATION_SERVICE").toBool()) { + if (qApp->property("IS_UKUI_NOTIFICATION_SERVER").toBool()) { connect(m_applicationInfo, &UkuiSearch::ApplicationInfo::appDBItems2BAdd, this,&SettingsManagerPrivate::desktopFileAdd); } connect(m_applicationInfo, &UkuiSearch::ApplicationInfo::appDBItems2BDelete, this, &SettingsManagerPrivate::desktopFileDelete); diff --git a/libukui-notification/notification-settings/single-application-settings.cpp b/libukui-notification/notification-settings/single-application-settings.cpp index d80978c..455e115 100644 --- a/libukui-notification/notification-settings/single-application-settings.cpp +++ b/libukui-notification/notification-settings/single-application-settings.cpp @@ -195,6 +195,3 @@ QString SingleApplicationSettings::desktopEntry() const { return d->m_desktopEntry; } - - - diff --git a/notification-ukcc-plugin/notification-ukcc-plugin.cpp b/notification-ukcc-plugin/notification-ukcc-plugin.cpp index b924233..804aa0e 100644 --- a/notification-ukcc-plugin/notification-ukcc-plugin.cpp +++ b/notification-ukcc-plugin/notification-ukcc-plugin.cpp @@ -468,12 +468,49 @@ void Notice::initListUI() {UkuiSearch::ApplicationProperty::DontDisplay, 0} }; - const UkuiSearch::ApplicationInfoMap& appInfoMap = m_appInfo->getInfo(properties, restrictions); + UkuiNotification::ApplicationsSettingsMap dataMap = UkuiNotification::ApplicationsSettings::self()->getAllApplicationsSettings(); - connect(this, &Notice::appDataInfo, this, [=](UkuiNotification::ApplicationsSettingsMap dataMap){ - UkuiNotification::ApplicationsSettingsMap appDataMap = dataMap; - UkuiNotification::ApplicationsSettingsMap::const_iterator i = appDataMap.constBegin(); - while(i != appDataMap.constEnd()) { + connect(this, &Notice::appDataInfo, this, &Notice::addItemUi, Qt::QueuedConnection); + + QtConcurrent::run([=](){ + const UkuiSearch::ApplicationInfoMap& appInfoMap = m_appInfo->getInfo(properties, restrictions); + Q_EMIT appDataInfo(appInfoMap); + }); + + connect(UkuiNotification::ApplicationsSettings::self(), &UkuiNotification::ApplicationsSettings::applicationInstalled, + this, [=](const QString &desktopEntry){ + + const UkuiSearch::ApplicationProperties& properties = { + UkuiSearch::ApplicationProperty::LocalName, + UkuiSearch::ApplicationProperty::Icon, + UkuiSearch::ApplicationProperty::DontDisplay + }; + + QtConcurrent::run([=](){ + UkuiSearch::ApplicationPropertyMap dataMap = m_appInfo->getInfo(desktopEntry, properties); + UkuiSearch::ApplicationInfoMap appInfoMap = {{desktopEntry, dataMap}}; + Q_EMIT appDataInfo(appInfoMap); + }); + }); +} + +void Notice::addItemUi(const UkuiSearch::ApplicationInfoMap &appInfoMap) +{ + if (appInfoMap.count() == 1) { + QString desktopEntry = appInfoMap.keys().at(0); + UkuiSearch::ApplicationPropertyMap dataMap = appInfoMap.value(desktopEntry); + if (dataMap[UkuiSearch::ApplicationProperty::DontDisplay].toInt() == 0) { + if (!m_appList.contains(desktopEntry)) { + initItemUi(desktopEntry, dataMap, + UkuiNotification::ApplicationsSettings::self()->creatSettings(desktopEntry)); + m_appList.append(desktopEntry); + } + } + } else { + UkuiNotification::ApplicationsSettingsMap dataMap = UkuiNotification::ApplicationsSettings::self()->getAllApplicationsSettings(); + UkuiNotification::ApplicationsSettingsMap::const_iterator i = dataMap.constBegin(); + m_appList.clear(); + while(i != dataMap.constEnd()) { const QString& desktopPath = i.key(); if (!appInfoMap.contains(desktopPath)) { @@ -481,15 +518,11 @@ void Notice::initListUI() continue; } else { initItemUi(desktopPath, appInfoMap[desktopPath], i.value()); + m_appList.append(desktopPath); } ++i; } - }, Qt::QueuedConnection); - - QtConcurrent::run([=](){ - UkuiNotification::ApplicationsSettingsMap dataMap = UkuiNotification::ApplicationsSettings::self()->getAllApplicationsSettings(); - Q_EMIT appDataInfo(dataMap); - }); + } } void Notice::initItemUi(const QString &desktopPath, const UkuiSearch::ApplicationPropertyMap& properties, UkuiNotification::SingleApplicationSettings *settings) @@ -589,7 +622,18 @@ void Notice::initItemUi(const QString &desktopPath, const UkuiSearch::Applicatio menu->blockSignals(false); }); connect(settings, &UkuiNotification::SingleApplicationSettings::uninstalled, [=]() { - baseWidget->hide(); + for (int i = 0; i < m_appList.length(); i++) { + if (desktopPath == m_appList.at(i)) { + m_appList.removeAt(i); + if (i == 0) { + removeLayoutItem(i); + removeLayoutItem(i); + } else { + removeLayoutItem(i * 2 - 1); + removeLayoutItem(i * 2 - 1); + } + } + } }); @@ -654,6 +698,17 @@ void Notice::setComBoxStatus(bool status) m_closeTimeMComboBox->setEnabled(status); } +void Notice::removeLayoutItem(int i) +{ + if ((i >= 0)&&(m_appListVerticalLayout->count() > i)) { + QWidget* widget = m_appListVerticalLayout->itemAt(i)->widget(); + if (widget) { + m_appListVerticalLayout->removeWidget(widget); + widget->deleteLater(); + } + } +} + void ToolButton::paintEvent(QPaintEvent *event) { QPalette palette; diff --git a/notification-ukcc-plugin/notification-ukcc-plugin.h b/notification-ukcc-plugin/notification-ukcc-plugin.h index b6df48e..f251458 100644 --- a/notification-ukcc-plugin/notification-ukcc-plugin.h +++ b/notification-ukcc-plugin/notification-ukcc-plugin.h @@ -66,21 +66,24 @@ public: void initConnection(); void initNoticeStatus(); void initListUI(); + void addItemUi(const UkuiSearch::ApplicationInfoMap& appInfoMap); void initItemUi(const QString &desktopPath, const UkuiSearch::ApplicationPropertyMap& properties, UkuiNotification::SingleApplicationSettings *settings); void setAppIcon(QLabel *iconlabel, const QString &icon); Q_SIGNALS: - void appDataInfo(UkuiNotification::ApplicationsSettingsMap appDataMap); + void appDataInfo(const UkuiSearch::ApplicationInfoMap&); private: void setHiddenNoticeApp(bool status); void setComBoxStatus(bool status); + void removeLayoutItem(int i); private: QString m_pluginName; int m_pluginType; + QVector m_appList; QWidget *m_pluginWidget = nullptr;