#include "watermark-manager.h"
#include <QDebug>

WatermarkManager::WatermarkManager()
{
    watermark = new WaterMark();
    watermark->switchState(false);

    QDBusConnection connection = QDBusConnection::sessionBus();
    if (!connection.registerObject("/com/kylin/MaintainMode/watermark", this, QDBusConnection::ExportAllSlots | QDBusConnection::ExportAllProperties | QDBusConnection::ExportAllSignals)) {
        qDebug() << "registerObject error:" << connection.lastError().message();
    }
    if (!connection.registerService("com.kylin.MaintainMode.watermark")) {
        qDebug() << "registerService error:" << connection.lastError().message();
    }
    if (!QDBusConnection::sessionBus().connect(
            QString(),
            "/com/kylin/MaintainMode/watermark",
            "com.kylin.MaintainMode.watermark",
            "waterMaskChanged",
            this,
            SLOT(UpdateWatermark(int, int, int)))) {
        qDebug() << "connect signal failed...";
    }
    qDebug() << "new WatermarkManager";
}

WatermarkManager::~WatermarkManager()
{
}

bool WatermarkManager::OpenWatermark()
{
    if (watermark->switchModeImmediate())
        watermark->open();
    return true;
}

bool WatermarkManager::CloseWatermark()
{
    if (watermark->switchModeImmediate())
        watermark->close();
    return true;
}

bool WatermarkManager::UpdateWatermark(int color, int font_size, int pos)
{
    watermark->update(color, font_size, pos); //通过d-feet能穿进来的方法，然后可以继续使用
    return true;
}
