#include "widget.h"
#include "videoplay.h"
#include "appdef.h"
#include "global.h"

#include <QApplication>
#include <QFile>

IniParser* g_confile = NULL;
char g_exec_path[256] = { 0 };
char g_exec_dir[256] = { 0 };
char g_run_dir[256] = { 0 };
char g_conf_file[256] = { 0 };
char g_log_file[256] = { 0 };

static int load_confile() {

    get_executable_path(g_exec_path, sizeof(g_exec_path));

    get_executable_dir(g_exec_dir, sizeof(g_exec_dir));

    get_run_dir(g_run_dir, sizeof(g_run_dir));

    // load confile
    g_confile = new IniParser;
    std::string ini = (qApp->applicationDirPath() + "/config/videoplay.ini").toStdString();
    if (access(ini.c_str(), 0) != 0) {
        std::cerr << "videoplay.ini file not exist" << std::endl;
        return -1;
    }
    g_confile->LoadFromFile(ini.c_str());

    return 1;
}

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    load_confile();

    Global::Instance()->setRootDirPath(qApp->applicationDirPath());


    Widget w;

    QFile styleFile(Global::Instance()->resourceDirPath() + QString("/style/dark_green/style.css"));
    if(styleFile.open(QIODevice::ReadOnly))
    {
        qApp->setStyleSheet(styleFile.readAll());
        styleFile.close();
    }

    w.show();
    return a.exec();
}
