#include "global.h"

#include <QSettings>
#include <QGSettings>
#include <QApplication>
#include <QFile>
#include <QDebug>
#include "path.h"

#include <kysdk/kysdk-system/libkysysinfo.h>

QSettings       *Global::g_settings     = nullptr;
SqliteHandle    *Global::g_sqlite       = nullptr;
GlobalConfig    *Global::g_config       = nullptr;
QGSettings      *Global::g_gsettings    = nullptr;
ShortCutSetting *Global::g_shortcut     = nullptr;
QGSettings      *Global::g_gsettings_control_center = nullptr;
Mpv::PlayState  Global::g_playstate     = Mpv::Idle;
bool Global::isWayland = false;
bool Global::isTablet = false;
bool Global::isHaWeiKe = false;
bool Global::isUrl = false;
bool Global::is4Kscreen = false;
bool Global::isSpecialCard = false;
//KPlayControl *Global::k_playcontrol = KPlayControl::getInstanece();

using namespace Global;

void Global::initGlobal() {

    // g_settings
    QString filename = Paths::iniPath() + "/kylin-video3.ini";
    QString dbname = Paths::iniPath() + "/kylin-video3.db";

    g_settings = new QSettings(filename, QSettings::IniFormat);
    g_settings->setIniCodec("UTF-8");
    // 运行环境
    if(!g_settings->contains("General/display_env"))
    {
        if((QString(qgetenv("XDG_SESSION_TYPE")) == "wayland"))
            g_settings->setValue("General/display_env", "wayland");
        else
            g_settings->setValue("General/display_env", "x11");
    }
    isWayland   = QString(qgetenv("XDG_SESSION_TYPE")) == "wayland";

    g_gsettings = new QGSettings(ORG_UKUI_STYLE);
    if (QGSettings::isSchemaInstalled(PERSONALISE_SHEME))
        g_gsettings_control_center = new QGSettings(PERSONALISE_SHEME);

    g_shortcut  = ShortCutSetting::getInstance(g_settings);
    g_sqlite    = SqliteHandle::getInstance(dbname);
    g_config    = GlobalConfig::getInstance();

    if (QString(kdk_system_get_projectName()) == "V10SP1" && QString(kdk_system_get_productFeatures()).toInt() >= 2) {
        isTablet = true;
    }
    else {
        isTablet = false;
    }
}
