- added some fancy animations to the start action buttons

- Made everything depend on the LinboBackend state
This commit is contained in:
Dorian Zedler 2020-11-23 11:57:51 +01:00
parent ba722f1634
commit c01d1b884d
Signed by: dorian
GPG key ID: D3B255CB8BC7CD37
15 changed files with 369 additions and 259 deletions

View file

@ -40,38 +40,36 @@ using namespace std;
class LinboBackend : public QObject class LinboBackend : public QObject
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY(LinboState state READ getState NOTIFY stateChanged) Q_PROPERTY(LinboBackend::LinboState state READ getState NOTIFY stateChanged)
Q_PROPERTY(LinboOs* currentOs READ getCurrentOs WRITE setCurrentOs NOTIFY currentOsChanged)
public: public:
explicit LinboBackend(QObject *parent = nullptr); explicit LinboBackend(QObject *parent = nullptr);
enum LinboState { enum LinboState {
Initializing,
Idle, Idle,
Root,
Partitioning,
Starting, Starting,
Syncing, Syncing,
Reinstalling Reinstalling,
Root,
Partitioning,
InitializingCache,
Updating
}; };
LinboState getState(); LinboState getState();
LinboConfig* getConfig(); LinboConfig* getConfig();
QList<LinboOs*> getOperatingSystems(); QList<LinboOs*> getOperatingSystems();
LinboOs* getCurrentOs();
void setCurrentOs(LinboOs* os);
protected: 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 read_pair(ifstream* input, QString& key, QString& value);
bool toBool(const QString& value); bool toBool(const QString& value);
LinboOs* read_os(ifstream* input); LinboOs* read_os(ifstream* input);
LinboDiskPartition* read_partition(ifstream* input); LinboDiskPartition* read_partition(ifstream* input);
void read_globals( ifstream* input, LinboConfig* config ); 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);
void setState(LinboState state);
private: private:
LinboState state; LinboState state;
@ -80,12 +78,26 @@ private:
QList<LinboOs*> operatingSystems; QList<LinboOs*> operatingSystems;
QList<LinboDiskPartition*> diskPartitions; QList<LinboDiskPartition*> diskPartitions;
QProcess* process; LinboOs* currentOs;
QString executeCommand(bool waitForFinished); QString const linboCmdCommand = "linbo_cmd";
QProcess* asynchronosProcess;
QProcess* synchronosProcess;
template<typename ... Strings> template<typename ... Strings>
QString executeCommand(bool waitForFinished, QString argument, const Strings&... arguments) { 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<typename ... Strings>
QStringList buildCommand(QString argument, const Strings&... arguments) {
// this appends a quoted space in case item is empty and resolves // this appends a quoted space in case item is empty and resolves
// problems with linbo_cmd's weird "shift"-usage // problems with linbo_cmd's weird "shift"-usage
if (argument.isEmpty()) if (argument.isEmpty())
@ -93,25 +105,33 @@ private:
else else
this->linboCommandCache.append(argument); this->linboCommandCache.append(argument);
return executeCommand(waitForFinished, arguments...); return buildCommand(arguments...);
} }
void readFromStdout();
void readFromStderr();
QString executeCommand(bool wait, QString command, QStringList commandArgs); QString executeCommand(bool wait, QString command, QStringList commandArgs);
void setState(LinboState state);
public slots: public slots:
void executeAutostart();
void shutdown(); void shutdown();
void reboot(); void reboot();
bool startOs(LinboOs* os); bool startCurrentOs();
bool syncOs(LinboOs* os); bool syncCurrentOs();
bool reinstallOs(LinboOs* os); bool reinstallCurrentOs();
bool partitionDrive(bool format = true);
bool initializeCache();
bool updateLinbo();
private slots:
void executeAutostart();
void readFromStdout();
void readFromStderr();
signals: signals:
void stateChanged(); void stateChanged(LinboBackend::LinboState state);
void currentOsChanged(LinboOs* os);
}; };

View file

@ -34,7 +34,6 @@ class LinboOsSelectButton : public QWidget
public: public:
friend class LinboOsSelectionRow; friend class LinboOsSelectionRow;
protected: protected:
void resizeEvent(QResizeEvent *event) override; void resizeEvent(QResizeEvent *event) override;

View file

@ -28,8 +28,11 @@ private:
private slots: private slots:
void resizeAndPositionAllButtons(); void resizeAndPositionAllButtons();
void handleButtonToggled(bool checked);
void handleLinboStateChanged(LinboBackend::LinboState newState);
signals: signals:
void selectedOsChanged();
}; };

View file

@ -17,14 +17,13 @@ class LinboStartActions : public QWidget
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit LinboStartActions(LinboBackend* backend, LinboOsSelectionRow* osSelectionRow, QWidget *parent = nullptr); explicit LinboStartActions(LinboBackend* backend, QWidget *parent = nullptr);
protected: protected:
void resizeEvent(QResizeEvent *event) override; void resizeEvent(QResizeEvent *event) override;
private: private:
LinboBackend* backend; LinboBackend* backend;
LinboOsSelectionRow* osSelectionRow;
QModernStackedWidget* stackView; QModernStackedWidget* stackView;
@ -37,12 +36,12 @@ private:
QWidget* progressBarWidget; QWidget* progressBarWidget;
QModernProgressBar* progressBar; QModernProgressBar* progressBar;
void resizeAndPositionAllItems(); bool inited;
private slots: private slots:
void executeStartAction(); void resizeAndPositionAllItems();
void executeSyncAction(); void handleCurrentOsChanged(LinboOs* newOs);
void executeReinstallAction(); void handleLinboStateChanged(LinboBackend::LinboState newState);
signals: signals:
void selectedOsChanged(); void selectedOsChanged();

View file

@ -44,9 +44,10 @@ private:
LinboBackend* backend; LinboBackend* backend;
LinboOsSelectionRow* osSelectionRow; LinboOsSelectionRow* osSelectionRow;
LinboStartActions* startActionsWidget; LinboStartActions* startActionsWidget;
QList<QModernPushButton*> powerActionButtons;
private slots: private slots:
void startOs(); void handleLinboStateChanged(LinboBackend::LinboState newState);
signals: signals:

View file

@ -38,8 +38,9 @@ class QModernPushButton : public QAbstractButton
public: public:
QModernPushButton(QString icon, QWidget* parent = nullptr); QModernPushButton(QString icon, QWidget* parent = nullptr);
void setVisible(bool visible) override; void setVisibleAnimated(bool visible, bool asynchronos = true);
void setVisible(bool visible, bool animated, bool asynchronos = true);
void setGeometryAnimated(const QRect& geometry);
protected: protected:
void resizeEvent(QResizeEvent *event) override; void resizeEvent(QResizeEvent *event) override;
@ -52,11 +53,14 @@ protected:
void mouseReleaseEvent(QMouseEvent *e) override; void mouseReleaseEvent(QMouseEvent *e) override;
private: private:
QGraphicsOpacityEffect* opacityEffect; QPropertyAnimation* geometryAnimation;
QList<QModernPushButtonOverlay*> overlays; QList<QModernPushButtonOverlay*> overlays;
private slots: private slots:
void handleToggled(bool checked); void handleToggled(bool checked);
signals:
void checked();
}; };
#endif // QMODERNPUSHBUTTON_H #endif // QMODERNPUSHBUTTON_H

View file

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject> <!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 4.13.2, 2020-11-16T18:00:23. --> <!-- Written by QtCreator 4.13.2, 2020-11-22T18:36:02. -->
<qtcreator> <qtcreator>
<data> <data>
<variable>EnvironmentId</variable> <variable>EnvironmentId</variable>

View file

@ -24,8 +24,9 @@ using namespace std;
LinboBackend::LinboBackend(QObject *parent) : QObject(parent) LinboBackend::LinboBackend(QObject *parent) : QObject(parent)
{ {
this->setState(Initializing);
this->config = new LinboConfig(this); this->config = new LinboConfig(this);
this->currentOs = nullptr;
// read start.conf // read start.conf
qDebug() << "Starting to parse start.conf"; qDebug() << "Starting to parse start.conf";
@ -38,7 +39,10 @@ LinboBackend::LinboBackend(QObject *parent) : QObject(parent)
// *** Image description section *** // *** Image description section ***
// entry in start tab // entry in start tab
read_qstring(&input, tmp_qstring); char line[500];
input.getline(line,500,'\n');
tmp_qstring = QString::fromAscii( line, -1 ).stripWhiteSpace();
if ( tmp_qstring.startsWith("#") || tmp_qstring.isEmpty() ) continue; if ( tmp_qstring.startsWith("#") || tmp_qstring.isEmpty() ) continue;
tmp_qstring = tmp_qstring.section("#",0,0).stripWhiteSpace(); // Strip comment tmp_qstring = tmp_qstring.section("#",0,0).stripWhiteSpace(); // Strip comment
@ -46,6 +50,10 @@ LinboBackend::LinboBackend(QObject *parent) : QObject(parent)
LinboOs* tmpOs = read_os(&input); LinboOs* tmpOs = read_os(&input);
if(!tmpOs->getName().isEmpty()) { if(!tmpOs->getName().isEmpty()) {
this->operatingSystems.append(tmpOs); this->operatingSystems.append(tmpOs);
if(tmpOs->getAutostart() && this->currentOs == nullptr)
this->currentOs = tmpOs;
// check if this is an additional/incremental image for an existing OS // check if this is an additional/incremental image for an existing OS
/* TODO unsigned int i; // Being checked later. /* TODO unsigned int i; // Being checked later.
for(i = 0; i < elements.size(); i++ ) { for(i = 0; i < elements.size(); i++ ) {
@ -75,17 +83,24 @@ LinboBackend::LinboBackend(QObject *parent) : QObject(parent)
} }
input.close(); 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() << "Finished parsing start.conf";
qDebug() << "Loading global configuration"; qDebug() << "Loading global configuration";
// load global config // load global config
QStringList command; QStringList command;
this->process = new QProcess(); // ascynchorons commands are logged to logger
/* connect( process, SIGNAL(readyReadStandardOutput()), this->asynchronosProcess = new QProcess();
connect( asynchronosProcess, SIGNAL(readyReadStandardOutput()),
this, SLOT(readFromStdout()) ); this, SLOT(readFromStdout()) );
connect( process, SIGNAL(readyReadStandardError()), connect( asynchronosProcess, SIGNAL(readyReadStandardError()),
this, SLOT(readFromStderr()) ); this, SLOT(readFromStderr()) );
*/
// synchronos commands are not logged
this->synchronosProcess = new QProcess();
// client ip // client ip
this->config->setIpAddress(this->executeCommand(true, "ip")); this->config->setIpAddress(this->executeCommand(true, "ip"));
@ -113,8 +128,10 @@ LinboBackend::LinboBackend(QObject *parent) : QObject(parent)
QString hd = this->config->getCache(); QString hd = this->config->getCache();
// e.g. turn /dev/sda1 into /dev/sda // e.g. turn /dev/sda1 into /dev/sda
hd.remove( *removePartition ); hd.remove( *removePartition );
this->config->setHddSize(this->executeCommand(true, "size", hd)); this->config->setHddSize(this->executeCommand(true, "size", hd));
qDebug() << "Finished loading global configuration";
this->setState(Idle);
} }
// -------------------- // --------------------
@ -133,12 +150,15 @@ void LinboBackend::reboot() {
this->executeCommand(false, "busybox", QStringList("reboot")); this->executeCommand(false, "busybox", QStringList("reboot"));
} }
bool LinboBackend::startOs(LinboOs* os) { bool LinboBackend::startCurrentOs() {
if(os == nullptr || this->state != Idle) LinboOs* os = this->currentOs;
if(os == nullptr || this->state != Idle || !this->currentOs->getStartbutton())
return false; return false;
this->setState(Starting); this->setState(Starting);
return true;
this->executeCommand( this->executeCommand(
false, false,
"start", "start",
@ -153,8 +173,10 @@ bool LinboBackend::startOs(LinboOs* os) {
return true; return true;
} }
bool LinboBackend::syncOs(LinboOs* os) { bool LinboBackend::syncCurrentOs() {
if(os == nullptr || this->state != Idle) LinboOs* os = this->currentOs;
if(os == nullptr || this->state != Idle || !this->currentOs->getSyncbutton())
return false; return false;
this->setState(Syncing); this->setState(Syncing);
@ -176,8 +198,10 @@ bool LinboBackend::syncOs(LinboOs* os) {
return true; return true;
} }
bool LinboBackend::reinstallOs(LinboOs* os) { bool LinboBackend::reinstallCurrentOs() {
if(os == nullptr || this->state != Idle) LinboOs* os = this->currentOs;
if(os == nullptr || this->state != Idle || !this->currentOs->getNewbutton())
return false; return false;
this->setState(Reinstalling); this->setState(Reinstalling);
@ -200,6 +224,66 @@ bool LinboBackend::reinstallOs(LinboOs* os) {
return true; return true;
} }
bool LinboBackend::partitionDrive(bool format) {
if(this->state != Root)
return false;
this->setState(Partitioning);
QStringList commandArgs = QStringList(format ? "partition":"partition_noformat");
for( int i=0; i < this->diskPartitions.length(); i++) {
LinboDiskPartition* p = this->diskPartitions[i];
commandArgs.append(
this->buildCommand(
p->getPath(),
QString::number(p->getSize()),
p->getId(),
QString((p->getBootable())?"bootable":"\" \""),
p->getFstype()
)
);
}
this->executeCommand(false, this->linboCmdCommand, commandArgs);
return true;
}
bool LinboBackend::initializeCache() {
if(this->state != Root)
return false;
this->setState(InitializingCache);
QStringList commandArgs = this->buildCommand("initcache", config->getServer(), config->getCache());
if( this->config->getDownloadType().isEmpty() )
commandArgs.append(this->config->getDownloadType());
else
commandArgs.append("rsync");
for(int i = 0; i < this->operatingSystems.length(); i++) {
LinboOs* os = this->operatingSystems[i];
commandArgs.append(this->buildCommand(os->getBaseImage()->getName(), os->getDifferentialImage()->getName()));
/* TODO ?? for(unsigned int j = 0; j < os[i].image_history.size(); j++) {
saveappend( command, os[i].image_history[j].get_image() );
}*/
}
this->executeCommand(false, this->linboCmdCommand, commandArgs);
return true;
}
bool LinboBackend::updateLinbo() {
if(this->state != Root)
return false;
this->executeCommand("update", this->config->getServer(), this->config->getCache());
return true;
}
LinboConfig* LinboBackend::getConfig() { LinboConfig* LinboBackend::getConfig() {
return this->config; return this->config;
} }
@ -208,36 +292,52 @@ QList<LinboOs*> LinboBackend::getOperatingSystems() {
return this->operatingSystems; return this->operatingSystems;
} }
LinboOs* LinboBackend::getCurrentOs() {
return this->currentOs;
}
void LinboBackend::setCurrentOs(LinboOs* os) {
if(this->state != Idle || !this->operatingSystems.contains(os) || this->currentOs == os)
return;
this->currentOs = os;
emit this->currentOsChanged(os);
}
// ----------- // -----------
// - Helpers - // - Helpers -
// ----------- // -----------
QString LinboBackend::executeCommand(bool waitForFinished) {
QStringList tmpList = this->linboCommandCache;
this->linboCommandCache.clear();
return this->executeCommand(waitForFinished, "linbo_cmd", tmpList);
}
QString LinboBackend::executeCommand(bool waitForFinished, QString command, QStringList commandArgs) { QString LinboBackend::executeCommand(bool waitForFinished, QString command, QStringList commandArgs) {
if(waitForFinished) qDebug() << "Executing " << (waitForFinished ? "synchronos":"asynchronos") << ": " << command << " " << commandArgs.join(" ");
// clear old output
this->process->readAll();
qDebug() << "Executing: " << command << " " << commandArgs.join(" ");
process->start(command, commandArgs);
process->waitForStarted();
if(waitForFinished) { if(waitForFinished) {
while( !process->waitForFinished(10000) ) {} // clear old output
return this->process->readAllStandardOutput(); this->synchronosProcess->readAll();
synchronosProcess->start(command, commandArgs);
synchronosProcess->waitForStarted();
while( !synchronosProcess->waitForFinished(10000) ) {}
return this->synchronosProcess->readAllStandardOutput();
} }
else {
asynchronosProcess->start(command, commandArgs);
asynchronosProcess->waitForStarted();
return ""; return "";
} }
}
void LinboBackend::readFromStdout() {
qDebug() << "OUT: " << this->asynchronosProcess->readAllStandardOutput();
}
void LinboBackend::readFromStderr() {
qDebug() << "ERR: " << this->asynchronosProcess->readAllStandardError();
}
LinboBackend::LinboState LinboBackend::getState() { LinboBackend::LinboState LinboBackend::getState() {
return this->state; return this->state;
@ -248,19 +348,7 @@ void LinboBackend::setState(LinboState state) {
return; return;
this->state = state; this->state = state;
emit this->stateChanged(); emit this->stateChanged(this->state);
}
void LinboBackend::read_qstring( ifstream* input, QString& tmp ) {
char line[500];
input->getline(line,500,'\n');
tmp = QString::fromAscii( line, -1 ).stripWhiteSpace();
}
void LinboBackend::read_bool( ifstream* input, bool& tmp) {
char line[500];
input->getline(line,500,'\n');
tmp = atoi( line );
} }
// Return true unless beginning of new section '[' is found. // Return true unless beginning of new section '[' is found.
@ -347,53 +435,3 @@ void LinboBackend::read_globals( ifstream* input, LinboConfig* config ) {
else if(key.compare("downloadtype") == 0) config->setDownloadType(value); else if(key.compare("downloadtype") == 0) config->setDownloadType(value);
} }
} }
QStringList LinboBackend::mkpartitioncommand(vector <LinboDiskPartition> &p) {
QStringList command = LINBO_CMD("partition");
for(unsigned int i=0; i<p.size(); i++) {
saveappend( command, p[i].getPath() );
saveappend( command, (QString::number(p[i].getSize())) );
saveappend( command, p[i].getId() );
saveappend( command, (QString((p[i].getBootable())?"bootable":"\" \"")) );
saveappend( command, p[i].getFstype() );
}
return command;
}
QStringList LinboBackend::mkpartitioncommand_noformat(vector <LinboDiskPartition> &p) {
QStringList command = LINBO_CMD("partition_noformat");
for(unsigned int i=0; i<p.size(); i++) {
saveappend( command, p[i].getPath() );
saveappend( command, (QString::number(p[i].getSize())) );
saveappend( command, p[i].getId() );
saveappend( command, (QString((p[i].getBootable())?"bootable":"\" \"")) );
saveappend( command, p[i].getFstype() );
}
return command;
}
// type is 0 for rsync, 1 for multicast, 3 for bittorrent
QStringList LinboBackend::mkcacheinitcommand(LinboConfig& config, vector<LinboOs> &os, const QString& type) {
QStringList command = LINBO_CMD("initcache");
saveappend( command, config.getServer() );
saveappend( command, config.getCache() );
if( ! type.isEmpty() )
command.append(type);
else
command.append("rsync");
for(unsigned int i = 0; i < os.size(); i++) {
saveappend( command, os[i].getBaseImage()->getName() );
/* TODO ?? for(unsigned int j = 0; j < os[i].image_history.size(); j++) {
saveappend( command, os[i].image_history[j].get_image() );
}*/
}
return command;
}
QStringList LinboBackend::mklinboupdatecommand(LinboConfig& config) {
QStringList command = LINBO_CMD("update");
saveappend( command, config.getServer() );
saveappend( command, config.getCache() );
return command;
}

View file

@ -1,4 +1,4 @@
#define NEVERDEF //#define NEVERDEF
#ifdef NEVERDEF #ifdef NEVERDEF
/* class building the LINBO GUI /* class building the LINBO GUI

View file

@ -36,10 +36,10 @@ LinboOs* LinboOsSelectButton::getOs() {
} }
void LinboOsSelectButton::setVisible(bool visible) { void LinboOsSelectButton::setVisible(bool visible) {
this->button->setVisible(visible, true, true); this->button->setVisibleAnimated(visible, true);
} }
void LinboOsSelectButton::resizeEvent(QResizeEvent *event) { void LinboOsSelectButton::resizeEvent(QResizeEvent *event) {
qDebug() << "Resize: width: " << event->size().width() << " height: " << event->size().height(); //qDebug() << "Resize: width: " << event->size().width() << " height: " << event->size().height();
this->button->setGeometry(QRect(event->size().width() / 2 - event->size().height() / 2 , 0, event->size().height(), event->size().height())); this->button->setGeometry(QRect(event->size().width() / 2 - event->size().height() / 2 , 0, event->size().height(), event->size().height()));
} }

View file

@ -3,24 +3,26 @@
LinboOsSelectionRow::LinboOsSelectionRow(LinboBackend* backend, QWidget *parent) : QWidget(parent) LinboOsSelectionRow::LinboOsSelectionRow(LinboBackend* backend, QWidget *parent) : QWidget(parent)
{ {
this->backend = backend; this->backend = backend;
this->showOnlySelectedButton = false; connect(this->backend, SIGNAL(stateChanged(LinboBackend::LinboState)), this, SLOT(handleLinboStateChanged(LinboBackend::LinboState)));
this->showOnlySelectedButton = false;
this->osButtonGroup = new QButtonGroup(); this->osButtonGroup = new QButtonGroup();
this->osButtonGroup->setExclusive(true); this->osButtonGroup->setExclusive(true);
for(LinboOs* os : backend->getOperatingSystems()) { for(LinboOs* os : backend->getOperatingSystems()) {
LinboOsSelectButton* osButton = new LinboOsSelectButton("/icons/" + os->getIconName(), os, this->osButtonGroup, this); LinboOsSelectButton* osButton = new LinboOsSelectButton("/icons/" + os->getIconName(), os, this->osButtonGroup, this);
connect(osButton->button, SIGNAL(toggled(bool)), this, SLOT(handleButtonToggled(bool)));
// auto select current OS
if(this->backend->getCurrentOs() == os)
osButton->button->setChecked(true);
this->osButtons.append(osButton); this->osButtons.append(osButton);
} }
// TODO: figure out by autostart
this->osButtonGroup->buttons()[0]->setChecked(true);
} }
void LinboOsSelectionRow::resizeAndPositionAllButtons() { void LinboOsSelectionRow::resizeAndPositionAllButtons() {
qDebug() << "Resizing all Buttons";
int buttonWidth = this->width() / this->osButtonGroup->buttons().length(); int buttonWidth = this->width() / this->osButtonGroup->buttons().length();
if(this->showOnlySelectedButton) { if(this->showOnlySelectedButton) {
for(int i = 0; i < this->osButtons.length(); i++) { for(int i = 0; i < this->osButtons.length(); i++) {
@ -43,6 +45,11 @@ void LinboOsSelectionRow::resizeAndPositionAllButtons() {
} }
} }
void LinboOsSelectionRow::handleButtonToggled(bool checked) {
if(checked)
this->backend->setCurrentOs(this->getSelectedOs());
}
LinboOs* LinboOsSelectionRow::getSelectedOs() { LinboOs* LinboOsSelectionRow::getSelectedOs() {
for(LinboOsSelectButton* button : this->osButtons) { for(LinboOsSelectButton* button : this->osButtons) {
if(button->button->isChecked()) if(button->button->isChecked())
@ -65,6 +72,23 @@ void LinboOsSelectionRow::setShowOnlySelectedButton(bool value) {
void LinboOsSelectionRow::resizeEvent(QResizeEvent *event) { void LinboOsSelectionRow::resizeEvent(QResizeEvent *event) {
QWidget::resizeEvent(event); QWidget::resizeEvent(event);
qDebug() << "RESIZE EVENT: width: " << width() << " height: " << height(); //qDebug() << "RESIZE EVENT: width: " << width() << " height: " << height();
this->resizeAndPositionAllButtons(); this->resizeAndPositionAllButtons();
} }
void LinboOsSelectionRow::handleLinboStateChanged(LinboBackend::LinboState newState) {
switch (newState) {
case LinboBackend::Idle:
this->setShowOnlySelectedButton(false);
break;
case LinboBackend::Starting:
case LinboBackend::Syncing:
case LinboBackend::Reinstalling:
this->setShowOnlySelectedButton(true);
break;
default:
break;
}
}

View file

@ -1,30 +1,36 @@
#include "../headers/linbostartactions.h" #include "../headers/linbostartactions.h"
LinboStartActions::LinboStartActions(LinboBackend* backend, LinboOsSelectionRow* osSelectionRow, QWidget *parent) : QWidget(parent) LinboStartActions::LinboStartActions(LinboBackend* backend, QWidget *parent) : QWidget(parent)
{ {
this->backend = backend; this->backend = backend;
this->osSelectionRow = osSelectionRow; connect(this->backend, SIGNAL(currentOsChanged(LinboOs*)), this, SLOT(handleCurrentOsChanged(LinboOs*)));
connect(this->backend, SIGNAL(stateChanged(LinboBackend::LinboState)), this, SLOT(handleLinboStateChanged(LinboBackend::LinboState)));
stackView = new QModernStackedWidget(this); this->stackView = new QModernStackedWidget(this);
this->inited = false;
// Action Buttons // Action Buttons
this->buttonWidget = new QWidget(); this->buttonWidget = new QWidget();
startOsButton = new QModernPushButton(":/svgIcons/startAction.svg", this->buttonWidget);
connect(startOsButton, SIGNAL(clicked()), this, SLOT(executeStartAction()));
syncOsButton = new QModernPushButton(":/svgIcons/syncAction.svg", this->buttonWidget);
reinstallOsButton = new QModernPushButton(":/svgIcons/resetAction.svg", this->buttonWidget);
this->stackView->addWidget(this->buttonWidget);
actionButtons.append(startOsButton); this->startOsButton = new QModernPushButton(":/svgIcons/startAction.svg", this->buttonWidget);
actionButtons.append(syncOsButton); connect(this->startOsButton, SIGNAL(clicked()), this->backend, SLOT(startCurrentOs()));
actionButtons.append(reinstallOsButton);
this->syncOsButton = new QModernPushButton(":/svgIcons/syncAction.svg", this->buttonWidget);
connect(this->syncOsButton, SIGNAL(clicked()), this->backend, SLOT(syncCurrentOs()));
this->reinstallOsButton = new QModernPushButton(":/svgIcons/resetAction.svg", this->buttonWidget);
connect(this->reinstallOsButton, SIGNAL(clicked()), this->backend, SLOT(reinstallCurrentOs()));
this->stackView->addWidget(this->buttonWidget);
// Progress bar // Progress bar
this->progressBarWidget = new QWidget(); this->progressBarWidget = new QWidget();
progressBar = new QModernProgressBar(this->progressBarWidget); this->progressBar = new QModernProgressBar(this->progressBarWidget);
progressBar->setIndeterminate(true); this->progressBar->setIndeterminate(true);
this->stackView->addWidget(this->progressBarWidget); this->stackView->addWidget(this->progressBarWidget);
connect(this->stackView, SIGNAL(currentChanged(int)), this, SLOT(resizeAndPositionAllItems()));
this->stackView->setCurrentWidget(this->buttonWidget); this->stackView->setCurrentWidget(this->buttonWidget);
} }
@ -35,14 +41,14 @@ void LinboStartActions::resizeAndPositionAllItems() {
// Action buttons // Action buttons
// bring buttons in correct order: // bring buttons in correct order:
LinboOs* selectedOs = this->osSelectionRow->getSelectedOs(); LinboOs* selectedOs = this->backend->getCurrentOs();
LinboOs::LinboOsStartAction defaultAction = selectedOs->getDefaultAction(); LinboOs::LinboOsStartAction defaultAction = LinboOs::UnknownAction;
if(selectedOs != nullptr)
defaultAction = selectedOs->getDefaultAction();
int syncOsPosition = 2;
int startOsPosition = 0; int startOsPosition = 0;
int syncOsPosition = 1; int reinstallOsPosition = 1;
int reinstallOsPosition = 2;
qDebug() << "Default action is: " << defaultAction;
switch (defaultAction) { switch (defaultAction) {
case LinboOs::StartOs: case LinboOs::StartOs:
@ -53,21 +59,16 @@ void LinboStartActions::resizeAndPositionAllItems() {
reinstallOsPosition = 2; reinstallOsPosition = 2;
break; break;
case LinboOs::ReinstallOs: case LinboOs::ReinstallOs:
reinstallOsPosition = 0;
syncOsPosition = 1; syncOsPosition = 1;
startOsPosition = 2; startOsPosition = 2;
reinstallOsPosition = 0;
break; break;
default: default:
break; break;
} }
//this->actionButtons.move(this->actionButtons.indexOf(this->startOsButton), startOsPosition); while (this->actionButtons.length() < 3)
//this->actionButtons.move(this->actionButtons.indexOf(this->syncOsButton), syncOsPosition);
//this->actionButtons.move(this->actionButtons.indexOf(this->reinstallOsButton), reinstallOsPosition);
while (this->actionButtons.length() < 3) {
this->actionButtons.append(nullptr); this->actionButtons.append(nullptr);
}
this->actionButtons[startOsPosition] = this->startOsButton; this->actionButtons[startOsPosition] = this->startOsButton;
this->actionButtons[syncOsPosition] = this->syncOsButton; this->actionButtons[syncOsPosition] = this->syncOsButton;
@ -75,54 +76,66 @@ void LinboStartActions::resizeAndPositionAllItems() {
// check for disabled actions // check for disabled actions
QList<bool> positionsEnabled; QList<bool> positionsEnabled;
positionsEnabled.append(true); while(positionsEnabled.length() < 3)
positionsEnabled.append(true); positionsEnabled.append(false);
positionsEnabled.append(true);
if(selectedOs != nullptr) {
positionsEnabled[startOsPosition] = selectedOs->getStartbutton(); positionsEnabled[startOsPosition] = selectedOs->getStartbutton();
positionsEnabled[syncOsPosition] = selectedOs->getSyncbutton(); positionsEnabled[syncOsPosition] = selectedOs->getSyncbutton();
positionsEnabled[reinstallOsPosition] = selectedOs->getNewbutton(); positionsEnabled[reinstallOsPosition] = selectedOs->getNewbutton();
}
QList<QRect> geometries;
while (geometries.length() < 3)
geometries.append(QRect());
// move buttons into place // move buttons into place
this->buttonWidget->setFixedSize(this->size()); this->buttonWidget->setFixedSize(this->size());
int buttonSpacing = this->height() * 0.1; int buttonSpacing = this->height() * 0.1;
int defaultButtonHeight = this->height() * 0.6; int defaultButtonHeight = this->height() * 0.6;
this->actionButtons[0]->setGeometry((this->width() - defaultButtonHeight) / 2, 0,defaultButtonHeight, defaultButtonHeight); geometries[0] = QRect((this->width() - defaultButtonHeight) / 2, 0,defaultButtonHeight, defaultButtonHeight);
int secondaryButtonHeight = this->height() * 0.3; int secondaryButtonHeight = this->height() * 0.3;
if(positionsEnabled[1] && positionsEnabled[2]) { if(positionsEnabled[1] && positionsEnabled[2]) {
this->actionButtons[1]->setGeometry( // place buttons besides each other
geometries[1] = QRect(
this->width() / 2 - secondaryButtonHeight - buttonSpacing / 2, this->width() / 2 - secondaryButtonHeight - buttonSpacing / 2,
defaultButtonHeight + buttonSpacing, defaultButtonHeight + buttonSpacing,
secondaryButtonHeight, secondaryButtonHeight,
secondaryButtonHeight secondaryButtonHeight
); );
this->actionButtons[2]->setGeometry( geometries[2] = QRect(
this->width() / 2 + buttonSpacing / 2, this->width() / 2 + buttonSpacing / 2,
defaultButtonHeight + buttonSpacing, defaultButtonHeight + buttonSpacing,
secondaryButtonHeight, secondaryButtonHeight,
secondaryButtonHeight secondaryButtonHeight
); );
} }
else if(!positionsEnabled[1]) { else {
this->actionButtons[1]->hide(); // place buttons on top of each other
this->actionButtons[2]->setGeometry( geometries[1] = QRect(
this->width() / 2 - secondaryButtonHeight / 2, this->width() / 2 - secondaryButtonHeight / 2,
defaultButtonHeight + buttonSpacing, defaultButtonHeight + buttonSpacing,
secondaryButtonHeight, secondaryButtonHeight,
secondaryButtonHeight secondaryButtonHeight
); );
geometries[2] = geometries[1];
}
for(int i = 0; i < this->actionButtons.length(); i++) {
if(this->inited) {
this->actionButtons[i]->setVisibleAnimated(positionsEnabled[i]);
this->actionButtons[i]->setGeometryAnimated(geometries[i]);
}
else {
// don't animate the first time
this->actionButtons[i]->setVisible(positionsEnabled[i]);
this->actionButtons[i]->setGeometry(geometries[i]);
} }
else if(!positionsEnabled[2]) {
this->actionButtons[1]->setGeometry(
this->width() / 2 - secondaryButtonHeight / 2,
defaultButtonHeight + buttonSpacing,
secondaryButtonHeight,
secondaryButtonHeight
);
this->actionButtons[2]->hide();
} }
// Progress bar // Progress bar
@ -130,6 +143,8 @@ void LinboStartActions::resizeAndPositionAllItems() {
int progressBarHeight = this->height() * 0.1; int progressBarHeight = this->height() * 0.1;
int progressBarWidth = this->width() * 0.5; int progressBarWidth = this->width() * 0.5;
progressBar->setGeometry((this->width() - progressBarWidth) / 2, (this->height() - progressBarHeight) / 2, progressBarWidth, progressBarHeight); progressBar->setGeometry((this->width() - progressBarWidth) / 2, (this->height() - progressBarHeight) / 2, progressBarWidth, progressBarHeight);
this->inited = true;
} }
void LinboStartActions::resizeEvent(QResizeEvent *event) { void LinboStartActions::resizeEvent(QResizeEvent *event) {
@ -137,23 +152,24 @@ void LinboStartActions::resizeEvent(QResizeEvent *event) {
QWidget::resizeEvent(event); QWidget::resizeEvent(event);
} }
void LinboStartActions::executeStartAction() { void LinboStartActions::handleCurrentOsChanged(LinboOs* newOs) {
this->stackView->setCurrentWidgetAnimated(this->progressBarWidget); Q_UNUSED(newOs)
this->osSelectionRow->setShowOnlySelectedButton(true); this->resizeAndPositionAllItems();
this->backend->startOs(this->osSelectionRow->getSelectedOs());
//this->progressBar->show();
} }
void LinboStartActions::executeSyncAction() { void LinboStartActions::handleLinboStateChanged(LinboBackend::LinboState newState) {
this->stackView->setCurrentWidgetAnimated(this->progressBarWidget); switch (newState) {
this->osSelectionRow->setShowOnlySelectedButton(true); case LinboBackend::Idle:
this->backend->startOs(this->osSelectionRow->getSelectedOs()); this->stackView->setCurrentWidgetAnimated(this->buttonWidget);
//this->progressBar->show(); break;
}
void LinboStartActions::executeReinstallAction() { case LinboBackend::Starting:
case LinboBackend::Syncing:
case LinboBackend::Reinstalling:
this->stackView->setCurrentWidgetAnimated(this->progressBarWidget); this->stackView->setCurrentWidgetAnimated(this->progressBarWidget);
this->osSelectionRow->setShowOnlySelectedButton(true); break;
this->backend->startOs(this->osSelectionRow->getSelectedOs());
//this->progressBar->show(); default:
break;
}
} }

View file

@ -22,6 +22,8 @@ LinboStartPage::LinboStartPage(LinboBackend* backend, QWidget *parent) : QWidget
{ {
this->backend = backend; this->backend = backend;
connect(this->backend, SIGNAL(stateChanged(LinboBackend::LinboState)), this, SLOT(handleLinboStateChanged(LinboBackend::LinboState)));
this->setGeometry(QRect(0,0,parent->width(), parent->height())); this->setGeometry(QRect(0,0,parent->width(), parent->height()));
// create an instance of the old GUI (as a backup) // create an instance of the old GUI (as a backup)
@ -30,19 +32,6 @@ LinboStartPage::LinboStartPage(LinboBackend* backend, QWidget *parent) : QWidget
// create the main layout // create the main layout
// OS Buttons
osSelectionRow = new LinboOsSelectionRow(this->backend);
osSelectionRow->setFixedHeight(this->height() * 0.25);
osSelectionRow->setFixedWidth(this->width());
// action buttons
this->startActionsWidget = new LinboStartActions(this->backend, this->osSelectionRow);
this->startActionsWidget->setFixedHeight(this->height() * 0.15);
this->startActionsWidget->setFixedWidth(this->width());
QLabel* versionLabel = new QLabel(backend->getConfig()->getVersion() + " - mod by Dorian Zedler");
// main layout // main layout
QWidget* mainLayoutWidget = new QWidget(this); QWidget* mainLayoutWidget = new QWidget(this);
mainLayoutWidget->setGeometry(this->geometry()); mainLayoutWidget->setGeometry(this->geometry());
@ -50,9 +39,22 @@ LinboStartPage::LinboStartPage(LinboBackend* backend, QWidget *parent) : QWidget
mainLayout->setSpacing(this->height()*0.025); mainLayout->setSpacing(this->height()*0.025);
mainLayout->setContentsMargins(0,0,0,0); mainLayout->setContentsMargins(0,0,0,0);
mainLayout->addItem(new QSpacerItem(0,0, QSizePolicy::Minimum, QSizePolicy::Expanding)); mainLayout->addItem(new QSpacerItem(0,0, QSizePolicy::Minimum, QSizePolicy::Expanding));
// OS Buttons
osSelectionRow = new LinboOsSelectionRow(this->backend);
mainLayout->addWidget(osSelectionRow); mainLayout->addWidget(osSelectionRow);
osSelectionRow->setFixedHeight(this->height() * 0.25);
osSelectionRow->setFixedWidth(this->width());
// action buttons
this->startActionsWidget = new LinboStartActions(this->backend, this->osSelectionRow);
mainLayout->addWidget(this->startActionsWidget); mainLayout->addWidget(this->startActionsWidget);
this->startActionsWidget->setFixedHeight(this->height() * 0.15);
this->startActionsWidget->setFixedWidth(this->width());
mainLayout->addItem(new QSpacerItem(0,0, QSizePolicy::Minimum, QSizePolicy::Expanding)); mainLayout->addItem(new QSpacerItem(0,0, QSizePolicy::Minimum, QSizePolicy::Expanding));
QLabel* versionLabel = new QLabel(backend->getConfig()->getVersion() + " - mod by Dorian Zedler");
mainLayout->addWidget(versionLabel); mainLayout->addWidget(versionLabel);
@ -66,16 +68,19 @@ LinboStartPage::LinboStartPage(LinboBackend* backend, QWidget *parent) : QWidget
QModernPushButton* settingsActionButton = new QModernPushButton(":/svgIcons/settingsAction.svg"); QModernPushButton* settingsActionButton = new QModernPushButton(":/svgIcons/settingsAction.svg");
connect(settingsActionButton, SIGNAL(clicked()), legacyGui, SLOT(open())); connect(settingsActionButton, SIGNAL(clicked()), legacyGui, SLOT(open()));
this->powerActionButtons.append(settingsActionButton);
settingsActionButton->setFixedHeight(buttonWidth); settingsActionButton->setFixedHeight(buttonWidth);
settingsActionButton->setFixedWidth(buttonWidth); settingsActionButton->setFixedWidth(buttonWidth);
QModernPushButton* rebootActionButton = new QModernPushButton(":/svgIcons/rebootAction.svg"); QModernPushButton* rebootActionButton = new QModernPushButton(":/svgIcons/rebootAction.svg");
connect(rebootActionButton, SIGNAL(clicked()), this->backend, SLOT(reboot())); connect(rebootActionButton, SIGNAL(clicked()), this->backend, SLOT(reboot()));
this->powerActionButtons.append(rebootActionButton);
rebootActionButton->setFixedHeight(buttonWidth); rebootActionButton->setFixedHeight(buttonWidth);
rebootActionButton->setFixedWidth(buttonWidth); rebootActionButton->setFixedWidth(buttonWidth);
QModernPushButton* shutdownActionButton = new QModernPushButton(":/svgIcons/shutdownAction.svg"); QModernPushButton* shutdownActionButton = new QModernPushButton(":/svgIcons/shutdownAction.svg");
connect(shutdownActionButton, SIGNAL(clicked()), this->backend, SLOT(shutdown())); connect(shutdownActionButton, SIGNAL(clicked()), this->backend, SLOT(shutdown()));
this->powerActionButtons.append(shutdownActionButton);
shutdownActionButton->setFixedHeight(buttonWidth); shutdownActionButton->setFixedHeight(buttonWidth);
shutdownActionButton->setFixedWidth(buttonWidth); shutdownActionButton->setFixedWidth(buttonWidth);
@ -86,24 +91,21 @@ LinboStartPage::LinboStartPage(LinboBackend* backend, QWidget *parent) : QWidget
powerActionsLayout->addWidget(shutdownActionButton); powerActionsLayout->addWidget(shutdownActionButton);
} }
void LinboStartPage::startOs() { void LinboStartPage::handleLinboStateChanged(LinboBackend::LinboState newState) {
/*progressBar->show(); switch (newState) {
defaultActionButton->hide(); case LinboBackend::Idle:
secondActionButton->hide(); for(QModernPushButton* powerActionButton : this->powerActionButtons)
thirdActionButton->hide();*/ powerActionButton->setVisibleAnimated(true);
this->osSelectionRow->setShowOnlySelectedButton(true); break;
/*LinboOs* startOs = static_cast<LinboOsSelectButton*>(this->osButtonGroup->checkedButton()->parent())->getOs();
for(QAbstractButton* abstractButton : this->osButtonGroup->buttons()) { case LinboBackend::Starting:
LinboOsSelectButton* button = static_cast<LinboOsSelectButton*>(abstractButton->parent()); case LinboBackend::Syncing:
if(button->getOs() != startOs) case LinboBackend::Reinstalling:
button->setFixedWidth(this->width() * 0.1); //hide(); for(QModernPushButton* powerActionButton : this->powerActionButtons)
//button->setMaximumSize(QSize(0, this->height() * 0.25)); powerActionButton->setVisibleAnimated(false);
break;
default:
break;
} }
//this->osButtonGroup->checkedButton()->setFixedWidth(this->width() * 0.8);
//this->osButtonGroup->checkedButton()->setMaximumSize(QSize(this->width(), this->height() * 0.25));
qDebug() << "starting: " << startOs->getName();
this->backend->startOs(startOs);*/
} }

View file

@ -21,6 +21,9 @@
QModernPushButton::QModernPushButton(QString icon, QWidget* parent) : QAbstractButton(parent) QModernPushButton::QModernPushButton(QString icon, QWidget* parent) : QAbstractButton(parent)
{ {
this->setMouseTracking(true); this->setMouseTracking(true);
this->geometryAnimation = new QPropertyAnimation(this, "geometry", this);
this->geometryAnimation->setDuration(400);
this->geometryAnimation->setEasingCurve(QEasingCurve::InOutQuad);
QStringList overlays; QStringList overlays;
overlays.append(icon); overlays.append(icon);
@ -28,6 +31,8 @@ QModernPushButton::QModernPushButton(QString icon, QWidget* parent) : QAbstractB
overlays.append(":svgIcons/overlayPressed.svg"); overlays.append(":svgIcons/overlayPressed.svg");
overlays.append(":svgIcons/overlayChecked.svg"); overlays.append(":svgIcons/overlayChecked.svg");
this->setObjectName(icon);
for(QString overlayName : overlays) { for(QString overlayName : overlays) {
QSvgWidget* overlayWidget = new QSvgWidget(this); QSvgWidget* overlayWidget = new QSvgWidget(this);
@ -38,6 +43,7 @@ QModernPushButton::QModernPushButton(QString icon, QWidget* parent) : QAbstractB
} }
this->overlays[0]->setVisible(true); this->overlays[0]->setVisible(true);
this->overlays[0]->setAnimationDuration(200);
this->overlays[1]->setAnimationDuration(200); this->overlays[1]->setAnimationDuration(200);
this->overlays[2]->setAnimationDuration(100); this->overlays[2]->setAnimationDuration(100);
@ -45,6 +51,8 @@ QModernPushButton::QModernPushButton(QString icon, QWidget* parent) : QAbstractB
} }
void QModernPushButton::handleToggled(bool checked) { void QModernPushButton::handleToggled(bool checked) {
if(checked)
emit this->checked();
if(this->overlays.length() >= 4) if(this->overlays.length() >= 4)
this->overlays[3]->setVisible(checked); this->overlays[3]->setVisible(checked);
} }
@ -62,30 +70,26 @@ void QModernPushButton::resizeEvent(QResizeEvent *event) {
} }
} }
void QModernPushButton::setVisible(bool visible, bool animated, bool asynchronos) { void QModernPushButton::setGeometryAnimated(const QRect& geometry) {
if(this->isVisible() == visible) this->geometryAnimation->setStartValue(this->geometry());
return; this->geometryAnimation->setEndValue(geometry);
this->geometryAnimation->start();
}
if(animated) { void QModernPushButton::setVisibleAnimated(bool visible, bool asynchronos) {
if(!this->isVisible())
this->setVisible(true);
this->setEnabled(visible);
this->overlays[0]->setVisible(visible); this->overlays[0]->setVisible(visible);
} }
else {
QWidget::setVisible(visible);
}
}
void QModernPushButton::setVisible(bool visible) {
QAbstractButton::setVisible(visible);
}
void QModernPushButton::paintEvent(QPaintEvent *e) { void QModernPushButton::paintEvent(QPaintEvent *e) {
QWidget::paintEvent(e); QWidget::paintEvent(e);
} }
void QModernPushButton::keyPressEvent(QKeyEvent *e) { void QModernPushButton::keyPressEvent(QKeyEvent *e) {
// TODO // TODO
return QAbstractButton::keyPressEvent(e); return QAbstractButton::keyPressEvent(e);
} }