/*
 * This file was generated by qdbusxml2cpp-fix version 0.8
 * Command line was: qdbusxml2cpp-fix -c Grub2 -p generated/com_deepin_daemon_grub2 ../xml/com.deepin.daemon.Grub2.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_daemon_grub2.h"

/*
 * Implementation of interface class __Grub2
 */

class __Grub2Private
{
public:
   __Grub2Private() = default;

    // begin member variables
    QString DefaultEntry;
    bool EnableTheme;
    QString Resolution;
    QString Theme;
    uint Timeout;
    bool Updating;

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

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

}

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

void __Grub2::onPropertyChanged(const QString &propName, const QVariant &value)
{
    if (propName == QStringLiteral("DefaultEntry"))
    {
        const QString &DefaultEntry = qvariant_cast<QString>(value);
        if (d_ptr->DefaultEntry != DefaultEntry)
        {
            d_ptr->DefaultEntry = DefaultEntry;
            Q_EMIT DefaultEntryChanged(d_ptr->DefaultEntry);
        }
        return;
    }

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

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

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

    if (propName == QStringLiteral("Timeout"))
    {
        const uint &Timeout = qvariant_cast<uint>(value);
        if (d_ptr->Timeout != Timeout)
        {
            d_ptr->Timeout = Timeout;
            Q_EMIT TimeoutChanged(d_ptr->Timeout);
        }
        return;
    }

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

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

QString __Grub2::defaultEntry()
{
    return qvariant_cast<QString>(internalPropGet("DefaultEntry", &d_ptr->DefaultEntry));
}

bool __Grub2::enableTheme()
{
    return qvariant_cast<bool>(internalPropGet("EnableTheme", &d_ptr->EnableTheme));
}

QString __Grub2::resolution()
{
    return qvariant_cast<QString>(internalPropGet("Resolution", &d_ptr->Resolution));
}

QString __Grub2::theme()
{
    return qvariant_cast<QString>(internalPropGet("Theme", &d_ptr->Theme));
}

uint __Grub2::timeout()
{
    return qvariant_cast<uint>(internalPropGet("Timeout", &d_ptr->Timeout));
}

bool __Grub2::updating()
{
    return qvariant_cast<bool>(internalPropGet("Updating", &d_ptr->Updating));
}

void __Grub2::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, &__Grub2::onPendingCallFinished);
        d_ptr->m_processingCalls.insert(callName, watcher);
    }
}

void __Grub2::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);
}
