// SPDX-FileCopyrightText: 2021 - 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

#ifndef WORKSPACE_H
#define WORKSPACE_H

#include "dfmplugin_workspace_global.h"

#include <dfm-framework/dpf.h>

namespace dfmplugin_workspace {

class Workspace : public dpf::Plugin
{
    Q_OBJECT
    Q_PLUGIN_METADATA(IID "org.deepin.plugin.filemanager" FILE "workspace.json")

    DPF_EVENT_NAMESPACE(DPWORKSPACE_NAMESPACE)

    // signal events
    DPF_EVENT_REG_SIGNAL(signal_View_SelectionChanged)
    DPF_EVENT_REG_SIGNAL(signal_View_RenameStartEdit)
    DPF_EVENT_REG_SIGNAL(signal_View_RenameEndEdit)
    DPF_EVENT_REG_SIGNAL(signal_View_ItemClicked)
    DPF_EVENT_REG_SIGNAL(signal_View_HeaderViewSectionChanged)
    DPF_EVENT_REG_SIGNAL(signal_Model_EmptyDir)

    DPF_EVENT_REG_SIGNAL(signal_ReportLog_MenuData)
    DPF_EVENT_REG_SIGNAL(signal_ReportLog_Commit)

    // slot events
    DPF_EVENT_REG_SLOT(slot_RegisterFocusFileViewDisabled)
    DPF_EVENT_REG_SLOT(slot_RegisterFileView)
    DPF_EVENT_REG_SLOT(slot_RegisterMenuScene)
    DPF_EVENT_REG_SLOT(slot_FindMenuScene)
    DPF_EVENT_REG_SLOT(slot_RegisterCustomTopWidget)
    DPF_EVENT_REG_SLOT(slot_RegisterViewHint)
    DPF_EVENT_REG_SLOT(slot_RegisterGroupStrategy)
    DPF_EVENT_REG_SLOT(slot_RegisteredGroupStrategies)
    DPF_EVENT_REG_SLOT(slot_ShowCustomTopWidget)
    DPF_EVENT_REG_SLOT(slot_GetCustomTopWidgetVisible)
    DPF_EVENT_REG_SLOT(slot_CheckSchemeViewIsFileView)
    DPF_EVENT_REG_SLOT(slot_RefreshDir)

    DPF_EVENT_REG_SLOT(slot_View_SetCustomViewProperty)
    DPF_EVENT_REG_SLOT(slot_View_GetVisualGeometry)
    DPF_EVENT_REG_SLOT(slot_View_GetViewItemRect)
    DPF_EVENT_REG_SLOT(slot_View_GetCurrentViewMode)
    DPF_EVENT_REG_SLOT(slot_View_GetDefaultViewMode)
    DPF_EVENT_REG_SLOT(slot_View_GetSelectedUrls)
    DPF_EVENT_REG_SLOT(slot_View_SelectFiles)
    DPF_EVENT_REG_SLOT(slot_View_SelectAll)
    DPF_EVENT_REG_SLOT(slot_View_ReverseSelect)
    DPF_EVENT_REG_SLOT(slot_View_SetSelectionMode)
    DPF_EVENT_REG_SLOT(slot_View_SetEnabledSelectionModes)
    DPF_EVENT_REG_SLOT(slot_View_SetDragEnabled)
    DPF_EVENT_REG_SLOT(slot_View_SetDragDropMode)
    DPF_EVENT_REG_SLOT(slot_View_ClosePersistentEditor)
    DPF_EVENT_REG_SLOT(slot_View_SetReadOnly)
    DPF_EVENT_REG_SLOT(slot_View_SetFilter)
    DPF_EVENT_REG_SLOT(slot_View_GetFilter)
    DPF_EVENT_REG_SLOT(slot_View_SetAlwaysOpenInCurrentWindow)
    DPF_EVENT_REG_SLOT(slot_View_AboutToChangeViewWidth)
    DPF_EVENT_REG_SLOT(slot_View_GetColumnWidth)

    DPF_EVENT_REG_SLOT(slot_Model_SetCustomFilterData)
    DPF_EVENT_REG_SLOT(slot_Model_SetCustomFilterCallback)
    DPF_EVENT_REG_SLOT(slot_Model_RegisterRoutePrehandle)
    DPF_EVENT_REG_SLOT(slot_Model_SetNameFilter)
    DPF_EVENT_REG_SLOT(slot_Model_GetNameFilter)
    DPF_EVENT_REG_SLOT(slot_Model_FileUpdate)
    DPF_EVENT_REG_SLOT(slot_Model_CurrentSortRole)
    DPF_EVENT_REG_SLOT(slot_Model_ColumnDisplayName)
    DPF_EVENT_REG_SLOT(slot_Model_ColumnRoles)
    DPF_EVENT_REG_SLOT(slot_Model_SetSort)
    DPF_EVENT_REG_SLOT(slot_Model_CurrentGroupStrategy)
    DPF_EVENT_REG_SLOT(slot_Model_SetGroup)
    DPF_EVENT_REG_SLOT(slot_Model_RegisterDataCache)
    DPF_EVENT_REG_SLOT(slot_Model_RegisterLoadStrategy)
    DPF_EVENT_REG_SLOT(slot_Model_GetCurrentBusy)

    // hook events
    DPF_EVENT_REG_HOOK(hook_SendOpenWindow)
    DPF_EVENT_REG_HOOK(hook_SendChangeCurrentUrl)
    DPF_EVENT_REG_HOOK(hook_Allow_Repeat_Url)

    DPF_EVENT_REG_HOOK(hook_DragDrop_CheckDragDropAction)
    DPF_EVENT_REG_HOOK(hook_DragDrop_FileDragMove)
    DPF_EVENT_REG_HOOK(hook_DragDrop_FileDrop)
    DPF_EVENT_REG_HOOK(hook_DragDrop_IsDrop)
    DPF_EVENT_REG_HOOK(hook_DragDrop_FileCanMove)

    DPF_EVENT_REG_HOOK(hook_ShortCut_CopyFiles)
    DPF_EVENT_REG_HOOK(hook_ShortCut_CopyFilePath)
    DPF_EVENT_REG_HOOK(hook_ShortCut_CutFiles)
    DPF_EVENT_REG_HOOK(hook_ShortCut_PasteFiles)
    DPF_EVENT_REG_HOOK(hook_ShortCut_DeleteFiles)
    DPF_EVENT_REG_HOOK(hook_ShortCut_MoveToTrash)
    DPF_EVENT_REG_HOOK(hook_ShortCut_EnterPressed)
    DPF_EVENT_REG_HOOK(hook_ShortCut_PreViewFiles)

    DPF_EVENT_REG_HOOK(hook_Delegate_PaintListItem)
    DPF_EVENT_REG_HOOK(hook_Delegate_LayoutText)
    DPF_EVENT_REG_HOOK(hook_Delegate_CheckTransparent)

    DPF_EVENT_REG_HOOK(hook_View_FetchSupportSelectionModes)

    DPF_EVENT_REG_HOOK(hook_Model_FetchCustomColumnRoles)
    DPF_EVENT_REG_HOOK(hook_Model_FetchCustomRoleDisplayName)

    DPF_EVENT_REG_HOOK(hook_Url_FetchPathtoVirtual)

public:
    virtual void initialize() override;
    virtual bool start() override;

signals:
    void readyToInstallWidget(const quint64);

private slots:
    void onWindowOpened(quint64 windId);
    void onWindowClosed(quint64 winId);

private:
    void initConfig();

    static void saveRemoteThumbnailToConf(const QVariant &var);
    static void syncRemoteThumbnailToAppSet(const QString &, const QString &, const QVariant &var);
    static bool isRemoteThumbnailConfEqual(const QVariant &dcon, const QVariant &dset);

    static void saveIconSizeToConf(const QVariant &var);
    static void syncIconSizeToAppSet(const QString &, const QString &, const QVariant &var);
    static bool isIconSizeConfEqual(const QVariant &dcon, const QVariant &dset);

    static void saveGridDensityToConf(const QVariant &var);
    static void syncGridDensityToAppSet(const QString &, const QString &, const QVariant &var);
    static bool isGridDensityConfEqual(const QVariant &dcon, const QVariant &dset);

    static void saveListHeightToConf(const QVariant &var);
    static void syncListHeightToAppSet(const QString &, const QString &, const QVariant &var);
    static bool isListHeightConfEqual(const QVariant &dcon, const QVariant &dset);
};

}

#endif   // WORKSPACE_H
