mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-04 17:33:05 +00:00
feat(plugin interface):interface method move to below,and add a version to interface
This commit is contained in:
parent
0c24252ad2
commit
7ce3a6c70d
@ -30,6 +30,7 @@
|
|||||||
static const QStringList CompatiblePluginApiList {
|
static const QStringList CompatiblePluginApiList {
|
||||||
"1.1.1",
|
"1.1.1",
|
||||||
"1.2",
|
"1.2",
|
||||||
|
"1.2.1",
|
||||||
DOCK_PLUGIN_API_VERSION
|
DOCK_PLUGIN_API_VERSION
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -45,7 +46,8 @@ AbstractPluginsController::AbstractPluginsController(QObject *parent)
|
|||||||
connect(m_dockDaemonInter, &DockDaemonInter::PluginSettingsSynced, this, &AbstractPluginsController::refreshPluginSettings, Qt::QueuedConnection);
|
connect(m_dockDaemonInter, &DockDaemonInter::PluginSettingsSynced, this, &AbstractPluginsController::refreshPluginSettings, Qt::QueuedConnection);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AbstractPluginsController::saveValue(PluginsItemInterface *const itemInter, const QString &key, const QVariant &value) {
|
void AbstractPluginsController::saveValue(PluginsItemInterface *const itemInter, const QString &key, const QVariant &value)
|
||||||
|
{
|
||||||
// is it necessary?
|
// is it necessary?
|
||||||
// refreshPluginSettings();
|
// refreshPluginSettings();
|
||||||
|
|
||||||
@ -61,7 +63,8 @@ void AbstractPluginsController::saveValue(PluginsItemInterface *const itemInter,
|
|||||||
m_dockDaemonInter->MergePluginSettings(QJsonDocument(remoteObject).toJson(QJsonDocument::JsonFormat::Compact));
|
m_dockDaemonInter->MergePluginSettings(QJsonDocument(remoteObject).toJson(QJsonDocument::JsonFormat::Compact));
|
||||||
}
|
}
|
||||||
|
|
||||||
const QVariant AbstractPluginsController::getValue(PluginsItemInterface *const itemInter, const QString &key, const QVariant& fallback) {
|
const QVariant AbstractPluginsController::getValue(PluginsItemInterface *const itemInter, const QString &key, const QVariant &fallback)
|
||||||
|
{
|
||||||
// load from local cache
|
// load from local cache
|
||||||
QVariant v = m_pluginSettingsObject.value(itemInter->pluginName()).toObject().value(key).toVariant();
|
QVariant v = m_pluginSettingsObject.value(itemInter->pluginName()).toObject().value(key).toVariant();
|
||||||
if (v.isNull() || !v.isValid()) {
|
if (v.isNull() || !v.isValid()) {
|
||||||
@ -71,7 +74,7 @@ const QVariant AbstractPluginsController::getValue(PluginsItemInterface *const i
|
|||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AbstractPluginsController::removeValue(PluginsItemInterface * const itemInter, const QStringList &keyList)
|
void AbstractPluginsController::removeValue(PluginsItemInterface *const itemInter, const QStringList &keyList)
|
||||||
{
|
{
|
||||||
if (keyList.isEmpty()) {
|
if (keyList.isEmpty()) {
|
||||||
m_pluginSettingsObject.remove(itemInter->pluginName());
|
m_pluginSettingsObject.remove(itemInter->pluginName());
|
||||||
@ -91,7 +94,7 @@ QMap<PluginsItemInterface *, QMap<QString, QObject *> > &AbstractPluginsControll
|
|||||||
return m_pluginsMap;
|
return m_pluginsMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
QObject *AbstractPluginsController::pluginItemAt(PluginsItemInterface * const itemInter, const QString &itemKey) const
|
QObject *AbstractPluginsController::pluginItemAt(PluginsItemInterface *const itemInter, const QString &itemKey) const
|
||||||
{
|
{
|
||||||
if (!m_pluginsMap.contains(itemInter))
|
if (!m_pluginsMap.contains(itemInter))
|
||||||
return nullptr;
|
return nullptr;
|
||||||
@ -133,7 +136,7 @@ void AbstractPluginsController::startLoader(PluginLoader *loader)
|
|||||||
QGSettings gsetting("com.deepin.dde.dock", "/com/deepin/dde/dock/");
|
QGSettings gsetting("com.deepin.dde.dock", "/com/deepin/dde/dock/");
|
||||||
|
|
||||||
QTimer::singleShot(gsetting.get("delay-plugins-time").toUInt(),
|
QTimer::singleShot(gsetting.get("delay-plugins-time").toUInt(),
|
||||||
loader, [=] { loader->start(QThread::LowestPriority); });
|
loader, [ = ] { loader->start(QThread::LowestPriority); });
|
||||||
}
|
}
|
||||||
|
|
||||||
void AbstractPluginsController::displayModeChanged()
|
void AbstractPluginsController::displayModeChanged()
|
||||||
@ -160,8 +163,7 @@ void AbstractPluginsController::loadPlugin(const QString &pluginFile)
|
|||||||
const QJsonObject &meta = pluginLoader->metaData().value("MetaData").toObject();
|
const QJsonObject &meta = pluginLoader->metaData().value("MetaData").toObject();
|
||||||
const QString &pluginApi = meta.value("api").toString();
|
const QString &pluginApi = meta.value("api").toString();
|
||||||
bool pluginIsValid = true;
|
bool pluginIsValid = true;
|
||||||
if (pluginApi.isEmpty() || !CompatiblePluginApiList.contains(pluginApi))
|
if (pluginApi.isEmpty() || !CompatiblePluginApiList.contains(pluginApi)) {
|
||||||
{
|
|
||||||
qWarning() << objectName()
|
qWarning() << objectName()
|
||||||
<< "plugin api version not matched! expect versions:" << CompatiblePluginApiList
|
<< "plugin api version not matched! expect versions:" << CompatiblePluginApiList
|
||||||
<< ", got version:" << pluginApi
|
<< ", got version:" << pluginApi
|
||||||
@ -171,8 +173,7 @@ void AbstractPluginsController::loadPlugin(const QString &pluginFile)
|
|||||||
}
|
}
|
||||||
|
|
||||||
PluginsItemInterface *interface = qobject_cast<PluginsItemInterface *>(pluginLoader->instance());
|
PluginsItemInterface *interface = qobject_cast<PluginsItemInterface *>(pluginLoader->instance());
|
||||||
if (!interface)
|
if (!interface) {
|
||||||
{
|
|
||||||
qWarning() << objectName() << "load plugin failed!!!" << pluginLoader->errorString() << pluginFile;
|
qWarning() << objectName() << "load plugin failed!!!" << pluginLoader->errorString() << pluginFile;
|
||||||
|
|
||||||
pluginLoader->unload();
|
pluginLoader->unload();
|
||||||
@ -193,27 +194,28 @@ void AbstractPluginsController::loadPlugin(const QString &pluginFile)
|
|||||||
if (!dbusService.isEmpty() && !m_dbusDaemonInterface->isServiceRegistered(dbusService).value()) {
|
if (!dbusService.isEmpty() && !m_dbusDaemonInterface->isServiceRegistered(dbusService).value()) {
|
||||||
qDebug() << objectName() << dbusService << "daemon has not started, waiting for signal";
|
qDebug() << objectName() << dbusService << "daemon has not started, waiting for signal";
|
||||||
connect(m_dbusDaemonInterface, &QDBusConnectionInterface::serviceOwnerChanged, this,
|
connect(m_dbusDaemonInterface, &QDBusConnectionInterface::serviceOwnerChanged, this,
|
||||||
[=](const QString &name, const QString &oldOwner, const QString &newOwner) {
|
[ = ](const QString & name, const QString & oldOwner, const QString & newOwner) {
|
||||||
Q_UNUSED(oldOwner);
|
Q_UNUSED(oldOwner);
|
||||||
if (name == dbusService && !newOwner.isEmpty()) {
|
if (name == dbusService && !newOwner.isEmpty()) {
|
||||||
qDebug() << objectName() << dbusService << "daemon started, init plugin and disconnect";
|
qDebug() << objectName() << dbusService << "daemon started, init plugin and disconnect";
|
||||||
initPlugin(interface);
|
initPlugin(interface);
|
||||||
disconnect(m_dbusDaemonInterface);
|
disconnect(m_dbusDaemonInterface);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
);
|
}
|
||||||
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTE(justforlxz): 插件的所有初始化工作都在init函数中进行,
|
// NOTE(justforlxz): 插件的所有初始化工作都在init函数中进行,
|
||||||
// loadPlugin函数是按队列执行的,initPlugin函数会有可能导致
|
// loadPlugin函数是按队列执行的,initPlugin函数会有可能导致
|
||||||
// 函数执行被阻塞。
|
// 函数执行被阻塞。
|
||||||
QTimer::singleShot(1, this, [=] {
|
QTimer::singleShot(1, this, [ = ] {
|
||||||
initPlugin(interface);
|
initPlugin(interface);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void AbstractPluginsController::initPlugin(PluginsItemInterface *interface) {
|
void AbstractPluginsController::initPlugin(PluginsItemInterface *interface)
|
||||||
|
{
|
||||||
qDebug() << objectName() << "init plugin: " << interface->pluginName();
|
qDebug() << objectName() << "init plugin: " << interface->pluginName();
|
||||||
interface->init(this);
|
interface->init(this);
|
||||||
qDebug() << objectName() << "init plugin finished: " << interface->pluginName();
|
qDebug() << objectName() << "init plugin finished: " << interface->pluginName();
|
||||||
@ -278,7 +280,7 @@ bool AbstractPluginsController::eventFilter(QObject *o, QEvent *e)
|
|||||||
if (e->type() != QEvent::DynamicPropertyChange)
|
if (e->type() != QEvent::DynamicPropertyChange)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
QDynamicPropertyChangeEvent * const dpce = static_cast<QDynamicPropertyChangeEvent *>(e);
|
QDynamicPropertyChangeEvent *const dpce = static_cast<QDynamicPropertyChangeEvent *>(e);
|
||||||
const QString propertyName = dpce->propertyName();
|
const QString propertyName = dpce->propertyName();
|
||||||
|
|
||||||
if (propertyName == PROP_POSITION)
|
if (propertyName == PROP_POSITION)
|
||||||
|
@ -27,7 +27,7 @@
|
|||||||
namespace Dock {
|
namespace Dock {
|
||||||
|
|
||||||
#define DOCK_PLUGIN_MIME "dock/plugin"
|
#define DOCK_PLUGIN_MIME "dock/plugin"
|
||||||
#define DOCK_PLUGIN_API_VERSION "1.2.1"
|
#define DOCK_PLUGIN_API_VERSION "1.2.2"
|
||||||
|
|
||||||
#define PROP_DISPLAY_MODE "DisplayMode"
|
#define PROP_DISPLAY_MODE "DisplayMode"
|
||||||
|
|
||||||
|
@ -54,7 +54,6 @@ public:
|
|||||||
virtual const QString pluginName() const = 0;
|
virtual const QString pluginName() const = 0;
|
||||||
virtual const QString pluginDisplayName() const { return QString(); }
|
virtual const QString pluginDisplayName() const { return QString(); }
|
||||||
|
|
||||||
virtual PluginType type() { return Normal; }
|
|
||||||
///
|
///
|
||||||
/// \brief init
|
/// \brief init
|
||||||
/// init your plugins, you need to save proxyInter to m_proxyInter
|
/// init your plugins, you need to save proxyInter to m_proxyInter
|
||||||
@ -224,6 +223,12 @@ public:
|
|||||||
///
|
///
|
||||||
virtual void pluginSettingsChanged() {}
|
virtual void pluginSettingsChanged() {}
|
||||||
|
|
||||||
|
///
|
||||||
|
/// \brief type
|
||||||
|
/// default plugin add dock right,fixed plugin add to dock fixed area
|
||||||
|
///
|
||||||
|
virtual PluginType type() { return Normal; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
///
|
///
|
||||||
/// \brief m_proxyInter
|
/// \brief m_proxyInter
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
{
|
{
|
||||||
"api": "1.1.1"
|
"api": "1.2.2"
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
{
|
{
|
||||||
"api": "1.1.1"
|
"api": "1.2.2"
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user