#include "launcheritem.h"
struct LauncherItemPrivate {
    QString name;
    int id;
    int type;
    int index;
    int pageIndex = -1;
    QString icon;
    QString desktopFile;
    QList<int> categories;
    int location;
    int rowSpan;
    int columnSpan;
    int state = LauncherItem::Normal;
    bool editable = false;
    bool selected = false;
    bool appOpen = false;
    int windowId = -1;
    bool nameVisible = true;
    QAbstractListModel *model = nullptr;
    QString qmlFile;
    bool uninstallable = true;
};

LauncherItem::LauncherItem(QObject *parent)
    : QObject(parent)
    , p(new LauncherItemPrivate())
{

}

LauncherItem::LauncherItem(const LauncherItem &other)
    : LauncherItem(other.parent())
{
    this->setName(other.name());
    this->setId(other.id());
    this->setType(other.type());
    this->setPageIndex(other.pageIndex());
    this->setIcon(other.icon());
    this->setDesktopFile(other.desktopFile());
    this->setLocation(other.location());
    this->setRowSpan(other.rowSpan());
    this->setColumnSpan(other.columnSpan());
    this->setState(other.state());
    this->setEditable(other.editable());
    this->setSelected(other.selected());
    this->setAppOpen(other.appOpen());
    this->setWindowId(other.windowId());
}

LauncherItem::~LauncherItem()
{
    delete p;
}

LauncherItem &LauncherItem::operator=(const LauncherItem &other)
{
    this->setName(other.name());
    this->setId(other.id());
    this->setType(other.type());
    this->setPageIndex(other.pageIndex());
    this->setIcon(other.icon());
    this->setDesktopFile(other.desktopFile());
    this->setLocation(other.location());
    this->setRowSpan(other.rowSpan());
    this->setColumnSpan(other.columnSpan());
    this->setState(other.state());
    this->setEditable(other.editable());
    this->setSelected(other.selected());
    this->setAppOpen(other.appOpen());
    this->setWindowId(other.windowId());
    this->setNameVisible(other.nameVisible());
    this->setUninstallable(other.uninstallable());

    return *this;
}

QString LauncherItem::name() const
{
    return p->name;
}

void LauncherItem::setName(const QString &name)
{
    if (p->name != name) {
        p->name = name;
        Q_EMIT nameChanged();
    }
}

int LauncherItem::id() const
{
    return p->id;
}

void LauncherItem::setId(const int &id)
{
    if (p->id != id) {
        p->id = id;
        Q_EMIT idChanged();
    }
}

int LauncherItem::type() const
{
    return p->type;
}

void LauncherItem::setType(const int &type)
{
    if (p->type != type) {
        p->type = type;
        Q_EMIT typeChanged();
    }
}

int LauncherItem::pageIndex() const
{
    return p->pageIndex;
}

void LauncherItem::setPageIndex(const int &pageIndex)
{
    if (p->pageIndex != pageIndex) {
        p->pageIndex = pageIndex;
        Q_EMIT pageIndexChanged();
    }
}

QString LauncherItem::icon() const
{
    return p->icon;
}

void LauncherItem::setIcon(const QString &icon)
{
    if (p->icon != icon) {
        p->icon = icon;
        Q_EMIT iconChanged();
    }
}

QString LauncherItem::desktopFile() const
{
    return p->desktopFile;
}

void LauncherItem::setDesktopFile(const QString &desktopFile)
{
    if (p->desktopFile != desktopFile) {
        p->desktopFile = desktopFile;
        Q_EMIT desktopFileChanged();
    }
}

QList<int> LauncherItem::categories() const
{
    return p->categories;
}

void LauncherItem::setCategories(const QList<int> &categories)
{
    if (p->categories != categories) {
        p->categories = categories;
        Q_EMIT categoriesChanged();
    }
}

int LauncherItem::location() const
{
    return p->location;
}

void LauncherItem::setLocation(const int &location)
{
    if (p->location != location) {
        p->location = location;
        Q_EMIT locationChanged();
    }
}

int LauncherItem::rowSpan() const
{
    return p->rowSpan;
}

void LauncherItem::setRowSpan(const int &rowSpan)
{
    if (p->rowSpan != rowSpan) {
        p->rowSpan = rowSpan;
        Q_EMIT rowSpanChanged();
    }
}

int LauncherItem::columnSpan() const
{
    return p->columnSpan;
}

void LauncherItem::setColumnSpan(const int &columnSpan)
{
    if (p->columnSpan != columnSpan) {
        p->columnSpan = columnSpan;
        Q_EMIT columnSpanChanged();
    }
}

int LauncherItem::state() const
{
    return p->state;
}

void LauncherItem::setState(const int &state)
{
    if (p->state != state) {
        p->state = state;
        Q_EMIT stateChanged();
    }
}

bool LauncherItem::editable() const
{
    return p->editable;
}

void LauncherItem::setEditable(const bool &editable)
{
    if (p->editable != editable) {
        p->editable = editable;
        Q_EMIT editableChanged();
    }
}

bool LauncherItem::selected() const
{
    return (p->selected && p->state == LauncherItem::Selectable);
}

void LauncherItem::setSelected(bool selected)
{
    if (p->selected != selected && p->state == LauncherItem::Selectable) {
        p->selected = selected;
        Q_EMIT selectedChanged();
    }
}

bool LauncherItem::appOpen() const
{
    return p->appOpen;
}

void LauncherItem::setAppOpen(const bool &appOpen)
{
    if (p->appOpen != appOpen) {
        p->appOpen = appOpen;
        Q_EMIT appOpenChanged();
    }
}

int LauncherItem::windowId() const
{
    return p->windowId;
}
void LauncherItem::setWindowId(const int &windowId)
{
    if (p->windowId != windowId) {
        p->windowId = windowId;
        Q_EMIT windowIdChanged();
    }
}

bool LauncherItem::nameVisible() const
{
    return p->nameVisible;
}

void LauncherItem::setNameVisible(const bool &nameVisible)
{
    if (p->nameVisible != nameVisible) {
        p->nameVisible = nameVisible;
        Q_EMIT nameVisibleChanged();
    }
}

QAbstractListModel *LauncherItem::model() const
{
    return p->model;
}

void LauncherItem::setModel(QAbstractListModel *model)
{
    if (p->model != model) {
        p->model = model;
        Q_EMIT modelChanged();
    }
}

QString LauncherItem::qmlFile() const
{
    return p->qmlFile;
}

void LauncherItem::setQmlFile(const QString &qmlFile)
{
    if (p->qmlFile != qmlFile) {
        p->qmlFile = qmlFile;
        Q_EMIT qmlFileChanged();
    }
}

bool LauncherItem::uninstallable() const
{
    return  p->uninstallable;
}

void LauncherItem::setUninstallable(const bool &uninstallable)
{
    if (p->uninstallable != uninstallable) {
        p->uninstallable = uninstallable;
        Q_EMIT uninsatllableChanged();
    }
}
