Skip to content

Commit fecbf47

Browse files
authored
Merge pull request #148 from kipr/backupPatch
Backup patch
2 parents 88e5d9d + 5cc4cc2 commit fecbf47

File tree

9 files changed

+406
-94
lines changed

9 files changed

+406
-94
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ option(DEBUG "Enable debug mode" OFF)
55
option(RELEASE "Enable release mode" OFF)
66
option(docker_cross "Cross compile option for docker container" OFF)
77
set(KIPR_VERSION_MAJOR 1)
8-
set(KIPR_VERSION_MINOR 2)
8+
set(KIPR_VERSION_MINOR 3)
99
set(KIPR_VERSION_PATCH 0)
1010
cmake_minimum_required(VERSION 2.8.11)
1111

include/botui/AboutWidget.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
#include "StandardWidget.h" // Include here if needed for inheritance
55
#include <QProcess>
6-
6+
#include <QMessageBox>
77
namespace Ui
88
{
99
class AboutWidget;
@@ -29,9 +29,13 @@ public slots:
2929
void developerList();
3030
void eventModeBackground(int checked);
3131

32+
private slots:
33+
void rebootBox();
34+
3235
private:
3336
Ui::AboutWidget *ui;
3437
QProcess proc;
38+
QMessageBox *msgBox;
3539
};
3640

3741
#endif

include/botui/BackupWidget.h

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
#include "Device.h"
55
#include "StandardWidget.h"
6+
#include <QProcess>
7+
#include <QDir>
68

79
namespace Ui
810
{
@@ -11,19 +13,30 @@ namespace Ui
1113

1214
class BackupWidget : public StandardWidget
1315
{
14-
Q_OBJECT
16+
Q_OBJECT
1517
public:
1618
BackupWidget(Device *device, QWidget *widget = 0);
1719
~BackupWidget();
1820

1921
public slots:
2022
void backupoption();
21-
//void cleardrive();
23+
// void cleardrive();
2224
void restore();
23-
25+
26+
private slots:
27+
void updateFinished(int exitCode, QProcess::ExitStatus exitStatus);
28+
void restoreFinished(int, QProcess::ExitStatus exitStatus);
29+
2430
private:
31+
bool isAlreadyMounted(const QString &device, const QString &mountPoint);
32+
bool mountUsb(const QString device, const QDir dir);
33+
bool unmountUsb(const QString device);
34+
static const QDir mountDir;
2535
Ui::BackupWidget *ui;
36+
QProcess *backup_process;
37+
QProcess *restore_process;
38+
void handleStandardOutput();
39+
void handleStandardError();
2640
};
2741

28-
2942
#endif

src/AboutWidget.cpp

Lines changed: 83 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@
77
#include "RootController.h"
88
#include "DeveloperListWidget.h"
99
#include <QProcess>
10+
#include <QMovie>
1011
#include <QDebug>
1112
#include <QRegularExpression>
12-
13+
#include <QTimer>
14+
#include <unistd.h>
1315
AboutWidget::AboutWidget(Device *device, QWidget *parent)
1416
: StandardWidget(device, parent),
15-
ui(new Ui::AboutWidget)
17+
ui(new Ui::AboutWidget), msgBox(nullptr)
1618
{
1719
ui->setupUi(this);
1820
// Setup the UI
@@ -94,13 +96,79 @@ AboutWidget::AboutWidget(Device *device, QWidget *parent)
9496

9597
connect(ui->developerList, SIGNAL(clicked()), SLOT(developerList()));
9698
connect(ui->toggleSwitch, SIGNAL(stateChanged(int)), this, SLOT(eventModeBackground(int)));
99+
connect(ui->toggleSwitch, SIGNAL(stateChanged(int)), this, SLOT(rebootBox()));
97100
}
98101

99102
AboutWidget::~AboutWidget()
100103
{
104+
if (msgBox)
105+
{
106+
msgBox->deleteLater(); // or delete msgBox; if you want to directly delete
107+
}
101108
delete ui;
102109
}
103110

111+
void AboutWidget::rebootBox()
112+
{
113+
qDebug() << "In rebootBox()";
114+
115+
if (!msgBox)
116+
{
117+
// Create the QMessageBox
118+
msgBox = new QMessageBox(this);
119+
msgBox->setWindowTitle("Switch Event Mode");
120+
msgBox->setMaximumSize(500, 480); // Limit the size of the QMessageBox
121+
msgBox->setStandardButtons(QMessageBox::NoButton);
122+
123+
// Create QLabel for the GIF
124+
QLabel *gifLabel = new QLabel();
125+
gifLabel->setAlignment(Qt::AlignCenter); // Center the GIF label
126+
127+
// Create QLabel for the message text
128+
QLabel *messageLabel = new QLabel("Switching Event Mode Now...");
129+
messageLabel->setAlignment(Qt::AlignCenter); // Center the message label
130+
131+
// Create a container widget and a new vertical layout
132+
QWidget *container = new QWidget();
133+
QVBoxLayout *vLayout = new QVBoxLayout(container);
134+
135+
// Add the GIF label and message label to the vertical layout
136+
vLayout->addWidget(gifLabel);
137+
vLayout->addWidget(messageLabel);
138+
139+
// Adjust the vertical layout spacing and margins
140+
vLayout->setSpacing(10);
141+
vLayout->setContentsMargins(10, 10, 10, 10);
142+
143+
// Set the layout of the container
144+
container->setLayout(vLayout);
145+
146+
// Access the internal layout of the QMessageBox
147+
QGridLayout *msgBoxLayout = qobject_cast<QGridLayout *>(msgBox->layout());
148+
if (msgBoxLayout)
149+
{
150+
msgBoxLayout->addWidget(container, 0, 0, 1, msgBoxLayout->columnCount());
151+
}
152+
else
153+
{
154+
qDebug() << "msgBoxLayout is nullptr!"; // Debugging message if layout is nullptr
155+
}
156+
157+
// Setup and start the GIF movie
158+
QMovie *movie = new QMovie("://qml/botguy_noMargin.gif");
159+
movie->setScaledSize(QSize(200, 240));
160+
gifLabel->setMovie(movie);
161+
movie->start();
162+
163+
// Show the QMessageBox non-blocking
164+
msgBox->setText(""); // Hide the default text to avoid duplication
165+
}
166+
msgBox->show();
167+
168+
// Debug information
169+
qDebug() << "Message box displayed, starting event mode change sequence...";
170+
}
171+
104172
QString AboutWidget::getRaspberryPiType()
105173
{
106174
QProcess process;
@@ -115,12 +183,11 @@ QString AboutWidget::getRaspberryPiType()
115183
{
116184
qDebug() << "Successfully got Raspberry Pi Type:" << output.trimmed(); // Trim output to remove whitespace
117185

118-
119-
if(output.trimmed() == "a020d3" || output.trimmed() == "a020d4")
186+
if (output.trimmed() == "a020d3" || output.trimmed() == "a020d4")
120187
{
121188
piType = "3B+";
122189
}
123-
else if(output.trimmed() == "a02082" || output.trimmed() == "a22082" || output.trimmed() == "a32082" || output.trimmed() == "a52082" || output.trimmed() == "a22083")
190+
else if (output.trimmed() == "a02082" || output.trimmed() == "a22082" || output.trimmed() == "a32082" || output.trimmed() == "a52082" || output.trimmed() == "a22083")
124191
{
125192
piType = "3B";
126193
}
@@ -192,22 +259,30 @@ void AboutWidget::eventModeBackground(int checked)
192259
qDebug() << "Checked: " << checked;
193260

194261
ui->toggleSwitch->setEnabled(false);
195-
262+
// rebootBox();
196263
if (checked == 2) // Enable Event Mode
197264
{
198265

199266
setEventModeState("true");
200267
emit eventModeEnabled();
201268
NetworkManager::ref().deactivateAP();
202-
ui->toggleSwitch->setEnabled(true);
203269
}
204270
else // Disable Event Mode
205271
{
206272
setEventModeState("false");
207273
emit eventModeDisabled();
208274
NetworkManager::ref().enableAP();
209-
ui->toggleSwitch->setEnabled(true);
210275
}
276+
277+
QTimer::singleShot(3000, this, [this]()
278+
{
279+
if (msgBox)
280+
{
281+
msgBox->hide();
282+
delete msgBox;
283+
msgBox = nullptr;
284+
}
285+
ui->toggleSwitch->setEnabled(true); });
211286
}
212287

213288
void AboutWidget::developerList()

0 commit comments

Comments
 (0)