Skip to content

Commit 49420ce

Browse files
committed
refactor: remove debug panel and legacy DBus code
1. Removed DataPanel.qml and related test functionality from NotifyHeader.qml 2. Removed legacy DBus notification handling code in notificationcenterpanel.cpp 3. Cleaned up NotifyAccessor by removing debug/test methods (addNotify, fetchDataInfo) 4. Simplified notification removal methods to only use new dataUpdater interface 5. Improved database error logging in DBAccessor 6. Enhanced notification logging in NotificationManager These changes remove unused debug/test code and legacy DBus interfaces that were replaced by the new dataUpdater system. The cleanup improves code maintainability and reduces potential security surface by removing unused code paths. The logging improvements provide better debugging information while removing redundant debug tools. refactor: 移除调试面板和遗留DBus代码 1. 移除DataPanel.qml及NotifyHeader.qml中的相关测试功能 2. 删除notificationcenterpanel.cpp中的遗留DBus通知处理代码 3. 清理NotifyAccessor中的调试/测试方法(addNotify, fetchDataInfo) 4. 简化通知移除方法,仅使用新的dataUpdater接口 5. 在DBAccessor中改进数据库错误日志记录 6. 在NotificationManager中增强通知日志记录 这些变更移除了未使用的调试/测试代码和被新dataUpdater系统取代的遗留DBus接 口。清理工作提高了代码可维护性,并通过移除未使用的代码路径减少了潜在的安 全风险。日志记录的改进在移除冗余调试工具的同时提供了更好的调试信息。
1 parent 3f362d3 commit 49420ce

8 files changed

Lines changed: 12 additions & 175 deletions

File tree

panels/notification/center/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ qt_add_qml_module(notificationcenterpanel
1919
NotifySettingMenu.qml
2020
AnimationSettingButton.qml
2121
BoundingRectangle.qml
22-
DataPanel.qml
2322
NotifyHeaderTitleText.qml
2423
SOURCES
2524
notificationcenterpanel.h

panels/notification/center/DataPanel.qml

Lines changed: 0 additions & 63 deletions
This file was deleted.

panels/notification/center/NotifyHeader.qml

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,6 @@ FocusScope {
1313
id: root
1414

1515
required property NotifyModel notifyModel
16-
signal headerClicked()
17-
18-
// test
19-
onHeaderClicked: function () {
20-
dataPanelLoader.active = !dataPanelLoader.active
21-
NotifyAccessor.fetchDataInfo()
22-
dataPanelLoader.item.show()
23-
}
24-
Loader {
25-
id: dataPanelLoader
26-
active: false
27-
sourceComponent: Window {
28-
id: dataPanel
29-
width: 360
30-
height: 600
31-
x: dataPanel.transientParent.x + root.Window.width + 10
32-
y: dataPanel.transientParent.y
33-
DataPanel {
34-
notifyModel: root.notifyModel
35-
}
36-
}
37-
}
3816

3917
RowLayout {
4018
anchors.fill: parent
@@ -43,12 +21,6 @@ FocusScope {
4321
Layout.alignment: Qt.AlignLeft
4422
Layout.leftMargin: 18
4523
tFont: DTK.fontManager.t4
46-
MouseArea {
47-
anchors.fill: parent
48-
onDoubleClicked: {
49-
root.headerClicked()
50-
}
51-
}
5224
}
5325

5426
Item {

panels/notification/center/notificationcenterpanel.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,10 @@ bool NotificationCenterPanel::init()
8888
Qt::QueuedConnection);
8989
notifycenter::NotifyAccessor::instance()->setDataUpdater(server);
9090
notifycenter::NotifyAccessor::instance()->setEnabled(visible());
91-
} else {
92-
// old interface by dbus
93-
auto connection = QDBusConnection::sessionBus();
94-
valid = connection.connect(DDENotifyDBusServer, DDENotifyDBusPath, DDENotifyDBusInterface,
95-
"RecordAdded", this, SLOT(onReceivedRecord(const QString &)));
9691
}
9792
if (!valid) {
9893
qWarning(notifyLog) << "NotifyConnection is invalid, and can't receive RecordAdded signal.";
94+
return false;
9995
}
10096

10197
return true;

panels/notification/center/notifyaccessor.cpp

Lines changed: 3 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -139,35 +139,21 @@ QStringList NotifyAccessor::fetchApps(int maxCount) const
139139
void NotifyAccessor::removeEntity(qint64 id)
140140
{
141141
qDebug(notifyLog) << "Remove notify" << id;
142-
if (m_dataUpdater) {
143-
QMetaObject::invokeMethod(m_dataUpdater, "removeNotification", Qt::DirectConnection,
144-
Q_ARG(qint64, id));
145-
} else {
146-
m_accessor->removeEntity(id);
147-
}
142+
QMetaObject::invokeMethod(m_dataUpdater, "removeNotification", Qt::DirectConnection, Q_ARG(qint64, id));
148143
}
149144

150145
void NotifyAccessor::removeEntityByApp(const QString &appName)
151146
{
152147
qDebug(notifyLog) << "Remove notifies for the application" << appName;
153148

154-
if (m_dataUpdater) {
155-
QMetaObject::invokeMethod(m_dataUpdater, "removeNotifications", Qt::DirectConnection,
156-
Q_ARG(const QString &, appName));
157-
} else {
158-
m_accessor->removeEntityByApp(appName);
159-
}
149+
QMetaObject::invokeMethod(m_dataUpdater, "removeNotifications", Qt::DirectConnection, Q_ARG(const QString &, appName));
160150
}
161151

162152
void NotifyAccessor::clear()
163153
{
164154
qDebug(notifyLog) << "Remove all notify";
165155

166-
if (m_dataUpdater) {
167-
QMetaObject::invokeMethod(m_dataUpdater, "removeNotifications", Qt::DirectConnection);
168-
} else {
169-
m_accessor->clear();
170-
}
156+
QMetaObject::invokeMethod(m_dataUpdater, "removeNotifications", Qt::DirectConnection);
171157
}
172158

173159
void NotifyAccessor::closeNotify(const NotifyEntity &entity, NotifyEntity::ClosedReason reason)
@@ -240,34 +226,6 @@ void NotifyAccessor::openNotificationSetting()
240226
}
241227
}
242228

243-
void NotifyAccessor::addNotify(const QString &appName, const QString &content)
244-
{
245-
qDebug(notifyLog) << "Add notify" << appName;
246-
static int id = 10000;
247-
NotifyEntity entity(id++, appName);
248-
entity.setBody(content);
249-
m_accessor->addEntity(entity);
250-
251-
if (auto entity = fetchLastEntity(appName); entity.isValid()) {
252-
entityReceived(entity.id());
253-
}
254-
}
255-
256-
void NotifyAccessor::fetchDataInfo()
257-
{
258-
QStringList info;
259-
auto entityCount = fetchEntityCount(DataAccessor::AllApp());
260-
auto apps = fetchApps();
261-
info.append(QString("notifyCount: %1, appCount: %2").arg(entityCount).arg(apps.size()));
262-
for (auto item : apps) {
263-
info.append(QString("%1 -> %2").arg(item).arg(fetchEntityCount(item)));
264-
}
265-
QString ret = info.join("\n");
266-
m_dataInfo = ret;
267-
dataInfoChanged();
268-
appsChanged();
269-
}
270-
271229
void NotifyAccessor::onNotificationStateChanged(qint64 id, int processedType)
272230
{
273231
if (!enabled())
@@ -285,16 +243,6 @@ void NotifyAccessor::onReceivedRecord(const QString &id)
285243
emit entityReceived(id.toLongLong());
286244
}
287245

288-
QString NotifyAccessor::dataInfo() const
289-
{
290-
return m_dataInfo;
291-
}
292-
293-
QStringList NotifyAccessor::apps() const
294-
{
295-
return m_apps;
296-
}
297-
298246
bool NotifyAccessor::debugging() const
299247
{
300248
return m_debugging;

panels/notification/center/notifyaccessor.h

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ class NotifyAccessor : public QObject
2525
Q_OBJECT
2626
QML_ELEMENT
2727
QML_SINGLETON
28-
Q_PROPERTY(QString dataInfo READ dataInfo NOTIFY dataInfoChanged FINAL)
29-
Q_PROPERTY(QStringList apps READ apps NOTIFY appsChanged FINAL)
3028
Q_PROPERTY(bool debugging READ debugging NOTIFY debuggingChanged)
3129
public:
3230
static NotifyAccessor *instance();
@@ -60,13 +58,6 @@ class NotifyAccessor : public QObject
6058
void stagingEntityReceived(qint64 id);
6159
void stagingEntityClosed(qint64 id);
6260

63-
public slots:
64-
void addNotify(const QString &appName, const QString &content);
65-
void fetchDataInfo();
66-
67-
signals:
68-
void dataInfoChanged();
69-
void appsChanged();
7061
void debuggingChanged();
7162

7263
private slots:
@@ -76,17 +67,13 @@ private slots:
7667
private:
7768
explicit NotifyAccessor(QObject *parent = nullptr);
7869

79-
QString dataInfo() const;
80-
QStringList apps() const;
8170
bool debugging() const;
8271

8372
private:
8473
DataAccessor *m_accessor = nullptr;
8574
QObject *m_dataUpdater = nullptr;
8675
QStringList m_pinnedApps;
87-
QStringList m_apps;
8876
bool m_debugging = false;
89-
QString m_dataInfo;
9077
bool m_enabled = false;
9178
};
9279
}

panels/notification/common/dbaccessor.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,11 @@ bool DBAccessor::open(const QString &dataPath)
173173
bool DBAccessor::isValid() const
174174
{
175175
QMutexLocker locker(&m_mutex);
176-
return !m_connection.lastError().isValid();
176+
if (m_connection.lastError().isValid()) {
177+
qWarning(notifyLog) << "Database error" << m_connection.lastError().text();
178+
return false;
179+
}
180+
return true;
177181
}
178182

179183
qint64 DBAccessor::addEntity(const NotifyEntity &entity)

panels/notification/server/notificationmanager.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -180,15 +180,9 @@ uint NotificationManager::Notify(const QString &appName, uint replacesId, const
180180
const QString &body, const QStringList &actions, const QVariantMap &hints,
181181
int expireTimeout)
182182
{
183-
qDebug(notifyLog) << "Notify"
184-
<< ", appName:" << appName
185-
<< ", summary:" << summary
186-
<< ", appIcon:" << appIcon
187-
<< ", body size:" << body.size()
188-
<< ", actions:" << actions
189-
<< ", hint: " << hints
190-
<< ", replaceId:" << replacesId
191-
<< ", expireTimeout:" << expireTimeout;
183+
qInfo(notifyLog) << "Notify"
184+
<< ", appName:" << appName << ", summary:" << summary << ", appIcon:" << appIcon << ", body size:" << body.size()
185+
<< ", actions:" << actions << ", hint: " << hints << ", replaceId:" << replacesId << ", expireTimeout:" << expireTimeout;
192186

193187
if (calledFromDBus() && m_setting->systemValue(NotificationSetting::CloseNotification).toBool()) {
194188
qDebug(notifyLog) << "Notify has been disabled by CloseNotification setting.";

0 commit comments

Comments
 (0)