#include "SystemGui.h"


CSystemGui::CSystemGui(QObject *parent) : QObject(parent)
{
    mGui = new CGuiMain();
    mProgramSettings = new CProgramSettings();
    mSMSClient = new CSMSClient(mGui->mSMSGui,&mSettings.mVoipMSSettings);
    mSprinklers = new CSprinkler(mGui->mSprinklerGui);
    mAvReceiver = new CAvReceiver(mGui->mAvReceiverGui);
    mChalet = new CChalet(mGui->mChaletGui);
    mPICUploader = new CPICUploader(mGui->mPICUploaderGui);
    mIspindel = new CIspindel(mGui->mIspindelGui);
    mLoraModuleIF = new CLoraModuleInterface(mGui->mChaletGui);
    mTrayVolumeCtrl = new CTrayVolumeCtrl(mGui->mAvReceiverGui);
    mGui->mAvReceiverGui->mTrayVolumeCtrlGuiHandle = mTrayVolumeCtrl;

    mSysTrayMgr = new CSystemTrayManager(mTrayVolumeCtrl);
    mSysTrayMgr->mProgramHandle=this;
    mSMSClient->mTrayIconMgr = mSysTrayMgr;



}

CSystemGui::~CSystemGui()
{
    delete mGui;
    delete mSMSClient;
    delete mProgramSettings;
    delete mSysTrayMgr;
    delete mAvReceiver;
    delete mChalet;
    delete mPICUploader;
    delete mIspindel;
    delete mLoraModuleIF;
    delete mTrayVolumeCtrl;

}

void CSystemGui::Start()
{
    mProgramSettings->LoadSettings(&mSettings);
    mGui->show();
    mSMSClient->Start();
    mAvReceiver->Start();
    mChalet->Start();
    mPICUploader->Start();
    mIspindel->Start();
//    mLoraModuleIF->Start();

}

void CSystemGui::ShowSettingsWindowRequest()
{

}

void CSystemGui::QuitApplicationRequest()
{
    QApplication::exit(69);
}

int CSystemGui::RespawnMainWindowRequest()
{
    //qDebug("Respawn request");
    mGui->RespawnMainWindow();
    return RET_OK;
}

int CSystemGui::TrayIconLeftClick()
{
    if(mGui->isVisible())
    {
        mGui->hide();


    }
    else
    {
        mGui->RespawnMainWindow();
    }

    return RET_OK;
}
