Skip to content

Commit

Permalink
Move reboot func to view and remove reboot view
Browse files Browse the repository at this point in the history
  • Loading branch information
Inokinoki committed Apr 9, 2022
1 parent 4495842 commit 9ac8572
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 166 deletions.
2 changes: 0 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ set(PROJECT_SOURCES
mainwindow.h
qefientryview.cpp
qefientryview.h
qefientryrebootview.cpp
qefientryrebootview.h
qefientry.cpp
qefientry.h
qefientrystaticlist.cpp
Expand Down
18 changes: 3 additions & 15 deletions mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,14 @@ MainWindow::MainWindow(QWidget *parent)
this->setWindowTitle(QStringLiteral("EFI Entry Manager"));
this->resize(800, 600);

// Create tabs
m_tab = new QTabWidget(this);

// Create a class for each page amd keep a ref to update
m_entryView = new QEFIEntryView(m_tab);
m_rebootView = new QEFIEntryRebootView(m_tab);

m_tab->insertTab(0, m_entryView, QStringLiteral("Boot Order"));
m_tab->insertTab(1, m_rebootView, QStringLiteral("Reboot with"));
m_entryView = new QEFIEntryView(this);

this->setCentralWidget(m_tab);
this->setCentralWidget(m_entryView);
}

MainWindow::~MainWindow()
{
if (m_tab != nullptr) delete m_tab;
m_tab = nullptr;

// Ownership has been passed to tab
m_entryView = nullptr;
m_rebootView = nullptr;
if (m_entryView != nullptr) delete m_entryView;
}

4 changes: 0 additions & 4 deletions mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,14 @@

#include <QMainWindow>

#include <QTabWidget>
#include <QLabel>

#include "qefientryrebootview.h"
#include "qefientryview.h"

class MainWindow : public QMainWindow
{
Q_OBJECT

QTabWidget *m_tab;
QEFIEntryRebootView *m_rebootView;
QEFIEntryView *m_entryView;
public:
MainWindow(QWidget *parent = nullptr);
Expand Down
102 changes: 0 additions & 102 deletions qefientryrebootview.cpp

This file was deleted.

43 changes: 0 additions & 43 deletions qefientryrebootview.h

This file was deleted.

44 changes: 44 additions & 0 deletions qefientryview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include "qefientrystaticlist.h"

#include <QDebug>
#include <QMessageBox>
#include <QProcess>

QEFIEntryView::QEFIEntryView(QWidget *parent)
: QWidget(parent)
Expand Down Expand Up @@ -36,20 +38,28 @@ QEFIEntryView::QEFIEntryView(QWidget *parent)
m_moveUpEntryButton = new QPushButton(QStringLiteral("Move up"), this);
m_moveDownEntryButton = new QPushButton(QStringLiteral("Move down"), this);
m_setCurrentButton = new QPushButton(QStringLiteral("Make default"), this);
m_rebootTargetButton = new QPushButton(QStringLiteral("Set reboot"), this);
m_rebootTargetButton->setDisabled(true);
m_buttonLayout->addWidget(m_moveUpEntryButton);
m_buttonLayout->addWidget(m_moveDownEntryButton);
m_buttonLayout->addWidget(m_setCurrentButton);
m_buttonLayout->addWidget(m_rebootTargetButton);
QObject::connect(m_moveUpEntryButton, &QPushButton::clicked,
this, &QEFIEntryView::moveUpClicked);
QObject::connect(m_moveDownEntryButton, &QPushButton::clicked,
this, &QEFIEntryView::moveDownClicked);
QObject::connect(m_setCurrentButton, &QPushButton::clicked,
this, &QEFIEntryView::setCurrentClicked);
QObject::connect(m_rebootTargetButton, &QPushButton::clicked,
this, &QEFIEntryView::rebootClicked);

m_buttonLayout->addStretch(1);

m_bootTimeoutLabel = new QLabel(QString::asprintf("Timeout: %d second(s)",
QEFIEntryStaticList::instance()->timeout()), this);
m_saveButton = new QPushButton(QStringLiteral("Save"), this);
m_resetButton = new QPushButton(QStringLiteral("Reset"), this);
m_buttonLayout->addWidget(m_bootTimeoutLabel);
m_buttonLayout->addWidget(m_saveButton);
m_buttonLayout->addWidget(m_resetButton);
QObject::connect(m_saveButton, &QPushButton::clicked,
Expand Down Expand Up @@ -82,6 +92,8 @@ QEFIEntryView::~QEFIEntryView()
if (m_setCurrentButton != nullptr) delete m_setCurrentButton;
if (m_saveButton != nullptr) delete m_saveButton;
if (m_resetButton != nullptr) delete m_resetButton;
if (m_rebootTargetButton != nullptr) delete m_rebootTargetButton;
if (m_bootTimeoutLabel != nullptr) delete m_bootTimeoutLabel;
}

void QEFIEntryView::entryChanged(int currentRow)
Expand Down Expand Up @@ -160,6 +172,7 @@ void QEFIEntryView::updateButtonState()
m_moveUpEntryButton->setDisabled(false);
m_moveDownEntryButton->setDisabled(false);
m_setCurrentButton->setDisabled(false);
m_rebootTargetButton->setDisabled(false);
m_saveButton->setDisabled(false);
m_resetButton->setDisabled(false);
if (0 == m_selectedItemIndex) {
Expand All @@ -172,6 +185,7 @@ void QEFIEntryView::updateButtonState()
m_moveUpEntryButton->setDisabled(true);
m_moveDownEntryButton->setDisabled(true);
m_setCurrentButton->setDisabled(true);
m_rebootTargetButton->setDisabled(true);
m_saveButton->setDisabled(false);
m_resetButton->setDisabled(false);
}
Expand All @@ -184,3 +198,33 @@ void QEFIEntryView::resetFromStaticListClicked(bool checked)
m_selectedItemIndex = -1;
resetClicked(checked);
}

void QEFIEntryView::rebootClicked(bool checked)
{
Q_UNUSED(checked);
if (m_rebootItemIndex >= 0 || m_rebootItemIndex < m_order.size()) {
qDebug() << "[EFIRebootView] Set " << m_order[m_rebootItemIndex] << " "
<< m_entryItems[m_order[m_rebootItemIndex]].name() << " as reboot target";
// Set BootNext
QEFIEntryStaticList::instance()->setBootNext(m_order[m_rebootItemIndex]);
int ret = QMessageBox::warning(this, QStringLiteral("Reboot to ") +
m_entryItems[m_order[m_rebootItemIndex]].name(),
QStringLiteral("Do you want to reboot now?"),
QMessageBox::Yes | QMessageBox::No,
QMessageBox::No);
if (ret == QMessageBox::Yes) {
// Reboot now
qDebug() << "[EFIRebootView] Reboot now";
QProcess process;
#ifdef Q_OS_WIN
process.startDetached("shutdown", {"/r", "/t", "0"});
#else
process.startDetached("reboot", {});
#endif
} else {
// Do nothing
qDebug() << "[EFIRebootView] Reboot later";
}
return;
}
}
5 changes: 5 additions & 0 deletions qefientryview.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,15 @@ class QEFIEntryView: public QWidget
QPushButton *m_setCurrentButton;
QPushButton *m_saveButton;
QPushButton *m_resetButton;
QPushButton *m_rebootTargetButton;

QLabel *m_bootTimeoutLabel;

QMap<quint16, QEFIEntry> m_entryItems;
QList<quint16> m_order;

int m_selectedItemIndex;
int m_rebootItemIndex;

void updateButtonState();
public:
Expand All @@ -45,6 +49,7 @@ public slots:
void resetFromStaticListClicked(bool checked);
void saveClicked(bool checked);
void setCurrentClicked(bool checked);
void rebootClicked(bool checked);

void moveUpClicked(bool checked);
void moveDownClicked(bool checked);
Expand Down

0 comments on commit 9ac8572

Please sign in to comment.