Skip to content

Commit

Permalink
chore: notify settings and icon tweak
Browse files Browse the repository at this point in the history
- get appid from AM first(pid ==> appid)
- get appid from cached item info(.names)
- if icon is empty get icon from settings

linux.qq.com desktop 文件名是 qq.desktop 即 appID 是 qq , 但是通知时 AppName 是QQ

Issue: linuxdeepin/developer-center#8281
  • Loading branch information
kegechen committed May 23, 2024
1 parent ce243ee commit d02d62f
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 25 deletions.
56 changes: 38 additions & 18 deletions dde-osd/src/notification/bubblemanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "signalbridge.h"

#include <DDesktopServices>
#include <DSGApplication>

#include <QStringList>
#include <QVariantMap>
Expand Down Expand Up @@ -145,6 +146,17 @@ uint BubbleManager::Notify(const QString &appName, uint replacesId,
const QString &body, const QStringList &actions,
const QVariantMap hints, int expireTimeout)
{
DCORE_USE_NAMESPACE

QString servicePid, appId;
if (calledFromDBus()) {
QDBusReply<uint> reply = connection().interface()->servicePid(message().service());
servicePid = QString::number(reply.value());
appId = DSGApplication::getId(reply.value());
}
if (appId.isEmpty())
appId = appName;

if (calledFromDBus()) {
QGSettings oem_setting("com.deepin.dde.notifications", "/com/deepin/dde/notifications/");
if (oem_setting.keys().contains("notifycationClosed") && oem_setting.get("notifycationClosed").toBool())
Expand All @@ -156,17 +168,22 @@ uint BubbleManager::Notify(const QString &appName, uint replacesId,
<< "appIcon:" + appIcon << "summary:" + summary << "body:" + body
<< "actions:" << actions << "hints:" << hints << "expireTimeout:" << expireTimeout;

// 记录通知发送方
QString cmd = QString("grep \"Name:\" /proc/%1/status").arg(QString::number(connection().interface()->servicePid(message().service())));
QProcess process;
QStringList args;
args << "-c";
args << cmd;
process.start("sh", args);
process.waitForReadyRead();
QString result = QString::fromUtf8(process.readAllStandardOutput());
qDebug() << "notify called by :" << result;
process.close();
qDebug() << "servicePid" << servicePid << "appid" << appId;

if (!servicePid.isEmpty()) {
// 记录通知发送方
QString cmd = QString("grep \"Name:\" /proc/%1/status").arg(servicePid);
QProcess process;
QStringList args;
args << "-c";
args << cmd;
process.start("sh", args);
process.waitForReadyRead();
qDebug() << "cmd :" << cmd;
QString result = QString::fromUtf8(process.readAllStandardOutput());
qDebug() << "notify called by :" << result;
process.close();
}
}
}

Expand All @@ -179,16 +196,19 @@ uint BubbleManager::Notify(const QString &appName, uint replacesId,
}

// 应用通知功能未开启不做处理
bool enableNotificaion = m_notifySettings->getAppSetting(appName, NotifySettings::ENABELNOTIFICATION).toBool();
bool enableNotificaion = m_notifySettings->getAppSetting(appId, NotifySettings::ENABELNOTIFICATION).toBool();

if (!enableNotificaion && !IgnoreList.contains(appName)) {
if (!enableNotificaion && !IgnoreList.contains(appId)) {
return 0;
}

QString strBody = body;
strBody.replace(QLatin1String("\\\\"), QLatin1String("\\"), Qt::CaseInsensitive);
QString icon = appIcon;
if (icon.isEmpty())
icon = m_notifySettings->getAppSetting(appId, NotifySettings::APPICON).toString();

EntityPtr notification = std::make_shared<NotificationEntity>(appName, QString(), appIcon,
EntityPtr notification = std::make_shared<NotificationEntity>(appName, QString(), icon,
summary, strBody, actions, hints,
QString::number(QDateTime::currentMSecsSinceEpoch()),
QString::number(replacesId),
Expand All @@ -203,10 +223,10 @@ uint BubbleManager::Notify(const QString &appName, uint replacesId,
bool lockscree = m_userInter->locked();

if (!systemNotification) {
enablePreview = m_notifySettings->getAppSetting(appName, NotifySettings::ENABELPREVIEW).toBool();
showInNotifyCenter = m_notifySettings->getAppSetting(appName, NotifySettings::SHOWINNOTIFICATIONCENTER).toBool();
playsound = m_notifySettings->getAppSetting(appName, NotifySettings::ENABELSOUND).toBool();
lockscreeshow = m_notifySettings->getAppSetting(appName, NotifySettings::LOCKSCREENSHOWNOTIFICATION).toBool();
enablePreview = m_notifySettings->getAppSetting(appId, NotifySettings::ENABELPREVIEW).toBool();
showInNotifyCenter = m_notifySettings->getAppSetting(appId, NotifySettings::SHOWINNOTIFICATIONCENTER).toBool();
playsound = m_notifySettings->getAppSetting(appId, NotifySettings::ENABELSOUND).toBool();
lockscreeshow = m_notifySettings->getAppSetting(appId, NotifySettings::LOCKSCREENSHOWNOTIFICATION).toBool();
}

notification->setShowPreview(enablePreview);
Expand Down
35 changes: 30 additions & 5 deletions dde-osd/src/notification/notifysettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include "notifysettings.h"
#include "constants.h"
#include "types/objectmanager_type.h"
#include "types/launcheriteminfo.h"
#include <DUtil>

#include <QGSettings>
Expand Down Expand Up @@ -80,6 +79,7 @@ static LauncherItemInfo fromObjectInterfaceMapToItemInfo(const QDBusObjectPath &
}
}
info.name = showName;
info.names = nameMap.values();
}
return info;

Expand Down Expand Up @@ -122,10 +122,16 @@ NotifySettings::NotifySettings(QObject *parent)
appAdded(info);
});
connect(m_applicationObjectInter, &ApplicationObjectManager1::InterfacesRemoved, this, [this](const QDBusObjectPath &object_path, const QStringList) {
QString id_origin = object_path.path().split("/").last();
QString path = object_path.path();
QString id_origin = path.split("/").last();
QString id = DUtil::unescapeFromObjectPath(id_origin);
qCInfo(SessionNotifySettings) << "Interface removed, removed id=" << id;
appRemoved(id);

LauncherItemInfo info;
info.path = path;
if (m_launcherItemInfoList.contains(info))
m_launcherItemInfoList.removeOne(info);
});
}

Expand All @@ -135,12 +141,12 @@ void NotifySettings::initAllSettings()
if (app_map.isEmpty()) {
m_initTimer->stop();
}
LauncherItemInfoList itemInfoList = fromObjectMaptoLauncherItemInfoList(app_map);
m_launcherItemInfoList = fromObjectMaptoLauncherItemInfoList(app_map);

QStringList appList = m_systemSetting->get("app-list").toStringList();
QStringList launcherList;

for(const LauncherItemInfo &item: itemInfoList) {
for(const LauncherItemInfo &item : m_launcherItemInfoList) {
if (IgnoreList.contains(item.id)) {
continue;
}
Expand Down Expand Up @@ -211,7 +217,22 @@ void NotifySettings::setAppSetting(const QString &id, const NotifySettings::AppC

QVariant NotifySettings::getAppSetting(const QString &id, const NotifySettings::AppConfigurationItem &item)
{
const QString newid = id.isEmpty() ? "empty-app" : id;
QString newid = id.isEmpty() ? "empty-app" : id;

auto it = std::find_if(m_launcherItemInfoList.begin(),
m_launcherItemInfoList.end(),
[newid](const LauncherItemInfo &info) {
return newid == info.id;
});
if (it == m_launcherItemInfoList.end()) {
for (auto info : m_launcherItemInfoList) {
if (info.names.contains(newid) && info.id != newid) {
qDebug() << newid << "not found,fallback to" << info.id;
newid = info.id;
}
}
}

QGSettings itemSetting(appSchemaKey.toLocal8Bit(), appSchemaPath.arg(newid).toLocal8Bit(), this);

QVariant results;
Expand Down Expand Up @@ -243,6 +264,7 @@ QVariant NotifySettings::getAppSetting(const QString &id, const NotifySettings::
break;
}
}

return results;
}

Expand Down Expand Up @@ -323,6 +345,9 @@ void NotifySettings::appAdded(const LauncherItemInfo &info)
itemSetting.set("show-in-notification-center", DEFAULT_ONLY_IN_NOTIFY);
itemSetting.set("lockscreen-show-notification", DEFAULT_LOCK_SHOW_NOTIFY);
}
if (!m_launcherItemInfoList.contains(info)) {
m_launcherItemInfoList << info;
}

Q_EMIT appAddedSignal(info.id);
}
Expand Down
1 change: 1 addition & 0 deletions dde-osd/src/notification/notifysettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ class NotifySettings : public AbstractNotifySetting
QTimer *m_initTimer;
QGSettings *m_systemSetting;
ApplicationObjectManager1 *m_applicationObjectInter;
LauncherItemInfoList m_launcherItemInfoList;
};

#endif // NOTIFYSETTINGS_H
7 changes: 6 additions & 1 deletion global_util/dbus/types/launcheriteminfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,10 @@

bool LauncherItemInfo::operator!=(const LauncherItemInfo &itemInfo)
{
return itemInfo.path != path;
return !operator==(itemInfo);
}

bool LauncherItemInfo::operator==(const LauncherItemInfo &itemInfo)
{
return itemInfo.path == path;
}
4 changes: 3 additions & 1 deletion global_util/dbus/types/launcheriteminfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@ struct LauncherItemInfo {
qint64 categoryId;
qint64 timeInstalled;
QStringList keywords;
QStringList names;
bool noDisplay;
bool operator!=(const LauncherItemInfo &versionInfo);
bool operator==(const LauncherItemInfo &versionInfo);

friend QDebug operator<<(QDebug argument, const LauncherItemInfo &info)
{
argument << info.path << info.name << info.id;
argument << info.path << info.names << info.id;
argument << info.icon << info.categoryId << info.timeInstalled << info.keywords << info.noDisplay;

return argument;
Expand Down

0 comments on commit d02d62f

Please sign in to comment.