/*
 * Peony-Qt
 *
 * Copyright (C) 2024, KylinSoft Co., Ltd.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 *
 * Authors: yangyanwei <yangyanwei@kylinos.cn>
 *
 */

#ifndef DESKTOPWINDOWMANAGER_H
#define DESKTOPWINDOWMANAGER_H

#include <QObject>
#include <QList>
#include <QScreen>
#include <QMap>
#include <QTimeLine>
#include <QDBusInterface>
class DesktopBackgroundWindow;
class AdvancedDesktopIconView;
class FileActionController;
class GlobalSettingsAdapter;
class BackgroundManager;
class QPoint;
class QQuickView;
namespace  Peony {
class AdvancedDesktopItemModel;
class DesktopItemProxyModel;
class PeonyDbusService;
}
class DesktopWindowManager : public QObject
{
   Q_OBJECT
public:
    explicit DesktopWindowManager(QObject *parent = nullptr);
    ~DesktopWindowManager();

    static DesktopWindowManager *getInstance();
    QPoint postion(const QString &uri);
    QMap<QString, QPoint> getAllItemPos(const QStringList &uris);
    void createIdAndPos(int *id, QPoint *pos);
    void markCreateFilePos(const QPoint &pos);

    void initializeWithScreens();

public Q_SLOTS:
    void addQmlDesktop(QScreen *screen);
    void switchDisplayMode();
    void singleScreenMode();
    void multiscreenMode();

    void relocateIconView();

    void initModelFinish();
    void raiseWid();
    void layoutViewItems();
    void clearAllRestoreInfo();
    void fileCreated(int id, const QString &uri);
    void setInfoPos(const QString &uri);
    Q_INVOKABLE void startInitAnima();
    Q_INVOKABLE bool getLockState();
    Q_INVOKABLE bool getQuickStartAvailable();
private:
    void registerCppTypeToQml();
    void initializeWindowView(QQuickView *window);
    void setupWindowConnections(QQuickView* window);
    void initPeonyDbusService();

Q_SIGNALS:
    void emitFinish();
    void setSortType(int sortType);
    void setSortOrder(int sortOrder);
    void modeChanged();
    void startInitAnimaRequest();
private:
    Peony::AdvancedDesktopItemModel *m_model = nullptr;
    QDBusInterface *m_dbusInterface = nullptr;
    QPoint m_markMousePressPos = QPoint(-1, -1);
    int m_markMousePressId = 0;
    bool m_initMetaInfo = false;
    bool m_desktopAutoLayout = false;
    Peony::PeonyDbusService *m_peonyDbusService = nullptr;
    QTimeLine *m_layoutTimeLine = nullptr;
    QTimeLine *m_modeTimeLine = nullptr;
    bool hasUnlockAnima = false;
    bool isQuickStartAvailable = false;
};

#define DESKTOP_MANAGER DesktopWindowManager::getInstance()

#endif // DESKTOPWINDOWMANAGER_H
