2016-06-16 16:56:21 +08:00
|
|
|
#include "dockpluginscontroller.h"
|
|
|
|
#include "pluginsiteminterface.h"
|
2016-06-23 16:43:22 +08:00
|
|
|
#include "dockitemcontroller.h"
|
2016-06-16 16:56:21 +08:00
|
|
|
|
|
|
|
#include <QDebug>
|
|
|
|
#include <QDir>
|
|
|
|
|
2016-06-23 16:43:22 +08:00
|
|
|
DockPluginsController::DockPluginsController(DockItemController *itemControllerInter)
|
|
|
|
: QObject(itemControllerInter),
|
|
|
|
m_itemControllerInter(itemControllerInter)
|
2016-06-16 16:56:21 +08:00
|
|
|
{
|
2016-06-28 10:06:04 +08:00
|
|
|
qApp->installEventFilter(this);
|
|
|
|
|
2016-06-16 16:56:21 +08:00
|
|
|
QMetaObject::invokeMethod(this, "loadPlugins", Qt::QueuedConnection);
|
|
|
|
}
|
|
|
|
|
|
|
|
DockPluginsController::~DockPluginsController()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-06-24 11:32:25 +08:00
|
|
|
void DockPluginsController::itemAdded(PluginsItemInterface * const itemInter, const QString &itemKey)
|
|
|
|
{
|
|
|
|
PluginsItem *item = new PluginsItem(itemInter, itemKey);
|
|
|
|
|
2016-06-28 10:06:04 +08:00
|
|
|
m_pluginList[itemInter][itemKey] = item;
|
|
|
|
|
2016-06-24 11:32:25 +08:00
|
|
|
emit pluginItemInserted(item);
|
|
|
|
}
|
|
|
|
|
2016-06-28 10:06:04 +08:00
|
|
|
void DockPluginsController::itemUpdate(PluginsItemInterface * const itemInter, const QString &itemKey)
|
2016-06-27 14:33:21 +08:00
|
|
|
{
|
2016-06-28 10:06:04 +08:00
|
|
|
PluginsItem *item = pluginItemAt(itemInter, itemKey);
|
|
|
|
|
|
|
|
Q_ASSERT(item);
|
|
|
|
|
|
|
|
item->update();
|
2016-06-27 14:33:21 +08:00
|
|
|
}
|
|
|
|
|
2016-06-16 16:56:21 +08:00
|
|
|
void DockPluginsController::loadPlugins()
|
|
|
|
{
|
2016-06-24 11:32:25 +08:00
|
|
|
// Q_ASSERT(m_pluginLoaderList.isEmpty());
|
|
|
|
// Q_ASSERT(m_pluginsInterfaceList.isEmpty());
|
2016-06-16 16:56:21 +08:00
|
|
|
|
2016-06-22 11:16:28 +08:00
|
|
|
#ifdef QT_DEBUG
|
2016-06-16 16:56:21 +08:00
|
|
|
const QDir pluginsDir("plugins");
|
2016-06-22 11:16:28 +08:00
|
|
|
#else
|
|
|
|
const QDir pluginsDir("../lib/dde-dock/plugins");
|
|
|
|
#endif
|
2016-06-16 16:56:21 +08:00
|
|
|
const QStringList plugins = pluginsDir.entryList(QDir::Files);
|
|
|
|
|
|
|
|
for (const QString file : plugins)
|
|
|
|
{
|
|
|
|
if (!QLibrary::isLibrary(file))
|
|
|
|
continue;
|
|
|
|
|
2016-06-24 16:00:15 +08:00
|
|
|
// TODO: old dock plugins is uncompatible
|
|
|
|
if (file.startsWith("libdde-dock-"))
|
|
|
|
continue;
|
|
|
|
|
2016-06-16 16:56:21 +08:00
|
|
|
const QString pluginFilePath = pluginsDir.absoluteFilePath(file);
|
|
|
|
QPluginLoader *pluginLoader = new QPluginLoader(pluginFilePath, this);
|
|
|
|
PluginsItemInterface *interface = qobject_cast<PluginsItemInterface *>(pluginLoader->instance());
|
|
|
|
if (!interface)
|
|
|
|
{
|
2016-06-24 15:47:35 +08:00
|
|
|
pluginLoader->unload();
|
2016-06-16 16:56:21 +08:00
|
|
|
pluginLoader->deleteLater();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-06-24 11:32:25 +08:00
|
|
|
interface->init(this);
|
|
|
|
|
|
|
|
// m_pluginLoaderList.append(pluginLoader);
|
|
|
|
// m_pluginsInterfaceList.append(interface);
|
2016-06-16 16:56:21 +08:00
|
|
|
}
|
|
|
|
}
|
2016-06-28 10:06:04 +08:00
|
|
|
|
|
|
|
void DockPluginsController::displayModeChanged()
|
|
|
|
{
|
|
|
|
const DisplayMode displayMode = qApp->property(PROP_DISPLAY_MODE).value<Dock::DisplayMode>();
|
|
|
|
for (auto inter : m_pluginList.keys())
|
|
|
|
inter->displayModeChanged(displayMode);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DockPluginsController::positionChanged()
|
|
|
|
{
|
|
|
|
const Position position = qApp->property(PROP_POSITION).value<Dock::Position>();
|
|
|
|
for (auto inter : m_pluginList.keys())
|
|
|
|
inter->positionChanged(position);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DockPluginsController::eventFilter(QObject *o, QEvent *e)
|
|
|
|
{
|
|
|
|
if (o != qApp)
|
|
|
|
return false;
|
|
|
|
if (e->type() != QEvent::DynamicPropertyChange)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
QDynamicPropertyChangeEvent * const dpce = static_cast<QDynamicPropertyChangeEvent *>(e);
|
|
|
|
const QString propertyName = dpce->propertyName();
|
|
|
|
|
|
|
|
if (propertyName == PROP_POSITION)
|
|
|
|
positionChanged();
|
|
|
|
else if (propertyName == PROP_DISPLAY_MODE)
|
|
|
|
displayModeChanged();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
PluginsItem *DockPluginsController::pluginItemAt(PluginsItemInterface * const itemInter, const QString &itemKey) const
|
|
|
|
{
|
|
|
|
if (!m_pluginList.contains(itemInter))
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
return m_pluginList[itemInter][itemKey];
|
|
|
|
}
|