/*
 * 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 Library General Public License as
 * published by the Free Software Foundation; either version 2, 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 Library General Public
 * License along with this program; if not, write to the
 * Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

#ifndef THUMBNAILITEM_H
#define THUMBNAILITEM_H

#include <QQuickItem>
#include <QQuickWindow>

#include "context.h"

class ThumbnailItem : public QQuickItem
{
    Q_OBJECT
    Q_PROPERTY(QString windowId READ windowId WRITE setWindowId NOTIFY windowIdChanged)
    Q_PROPERTY(QString outputId READ outputId WRITE setOutputId NOTIFY outputIdChanged)
    Q_PROPERTY(int thumbnailType READ thumbnailType WRITE setThumbnailType NOTIFY thumbnailTypeChanged)
    Q_PROPERTY(bool isActive READ isActive WRITE setActive NOTIFY isActiveChanged)

  public:
    explicit ThumbnailItem(QQuickItem *parent = nullptr);
    ~ThumbnailItem();

    QString windowId() const;
    void setWindowId(QString windowId);

    QString outputId() const;
    void setOutputId(QString outputId);

    int thumbnailType() { return m_thumbnailType; }
    void setThumbnailType(int type);
    bool isActive() { return m_active; }
    void setActive(bool active);

  signals:
    void windowIdChanged();
    void outputIdChanged();
    void thumbnailTypeChanged();
    void isActiveChanged();

  protected:
    QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *) override;

  private Q_SLOTS:
    void BufferImportDmabuf();
    void thumbnailIsDeleted();

  private:
    void active(bool active);

    class Private;
    Private *pri;
    Context *context = nullptr;
    Thumbnail *thumbnail = nullptr;
    int m_thumbnailType = 1;
    bool m_active = false;
    bool m_thumbnailIsDeleted = false;
    QString m_currentUuid;
    wl_display *m_display = nullptr;
};

#endif // ThumbnailItem_H
