Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: [gui/detailspace] WindowManager init function and detailspace plugin #2040

Merged
merged 2 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/dfm-gui/windowmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class WindowManager : public QObject
using Handle = QPointer<Panel>;

static WindowManager *instance();
void initialize();
QSharedPointer<QQmlEngine> engine() const;

Handle createWindow(const QUrl &url, const QString &pluginName,
Expand Down
1 change: 1 addition & 0 deletions src/apps/dde-file-manager/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ static bool initQmlEngine()
globalEngine->addImportPath(DFM_QML_MODULE);
#endif

dfmgui::WindowManager::instance()->initialize();
return true;
}

Expand Down
65 changes: 43 additions & 22 deletions src/dfm-gui/windowmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,29 @@ WindowManagerPrivate::WindowManagerPrivate(WindowManager *q)
{
}

/*!
* \brief 注册标识为 \a uri 的 QML 模块信息
* 此函数单独抽离,由于 QtCreator 对 std::call_once 结构下识别不佳,不能有效通过 @uri 识别注册模块。
*/
void WindowManagerPrivate::registerType(const char *uri)
{
// 注册,使用 @uri ... 标记,以在 QtCreator 中方便访问
// @uri org.dfm.base
qmlRegisterModule(uri, 1, 0);
qmlRegisterUncreatableType<Applet>(uri, 1, 0, "Applet", "Applet attached");
qmlRegisterExtendedType<Applet, AppletAttached>(uri, 1, 0, "Applet");
qmlRegisterUncreatableType<Containment>(uri, 1, 0, "Containment", "Containment attached");
qmlRegisterExtendedType<Containment, ContainmentAttached>(uri, 1, 0, "Containment");
qmlRegisterUncreatableType<Panel>(uri, 1, 0, "Panel", "Panel attached");
qmlRegisterExtendedType<Panel, PanelAttached>(uri, 1, 0, "Panel");
qmlRegisterType<AppletItem>(uri, 1, 0, "AppletItem");
qmlRegisterType<ContainmentItem>(uri, 1, 0, "ContainmentItem");

// 工具类,生命周期由 WindowManager 管理
QuickUtils *globalUtils = new QuickUtils(q_ptr);
qmlRegisterSingletonInstance<QuickUtils>(uri, 1, 0, "QuickUtils", globalUtils);
}

WindowManager::Handle WindowManagerPrivate::createQuickWindow(const QString &pluginName, const QString &quickId, const QVariantMap &var)
{
// 首次进入初始化
Expand Down Expand Up @@ -252,28 +275,6 @@ void WindowManagerPrivate::aboutToQuit()
WindowManager::WindowManager()
: dptr(new WindowManagerPrivate(this))
{
// 注册,使用 @uri ... 标记,以在 QtCreator 中方便访问
// @uri org.dfm.base
const char *uri { "org.dfm.base" };
qmlRegisterModule(uri, 1, 0);
qmlRegisterUncreatableType<Applet>(uri, 1, 0, "Applet", "Applet attached");
qmlRegisterExtendedType<Applet, AppletAttached>(uri, 1, 0, "Applet");
qmlRegisterUncreatableType<Containment>(uri, 1, 0, "Containment", "Containment attached");
qmlRegisterExtendedType<Containment, ContainmentAttached>(uri, 1, 0, "Containment");
qmlRegisterUncreatableType<Panel>(uri, 1, 0, "Panel", "Panel attached");
qmlRegisterExtendedType<Panel, PanelAttached>(uri, 1, 0, "Panel");
qmlRegisterType<AppletItem>(uri, 1, 0, "AppletItem");
qmlRegisterType<ContainmentItem>(uri, 1, 0, "ContainmentItem");

// 工具类,生命周期由 WindowManager 管理
QuickUtils *globalUtils = new QuickUtils(this);
qmlRegisterSingletonInstance<QuickUtils>(uri, 1, 0, "QuickUtils", globalUtils);

// 退出时清理界面和 QQmlengine
connect(qApp, &QCoreApplication::aboutToQuit, this, [this]() {
Q_D(WindowManager);
d->aboutToQuit();
});
}

WindowManager::~WindowManager() { }
Expand All @@ -284,6 +285,23 @@ WindowManager *WindowManager::instance()
return &manager;
}

/*!
* \return 初始化界面管理,仅会执行一次,执行 `org.dfm.base` QML 模块的注册,以及关键信号的关联
*/
void WindowManager::initialize()
{
static std::once_flag flag;
std::call_once(flag, [this]() {
d_func()->registerType("org.dfm.base");

// 退出时清理界面和 QQmlengine
connect(qApp, &QCoreApplication::aboutToQuit, this, [this]() {
Q_D(WindowManager);
d->aboutToQuit();
});
});
}

/*!
* \brief 返回当前界面使用的全局 QQmlEngine , 可用于对 QQmlEngine 进行初始化设置。
* \warning 不要持久化保留此函数返回的指针,当 qApp 抛出 aboutToQuit() 信号时,会释放此
Expand All @@ -304,6 +322,9 @@ QSharedPointer<QQmlEngine> WindowManager::engine() const
* \brief 根据传入的插件 \a pluginName 和组件 \a quickId 信息查找并创建对应的主窗体,\a var 为初始化时传递给主窗体组件的参数,
* 创建的窗口会被当前管理类保留管理.
* \return 创建的 QQuickWindow 和 Panel,无法创建返回空的 Handle
*
* \warning 主窗口对应的 Qml 组件会立即加载,子 Applet 是异步加载的,所以在默认初始化的流程中,不使用旧版框架中 findWindowId() 这类
* 接口
*/
WindowManager::Handle WindowManager::createWindow(const QUrl &url, const QString &pluginName,
const QString &quickId, const QVariantMap &var)
Expand Down
2 changes: 2 additions & 0 deletions src/dfm-gui/windowmanager_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class WindowManagerPrivate
explicit WindowManagerPrivate(WindowManager *q);
~WindowManagerPrivate() = default;

void registerType(const char *uri);

WindowManager::Handle createQuickWindow(const QString &pluginName, const QString &quickId, const QVariantMap &var);
void connectWindowHandle(const WindowManager::Handle &handle);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ target_include_directories(${PROJECT_NAME}

target_link_libraries(${PROJECT_NAME}
DFM::base
DFM::gui
DFM::framework
${DtkWidget_LIBRARIES}
)
Expand Down
30 changes: 0 additions & 30 deletions src/plugins/filemanager/core/dfmplugin-detailspace/DetailSpace.qml

This file was deleted.

34 changes: 34 additions & 0 deletions src/plugins/filemanager/core/dfmplugin-detailspace/detailspace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,51 @@
#include "detailspace.h"
#include "utils/detailspacehelper.h"
#include "events/detailspaceeventreceiver.h"
#include "detailspacecontainment.h"
#include "model/quickfilebaseinfomodel.h"

#include <dfm-base/widgets/filemanagerwindowsmanager.h>

#include <dfm-gui/windowmanager.h>
#include <dfm-gui/appletfactory.h>

#include <QQmlEngine>

namespace dfmplugin_detailspace {
DFM_LOG_REISGER_CATEGORY(DPDETAILSPACE_NAMESPACE)
DFMBASE_USE_NAMESPACE

static constexpr char kAppletUrl[] { "org.dfm.detailspace" };

static dfmgui::Applet *createDetailSpaceApplet(const QString &url, dfmgui::Containment *parent, QString *errorString)
{
if (kAppletUrl == url) {
Q_ASSERT_X(parent && parent->flags().testFlag(dfmgui::Applet::kPanel),
"Create detailspace applet", "Parent must based on panel");

auto detailSpace = new DetailSpaceContainment(parent);
QObject::connect(parent, &dfmgui::Applet::currentUrlChanged, detailSpace, &DetailSpaceContainment::setCurrentUrl);
return detailSpace;
}
return nullptr;
}

void DetailSpace::initialize()
{
connect(&FMWindowsIns, &FileManagerWindowsManager::windowClosed, this, &DetailSpace::onWindowClosed, Qt::DirectConnection);
DetailSpaceEventReceiver::instance().connectService();

// 注册插件使用模块组件
// @uri org.dfm.detailspace
const char *uri = "org.dfm.detailspace";
qmlRegisterType<QuickFileBaseInfoModel>(uri, 1, 0, "BaseFileInfoModel");

QString errorString;
bool ret = dfmgui::AppletFactory::instance()->regCreator(
kAppletUrl, &createDetailSpaceApplet, &errorString);
if (!ret) {
fmWarning() << QString("Register applet %1 failed.").arg(kAppletUrl) << errorString;
}
}

bool DetailSpace::start()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
],
"Quick": [
{
"Url" : "DetailSpace.qml",
"Url" : "qml/DetailSpace.qml",
"Id" : "detailspace",
"Parent" : "dfmplugin-core.filewindow"
"Parent" : "dfmplugin-core.filewindow",
"Applet" : "org.dfm.detailspace"
}
]
}
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

#include "detailspacecontainment.h"

#include <dfm-base/interfaces/fileinfo.h>
#include <dfm-base/base/schemefactory.h>
#include <dfm-base/utils/thumbnail/thumbnailhelper.h>

#include <dfm-framework/event/event.h>

DFMBASE_USE_NAMESPACE

namespace dfmplugin_detailspace {

DetailSpaceContainment::DetailSpaceContainment(QObject *parent)
: dfmgui::Containment(parent)
{
}

bool DetailSpaceContainment::detailVisible() const

Check warning on line 22 in src/plugins/filemanager/core/dfmplugin-detailspace/detailspacecontainment.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'detailVisible' is never used.
{
return visibleFlag;
}

void DetailSpaceContainment::setDetailVisible(bool b)

Check warning on line 27 in src/plugins/filemanager/core/dfmplugin-detailspace/detailspacecontainment.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'setDetailVisible' is never used.
{
if (visibleFlag != b) {
visibleFlag = b;
Q_EMIT detailVisibleChanged(b);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

#ifndef DETAILSPACECONTAINMENT_H
#define DETAILSPACECONTAINMENT_H

#include <QObject>

#include <dfm-gui/containment.h>

namespace dfmplugin_detailspace {

class DetailSpaceContainment : public dfmgui::Containment
{
Q_OBJECT

Q_PROPERTY(bool detailVisible READ detailVisible WRITE setDetailVisible NOTIFY detailVisibleChanged FINAL)

public:
explicit DetailSpaceContainment(QObject *parent = nullptr);

bool detailVisible() const;
void setDetailVisible(bool b);
Q_SIGNAL void detailVisibleChanged(bool b);

private:
bool visibleFlag { false };
QString curIconName;
};

}

#endif // DETAILSPACECONTAINMENT_H
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ enum DetailFilterType {
kFileInterviewTimeField = 1 << 7,
kFileChangeTimeField = 1 << 8
};
Q_ENUM_NS(DetailFilterType)
Q_FLAG_NS(DetailFilterType)

// TODO: try remove it
enum BasicFieldExpandEnum : int {
kNotAll,
kFileName,
Expand Down
Loading
Loading