#ifndef PROCESSBASIC_H
#define PROCESSBASIC_H

#include <QObject>
#include <QProcess>
#include <QIcon>
#include <QTimer>

class ProcessBasic : public QObject
{
    Q_OBJECT
    enum ProcessStep
    {
        Prepare = 0,
        Config,
        Working,
        Worked
    };

Q_SIGNALS:
    // log
    void info(QString); void warn(QString);
    void error(QString); void debug(QString);
    // progress
    void title(QString);
    void setRange(int, int);
    void setValue(int, QIcon icon = QIcon(), QString str = QString());
    void addValue(int, QIcon icon = QIcon(), QString str = QString());
    void cancel(bool);
    void updateIcon(QIcon);
    // tip
    void success(QString); void fail(QString);
    void eject();
public:
    ProcessBasic(QObject *parent = nullptr);
    ~ProcessBasic();
public:
    virtual void exec();
protected:
    virtual bool prepare();
    virtual bool config();
    virtual bool working();
    virtual bool worked();
protected slots:
    virtual void slotsCancel();
    virtual void slotsStart() = 0;
    virtual void slotsOutput() = 0;
    virtual void slotsError() = 0;
    virtual void slotsFinished(int,QProcess::ExitStatus) = 0;
    virtual void slotsIcon();
    virtual void slotsExit();
private:
    void connection();
protected:
    unsigned int    m_u32Icon;
    bool            m_bCancel;
    bool            m_oKeep;
    QProcess       *m_oProcess;
    QTimer         *m_oTimer;
    QString         m_oProcessName;
    QString         m_oDeviceBlock;
    QStringList     m_oArguments;
    QIcon           m_oIcon;
    QString         m_lastErrorMsg;
};

#endif // PROCESSBASIC_H
