/**************************************************************************** ** Modern Linbo GUI ** Copyright (C) 2020 Dorian Zedler ** ** This program is free software: you can redistribute it and/or modify ** it under the terms of the GNU Affero General Public License as published ** by the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** ** 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 Affero General Public License for more details. ** ** You should have received a copy of the GNU Affero General Public License ** along with this program. If not, see . ****************************************************************************/ #ifndef LINBOBACKEND_H #define LINBOBACKEND_H #include #include #include #include #include #include #include #include #include #include #include #include "linbologger.h" #include "linboconfig.h" #include "linboos.h" #include "linboimage.h" #include "linbodiskpartition.h" using namespace std; class LinboBackend : public QObject { Q_OBJECT Q_PROPERTY(LinboBackend::LinboState state READ getState NOTIFY stateChanged) Q_PROPERTY(LinboOs* currentOs READ getCurrentOs WRITE setCurrentOs NOTIFY currentOsChanged) Q_PROPERTY(double autostartTimeoutProgress READ getAutostartTimeoutProgress NOTIFY autostartTimeoutProgressChanged) Q_PROPERTY(int autostartTimeoutRemainingSeconds READ getAutostartTimeoutRemainingSeconds NOTIFY autostartTimeoutProgressChanged) public: explicit LinboBackend(QObject *parent = nullptr); enum LinboState { Initializing, Autostarting, Idle, Starting, Syncing, Reinstalling, Root, Partitioning, InitializingCache, Updating }; LinboState getState(); LinboLogger* getLogger(); LinboConfig* getConfig(); QList getOperatingSystems(); LinboOs* getCurrentOs(); void setCurrentOs(LinboOs* os); double getAutostartTimeoutProgress(); int getAutostartTimeoutRemainingSeconds(); protected: bool read_pair(ifstream* input, QString& key, QString& value); bool toBool(const QString& value); LinboOs* read_os(ifstream* input); LinboDiskPartition* read_partition(ifstream* input); void read_globals( ifstream* input, LinboConfig* config ); private: LinboState state; LinboLogger* logger; LinboConfig* config; QStringList linboCommandCache; QList operatingSystems; QList diskPartitions; QElapsedTimer* autostartElapsedTimer; QTimer* autostartTimer; QTimer* autostartRemainingTimeRefreshTimer; LinboOs* currentOs; QString const linboCmdCommand = "linbo_cmd"; QProcess* asynchronosProcess; QProcess* synchronosProcess; template QString executeCommand(bool waitForFinished, QString argument, const Strings&... arguments) { return this->executeCommand(waitForFinished, this->linboCmdCommand, this->buildCommand(argument, arguments ...)); } QStringList buildCommand() { QStringList tmpArguments = this->linboCommandCache; this->linboCommandCache.clear(); return tmpArguments; } template QStringList buildCommand(QString argument, const Strings&... arguments) { // this appends a quoted space in case item is empty and resolves // problems with linbo_cmd's weird "shift"-usage if (argument.isEmpty()) this->linboCommandCache.append(""); else this->linboCommandCache.append(argument); return buildCommand(arguments...); } QString executeCommand(bool wait, QString command, QStringList commandArgs); void setState(LinboState state); public slots: void shutdown(); void reboot(); bool startCurrentOs(); bool syncCurrentOs(); bool reinstallCurrentOs(); bool partitionDrive(bool format = true); bool initializeCache(); bool updateLinbo(); private slots: void executeAutostart(); void handleAutostartTimerTimeout(); void readFromStdout(); void readFromStderr(); signals: void stateChanged(LinboBackend::LinboState state); void currentOsChanged(LinboOs* os); }; #endif // LINBOBACKEND_H