mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-04 17:33:05 +00:00
feat: support SNI tray status property
https://github.com/linuxdeepin/internal-discussion/issues/746 Change-Id: Ie036abe71858a74d500487cd434c69cc1ac26e45
This commit is contained in:
parent
a5cf01551a
commit
6c7498a7a7
Notes:
gerrit
2019-01-04 10:28:06 +08:00
Verified+1: <jenkins@deepin.com> Verified+1: liuwen123 <liuwen@linuxdeepin.com> Code-Review+2: listenerri <listenerri@gmail.com> Submitted-by: listenerri <listenerri@gmail.com> Submitted-at: Fri, 04 Jan 2019 10:28:05 +0800 Reviewed-on: https://cr.deepin.io/41087 Project: dde/dde-dock Branch: refs/heads/master
@ -30,7 +30,7 @@
|
||||
#define IconSize 16
|
||||
|
||||
const QStringList ItemCategoryList {"ApplicationStatus" , "Communications" , "SystemServices", "Hardware"};
|
||||
const QStringList ItemStatusList {"ApplicationStatus" , "Communications" , "SystemServices", "Hardware"};
|
||||
const QStringList ItemStatusList {"Passive" , "Active" , "NeedsAttention"};
|
||||
const QStringList LeftClickInvalidIdList {"sogou-qimpanel",};
|
||||
|
||||
SNITrayWidget::SNITrayWidget(const QString &sniServicePath, QWidget *parent)
|
||||
@ -61,6 +61,7 @@ SNITrayWidget::SNITrayWidget(const QString &sniServicePath, QWidget *parent)
|
||||
connect(m_sniInter, &StatusNotifierItem::NewIcon, m_updateTimer, static_cast<void (QTimer::*) ()>(&QTimer::start));
|
||||
connect(m_sniInter, &StatusNotifierItem::NewOverlayIcon, this, &SNITrayWidget::refreshOverlayIcon);
|
||||
connect(m_sniInter, &StatusNotifierItem::NewAttentionIcon, this, &SNITrayWidget::refreshAttentionIcon);
|
||||
connect(m_sniInter, &StatusNotifierItem::NewStatus, this, &SNITrayWidget::onStatusChanged);
|
||||
|
||||
QTimer::singleShot(0, this, &SNITrayWidget::refreshIcon);
|
||||
}
|
||||
@ -111,6 +112,26 @@ bool SNITrayWidget::isValid()
|
||||
return m_sniInter->isValid();
|
||||
}
|
||||
|
||||
SNITrayWidget::ItemStatus SNITrayWidget::status()
|
||||
{
|
||||
const QString &status = m_sniInter->status();
|
||||
if (!ItemStatusList.contains(status)) {
|
||||
return ItemStatus::Active;
|
||||
}
|
||||
|
||||
return static_cast<ItemStatus>(ItemStatusList.indexOf(status));
|
||||
}
|
||||
|
||||
SNITrayWidget::ItemCategory SNITrayWidget::category()
|
||||
{
|
||||
const QString &category = m_sniInter->category();
|
||||
if (!ItemCategoryList.contains(category)) {
|
||||
return UnknownCategory;
|
||||
}
|
||||
|
||||
return static_cast<ItemCategory>(ItemCategoryList.indexOf(category));
|
||||
}
|
||||
|
||||
QString SNITrayWidget::toSNIKey(const QString &sniServicePath)
|
||||
{
|
||||
QString key;
|
||||
@ -164,29 +185,6 @@ void SNITrayWidget::initMenu()
|
||||
qDebug() << "the sni menu obect is:" << m_menu;
|
||||
}
|
||||
|
||||
/*
|
||||
*ItemCategory SNITrayWidget::category()
|
||||
*{
|
||||
* const QString &category = m_sniInter->category();
|
||||
* if (!ItemCategoryList.contains(category)) {
|
||||
* return UnknownCategory;
|
||||
* }
|
||||
*
|
||||
* return static_cast<ItemCategory>(ItemCategoryList.indexOf(category));
|
||||
*}
|
||||
*
|
||||
*ItemStatus SNITrayWidget::status()
|
||||
*{
|
||||
* const QString &status = m_sniInter->status();
|
||||
* if (!ItemStatusList.contains(status)) {
|
||||
* return UnknownStatus;
|
||||
* }
|
||||
*
|
||||
* return static_cast<ItemStatus>(ItemStatusList.indexOf(status));
|
||||
*}
|
||||
*
|
||||
*/
|
||||
|
||||
void SNITrayWidget::refreshIcon()
|
||||
{
|
||||
QPixmap pix = newIconPixmap(Icon);
|
||||
@ -250,6 +248,15 @@ void SNITrayWidget::showContextMenu(int x, int y)
|
||||
}
|
||||
}
|
||||
|
||||
void SNITrayWidget::onStatusChanged(const QString &status)
|
||||
{
|
||||
if (!ItemStatusList.contains(status)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Q_EMIT statusChanged(static_cast<SNITrayWidget::ItemStatus>(ItemStatusList.indexOf(status)));
|
||||
}
|
||||
|
||||
QSize SNITrayWidget::sizeHint() const
|
||||
{
|
||||
return QSize(26, 26);
|
||||
|
@ -32,13 +32,15 @@
|
||||
|
||||
using namespace com::deepin::dde;
|
||||
|
||||
enum ItemCategory {UnknownCategory = -1, ApplicationStatus, Communications, SystemServices, Hardware};
|
||||
enum ItemStatus {UnknownStatus = -1, Passive, Active, NeedsAttention};
|
||||
enum IconType {UnknownIconType = -1, Icon, OverlayIcon, AttentionIcon, AttentionMovieIcon};
|
||||
|
||||
class SNITrayWidget : public AbstractTrayWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
enum ItemCategory {UnknownCategory = -1, ApplicationStatus, Communications, SystemServices, Hardware};
|
||||
enum ItemStatus {Passive, Active, NeedsAttention};
|
||||
enum IconType {UnknownIconType = -1, Icon, OverlayIcon, AttentionIcon, AttentionMovieIcon};
|
||||
|
||||
public:
|
||||
SNITrayWidget(const QString &sniServicePath, QWidget *parent = Q_NULLPTR);
|
||||
virtual ~SNITrayWidget();
|
||||
@ -49,17 +51,23 @@ public:
|
||||
const QImage trayImage() Q_DECL_OVERRIDE;
|
||||
|
||||
bool isValid();
|
||||
SNITrayWidget::ItemStatus status();
|
||||
SNITrayWidget::ItemCategory category();
|
||||
|
||||
static QString toSNIKey(const QString &sniServicePath);
|
||||
static bool isSNIKey(const QString &itemKey);
|
||||
static QPair<QString, QString> serviceAndPath(const QString &servicePath);
|
||||
|
||||
Q_SIGNALS:
|
||||
void statusChanged(SNITrayWidget::ItemStatus status);
|
||||
|
||||
private Q_SLOTS:
|
||||
void initMenu();
|
||||
void refreshIcon();
|
||||
void refreshOverlayIcon();
|
||||
void refreshAttentionIcon();
|
||||
void showContextMenu(int x, int y);
|
||||
void onStatusChanged(const QString &status);
|
||||
|
||||
private:
|
||||
QSize sizeHint() const Q_DECL_OVERRIDE;
|
||||
|
@ -22,7 +22,6 @@
|
||||
|
||||
#include "trayplugin.h"
|
||||
#include "fashiontrayitem.h"
|
||||
#include "snitraywidget.h"
|
||||
|
||||
#include <QDir>
|
||||
#include <QWindow>
|
||||
@ -98,7 +97,7 @@ void TrayPlugin::init(PluginProxyInterface *proxyInter)
|
||||
connect(m_trayInter, &DBusTrayManager::Changed, this, &TrayPlugin::trayChanged);
|
||||
|
||||
connect(m_systemTraysController, &SystemTraysController::systemTrayAdded, this, &TrayPlugin::addTrayWidget);
|
||||
connect(m_systemTraysController, &SystemTraysController::systemTrayRemoved, this, &TrayPlugin::trayRemoved);
|
||||
connect(m_systemTraysController, &SystemTraysController::systemTrayRemoved, this, [=](const QString &itemKey) {trayRemoved(itemKey);});
|
||||
|
||||
m_trayInter->Manage();
|
||||
|
||||
@ -342,9 +341,14 @@ void TrayPlugin::traySNIAdded(const QString &itemKey, const QString &sniServiceP
|
||||
return;
|
||||
}
|
||||
|
||||
AbstractTrayWidget *trayWidget = new SNITrayWidget(sniServicePath);
|
||||
connect(trayWidget, &AbstractTrayWidget::iconChanged, this, &TrayPlugin::sniItemIconChanged);
|
||||
addTrayWidget(itemKey, trayWidget);
|
||||
SNITrayWidget *trayWidget = new SNITrayWidget(sniServicePath);
|
||||
if (trayWidget->status() == SNITrayWidget::ItemStatus::Passive) {
|
||||
m_trayMap.insert(itemKey, trayWidget);
|
||||
} else {
|
||||
addTrayWidget(itemKey, trayWidget);
|
||||
}
|
||||
|
||||
connect(trayWidget, &SNITrayWidget::statusChanged, this, &TrayPlugin::onSNIItemStatusChanged);
|
||||
}
|
||||
|
||||
void TrayPlugin::trayIndicatorAdded(const QString &itemKey)
|
||||
@ -375,13 +379,13 @@ void TrayPlugin::trayIndicatorAdded(const QString &itemKey)
|
||||
});
|
||||
}
|
||||
|
||||
void TrayPlugin::trayRemoved(const QString &itemKey)
|
||||
void TrayPlugin::trayRemoved(const QString &itemKey, const bool deleteObject)
|
||||
{
|
||||
if (!m_trayMap.contains(itemKey)) {
|
||||
return;
|
||||
}
|
||||
|
||||
AbstractTrayWidget *widget = m_trayMap.take(itemKey);
|
||||
AbstractTrayWidget *widget = m_trayMap.value(itemKey);
|
||||
|
||||
if (displayMode() == Dock::Efficient) {
|
||||
m_proxyInter->itemRemoved(this, itemKey);
|
||||
@ -393,7 +397,8 @@ void TrayPlugin::trayRemoved(const QString &itemKey)
|
||||
// set the parent of the tray object to avoid be deconstructed by parent(DockItem/PluginsItem/TrayPluginsItem)
|
||||
if (widget->trayTyep() == AbstractTrayWidget::TrayType::SystemTray) {
|
||||
widget->setParent(nullptr);
|
||||
} else {
|
||||
} else if (deleteObject) {
|
||||
m_trayMap.remove(itemKey);
|
||||
widget->deleteLater();
|
||||
}
|
||||
}
|
||||
@ -408,14 +413,6 @@ void TrayPlugin::trayChanged(quint32 winId)
|
||||
m_trayMap.value(itemKey)->updateIcon();
|
||||
}
|
||||
|
||||
void TrayPlugin::sniItemIconChanged()
|
||||
{
|
||||
AbstractTrayWidget *trayWidget = static_cast<AbstractTrayWidget *>(sender());
|
||||
if (!m_trayMap.values().contains(trayWidget)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void TrayPlugin::switchToMode(const Dock::DisplayMode mode)
|
||||
{
|
||||
if (mode == Dock::Fashion) {
|
||||
@ -469,6 +466,29 @@ void TrayPlugin::onRequestRefershWindowVisible()
|
||||
m_proxyInter->requestRefreshWindowVisible(this, itemKey);
|
||||
}
|
||||
|
||||
void TrayPlugin::onSNIItemStatusChanged(SNITrayWidget::ItemStatus status)
|
||||
{
|
||||
SNITrayWidget *trayWidget = static_cast<SNITrayWidget *>(sender());
|
||||
const QString &itemKey = m_trayMap.key(trayWidget);
|
||||
if (!trayWidget || itemKey.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (status) {
|
||||
case SNITrayWidget::Passive: {
|
||||
trayRemoved(itemKey, false);
|
||||
break;
|
||||
}
|
||||
case SNITrayWidget::Active:
|
||||
case SNITrayWidget::NeedsAttention: {
|
||||
addTrayWidget(itemKey, trayWidget);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void TrayPlugin::loadIndicator()
|
||||
{
|
||||
QDir indicatorConfDir("/etc/dde-dock/indicator");
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include "xwindowtraywidget.h"
|
||||
#include "indicatortray.h"
|
||||
#include "indicatortraywidget.h"
|
||||
#include "snitraywidget.h"
|
||||
#include "system-trays/systemtrayscontroller.h"
|
||||
#include "dbus/sni/statusnotifierwatcher_interface.h"
|
||||
|
||||
@ -76,13 +77,13 @@ private slots:
|
||||
void trayXWindowAdded(const QString &itemKey, quint32 winId);
|
||||
void traySNIAdded(const QString &itemKey, const QString &sniServicePath);
|
||||
void trayIndicatorAdded(const QString &itemKey);
|
||||
void trayRemoved(const QString &itemKey);
|
||||
void trayRemoved(const QString &itemKey, const bool deleteObject = true);
|
||||
void trayChanged(quint32 winId);
|
||||
void sniItemIconChanged();
|
||||
void switchToMode(const Dock::DisplayMode mode);
|
||||
void onDbusNameOwnerChanged(const QString &name, const QString &oldOwner, const QString &newOwner);
|
||||
void onRequestWindowAutoHide(const bool autoHide);
|
||||
void onRequestRefershWindowVisible();
|
||||
void onSNIItemStatusChanged(SNITrayWidget::ItemStatus status);
|
||||
|
||||
private:
|
||||
DBusTrayManager *m_trayInter;
|
||||
|
Loading…
x
Reference in New Issue
Block a user