/*
 * This file was generated by qdbusxml2cpp-fix version 0.8
 * Command line was: qdbusxml2cpp-fix -c Updater -p generated/com_deepin_lastore_updater ../xml/com.deepin.lastore.Updater.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_lastore_updater.h"

/*
 * Implementation of interface class __Updater
 */

class __UpdaterPrivate
{
public:
   __UpdaterPrivate() = default;

    // begin member variables
    bool AutoCheckUpdates;
    bool AutoDownloadUpdates;
    qulonglong AutoInstallUpdateType;
    bool AutoInstallUpdates;
    LastoreUpdatePackagesInfo ClassifiedUpdatablePackages;
    QString MirrorSource;
    QStringList UpdatableApps;
    QStringList UpdatablePackages;
    bool UpdateNotify;

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

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

    if (QMetaType::type("AppUpdateInfoList") == QMetaType::UnknownType)
        registerAppUpdateInfoListMetaType();
    if (QMetaType::type("MirrorInfoList") == QMetaType::UnknownType)
        registerMirrorInfoListMetaType();
    if (QMetaType::type("LastoreUpdatePackagesInfo") == QMetaType::UnknownType)
        registerLastoreUpdatePackagesInfoMetaType();
}

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

void __Updater::onPropertyChanged(const QString &propName, const QVariant &value)
{
    if (propName == QStringLiteral("AutoCheckUpdates"))
    {
        const bool &AutoCheckUpdates = qvariant_cast<bool>(value);
        if (d_ptr->AutoCheckUpdates != AutoCheckUpdates)
        {
            d_ptr->AutoCheckUpdates = AutoCheckUpdates;
            Q_EMIT AutoCheckUpdatesChanged(d_ptr->AutoCheckUpdates);
        }
        return;
    }

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

    if (propName == QStringLiteral("AutoInstallUpdateType"))
    {
        const qulonglong &AutoInstallUpdateType = qvariant_cast<qulonglong>(value);
        if (d_ptr->AutoInstallUpdateType != AutoInstallUpdateType)
        {
            d_ptr->AutoInstallUpdateType = AutoInstallUpdateType;
            Q_EMIT AutoInstallUpdateTypeChanged(d_ptr->AutoInstallUpdateType);
        }
        return;
    }

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

    if (propName == QStringLiteral("ClassifiedUpdatablePackages"))
    {
        const LastoreUpdatePackagesInfo &ClassifiedUpdatablePackages = qvariant_cast<LastoreUpdatePackagesInfo>(value);
        if (d_ptr->ClassifiedUpdatablePackages != ClassifiedUpdatablePackages)
        {
            d_ptr->ClassifiedUpdatablePackages = ClassifiedUpdatablePackages;
            Q_EMIT ClassifiedUpdatablePackagesChanged(d_ptr->ClassifiedUpdatablePackages);
        }
        return;
    }

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

    if (propName == QStringLiteral("UpdatableApps"))
    {
        const QStringList &UpdatableApps = qvariant_cast<QStringList>(value);
        if (d_ptr->UpdatableApps != UpdatableApps)
        {
            d_ptr->UpdatableApps = UpdatableApps;
            Q_EMIT UpdatableAppsChanged(d_ptr->UpdatableApps);
        }
        return;
    }

    if (propName == QStringLiteral("UpdatablePackages"))
    {
        const QStringList &UpdatablePackages = qvariant_cast<QStringList>(value);
        if (d_ptr->UpdatablePackages != UpdatablePackages)
        {
            d_ptr->UpdatablePackages = UpdatablePackages;
            Q_EMIT UpdatablePackagesChanged(d_ptr->UpdatablePackages);
        }
        return;
    }

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

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

bool __Updater::autoCheckUpdates()
{
    return qvariant_cast<bool>(internalPropGet("AutoCheckUpdates", &d_ptr->AutoCheckUpdates));
}

bool __Updater::autoDownloadUpdates()
{
    return qvariant_cast<bool>(internalPropGet("AutoDownloadUpdates", &d_ptr->AutoDownloadUpdates));
}

qulonglong __Updater::autoInstallUpdateType()
{
    return qvariant_cast<qulonglong>(internalPropGet("AutoInstallUpdateType", &d_ptr->AutoInstallUpdateType));
}

bool __Updater::autoInstallUpdates()
{
    return qvariant_cast<bool>(internalPropGet("AutoInstallUpdates", &d_ptr->AutoInstallUpdates));
}

void __Updater::setAutoInstallUpdates(bool value)
{

   internalPropSet("AutoInstallUpdates", QVariant::fromValue(value), &d_ptr->AutoInstallUpdates);
}

LastoreUpdatePackagesInfo __Updater::classifiedUpdatablePackages()
{
    return qvariant_cast<LastoreUpdatePackagesInfo>(internalPropGet("ClassifiedUpdatablePackages", &d_ptr->ClassifiedUpdatablePackages));
}

QString __Updater::mirrorSource()
{
    return qvariant_cast<QString>(internalPropGet("MirrorSource", &d_ptr->MirrorSource));
}

QStringList __Updater::updatableApps()
{
    return qvariant_cast<QStringList>(internalPropGet("UpdatableApps", &d_ptr->UpdatableApps));
}

QStringList __Updater::updatablePackages()
{
    return qvariant_cast<QStringList>(internalPropGet("UpdatablePackages", &d_ptr->UpdatablePackages));
}

bool __Updater::updateNotify()
{
    return qvariant_cast<bool>(internalPropGet("UpdateNotify", &d_ptr->UpdateNotify));
}

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

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