#include <QApplication>
#include <QMessageBox>
#include <QLockFile>
#include <QDir>

#include "models/lotrodatmanager.h"

#include "widgets/browsewidget.h"
#include "widgets/exportwidget.h"
#include "widgets/importwidget.h"
#include "widgets/mainwindow.h"
#include "widgets/managewidget.h"

#include <QTextCodec>
#include <QDebug>
#include <QResource>
#include <QFontDatabase>

int main(int argc, char *argv[])
{
    setlocale(LC_ALL,"Russian");
    QApplication a(argc, argv);

    qDebug() << "Checking if there's another instance of Legacy";

    QLockFile lockFile(QDir::temp().absoluteFilePath("rulotro.lock"));
    if(!lockFile.tryLock(1)){
        QMessageBox msgBox;
        msgBox.setIcon(QMessageBox::Warning);
        msgBox.setText("Приложение уже запущено.\nРазрешено запускать только один экземпляр приложения.");
        msgBox.exec();
        return 1;
    }

    qDebug() << "Registering resources";
    QResource::registerResource(QApplication::applicationDirPath() + "/data_adv.gtr");
    QResource::registerResource(QApplication::applicationDirPath() + "/data02.gtr");

    QFontDatabase::addApplicationFont(":/assets/fonts/trajan.ttf");
    QFontDatabase::addApplicationFont(":/assets/fonts/viking.ttf");
    QFontDatabase::addApplicationFont(":/assets/fonts/title.ttf");

    qDebug() << "Starting main frame initialisation...";

    MainWindow* main_window = new MainWindow(nullptr);
    main_window->setAttribute(Qt::WA_DeleteOnClose);

    qDebug() << "Finished initialisation, starting application...";
    return a.exec();
}
