From cacd1f5468dfe29f77d58dec6cf474a4986bf57f Mon Sep 17 00:00:00 2001 From: Dorian Zedler Date: Mon, 16 Nov 2020 18:01:03 +0100 Subject: [PATCH] - a few new buttons - started to implement new backend --- headers/backend/linbobackend.h | 91 ++ headers/backend/linboconfig.h | 82 ++ headers/backend/linbodiskpartition.h | 54 + headers/backend/linboimage.h | 46 + headers/backend/linboos.h | 94 ++ headers/linbogui.h | 29 +- headers/linboosselectbutton.h | 26 +- headers/linbostartpage.h | 18 + headers/qmodernpushbutton.h | 34 +- linboGUI.pro | 12 + linboGUI.pro.user | 2 +- resources/linbo.qrc | 4 + resources/svgIcons/check-solid.svg | 1 - resources/svgIcons/overlayPressed.svg | 37 + resources/svgIcons/play-solid.svg | 1 - resources/svgIcons/power-off-solid.svg | 1 - resources/svgIcons/rebootAction.svg | 62 ++ resources/svgIcons/recycle-solid.svg | 1 - resources/svgIcons/redo-alt-solid.svg | 1 - resources/svgIcons/resetAction.svg | 8 +- resources/svgIcons/settingsAction.svg | 62 ++ resources/svgIcons/shutdownAction.svg | 62 ++ resources/svgIcons/startAction.svg | 12 +- resources/svgIcons/sync-alt-solid.svg | 1 - resources/svgIcons/syncAction.svg | 12 +- sources/backend/linbobackend.cpp | 416 ++++++++ sources/backend/linboconfig.cpp | 30 + sources/backend/linbodiskpartition.cpp | 24 + sources/backend/linboimage.cpp | 24 + sources/backend/linboos.cpp | 29 + sources/legacy/linboGUIImpl.cc | 14 +- sources/legacy/linboGUIImplTmp.cpp | 1265 ++++++++++++++++++++++++ sources/legacy/linboPushButton.cc | 3 + sources/linbogui.cpp | 77 +- sources/linboosselectbutton.cpp | 26 +- sources/linbostartpage.cpp | 18 + sources/main.cpp | 31 +- sources/qmodernpushbutton.cpp | 91 +- 38 files changed, 2703 insertions(+), 98 deletions(-) create mode 100644 headers/backend/linbobackend.h create mode 100644 headers/backend/linboconfig.h create mode 100644 headers/backend/linbodiskpartition.h create mode 100644 headers/backend/linboimage.h create mode 100644 headers/backend/linboos.h delete mode 100644 resources/svgIcons/check-solid.svg create mode 100644 resources/svgIcons/overlayPressed.svg delete mode 100644 resources/svgIcons/play-solid.svg delete mode 100644 resources/svgIcons/power-off-solid.svg create mode 100644 resources/svgIcons/rebootAction.svg delete mode 100644 resources/svgIcons/recycle-solid.svg delete mode 100644 resources/svgIcons/redo-alt-solid.svg create mode 100644 resources/svgIcons/settingsAction.svg create mode 100644 resources/svgIcons/shutdownAction.svg delete mode 100644 resources/svgIcons/sync-alt-solid.svg create mode 100644 sources/backend/linbobackend.cpp create mode 100644 sources/backend/linboconfig.cpp create mode 100644 sources/backend/linbodiskpartition.cpp create mode 100644 sources/backend/linboimage.cpp create mode 100644 sources/backend/linboos.cpp create mode 100644 sources/legacy/linboGUIImplTmp.cpp diff --git a/headers/backend/linbobackend.h b/headers/backend/linbobackend.h new file mode 100644 index 0000000..5cdcee3 --- /dev/null +++ b/headers/backend/linbobackend.h @@ -0,0 +1,91 @@ +/**************************************************************************** + ** 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 "linboconfig.h" +#include "linboos.h" +#include "linboimage.h" +#include "linbodiskpartition.h" + +using namespace std; + +class LinboBackend : public QObject +{ + Q_OBJECT +public: + explicit LinboBackend(QObject *parent = nullptr); + + LinboConfig* getConfig(); + QList 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 mksyncstartcommand(LinboConfig& config, LinboOs& os); + QStringList mksynccommand(LinboConfig& config, LinboOs& os); + QStringList mksyncrcommand(LinboConfig& config, LinboOs& os); + QStringList mkpartitioncommand(vector &p); + QStringList mkpartitioncommand_noformat(vector &p); + QStringList mkcacheinitcommand(LinboConfig& config, vector &os, const QString& type); + QStringList mklinboupdatecommand(LinboConfig& config); + +private: + LinboConfig* config; + QList operatingSystems; + QList diskPartitions; + + QProcess* process; + + void readFromStdout(); + void readFromStderr(); + + void executeCommand(QStringList commandArgs, bool waitForFinished = true); + +public slots: + void executeAutostart(); + void shutdown(); + void reboot(); + + bool startOs(LinboOs* os); + //bool syncStartOs(); + //bool reinstallStartOs(); + +signals: + +}; + +#endif // LINBOBACKEND_H diff --git a/headers/backend/linboconfig.h b/headers/backend/linboconfig.h new file mode 100644 index 0000000..9ec5daf --- /dev/null +++ b/headers/backend/linboconfig.h @@ -0,0 +1,82 @@ +/**************************************************************************** + ** 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 LINBOCONFIG_H +#define LINBOCONFIG_H + +#include + +class LinboConfig : public QObject +{ + Q_OBJECT +public: + explicit LinboConfig(QObject *parent = nullptr); + + friend class LinboBackend; + + const QString& getServer() const {return this->server;} + const QString& getIpAddress() const {return this->ipAddress;} + const QString& getMacAddress() const {return this->macAddress;} + const QString& getVersion() const {return this->version;} + const QString& getHostname() const {return this->hostname;} + const QString& getCpu() const {return this->cpu;} + const QString& getRamSize() const {return this->ramSize;} + const QString& getCacheSize() const {return this->cacheSize;} + const QString& getHddSize() const {return this->hddSize;} + + const QString& getCache() const {return this->cache;} + const QString& getHostgroup() const {return this->hostgroup;} + const unsigned int& getRootTimeout() const {return this->rootTimeout;} + const bool& getAutopartition() {return this->autoPartition;} + const bool& getAutoInitCache() {return this->autoInitCache;} + const QString& getBackgroundFontcolor() {return this->backgroundFontcolor;} + const QString& getConsoleFontcolorStdout() {return this->consoleFontcolorStdout;} + const QString& getConsoleFontcolorStderr() {return this->consoleFontcolorStderr;} + const QString& getDownloadType() {return this->downloadType;} + const bool& getAutoFormat() {return this->autoFormat;} + +protected: + void setServer( const QString& server ) {this->server = server;} + void setIpAddress( const QString& ipAddress ) {this->ipAddress = ipAddress;} + void setMacAddress( const QString& macAddress ) {this->macAddress = macAddress;} + void setVersion( const QString& version ) {this->version = version;} + void setHostname( const QString& hostname ) {this->hostname = hostname;} + void setCpu( const QString& cpu ) {this->cpu = cpu;} + void setRamSize( const QString& ramSize ) {this->ramSize = ramSize;} + void setCacheSize( const QString& cacheSize ) {this->cacheSize = cacheSize;} + void setHddSize( const QString& hddSize ) {this->hddSize = hddSize;} + void setCache( const QString& cache ) {this->cache = cache;} + void setHostgroup( const QString& hostgroup ) {this->hostgroup = hostgroup;} + void setRootTimeout( const unsigned int& rootTimeout ) {this->rootTimeout = rootTimeout;} + void setAutopartition( const bool& autoPartition ){this->autoPartition = autoPartition;} + void setAutoInitCache( const bool& autoInitCache ){this->autoInitCache = autoInitCache;} + void setBackgroundFontcolor( const QString& backgroundFontcolor ){this->backgroundFontcolor = backgroundFontcolor;} + void setConsoleFontcolorStdout( const QString& consoleFontcolorStdout ){this->consoleFontcolorStdout = consoleFontcolorStdout;} + void setConsoleFontcolorStderr( const QString& consoleFontcolorStderr ){this->consoleFontcolorStderr = consoleFontcolorStderr;} + void setDownloadType( const QString& downloadType ){this->downloadType = downloadType;} + void setAutoFormat( const bool& autoFormat ){this->autoFormat = autoFormat;} + +private: + QString server, ipAddress, macAddress, version, hostname, cpu, ramSize, cacheSize, hddSize, cache, hostgroup, downloadType, backgroundFontcolor, consoleFontcolorStdout, consoleFontcolorStderr; + unsigned int rootTimeout; + bool autoPartition, autoInitCache, autoFormat; + +signals: + +}; + +#endif // LINBOCONFIG_H diff --git a/headers/backend/linbodiskpartition.h b/headers/backend/linbodiskpartition.h new file mode 100644 index 0000000..b6b09eb --- /dev/null +++ b/headers/backend/linbodiskpartition.h @@ -0,0 +1,54 @@ +/**************************************************************************** + ** 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 LINBODISKPARTITION_H +#define LINBODISKPARTITION_H + +#include + +class LinboDiskPartition : public QObject +{ + Q_OBJECT +public: + explicit LinboDiskPartition(QObject *parent = nullptr); + + friend class LinboBackend; + + const QString& getPath() const {return this->path;} + const QString& getId() const {return this->id;} + const QString& getFstype() const {return this->fstype;} + const unsigned int& getSize() const {return this->size;} + const bool& getBootable() const {return this->bootable;} + +protected: + void setPath( const QString& path ) {this->path = path;} + void setId( const QString& id ) {this->id = id;} + void setFstype( const QString& fstype ) {this->fstype = fstype;} + void setSize( const unsigned int& size ) {this->size = size;} + void setBootable( const bool& bootable ) {this->bootable = bootable;} + +private: + QString path, id, fstype; + unsigned int size; + bool bootable; + +signals: + +}; + +#endif // LINBODISKPARTITION_H diff --git a/headers/backend/linboimage.h b/headers/backend/linboimage.h new file mode 100644 index 0000000..afb1975 --- /dev/null +++ b/headers/backend/linboimage.h @@ -0,0 +1,46 @@ +/**************************************************************************** + ** 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 LINBOIMAGE_H +#define LINBOIMAGE_H + +#include + +class LinboImage : public QObject +{ + Q_OBJECT +public: + explicit LinboImage(QString name, QObject *parent = nullptr); + + friend class LinboBackend; + + const QString& getDescription() const {return this->description;} + const QString& getName() const {return this->name;} + +protected: + void setDescription (const QString& description) {this->description = description;} + void setName(const QString& name) {this->name = name;} + +private: + QString name, + description; + + +}; + +#endif // LINBOIMAGE_H diff --git a/headers/backend/linboos.h b/headers/backend/linboos.h new file mode 100644 index 0000000..37e20c5 --- /dev/null +++ b/headers/backend/linboos.h @@ -0,0 +1,94 @@ +/**************************************************************************** + ** 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 LINBOOS_H +#define LINBOOS_H + +#include + +#include "linboimage.h" + +class LinboOs : public QObject +{ + Q_OBJECT +public: + explicit LinboOs(QObject *parent = nullptr); + + friend class LinboBackend; + + const QString& getName() const {return this->name;} + const QString& getDescription() const {return this->description;} + const QString& getVersion() const {return this->version;} + const LinboImage* getBaseImage() const {return this->baseImage;} + const LinboImage* getDifferentialImage() const {return this->differentialImage;} + const QString& getIconName() const {return this->iconName;} + const QString& getRootPartition() const {return this->rootPartition;} + const QString& getBootPartition() const {return this->bootPartition;} + const QString& getKernel() const {return this->kernel;} + const QString& getInitrd() const {return this->initrd;} + const QString& getKernelOptions() const {return this->kernelOptions;} + const bool& getSyncbutton() const {return this->syncButton;} + const bool& getStartbutton() const {return this->startButton;} + const bool& getNewbutton() const {return this->newButton;} + const bool& getAutostart() const {return this->autostart;} + const int& getAutostartTimeout() const {return this->autostartTimeout;} + const QString& getDefaultAction() const {return this->defaultAction;} + const bool& getHidden() const {return this->hidden;} + +protected: + void setName( const QString& name ) {this->name = name;} + void setDescription ( const QString& description ) {this->description = description;} + void setVersion( const QString& version ) {this->version = version;} + void setBaseImage( LinboImage* baseImage ) {this->baseImage = baseImage;} + void setDifferentialImage(LinboImage* differentialImage) {this->differentialImage = differentialImage;} + void setIconName( const QString& iconName ) {this->iconName = iconName;} + void setRootPartition( const QString& rootPartition ) {this->rootPartition = rootPartition;} + void setBootPartition( const QString& bootPartition ) {this->bootPartition = bootPartition;} + void setKernel( const QString& kernel ) {this->kernel = kernel;} + void setInitrd( const QString& initrd ) {this->initrd = initrd;} + void setKernelOptions( const QString& kernelOptions ) {this->kernelOptions = kernelOptions;} + void setSyncButton ( const bool& syncButton ) {this->syncButton = syncButton;} + void setStartButton( const bool& startButton) {this->startButton = startButton;} + void setNewButton ( const bool& newButton ) {this->newButton = newButton;} + void setAutostart ( const bool& autostart ) {this->autostart = autostart;} + void setAutostartTimeout ( const int& autostartTimeout ) {this->autostartTimeout = autostartTimeout;} + void setDefaultAction ( const QString& defaultAction ) {this->defaultAction = defaultAction;} + void setHidden ( const bool& hidden ) {this->hidden = hidden;} + +private: + QString name, // OS Name + version, + description, + iconName, // Thumbnail for Image + rootPartition, // Root partition + bootPartition, // Root partition + image, + kernel, + initrd, + kernelOptions, + defaultAction; +int autostartTimeout; +bool syncButton, startButton, newButton, autostart, +hidden; // show OS tab or not + +LinboImage* baseImage; +LinboImage* differentialImage; + +}; + +#endif // LINBOOS_H diff --git a/headers/linbogui.h b/headers/linbogui.h index 3dd1754..14dc5e3 100644 --- a/headers/linbogui.h +++ b/headers/linbogui.h @@ -1,3 +1,21 @@ +/**************************************************************************** + ** 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 LINBOGUI_H #define LINBOGUI_H @@ -9,14 +27,21 @@ #include "linboGUIImpl.hh" #include "linbostartpage.h" +#include "linbobackend.h" -class linboGui : public QDialog +class LinboGui : public QDialog { Q_OBJECT public: - linboGui(); + LinboGui(); void done(int r) override; + +private: + LinboBackend* backend; + +private slots: + void startOs(); }; #endif // LINBOGUI_H diff --git a/headers/linboosselectbutton.h b/headers/linboosselectbutton.h index 061b93b..97f1890 100644 --- a/headers/linboosselectbutton.h +++ b/headers/linboosselectbutton.h @@ -1,14 +1,38 @@ +/**************************************************************************** + ** 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 LINBOOSSELECTBUTTON_H #define LINBOOSSELECTBUTTON_H #include #include "qmodernpushbutton.h" +#include "linboos.h" class LinboOsSelectButton : public QModernPushButton { Q_OBJECT public: - LinboOsSelectButton(QString icon, QWidget* parent = nullptr); + LinboOsSelectButton(QString icon, LinboOs* os, QWidget* parent = nullptr); + + LinboOs* getOs(); + +private: + LinboOs* os; }; #endif // LINBOOSSELECTBUTTON_H diff --git a/headers/linbostartpage.h b/headers/linbostartpage.h index 683403d..e6e24e0 100644 --- a/headers/linbostartpage.h +++ b/headers/linbostartpage.h @@ -1,3 +1,21 @@ +/**************************************************************************** + ** 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 LINBOGUISTARTPAGE_H #define LINBOGUISTARTPAGE_H diff --git a/headers/qmodernpushbutton.h b/headers/qmodernpushbutton.h index 18d072a..1e19a79 100644 --- a/headers/qmodernpushbutton.h +++ b/headers/qmodernpushbutton.h @@ -1,3 +1,21 @@ +/**************************************************************************** + ** 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 QMODERNPUSHBUTTON_H #define QMODERNPUSHBUTTON_H @@ -10,7 +28,7 @@ #include #include -class QModernPushButton : public QPushButton +class QModernPushButton : public QAbstractButton { Q_OBJECT public: @@ -18,10 +36,20 @@ public: protected: void resizeEvent(QResizeEvent *event) override; + void paintEvent(QPaintEvent *e) override; + void keyPressEvent(QKeyEvent *e) override; + void keyReleaseEvent(QKeyEvent *e) override; + void enterEvent(QEvent *e) override; + void leaveEvent(QEvent *e) override; + void mousePressEvent(QMouseEvent *e) override; + void mouseReleaseEvent(QMouseEvent *e) override; private: QSvgWidget* svgWidget; - QSvgWidget* overlayNormalWidget; + QSvgWidget* overlayHoveredWidget; + QGraphicsOpacityEffect* overlayHoveredEffect; + QSvgWidget* overlayPressedWidget; + QGraphicsOpacityEffect* overlayPressedEffect; QSvgWidget* overlayCheckedWidget; QGraphicsOpacityEffect* overlayCheckedEffect; @@ -29,8 +57,6 @@ private: private slots: void handleToggled(bool checked); - QString generateStyleSheet(); - }; #endif // QMODERNPUSHBUTTON_H diff --git a/linboGUI.pro b/linboGUI.pro index cef6441..67b2eeb 100644 --- a/linboGUI.pro +++ b/linboGUI.pro @@ -14,10 +14,15 @@ target.path = /usr/bin INCLUDEPATH += \ headers/ \ + headers/backend \ headers/legacy # Input HEADERS += \ + headers/backend/linboconfig.h \ + headers/backend/linbodiskpartition.h \ + headers/backend/linboimage.h \ + headers/backend/linboos.h \ headers/legacy/image_description.hh \ headers/legacy/linboConsoleImpl.hh \ headers/legacy/linboCounterImpl.hh \ @@ -34,16 +39,22 @@ HEADERS += \ headers/legacy/linboLogConsole.hh \ headers/legacy/linboRegisterBoxImpl.hh \ headers/legacy/linboYesNoImpl.hh \ + headers/backend/linbobackend.h \ headers/linbogui.h \ headers/linboosselectbutton.h \ headers/linbostartpage.h \ headers/qmodernpushbutton.h SOURCES += \ + sources/backend/linboconfig.cpp \ + sources/backend/linbodiskpartition.cpp \ + sources/backend/linboimage.cpp \ + sources/backend/linboos.cpp \ sources/legacy/image_description.cc \ sources/legacy/linboConsoleImpl.cc \ sources/legacy/linboCounterImpl.cc \ sources/legacy/linboGUIImpl.cc \ + sources/legacy/linboGUIImplTmp.cpp \ sources/legacy/linboImageSelectorImpl.cc \ sources/legacy/linboImageUploadImpl.cc \ sources/legacy/linboInfoBrowserImpl.cc \ @@ -56,6 +67,7 @@ SOURCES += \ sources/legacy/linboLogConsole.cc \ sources/legacy/linboRegisterBoxImpl.cc \ sources/legacy/linboYesNoImpl.cc \ + sources/backend/linbobackend.cpp \ sources/linbogui.cpp \ sources/linboosselectbutton.cpp \ sources/linbostartpage.cpp \ diff --git a/linboGUI.pro.user b/linboGUI.pro.user index 03ce2e7..2873e2e 100644 --- a/linboGUI.pro.user +++ b/linboGUI.pro.user @@ -1,6 +1,6 @@ - + EnvironmentId diff --git a/resources/linbo.qrc b/resources/linbo.qrc index b6a54ca..d43cf78 100644 --- a/resources/linbo.qrc +++ b/resources/linbo.qrc @@ -22,5 +22,9 @@ svgIcons/syncAction.svg svgIcons/resetAction.svg svgIcons/overlayNormal.svg + svgIcons/overlayPressed.svg + svgIcons/shutdownAction.svg + svgIcons/rebootAction.svg + svgIcons/settingsAction.svg diff --git a/resources/svgIcons/check-solid.svg b/resources/svgIcons/check-solid.svg deleted file mode 100644 index 15d7ab5..0000000 --- a/resources/svgIcons/check-solid.svg +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/resources/svgIcons/overlayPressed.svg b/resources/svgIcons/overlayPressed.svg new file mode 100644 index 0000000..a7a4128 --- /dev/null +++ b/resources/svgIcons/overlayPressed.svg @@ -0,0 +1,37 @@ + + + + + + + image/svg+xml + + + + + + + + + diff --git a/resources/svgIcons/play-solid.svg b/resources/svgIcons/play-solid.svg deleted file mode 100644 index bcd81f7..0000000 --- a/resources/svgIcons/play-solid.svg +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/resources/svgIcons/power-off-solid.svg b/resources/svgIcons/power-off-solid.svg deleted file mode 100644 index 430ae5c..0000000 --- a/resources/svgIcons/power-off-solid.svg +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/resources/svgIcons/rebootAction.svg b/resources/svgIcons/rebootAction.svg new file mode 100644 index 0000000..bf707b1 --- /dev/null +++ b/resources/svgIcons/rebootAction.svg @@ -0,0 +1,62 @@ + + diff --git a/resources/svgIcons/recycle-solid.svg b/resources/svgIcons/recycle-solid.svg deleted file mode 100644 index 0834f87..0000000 --- a/resources/svgIcons/recycle-solid.svg +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/resources/svgIcons/redo-alt-solid.svg b/resources/svgIcons/redo-alt-solid.svg deleted file mode 100644 index b8e9455..0000000 --- a/resources/svgIcons/redo-alt-solid.svg +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/resources/svgIcons/resetAction.svg b/resources/svgIcons/resetAction.svg index f7a0d22..b0a7d37 100644 --- a/resources/svgIcons/resetAction.svg +++ b/resources/svgIcons/resetAction.svg @@ -43,8 +43,8 @@ guidetolerance="10" inkscape:pageopacity="0" inkscape:pageshadow="2" - inkscape:window-width="1850" - inkscape:window-height="1016" + inkscape:window-width="1245" + inkscape:window-height="1376" id="namedview6" showgrid="false" inkscape:zoom="1" @@ -52,11 +52,11 @@ inkscape:cy="256" inkscape:window-x="70" inkscape:window-y="27" - inkscape:window-maximized="1" + inkscape:window-maximized="0" inkscape:current-layer="svg4" inkscape:document-rotation="0" /> + style="fill:#000000;fill-opacity:1;stroke-width:10;stroke:#ffffff;stroke-opacity:1;stroke-miterlimit:4;stroke-dasharray:none" /> diff --git a/resources/svgIcons/settingsAction.svg b/resources/svgIcons/settingsAction.svg new file mode 100644 index 0000000..728686f --- /dev/null +++ b/resources/svgIcons/settingsAction.svg @@ -0,0 +1,62 @@ + + diff --git a/resources/svgIcons/shutdownAction.svg b/resources/svgIcons/shutdownAction.svg new file mode 100644 index 0000000..8f19701 --- /dev/null +++ b/resources/svgIcons/shutdownAction.svg @@ -0,0 +1,62 @@ + + diff --git a/resources/svgIcons/startAction.svg b/resources/svgIcons/startAction.svg index 3f00d22..efa2c2b 100644 --- a/resources/svgIcons/startAction.svg +++ b/resources/svgIcons/startAction.svg @@ -43,20 +43,20 @@ guidetolerance="10" inkscape:pageopacity="0" inkscape:pageshadow="2" - inkscape:window-width="1850" - inkscape:window-height="1016" + inkscape:window-width="1245" + inkscape:window-height="1376" id="namedview6" showgrid="false" - inkscape:zoom="0.84960938" + inkscape:zoom="1" inkscape:cx="224" inkscape:cy="256" inkscape:window-x="70" inkscape:window-y="27" - inkscape:window-maximized="1" + inkscape:window-maximized="0" inkscape:current-layer="svg4" inkscape:document-rotation="0" /> + style="fill:none;fill-opacity:1;stroke:#000000;stroke-width:30;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" /> diff --git a/resources/svgIcons/sync-alt-solid.svg b/resources/svgIcons/sync-alt-solid.svg deleted file mode 100644 index adacb5d..0000000 --- a/resources/svgIcons/sync-alt-solid.svg +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/resources/svgIcons/syncAction.svg b/resources/svgIcons/syncAction.svg index 06f28e3..93392d7 100644 --- a/resources/svgIcons/syncAction.svg +++ b/resources/svgIcons/syncAction.svg @@ -43,20 +43,20 @@ guidetolerance="10" inkscape:pageopacity="0" inkscape:pageshadow="2" - inkscape:window-width="1850" - inkscape:window-height="1016" + inkscape:window-width="1245" + inkscape:window-height="1376" id="namedview6" showgrid="false" - inkscape:zoom="1.2015291" + inkscape:zoom="1" inkscape:cx="256" inkscape:cy="256" - inkscape:window-x="70" + inkscape:window-x="1315" inkscape:window-y="27" - inkscape:window-maximized="1" + inkscape:window-maximized="0" inkscape:current-layer="svg4" inkscape:document-rotation="0" /> + style="fill:#000000;fill-opacity:1;stroke-width:15;stroke:#ffffff;stroke-opacity:1;stroke-miterlimit:4;stroke-dasharray:none" /> diff --git a/sources/backend/linbobackend.cpp b/sources/backend/linbobackend.cpp new file mode 100644 index 0000000..0570221 --- /dev/null +++ b/sources/backend/linbobackend.cpp @@ -0,0 +1,416 @@ +/**************************************************************************** + ** 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 . + ****************************************************************************/ + +#include "linbobackend.h" + +#define LINBO_CMD(arg) QStringList("linbo_cmd") << (arg); + +using namespace std; + +LinboBackend::LinboBackend(QObject *parent) : QObject(parent) +{ + + this->config = new LinboConfig(this); + + // read start.conf + qDebug() << "Starting to parse start.conf"; + ifstream input; + input.open( "start.conf", ios_base::in ); + + QString tmp_qstring; + + while( !input.eof() ) { + // *** Image description section *** + + // entry in start tab + read_qstring(&input, tmp_qstring); + if ( tmp_qstring.startsWith("#") || tmp_qstring.isEmpty() ) continue; + + tmp_qstring = tmp_qstring.section("#",0,0).stripWhiteSpace(); // Strip comment + if(tmp_qstring.lower().compare("[os]") == 0) { + LinboOs* tmpOs = read_os(&input); + if(!tmpOs->getName().isEmpty()) { + this->operatingSystems.append(tmpOs); + // check if this is an additional/incremental image for an existing OS + /* TODO unsigned int i; // Being checked later. + for(i = 0; i < elements.size(); i++ ) { + if(tmp_os.get_name().lower().compare(elements[i].get_name().lower()) == 0) { + elements[i].image_history.push_back(tmp_image); break; + } + } + if(i==elements.size()) { // Not included yet -> new image + tmp_os.image_history.push_back(tmp_image); + elements.push_back(tmp_os); + }*/ + } + else { + tmpOs->deleteLater(); + } + } else if(tmp_qstring.lower().compare("[linbo]") == 0) { + read_globals(&input, config); + } else if(tmp_qstring.lower().compare("[partition]") == 0) { + LinboDiskPartition* tmpPartition = read_partition(&input); + if(!tmpPartition->getPath().isEmpty()) { + diskPartitions.append(tmpPartition); + } + else { + tmpPartition->deleteLater(); + } + } + } + input.close(); + + qDebug() << "Finished parsing start.conf"; + qDebug() << "Loading global configuration"; + + // load global config + QStringList command; + this->process = new QProcess(); + + // client ip + command = LINBO_CMD("ip"); + // myprocess->setArguments( command ); + process->start( command.join(" ") ); + while( !process->waitForFinished(10000) ) {} + this->config->setIpAddress(process->readAllStandardOutput()); + + // mac address + command.clear(); + command = LINBO_CMD("mac"); + + process->start( command.join(" ") ); + while( !process->waitForFinished(10000) ) {} + this->config->setMacAddress(process->readAllStandardOutput()); + + // Version + command = LINBO_CMD("version"); + // myprocess->setArguments( command ); + process->start( command.join(" ") ); + while( !process->waitForFinished(10000) ) {} + this->config->setVersion(process->readAllStandardOutput().stripWhiteSpace()); + + // hostname + command = LINBO_CMD("hostname"); + // myprocess->setArguments( command ); + process->start( command.join(" ") ); + while( !process->waitForFinished(10000) ) {} + this->config->setHostname(process->readAllStandardOutput()); + + // CPU + command = LINBO_CMD("cpu"); + // myprocess->setArguments( command ); + process->start( command.join(" ") ); + while( !process->waitForFinished(10000) ) {} + this->config->setCpu(process->readAllStandardOutput()); + + // Memory + command = LINBO_CMD("memory"); + process->start( command.join(" ") ); + while( !process->waitForFinished(10000) ) {} + this->config->setRamSize(process->readAllStandardOutput()); + + // Cache Size + command = LINBO_CMD("size"); + saveappend( command, this->config->getCache() ); + process->start( command.join(" ") ); + while( !process->waitForFinished(10000) ) {} + this->config->setCacheSize(process->readAllStandardOutput()); + + // Harddisk Size + QRegExp *removePartition = new QRegExp("[0-9]{1,2}"); + QString hd = this->config->getCache(); + hd.remove( *removePartition ); + + command = LINBO_CMD("size"); + saveappend( command, hd ); + + process->start( command.join(" ") ); + while( !process->waitForFinished(10000) ) {} + this->config->setHddSize(process->readAllStandardOutput()); +} + +// -------------------- +// - Public functions - +// -------------------- + + +void LinboBackend::executeAutostart() { + +} + +void LinboBackend::shutdown() { + QStringList command; + command.clear(); + command = QStringList("busybox"); + command.append("poweroff"); + // TODO logConsole->writeStdOut( QString("shutdown entered") ); + process->start( command.join(" ") ); +} + +void LinboBackend::reboot() { + QStringList command; + command.clear(); + command = QStringList("busybox"); + command.append("reboot"); + // TODO logConsole->writeStdOut( QString("reboot entered") ); + process->start( command.join(" ") ); +} + +bool LinboBackend::startOs(LinboOs* os) { + if(os == nullptr) + return false; + + QStringList command = LINBO_CMD("start"); + saveappend( command, os->getBootPartition() ); + saveappend( command, os->getRootPartition() ); + saveappend( command, os->getKernel() ); + saveappend( command, os->getInitrd() ); + saveappend( command, os->getKernelOptions() ); + saveappend( command, this->config->getCache() ); + + this->executeCommand(command, false); + + return true; +} + +LinboConfig* LinboBackend::getConfig() { + return this->config; +} + +QList LinboBackend::getOperatingSystems() { + return this->operatingSystems; +} + + +// ----------- +// - Helpers - +// ----------- + +void LinboBackend::executeCommand(QStringList commandArgs, bool waitForFinished) { + + QString command = commandArgs.takeFirst(); + + qDebug() << "Executing: " << command << " " << commandArgs.join(" "); + + process->start(command, commandArgs); + process->waitForStarted(); + + if(waitForFinished) + while( !process->waitForFinished(10000) ) {} +} + +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. +bool LinboBackend::read_pair(ifstream* input, QString& key, QString& value) { + char line[1024]; + if(input->peek() == '[') return false; // Next section found. + input->getline(line,1024,'\n'); + QString s = QString::fromAscii( line, -1 ).stripWhiteSpace(); + key = s.section("=",0,0).stripWhiteSpace().lower(); + if(s.startsWith("#")||key.isEmpty()) { + key = QString(""); value = QString(""); + } else { + value=s.section("=",1).section("#",0,0).stripWhiteSpace(); + } + return true; +} + +bool LinboBackend::toBool(const QString& value) { + if(value.startsWith("yes",false)) return true; + if(value.startsWith("true",false)) return true; + if(value.startsWith("enable",false)) return true; + return false; +} + +LinboOs* LinboBackend::read_os(ifstream* input) { + LinboOs* os = new LinboOs(this); + QString key, value; + while(!input->eof() && read_pair(input, 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); + else if(key.compare("iconname") == 0) os->setIconName(value); + else if(key.compare("image") == 0) os->setDifferentialImage(new LinboImage(value, os)); + else if(key.compare("baseimage") == 0) os->setBaseImage(new LinboImage(value, os)); + else if(key.compare("boot") == 0) os->setBootPartition(value); + else if(key.compare("root") == 0) os->setRootPartition(value); + else if(key.compare("kernel") == 0) os->setKernel(value); + else if(key.compare("initrd") == 0) os->setInitrd(value); + else if(key.compare("append") == 0) os->setKernelOptions(value); + else if(key.compare("syncenabled") == 0) os->setSyncButton(toBool(value)); + else if(key.compare("startenabled") == 0) os->setStartButton(toBool(value)); + else if((key.compare("remotesyncenabled") == 0) || (key.compare("newenabled") == 0)) os->setNewButton(toBool(value)); + else if(key.compare("defaultaction") == 0) os->setDefaultAction(value); + else if(key.compare("autostart") == 0) os->setAutostart(toBool(value)); + else if(key.compare("autostarttimeout") == 0) os->setAutostartTimeout(value.toInt()); + else if(key.compare("hidden") == 0) os->setHidden(toBool(value)); + } + return os; +} + +LinboDiskPartition* LinboBackend::read_partition(ifstream* input) { + LinboDiskPartition* partition = new LinboDiskPartition(this); + QString key, value; + while(!input->eof() && read_pair(input, key, value)) { + if(key.compare("dev") == 0) partition->setPath(value); + else if(key.compare("size") == 0) partition->setSize(value.toInt()); + else if(key.compare("id") == 0) partition->setId(value); + else if(key.compare("fstype") == 0) partition->setFstype(value); + else if(key.startsWith("bootable", false)) partition->setBootable(toBool(value)); + } + return partition; +} + +void LinboBackend::read_globals( ifstream* input, LinboConfig* config ) { + QString key, value; + while(!input->eof() && read_pair(input, key, value)) { + if(key.compare("server") == 0) config->setServer(value); + else if(key.compare("cache") == 0) config->setCache(value); + else if(key.compare("roottimeout") == 0) config->setRootTimeout((unsigned int)value.toInt()); + else if(key.compare("group") == 0) config->setHostgroup(value); + else if(key.compare("autopartition") == 0) config->setAutopartition(toBool(value)); + else if(key.compare("autoinitcache") == 0) config->setAutoInitCache(toBool(value)); + else if(key.compare("autoformat") == 0) config->setAutoFormat(toBool(value)); + else if(key.compare("backgroundfontcolor") == 0) config->setBackgroundFontcolor(value); + else if(key.compare("consolefontcolorstdout") == 0) config->setConsoleFontcolorStdout(value); + else if(key.compare("consolefontcolorstderr") == 0) config->setConsoleFontcolorStderr(value); + else if(key.compare("usemulticast") == 0) { + if( (unsigned int)value.toInt() == 0 ) + config->setDownloadType("rsync"); + else + config->setDownloadType("multicast"); + } + else if(key.compare("downloadtype") == 0) config->setDownloadType(value); + } +} + +// this appends a quoted space in case item is empty and resolves +// problems with linbo_cmd's weird "shift"-usage +void LinboBackend::saveappend( QStringList& command, const QString& item ) { + if ( item.isEmpty() ) + command.append(""); + else + command.append( item ); + +} + +// Sync+start image +QStringList LinboBackend::mksyncstartcommand(LinboConfig& config, LinboOs& os) { + QStringList command = LINBO_CMD("syncstart"); + saveappend( command, config.getServer() ); + saveappend( command, config.getCache() ); + saveappend( command, os.getBaseImage()->getName() ); + saveappend( command, os.getDifferentialImage()->getName() ); + saveappend( command, os.getBootPartition() ); // boot is same as root + saveappend( command, os.getRootPartition() ); + saveappend( command, os.getKernel() ); + saveappend( command, os.getInitrd() ); + saveappend( command, os.getKernelOptions() ); + return command; +} + +// Sync image from cache +QStringList LinboBackend::mksynccommand(LinboConfig& config, LinboOs& os) { + QStringList command = LINBO_CMD("sync"); + saveappend( command, config.getCache() ); + saveappend( command, os.getBaseImage()->getName() ); + saveappend( command, os.getDifferentialImage()->getName() ); + saveappend( command, os.getBootPartition() ); + saveappend( command, os.getRootPartition() ); + saveappend( command, os.getKernel() ); + saveappend( command, os.getInitrd() ); + saveappend( command, os.getKernelOptions() ); + return command; +} + +// Sync image from server +QStringList LinboBackend::mksyncrcommand(LinboConfig& config, LinboOs& os) { + QStringList command = LINBO_CMD("syncr"); + saveappend( command, config.getServer() ); + saveappend( command, config.getCache() ); + saveappend( command, os.getBaseImage()->getName() ); + saveappend( command, os.getDifferentialImage()->getName() ); + saveappend( command, os.getBootPartition() ); + saveappend( command, os.getRootPartition() ); + saveappend( command, os.getKernel() ); + saveappend( command, os.getInitrd() ); + saveappend( command, os.getKernelOptions() ); + saveappend( command, QString("force") ); + return command; +} + +QStringList LinboBackend::mkpartitioncommand(vector &p) { + QStringList command = LINBO_CMD("partition"); + for(unsigned int i=0; i &p) { + QStringList command = LINBO_CMD("partition_noformat"); + for(unsigned int i=0; i &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; +} diff --git a/sources/backend/linboconfig.cpp b/sources/backend/linboconfig.cpp new file mode 100644 index 0000000..e86eca6 --- /dev/null +++ b/sources/backend/linboconfig.cpp @@ -0,0 +1,30 @@ +/**************************************************************************** + ** 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 . + ****************************************************************************/ + +#include "../../headers/backend/linboconfig.h" + +LinboConfig::LinboConfig(QObject *parent) : QObject(parent) +{ + autoPartition = 0; + autoInitCache = 0; + backgroundFontcolor = "black"; + consoleFontcolorStdout = "white"; + consoleFontcolorStderr = "red"; + downloadType = "rsync"; + autoFormat = 0; +} diff --git a/sources/backend/linbodiskpartition.cpp b/sources/backend/linbodiskpartition.cpp new file mode 100644 index 0000000..da6e292 --- /dev/null +++ b/sources/backend/linbodiskpartition.cpp @@ -0,0 +1,24 @@ +/**************************************************************************** + ** 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 . + ****************************************************************************/ + +#include "../../headers/backend/linbodiskpartition.h" + +LinboDiskPartition::LinboDiskPartition(QObject *parent) : QObject(parent) +{ + +} diff --git a/sources/backend/linboimage.cpp b/sources/backend/linboimage.cpp new file mode 100644 index 0000000..2355bac --- /dev/null +++ b/sources/backend/linboimage.cpp @@ -0,0 +1,24 @@ +/**************************************************************************** + ** 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 . + ****************************************************************************/ + +#include "../../headers/backend/linboimage.h" + +LinboImage::LinboImage(QString name, QObject *parent) : QObject(parent) +{ + this->setName(name); +} diff --git a/sources/backend/linboos.cpp b/sources/backend/linboos.cpp new file mode 100644 index 0000000..61a1966 --- /dev/null +++ b/sources/backend/linboos.cpp @@ -0,0 +1,29 @@ +/**************************************************************************** + ** 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 . + ****************************************************************************/ + +#include "../../headers/backend/linboos.h" + +LinboOs::LinboOs(QObject *parent) : QObject(parent) +{ +autostart = false; +autostartTimeout = 0; +hidden = false; +defaultAction = QString("sync"); +// TODO ?? image_history.clear(); +iconName = QString("defaultIcon.svg"); +} diff --git a/sources/legacy/linboGUIImpl.cc b/sources/legacy/linboGUIImpl.cc index 7e65a2e..657c47e 100644 --- a/sources/legacy/linboGUIImpl.cc +++ b/sources/legacy/linboGUIImpl.cc @@ -340,7 +340,6 @@ linboGUIImpl::linboGUIImpl(QWidget* parent) : QDialog(parent) waiting->update(); waiting->execute(); -#ifndef TEST_ENV QWSServer* wsServer = QWSServer::instance(); QImage bgimg( "/icons/linbo_wallpaper.png", "PNG" ); @@ -348,17 +347,9 @@ linboGUIImpl::linboGUIImpl(QWidget* parent) : QDialog(parent) wsServer->setBackground( QBrush( bgimg.scaled( qRect.width(), qRect.height(), Qt::IgnoreAspectRatio ) ) ); wsServer->refresh(); } -#endif - - // check whether we need to invert the color of some of our labels because of a - // dark background picture ifstream input; -#ifdef TEST_ENV - input.open( "/home/dorian/Pictures/start.conf.win10-ubuntu", ios_base::in ); -#else input.open( "start.conf", ios_base::in ); -#endif QString tmp_qstring; @@ -379,7 +370,8 @@ linboGUIImpl::linboGUIImpl(QWidget* parent) : QDialog(parent) unsigned int i; // Being checked later. for(i = 0; i < elements.size(); i++ ) { if(tmp_os.get_name().lower().compare(elements[i].get_name().lower()) == 0) { - elements[i].image_history.push_back(tmp_image); break; + elements[i].image_history.push_back(tmp_image); + break; } } if(i==elements.size()) { // Not included yet -> new image @@ -1255,7 +1247,7 @@ linboGUIImpl::linboGUIImpl(QWidget* parent) : QDialog(parent) registerbutton->setEnabled( true ); // add tooltip and icon - QToolTip::add( registerbutton, QString("?ffnet den Registrierungsdialog zur Aufnahme neuer Rechner") ); + QToolTip::add( registerbutton, QString("Öffnet den Registrierungsdialog zur Aufnahme neuer Rechner") ); if( withicons ) registerbutton->setIconSet( QIcon( ":/icons/register-22x22.png") ); diff --git a/sources/legacy/linboGUIImplTmp.cpp b/sources/legacy/linboGUIImplTmp.cpp new file mode 100644 index 0000000..b1fae7e --- /dev/null +++ b/sources/legacy/linboGUIImplTmp.cpp @@ -0,0 +1,1265 @@ +//#define NEVERDEF +#ifdef NEVERDEF + +/* class building the LINBO GUI + +Copyright (C) 2007 Martin Oehler +Copyright (C) 2007 Klaus Knopper + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License. + +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 General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + +*/ + +#include "linboGUIImpl.hh" +#include // for signal() +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "linboProgressImpl.hh" +#include "linboMulticastBoxImpl.hh" +#include "linboDialog.hh" +#include "linboYesNoImpl.hh" +#include "linboInputBoxImpl.hh" +#include "linboImageSelectorImpl.hh" +#include "linboImageUploadImpl.hh" +#include "linboInfoBrowserImpl.hh" +#include "linboRegisterBoxImpl.hh" +#include "linboConsoleImpl.hh" +#include +#include +#include +#include + +#define LINBO_CMD(arg) QStringList("linbo_cmd") << (arg); + + +linboGUIImpl::linboGUIImpl(QWidget* parent) : QDialog(parent) + +{ + + Ui_linboGUI::setupUi((QDialog*)this); + + QImage tmpImage; + + // our early default + fonttemplate = tr("%1"); + + logConsole = new linboLogConsole(0); + + // reset root - we're an user now + root = false; + + // we want to see icons + withicons = true; + + // show command output on LINBO console + outputvisible = true; + + // default setting -> no image selected for autostart + autostart = 0; + autostarttimeout = 0; + + // first "last visited" tab is start tab + preTab = 0; + + // logfilepath + logfilepath = QString("/tmp/linbo.log"); + + // clear buttons array + p_buttons.clear(); + buttons_config.clear(); + // hide the main GUI + this->hide(); + + waiting = new linboMsgImpl( this ); + waiting->message->setText( QString("LINBO
Netzwerk Check") ); + + QStringList waitCommand = LINBO_CMD("ready"); + + waiting->setCommand( waitCommand ); + + waiting->show(); + waiting->raise(); + waiting->setActiveWindow(); + waiting->update(); + waiting->execute(); + + + // we can set this now since our globals have been read + logConsole->setLinboLogConsole( config.get_consolefontcolorstdout(), + config.get_consolefontcolorstderr(), + Console ); + + int height = 5; + int imagingHeight = 5; + + QStringList command; + + startView->setHScrollBarMode(Q3ScrollView::AlwaysOff); + startView->setVScrollBarMode(Q3ScrollView::Auto); + startView->setGeometry( QRect( 10, 10, 600, 180 ) ); + startView->viewport()->setBackgroundColor( "white" ); + + imagingView->setHScrollBarMode(Q3ScrollView::AlwaysOff); + imagingView->setVScrollBarMode(Q3ScrollView::Auto); + imagingView->setGeometry( QRect( 10, 10, 410, 180 ) ); + imagingView->viewport()->setBackgroundColor( "white" ); + + partitionView->setHScrollBarMode(Q3ScrollView::AlwaysOff); + partitionView->setVScrollBarMode(Q3ScrollView::Auto); + partitionView->setGeometry( QRect( 420, 10, 180, 180 ) ); + partitionView->viewport()->setBackgroundColor( "white" ); + + + // since some tabs can be hidden, we have to maintain this counter + int nextPosForTabInsert = 0; + int horizontalOffset = 0; + // this is for separating the elements + int innerVerticalOffset = 32; + + for( unsigned int i = 0; i < elements.size(); i++ ) { + // this determines our vertical offset + if( i % 2 == 1 ) { + // an odd element is moved to the right + horizontalOffset = 300; + } else { + horizontalOffset = 0; + } + + int n = elements[i].find_current_image(); + if ( i == 0 ) { + height = 14; + imagingHeight = 14; + } + // Start View + QLabel *startlabel = new QLabel( startView->viewport() ); + startlabel->setGeometry( QRect( (90 + horizontalOffset), height, 180, 30 ) ); + startlabel->setText( elements[i].get_name() + " " + elements[i].image_history[n].get_version() ); + startView->addChild( startlabel, (90 + horizontalOffset), height ); + + // Imaging View + QLabel *imaginglabel = new QLabel( imagingView->viewport() ); + imaginglabel->setGeometry( QRect( 15, imagingHeight, 165, 30 ) ); + imaginglabel->setText( elements[i].get_name() ); + imagingView->addChild( imaginglabel, 15, imagingHeight ); + + if( i == 0 ) { + height = 5; + imagingHeight = 5; + } + // Start Tab + linbopushbutton *defaultbutton = new linbopushbutton( startView->viewport() ); + defaultbutton->setGeometry( QRect( (15 + horizontalOffset), height, 64, 64 ) ); + + QLabel *defaultactionlabel = new QLabel( startView->viewport() ); + defaultactionlabel->setGeometry( QRect( (15 + horizontalOffset), height+42, 22, 22 ) ); + + if( withicons ) { + if( elements[i].get_iconname() == "defaulticon.png" ) { + defaultbutton->setIconSet( QIcon(":/icons/default.png" ) ); + } else { + defaultbutton->setIconSet( QIcon( QString("/icons/") + elements[i].get_iconname() ) ); + } + defaultbutton->setIconSize( QSize(64,64) ); + } + + if( elements[i].image_history[n].get_defaultaction() == "sync") { + // assign command + command = mksyncstartcommand(config, elements[i],elements[i].image_history[n]); + QToolTip::add( defaultbutton, QString("Startet " + elements[i].get_name() + " " + + elements[i].image_history[n].get_version() + + " synchronisiert") ); + + defaultactionlabel->setPixmap( QPixmap(":/icons/sync+start-22x22.png" ) ); + defaultbutton->setEnabled( elements[i].image_history[n].get_syncbutton() ); + + } + if( elements[i].image_history[n].get_defaultaction() == "new" ) { + // assign command + command = mksyncrcommand(config, elements[i],elements[i].image_history[n]); + QToolTip::add( defaultbutton, QString("Installiert " + elements[i].get_name() + " " + + elements[i].image_history[n].get_version() + + " neu und startet es") ); + + defaultactionlabel->setPixmap( QPixmap(":/icons/new+start-22x22.png" ) ); + defaultbutton->setEnabled( elements[i].image_history[n].get_newbutton() ); + } + if( elements[i].image_history[n].get_defaultaction() == "start" ) { + // assign command + command = LINBO_CMD("start"); + saveappend( command, elements[i].get_boot() ); + saveappend( command, elements[i].get_root() ); + saveappend( command, elements[i].image_history[n].get_kernel() ); + saveappend( command, elements[i].image_history[n].get_initrd() ); + saveappend( command, elements[i].image_history[n].get_append() ); + saveappend( command, config.get_cache() ); + + + QToolTip::add( defaultbutton, QString("Startet " + elements[i].get_name() + " " + + elements[i].image_history[n].get_version() + + " unsynchronisiert") ); + + defaultactionlabel->setPixmap( QPixmap(":/icons/start-22x22.png" ) ); + defaultbutton->setEnabled( elements[i].image_history[n].get_startbutton() ); + } + + defaultbutton->setTextBrowser( config.get_consolefontcolorstdout(), + config.get_consolefontcolorstderr(), + Console ); + + defaultbutton->setMainApp( (QDialog*)this ); + defaultbutton->setCommand( command ); + defaultbutton->setMainApp( this ); + + // assign button to button list + p_buttons.push_back( defaultbutton ); + buttons_config.push_back( 1 ); + // startView->addChild( defaultbutton, (90 + horizontalOffset), (height + innerVerticalOffset) ); + + linbopushbutton *syncbutton = new linbopushbutton( startView->viewport() ); + syncbutton->setGeometry( QRect( (90 + horizontalOffset), (height + innerVerticalOffset), 32, 32 ) ); + // syncbutton->setText( QString("Sync+Start") ); + syncbutton->setTextBrowser( config.get_consolefontcolorstdout(), + config.get_consolefontcolorstderr(), + Console ); + + // add tooltip and icon + QToolTip::add( syncbutton, QString("Startet " + elements[i].get_name() + " " + + elements[i].image_history[n].get_version() + + " synchronisiert") ); + + if( withicons ) { + syncbutton->setIconSet( QIcon(":/icons/sync+start-22x22.png" ) ); + syncbutton->setIconSize( QSize(32,32) ); + } + + // assign command + command = mksyncstartcommand(config, elements[i],elements[i].image_history[n]); + syncbutton->setCommand( command ); + syncbutton->setMainApp( this ); + syncbutton->setEnabled( elements[i].image_history[n].get_syncbutton() ); + + // assign button to button list + p_buttons.push_back( syncbutton ); + buttons_config.push_back( elements[i].image_history[n].get_syncbutton() ); + startView->addChild( syncbutton, (90 + horizontalOffset), (height + innerVerticalOffset) ); + + // Start Tab + linbopushbutton *startbutton = new linbopushbutton( startView->viewport() ); + startbutton->setGeometry( QRect( (124 + horizontalOffset), (height + innerVerticalOffset), 32, 32 ) ); + // startbutton->setText( QString("Start") ); + startbutton->setTextBrowser( config.get_consolefontcolorstdout(), + config.get_consolefontcolorstderr(), + Console ); + + // add tooltip and icon + QToolTip::add( startbutton, QString("Startet " + elements[i].get_name() + " " + + elements[i].image_history[n].get_version() + + " unsynchronisiert") ); + + if( withicons ) { + startbutton->setIconSet( QIcon(":/icons/start-22x22.png" ) ); + startbutton->setIconSize( QSize(32,32) ); + } + + // build "start" command + command = LINBO_CMD("start"); + saveappend( command, elements[i].get_boot() ); + saveappend( command, elements[i].get_root() ); + saveappend( command, elements[i].image_history[n].get_kernel() ); + saveappend( command, elements[i].image_history[n].get_initrd() ); + saveappend( command, elements[i].image_history[n].get_append() ); + saveappend( command, config.get_cache() ); + + startbutton->setCommand( command ); + startbutton->setMainApp( this ); + startbutton->setEnabled( elements[i].image_history[n].get_startbutton() ); + + // assign button to button list + p_buttons.push_back( startbutton ); + buttons_config.push_back( elements[i].image_history[n].get_startbutton() ); + startView->addChild( startbutton, (124 + horizontalOffset), (height + innerVerticalOffset) ); + + // Imaging Tab + linbopushbutton *createbutton = new linbopushbutton( imagingView->viewport() ); + createbutton->setGeometry( QRect( 150, imagingHeight, 120, 30 ) ); + createbutton->setText( QString("Image erstellen") ); + createbutton->setTextBrowser( config.get_consolefontcolorstdout(), + config.get_consolefontcolorstderr(), + Console ); + + linboImageSelectorImpl *buildImageSelector = new linboImageSelectorImpl( createbutton ); + // clear list + buildImageSelector->listBox->clear(); + + // incremental image - when assigned + if( !(elements[i].image_history[n].get_image().stripWhiteSpace()).isEmpty() ) + buildImageSelector->listBox->insertItem(elements[i].image_history[n].get_image()); + + // fill list with images + // base image + buildImageSelector->listBox->insertItem(elements[i].get_baseimage()); + + // entry for creating a new image + buildImageSelector->listBox->insertItem( QString("[Neuer Dateiname]") ); + + + buildImageSelector->setTextBrowser( config.get_consolefontcolorstdout(), + config.get_consolefontcolorstderr(), + Console ); + buildImageSelector->setCache( config.get_cache() ); + buildImageSelector->setBaseImage( elements[i].get_baseimage() ); + buildImageSelector->setMainApp( this ); + + command = LINBO_CMD("readfile"); + saveappend( command, config.get_cache() ); + saveappend( command, elements[i].get_baseimage() + QString(".desc") ); + saveappend( command, ( QString("/tmp/") + elements[i].get_baseimage() + QString(".desc") ) ); + buildImageSelector->setLoadCommand( command ); + + command = LINBO_CMD("writefile"); + saveappend( command, config.get_cache() ); + saveappend( command, ( elements[i].get_baseimage() + QString(".desc") ) ); + saveappend( command, ( QString("/tmp/") + elements[i].get_baseimage() + QString(".desc") ) ); + buildImageSelector->setSaveCommand( command ); + + createbutton->setLinboDialog( (linboDialog*)(buildImageSelector) ); + createbutton->setQDialog( (QDialog*)(buildImageSelector) ); + createbutton->setProgress( false ); + createbutton->setEnabled( true ); + createbutton->setMainApp((QDialog*)this ); + + // add tooltip and icon + QToolTip::add( createbutton, QString("Ein neues Image f?r " + elements[i].get_name() + " " + + elements[i].image_history[n].get_version() + + " erstellen") ); + + if( withicons ) { + createbutton->setIconSet( QIcon( ":/icons/image-22x22.png" ) ); + createbutton->setIconSize( QSize(32,32) ); + } + + + // build "create" command + command = LINBO_CMD("create"); + saveappend( command, config.get_cache() ); + + saveappend( command, (elements[i].image_history[n].get_image()) ); + saveappend( command, (elements[i].get_baseimage()) ); + saveappend( command, (elements[i].get_boot()) ); + saveappend( command, (elements[i].get_root()) ); + saveappend( command, (elements[i].image_history[n].get_kernel()) ); + saveappend( command, (elements[i].image_history[n].get_initrd()) ); + buildImageSelector->setCommand( command ); + + // this is done really late now to prevent segfaulting our main app (because + // commands are not set earlier) + buildImageSelector->listBox->setSelected(0,true); + + // assign button to button list + p_buttons.push_back( createbutton ); + buttons_config.push_back( 1 ); + imagingView->addChild( createbutton, 150, imagingHeight ); + + // Start Tab + linbopushbutton *newbutton = new linbopushbutton( startView->viewport() ); + newbutton->setGeometry( QRect( (158 + horizontalOffset), (height + innerVerticalOffset), 32, 32 ) ); + // newbutton->setText( QString("Neu+Start") ); + newbutton->setTextBrowser( config.get_consolefontcolorstdout(), + config.get_consolefontcolorstderr(), + Console ); + + // add tooltip and icon + QToolTip::add( newbutton, QString("Installiert " + elements[i].get_name() + " " + + elements[i].image_history[n].get_version() + + " neu und startet es") ); + + if( withicons ) { + newbutton->setIconSet( QIcon( ":/icons/new+start-22x22.png" ) ); + newbutton->setIconSize( QSize(32,32) ); + } + + + // assign command + command = mksyncrcommand(config, elements[i],elements[i].image_history[n]); + newbutton->setCommand( command ); + newbutton->setMainApp((QDialog*)this ); + newbutton->setEnabled( elements[i].image_history[n].get_newbutton() ); + + // assign button to button list + p_buttons.push_back( newbutton ); + buttons_config.push_back( elements[i].image_history[n].get_newbutton() ); + startView->addChild( newbutton, (158 + horizontalOffset), (height + innerVerticalOffset) ); + + linbopushbutton *infobuttonstart = new linbopushbutton( startView->viewport() ); + infobuttonstart->setGeometry( QRect( (192 + horizontalOffset), (height + innerVerticalOffset), 32, 32 ) ); + // infobuttonstart->setText( QString("Info") ); + infobuttonstart->setEnabled( true ); + infobuttonstart->setTextBrowser( config.get_consolefontcolorstdout(), + config.get_consolefontcolorstderr(), + Console ); + + // add tooltip and icon + QToolTip::add( infobuttonstart, QString("Informationen zu " + elements[i].get_name() + " " + + elements[i].image_history[n].get_version()) ); + + if( withicons ) { + infobuttonstart->setIconSet( QIcon( ":/icons/information-22x22.png" ) ); + infobuttonstart->setIconSize( QSize(32,32) ); + } + + linboInfoBrowserImpl *infoBrowser = new linboInfoBrowserImpl( infobuttonstart ); + infoBrowser->setTextBrowser( config.get_consolefontcolorstdout(), + config.get_consolefontcolorstderr(), + Console ); + infoBrowser->setMainApp( this ); + infoBrowser->setFilePath( QString("/tmp/") + elements[i].get_baseimage() + QString(".desc") ); + + command = LINBO_CMD("readfile"); + saveappend( command, config.get_cache() ); + saveappend( command, ( elements[i].get_baseimage() + QString(".desc") ) ); + saveappend( command, ( QString("/tmp/") + elements[i].get_baseimage() + QString(".desc") ) ); + infoBrowser->setLoadCommand( command ); + + command = LINBO_CMD("writefile"); + saveappend( command, config.get_cache() ); + saveappend( command, ( elements[i].get_baseimage() + QString(".desc") ) ); + saveappend( command, ( QString("/tmp/") + elements[i].get_baseimage() + QString(".desc") ) ); + infoBrowser->setSaveCommand( command ); + + command = LINBO_CMD("upload"); + saveappend( command, config.get_server() ); + saveappend( command, QString("linbo") ); + saveappend( command, QString("password") ); + saveappend( command, config.get_cache() ); + saveappend( command, ( elements[i].get_baseimage() + QString(".desc") ) ); + infoBrowser->setUploadCommand( command ); + + infobuttonstart->setProgress( false ); + infobuttonstart->setMainApp((QDialog*)this ); + infobuttonstart->setLinboDialog( (linboDialog*)(infoBrowser) ); + infobuttonstart->setQDialog( (QDialog*)(infoBrowser) ); + + // assign button to button list + p_buttons.push_back( infobuttonstart ); + buttons_config.push_back( 1 ); + startView->addChild( infobuttonstart, (192 + horizontalOffset), (height + innerVerticalOffset) ); + + // Imaging Tab + linbopushbutton *uploadbutton = new linbopushbutton( imagingView->viewport() ); + uploadbutton->setGeometry( QRect( 270, imagingHeight, 120, 30 ) ); + uploadbutton->setText( QString("Image hochladen") ); + uploadbutton->setEnabled( true ); + uploadbutton->setTextBrowser( config.get_consolefontcolorstdout(), + config.get_consolefontcolorstderr(), + Console ); + + // add tooltip and icon + QToolTip::add( uploadbutton, QString("Ein Image f?r " + elements[i].get_name() + " " + + elements[i].image_history[n].get_version() + + " auf den Server hochladen" ) ); + + if( withicons ) + uploadbutton->setIconSet( QIcon( ":/icons/upload-22x22.png" ) ); + + linboImageUploadImpl *imageUpload = new linboImageUploadImpl( uploadbutton); + imageUpload->setTextBrowser( config.get_consolefontcolorstdout(), + config.get_consolefontcolorstderr(), + Console ); + imageUpload->setMainApp( this ); + + // clear list + imageUpload->listBox->clear(); + // fill list with images + + // incremental image - when assigned + if( !(elements[i].image_history[n].get_image().stripWhiteSpace()).isEmpty() ) + imageUpload->listBox->insertItem(elements[i].image_history[n].get_image()); + + // base image + imageUpload->listBox->insertItem(elements[i].get_baseimage()); + + command = LINBO_CMD("upload"); + saveappend( command, config.get_server() ); + saveappend( command, QString("linbo") ); + saveappend( command, QString("password") ); + saveappend( command, config.get_cache() ); + if( (elements[i].image_history[n].get_image().stripWhiteSpace()).isEmpty() ) { + saveappend( command, elements[i].get_baseimage() ); + } else { + saveappend( command, elements[i].image_history[n].get_image() ); + } + imageUpload->setCommand( command ); + + uploadbutton->setMainApp((QDialog*)this ); + uploadbutton->setLinboDialog( (linboDialog*)(imageUpload) ); + uploadbutton->setQDialog( (QDialog*)(imageUpload) ); + uploadbutton->setProgress( false ); + + // assign button to button list + p_buttons.push_back( uploadbutton ); + buttons_config.push_back( 1 ); + imagingView->addChild( uploadbutton, 270, imagingHeight ); + + // where is my homie? + createbutton->setNeighbour( uploadbutton ); + uploadbutton->setNeighbour( createbutton ); + + + + // only for an odd element + if( i % 2 == 1 ) { + height += 69; + } + + // the height of 69 is one complete element row, 5 is our start height + startView->resizeContents( 600, ( (int)((i+2)/2) * 69 + 5 ) ); + + imagingHeight += 32; + + int height2 = 5; + + // check: if one of the history entries is declared hidden, + // hide the complete tab + bool isHidden = false; + + for( unsigned int n = 0; n < elements[i].image_history.size(); n++ ) { + isHidden |= elements[i].image_history[n].get_hidden(); + } + + // check whether our per-OS tabs should be displayed or not + // we save a lot of memory by not building these elements + if ( !isHidden ) { + QWidget* newtab = new QWidget( Tabs ); + Q3ScrollView* view = new Q3ScrollView( newtab ); + + view->setHScrollBarMode(Q3ScrollView::AlwaysOff); + view->setVScrollBarMode(Q3ScrollView::Auto); + view->viewport()->setBackgroundColor( "white" ); + view->setGeometry( QRect( 10, 10, 600, 180 ) ); + + int iHorizontalOffset = 0; + + for( unsigned int n = 0; n < elements[i].image_history.size(); n++ ) { + + // QT BUG! + if ( n == 0 ) { + height2 = 14; + } + + if( n % 2 == 1 ) { + // an odd element is moved to the right + iHorizontalOffset = 300; + } else { + iHorizontalOffset = 0; + } + QLabel *imagename = new QLabel( view->viewport() ); + imagename->setGeometry( QRect( (90 + iHorizontalOffset), height2, 180, 30 ) ); + imagename->setText( elements[i].image_history[n].get_version() + ";" + elements[i].image_history[n].get_description() ); + view->addChild( imagename, (90 + iHorizontalOffset), height2 ); + if ( n == 0 ) { + height2 = 5; + } + + /* QLabel *imagetext = new QLabel( view->viewport() ); + imagetext->setGeometry( QRect( 120, height2, 260, 30 ) ); + imagetext->setText( elements[i].image_history[n].get_description() ); + view->addChild( imagetext, 120, height2 ); + */ + + linbopushbutton *idefaultbutton = new linbopushbutton( view->viewport() ); + idefaultbutton->setGeometry( QRect( (15 + iHorizontalOffset), height2, 64, 64 ) ); + + QLabel *idefaultactionlabel = new QLabel( startView->viewport() ); + idefaultactionlabel->setGeometry( QRect( (15 + iHorizontalOffset), height2+42, 22, 22 ) ); + + + if( withicons ) { + if( elements[i].get_iconname() == "defaulticon.png" ) { + // TODO: choose another default icon - something that looks like the LINBO-Logo + idefaultbutton->setIconSet( QIcon(":/icons/default.png" ) ); + } else { + idefaultbutton->setIconSet( QIcon( QString("/icons/") + elements[i].get_iconname() ) ); + } + idefaultbutton->setIconSize( QSize(64,64) ); + } + + if( elements[i].image_history[n].get_defaultaction() == "sync") { + // assign command + command = mksyncstartcommand(config, elements[i],elements[i].image_history[n]); + QToolTip::add( idefaultbutton, QString("Startet " + elements[i].get_name() + " " + + elements[i].image_history[n].get_version() + + " synchronisiert") ); + + idefaultactionlabel->setPixmap( QPixmap(":/icons/sync+start-22x22.png" ) ); + } + if( elements[i].image_history[n].get_defaultaction() == "new" ) { + // assign command + command = mksyncrcommand(config, elements[i],elements[i].image_history[n]); + QToolTip::add( idefaultbutton, QString("Installiert " + elements[i].get_name() + " " + + elements[i].image_history[n].get_version() + + " neu und startet es") ); + + defaultactionlabel->setPixmap( QPixmap(":/icons/new+start-22x22.png" ) ); + } + if( elements[i].image_history[n].get_defaultaction() == "start" ) { + // assign command + command = LINBO_CMD("start"); + saveappend( command, elements[i].get_boot() ); + saveappend( command, elements[i].get_root() ); + saveappend( command, elements[i].image_history[n].get_kernel() ); + saveappend( command, elements[i].image_history[n].get_initrd() ); + saveappend( command, elements[i].image_history[n].get_append() ); + saveappend( command, config.get_cache() ); + + + QToolTip::add( idefaultbutton, QString("Startet " + elements[i].get_name() + " " + + elements[i].image_history[n].get_version() + + " unsynchronisiert") ); + + defaultactionlabel->setPixmap( QPixmap(":/icons/start-22x22.png" ) ); + } + + idefaultbutton->setCommand( command ); + idefaultbutton->setTextBrowser( config.get_consolefontcolorstdout(), + config.get_consolefontcolorstderr(), + Console ); + idefaultbutton->setMainApp( (QDialog*)this ); + p_buttons.push_back( idefaultbutton ); + buttons_config.push_back( 1 ); + + linbopushbutton *isyncbutton = new linbopushbutton( view->viewport() ); + isyncbutton->setGeometry( QRect( (90 + iHorizontalOffset), (height2 + innerVerticalOffset), 32, 32 ) ); + // isyncbutton->setText( QString("Sync+Start") ); + isyncbutton->setTextBrowser( config.get_consolefontcolorstdout(), + config.get_consolefontcolorstderr(), + Console ); + isyncbutton->setEnabled( true ); + + // add tooltip and icon + QToolTip::add( isyncbutton, QString("Startet " + elements[i].get_name() + " " + + elements[i].image_history[n].get_version() + + " synchronisiert") ); + + if( withicons ) { + isyncbutton->setIconSet( QIcon( ":/icons/sync+start-22x22.png" ) ); + isyncbutton->setIconSize( QSize(32,32) ); + } + + command = mksyncstartcommand(config, elements[i],elements[i].image_history[n]); + isyncbutton->setCommand( command ); + isyncbutton->setMainApp((QDialog*)this ); + + // assign button to button list + p_buttons.push_back( isyncbutton ); + buttons_config.push_back( 1 ); + view->addChild( isyncbutton, (90 + iHorizontalOffset), (height2 + innerVerticalOffset) ); + + linbopushbutton *irecreatebutton = new linbopushbutton( view->viewport() ); + irecreatebutton->setGeometry( QRect( (124 + iHorizontalOffset), (height2 + innerVerticalOffset), 32, 32 ) ); + // irecreatebutton->setText( QString("Neu+Start") ); + irecreatebutton->setTextBrowser( config.get_consolefontcolorstdout(), + config.get_consolefontcolorstderr(), + Console ); + + command = mksyncrcommand(config, elements[i],elements[i].image_history[n]); + irecreatebutton->setCommand( command ); + irecreatebutton->setEnabled( true ); + + // add tooltip and icon + QToolTip::add( irecreatebutton, QString("Installiert " + elements[i].get_name() + " " + + elements[i].image_history[n].get_version() + + " neu und startet es") ); + + if( withicons ) { + irecreatebutton->setIconSet( QIcon( ":/icons/new+start-22x22.png" ) ); + irecreatebutton->setIconSize( QSize(32,32) ); + } + + irecreatebutton->setMainApp(this ); + // assign button to button list + p_buttons.push_back( irecreatebutton ); + buttons_config.push_back( 1 ); + view->addChild( irecreatebutton, (124 + iHorizontalOffset), (height2 + innerVerticalOffset) ); + + linbopushbutton *iinfobuttonstart = new linbopushbutton( view->viewport() ); + iinfobuttonstart->setGeometry( QRect( (158 + iHorizontalOffset), (height2 + innerVerticalOffset), 32, 32 ) ); + // iinfobuttonstart->setText( QString("Info") ); + iinfobuttonstart->setEnabled( true ); + iinfobuttonstart->setTextBrowser( config.get_consolefontcolorstdout(), + config.get_consolefontcolorstderr(), + Console ); + + linboInfoBrowserImpl *iinfoBrowser = new linboInfoBrowserImpl( iinfobuttonstart ); + iinfoBrowser->setTextBrowser( config.get_consolefontcolorstdout(), + config.get_consolefontcolorstderr(), + Console ); + iinfoBrowser->setMainApp(this); + iinfoBrowser->setFilePath( QString("/tmp/") + elements[i].get_baseimage() + QString(".desc") ); + iinfobuttonstart->setProgress( false ); + iinfobuttonstart->setMainApp(this ); + + command = LINBO_CMD("readfile"); + saveappend( command, config.get_cache() ); + saveappend( command, ( elements[i].get_baseimage() + QString(".desc") ) ); + saveappend( command, ( QString("/tmp/") + elements[i].get_baseimage() + QString(".desc") ) ); + iinfoBrowser->setLoadCommand( command ); + + command = LINBO_CMD("writefile"); + saveappend( command, config.get_cache() ); + saveappend( command, ( elements[i].get_baseimage() + QString(".desc") ) ); + saveappend( command, ( QString("/tmp/") + elements[i].get_baseimage() + QString(".desc") ) ); + iinfoBrowser->setSaveCommand( command ); + + command = LINBO_CMD("upload"); + saveappend( command, config.get_server() ); + saveappend( command, QString("linbo") ); + saveappend( command, QString("password") ); + saveappend( command, config.get_cache() ); + saveappend( command, ( QString("/tmp/") + elements[i].get_baseimage() + QString(".desc") ) ); + iinfoBrowser->setUploadCommand( command ); + + iinfobuttonstart->setLinboDialog( (linboDialog*)(infoBrowser) ); + iinfobuttonstart->setQDialog( (QDialog*)(infoBrowser) ); + + // add tooltip and icon + QToolTip::add( iinfobuttonstart, QString("Informationen zu " + elements[i].get_name() + " " + + elements[i].image_history[n].get_version()) ); + + if( withicons ) { + iinfobuttonstart->setIconSet( QIcon( ":/icons/information-22x22.png" ) ); + iinfobuttonstart->setIconSize(QSize(32,32)); + } + + // assign button to button list + p_buttons.push_back( iinfobuttonstart ); + buttons_config.push_back( 1 ); + view->addChild( iinfobuttonstart, (158 + iHorizontalOffset), (height2 + innerVerticalOffset) ); + + if( elements[i].image_history[n].get_autostart() && + !autostart ) { + + + logConsole->writeStdOut( QString("Autostart selected for OS Nr. ") + + QString::number(i) + + QString(", Image History Nr. ") + + QString::number( n )); + + autostart = idefaultbutton; + autostarttimeout = elements[i].image_history[n].get_autostarttimeout(); + } + + + + if( n % 2 == 1 ) { + height2 += 69; + } + // the height of 69 is one complete element row + view->resizeContents( 600, ( (int)((n+2)/2) * 69 + 5 ) ); + } + Tabs->insertTab( newtab, elements[i].get_name(), (nextPosForTabInsert+1) ); + nextPosForTabInsert++; + } else { + // in case one of the elements is marked as "Autostart", we have to create the + // matching, invisible sync+start button + + for( unsigned int n = 0; n < elements[i].image_history.size(); n++ ) { + + if( elements[i].image_history[n].get_autostart() && + !autostart ) { + + logConsole->writeStdOut( QString("Autostart selected for OS Nr. ") + + QString::number(i) + + QString(", Image History Nr. ") + + QString::number( n ) ); + + autostart = defaultbutton; + autostarttimeout = elements[i].image_history[n].get_autostarttimeout(); + } + } + } + + } + + imagingView->resizeContents( 410, imagingHeight ); + + // the first element of a view does have display problems so we add a dummy + QLabel *partitionlabel = new QLabel( partitionView->viewport() ); + partitionlabel->setGeometry( QRect( 5, 5, 165, 30 ) ); + partitionlabel->setText(""); + partitionView->addChild( partitionlabel, 5,5 ); + + linbopushbutton *consolebuttonimaging = new linbopushbutton( partitionView->viewport() ); + // left-align graphics and text + consolebuttonimaging->setStyleSheet("QPushButton{text-align : left; padding-left: 5px;}"); + consolebuttonimaging->setGeometry( QRect( 15, 27, 130, 30 ) ); + consolebuttonimaging->setText( QString("Console") ); + consolebuttonimaging->setTextBrowser( config.get_consolefontcolorstdout(), + config.get_consolefontcolorstderr(), + Console ); + + linboConsoleImpl *linboconsole = new linboConsoleImpl( consolebuttonimaging ); + linboconsole->setMainApp(this ); + linboconsole->setTextBrowser( config.get_consolefontcolorstdout(), + config.get_consolefontcolorstderr(), + Console ); + + consolebuttonimaging->setProgress( false ); + consolebuttonimaging->setMainApp(this ); + consolebuttonimaging->setLinboDialog( (linboDialog*)(linboconsole) ); + consolebuttonimaging->setQDialog( (QDialog*)(linboconsole) ); + + // add tooltip and icon + QToolTip::add( consolebuttonimaging, QString("Öffnet das Konsolenfenster") ); + + if( withicons ) + consolebuttonimaging->setIconSet( QIcon( ":/icons/console-22x22.png" ) ); + + // assign button to button list + p_buttons.push_back( consolebuttonimaging ); + buttons_config.push_back( 1 ); + partitionView->addChild( consolebuttonimaging, 15, 27 ); + + linbopushbutton *multicastbuttonimaging = new linbopushbutton( partitionView->viewport() ); + // left-align graphics and text + multicastbuttonimaging->setStyleSheet("QPushButton{text-align : left; padding-left: 5px;}"); + multicastbuttonimaging->setGeometry( QRect( 15, 59, 130, 30 ) ); + multicastbuttonimaging->setText( QString("Cache aktualisieren") ); + multicastbuttonimaging->setTextBrowser( config.get_consolefontcolorstdout(), + config.get_consolefontcolorstderr(), + Console ); + + // add tooltip and icon + QToolTip::add( multicastbuttonimaging, QString("Aktualisiert den lokalen Cache") ); + + if( withicons ) + multicastbuttonimaging->setIconSet( QIcon( ":/icons/cache-22x22.png" ) ); + + linboMulticastBoxImpl *multicastbox = new linboMulticastBoxImpl( multicastbuttonimaging ); + multicastbox->setMainApp(this ); + multicastbox->setTextBrowser( config.get_consolefontcolorstdout(), + config.get_consolefontcolorstderr(), + Console ); + + multicastbox->setRsyncCommand( mkcacheinitcommand( config, elements, QString("rsync")) ); + multicastbox->setMulticastCommand( mkcacheinitcommand( config, elements, QString("multicast")) ); + multicastbox->setBittorrentCommand( mkcacheinitcommand( config, elements, QString("torrent")) ); + + multicastbuttonimaging->setProgress( false ); + multicastbuttonimaging->setMainApp(this ); + multicastbuttonimaging->setLinboDialog( (linboDialog*)(multicastbox) ); + multicastbuttonimaging->setQDialog( (QDialog*)(multicastbox) ); + + autoinitcache = 0; + // this button MUSTN't have a parent, otherwise we get a artifact button + // inside the imaging tab + linbopushbutton *autoinitcachebutton = new linbopushbutton(0); + // this invisible button is needed für autoinitcache + if( config.get_autoinitcache() ) { + autoinitcachebutton->setTextBrowser( config.get_consolefontcolorstdout(), + config.get_consolefontcolorstderr(), + Console ); + autoinitcachebutton->setMainApp(this ); + autoinitcachebutton->setProgress( true ); + autoinitcachebutton->setCommand( mkcacheinitcommand( config, elements, config.get_downloadtype() ) ); + autoinitcache = autoinitcachebutton; + autoinitcachebutton->hide(); + } + + // assign button to button list + p_buttons.push_back( multicastbuttonimaging ); + buttons_config.push_back( 1 ); + partitionView->addChild( multicastbuttonimaging, 15, 59 ); + + // Partition button - Imaging tab + linbopushbutton *partitionbutton = new linbopushbutton( partitionView->viewport() ); + // left-align graphics and text + partitionbutton->setStyleSheet("QPushButton{text-align : left; padding-left: 5px;}"); + partitionbutton->setGeometry( QRect( 15, 91, 130, 30 ) ); + partitionbutton->setText( QString("Partitionieren") ); + partitionbutton->setTextBrowser( config.get_consolefontcolorstdout(), + config.get_consolefontcolorstderr(), + Console ); + partitionbutton->setMainApp(this ); + partitionbutton->setEnabled( true ); + + // add tooltip and icon + QToolTip::add( partitionbutton, QString("Partitioniert die Festplatte neu") ); + + if( withicons ) + partitionbutton->setIconSet( QIcon( ":/icons/partition-22x22.png" ) ); + + linboYesNoImpl *yesNoPartition = new linboYesNoImpl( partitionbutton); + yesNoPartition->question->setText("Alle Daten auf der Festplatte löschen?"); + yesNoPartition->setTextBrowser( config.get_consolefontcolorstdout(), + config.get_consolefontcolorstderr(), + Console ); + yesNoPartition->setMainApp(this ); + yesNoPartition->setCommand(mkpartitioncommand(partitions)); + + autopartition = 0; + linbopushbutton *autopartitionbutton = new linbopushbutton(); + // this invisible button is needed f?r autopartition + if( config.get_autopartition() ) { + autopartitionbutton->setTextBrowser( config.get_consolefontcolorstdout(), + config.get_consolefontcolorstderr(), + Console ); + autopartitionbutton->setMainApp(this ); + autopartitionbutton->setProgress( true ); + // here we set whether a partition should be automatically formatted after + // the partition table has been overwritten + if( config.get_autoformat() ) + autopartitionbutton->setCommand(mkpartitioncommand(partitions)); + else + autopartitionbutton->setCommand(mkpartitioncommand_noformat(partitions)); + autopartition = autopartitionbutton; + autopartitionbutton->setHidden( true ); + } + + partitionbutton->setProgress( false ); + + partitionbutton->setLinboDialog( (linboDialog*)(yesNoPartition) ); + partitionbutton->setQDialog( (QDialog*)(yesNoPartition) ); + + + partitionView->addChild( partitionbutton, 15, 91 ); + + // assign button to button list + p_buttons.push_back( partitionbutton ); + buttons_config.push_back( 1 ); + + // RegisterBox button - Imaging tab + linbopushbutton *registerbutton = new linbopushbutton( partitionView->viewport() ); + // left-align graphics and text + registerbutton->setStyleSheet("QPushButton{text-align : left; padding-left: 5px;}"); + registerbutton->setGeometry( QRect( 15, 123, 130, 30 ) ); + registerbutton->setText( QString("Registrieren") ); + registerbutton->setTextBrowser( config.get_consolefontcolorstdout(), + config.get_consolefontcolorstderr(), + Console ); + registerbutton->setMainApp(this ); + registerbutton->setEnabled( true ); + + // add tooltip and icon + QToolTip::add( registerbutton, QString("Öffnet den Registrierungsdialog zur Aufnahme neuer Rechner") ); + + if( withicons ) + registerbutton->setIconSet( QIcon( ":/icons/register-22x22.png") ); + + + linboRegisterBoxImpl *registerBox = new linboRegisterBoxImpl( registerbutton ); + registerBox->setTextBrowser( config.get_consolefontcolorstdout(), + config.get_consolefontcolorstderr(), + Console ); + registerBox->setMainApp(this ); + + //cout << "Preregister command"; + command = LINBO_CMD("preregister"); + saveappend( command, config.get_server() ); + registerBox->setPreCommand( command ); + + + //cout << "Register Command"; + command = LINBO_CMD("register"); + saveappend( command, config.get_server() ); + saveappend( command, QString("linbo") ); + saveappend( command, QString("password") ); + saveappend( command, QString("clientRoom") ); + saveappend( command, QString("clientName") ); + saveappend( command, QString("clientIP") ); + saveappend( command, QString("clientGroup") ); + + registerBox->setCommand( command ); + + registerbutton->setProgress( false ); + + registerbutton->setLinboDialog( (linboDialog*)(registerBox) ); + registerbutton->setQDialog( (QDialog*)(registerBox) ); + + partitionView->addChild( registerbutton, 15, 123 ); + + // assign button to button list + p_buttons.push_back( registerbutton ); + buttons_config.push_back( 1 ); + + buttons_config_save.clear(); + for( unsigned int i = 0; i < p_buttons.size(); i++ ) { + buttons_config_save.push_back( p_buttons[i]->isEnabled() ); + } + + myLPasswordBox = new linboPasswordBoxImpl( this ); + myQPasswordBox = (QDialog*)(myLPasswordBox); + myLPasswordBox->setMainApp(this ); + myLPasswordBox->setTextBrowser( config.get_consolefontcolorstdout(), + config.get_consolefontcolorstderr(), + Console ); + + + // Code for detecting tab changes + connect( Tabs, SIGNAL(currentChanged( QWidget* )), + this, SLOT(tabWatcher( QWidget* )) ); + + // create process for our status bar + + process = new QProcess( this ); + /* connect( process, SIGNAL(readyReadStandardOutput()), + this, SLOT(readFromStdout()) ); + connect( process, SIGNAL(readyReadStandardError()), + this, SLOT(readFromStderr()) ); + */ + + // we don't want to see this on the LINBO Console + outputvisible = false; + + // client ip + command = LINBO_CMD("ip"); + // myprocess->setArguments( command ); + process->start( command.join(" ") ); + while( !process->waitForFinished(10000) ) { + } + + clientIPLabel->setText( fonttemplate.arg(QString("Client IP: ") + process->readAllStandardOutput() ) ); + + // server ip + + // serverIPLabel->setText( QString(" Server IP: ") + config.get_server() ); + + // mac address + command.clear(); + command = LINBO_CMD("mac"); + + process->start( command.join(" ") ); + while( !process->waitForFinished(10000) ) { + } + macLabel->setText( fonttemplate.arg(QString("MAC: ") + process->readAllStandardOutput() ) ); + + // Server and Version +// hostname and hostgroup + + command = LINBO_CMD("version"); + // myprocess->setArguments( command ); + process->start( command.join(" ") ); + while( !process->waitForFinished(10000) ) { + } + + versionLabel->setText( (process->readAllStandardOutput()).stripWhiteSpace() + QString(" - (mod by Dorian Zedler) - auf Server ") + config.get_server()); + + // hostname and hostgroup + + command = LINBO_CMD("hostname"); + // myprocess->setArguments( command ); + process->start( command.join(" ") ); + while( !process->waitForFinished(10000) ) { + } + + + + nameLabel->setText( fonttemplate.arg(QString("Host: ") + process->readAllStandardOutput() ) ); + groupLabel->setText( fonttemplate.arg(QString("Gruppe: ") + config.get_hostgroup() ) ); + + // our clock displaying the system time + myTimer = new QTimer(this); + connect( myTimer, SIGNAL(timeout()), this, SLOT(processTimeout()) ); + myTimer->start( 1000, FALSE ); + + // CPU + command = LINBO_CMD("cpu"); + // myprocess->setArguments( command ); + process->start( command.join(" ") ); + while( !process->waitForFinished(10000) ) { + } + + cpuLabel->setText( fonttemplate.arg(QString("CPU: ") + process->readAllStandardOutput() ) ); + + // Memory + command = LINBO_CMD("memory"); + process->start( command.join(" ") ); + while( !process->waitForFinished(10000) ) { + } + + memLabel->setText( fonttemplate.arg(QString("RAM: ") + process->readAllStandardOutput() ) ); + + // Cache Size + command = LINBO_CMD("size"); + saveappend( command, config.get_cache() ); + process->start( command.join(" ") ); + while( !process->waitForFinished(10000) ) { + } + cacheLabel->setText( fonttemplate.arg(QString("Cache: ") + process->readAllStandardOutput() ) ); + + // Harddisk Size + QRegExp *removePartition = new QRegExp("[0-9]{1,2}"); + QString hd = config.get_cache(); + hd.remove( *removePartition ); + + command = LINBO_CMD("size"); + saveappend( command, hd ); + + process->start( command.join(" ") ); + while( !process->waitForFinished(10000) ) { + } + + hdLabel->setText( fonttemplate.arg(QString("HD: ") + process->readAllStandardOutput() ) ); + + // enable console output again + outputvisible = true; + + // select start tab + Tabs->setCurrentPage(0); + +} + + + +void linboGUIImpl::processTimeout() { + + timeLabel->setText( fonttemplate.arg(QTime::currentTime().toString() ) ); +} + + +void linboGUIImpl::log( const QString& data ) { + // write to our logfile + QFile logfile( logfilepath ); + logfile.open( QIODevice::WriteOnly | QIODevice::Append ); + Q3TextStream logstream( &logfile ); + logstream << data << "\n"; + logfile.flush(); + logfile.close(); +} + +void linboGUIImpl::readFromStdout() +{ + // TODO: reactivate log + // log( linestdout ); + + if( outputvisible ) { + logConsole->writeStdOut( process->readAllStandardOutput() ); + } +} + +void linboGUIImpl::readFromStderr() +{ + // TODO: reactivate log + // log( linestderr ); + + if( outputvisible ) { + + logConsole->writeStdErr( process->readAllStandardError() ); + } + +} + +void linboGUIImpl::executeAutostart() { + + // if there is "autopartition" set, execute the hidden button + if( autopartition ) + autopartition->lclicked(); + + // if there is "autoinitcache" set, execute the hidden button + if( autoinitcache ) + autoinitcache->lclicked(); + + // if there is a with "autostart" declared image, execute the hidden button + if( autostart != 0 ) { + if( autostarttimeout > 0 ) { + + myAutostartTimer = new QTimer(0); + myAutostartTimer->stop(); + myAutostartTimer->start( 1000, FALSE ); + + myCounter = new linboCounterImpl(this); + myCounter->text->setText("Autostart in..."); + myCounter->logoutButton->setText("Autostart abbrechen"); + myCounter->counter->display( autostarttimeout ); + myCounter->timeoutCheck->hide(); + + // connect( myCounter->logoutButton, SIGNAL(pressed()), app, SLOT(resetButtons()) ); + connect( myCounter->logoutButton, SIGNAL(clicked()), myAutostartTimer, SLOT(stop()) ); + connect( myAutostartTimer, SIGNAL(timeout()), this, SLOT(autostartTimeoutSlot()) ); + + myCounter->show(); + myCounter->raise(); + myCounter->move( QPoint( 5, 5 ) ); + + } else { + autostart->lclicked(); + } + } + +} + +void linboGUIImpl::autostartTimeoutSlot() { + if( !myCounter->timeoutCheck->isChecked() ) { + // do nothing but dont stop timer + } + else { + if( autostarttimeout > 0 ) { + autostarttimeout--; + myCounter->counter->display( autostarttimeout ); + } else { + myCounter->hide(); + myCounter->close(); + myAutostartTimer->stop(); + autostart->lclicked(); + this->resetButtons(); + } + } + + +} + +void linboGUIImpl::tabWatcher( QWidget* currentWidget) { + + if( !isRoot() ) { + if( Tabs->tabLabel(currentWidget) == "Imaging" ) { + // if our partition button is disabled, there is a linbo_cmd running + if( p_buttons[ ( p_buttons.size() - 1 ) ]->isEnabled() ) { + Tabs->setCurrentPage( preTab ); + myQPasswordBox->show(); + myQPasswordBox->raise(); + myQPasswordBox->setActiveWindow(); + myQPasswordBox->setEnabled( true ); + } + else { + Tabs->setCurrentPage( preTab ); + } + } + } + if( (Tabs->count() - 1) != Tabs->currentPageIndex() ) + preTab = Tabs->currentPageIndex(); +} + +bool linboGUIImpl::isRoot() const { + return root; +} + +void linboGUIImpl::showImagingTab() { + Tabs->setCurrentPage( (Tabs->count() - 1) ); +} +#endif diff --git a/sources/legacy/linboPushButton.cc b/sources/legacy/linboPushButton.cc index 4e612cc..b49ebc6 100644 --- a/sources/legacy/linboPushButton.cc +++ b/sources/legacy/linboPushButton.cc @@ -3,6 +3,7 @@ #include #include #include +#include #include "linboPushButton.hh" linbopushbutton::linbopushbutton( QWidget* parent, @@ -134,6 +135,8 @@ void linbopushbutton::lclicked() QString command = processargs.takeFirst(); logConsole->writeStdErr( QString("Executing ") + command + processargs.join(" ") ); + qDebug() << QString("Executing ") + command + processargs.join(" "); + return; progwindow->startTimer(); process->start( command, processargs ); diff --git a/sources/linbogui.cpp b/sources/linbogui.cpp index 503bf31..135a346 100644 --- a/sources/linbogui.cpp +++ b/sources/linbogui.cpp @@ -1,6 +1,24 @@ +/**************************************************************************** + ** 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 . + ****************************************************************************/ + #include "../headers/linbogui.h" -linboGui::linboGui() +LinboGui::LinboGui() { // fill whole screen Qt::WindowFlags flags; @@ -12,22 +30,28 @@ linboGui::linboGui() this->setFixedWidth(QApplication::desktop()->screenGeometry().width()); // black bakground + // linuxmuster background color: #394f5e this->setStyleSheet( "QDialog { background: white }"); + // create an instance of the old GUI (as a backup) linboGUIImpl* legacyGui = new linboGUIImpl(this); legacyGui->setStyleSheet( "QDialog { background: white }"); - //legacyGui->show(); + + // create the backend + this->backend = new LinboBackend(this); + + qDebug() << this->backend->getOperatingSystems()[0]->getName(); // create the main layout // OS Buttons - LinboOsSelectButton* osButton = new LinboOsSelectButton(":/svgIcons/ubuntu.svg", this); + LinboOsSelectButton* osButton = new LinboOsSelectButton(":/svgIcons/ubuntu.svg", nullptr, this); osButton->setFixedHeight(250); osButton->setFixedWidth(250); osButton->setChecked(true); - LinboOsSelectButton* osButton_1 = new LinboOsSelectButton(":/svgIcons/windows.svg", this); + LinboOsSelectButton* osButton_1 = new LinboOsSelectButton(":/svgIcons/windows.svg", nullptr, this); osButton_1->setFixedHeight(250); osButton_1->setFixedWidth(250); @@ -45,6 +69,7 @@ linboGui::linboGui() QModernPushButton* defaultActionButton = new QModernPushButton(":/svgIcons/startAction.svg"); defaultActionButton->setFixedHeight(110); defaultActionButton->setFixedWidth(110); + connect(defaultActionButton, SIGNAL(clicked()), this, SLOT(startOs())); QModernPushButton* secondActionButton = new QModernPushButton(":/svgIcons/syncAction.svg"); secondActionButton->setFixedHeight(50); @@ -60,20 +85,58 @@ linboGui::linboGui() actionButtonLayout->addWidget(thirdActionButton); actionButtonLayout->addItem(new QSpacerItem(10,10, QSizePolicy::Expanding, QSizePolicy::Minimum)); + QLabel* versionLabel = new QLabel(backend->getConfig()->getVersion()); + // main layout - QVBoxLayout* mainLayout = new QVBoxLayout(this); + QWidget* mainLayoutWidget = new QWidget(this); + mainLayoutWidget->setGeometry(this->geometry()); + QVBoxLayout* mainLayout = new QVBoxLayout(mainLayoutWidget); mainLayout->addItem(new QSpacerItem(10,10, QSizePolicy::Minimum, QSizePolicy::Expanding)); mainLayout->addLayout(osButtonRow); - mainLayout->addItem(new QSpacerItem(10,10, QSizePolicy::Minimum, QSizePolicy::Expanding)); + //mainLayout->addItem(new QSpacerItem(10,10, QSizePolicy::Minimum, QSizePolicy::Expanding)); mainLayout->addWidget(defaultActionButton); mainLayout->setAlignment(defaultActionButton, Qt::AlignHCenter); mainLayout->addLayout(actionButtonLayout); mainLayout->addItem(new QSpacerItem(10,10, QSizePolicy::Minimum, QSizePolicy::Expanding)); + mainLayout->addWidget(versionLabel); + + // power and settings Buttons + QWidget* powerActionsLayoutWidget = new QWidget(this); + int height = this->height() * 0.25; + int width = height / 3; + int buttonWidth = width * 0.8; + powerActionsLayoutWidget->setGeometry(QRect(this->width() - width * 1.1, this->height() - height + width * 0.1, width, height)); + + QModernPushButton* settingsActionButton = new QModernPushButton(":/svgIcons/settingsAction.svg"); + connect(settingsActionButton, SIGNAL(clicked()), legacyGui, SLOT(open())); + settingsActionButton->setFixedHeight(buttonWidth); + settingsActionButton->setFixedWidth(buttonWidth); + + QModernPushButton* rebootActionButton = new QModernPushButton(":/svgIcons/rebootAction.svg"); + connect(rebootActionButton, SIGNAL(clicked()), this->backend, SLOT(reboot())); + rebootActionButton->setFixedHeight(buttonWidth); + rebootActionButton->setFixedWidth(buttonWidth); + + QModernPushButton* shutdownActionButton = new QModernPushButton(":/svgIcons/shutdownAction.svg"); + connect(shutdownActionButton, SIGNAL(clicked()), this->backend, SLOT(shutdown())); + shutdownActionButton->setFixedHeight(buttonWidth); + shutdownActionButton->setFixedWidth(buttonWidth); + + QVBoxLayout* powerActionsLayout = new QVBoxLayout(powerActionsLayoutWidget); + powerActionsLayout->setSpacing(0); + powerActionsLayout->addWidget(settingsActionButton); + powerActionsLayout->addWidget(rebootActionButton); + powerActionsLayout->addWidget(shutdownActionButton); } +void LinboGui::startOs() { + qDebug() << "starting: " << this->backend->getOperatingSystems()[1]->getName(); + this->backend->startOs(this->backend->getOperatingSystems()[1]); +} + // prevent closing (eg. by pressing escape key) -void linboGui::done(int r) { +void LinboGui::done(int r) { Q_UNUSED(r) } diff --git a/sources/linboosselectbutton.cpp b/sources/linboosselectbutton.cpp index d0edc72..f2c7d41 100644 --- a/sources/linboosselectbutton.cpp +++ b/sources/linboosselectbutton.cpp @@ -1,5 +1,29 @@ +/**************************************************************************** + ** 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 . + ****************************************************************************/ + #include "linboosselectbutton.h" -LinboOsSelectButton::LinboOsSelectButton(QString icon, QWidget* parent) : QModernPushButton(icon, parent) +LinboOsSelectButton::LinboOsSelectButton(QString icon, LinboOs* os, QWidget* parent) : QModernPushButton(icon, parent) { + this->setCheckable(true); + this->os = os; +} + +LinboOs* LinboOsSelectButton::getOs() { + return this->os; } diff --git a/sources/linbostartpage.cpp b/sources/linbostartpage.cpp index 6a8abf3..e606f9b 100644 --- a/sources/linbostartpage.cpp +++ b/sources/linbostartpage.cpp @@ -1,3 +1,21 @@ +/**************************************************************************** + ** 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 . + ****************************************************************************/ + #include "../headers/linbostartpage.h" linboStartPage::linboStartPage(QWidget *parent) : QWidget(parent) diff --git a/sources/main.cpp b/sources/main.cpp index 7871bcd..573c1e1 100644 --- a/sources/main.cpp +++ b/sources/main.cpp @@ -17,9 +17,8 @@ int main( int argc, char* argv[] ) { - QApplication myapp( argc, argv ); + QApplication linboGuiApp( argc, argv ); -#ifndef TEST_ENV QWSServer* wsServer = QWSServer::instance(); QImage bgimg( "/icons/linbo_wallpaper.png", "PNG" ); @@ -30,31 +29,9 @@ int main( int argc, char* argv[] ) wsServer->setBackground( QBrush( bgimg.scaled( width, height, Qt::IgnoreAspectRatio ) ) ); wsServer->refresh(); } -#endif + LinboGui* linboGui = new LinboGui; + linboGui->show(); - - linboGui* gui = new linboGui; - gui->show(); - // this paints a transparent main widget - //myGUI->setStyleSheet( "QDialog#linboGUI{ background: blue }"); - - - /* myGUI->Console->viewport()->setAutoFillBackground(true); - myGUI->Console->setTextColor( QColor("white") ); - - QPalette palette; */ - // a grey transparent background - // myGUI->Console->setStyleSheet("QTextEdit#Console{ background: transparent }"); - -#ifdef TEST_ENV - QMainWindow window; - window.setCentralWidget(myGUI); - window.setGeometry(myGUI->geometry()); - window.show(); -#endif - - //QTimer::singleShot( 100, myGUI, SLOT(executeAutostart()) ); - - return myapp.exec(); + return linboGuiApp.exec(); } diff --git a/sources/qmodernpushbutton.cpp b/sources/qmodernpushbutton.cpp index 2402631..2b49769 100644 --- a/sources/qmodernpushbutton.cpp +++ b/sources/qmodernpushbutton.cpp @@ -1,18 +1,42 @@ +/**************************************************************************** + ** 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 . + ****************************************************************************/ + #include "../headers/qmodernpushbutton.h" -QModernPushButton::QModernPushButton(QString icon, QWidget* parent) : QPushButton(parent) +QModernPushButton::QModernPushButton(QString icon, QWidget* parent) : QAbstractButton(parent) { - this->setStyleSheet(this->generateStyleSheet()); - this->setCheckable(true); - this->svgWidget = new QSvgWidget(this); this->svgWidget->load(QString(icon)); + this->setMouseTracking(true); - this->overlayNormalWidget = new QSvgWidget(this->svgWidget); + this->overlayHoveredWidget = new QSvgWidget(this->svgWidget); + this->overlayHoveredEffect = new QGraphicsOpacityEffect(this); + this->overlayHoveredEffect->setOpacity(0); + this->overlayHoveredWidget->setGraphicsEffect(this->overlayHoveredEffect); + + this->overlayPressedWidget = new QSvgWidget(this->svgWidget); + this->overlayPressedWidget->load(QString(":svgIcons/overlayPressed.svg")); + this->overlayPressedEffect = new QGraphicsOpacityEffect(this); + this->overlayPressedEffect->setOpacity(0); + this->overlayPressedWidget->setGraphicsEffect(this->overlayPressedEffect); this->overlayCheckedWidget = new QSvgWidget(this->svgWidget); this->overlayCheckedWidget->load(QString(":svgIcons/overlayChecked.svg")); - this->overlayCheckedEffect = new QGraphicsOpacityEffect(this); this->overlayCheckedEffect->setOpacity(0); this->overlayCheckedWidget->setGraphicsEffect(this->overlayCheckedEffect); @@ -34,18 +58,6 @@ void QModernPushButton::handleToggled(bool checked) { animation->start(); } -QString QModernPushButton::generateStyleSheet() { - return "QPushButton {\n" - " background-color: transparent;\n" - "}\n" - "QPushButton:hover {" - "background-color: lightblue;" - "}" - "QPushButton:active {\n" - " outline: none;" - "}"; -} - void QModernPushButton::resizeEvent(QResizeEvent *event) { this->svgWidget->setGeometry(QRect(0, 0, event->size().width(), event->size().height())); @@ -53,10 +65,45 @@ void QModernPushButton::resizeEvent(QResizeEvent *event) { QFile file(":svgIcons/overlayNormal.svg"); file.open(QFile::ReadOnly); QString overlayNormalString = file.readAll(); - overlayNormalString.replace("stroke-width:15px", "stroke-width:" + QString::number(500/event->size().width() * 5) + "px"); - //this->overlayNormalWidget->load(overlayNormalString.toUtf8()); - - this->overlayNormalWidget->setGeometry(QRect(0, 0, event->size().width(), event->size().height())); + //overlayNormalString.replace("stroke-width:15px", "stroke-width:" + QString::number(500/event->size().width() * 5) + "px"); + this->overlayHoveredWidget->load(overlayNormalString.toUtf8()); + this->overlayHoveredWidget->setGeometry(QRect(0, 0, event->size().width(), event->size().height())); this->overlayCheckedWidget->setGeometry(QRect(0, 0, event->size().width(), event->size().height())); } + +void QModernPushButton::paintEvent(QPaintEvent *e) { + Q_UNUSED(e) +} + + +void QModernPushButton::keyPressEvent(QKeyEvent *e) { + // TODO + + return QAbstractButton::keyPressEvent(e); +} + +void QModernPushButton::keyReleaseEvent(QKeyEvent *e) { + // TODO + return QAbstractButton::keyReleaseEvent(e); +} + +void QModernPushButton::enterEvent(QEvent *e) { + this->overlayHoveredEffect->setOpacity(1); + return QAbstractButton::enterEvent(e); +} + +void QModernPushButton::leaveEvent(QEvent *e) { + this->overlayHoveredEffect->setOpacity(0); + return QAbstractButton::leaveEvent(e); +} + +void QModernPushButton::mousePressEvent(QMouseEvent *e) { + this->overlayPressedEffect->setOpacity(1); + return QAbstractButton::mousePressEvent(e); +} + +void QModernPushButton::mouseReleaseEvent(QMouseEvent *e) { + this->overlayPressedEffect->setOpacity(0); + return QAbstractButton::mouseReleaseEvent(e); +}