#ifndef GLOBAL_H
#define GLOBAL_H

#include <QObject>
#include <QList>
#include <QMutex>

/**
* @brief 相机排列显示
**/
struct CameraDisplayParam
{
    int type;
    int index;
};

/**
* @brief 单例类
*  用来管理配置文件
**/
class Global : public QObject
{
    Q_OBJECT
public:
    static Global *Instance();

    void setRootDirPath(const QString &path);
    QString rootDirPath();

    QString resourceDirPath();

    QString hostIP();

    void setTheme(const QString &theme);
    QString theme();

    void setCameraDisplayParam(CameraDisplayParam p);
    CameraDisplayParam cameraDisplayParam();

signals:
    void refresh();

protected:
    Global();

private:
    /**
     *@brief 检查资源目录或者文件是否存在
     **/
    void checkResource();

    QString configFilePath();

private:
    static Global *mInstance;
    static QMutex mMutex;

    QString mRootPath;

    // 样式表索引
    QString mThemeIndex;

    // 相机排列显示
    CameraDisplayParam mCameraDisplayParam;

    // GC类
    // 程序退出后，该类的析构函数释放单例内存
    class GC
    {
    public:
        ~GC()
        {
            if (mInstance != nullptr)
            {
                delete mInstance;
                mInstance = nullptr;
            }
        }
    };

    static GC gc;
};

#endif // GLOBAL_H
