#include "cscallbacksendprogress.h"

#include <QDebug>

#include "mainwindow.h"

CSCallbackSendProgress::CSCallbackSendProgress()
{
    m_nCount = 0;
    m_nPrevBytes = 1;
    m_bExitSend = false;
}

CSCallbackSendProgress::~CSCallbackSendProgress()
{
}

void CSCallbackSendProgress::ProgressInfo(int nState)
{

}

void CSCallbackSendProgress::ProgressError(int nState)
{

}

void CSCallbackSendProgress::ProgressComplete()
{
    if(m_bExecBackground==true)
    {
        return;
    }
    MainWindow* pMainWindow = MainWindow::GetMainWindow();
    pMainWindow->UpdateSendComplete();
}

void CSCallbackSendProgress::ProgressState(int nProgressBytes, int nTotalBytes)
{
    if(m_bExecBackground==true)
    {
        return;
    }
    //qDebug() << nProgressBytes << ", " << nTotalBytes;

    MainWindow* pMainWindow = MainWindow::GetMainWindow();

    if(nProgressBytes<m_nPrevBytes)
    {
        m_nCount++;
        pMainWindow->UpdateSendInfo(m_nCount, m_nTotalCount);
    }

    m_nPrevBytes = nProgressBytes;
}

void CSCallbackSendProgress::SetTotalCount(int nCount)
{
    m_nTotalCount = nCount;
}


void CSCallbackSendProgress::ProgressDICOMMake(int nCurrentFile, int nTotalFile)
{

}

void CSCallbackSendProgress::SetExecBackground(bool bExecBackground)
{
    m_bExecBackground = bExecBackground;
}


void CSCallbackSendProgress::SetExitSend(bool bExitSend)
{
    m_Lock.lock();
    {
        m_bExitSend = bExitSend;
    }
    m_Lock.unlock();

}

bool CSCallbackSendProgress::IsExitSend()
{
    bool bExitSend;
    m_Lock.lock();
    {
        bExitSend = m_bExitSend;
    }
    m_Lock.unlock();
    return bExitSend;
}

void CSCallbackSendProgress::Clear()
{
    CSCallback::Clear();

    m_nCount = 0;
    m_nPrevBytes = 1;

    SetExitSend(false);

}
