Skip to content

Commit

Permalink
chore: compatible with old notification center
Browse files Browse the repository at this point in the history
Register old dbus service to response Shortcut keys.
also we can replace the action in dde-daemon,
https://github.com/linuxdeepin/dde-daemon/blob/master/misc/dde-daemon/keybinding/system_actions.json#L88

task: https://pms.uniontech.com/task-view-365219.html
  • Loading branch information
18202781743 authored and deepin-bot[bot] committed Oct 16, 2024
1 parent 6bdccd5 commit 5663879
Show file tree
Hide file tree
Showing 9 changed files with 149 additions and 3 deletions.
2 changes: 2 additions & 0 deletions panels/notification/center/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ qt_add_qml_module(notificationcenterpanel
notificationcenterpanel.cpp
notificationcenterproxy.h
notificationcenterproxy.cpp
notificationcenterdbusadaptor.h
notificationcenterdbusadaptor.cpp
notifyaccessor.h
notifyaccessor.cpp
notifymodel.h
Expand Down
36 changes: 36 additions & 0 deletions panels/notification/center/notificationcenterdbusadaptor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

#include "notificationcenterdbusadaptor.h"
#include "notificationcenterproxy.h"

namespace notification {

NotificationCenterDBusAdaptor::NotificationCenterDBusAdaptor(QObject *parent)
: QDBusAbstractAdaptor(parent)
{
setAutoRelaySignals(true);
}

void NotificationCenterDBusAdaptor::Toggle()
{
return impl()->Toggle();
}

void NotificationCenterDBusAdaptor::Show()
{
return impl()->Show();
}

void NotificationCenterDBusAdaptor::Hide()
{
return impl()->Hide();
}

NotificationCenterProxy *NotificationCenterDBusAdaptor::impl() const
{
return qobject_cast<NotificationCenterProxy *>(parent());
}

} // notification
30 changes: 30 additions & 0 deletions panels/notification/center/notificationcenterdbusadaptor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

#pragma once

#include <QDBusVariant>
#include <QDBusAbstractAdaptor>

namespace notification {

class NotificationCenterProxy;
class NotificationCenterDBusAdaptor : public QDBusAbstractAdaptor
{
Q_OBJECT
Q_CLASSINFO("D-Bus Interface", "org.deepin.dde.Widgets1")

public:
explicit NotificationCenterDBusAdaptor(QObject *parent = nullptr);

public Q_SLOTS: // methods
void Toggle();
void Show();
void Hide();

private:
NotificationCenterProxy *impl() const;
};

} // notification
12 changes: 12 additions & 0 deletions panels/notification/center/notificationcenterpanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "notificationcenterpanel.h"

#include "notificationcenterproxy.h"
#include "notificationcenterdbusadaptor.h"
#include "notifyaccessor.h"
#include "dbaccessor.h"

Expand All @@ -17,6 +18,7 @@
#include <QDBusConnection>
#include <QDBusInterface>
#include <QLoggingCategory>
#include <QDBusConnectionInterface>

DS_USE_NAMESPACE

Expand Down Expand Up @@ -78,6 +80,16 @@ bool NotificationCenterPanel::init()
return false;
}

// TODO compatible with old notification center
QDBusConnection connection = QDBusConnection::sessionBus();
connection.interface()->registerService("org.deepin.dde.Widgets1",
QDBusConnectionInterface::ReplaceExistingService,
QDBusConnectionInterface::AllowReplacement);
if (!connection.registerObject("/org/deepin/dde/Widgets1", m_proxy)) {
return false;
}
new NotificationCenterDBusAdaptor(m_proxy);

DPanel::init();

auto accessor = notification::DBAccessor::instance();
Expand Down
2 changes: 2 additions & 0 deletions panels/notification/osd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
add_library(osdpanel SHARED
osdpanel.cpp
osdpanel.h
osddbusadaptor.h
osddbusadaptor.cpp
test.sh
)

Expand Down
26 changes: 26 additions & 0 deletions panels/notification/osd/osddbusadaptor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

#include "osddbusadaptor.h"
#include "osdpanel.h"

namespace osd {

OsdDBusAdaptor::OsdDBusAdaptor(QObject *parent)
: QDBusAbstractAdaptor(parent)
{
setAutoRelaySignals(true);
}

void OsdDBusAdaptor::ShowOSD(const QString &text)
{
return impl()->ShowOSD(text);
}

OsdPanel *OsdDBusAdaptor::impl() const
{
return qobject_cast<OsdPanel *>(parent());
}

} // osd
28 changes: 28 additions & 0 deletions panels/notification/osd/osddbusadaptor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

#pragma once

#include <QDBusVariant>
#include <QDBusAbstractAdaptor>

namespace osd {

class OsdPanel;
class OsdDBusAdaptor : public QDBusAbstractAdaptor
{
Q_OBJECT
Q_CLASSINFO("D-Bus Interface", "org.deepin.dde.Osd1")

public:
explicit OsdDBusAdaptor(QObject *parent = nullptr);

public Q_SLOTS: // methods
void ShowOSD(const QString &text);

private:
OsdPanel *impl() const;
};

} // osd
12 changes: 11 additions & 1 deletion panels/notification/osd/osdpanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

#include "osdpanel.h"

#include "osddbusadaptor.h"
#include "pluginfactory.h"
#include <QDBusConnectionInterface>

#include <QDBusConnection>
#include <QTimer>
Expand Down Expand Up @@ -34,6 +36,14 @@ bool OsdPanel::init()
return false;
}

bus.interface()->registerService("org.deepin.dde.Osd1",
QDBusConnectionInterface::ReplaceExistingService,
QDBusConnectionInterface::AllowReplacement);
if (!bus.registerObject("/", "org.deepin.dde.Osd1", this, QDBusConnection::ExportAllSlots)) {
return false;
}
new OsdDBusAdaptor(this);

m_osdTimer = new QTimer(this);
m_osdTimer->setInterval(m_interval);
m_osdTimer->setSingleShot(true);
Expand All @@ -53,7 +63,7 @@ bool OsdPanel::visible() const
return m_visible;
}

void OsdPanel::showText(const QString &text)
void OsdPanel::ShowOSD(const QString &text)
{
qCInfo(osdLog()) << "show text" << text;
m_osdTimer->setInterval(text == "SwitchWM3D" ? 2000 : 1000);
Expand Down
4 changes: 2 additions & 2 deletions panels/notification/osd/osdpanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class OsdPanel : public DS_NAMESPACE::DPanel
Q_OBJECT
Q_PROPERTY(bool visible READ visible NOTIFY visibleChanged FINAL)
Q_PROPERTY(QString osdType READ osdType NOTIFY osdTypeChanged FINAL)
Q_CLASSINFO("D-Bus Interface", "org.deepin.osdService")
Q_CLASSINFO("D-Bus Interface", "org.deepin.dde.shell.osd")
public:
explicit OsdPanel(QObject *parent = nullptr);

Expand All @@ -25,7 +25,7 @@ class OsdPanel : public DS_NAMESPACE::DPanel
QString osdType() const;

public Q_SLOTS:
void showText(const QString &text);
void ShowOSD(const QString &text);

Q_SIGNALS:
void visibleChanged();
Expand Down

0 comments on commit 5663879

Please sign in to comment.