Skip to content

Commit

Permalink
Merge pull request #148 from kipr/backupPatch
Browse files Browse the repository at this point in the history
Backup patch
  • Loading branch information
tcorbly authored Dec 18, 2024
2 parents 88e5d9d + 5cc4cc2 commit fecbf47
Show file tree
Hide file tree
Showing 9 changed files with 406 additions and 94 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ option(DEBUG "Enable debug mode" OFF)
option(RELEASE "Enable release mode" OFF)
option(docker_cross "Cross compile option for docker container" OFF)
set(KIPR_VERSION_MAJOR 1)
set(KIPR_VERSION_MINOR 2)
set(KIPR_VERSION_MINOR 3)
set(KIPR_VERSION_PATCH 0)
cmake_minimum_required(VERSION 2.8.11)

Expand Down
6 changes: 5 additions & 1 deletion include/botui/AboutWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include "StandardWidget.h" // Include here if needed for inheritance
#include <QProcess>

#include <QMessageBox>
namespace Ui
{
class AboutWidget;
Expand All @@ -29,9 +29,13 @@ public slots:
void developerList();
void eventModeBackground(int checked);

private slots:
void rebootBox();

private:
Ui::AboutWidget *ui;
QProcess proc;
QMessageBox *msgBox;
};

#endif
21 changes: 17 additions & 4 deletions include/botui/BackupWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#include "Device.h"
#include "StandardWidget.h"
#include <QProcess>
#include <QDir>

namespace Ui
{
Expand All @@ -11,19 +13,30 @@ namespace Ui

class BackupWidget : public StandardWidget
{
Q_OBJECT
Q_OBJECT
public:
BackupWidget(Device *device, QWidget *widget = 0);
~BackupWidget();

public slots:
void backupoption();
//void cleardrive();
// void cleardrive();
void restore();


private slots:
void updateFinished(int exitCode, QProcess::ExitStatus exitStatus);
void restoreFinished(int, QProcess::ExitStatus exitStatus);

private:
bool isAlreadyMounted(const QString &device, const QString &mountPoint);
bool mountUsb(const QString device, const QDir dir);
bool unmountUsb(const QString device);
static const QDir mountDir;
Ui::BackupWidget *ui;
QProcess *backup_process;
QProcess *restore_process;
void handleStandardOutput();
void handleStandardError();
};


#endif
91 changes: 83 additions & 8 deletions src/AboutWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
#include "RootController.h"
#include "DeveloperListWidget.h"
#include <QProcess>
#include <QMovie>
#include <QDebug>
#include <QRegularExpression>

#include <QTimer>
#include <unistd.h>
AboutWidget::AboutWidget(Device *device, QWidget *parent)
: StandardWidget(device, parent),
ui(new Ui::AboutWidget)
ui(new Ui::AboutWidget), msgBox(nullptr)
{
ui->setupUi(this);
// Setup the UI
Expand Down Expand Up @@ -94,13 +96,79 @@ AboutWidget::AboutWidget(Device *device, QWidget *parent)

connect(ui->developerList, SIGNAL(clicked()), SLOT(developerList()));
connect(ui->toggleSwitch, SIGNAL(stateChanged(int)), this, SLOT(eventModeBackground(int)));
connect(ui->toggleSwitch, SIGNAL(stateChanged(int)), this, SLOT(rebootBox()));
}

AboutWidget::~AboutWidget()
{
if (msgBox)
{
msgBox->deleteLater(); // or delete msgBox; if you want to directly delete
}
delete ui;
}

void AboutWidget::rebootBox()
{
qDebug() << "In rebootBox()";

if (!msgBox)
{
// Create the QMessageBox
msgBox = new QMessageBox(this);
msgBox->setWindowTitle("Switch Event Mode");
msgBox->setMaximumSize(500, 480); // Limit the size of the QMessageBox
msgBox->setStandardButtons(QMessageBox::NoButton);

// Create QLabel for the GIF
QLabel *gifLabel = new QLabel();
gifLabel->setAlignment(Qt::AlignCenter); // Center the GIF label

// Create QLabel for the message text
QLabel *messageLabel = new QLabel("Switching Event Mode Now...");
messageLabel->setAlignment(Qt::AlignCenter); // Center the message label

// Create a container widget and a new vertical layout
QWidget *container = new QWidget();
QVBoxLayout *vLayout = new QVBoxLayout(container);

// Add the GIF label and message label to the vertical layout
vLayout->addWidget(gifLabel);
vLayout->addWidget(messageLabel);

// Adjust the vertical layout spacing and margins
vLayout->setSpacing(10);
vLayout->setContentsMargins(10, 10, 10, 10);

// Set the layout of the container
container->setLayout(vLayout);

// Access the internal layout of the QMessageBox
QGridLayout *msgBoxLayout = qobject_cast<QGridLayout *>(msgBox->layout());
if (msgBoxLayout)
{
msgBoxLayout->addWidget(container, 0, 0, 1, msgBoxLayout->columnCount());
}
else
{
qDebug() << "msgBoxLayout is nullptr!"; // Debugging message if layout is nullptr
}

// Setup and start the GIF movie
QMovie *movie = new QMovie("://qml/botguy_noMargin.gif");
movie->setScaledSize(QSize(200, 240));
gifLabel->setMovie(movie);
movie->start();

// Show the QMessageBox non-blocking
msgBox->setText(""); // Hide the default text to avoid duplication
}
msgBox->show();

// Debug information
qDebug() << "Message box displayed, starting event mode change sequence...";
}

QString AboutWidget::getRaspberryPiType()
{
QProcess process;
Expand All @@ -115,12 +183,11 @@ QString AboutWidget::getRaspberryPiType()
{
qDebug() << "Successfully got Raspberry Pi Type:" << output.trimmed(); // Trim output to remove whitespace


if(output.trimmed() == "a020d3" || output.trimmed() == "a020d4")
if (output.trimmed() == "a020d3" || output.trimmed() == "a020d4")
{
piType = "3B+";
}
else if(output.trimmed() == "a02082" || output.trimmed() == "a22082" || output.trimmed() == "a32082" || output.trimmed() == "a52082" || output.trimmed() == "a22083")
else if (output.trimmed() == "a02082" || output.trimmed() == "a22082" || output.trimmed() == "a32082" || output.trimmed() == "a52082" || output.trimmed() == "a22083")
{
piType = "3B";
}
Expand Down Expand Up @@ -192,22 +259,30 @@ void AboutWidget::eventModeBackground(int checked)
qDebug() << "Checked: " << checked;

ui->toggleSwitch->setEnabled(false);

// rebootBox();
if (checked == 2) // Enable Event Mode
{

setEventModeState("true");
emit eventModeEnabled();
NetworkManager::ref().deactivateAP();
ui->toggleSwitch->setEnabled(true);
}
else // Disable Event Mode
{
setEventModeState("false");
emit eventModeDisabled();
NetworkManager::ref().enableAP();
ui->toggleSwitch->setEnabled(true);
}

QTimer::singleShot(3000, this, [this]()
{
if (msgBox)
{
msgBox->hide();
delete msgBox;
msgBox = nullptr;
}
ui->toggleSwitch->setEnabled(true); });
}

void AboutWidget::developerList()
Expand Down
Loading

0 comments on commit fecbf47

Please sign in to comment.