/*
 * Copyright (C) 2025 UBports Foundation
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; version 3.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Authors: Alfred Neumayer <alfred@ubports.com>
 */

#ifndef COMMANDRUNNER_H
#define COMMANDRUNNER_H

#include <QObject>
#include <QProcess>

class CommandRunner : public QObject
{
    Q_OBJECT

public:
    explicit CommandRunner(QObject *parent = nullptr);

    int shell(const QStringList& command, const bool waitForCompletion, QByteArray* output = nullptr);
    int sudo(const QStringList& command, const bool waitForCompletion, QByteArray* output = nullptr);

public Q_SLOTS:
    void writeInput(const QString input);
    void cancel();
    bool validatePassword();

private:
    bool sudo(const QStringList& command);
    QProcess m_process;

Q_SIGNALS:
    void passwordRequested();
    void outputReceived(const QString& output);
};

#endif // COMMANDRUNNER_H
