Skip to content

Commit

Permalink
Edited AboutWidget constructor state for Event Mode
Browse files Browse the repository at this point in the history
  • Loading branch information
erinharrington-12 committed Oct 1, 2024
1 parent db07287 commit 1787543
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion include/botui/AboutWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class AboutWidget : public StandardWidget
AboutWidget(Device *device, QWidget *parent = nullptr);
~AboutWidget();

void getEventModeState();
bool getEventModeState();
void setEventModeState(QString newState);

signals:
Expand Down
21 changes: 16 additions & 5 deletions src/AboutWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ AboutWidget::AboutWidget(Device *device, QWidget *parent)
setupConnections(this);

//Event Mode persistent state check
getEventModeState();
bool eventModeState = getEventModeState();

if(eventModeState){
eventModeBackground(2);
}

const bool on = NetworkManager::ref().isOn();
// Version Number
Expand All @@ -37,7 +41,7 @@ AboutWidget::AboutWidget(Device *device, QWidget *parent)

// Check if eth0 is active (/sys/class/net/eth0/carrier will output 1 if eth0 is active and 0 if it is not)
QStringList arguments;
arguments << "/sys/class/net/eth0/carrier";
arguments << "/sys/class/net/eno1/carrier";

QProcess *myProcess = new QProcess(parent);
myProcess->start("cat", arguments);
Expand Down Expand Up @@ -92,10 +96,10 @@ AboutWidget::~AboutWidget()
delete ui;
}

void AboutWidget::getEventModeState()
bool AboutWidget::getEventModeState()
{
QProcess eventModeProcess;
QString command = "grep '^EVENT_MODE' /home/kipr/wifiConnectionMode.txt | awk '{print $2}'";
QString command = "grep '^EVENT_MODE' /home/erin/Documents/wifiConnectionMode.txt | awk '{print $2}'";

eventModeProcess.start("bash", QStringList() << "-c" << command);
eventModeProcess.waitForFinished();
Expand All @@ -108,10 +112,12 @@ void AboutWidget::getEventModeState()
if (output == "true")
{
ui->toggleSwitch->setChecked(true);
return true;
}
else
{
ui->toggleSwitch->setChecked(false);
return false;
}
}
else
Expand All @@ -123,7 +129,7 @@ void AboutWidget::getEventModeState()
void AboutWidget::setEventModeState(QString newState)
{
QProcess process;
QString command = QString("sed -i 's/^EVENT_MODE.*/EVENT_MODE %1/' /home/kipr/wifiConnectionMode.txt").arg(newState);
QString command = QString("sed -i 's/^EVENT_MODE.*/EVENT_MODE %1/' /home/erin/Documents/wifiConnectionMode.txt").arg(newState);

process.start("bash", QStringList() << "-c" << command);
process.waitForFinished();
Expand All @@ -143,18 +149,23 @@ void AboutWidget::eventModeBackground(int checked)

qDebug() << "Event Mode Background toggled";
qDebug() << "Checked: " << checked;

ui->toggleSwitch->setEnabled(false);

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);

}
}
Expand Down

0 comments on commit 1787543

Please sign in to comment.