#include "processisoinfo.h"
#include "src/view/modaldialog.h"
#include "src/data/datacdrom.h"
#include "src/po/translation.h"

ProcessISOInfo::ProcessISOInfo(void *d, QObject *parent) :
    ProcessBasic(parent),
    m_oCDROM(d)
{
    m_oProcessName = _("load");
    m_bIsEmpty = true;
}

bool ProcessISOInfo::prepare()
{
    DataCDROM *cdrom;
    cdrom = static_cast<DataCDROM *>(m_oCDROM);
    if (!cdrom) error(_("ERROR:ISOINFO-PREPARE"));
    m_oProcess->setProgram("isoinfo");
    m_oArguments << "-d" << "-i" << cdrom->device();
    return true;
}

void ProcessISOInfo::slotsError()
{
    QString error;

    error = m_oProcess->readAllStandardError();
    if (error.contains("CD-ROM is NOT in ISO 9660 format")) m_bIsEmpty = true;
}

void ProcessISOInfo::slotsOutput()
{
    DataCDROM *cdrom;
    QString output;
    QString s;
    QStringList ss;
    QStringList st;

    output = m_oProcess->readAllStandardOutput();
    if (output.contains("CD-ROM is NOT in ISO 9660 format")) m_bIsEmpty = true;
    ss = output.split("\n");
    cdrom = static_cast<DataCDROM *>(m_oCDROM);
    foreach (s, ss)
    {
        if (s.startsWith("Volume id:"))
        {
            m_bIsEmpty = false;
            st = s.split(":");
            //cdrom->volumnID(st.last().trimmed());//不许改datasetting.cpp中的光盘属性，3.2-18版本改
        }
        else if (s.startsWith("Publisher id:"))
        {
            m_bIsEmpty = false;
            st = s.split(":");
            //cdrom->publisher(st.last().trimmed());
        }
        else if (s.startsWith("Data preparer id:"))
        {
            m_bIsEmpty = false;
            st = s.split(":");
            //cdrom->preparer(st.last().trimmed());
        }
        else if (s.startsWith("Copyright File id:"))
        {
            m_bIsEmpty = false;
            st = s.split(":");
            //cdrom->copyright(st.last().trimmed());
        }
        else {}
    }
}

ProcessISOInfo::~ProcessISOInfo()
{}
