fix:修复插件跟随应用增删变化需要重启的问题
This commit is contained in:
parent
81b9e5f92f
commit
58fd71fec7
|
@ -48,7 +48,7 @@ ApplicationsSettings *UkuiNotification::ApplicationsSettings::self()
|
||||||
ApplicationsSettings::ApplicationsSettings(QObject *parent) : QObject(parent), d(new ApplicationsSettingsPrivate)
|
ApplicationsSettings::ApplicationsSettings(QObject *parent) : QObject(parent), d(new ApplicationsSettingsPrivate)
|
||||||
{
|
{
|
||||||
d->m_settingsData = SettingsManager::self()->getAllAppSettings();
|
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);
|
connect(SettingsManager::self(), &SettingsManager::settingsDataChanged, this, &ApplicationsSettings::settingsDataChanged);
|
||||||
qmlRegisterUncreatableType<UkuiNotification::SingleApplicationSettings>("org.ukui.notification.client", 1, 0, "SingleApplicationSettings", "");
|
qmlRegisterUncreatableType<UkuiNotification::SingleApplicationSettings>("org.ukui.notification.client", 1, 0, "SingleApplicationSettings", "");
|
||||||
}
|
}
|
||||||
|
@ -63,14 +63,7 @@ ApplicationsSettings::~ApplicationsSettings()
|
||||||
|
|
||||||
SingleApplicationSettings *ApplicationsSettings::creatSettings(const PopupNotification ¬ification)
|
SingleApplicationSettings *ApplicationsSettings::creatSettings(const PopupNotification ¬ification)
|
||||||
{
|
{
|
||||||
QString desktopEntry = notification.desktopEntry();
|
return creatSettings(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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ApplicationsSettingsMap &ApplicationsSettings::getAllApplicationsSettings()
|
ApplicationsSettingsMap &ApplicationsSettings::getAllApplicationsSettings()
|
||||||
|
@ -127,4 +120,22 @@ void ApplicationsSettings::settingsDataChanged()
|
||||||
Q_EMIT settingsUpdated();
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -43,6 +43,7 @@ public:
|
||||||
* @return 返回的指针不需要使用者回收
|
* @return 返回的指针不需要使用者回收
|
||||||
*/
|
*/
|
||||||
SingleApplicationSettings *creatSettings(const PopupNotification ¬ification);
|
SingleApplicationSettings *creatSettings(const PopupNotification ¬ification);
|
||||||
|
SingleApplicationSettings *creatSettings(QString desktopEntry);
|
||||||
ApplicationsSettingsMap &getAllApplicationsSettings();
|
ApplicationsSettingsMap &getAllApplicationsSettings();
|
||||||
/**
|
/**
|
||||||
* @brief getAppSettings
|
* @brief getAppSettings
|
||||||
|
@ -61,6 +62,7 @@ private Q_SLOTS:
|
||||||
private:
|
private:
|
||||||
ApplicationsSettings(QObject *parent = nullptr);
|
ApplicationsSettings(QObject *parent = nullptr);
|
||||||
void settingsDataChanged();
|
void settingsDataChanged();
|
||||||
|
void onApplicationUninstalled(const QString &desktopEntry);
|
||||||
ApplicationsSettingsPrivate *d = nullptr;
|
ApplicationsSettingsPrivate *d = nullptr;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,7 +55,7 @@ void SettingsManagerPrivate::init()
|
||||||
connect(m_watcher, &QFileSystemWatcher::fileChanged, this, &SettingsManagerPrivate::checkAndLoad);
|
connect(m_watcher, &QFileSystemWatcher::fileChanged, this, &SettingsManagerPrivate::checkAndLoad);
|
||||||
//TODO 应用数据服务接口更新中
|
//TODO 应用数据服务接口更新中
|
||||||
m_applicationInfo = new UkuiSearch::ApplicationInfo(this);
|
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::appDBItems2BAdd, this,&SettingsManagerPrivate::desktopFileAdd);
|
||||||
}
|
}
|
||||||
connect(m_applicationInfo, &UkuiSearch::ApplicationInfo::appDBItems2BDelete, this, &SettingsManagerPrivate::desktopFileDelete);
|
connect(m_applicationInfo, &UkuiSearch::ApplicationInfo::appDBItems2BDelete, this, &SettingsManagerPrivate::desktopFileDelete);
|
||||||
|
|
|
@ -195,6 +195,3 @@ QString SingleApplicationSettings::desktopEntry() const
|
||||||
{
|
{
|
||||||
return d->m_desktopEntry;
|
return d->m_desktopEntry;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -468,12 +468,49 @@ void Notice::initListUI()
|
||||||
{UkuiSearch::ApplicationProperty::DontDisplay, 0}
|
{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){
|
connect(this, &Notice::appDataInfo, this, &Notice::addItemUi, Qt::QueuedConnection);
|
||||||
UkuiNotification::ApplicationsSettingsMap appDataMap = dataMap;
|
|
||||||
UkuiNotification::ApplicationsSettingsMap::const_iterator i = appDataMap.constBegin();
|
QtConcurrent::run([=](){
|
||||||
while(i != appDataMap.constEnd()) {
|
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();
|
const QString& desktopPath = i.key();
|
||||||
|
|
||||||
if (!appInfoMap.contains(desktopPath)) {
|
if (!appInfoMap.contains(desktopPath)) {
|
||||||
|
@ -481,15 +518,11 @@ void Notice::initListUI()
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
initItemUi(desktopPath, appInfoMap[desktopPath], i.value());
|
initItemUi(desktopPath, appInfoMap[desktopPath], i.value());
|
||||||
|
m_appList.append(desktopPath);
|
||||||
}
|
}
|
||||||
++i;
|
++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)
|
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);
|
menu->blockSignals(false);
|
||||||
});
|
});
|
||||||
connect(settings, &UkuiNotification::SingleApplicationSettings::uninstalled, [=]() {
|
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);
|
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)
|
void ToolButton::paintEvent(QPaintEvent *event)
|
||||||
{
|
{
|
||||||
QPalette palette;
|
QPalette palette;
|
||||||
|
|
|
@ -66,21 +66,24 @@ public:
|
||||||
void initConnection();
|
void initConnection();
|
||||||
void initNoticeStatus();
|
void initNoticeStatus();
|
||||||
void initListUI();
|
void initListUI();
|
||||||
|
void addItemUi(const UkuiSearch::ApplicationInfoMap& appInfoMap);
|
||||||
void initItemUi(const QString &desktopPath,
|
void initItemUi(const QString &desktopPath,
|
||||||
const UkuiSearch::ApplicationPropertyMap& properties,
|
const UkuiSearch::ApplicationPropertyMap& properties,
|
||||||
UkuiNotification::SingleApplicationSettings *settings);
|
UkuiNotification::SingleApplicationSettings *settings);
|
||||||
void setAppIcon(QLabel *iconlabel, const QString &icon);
|
void setAppIcon(QLabel *iconlabel, const QString &icon);
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void appDataInfo(UkuiNotification::ApplicationsSettingsMap appDataMap);
|
void appDataInfo(const UkuiSearch::ApplicationInfoMap&);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setHiddenNoticeApp(bool status);
|
void setHiddenNoticeApp(bool status);
|
||||||
void setComBoxStatus(bool status);
|
void setComBoxStatus(bool status);
|
||||||
|
void removeLayoutItem(int i);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString m_pluginName;
|
QString m_pluginName;
|
||||||
int m_pluginType;
|
int m_pluginType;
|
||||||
|
QVector<QString> m_appList;
|
||||||
|
|
||||||
QWidget *m_pluginWidget = nullptr;
|
QWidget *m_pluginWidget = nullptr;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue