2020-11-16 18:01:03 +01:00
|
|
|
/****************************************************************************
|
|
|
|
** Modern Linbo GUI
|
|
|
|
** Copyright (C) 2020 Dorian Zedler <dorian@itsblue.de>
|
|
|
|
**
|
|
|
|
** 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 <http://www.gnu.org/licenses/>.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef LINBOBACKEND_H
|
|
|
|
#define LINBOBACKEND_H
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
#include <QStringList>
|
|
|
|
#include <QtDebug>
|
|
|
|
#include <QProcess>
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
#include <iostream>
|
|
|
|
#include <fstream>
|
|
|
|
#include <istream>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "linboconfig.h"
|
|
|
|
#include "linboos.h"
|
|
|
|
#include "linboimage.h"
|
|
|
|
#include "linbodiskpartition.h"
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
class LinboBackend : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
2020-11-20 15:09:36 +01:00
|
|
|
Q_PROPERTY(LinboState state READ getState NOTIFY stateChanged)
|
2020-11-16 18:01:03 +01:00
|
|
|
public:
|
|
|
|
explicit LinboBackend(QObject *parent = nullptr);
|
|
|
|
|
2020-11-19 14:39:32 +01:00
|
|
|
enum LinboState {
|
|
|
|
Idle,
|
|
|
|
Root,
|
|
|
|
Partitioning,
|
|
|
|
Starting,
|
|
|
|
Syncing,
|
2020-11-20 15:09:36 +01:00
|
|
|
Reinstalling
|
2020-11-19 14:39:32 +01:00
|
|
|
};
|
|
|
|
|
2020-11-20 15:09:36 +01:00
|
|
|
LinboState getState();
|
2020-11-16 18:01:03 +01:00
|
|
|
LinboConfig* getConfig();
|
|
|
|
QList<LinboOs*> getOperatingSystems();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void read_qstring(ifstream* input, QString& tmp );
|
|
|
|
void read_bool( ifstream* input, bool& tmp);
|
|
|
|
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 );
|
|
|
|
void saveappend( QStringList& command, const QString& item );
|
|
|
|
QStringList mkpartitioncommand(vector <LinboDiskPartition> &p);
|
|
|
|
QStringList mkpartitioncommand_noformat(vector <LinboDiskPartition> &p);
|
|
|
|
QStringList mkcacheinitcommand(LinboConfig& config, vector<LinboOs> &os, const QString& type);
|
|
|
|
QStringList mklinboupdatecommand(LinboConfig& config);
|
|
|
|
|
2020-11-20 15:09:36 +01:00
|
|
|
void setState(LinboState state);
|
|
|
|
|
2020-11-16 18:01:03 +01:00
|
|
|
private:
|
2020-11-20 15:09:36 +01:00
|
|
|
LinboState state;
|
2020-11-16 18:01:03 +01:00
|
|
|
LinboConfig* config;
|
2020-11-20 15:09:36 +01:00
|
|
|
QStringList linboCommandCache;
|
2020-11-16 18:01:03 +01:00
|
|
|
QList<LinboOs*> operatingSystems;
|
|
|
|
QList<LinboDiskPartition*> diskPartitions;
|
|
|
|
|
|
|
|
QProcess* process;
|
|
|
|
|
2020-11-20 15:09:36 +01:00
|
|
|
QString executeCommand(bool waitForFinished);
|
|
|
|
|
|
|
|
template<typename ... Strings>
|
|
|
|
QString executeCommand(bool waitForFinished, 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 executeCommand(waitForFinished, arguments...);
|
|
|
|
}
|
|
|
|
|
2020-11-16 18:01:03 +01:00
|
|
|
void readFromStdout();
|
|
|
|
void readFromStderr();
|
|
|
|
|
2020-11-20 15:09:36 +01:00
|
|
|
QString executeCommand(bool wait, QString command, QStringList commandArgs);
|
2020-11-16 18:01:03 +01:00
|
|
|
|
|
|
|
public slots:
|
|
|
|
void executeAutostart();
|
|
|
|
void shutdown();
|
|
|
|
void reboot();
|
|
|
|
|
|
|
|
bool startOs(LinboOs* os);
|
2020-11-20 15:09:36 +01:00
|
|
|
bool syncOs(LinboOs* os);
|
|
|
|
bool reinstallOs(LinboOs* os);
|
2020-11-16 18:01:03 +01:00
|
|
|
|
|
|
|
signals:
|
2020-11-20 15:09:36 +01:00
|
|
|
void stateChanged();
|
2020-11-16 18:01:03 +01:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // LINBOBACKEND_H
|