Skip to content

Commit

Permalink
feat: support item sort key interface of TrayPlugin inner plugin
Browse files Browse the repository at this point in the history
Change-Id: I8da85bb4d821c400cac2113696d3c12c7fed0c36
  • Loading branch information
listenerri committed Nov 21, 2018
1 parent 7207bbf commit 2ebef72
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 16 deletions.
74 changes: 61 additions & 13 deletions plugins/tray/system-trays/systemtrayscontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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()) {
Expand Down Expand Up @@ -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);
}
11 changes: 8 additions & 3 deletions plugins/tray/system-trays/systemtrayscontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,11 @@ class SystemTraysController : public QObject, PluginProxyInterface
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();
Expand All @@ -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;
};
Expand Down
21 changes: 21 additions & 0 deletions plugins/tray/trayplugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);
}
Expand Down Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions plugins/tray/trayplugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class TrayPlugin : public QObject, PluginsItemInterface
private:
void loadIndicator();
const QString getWindowClass(quint32 winId);
bool isSystemTrayItem(const QString &itemKey);

private slots:
void addTrayWidget(const QString &itemKey, AbstractTrayWidget *trayWidget);
Expand Down

0 comments on commit 2ebef72

Please sign in to comment.