- added log text

- started to implement autostart
This commit is contained in:
Dorian Zedler 2020-11-24 20:25:39 +01:00
parent c01d1b884d
commit 06dd8c4be3
Signed by: dorian
GPG Key ID: D3B255CB8BC7CD37
20 changed files with 1727 additions and 22 deletions

View File

@ -14,13 +14,14 @@
-opensource \
-release \
-static \
-fontconfig \
-freetype \
-no-accessibility \
-no-xmlpatterns \
-no-phonon \
-no-phonon-backend \
-no-webkit \
-no-exceptions \
-no-svg \
-no-script \
-no-scripttools \
-no-nis \
@ -38,7 +39,6 @@
-no-largefile \
-no-xinerama \
-no-xrender \
-no-freetype \
-no-opengl \
-no-glib \
-nomake examples \

View File

@ -23,6 +23,8 @@
#include <QStringList>
#include <QtDebug>
#include <QProcess>
#include <QTimer>
#include <QElapsedTimer>
#include <vector>
#include <iostream>
@ -30,6 +32,7 @@
#include <istream>
#include <stdlib.h>
#include "linbologger.h"
#include "linboconfig.h"
#include "linboos.h"
#include "linboimage.h"
@ -42,12 +45,15 @@ 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,
@ -59,10 +65,13 @@ public:
};
LinboState getState();
LinboLogger* getLogger();
LinboConfig* getConfig();
QList<LinboOs*> getOperatingSystems();
LinboOs* getCurrentOs();
void setCurrentOs(LinboOs* os);
double getAutostartTimeoutProgress();
int getAutostartTimeoutRemainingSeconds();
protected:
bool read_pair(ifstream* input, QString& key, QString& value);
@ -73,11 +82,16 @@ protected:
private:
LinboState state;
LinboLogger* logger;
LinboConfig* config;
QStringList linboCommandCache;
QList<LinboOs*> operatingSystems;
QList<LinboDiskPartition*> diskPartitions;
QElapsedTimer* autostartElapsedTimer;
QTimer* autostartTimer;
QTimer* autostartRemainingTimeRefreshTimer;
LinboOs* currentOs;
QString const linboCmdCommand = "linbo_cmd";
@ -126,6 +140,7 @@ public slots:
private slots:
void executeAutostart();
void handleAutostartTimerTimeout();
void readFromStdout();
void readFromStderr();

View File

@ -0,0 +1,47 @@
#ifndef LINBOLOGGER_H
#define LINBOLOGGER_H
#include <QObject>
#include <QtDebug>
#include <QDateTime>
class LinboLogger : public QObject
{
Q_OBJECT
Q_PROPERTY(LinboLog latestLog READ getLatestLog NOTIFY latestLogChanged)
public:
friend class LinboBackend;
enum LinboLogType {
UnknownLogType = -1,
StdOut,
StdErr,
LinboGuiInfo,
LinboGuiError
};
typedef struct {
QString message;
LinboLogType type;
QDateTime time;
} LinboLog;
const LinboLog& getLatestLog();
QString logTypeToString(LinboLogType logType);
private:
explicit LinboLogger(QObject *parent = nullptr);
void log(QString logText, LinboLogType logType);
QList<LinboLog> logHistory;
signals:
void latestLogChanged(const LinboLogger::LinboLog& latestLog);
};
#endif // LINBOLOGGER_H

View File

@ -66,7 +66,6 @@ public:
}
LinboOsStartAction startActionFromString(const QString& name) const {
qDebug() << "default action name is: " << name;
if(name == "start")
return StartOs;
else if(name == "sync")

View File

@ -24,6 +24,8 @@
#include <QApplication>
#include <QDesktopWidget>
#include <QBoxLayout>
#include <QFont>
#include <QFontDatabase>
#include "linboGUIImpl.hh"
#include "linbostartpage.h"

View File

@ -6,8 +6,10 @@
#include <QHBoxLayout>
#include <QStackedWidget>
#include <QList>
#include <QLabel>
#include "linbobackend.h"
#include "linbologger.h"
#include "linboosselectionrow.h"
#include "qmodernstackedwidget.h"
#include "qmodernpushbutton.h"
@ -35,6 +37,8 @@ private:
QWidget* progressBarWidget;
QModernProgressBar* progressBar;
QFont logFont;
QLabel* logLabel;
bool inited;
@ -42,6 +46,7 @@ private slots:
void resizeAndPositionAllItems();
void handleCurrentOsChanged(LinboOs* newOs);
void handleLinboStateChanged(LinboBackend::LinboState newState);
void handleLatestLogChanged(const LinboLogger::LinboLog& latestLog);
signals:
void selectedOsChanged();

View File

@ -25,6 +25,7 @@ HEADERS += \
headers/backend/linboconfig.h \
headers/backend/linbodiskpartition.h \
headers/backend/linboimage.h \
headers/backend/linbologger.h \
headers/backend/linboos.h \
headers/legacy/image_description.hh \
headers/legacy/linboConsoleImpl.hh \
@ -57,6 +58,7 @@ SOURCES += \
sources/backend/linboconfig.cpp \
sources/backend/linbodiskpartition.cpp \
sources/backend/linboimage.cpp \
sources/backend/linbologger.cpp \
sources/backend/linboos.cpp \
sources/legacy/image_description.cc \
sources/legacy/linboConsoleImpl.cc \
@ -105,3 +107,9 @@ FORMS += \
RESOURCES += \
resources/linbo.qrc
DISTFILES += \
resources/fonts/Segoe UI Bold Italic.ttf \
resources/fonts/Segoe UI Bold.ttf \
resources/fonts/Segoe UI Italic.ttf \
resources/fonts/Segoe UI.ttf

Binary file not shown.

BIN
resources/fonts/SegoeUI.eot Normal file

Binary file not shown.

1520
resources/fonts/SegoeUI.svg Normal file

File diff suppressed because it is too large Load Diff

After

Width:  |  Height:  |  Size: 92 KiB

BIN
resources/fonts/SegoeUI.ttf Normal file

Binary file not shown.

Binary file not shown.

View File

@ -26,5 +26,6 @@
<file>svgIcons/shutdownAction.svg</file>
<file>svgIcons/rebootAction.svg</file>
<file>svgIcons/settingsAction.svg</file>
<file>fonts/SegoeUI.ttf</file>
</qresource>
</RCC>

View File

@ -25,11 +25,18 @@ using namespace std;
LinboBackend::LinboBackend(QObject *parent) : QObject(parent)
{
this->setState(Initializing);
this->logger = new LinboLogger(this);
this->config = new LinboConfig(this);
this->autostartTimer = new QTimer(this);
this->autostartTimer->setSingleShot(true);
this->autostartRemainingTimeRefreshTimer = new QTimer(this);
this->autostartRemainingTimeRefreshTimer->setSingleShot(true);
this->autostartRemainingTimeRefreshTimer->setInterval(10);
this->autostartElapsedTimer = new QElapsedTimer();
this->currentOs = nullptr;
// read start.conf
qDebug() << "Starting to parse start.conf";
this->logger->log("Starting to parse start.conf", LinboLogger::LinboGuiInfo);
ifstream input;
input.open( "start.conf", ios_base::in );
@ -83,12 +90,8 @@ LinboBackend::LinboBackend(QObject *parent) : QObject(parent)
}
input.close();
// default select first OS
if(this->operatingSystems.length() > 0 && this->currentOs == nullptr)
this->currentOs = this->operatingSystems[0];
qDebug() << "Finished parsing start.conf";
qDebug() << "Loading global configuration";
this->logger->log("Finished to parsing start.conf", LinboLogger::LinboGuiInfo);
this->logger->log("Loading global configuration", LinboLogger::LinboGuiInfo);
// load global config
QStringList command;
@ -130,8 +133,18 @@ LinboBackend::LinboBackend(QObject *parent) : QObject(parent)
hd.remove( *removePartition );
this->config->setHddSize(this->executeCommand(true, "size", hd));
qDebug() << "Finished loading global configuration";
this->setState(Idle);
this->logger->log("Finished loading global configuration", LinboLogger::LinboGuiInfo);
// default select first OS if no other OS has been selected yet
if(this->operatingSystems.length() > 0 && this->currentOs == nullptr)
this->currentOs = this->operatingSystems[0];
// triger autostart
if(this->currentOs->getAutostart())
this->executeAutostart();
else
this->setState(Idle);
}
// --------------------
@ -139,6 +152,11 @@ LinboBackend::LinboBackend(QObject *parent) : QObject(parent)
// --------------------
void LinboBackend::executeAutostart() {
this->autostartTimer->setInterval(this->currentOs->getAutostartTimeout() * 1000);
this->autostartElapsedTimer->restart();
}
void handleAutostartTimerTimeout() {
}
@ -159,6 +177,7 @@ bool LinboBackend::startCurrentOs() {
this->setState(Starting);
return true;
this->executeCommand(
false,
"start",
@ -284,6 +303,10 @@ bool LinboBackend::updateLinbo() {
return true;
}
LinboLogger* LinboBackend::getLogger() {
return this->logger;
}
LinboConfig* LinboBackend::getConfig() {
return this->config;
}
@ -304,13 +327,22 @@ void LinboBackend::setCurrentOs(LinboOs* os) {
emit this->currentOsChanged(os);
}
double LinboBackend::getAutostartTimeoutProgress() {
return this->autostartElapsedTimer->elapsed() / this->autostartTimer->interval();
}
int LinboBackend::getAutostartTimeoutRemainingSeconds() {
return (this->autostartTimer->interval() - this->autostartElapsedTimer->elapsed()) / 1000;
}
// -----------
// - Helpers -
// -----------
QString LinboBackend::executeCommand(bool waitForFinished, QString command, QStringList commandArgs) {
qDebug() << "Executing " << (waitForFinished ? "synchronos":"asynchronos") << ": " << command << " " << commandArgs.join(" ");
this->logger->log("Executing " + QString(waitForFinished ? "synchronos":"asynchronos") + ": " + command + " " + commandArgs.join(" "), LinboLogger::LinboGuiInfo);
if(waitForFinished) {
// clear old output
@ -332,11 +364,19 @@ QString LinboBackend::executeCommand(bool waitForFinished, QString command, QStr
void LinboBackend::readFromStdout() {
qDebug() << "OUT: " << this->asynchronosProcess->readAllStandardOutput();
QString stdOut = this->asynchronosProcess->readAllStandardOutput();
QStringList lines = stdOut.split("\n");
for(QString line : lines) {
this->logger->log(line, LinboLogger::StdOut);
}
}
void LinboBackend::readFromStderr() {
qDebug() << "ERR: " << this->asynchronosProcess->readAllStandardError();
QString stdOut = this->asynchronosProcess->readAllStandardError();
QStringList lines = stdOut.split("\n");
for(QString line : lines) {
this->logger->log(line, LinboLogger::StdErr);
}
}
LinboBackend::LinboState LinboBackend::getState() {
@ -377,7 +417,6 @@ LinboOs* LinboBackend::read_os(ifstream* input) {
LinboOs* os = new LinboOs(this);
QString key, value;
while(!input->eof() && read_pair(input, key, value)) {
qDebug() << key << "=" << value;
if(key.compare("name") == 0) os->setName(value);
else if(key.compare("description") == 0) os->setDescription(value);
else if(key.compare("version") == 0) os->setVersion(value);

View File

@ -0,0 +1,34 @@
#include "../../headers/backend/linbologger.h"
LinboLogger::LinboLogger(QObject *parent) : QObject(parent)
{
}
QString LinboLogger::logTypeToString(LinboLogType logType) {
switch (logType) {
case StdErr:
return "StrErr";
case StdOut:
return "StdOut";
case LinboGuiInfo:
return "Info";
case LinboGuiError:
return "Error";
default:
return "UNKNOW";
}
}
void LinboLogger::log(QString logText, LinboLogType logType) {
if(logText.isEmpty() || logText == "")
return;
qDebug() << qPrintable("[" + this->logTypeToString(logType) + "]") << logText;
LinboLog latestLog {logText, logType, QDateTime::currentDateTime()};
this->logHistory.append(latestLog);
emit this->latestLogChanged(latestLog);
}
const LinboLogger::LinboLog& LinboLogger::getLatestLog() {
return this->logHistory.last();
}

View File

@ -1504,7 +1504,7 @@ void linboGUIImpl::resetButtons() {
}
void linboGUIImpl::executeAutostart() {
return; // autostart is handles by new GUI
return; // autostart is handled by new backend
// if there is "autopartition" set, execute the hidden button
if( autopartition )
autopartition->lclicked();
@ -1543,6 +1543,7 @@ void linboGUIImpl::executeAutostart() {
}
void linboGUIImpl::autostartTimeoutSlot() {
return; // autostart is handled by new backend
if( !myCounter->timeoutCheck->isChecked() ) {
// do nothing but dont stop timer
}

View File

@ -29,7 +29,9 @@ LinboGui::LinboGui()
this->setFixedHeight(QApplication::desktop()->screenGeometry().height());
this->setFixedWidth(QApplication::desktop()->screenGeometry().width());
qDebug() << this->geometry();
QFontDatabase db;
qDebug() << QFontDatabase::addApplicationFont(":/fonts/SegoeUI.ttf");
qDebug() << db.families();
// white bakground
// linuxmuster background color: #394f5e

View File

@ -5,6 +5,7 @@ LinboStartActions::LinboStartActions(LinboBackend* backend, QWidget *parent) : Q
this->backend = backend;
connect(this->backend, SIGNAL(currentOsChanged(LinboOs*)), this, SLOT(handleCurrentOsChanged(LinboOs*)));
connect(this->backend, SIGNAL(stateChanged(LinboBackend::LinboState)), this, SLOT(handleLinboStateChanged(LinboBackend::LinboState)));
connect(this->backend->getLogger(), SIGNAL(latestLogChanged(const LinboLogger::LinboLog&)), this, SLOT(handleLatestLogChanged(const LinboLogger::LinboLog&)));
this->stackView = new QModernStackedWidget(this);
@ -28,6 +29,13 @@ LinboStartActions::LinboStartActions(LinboBackend* backend, QWidget *parent) : Q
this->progressBarWidget = new QWidget();
this->progressBar = new QModernProgressBar(this->progressBarWidget);
this->progressBar->setIndeterminate(true);
this->logLabel = new QLabel("", this->progressBarWidget);
this->logLabel->setAlignment(Qt::AlignCenter);
this->logFont = QFont("Segoe UI");
this->logLabel->setFont(this->logFont);
this->stackView->addWidget(this->progressBarWidget);
connect(this->stackView, SIGNAL(currentChanged(int)), this, SLOT(resizeAndPositionAllItems()));
@ -142,7 +150,13 @@ void LinboStartActions::resizeAndPositionAllItems() {
this->progressBarWidget->setFixedSize(this->size());
int progressBarHeight = this->height() * 0.1;
int progressBarWidth = this->width() * 0.5;
progressBar->setGeometry((this->width() - progressBarWidth) / 2, (this->height() - progressBarHeight) / 2, progressBarWidth, progressBarHeight);
int logLabelHeight = progressBarHeight * 2;
int logLabelWidth = this->width() * 0.8;
progressBar->setGeometry((this->width() - progressBarWidth) / 2, (this->height() - logLabelHeight - progressBarHeight) / 2, progressBarWidth, progressBarHeight);
this->logFont.setPixelSize(logLabelHeight * 0.8);
this->logLabel->setFont(this->logFont);
this->logLabel->setGeometry((this->width() - logLabelWidth) / 2, this->height() - logLabelHeight, logLabelWidth, logLabelHeight);
this->inited = true;
}
@ -173,3 +187,20 @@ void LinboStartActions::handleLinboStateChanged(LinboBackend::LinboState newStat
break;
}
}
void LinboStartActions::handleLatestLogChanged(const LinboLogger::LinboLog& latestLog) {
QString logColor = "black";
switch (latestLog.type) {
case LinboLogger::StdErr:
logColor = this->backend->getConfig()->getConsoleFontcolorStderr();
break;
case LinboLogger::StdOut:
// TODO?? logColor = this->backend->getConfig()->getConsoleFontcolorStdout();
break;
default:
break;
}
this->logLabel->setStyleSheet("QLabel { color : " + logColor + "; }");
this->logLabel->setText(latestLog.message);
}

View File

@ -55,6 +55,7 @@ LinboStartPage::LinboStartPage(LinboBackend* backend, QWidget *parent) : QWidget
mainLayout->addItem(new QSpacerItem(0,0, QSizePolicy::Minimum, QSizePolicy::Expanding));
QLabel* versionLabel = new QLabel(backend->getConfig()->getVersion() + " - mod by Dorian Zedler");
versionLabel->setFont(QFont("Segoe UI"));
mainLayout->addWidget(versionLabel);
@ -63,7 +64,7 @@ LinboStartPage::LinboStartPage(LinboBackend* backend, QWidget *parent) : QWidget
int height = this->height() * 0.2;
int width = height / 3;
int margins = width * 0.1;
int buttonWidth = width * 0.8;
int buttonWidth = width * 0.6;
powerActionsLayoutWidget->setGeometry(QRect(this->width() - (width + margins), this->height() - (height + margins), width * 1.1, height));
QModernPushButton* settingsActionButton = new QModernPushButton(":/svgIcons/settingsAction.svg");

View File

@ -100,7 +100,7 @@ void QModernPushButton::keyReleaseEvent(QKeyEvent *e) {
void QModernPushButton::enterEvent(QEvent *e) {
if(this->overlays.length() >= 2)
if(this->overlays.length() >= 2 && this->isEnabled())
this->overlays[1]->setVisible(true);
return QAbstractButton::enterEvent(e);
}
@ -112,7 +112,7 @@ void QModernPushButton::leaveEvent(QEvent *e) {
}
void QModernPushButton::mousePressEvent(QMouseEvent *e) {
if(this->overlays.length() >= 3)
if(this->overlays.length() >= 3 && this->isEnabled())
this->overlays[2]->setVisible(true);
return QAbstractButton::mousePressEvent(e);
}