/*
 * This file was generated by qdbusxml2cpp-fix version 0.8
 * Command line was: qdbusxml2cpp-fix -c Entry -p generated/com_deepin_dde_daemon_dock_entry ../xml/com.deepin.dde.daemon.Dock.Entry.xml
 *
 * qdbusxml2cpp-fix is Copyright (C) 2016 Deepin Technology Co., Ltd.
 *
 * This is an auto-generated file.
 * This file may have been hand-edited. Look for HAND-EDIT comments
 * before re-generating it.
 */

#include "generated/com_deepin_dde_daemon_dock_entry.h"

/*
 * Implementation of interface class __Entry
 */

class __EntryPrivate
{
public:
   __EntryPrivate() = default;

    // begin member variables
    uint CurrentWindow;
    QString DesktopFile;
    QString Icon;
    QString Id;
    bool IsActive;
    bool IsDocked;
    QString Menu;
    QString Name;
    WindowInfoMap WindowInfos;

public:
    QMap<QString, QDBusPendingCallWatcher *> m_processingCalls;
    QMap<QString, QList<QVariant>> m_waittingCalls;
};

__Entry::__Entry(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent)
    : DBusExtendedAbstractInterface(service, path, staticInterfaceName(), connection, parent)
    , d_ptr(new __EntryPrivate)
{
    connect(this, &__Entry::propertyChanged, this, &__Entry::onPropertyChanged);

    if (QMetaType::type("WindowList") == QMetaType::UnknownType)
        registerWindowListMetaType();
    if (QMetaType::type("WindowInfoMap") == QMetaType::UnknownType)
        registerWindowInfoMapMetaType();
}

__Entry::~__Entry()
{
    qDeleteAll(d_ptr->m_processingCalls.values());
    delete d_ptr;
}

void __Entry::onPropertyChanged(const QString &propName, const QVariant &value)
{
    if (propName == QStringLiteral("CurrentWindow"))
    {
        const uint &CurrentWindow = qvariant_cast<uint>(value);
        if (d_ptr->CurrentWindow != CurrentWindow)
        {
            d_ptr->CurrentWindow = CurrentWindow;
            Q_EMIT CurrentWindowChanged(d_ptr->CurrentWindow);
        }
        return;
    }

    if (propName == QStringLiteral("DesktopFile"))
    {
        const QString &DesktopFile = qvariant_cast<QString>(value);
        if (d_ptr->DesktopFile != DesktopFile)
        {
            d_ptr->DesktopFile = DesktopFile;
            Q_EMIT DesktopFileChanged(d_ptr->DesktopFile);
        }
        return;
    }

    if (propName == QStringLiteral("Icon"))
    {
        const QString &Icon = qvariant_cast<QString>(value);
        if (d_ptr->Icon != Icon)
        {
            d_ptr->Icon = Icon;
            Q_EMIT IconChanged(d_ptr->Icon);
        }
        return;
    }

    if (propName == QStringLiteral("Id"))
    {
        const QString &Id = qvariant_cast<QString>(value);
        if (d_ptr->Id != Id)
        {
            d_ptr->Id = Id;
            Q_EMIT IdChanged(d_ptr->Id);
        }
        return;
    }

    if (propName == QStringLiteral("IsActive"))
    {
        const bool &IsActive = qvariant_cast<bool>(value);
        if (d_ptr->IsActive != IsActive)
        {
            d_ptr->IsActive = IsActive;
            Q_EMIT IsActiveChanged(d_ptr->IsActive);
        }
        return;
    }

    if (propName == QStringLiteral("IsDocked"))
    {
        const bool &IsDocked = qvariant_cast<bool>(value);
        if (d_ptr->IsDocked != IsDocked)
        {
            d_ptr->IsDocked = IsDocked;
            Q_EMIT IsDockedChanged(d_ptr->IsDocked);
        }
        return;
    }

    if (propName == QStringLiteral("Menu"))
    {
        const QString &Menu = qvariant_cast<QString>(value);
        if (d_ptr->Menu != Menu)
        {
            d_ptr->Menu = Menu;
            Q_EMIT MenuChanged(d_ptr->Menu);
        }
        return;
    }

    if (propName == QStringLiteral("Name"))
    {
        const QString &Name = qvariant_cast<QString>(value);
        if (d_ptr->Name != Name)
        {
            d_ptr->Name = Name;
            Q_EMIT NameChanged(d_ptr->Name);
        }
        return;
    }

    if (propName == QStringLiteral("WindowInfos"))
    {
        const WindowInfoMap &WindowInfos = qvariant_cast<WindowInfoMap>(value);
        if (d_ptr->WindowInfos != WindowInfos)
        {
            d_ptr->WindowInfos = WindowInfos;
            Q_EMIT WindowInfosChanged(d_ptr->WindowInfos);
        }
        return;
    }

    qWarning() << "property not handle: " << propName;
    return;
}

uint __Entry::currentWindow()
{
    return qvariant_cast<uint>(internalPropGet("CurrentWindow", &d_ptr->CurrentWindow));
}

QString __Entry::desktopFile()
{
    return qvariant_cast<QString>(internalPropGet("DesktopFile", &d_ptr->DesktopFile));
}

QString __Entry::icon()
{
    return qvariant_cast<QString>(internalPropGet("Icon", &d_ptr->Icon));
}

QString __Entry::id()
{
    return qvariant_cast<QString>(internalPropGet("Id", &d_ptr->Id));
}

bool __Entry::isActive()
{
    return qvariant_cast<bool>(internalPropGet("IsActive", &d_ptr->IsActive));
}

bool __Entry::isDocked()
{
    return qvariant_cast<bool>(internalPropGet("IsDocked", &d_ptr->IsDocked));
}

QString __Entry::menu()
{
    return qvariant_cast<QString>(internalPropGet("Menu", &d_ptr->Menu));
}

QString __Entry::name()
{
    return qvariant_cast<QString>(internalPropGet("Name", &d_ptr->Name));
}

WindowInfoMap __Entry::windowInfos()
{
    return qvariant_cast<WindowInfoMap>(internalPropGet("WindowInfos", &d_ptr->WindowInfos));
}

void __Entry::CallQueued(const QString &callName, const QList<QVariant> &args)
{
    if (d_ptr->m_waittingCalls.contains(callName))
    {
        d_ptr->m_waittingCalls[callName] = args;
        return;
    }
    if (d_ptr->m_processingCalls.contains(callName))
    {
        d_ptr->m_waittingCalls.insert(callName, args);
    } else {
        QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(asyncCallWithArgumentList(callName, args));
        connect(watcher, &QDBusPendingCallWatcher::finished, this, &__Entry::onPendingCallFinished);
        d_ptr->m_processingCalls.insert(callName, watcher);
    }
}

void __Entry::onPendingCallFinished(QDBusPendingCallWatcher *w)
{
    w->deleteLater();
    const auto callName = d_ptr->m_processingCalls.key(w);
    Q_ASSERT(!callName.isEmpty());
    if (callName.isEmpty())
        return;
    d_ptr->m_processingCalls.remove(callName);
    if (!d_ptr->m_waittingCalls.contains(callName))
        return;
    const auto args = d_ptr->m_waittingCalls.take(callName);
    CallQueued(callName, args);
}
