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;