mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-04 17:33:05 +00:00
refactor: the item key which can identify tray items
https://github.com/linuxdeepin/internal-discussion/issues/1072 https://github.com/linuxdeepin/developer-center/issues/885 Change-Id: Ica41815368bacbcc6a163687d329c2a3bda27b2d
This commit is contained in:
parent
f35828ad49
commit
daed0fc57e
Notes:
gerrit
2019-03-19 15:04:43 +08:00
Verified+1: <jenkins@deepin.com> Code-Review+2: listenerri <listenerri@gmail.com> Submitted-by: listenerri <listenerri@gmail.com> Submitted-at: Tue, 19 Mar 2019 15:04:42 +0800 Reviewed-on: https://cr.deepin.io/42022 Project: dde/dde-dock Branch: refs/heads/master
@ -38,7 +38,7 @@ public:
|
||||
explicit AbstractTrayWidget(QWidget *parent = Q_NULLPTR, Qt::WindowFlags f = Qt::WindowFlags());
|
||||
virtual ~AbstractTrayWidget();
|
||||
|
||||
// virtual QString itemKeyForConfig() = 0;
|
||||
virtual QString itemKeyForConfig() = 0;
|
||||
virtual void setActive(const bool active) = 0;
|
||||
virtual void updateIcon() = 0;
|
||||
virtual void sendClick(uint8_t mouseButton, int x, int y) = 0;
|
||||
|
@ -29,7 +29,8 @@ HoldContainer::HoldContainer(TrayPlugin *trayPlugin, QWidget *parent)
|
||||
|
||||
bool HoldContainer::acceptWrapper(FashionTrayWidgetWrapper *wrapper)
|
||||
{
|
||||
const QString &key = wrapper->itemKey() + HoldKeySuffix;
|
||||
const QString &key = wrapper->absTrayWidget()->itemKeyForConfig() + HoldKeySuffix;
|
||||
|
||||
return trayPlugin()->getValue(wrapper->itemKey(), key, false).toBool();
|
||||
}
|
||||
|
||||
@ -38,7 +39,7 @@ void HoldContainer::addWrapper(FashionTrayWidgetWrapper *wrapper)
|
||||
AbstractContainer::addWrapper(wrapper);
|
||||
|
||||
if (containsWrapper(wrapper)) {
|
||||
const QString &key = wrapper->itemKey() + HoldKeySuffix;
|
||||
const QString &key = wrapper->absTrayWidget()->itemKeyForConfig() + HoldKeySuffix;
|
||||
trayPlugin()->saveValue(wrapper->itemKey(), key, true);
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ void NormalContainer::addWrapper(FashionTrayWidgetWrapper *wrapper)
|
||||
AbstractContainer::addWrapper(wrapper);
|
||||
|
||||
if (containsWrapper(wrapper)) {
|
||||
const QString &key = wrapper->itemKey() + HoldKeySuffix;
|
||||
const QString &key = wrapper->absTrayWidget()->itemKeyForConfig() + HoldKeySuffix;
|
||||
trayPlugin()->saveValue(wrapper->itemKey(), key, false);
|
||||
}
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ public:
|
||||
|
||||
void updateContent();
|
||||
|
||||
void initDBus(const QString &indicatorKey);
|
||||
void initDBus(const QString &indicatorName);
|
||||
|
||||
template<typename Func>
|
||||
void featData(const QString &key,
|
||||
@ -99,7 +99,7 @@ public:
|
||||
}
|
||||
|
||||
IndicatorTrayWidget* indicatorTrayWidget = Q_NULLPTR;
|
||||
QString itemKey;
|
||||
QString indicatorName;
|
||||
QMap<QString, QString> propertyNames;
|
||||
QMap<QString, QString> propertyInterfaceNames;
|
||||
|
||||
@ -111,9 +111,9 @@ void IndicatorTrayPrivate::init()
|
||||
{
|
||||
//Q_Q(IndicatorTray);
|
||||
|
||||
indicatorTrayWidget = new IndicatorTrayWidget(itemKey);
|
||||
indicatorTrayWidget = new IndicatorTrayWidget(indicatorName);
|
||||
|
||||
initDBus(itemKey);
|
||||
initDBus(indicatorName);
|
||||
updateContent();
|
||||
}
|
||||
|
||||
@ -124,11 +124,11 @@ void IndicatorTrayPrivate::updateContent()
|
||||
Q_EMIT indicatorTrayWidget->iconChanged();
|
||||
}
|
||||
|
||||
void IndicatorTrayPrivate::initDBus(const QString &indicatorKey)
|
||||
void IndicatorTrayPrivate::initDBus(const QString &indicatorName)
|
||||
{
|
||||
Q_Q(IndicatorTray);
|
||||
|
||||
QString filepath = QString("/etc/dde-dock/indicator/%1.json").arg(indicatorKey);
|
||||
QString filepath = QString("/etc/dde-dock/indicator/%1.json").arg(indicatorName);
|
||||
QFile confFile(filepath);
|
||||
if (!confFile.open(QIODevice::ReadOnly)) {
|
||||
qCritical() << "read indicator config Error";
|
||||
@ -140,7 +140,7 @@ void IndicatorTrayPrivate::initDBus(const QString &indicatorKey)
|
||||
|
||||
auto delay = config.value("delay").toInt(0);
|
||||
|
||||
qDebug() << "delay load" << delay << indicatorKey << q;
|
||||
qDebug() << "delay load" << delay << indicatorName << q;
|
||||
|
||||
QTimer::singleShot(delay, [ = ]() {
|
||||
auto data = config.value("data").toObject();
|
||||
@ -190,13 +190,13 @@ void IndicatorTrayPrivate::initDBus(const QString &indicatorKey)
|
||||
});
|
||||
}
|
||||
|
||||
IndicatorTray::IndicatorTray(const QString &itemKey, QObject *parent)
|
||||
IndicatorTray::IndicatorTray(const QString &indicatorName, QObject *parent)
|
||||
: QObject(parent)
|
||||
, d_ptr(new IndicatorTrayPrivate(this))
|
||||
{
|
||||
Q_D(IndicatorTray);
|
||||
|
||||
d->itemKey = itemKey;
|
||||
d->indicatorName = indicatorName;
|
||||
d->init();
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,7 @@ class IndicatorTray : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit IndicatorTray(const QString &itemKey, QObject *parent = nullptr);
|
||||
explicit IndicatorTray(const QString &indicatorName, QObject *parent = nullptr);
|
||||
~IndicatorTray();
|
||||
|
||||
IndicatorTrayWidget *widget();
|
||||
|
@ -28,8 +28,9 @@
|
||||
#include <QDBusConnection>
|
||||
#include <QDBusInterface>
|
||||
|
||||
IndicatorTrayWidget::IndicatorTrayWidget(const QString &indicatorKey, QWidget *parent, Qt::WindowFlags f)
|
||||
IndicatorTrayWidget::IndicatorTrayWidget(const QString &indicatorName, QWidget *parent, Qt::WindowFlags f)
|
||||
: AbstractTrayWidget(parent, f)
|
||||
, m_indicatorName(indicatorName)
|
||||
{
|
||||
setAttribute(Qt::WA_TranslucentBackground);
|
||||
|
||||
@ -48,8 +49,8 @@ IndicatorTrayWidget::IndicatorTrayWidget(const QString &indicatorKey, QWidget *p
|
||||
setLayout(layout);
|
||||
|
||||
// register dbus
|
||||
auto path = QString("/com/deepin/dde/Dock/Indicator/") + indicatorKey;
|
||||
auto interface = QString("com.deepin.dde.Dock.Indicator.") + indicatorKey;
|
||||
auto path = QString("/com/deepin/dde/Dock/Indicator/") + m_indicatorName;
|
||||
auto interface = QString("com.deepin.dde.Dock.Indicator.") + m_indicatorName;
|
||||
auto sessionBus = QDBusConnection::sessionBus();
|
||||
sessionBus.registerObject(path,
|
||||
interface,
|
||||
@ -61,6 +62,11 @@ IndicatorTrayWidget::~IndicatorTrayWidget()
|
||||
{
|
||||
}
|
||||
|
||||
QString IndicatorTrayWidget::itemKeyForConfig()
|
||||
{
|
||||
return toIndicatorKey(m_indicatorName);
|
||||
}
|
||||
|
||||
void IndicatorTrayWidget::setActive(const bool)
|
||||
{
|
||||
|
||||
|
@ -30,9 +30,10 @@ class IndicatorTrayWidget: public AbstractTrayWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit IndicatorTrayWidget(const QString &itemKey, QWidget *parent = Q_NULLPTR, Qt::WindowFlags f = Qt::WindowFlags());
|
||||
explicit IndicatorTrayWidget(const QString &indicatorName, QWidget *parent = Q_NULLPTR, Qt::WindowFlags f = Qt::WindowFlags());
|
||||
~IndicatorTrayWidget();
|
||||
|
||||
QString itemKeyForConfig() override;
|
||||
void setActive(const bool active) Q_DECL_OVERRIDE;
|
||||
void updateIcon() Q_DECL_OVERRIDE;
|
||||
const QImage trayImage() Q_DECL_OVERRIDE;
|
||||
@ -53,5 +54,7 @@ Q_SIGNALS:
|
||||
|
||||
private:
|
||||
QLabel *m_label;
|
||||
|
||||
QString m_indicatorName;
|
||||
};
|
||||
|
||||
|
@ -39,13 +39,15 @@ SNITrayWidget::SNITrayWidget(const QString &sniServicePath, QWidget *parent)
|
||||
m_menu(nullptr),
|
||||
m_updateIconTimer(new QTimer(this)),
|
||||
m_updateOverlayIconTimer(new QTimer(this)),
|
||||
m_updateAttentionIconTimer(new QTimer(this))
|
||||
m_updateAttentionIconTimer(new QTimer(this)),
|
||||
m_sniServicePath(sniServicePath)
|
||||
{
|
||||
if (sniServicePath.startsWith("/") || !sniServicePath.contains("/")) {
|
||||
if (m_sniServicePath.startsWith("/") || !m_sniServicePath.contains("/")) {
|
||||
qDebug() << "SNI service path invalid";
|
||||
return;
|
||||
}
|
||||
|
||||
QPair<QString, QString> pair = serviceAndPath(sniServicePath);
|
||||
QPair<QString, QString> pair = serviceAndPath(m_sniServicePath);
|
||||
m_dbusService = pair.first;
|
||||
m_dbusPath = pair.second;
|
||||
|
||||
@ -119,6 +121,28 @@ SNITrayWidget::~SNITrayWidget()
|
||||
{
|
||||
}
|
||||
|
||||
QString SNITrayWidget::itemKeyForConfig()
|
||||
{
|
||||
QString key;
|
||||
|
||||
do {
|
||||
key = m_sniId;
|
||||
if (!key.isEmpty()) {
|
||||
break;
|
||||
}
|
||||
|
||||
key = QDBusInterface(m_dbusService, m_dbusPath, StatusNotifierItem::staticInterfaceName())
|
||||
.property("Id").toString();
|
||||
if (!key.isEmpty()) {
|
||||
break;
|
||||
}
|
||||
|
||||
key = m_sniServicePath;
|
||||
} while (false);
|
||||
|
||||
return QString("sni:%1").arg(key);
|
||||
}
|
||||
|
||||
void SNITrayWidget::setActive(const bool active)
|
||||
{
|
||||
}
|
||||
@ -182,19 +206,7 @@ SNITrayWidget::ItemCategory SNITrayWidget::category()
|
||||
|
||||
QString SNITrayWidget::toSNIKey(const QString &sniServicePath)
|
||||
{
|
||||
QString key;
|
||||
|
||||
do {
|
||||
const QPair<QString, QString> &sap = serviceAndPath(sniServicePath);
|
||||
key = QDBusInterface(sap.first, sap.second, StatusNotifierItem::staticInterfaceName()).property("Id").toString();
|
||||
if (!key.isEmpty()) {
|
||||
break;
|
||||
}
|
||||
|
||||
key = sniServicePath;
|
||||
} while (false);
|
||||
|
||||
return QString("sni:%1").arg(key);
|
||||
return QString("sni:%1").arg(sniServicePath);
|
||||
}
|
||||
|
||||
bool SNITrayWidget::isSNIKey(const QString &itemKey)
|
||||
|
@ -47,6 +47,7 @@ public:
|
||||
SNITrayWidget(const QString &sniServicePath, QWidget *parent = Q_NULLPTR);
|
||||
virtual ~SNITrayWidget();
|
||||
|
||||
QString itemKeyForConfig() override;
|
||||
void setActive(const bool active) Q_DECL_OVERRIDE;
|
||||
void updateIcon() Q_DECL_OVERRIDE;
|
||||
void sendClick(uint8_t mouseButton, int x, int y) Q_DECL_OVERRIDE;
|
||||
@ -99,6 +100,7 @@ private:
|
||||
QTimer *m_updateOverlayIconTimer;
|
||||
QTimer *m_updateAttentionIconTimer;
|
||||
|
||||
QString m_sniServicePath;
|
||||
QString m_dbusService;
|
||||
QString m_dbusPath;
|
||||
|
||||
|
@ -86,6 +86,11 @@ SystemTrayItem::~SystemTrayItem()
|
||||
popupWindowAccept();
|
||||
}
|
||||
|
||||
QString SystemTrayItem::itemKeyForConfig()
|
||||
{
|
||||
return m_itemKey;
|
||||
}
|
||||
|
||||
void SystemTrayItem::setActive(const bool active)
|
||||
{
|
||||
Q_UNUSED(active);
|
||||
|
@ -39,6 +39,7 @@ public:
|
||||
virtual ~SystemTrayItem();
|
||||
|
||||
public:
|
||||
QString itemKeyForConfig() override;
|
||||
void setActive(const bool active) Q_DECL_OVERRIDE;
|
||||
void updateIcon() Q_DECL_OVERRIDE;
|
||||
const QImage trayImage() Q_DECL_OVERRIDE;
|
||||
|
@ -152,7 +152,12 @@ bool TrayPlugin::itemAllowContainer(const QString &itemKey)
|
||||
|
||||
bool TrayPlugin::itemIsInContainer(const QString &itemKey)
|
||||
{
|
||||
const QString &key = "container_" + itemKey;
|
||||
AbstractTrayWidget * const trayWidget = m_trayMap.value(itemKey, nullptr);
|
||||
if (trayWidget == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const QString &key = "container_" + trayWidget->itemKeyForConfig();
|
||||
|
||||
return m_proxyInter->getValue(this, key, false).toBool();
|
||||
}
|
||||
@ -164,9 +169,16 @@ int TrayPlugin::itemSortKey(const QString &itemKey)
|
||||
return m_systemTraysController->systemTrayItemSortKey(itemKey);
|
||||
}
|
||||
|
||||
const QString key = QString("pos_%1_%2").arg(itemKey).arg(displayMode());
|
||||
const int defaultSort = displayMode() == Dock::DisplayMode::Fashion ? 0 : 0;
|
||||
|
||||
return m_proxyInter->getValue(this, key, displayMode() == Dock::DisplayMode::Fashion ? 0 : 0).toInt();
|
||||
AbstractTrayWidget * const trayWidget = m_trayMap.value(itemKey, nullptr);
|
||||
if (trayWidget == nullptr) {
|
||||
return defaultSort;
|
||||
}
|
||||
|
||||
const QString key = QString("pos_%1_%2").arg(trayWidget->itemKeyForConfig()).arg(displayMode());
|
||||
|
||||
return m_proxyInter->getValue(this, key, defaultSort).toInt();
|
||||
}
|
||||
|
||||
void TrayPlugin::setSortKey(const QString &itemKey, const int order)
|
||||
@ -180,13 +192,23 @@ void TrayPlugin::setSortKey(const QString &itemKey, const int order)
|
||||
return m_systemTraysController->setSystemTrayItemSortKey(itemKey, order);
|
||||
}
|
||||
|
||||
const QString key = QString("pos_%1_%2").arg(itemKey).arg(displayMode());
|
||||
AbstractTrayWidget * const trayWidget = m_trayMap.value(itemKey, nullptr);
|
||||
if (trayWidget == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
const QString key = QString("pos_%1_%2").arg(trayWidget->itemKeyForConfig()).arg(displayMode());
|
||||
m_proxyInter->saveValue(this, key, order);
|
||||
}
|
||||
|
||||
void TrayPlugin::setItemIsInContainer(const QString &itemKey, const bool container)
|
||||
{
|
||||
const QString &key = "container_" + itemKey;
|
||||
AbstractTrayWidget * const trayWidget = m_trayMap.value(itemKey, nullptr);
|
||||
if (trayWidget == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
const QString &key = "container_" + trayWidget->itemKeyForConfig();
|
||||
|
||||
m_proxyInter->saveValue(this, key, container);
|
||||
}
|
||||
|
@ -102,6 +102,11 @@ XEmbedTrayWidget::~XEmbedTrayWidget()
|
||||
AppWinidSuffixMap[m_appName].remove(m_windowId);
|
||||
}
|
||||
|
||||
QString XEmbedTrayWidget::itemKeyForConfig()
|
||||
{
|
||||
return QString("window:%1").arg(getAppNameForWindow(m_windowId));
|
||||
}
|
||||
|
||||
const QImage XEmbedTrayWidget::trayImage()
|
||||
{
|
||||
return m_image;
|
||||
@ -365,17 +370,7 @@ QString XEmbedTrayWidget::getWindowProperty(quint32 winId, QString propName)
|
||||
|
||||
QString XEmbedTrayWidget::toXEmbedKey(quint32 winId)
|
||||
{
|
||||
const QString &appName = getAppNameForWindow(winId);
|
||||
int suffix = getTrayWidgetKeySuffix(appName, winId);
|
||||
|
||||
QString key;
|
||||
if (suffix == 1) {
|
||||
key = QString("window:%1").arg(appName);
|
||||
} else {
|
||||
key = QString("window:%1-%2").arg(appName).arg(suffix);
|
||||
}
|
||||
|
||||
return key;
|
||||
return QString("window:%1").arg(winId);
|
||||
}
|
||||
|
||||
bool XEmbedTrayWidget::isXEmbedKey(const QString &itemKey)
|
||||
|
@ -35,6 +35,7 @@ public:
|
||||
explicit XEmbedTrayWidget(quint32 winId, QWidget *parent = 0);
|
||||
~XEmbedTrayWidget();
|
||||
|
||||
QString itemKeyForConfig() override;
|
||||
void updateIcon() Q_DECL_OVERRIDE;
|
||||
void setActive(const bool active) Q_DECL_OVERRIDE;
|
||||
const QImage trayImage() Q_DECL_OVERRIDE;
|
||||
|
Loading…
x
Reference in New Issue
Block a user