From 38264b4388470e9789ee828999416d498d95a28e Mon Sep 17 00:00:00 2001 From: Hualet Wang Date: Thu, 2 Jul 2015 19:47:53 +0800 Subject: [PATCH] new dockplugininterface --- .../dde-dock-systray-plugin.pro | 1 - dde-dock-systray-plugin/docktrayitem.cpp | 53 ++----------------- dde-dock-systray-plugin/docktrayitem.h | 20 ++----- dde-dock-systray-plugin/systrayplugin.cpp | 27 +++++----- dde-dock-systray-plugin/systrayplugin.h | 8 +-- dde-dock/dde-dock.pro | 6 ++- dde-dock/src/Panel/panel.cpp | 1 + dde-dock/src/dockplugininterface.h | 6 ++- dde-dock/src/pluginitemwrapper.cpp | 19 +++++++ dde-dock/src/pluginitemwrapper.h | 18 +++++++ dde-dock/src/systraymanager.cpp | 14 +++-- dde-dock/src/systraymanager.h | 2 +- 12 files changed, 85 insertions(+), 90 deletions(-) create mode 100644 dde-dock/src/pluginitemwrapper.cpp create mode 100644 dde-dock/src/pluginitemwrapper.h diff --git a/dde-dock-systray-plugin/dde-dock-systray-plugin.pro b/dde-dock-systray-plugin/dde-dock-systray-plugin.pro index f57e46610..1a37da198 100644 --- a/dde-dock-systray-plugin/dde-dock-systray-plugin.pro +++ b/dde-dock-systray-plugin/dde-dock-systray-plugin.pro @@ -20,7 +20,6 @@ SOURCES += systrayplugin.cpp \ HEADERS += systrayplugin.h \ docktrayitem.h \ - ../dde-dock/src/abstractdockitem.h \ dbustraymanager.h target.path = /usr/share/dde-dock/plugins/ diff --git a/dde-dock-systray-plugin/docktrayitem.cpp b/dde-dock-systray-plugin/docktrayitem.cpp index a7ff20137..3ad8952f9 100644 --- a/dde-dock-systray-plugin/docktrayitem.cpp +++ b/dde-dock-systray-plugin/docktrayitem.cpp @@ -2,9 +2,9 @@ #include "docktrayitem.h" -DockTrayItem * DockTrayItem::fromWinId(WId winId, QWidget *parent) +DockTrayItem * DockTrayItem::fromWinId(WId winId) { - DockTrayItem *item = new DockTrayItem(parent); + DockTrayItem *item = new DockTrayItem; QWindow *win = QWindow::fromWinId(winId); QWidget *child = QWidget::createWindowContainer(win, item); @@ -17,57 +17,12 @@ DockTrayItem * DockTrayItem::fromWinId(WId winId, QWidget *parent) } DockTrayItem::DockTrayItem(QWidget *parent) - : AbstractDockItem(parent) + : QWidget(parent) { - setFixedSize(32, 32); + setFixedSize(16, 16); } DockTrayItem::~DockTrayItem() { } - -void DockTrayItem::setTitle(const QString &) -{ - -} - -void DockTrayItem::setIcon(const QString &, int) -{ - -} - -void DockTrayItem::setMoveable(bool) -{ - -} - -bool DockTrayItem::moveable() -{ - return false; -} - -void DockTrayItem::setActived(bool) -{ - -} - -bool DockTrayItem::actived() -{ - return false; -} - -void DockTrayItem::setIndex(int value) -{ - m_itemIndex = value; -} - -int DockTrayItem::index() -{ - return m_itemIndex; -} - -QWidget * DockTrayItem::getContents() -{ - return NULL; -} diff --git a/dde-dock-systray-plugin/docktrayitem.h b/dde-dock-systray-plugin/docktrayitem.h index a64d32a03..ac57f23df 100644 --- a/dde-dock-systray-plugin/docktrayitem.h +++ b/dde-dock-systray-plugin/docktrayitem.h @@ -2,30 +2,20 @@ #define DOCKTRAYITEM_H #include +#include -#include "abstractdockitem.h" - -class DockTrayItem : public AbstractDockItem +class DockTrayItem : public QWidget { Q_OBJECT enum Style { Simple, Composite }; public: - explicit DockTrayItem(QWidget *parent = 0); ~DockTrayItem(); - static DockTrayItem* fromWinId(WId winId, QWidget *parent=0); + static DockTrayItem* fromWinId(WId winId); - void setTitle(const QString &title) Q_DECL_OVERRIDE; - void setIcon(const QString &iconPath, int size = 42) Q_DECL_OVERRIDE; - void setMoveable(bool value) Q_DECL_OVERRIDE; - bool moveable() Q_DECL_OVERRIDE; - void setActived(bool value) Q_DECL_OVERRIDE; - bool actived() Q_DECL_OVERRIDE; - void setIndex(int value) Q_DECL_OVERRIDE; - int index() Q_DECL_OVERRIDE; - - QWidget * getContents() Q_DECL_OVERRIDE; +private: + DockTrayItem(QWidget *parent = 0); }; #endif // DOCKTRAYITEM_H diff --git a/dde-dock-systray-plugin/systrayplugin.cpp b/dde-dock-systray-plugin/systrayplugin.cpp index 041423e7a..b9842c7e3 100644 --- a/dde-dock-systray-plugin/systrayplugin.cpp +++ b/dde-dock-systray-plugin/systrayplugin.cpp @@ -3,17 +3,14 @@ #include "systrayplugin.h" #include "abstractdockitem.h" + SystrayPlugin::~SystrayPlugin() { this->clearItems(); } -QList SystrayPlugin::items() +void SystrayPlugin::init() { - //clear m_items. - this->clearItems(); - - // get xids of trayicons. if (!m_dbusTrayManager) { m_dbusTrayManager = new com::deepin::dde::TrayManager("com.deepin.dde.TrayManager", "/com/deepin/dde/TrayManager", @@ -24,22 +21,24 @@ QList SystrayPlugin::items() QList trayIcons = m_dbusTrayManager->trayIcons(); qDebug() << "Found trayicons: " << trayIcons; - QList winIds; - foreach (QVariant trayIcon, trayIcons) { - winIds << trayIcon.toUInt(); + foreach (uint trayIcon, trayIcons) { + m_items[QString::number(trayIcon)] = DockTrayItem::fromWinId(trayIcon); } +} - // generate items. - foreach (WId winId, winIds) { - m_items << DockTrayItem::fromWinId(winId); - } +QStringList SystrayPlugin::uuids() +{ + return m_items.keys(); +} - return m_items; +QWidget * SystrayPlugin::getItem(QString uuid) +{ + return m_items.value(uuid); } void SystrayPlugin::clearItems() { - foreach (AbstractDockItem * item, m_items) { + foreach (QWidget * item, m_items) { item->deleteLater(); } m_items.clear(); diff --git a/dde-dock-systray-plugin/systrayplugin.h b/dde-dock-systray-plugin/systrayplugin.h index d51e2197a..0f9699d6c 100644 --- a/dde-dock-systray-plugin/systrayplugin.h +++ b/dde-dock-systray-plugin/systrayplugin.h @@ -2,10 +2,10 @@ #define SYSTRAYPLUGIN_H #include +#include #include "docktrayitem.h" #include "dockplugininterface.h" -#include "abstractdockitem.h" #include "dbustraymanager.h" class SystrayPlugin : public QObject, DockPluginInterface @@ -17,10 +17,12 @@ class SystrayPlugin : public QObject, DockPluginInterface public: ~SystrayPlugin(); - QList items() Q_DECL_OVERRIDE; + void init() Q_DECL_OVERRIDE; + QStringList uuids() Q_DECL_OVERRIDE; + QWidget * getItem(QString uuid) Q_DECL_OVERRIDE; private: - QList m_items; + QMap m_items; com::deepin::dde::TrayManager *m_dbusTrayManager = 0; void clearItems(); diff --git a/dde-dock/dde-dock.pro b/dde-dock/dde-dock.pro index b4e788a10..ab1f54169 100644 --- a/dde-dock/dde-dock.pro +++ b/dde-dock/dde-dock.pro @@ -25,7 +25,8 @@ SOURCES += \ src/systraymanager.cpp \ src/Panel/panelmenu.cpp \ src/Controller/dockmodedata.cpp \ - src/Controller/dockconstants.cpp + src/Controller/dockconstants.cpp \ + src/pluginitemwrapper.cpp HEADERS += \ src/abstractdockitem.h \ @@ -41,7 +42,8 @@ HEADERS += \ src/systraymanager.h \ src/Panel/panelmenu.h \ src/Controller/dockmodedata.h \ - src/Controller/dockconstants.h + src/Controller/dockconstants.h \ + src/pluginitemwrapper.h RESOURCES += \ images.qrc \ diff --git a/dde-dock/src/Panel/panel.cpp b/dde-dock/src/Panel/panel.cpp index b5653b345..5acf34d20 100644 --- a/dde-dock/src/Panel/panel.cpp +++ b/dde-dock/src/Panel/panel.cpp @@ -40,6 +40,7 @@ Panel::Panel(QWidget *parent) SystrayManager *manager = new SystrayManager(); foreach (AbstractDockItem *item, manager->trayIcons()) { rightLayout->addItem(item); + qDebug() << item->geometry(); } panelMenu = new PanelMenu(); diff --git a/dde-dock/src/dockplugininterface.h b/dde-dock/src/dockplugininterface.h index 4aee9aaa4..f60c8eb71 100644 --- a/dde-dock/src/dockplugininterface.h +++ b/dde-dock/src/dockplugininterface.h @@ -2,13 +2,15 @@ #define DOCKPLUGININTERFACE_H #include -#include "abstractdockitem.h" +#include class DockPluginInterface { public: virtual ~DockPluginInterface() {} - virtual QList items() = 0; + virtual void init() = 0; + virtual QStringList uuids() = 0; + virtual QWidget* getItem(QString uuid) = 0; }; QT_BEGIN_NAMESPACE diff --git a/dde-dock/src/pluginitemwrapper.cpp b/dde-dock/src/pluginitemwrapper.cpp new file mode 100644 index 000000000..b8996ff9a --- /dev/null +++ b/dde-dock/src/pluginitemwrapper.cpp @@ -0,0 +1,19 @@ +#include "pluginitemwrapper.h" + +PluginItemWrapper::PluginItemWrapper(DockPluginInterface *plugin, + QString uuid, QWidget * parent) : + AbstractDockItem(parent), + m_plugin(plugin), + m_uuid(uuid) +{ + if (m_plugin) { + QWidget * item = m_plugin->getItem(uuid); + + if (item) { + setFixedSize(item->size()); + + item->setParent(this); + item->move(this->rect().center() - item->rect().center()); + } + } +} diff --git a/dde-dock/src/pluginitemwrapper.h b/dde-dock/src/pluginitemwrapper.h new file mode 100644 index 000000000..d33f63e80 --- /dev/null +++ b/dde-dock/src/pluginitemwrapper.h @@ -0,0 +1,18 @@ +#ifndef PLUGINITEMWRAPPER_H +#define PLUGINITEMWRAPPER_H + +#include "abstractdockitem.h" +#include "dockplugininterface.h" + +class PluginItemWrapper : public AbstractDockItem +{ +public: + PluginItemWrapper(DockPluginInterface *plugin, QString uuid, QWidget * parent = 0); + + +private: + DockPluginInterface * m_plugin; + QString m_uuid; +}; + +#endif // PLUGINITEMWRAPPER_H diff --git a/dde-dock/src/systraymanager.cpp b/dde-dock/src/systraymanager.cpp index 5e4d96b6d..e617c2ef7 100644 --- a/dde-dock/src/systraymanager.cpp +++ b/dde-dock/src/systraymanager.cpp @@ -3,6 +3,7 @@ #include #include "systraymanager.h" +#include "pluginitemwrapper.h" static QString SystrayPluginPath = "/usr/share/dde-dock/plugins/libdock-systray-plugin.so"; @@ -15,11 +16,17 @@ SystrayManager::SystrayManager(QObject *parent) QList SystrayManager::trayIcons() { + QList result; + if (m_plugin) { - return m_plugin->items(); - } else { - return QList(); + QStringList uuids = m_plugin->uuids(); + + foreach (QString uuid, uuids) { + result << new PluginItemWrapper(m_plugin, uuid); + } } + + return result; } void SystrayManager::loadPlugin() @@ -29,6 +36,7 @@ void SystrayManager::loadPlugin() QObject *plugin = loader.instance(); if (plugin) { m_plugin = qobject_cast(plugin); + m_plugin->init(); } else { qWarning() << "Failed to load systray plugin."; qWarning() << loader.errorString(); diff --git a/dde-dock/src/systraymanager.h b/dde-dock/src/systraymanager.h index e092f99c3..318cefafd 100644 --- a/dde-dock/src/systraymanager.h +++ b/dde-dock/src/systraymanager.h @@ -4,6 +4,7 @@ #include #include "dockplugininterface.h" +class AbstractDockItem; class SystrayManager : public QObject { Q_OBJECT @@ -16,7 +17,6 @@ private: DockPluginInterface *m_plugin; void loadPlugin(); - void unloadPlugin(); }; #endif // SYSTRAYMANAGER_H