#include "processopenfile.h"

ProcessOpenFile::ProcessOpenFile(QString path, QObject *parent) :
    ProcessBasic(parent)
{
    m_oArguments << path;
    m_oPeony = new QProcess(this);
    m_oPeony->setProgram("peony");
    m_oPeonyArgs.clear();
    m_oPeonyArgs << "-i";
}

void ProcessOpenFile::setFile(QString path)
{
    m_oArguments.clear();
    m_oArguments << path;
    m_oPeonyArgs << path;
}

void ProcessOpenFile::exec()
{
    prepare();
    m_oProcess->setArguments(m_oArguments);
    m_oProcess->start();
    connect(m_oProcess, SIGNAL(started()), this, SLOT(slotsStart()));
    connect(m_oProcess, SIGNAL(readyReadStandardOutput()), this, SLOT(slotsOutput()));
    connect(m_oProcess, SIGNAL(readyReadStandardError()), this, SLOT(slotsError()));
    connect(m_oProcess, SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(slotsFinished(int,QProcess::ExitStatus)));
}

bool ProcessOpenFile::prepare()
{
    m_oProcess->setProgram("xdg-open");
    return true;
}

void ProcessOpenFile::slotsError()
{
    m_oPeony->setArguments(m_oPeonyArgs);
    m_oPeony->start();
}

void ProcessOpenFile::slotsFinished(int errCode, QProcess::ExitStatus status)
{
}

ProcessOpenFile::~ProcessOpenFile()
{}
