#include "gsettings_monitor.h"
#include "horizontalorverticalmode.h"
#include "ukui_settings_monitor.h"
#include "QTimer"
UkuiSettingsMonitor::UkuiSettingsMonitor()
{
    d_ptrGsetting = new GsettingsMonitor();
    d_ptrDbus = new HorizontalOrVerticalMode();

    connect(d_ptrGsetting, &GsettingsMonitor::transparencyUpdate, this, &UkuiSettingsMonitor::transparencyUpdate);
    connect(d_ptrGsetting, &GsettingsMonitor::styleStatusUpdate, this, [=](GsettingsMonitor::StyleStatus status){
        emit styleStatusUpdate(StyleStatus(status));
    });
    connect(d_ptrDbus,     &HorizontalOrVerticalMode::RotationSig, this, [=](deviceMode mode){
        emit tabletModeUpdate(TabletStatus(mode));
    });

}

UkuiSettingsMonitor::~UkuiSettingsMonitor()
{
    delete d_ptrGsetting;
    delete d_ptrDbus;
}

int UkuiSettingsMonitor::transparency() const
{
    return d_ptrGsetting->transparency();
}

UkuiSettingsMonitor::StyleStatus UkuiSettingsMonitor::styleStatus() const
{
    return StyleStatus(d_ptrGsetting->styleStatus());
}

UkuiSettingsMonitor::TabletStatus UkuiSettingsMonitor::tabletMode() const
{
    return TabletStatus(d_ptrDbus->defaultModeCapture());
}

void UkuiSettingsMonitor::startTest(TabletStatus status)
{
    static int cnt = 0;
    QTimer *timer = new QTimer();
    connect(timer, &QTimer::timeout, [=](){
        if (status != None) {
            emit this->tabletModeUpdate(status);
            return ;
        }
        cnt++;

        if (cnt % 2 == 0) {
            emit this->tabletModeUpdate(TabletStatus::PCMode);
        } else {
            emit this->tabletModeUpdate(TabletStatus::PADHorizontalMode);
        }
    });
    timer->start(1000);

}

