#include "generalsetting.h"

CGeneralSetting::CGeneralSetting(QObject *parent) : QObject(parent),
    myState("none")
{

}

void CGeneralSetting::setCenterState(const QString &centerState)
{
    qDebug() << "CGeneralSetting::setCenterState" << centerState;
    if(myState != centerState){
        qDebug() << "emit centerStateChanged";
        myState = centerState;
        emit centerStateChanged(myState);
    }
}

void CGeneralSetting::openOnboard()
{
    if (!QDBusConnection::sessionBus().isConnected()) {
        qDebug()<<"Cannot connect to the D-Bus session bus.";
    }

    QDBusInterface iface("org.onboard.Onboard",
                         "/org/onboard/Onboard/Keyboard",
                         "org.onboard.Onboard.Keyboard",
                         QDBusConnection::sessionBus());

    if (iface.isValid())
    {
        iface.call("Show");
    }

}

void CGeneralSetting::openControlCenter(const QString &controlStr)
{
    qDebug() << "CGeneralSetting::openControlCenter()" << controlStr;
    controlCenter.runApplication(controlStr);
}

void CGeneralSetting::openControlCenterConfig(const QString &controlStr, const QStringList &config)
{
    qDebug() << "CGeneralSetting::openControlCenterConfig()" << controlStr << " " << config;
    controlCenter.runApplicationConfig(controlStr, config);
}

QString CGeneralSetting::getCenterState() const
{
    qDebug() << "CGeneralSetting::getCenterState()";
    return myState;
}

void CGeneralSetting::statePrint()
{
    qDebug() << "CGeneralSetting::statePrint()";
}

void CGeneralSetting::openGeneralSetting(const QString &str)
{
    qDebug() << "CGeneralSetting::openGeneralSetting" << str;
    if(str == "onboard"){
        openOnboard();
    }
    else if(str == "ukui-control-center.desktop"){
        openControlCenter(str);
    }
    else if(str == "ukui-control-center-u"){
        openControlCenterConfig("ukui-control-center.desktop",{"-m","userinfo"});
    }
}
