-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add AppletBridge to connect applets
We add AppletProxy to export Applet's signals and slots. AppletMetaProxy as QObject's router for signals and slots. task: https://pms.uniontech.com/task-view-365219.html
- Loading branch information
1 parent
fe0d038
commit b4d88ce
Showing
16 changed files
with
409 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd. | ||
// | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
#include "appletbridge.h" | ||
#include "containment.h" | ||
#include "private/appletbridge_p.h" | ||
#include "private/applet_p.h" | ||
|
||
#include "pluginloader.h" | ||
#include <QQueue> | ||
|
||
DS_BEGIN_NAMESPACE | ||
|
||
DAppletBridgePrivate::DAppletBridgePrivate(DAppletBridge *qq) | ||
: DTK_CORE_NAMESPACE::DObjectPrivate(qq) | ||
{ | ||
} | ||
|
||
DAppletBridgePrivate::~DAppletBridgePrivate() | ||
{ | ||
} | ||
|
||
QList<DApplet *> DAppletBridgePrivate::applets() const | ||
{ | ||
QList<DApplet *> applets; | ||
auto rootApplet = DPluginLoader::instance()->rootApplet(); | ||
auto root = qobject_cast<DContainment *>(rootApplet); | ||
|
||
QQueue<DContainment *> containments; | ||
containments.enqueue(root); | ||
while (!containments.isEmpty()) { | ||
DContainment *containment = containments.dequeue(); | ||
for (const auto applet : containment->applets()) { | ||
if (auto item = qobject_cast<DContainment *>(applet)) { | ||
containments.enqueue(item); | ||
} | ||
if (applet->pluginId() == m_pluginId) | ||
applets << applet; | ||
} | ||
} | ||
return applets; | ||
} | ||
|
||
DAppletBridge::DAppletBridge(const QString &pluginId, QObject *parent) | ||
: DAppletBridge(*new DAppletBridgePrivate(this), parent) | ||
{ | ||
d_func()->m_pluginId = pluginId; | ||
} | ||
|
||
DAppletBridge::DAppletBridge(DAppletBridgePrivate &dd, QObject *parent) | ||
: QObject(parent) | ||
, DObject(dd) | ||
{ | ||
} | ||
|
||
DAppletBridge::~DAppletBridge() | ||
{ | ||
} | ||
|
||
bool DAppletBridge::isValid() const | ||
{ | ||
D_DC(DAppletBridge); | ||
const auto plugin = DPluginLoader::instance()->plugin(d->m_pluginId); | ||
return plugin.isValid(); | ||
} | ||
|
||
QList<DAppletProxy *> DAppletBridge::applets() const | ||
{ | ||
D_DC(DAppletBridge); | ||
if (!isValid()) | ||
return {}; | ||
QList<DAppletProxy *> ret; | ||
for (const auto item : d->applets()) { | ||
if (auto proxy = item->d_func()->appletProxy()) { | ||
ret << proxy; | ||
} | ||
} | ||
return ret; | ||
} | ||
|
||
DAppletProxy *DAppletBridge::applet() const | ||
{ | ||
D_DC(DAppletBridge); | ||
if (!isValid()) | ||
return {}; | ||
for (const auto item : d->applets()) { | ||
if (auto proxy = item->d_func()->appletProxy()) { | ||
return proxy; | ||
} | ||
} | ||
return nullptr; | ||
} | ||
|
||
DS_END_NAMESPACE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd. | ||
// | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
#pragma once | ||
|
||
#include "dsglobal.h" | ||
#include "appletproxy.h" | ||
|
||
#include <QObject> | ||
#include <DObject> | ||
|
||
DS_BEGIN_NAMESPACE | ||
/** | ||
* @brief Interacting with other applets | ||
*/ | ||
class DAppletBridgePrivate; | ||
class DS_SHARE DAppletBridge : public QObject, public DTK_CORE_NAMESPACE::DObject | ||
{ | ||
Q_OBJECT | ||
D_DECLARE_PRIVATE(DAppletBridge) | ||
public: | ||
explicit DAppletBridge(const QString &pluginId, QObject *parent = nullptr); | ||
virtual ~DAppletBridge() override; | ||
|
||
bool isValid() const; | ||
|
||
QList<DAppletProxy *> applets() const; | ||
DAppletProxy *applet() const; | ||
|
||
protected: | ||
explicit DAppletBridge(DAppletBridgePrivate &dd, QObject *parent = nullptr); | ||
}; | ||
|
||
DS_END_NAMESPACE |
Oops, something went wrong.