mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-04 09:23:03 +00:00
change plugin interface
Change-Id: Ie2e3fd67559cd1af77deec2377c7978ad00364f1
This commit is contained in:
parent
53cea04d4c
commit
2037457bf7
@ -68,7 +68,7 @@ DockItemController::DockItemController(QObject *parent)
|
|||||||
connect(m_appInter, &DBusDock::EntryAdded, this, &DockItemController::appItemAdded);
|
connect(m_appInter, &DBusDock::EntryAdded, this, &DockItemController::appItemAdded);
|
||||||
connect(m_appInter, &DBusDock::EntryRemoved, this, &DockItemController::appItemRemoved);
|
connect(m_appInter, &DBusDock::EntryRemoved, this, &DockItemController::appItemRemoved);
|
||||||
|
|
||||||
connect(m_pluginsInter, &DockPluginsController::pluginsInserted, this, &DockItemController::pluginsItemInserted);
|
connect(m_pluginsInter, &DockPluginsController::pluginItemInserted, this, &DockItemController::pluginsItemInserted);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DockItemController::appItemAdded(const QDBusObjectPath &path, const int index)
|
void DockItemController::appItemAdded(const QDBusObjectPath &path, const int index)
|
||||||
|
@ -16,10 +16,17 @@ DockPluginsController::~DockPluginsController()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DockPluginsController::itemAdded(PluginsItemInterface * const itemInter, const QString &itemKey)
|
||||||
|
{
|
||||||
|
PluginsItem *item = new PluginsItem(itemInter, itemKey);
|
||||||
|
|
||||||
|
emit pluginItemInserted(item);
|
||||||
|
}
|
||||||
|
|
||||||
void DockPluginsController::loadPlugins()
|
void DockPluginsController::loadPlugins()
|
||||||
{
|
{
|
||||||
Q_ASSERT(m_pluginLoaderList.isEmpty());
|
// Q_ASSERT(m_pluginLoaderList.isEmpty());
|
||||||
Q_ASSERT(m_pluginsInterfaceList.isEmpty());
|
// Q_ASSERT(m_pluginsInterfaceList.isEmpty());
|
||||||
|
|
||||||
#ifdef QT_DEBUG
|
#ifdef QT_DEBUG
|
||||||
const QDir pluginsDir("plugins");
|
const QDir pluginsDir("plugins");
|
||||||
@ -42,7 +49,9 @@ void DockPluginsController::loadPlugins()
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_pluginLoaderList.append(pluginLoader);
|
interface->init(this);
|
||||||
m_pluginsInterfaceList.append(interface);
|
|
||||||
|
// m_pluginLoaderList.append(pluginLoader);
|
||||||
|
// m_pluginsInterfaceList.append(interface);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,13 +2,14 @@
|
|||||||
#define DOCKPLUGINSCONTROLLER_H
|
#define DOCKPLUGINSCONTROLLER_H
|
||||||
|
|
||||||
#include "item/pluginsitem.h"
|
#include "item/pluginsitem.h"
|
||||||
|
#include "pluginproxyinterface.h"
|
||||||
|
|
||||||
#include <QPluginLoader>
|
#include <QPluginLoader>
|
||||||
#include <QList>
|
#include <QList>
|
||||||
|
|
||||||
class DockItemController;
|
class DockItemController;
|
||||||
class PluginsItemInterface;
|
class PluginsItemInterface;
|
||||||
class DockPluginsController : public QObject
|
class DockPluginsController : public QObject, PluginProxyInterface
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
@ -16,15 +17,17 @@ public:
|
|||||||
explicit DockPluginsController(DockItemController *itemControllerInter = 0);
|
explicit DockPluginsController(DockItemController *itemControllerInter = 0);
|
||||||
~DockPluginsController();
|
~DockPluginsController();
|
||||||
|
|
||||||
|
void itemAdded(PluginsItemInterface * const itemInter, const QString &itemKey);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void pluginsInserted(PluginsItem *pluginsItem) const;
|
void pluginItemInserted(PluginsItem *pluginsItem) const;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void loadPlugins();
|
void loadPlugins();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QList<PluginsItemInterface *> m_pluginsInterfaceList;
|
// QList<PluginsItemInterface *> m_pluginsInterfaceList;
|
||||||
QList<QPluginLoader *> m_pluginLoaderList;
|
// QList<QPluginLoader *> m_pluginLoaderList;
|
||||||
DockItemController *m_itemControllerInter;
|
DockItemController *m_itemControllerInter;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -5,14 +5,20 @@
|
|||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QBoxLayout>
|
#include <QBoxLayout>
|
||||||
|
|
||||||
PluginsItem::PluginsItem(PluginsItemInterface* const inter, QWidget *parent)
|
PluginsItem::PluginsItem(PluginsItemInterface* const pluginInter, const QString &itemKey, QWidget *parent)
|
||||||
: DockItem(Plugins, parent),
|
: DockItem(Plugins, parent),
|
||||||
m_inter(inter)
|
m_pluginInter(pluginInter),
|
||||||
|
m_itemKey(itemKey)
|
||||||
{
|
{
|
||||||
|
m_type = pluginInter->pluginType(itemKey);
|
||||||
|
|
||||||
|
if (m_type == PluginsItemInterface::Simple)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// construct complex widget layout
|
||||||
QBoxLayout *layout = new QHBoxLayout;
|
QBoxLayout *layout = new QHBoxLayout;
|
||||||
layout->addWidget(m_inter->centeralWidget());
|
layout->addWidget(m_pluginInter->itemWidget(itemKey));
|
||||||
layout->setSpacing(0);
|
layout->setSpacing(0);
|
||||||
layout->setMargin(0);
|
layout->setMargin(0);
|
||||||
|
|
||||||
setLayout(layout);
|
setLayout(layout);
|
||||||
}
|
}
|
||||||
|
@ -2,17 +2,20 @@
|
|||||||
#define PLUGINSITEM_H
|
#define PLUGINSITEM_H
|
||||||
|
|
||||||
#include "dockitem.h"
|
#include "dockitem.h"
|
||||||
|
#include "pluginsiteminterface.h"
|
||||||
|
|
||||||
class PluginsItemInterface;
|
|
||||||
class PluginsItem : public DockItem
|
class PluginsItem : public DockItem
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit PluginsItem(PluginsItemInterface* const inter, QWidget *parent = 0);
|
explicit PluginsItem(PluginsItemInterface* const pluginInter, const QString &itemKey, QWidget *parent = 0);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
PluginsItemInterface* const m_inter;
|
PluginsItemInterface * const m_pluginInter;
|
||||||
|
const QString m_itemKey;
|
||||||
|
|
||||||
|
PluginsItemInterface::PluginType m_type;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // PLUGINSITEM_H
|
#endif // PLUGINSITEM_H
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
HEADERS += \
|
HEADERS += \
|
||||||
$$PWD/pluginsiteminterface.h \
|
$$PWD/pluginsiteminterface.h \
|
||||||
$$PWD/constants.h
|
$$PWD/constants.h \
|
||||||
|
$$PWD/pluginproxyinterface.h
|
||||||
|
|
||||||
INCLUDEPATH += $$PWD
|
INCLUDEPATH += $$PWD
|
||||||
|
|
||||||
|
14
interfaces/pluginproxyinterface.h
Normal file
14
interfaces/pluginproxyinterface.h
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
#ifndef PLUGINPROXYINTERFACE_H
|
||||||
|
#define PLUGINPROXYINTERFACE_H
|
||||||
|
|
||||||
|
#include <QtCore>
|
||||||
|
|
||||||
|
class PluginsItemInterface;
|
||||||
|
class PluginProxyInterface
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual void itemAdded(PluginsItemInterface * const itemInter, const QString &itemKey) = 0;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // PLUGINPROXYINTERFACE_H
|
@ -1,15 +1,37 @@
|
|||||||
#ifndef PLUGINSITEMINTERFACE_H
|
#ifndef PLUGINSITEMINTERFACE_H
|
||||||
#define PLUGINSITEMINTERFACE_H
|
#define PLUGINSITEMINTERFACE_H
|
||||||
|
|
||||||
|
#include "pluginproxyinterface.h"
|
||||||
|
|
||||||
|
#include <QIcon>
|
||||||
#include <QtCore>
|
#include <QtCore>
|
||||||
|
|
||||||
class PluginsItemInterface
|
class PluginsItemInterface
|
||||||
{
|
{
|
||||||
|
public:
|
||||||
|
enum PluginType
|
||||||
|
{
|
||||||
|
Simple,
|
||||||
|
Complex,
|
||||||
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual ~PluginsItemInterface() {}
|
virtual ~PluginsItemInterface() {}
|
||||||
|
|
||||||
virtual const QString name() = 0;
|
// the unique plugin id
|
||||||
virtual QWidget *centeralWidget() = 0;
|
virtual const QString pluginName() = 0;
|
||||||
|
// plugins type, simple icon or complex widget
|
||||||
|
virtual PluginType pluginType(const QString &itemKey) = 0;
|
||||||
|
// init plugins
|
||||||
|
virtual void init(PluginProxyInterface *proxyInter) = 0;
|
||||||
|
|
||||||
|
// if complex widget mode, only return widget to plugins item
|
||||||
|
virtual QWidget *itemWidget(const QString &itemKey) {Q_UNUSED(itemKey); return nullptr;}
|
||||||
|
// in simple icon mode, plugins need to implements some data source functions
|
||||||
|
virtual const QIcon itemIcon(const QString &itemKey) {Q_UNUSED(itemKey); return QIcon();}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
PluginProxyInterface *m_proxyInter;
|
||||||
};
|
};
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
|
@ -24,13 +24,28 @@ DatetimePlugin::~DatetimePlugin()
|
|||||||
delete m_timeLabel;
|
delete m_timeLabel;
|
||||||
}
|
}
|
||||||
|
|
||||||
const QString DatetimePlugin::name()
|
const QString DatetimePlugin::pluginName()
|
||||||
{
|
{
|
||||||
return "datetime";
|
return "datetime";
|
||||||
}
|
}
|
||||||
|
|
||||||
QWidget *DatetimePlugin::centeralWidget()
|
PluginsItemInterface::PluginType DatetimePlugin::pluginType(const QString &itemKey)
|
||||||
{
|
{
|
||||||
|
Q_UNUSED(itemKey);
|
||||||
|
|
||||||
|
return Complex;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DatetimePlugin::init(PluginProxyInterface *proxyInter)
|
||||||
|
{
|
||||||
|
m_proxyInter = proxyInter;
|
||||||
|
m_proxyInter->itemAdded(this, QString());
|
||||||
|
}
|
||||||
|
|
||||||
|
QWidget *DatetimePlugin::itemWidget(const QString &itemKey)
|
||||||
|
{
|
||||||
|
Q_UNUSED(itemKey);
|
||||||
|
|
||||||
return m_timeLabel;
|
return m_timeLabel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,8 +16,12 @@ public:
|
|||||||
explicit DatetimePlugin(QObject *parent = 0);
|
explicit DatetimePlugin(QObject *parent = 0);
|
||||||
~DatetimePlugin();
|
~DatetimePlugin();
|
||||||
|
|
||||||
const QString name();
|
const QString pluginName();
|
||||||
QWidget *centeralWidget();
|
PluginType pluginType(const QString &itemKey);
|
||||||
|
void init(PluginProxyInterface *proxyInter);
|
||||||
|
|
||||||
|
QWidget *itemWidget(const QString &itemKey);
|
||||||
|
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void refershTime();
|
void refershTime();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user