96 lines
2.8 KiB
C++
96 lines
2.8 KiB
C++
#pragma once
|
|
|
|
#include <QObject>
|
|
#include <QProcess>
|
|
#include <QProcessEnvironment>
|
|
#include <QQmlEngine>
|
|
#include <QStringList>
|
|
#include <QTemporaryDir>
|
|
#include <QTimer>
|
|
#include <QVariantList>
|
|
|
|
class UpdateManager : public QObject
|
|
{
|
|
Q_OBJECT
|
|
QML_ELEMENT
|
|
|
|
Q_PROPERTY(int packageCount READ packageCount NOTIFY packageCountChanged)
|
|
Q_PROPERTY(bool isChecking READ isChecking NOTIFY isCheckingChanged)
|
|
Q_PROPERTY(bool isUpdating READ isUpdating NOTIFY isUpdatingChanged)
|
|
Q_PROPERTY(bool isInstalling READ isInstalling NOTIFY isInstallingChanged)
|
|
Q_PROPERTY(bool isRemoving READ isRemoving NOTIFY isRemovingChanged)
|
|
Q_PROPERTY(QStringList removalLog READ removalLog NOTIFY removalLogChanged)
|
|
Q_PROPERTY(QStringList updateLog READ updateLog NOTIFY updateLogChanged)
|
|
Q_PROPERTY(QStringList installLog READ installLog NOTIFY installLogChanged)
|
|
Q_PROPERTY(QVariantList packages READ packages NOTIFY packagesChanged)
|
|
|
|
public:
|
|
explicit UpdateManager(QObject* parent = nullptr);
|
|
|
|
public:
|
|
enum class PackageManager { Pacman, Yay };
|
|
Q_ENUM(PackageManager)
|
|
|
|
private:
|
|
QProcess m_process;
|
|
QProcess m_update_process;
|
|
PackageManager m_package_manager = PackageManager::Yay;
|
|
|
|
bool m_is_checking = false;
|
|
bool m_is_updating = false;
|
|
bool m_is_installing = false;
|
|
bool m_is_removing = false;
|
|
bool m_update_timedout = false;
|
|
|
|
QString m_update_manager;
|
|
QString m_update_log_buffer;
|
|
|
|
QVariantList m_packages;
|
|
std::unique_ptr<QTemporaryDir> m_askpass_dir;
|
|
QByteArray m_update_output;
|
|
QStringList m_update_log;
|
|
QStringList m_install_log;
|
|
QStringList m_removal_log;
|
|
QTimer m_update_watchdog;
|
|
|
|
public:
|
|
int packageCount() const;
|
|
bool isChecking() const;
|
|
bool isUpdating() const;
|
|
bool isInstalling() const;
|
|
bool isRemoving() const;
|
|
QStringList updateLog() const;
|
|
QStringList installLog() const;
|
|
QStringList removalLog() const;
|
|
QVariantList packages() const;
|
|
|
|
public:
|
|
Q_INVOKABLE void checkUpdates();
|
|
Q_INVOKABLE void update(const QString& password, const QString& packageManager);
|
|
|
|
private:
|
|
void set_packages(const QVariantList& value);
|
|
void set_is_checking(bool value);
|
|
void set_is_updating(bool value);
|
|
QString create_ask_pass_helper(const QString& password);
|
|
void add_log_line(const QString &line);
|
|
QProcessEnvironment update_environment(const QString& askpass) const;
|
|
void begin_package_update();
|
|
|
|
private:
|
|
void on_process_finished(int exitCode, QProcess::ExitStatus status);
|
|
void on_process_error(QProcess::ProcessError error);
|
|
|
|
signals:
|
|
void packageCountChanged();
|
|
void isCheckingChanged();
|
|
void isUpdatingChanged();
|
|
void isInstallingChanged();
|
|
void isRemovingChanged();
|
|
void packagesChanged();
|
|
void updateLogChanged();
|
|
void installLogChanged();
|
|
void removalLogChanged();
|
|
};
|
|
|