#ifndef APP_H
#define APP_H

#include "mainwindow.h"
#include "ui_mainwindow.h"

#include "config.h"
#include "network.h"
#include "helper.h"
#include "downloadmanager.h"

#include <QRegExp>
#include <QBitmap>
#include <QClipboard>
#include <QException>
#include <QWidget>
#include <QGraphicsDropShadowEffect>
#include <QDesktopWidget>
#include <QFile>
#include <QFileInfo>
#include <QDir>
#include <QFileDialog>
#include <QMessageBox>
#include <QRect>
#include <QGridLayout>
#include <QMovie>
#include <QListWidget>
#include <QtConcurrent/QtConcurrent>
#include <QMessageLogger>
#include <QDebug>
#include <QFutureWatcher>
#include "LotroDat.h"
#include <string>

using namespace LOTRO_DAT;

class App {

public:
    App() {
        config = new AConfig();
        network = new ANetwork();
        helper = new Helper();
        downloader = new DownloadManager();
        writtenLabel = new QLabel();
        buildSeparators(9472, 65507, 45, 60, 48, 85);//9472 создаем разделители
    }

    static App& getInstance() {
        static App instance;
        return instance;
    }

    AConfig * config;
    ANetwork * network;
    Helper * helper;
    MainWindow * window;
    DownloadManager * downloader;
    QLabel * writtenLabel;
    QString state;

    QString app_folder = "";
    QString qsep, qsepn, tsep, tsepn, bsep, bsepn;
    QString stylehtml;
    bool ready = true;

    void log(QString msg){
        QString format = "[" + QDate::currentDate().toString(Qt::ISODate).toUtf8() + " " + QTime::currentTime().toString(Qt::ISODate).toUtf8() + "]    " + msg;
        fprintf(stderr, (format + "\n").toUtf8());
    }

    void logSectionStart(const char * msg){
        topSeparate();
        fprintf(stderr, "%s\n", msg);
        bottomSeparate();
    }

    void logSectionEnd(){
        fprintf(stderr, " \n");
    }

    void topSeparate(){
        fprintf(stderr, tsepn.toUtf8());
    }

    void bottomSeparate(){
        fprintf(stderr, bsepn.toUtf8());
    }

    void buildSeparators(int code_top, int code_bottom, int qcode, int tsize, int bsize, int qsize){
        for(int i = 0; i < tsize; i++){ tsep.append(QChar(QChar(code_top))); }
        tsepn = tsep + "\n";
        for(int i = 0; i < bsize; i++){ bsep.append(QChar(QChar(code_bottom))); }
        bsepn = bsep + "\n";
        for(int i = 0; i < qsize; i++){ qsep.append(QChar(QChar(qcode))); }
        qsepn = qsep + "\n";
    }
};
#endif // APP_H
