#include "loappconfig.h"
#include <LoQClass/loglwindow.h>

LoAppConfig *LoAppConfig::m_instance = nullptr;

LoAppConfig::LoAppConfig()
{
    m_OrganizationName   = "Shanghai Xixun Electronic Technology Co., Ltd.";
    m_OrganizationDomain = "www.ledok.cn";
    m_ApplicationName    = "LedOK Express";
    m_DocumentsLocation  = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
    m_NProgramsLocation  = m_DocumentsLocation + MACRO_FENGEFU + m_ApplicationName + "\\NPrograms";
    m_SearchPath         = m_DocumentsLocation;

    LoGLWindow glw;
    m_OpenGLVendor     = glw.vendor();
    m_OpenGLRenderer   = glw.renderer();
    m_OpenGLVersion    = glw.version();
    m_OpenGLExtensions = glw.extensions().split(' ');
    m_OpenGLExtensions.removeDuplicates();
    m_OpenGLExtensions.removeOne("");
    qDebug() << "OpenGLVendor  : " << m_OpenGLVendor;
    qDebug() << "OpenGLRenderer: " << m_OpenGLRenderer;
    qDebug() << "OpenGLVersion : " << m_OpenGLVersion;
}

LoAppConfig* LoAppConfig::getInstance()
{
    if(m_instance == nullptr)
        m_instance = new LoAppConfig();
    return m_instance;
}

QString LoAppConfig::styleSheet()
{
    QString qss;
    QString qss_path = ":/qss";
    QDir qss_dir(qss_path);
    QStringList filters;
    filters << "*.css";
    QStringList qss_list = qss_dir.entryList(filters);
    std::sort(qss_list.begin(), qss_list.end(), [](const QString &a, const QString &b) {
        return a < b;
    });
    foreach(QString qss_name, qss_list) {
        QFile f(qss_path + MACRO_FENGEFU + qss_name);
        if(f.exists() && f.open(QFile::ReadOnly)) {
            qss += f.readAll();
            f.close();
            qDebug() << qss_name;
        }
    }
    return qss;
}
