mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-04 17:33:05 +00:00
feat: support item sort key interface of TrayPlugin inner plugin
Change-Id: I8da85bb4d821c400cac2113696d3c12c7fed0c36
This commit is contained in:
parent
7207bbff10
commit
2ebef72a18
Notes:
gerrit
2018-11-22 08:59:30 +08:00
Reviewed-on: https://cr.deepin.io/39922 Project: dde/dde-dock Branch: refs/heads/dev/drag-drop-fashion-trays
@ -39,15 +39,15 @@ SystemTraysController::SystemTraysController(QObject *parent)
|
||||
void SystemTraysController::itemAdded(PluginsItemInterface * const itemInter, const QString &itemKey)
|
||||
{
|
||||
// check if same item added
|
||||
if (m_pluginList.contains(itemInter))
|
||||
if (m_pluginList[itemInter].contains(itemKey))
|
||||
if (m_pluginsMap.contains(itemInter))
|
||||
if (m_pluginsMap[itemInter].contains(itemKey))
|
||||
return;
|
||||
|
||||
SystemTrayItem *item = new SystemTrayItem(itemInter, itemKey);
|
||||
|
||||
item->setVisible(false);
|
||||
|
||||
m_pluginList[itemInter][itemKey] = item;
|
||||
m_pluginsMap[itemInter][itemKey] = item;
|
||||
|
||||
emit systemTrayAdded(itemKey, item);
|
||||
}
|
||||
@ -74,7 +74,7 @@ void SystemTraysController::itemRemoved(PluginsItemInterface * const itemInter,
|
||||
|
||||
emit systemTrayRemoved(itemKey);
|
||||
|
||||
m_pluginList[itemInter].remove(itemKey);
|
||||
m_pluginsMap[itemInter].remove(itemKey);
|
||||
|
||||
// do not delete the itemWidget object(specified in the plugin interface)
|
||||
item->centralWidget()->setParent(nullptr);
|
||||
@ -104,7 +104,7 @@ void SystemTraysController::startLoader()
|
||||
void SystemTraysController::displayModeChanged()
|
||||
{
|
||||
const Dock::DisplayMode displayMode = qApp->property(PROP_DISPLAY_MODE).value<Dock::DisplayMode>();
|
||||
const auto inters = m_pluginList.keys();
|
||||
const auto inters = m_pluginsMap.keys();
|
||||
|
||||
for (auto inter : inters)
|
||||
inter->displayModeChanged(displayMode);
|
||||
@ -113,7 +113,7 @@ void SystemTraysController::displayModeChanged()
|
||||
void SystemTraysController::positionChanged()
|
||||
{
|
||||
const Dock::Position position = qApp->property(PROP_POSITION).value<Dock::Position>();
|
||||
const auto inters = m_pluginList.keys();
|
||||
const auto inters = m_pluginsMap.keys();
|
||||
|
||||
for (auto inter : inters)
|
||||
inter->positionChanged(position);
|
||||
@ -138,7 +138,7 @@ void SystemTraysController::loadPlugin(const QString &pluginFile)
|
||||
return;
|
||||
}
|
||||
|
||||
m_pluginList.insert(interface, QMap<QString, SystemTrayItem *>());
|
||||
m_pluginsMap.insert(interface, QMap<QString, SystemTrayItem *>());
|
||||
|
||||
QString dbusService = meta.value("depends-daemon-dbus-service").toString();
|
||||
if (!dbusService.isEmpty() && !m_dbusDaemonInterface->isServiceRegistered(dbusService).value()) {
|
||||
@ -184,21 +184,69 @@ bool SystemTraysController::eventFilter(QObject *o, QEvent *e)
|
||||
|
||||
SystemTrayItem *SystemTraysController::pluginItemAt(PluginsItemInterface * const itemInter, const QString &itemKey) const
|
||||
{
|
||||
if (!m_pluginList.contains(itemInter))
|
||||
if (!m_pluginsMap.contains(itemInter))
|
||||
return nullptr;
|
||||
|
||||
return m_pluginList[itemInter][itemKey];
|
||||
return m_pluginsMap[itemInter][itemKey];
|
||||
}
|
||||
|
||||
void SystemTraysController::saveValue(PluginsItemInterface *const itemInter, const QString &itemKey, const QVariant &value) {
|
||||
PluginsItemInterface *SystemTraysController::pluginInterAt(const QString &itemKey) const
|
||||
{
|
||||
for (auto it = m_pluginsMap.constBegin(); it != m_pluginsMap.constEnd(); ++it) {
|
||||
for (auto key : it.value().keys()) {
|
||||
if (key == itemKey) {
|
||||
return it.key();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
PluginsItemInterface *SystemTraysController::pluginInterAt(SystemTrayItem *systemTrayItem) const
|
||||
{
|
||||
for (auto it = m_pluginsMap.constBegin(); it != m_pluginsMap.constEnd(); ++it) {
|
||||
for (auto item : it.value().values()) {
|
||||
if (item == systemTrayItem) {
|
||||
return it.key();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void SystemTraysController::saveValue(PluginsItemInterface *const itemInter, const QString &key, const QVariant &value) {
|
||||
m_pluginsSetting.beginGroup(itemInter->pluginName());
|
||||
m_pluginsSetting.setValue(itemKey, value);
|
||||
m_pluginsSetting.setValue(key, value);
|
||||
m_pluginsSetting.endGroup();
|
||||
}
|
||||
|
||||
const QVariant SystemTraysController::getValue(PluginsItemInterface *const itemInter, const QString &itemKey, const QVariant& failback) {
|
||||
const QVariant SystemTraysController::getValue(PluginsItemInterface *const itemInter, const QString &key, const QVariant& failback) {
|
||||
m_pluginsSetting.beginGroup(itemInter->pluginName());
|
||||
QVariant value { std::move(m_pluginsSetting.value(itemKey, failback)) };
|
||||
QVariant value { std::move(m_pluginsSetting.value(key, failback)) };
|
||||
m_pluginsSetting.endGroup();
|
||||
return std::move(value);
|
||||
}
|
||||
|
||||
int SystemTraysController::systemTrayItemSortKey(const QString &itemKey)
|
||||
{
|
||||
auto inter = pluginInterAt(itemKey);
|
||||
|
||||
if (!inter) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return inter->itemSortKey(itemKey);
|
||||
}
|
||||
|
||||
void SystemTraysController::setSystemTrayItemSortKey(const QString &itemKey, const int order)
|
||||
{
|
||||
auto inter = pluginInterAt(itemKey);
|
||||
|
||||
if (!inter) {
|
||||
return;
|
||||
}
|
||||
|
||||
inter->setSortKey(itemKey, order);
|
||||
}
|
||||
|
@ -43,8 +43,11 @@ public:
|
||||
void itemUpdate(PluginsItemInterface * const itemInter, const QString &itemKey);
|
||||
void itemRemoved(PluginsItemInterface * const itemInter, const QString &itemKey);
|
||||
void requestContextMenu(PluginsItemInterface * const itemInter, const QString &itemKey);
|
||||
void saveValue(PluginsItemInterface *const itemInter, const QString &itemKey, const QVariant &value);
|
||||
const QVariant getValue(PluginsItemInterface *const itemInter, const QString &itemKey, const QVariant& failback = QVariant());
|
||||
void saveValue(PluginsItemInterface *const itemInter, const QString &key, const QVariant &value);
|
||||
const QVariant getValue(PluginsItemInterface *const itemInter, const QString &key, const QVariant& failback = QVariant());
|
||||
|
||||
int systemTrayItemSortKey(const QString &itemKey);
|
||||
void setSystemTrayItemSortKey(const QString &itemKey, const int order);
|
||||
|
||||
public slots:
|
||||
void startLoader();
|
||||
@ -63,10 +66,12 @@ private slots:
|
||||
private:
|
||||
bool eventFilter(QObject *o, QEvent *e);
|
||||
SystemTrayItem *pluginItemAt(PluginsItemInterface * const itemInter, const QString &itemKey) const;
|
||||
PluginsItemInterface *pluginInterAt(const QString &itemKey) const;
|
||||
PluginsItemInterface *pluginInterAt(SystemTrayItem *systemTrayItem) const;
|
||||
|
||||
private:
|
||||
QDBusConnectionInterface *m_dbusDaemonInterface;
|
||||
QMap<PluginsItemInterface *, QMap<QString, SystemTrayItem *>> m_pluginList;
|
||||
QMap<PluginsItemInterface *, QMap<QString, SystemTrayItem *>> m_pluginsMap;
|
||||
|
||||
QSettings m_pluginsSetting;
|
||||
};
|
||||
|
@ -156,6 +156,11 @@ bool TrayPlugin::itemIsInContainer(const QString &itemKey)
|
||||
|
||||
int TrayPlugin::itemSortKey(const QString &itemKey)
|
||||
{
|
||||
// 如果是系统托盘图标则调用内部插件的相应接口
|
||||
if (isSystemTrayItem(itemKey)) {
|
||||
return m_systemTraysController->systemTrayItemSortKey(itemKey);
|
||||
}
|
||||
|
||||
Dock::DisplayMode mode = displayMode();
|
||||
const QString key = QString("pos_%1_%2").arg(itemKey).arg(mode);
|
||||
|
||||
@ -164,6 +169,11 @@ int TrayPlugin::itemSortKey(const QString &itemKey)
|
||||
|
||||
void TrayPlugin::setSortKey(const QString &itemKey, const int order)
|
||||
{
|
||||
// 如果是系统托盘图标则调用内部插件的相应接口
|
||||
if (isSystemTrayItem(itemKey)) {
|
||||
return m_systemTraysController->setSystemTrayItemSortKey(itemKey, order);
|
||||
}
|
||||
|
||||
const QString key = QString("pos_%1_%2").arg(itemKey).arg(displayMode());
|
||||
m_proxyInter->saveValue(this, key, order);
|
||||
}
|
||||
@ -201,6 +211,17 @@ const QString TrayPlugin::getWindowClass(quint32 winId)
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool TrayPlugin::isSystemTrayItem(const QString &itemKey)
|
||||
{
|
||||
AbstractTrayWidget * const trayWidget = m_trayMap.value(itemKey, nullptr);
|
||||
|
||||
if (trayWidget && trayWidget->trayTyep() == AbstractTrayWidget::TrayType::SystemTray) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void TrayPlugin::sniItemsChanged()
|
||||
{
|
||||
const QStringList &itemServicePaths = m_sniWatcher->RegisteredStatusNotifierItems();
|
||||
|
@ -65,6 +65,7 @@ public:
|
||||
private:
|
||||
void loadIndicator();
|
||||
const QString getWindowClass(quint32 winId);
|
||||
bool isSystemTrayItem(const QString &itemKey);
|
||||
|
||||
private slots:
|
||||
void addTrayWidget(const QString &itemKey, AbstractTrayWidget *trayWidget);
|
||||
|
Loading…
x
Reference in New Issue
Block a user