#include "kylintabletdekstopplugin.h"
#include <QtQml/qqml.h>
#include <QQmlContext>
#include <QQmlEngine>
#include <QDebug>
#include "modelmanager.h"
#include "appmanager.h"
#include "utils/getscreenshot.h"
#include "kgridview/kgridview.h"
//#include "KylinItemView/kquickgridview.h"
#include "base/launcheritem.h"
#include "base/categoryitem.h"
#include "core/modelmanager.h"
#include "core/appmanager.h"
#include "core/pluginitem.h"
#include "core/taskbarmanager.h"
#include "logger.h"
#include "utils/getscreenshot.h"
#include "utils/desktopbackground.h"
#include "ukui-log4qt.h"
#include "utils/generalsetting.h"
#include "utils/wirelessstatus.h"
#include "utils/wiredlinkstate.h"
#include "utils/accountlogout.h"
#include "utils/blurhelper.h"
#include "base/trayicon.h"
#include "base/sidebarstate.h"
#include "utils/taskbarmask.h"
#include "utils/showclendar.h"

void KylinTabletDekstopPlugin::registerTypes(const char *uri)
{
    Q_UNUSED(uri)
    qmlRegisterType<LauncherItem>("org.ukui.tablet", 1, 0, "LauncherItem");
    qmlRegisterType<CategoryItem>("org.ukui.tablet", 1, 0, "CategoryItem");
    qmlRegisterType<GetScreenShot>("org.ukui.tablet", 1, 0, "ScreenShot");
    qmlRegisterType<DesktopBackground>("org.ukui.tablet", 1, 0, "Background");
    qmlRegisterType<KQuickGridView>("org.ukui.tablet", 1, 0, "KGridView");
    qmlRegisterType<LauncherItem>("org.ukui.tablet", 1, 0, "LauncherItem");
    qmlRegisterType<CGeneralSetting>("MyGeneralSetting", 1, 0, "CGeneralSetting");
    qmlRegisterType<WirelessStatus>("org.ukui.tablet", 1, 0, "WirelessStatus");
    qmlRegisterType<WiredLinkState>("org.ukui.tablet", 1, 0, "WiredLinkState");
    qmlRegisterType<AccountLogout>("org.ukui.tablet", 1, 0, "AccountLogout");
    qmlRegisterType<BlurHelper>("org.ukui.tablet", 1, 0, "BlurHelper");
    qmlRegisterType<PluginItem>("org.ukui.tablet", 1, 0, "PluginItem");
    qmlRegisterType<TrayIcon>("org.ukui.tablet", 1, 0, "TrayIcon");
    qmlRegisterType<TaskbarMask>("org.ukui.tablet", 1, 0, "TaskbarMask");
}

void KylinTabletDekstopPlugin::initializeEngine(QQmlEngine *engine, const char *uri)
{
    Q_UNUSED(uri)
    ModelManager *modelManager = new ModelManager(this);
    engine->rootContext()->setContextProperty("modelManager", modelManager);

    AppManager *appMgr = new AppManager(this);
    engine->rootContext()->setContextProperty("appManager", appMgr);

    TrayIcon *trayIcon = new TrayIcon();
    engine->rootContext()->setContextProperty("trayIcon", trayIcon);

    SidebarState *sidebarState = new SidebarState(this);
    engine->rootContext()->setContextProperty("sidebarState", sidebarState);

    ShowClendar *showCal = new ShowClendar(this);
    engine->rootContext()->setContextProperty("showCal", showCal);

    QString qtquickSceneBackend = qEnvironmentVariable("QT_QUICK_BACKEND");
    bool openGLEnabled = qtquickSceneBackend == "software" ? false : true;
    engine->rootContext()->setContextProperty("openGLEnabled", QVariant::fromValue<bool>(openGLEnabled));
}
