#include "LogsSorter.h"

CLogsSorter::CLogsSorter() : QObject()
{

}

int CLogsSorter::InitLogsSorter()
{
    mMainWindow.mConfigPage->mProgramPtr = this;
    mMainWindow.mStatusPage->mProgramPtr = this;
    mSorterConfig.mProgramHandle = this;
    mMainWindow.show();

    AddGeneralMsgTextRequest("Démarrage de l'application");

    if(mSorterConfig.LoadLogsSorterConfig(".\\Config.bin") != RET_OK)
    {
        AddGeneralMsgTextRequest("Échec du chargement de la configuration");
    }
    else
    {
        AddGeneralMsgTextRequest("Configuration chargée avec succès");
    }
    mMainWindow.mConfigPage->InitializeConfigData(&mSorterConfig.mLogsSorterConfig);

    mLogsHandler.mProgramPtr = this;
    mLogsHandler.SetSortingConfigData(&mSorterConfig.mLogsSorterConfig);

    return RET_OK;

}

int CLogsSorter::SaveSorterConfigRequest(CLogsSorterConfigData NewConfig)
{
    mSorterConfig.SetNewConfig(NewConfig);
    return RET_OK;
}

CLogsSorterConfigData *CLogsSorter::GetSorterConfigRequest()
{
    return &mSorterConfig.mLogsSorterConfig;
}

int CLogsSorter::AddGeneralMsgTextRequest(QString NewLine, QColor Color)
{
    mMainWindow.mStatusPage->AddGeneralMsgBoxLineEntry(NewLine,Color);

    return RET_OK;
}

int CLogsSorter::LauchManualScanRequest()
{
    return mLogsHandler.ParseWatchedDirectory();
}
