Skip to content

Commit

Permalink
Allow to change the visbility(enable or disable)
Browse files Browse the repository at this point in the history
  • Loading branch information
Inokinoki committed May 2, 2022
1 parent d675303 commit 01f18d0
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 0 deletions.
8 changes: 8 additions & 0 deletions qefientry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ bool QEFIEntry::isActive() const
return m_isActive;
}

void QEFIEntry::setActive(bool active)
{
if (m_loadOption != nullptr) {
m_loadOption->setIsVisible(active);
}
m_isActive = active;
}

QEFILoadOption *QEFIEntry::loadOption() const
{
return m_loadOption;
Expand Down
2 changes: 2 additions & 0 deletions qefientry.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class QEFIEntry
QString devicePath() const;
bool isActive() const;
QEFILoadOption *loadOption() const;

void setActive(bool active);
};

#endif // QEFIENTRY_H
35 changes: 35 additions & 0 deletions qefientrystaticlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,38 @@ void QEFIEntryStaticList::setBootOrder(const QList<quint16> &newOrder)
QStringLiteral("BootOrder"), orderBuffer);
// TODO: Sync the order in this class
}

bool QEFIEntryStaticList::setBootVisibility(
const quint16 bootID, bool visible)
{
int index = m_order.indexOf(bootID);
if (index == -1) return false;

auto bootDataIter = m_cachedItem.find(bootID);
if (bootDataIter != m_cachedItem.end()) {
QByteArray &bootData = *bootDataIter;
if (bootData.size() < 4) return false;

// Set the data
quint32 attribute = (
(bootData[3] << 24) | (bootData[2] << 16) |
(bootData[1] << 8) | (bootData[0])
);
if (visible ^ (attribute & QEFI_LOAD_OPTION_ACTIVE)) {
// Visibility is changed
if (visible) attribute |= 0x00000001;
else attribute &= 0xFFFFFFFE;

QString name = QString::asprintf("Boot%04X", bootID);
bootData[3] = (attribute >> 24);
bootData[2] = ((attribute >> 16) & 0xFF);
bootData[1] = ((attribute >> 8) & 0xFF);
bootData[0] = (attribute & 0xFF);
qefi_set_variable(QUuid("8be4df61-93ca-11d2-aa0d-00e098032b8c"),
name, bootData);

return true;
}
}
return false;
}
1 change: 1 addition & 0 deletions qefientrystaticlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class QEFIEntryStaticList

void setBootNext(const quint16 &next);
void setBootOrder(const QList<quint16> &newOrder);
bool setBootVisibility(const quint16 bootID, bool visible);

virtual ~QEFIEntryStaticList();
};
Expand Down
41 changes: 41 additions & 0 deletions qefientryview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,15 @@ 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_visibilityButton = new QPushButton(QStringLiteral("Enable"), this);
m_visibilityButton->setDisabled(true);
m_rebootTargetButton = new QPushButton(QStringLiteral("Set reboot"), this);
m_rebootTargetButton->setDisabled(true);
m_detailButton = new QPushButton(QStringLiteral("Details"), this);
m_buttonLayout->addWidget(m_moveUpEntryButton);
m_buttonLayout->addWidget(m_moveDownEntryButton);
m_buttonLayout->addWidget(m_setCurrentButton);
m_buttonLayout->addWidget(m_visibilityButton);
m_buttonLayout->addWidget(m_rebootTargetButton);
m_buttonLayout->addWidget(m_detailButton);
QObject::connect(m_moveUpEntryButton, &QPushButton::clicked,
Expand All @@ -63,6 +66,8 @@ QEFIEntryView::QEFIEntryView(QWidget *parent)
this, &QEFIEntryView::moveDownClicked);
QObject::connect(m_setCurrentButton, &QPushButton::clicked,
this, &QEFIEntryView::setCurrentClicked);
QObject::connect(m_visibilityButton, &QPushButton::clicked,
this, &QEFIEntryView::visibilityClicked);
QObject::connect(m_rebootTargetButton, &QPushButton::clicked,
this, &QEFIEntryView::rebootClicked);
QObject::connect(m_detailButton, &QPushButton::clicked,
Expand Down Expand Up @@ -108,6 +113,7 @@ QEFIEntryView::~QEFIEntryView()
if (m_saveButton != nullptr) delete m_saveButton;
if (m_resetButton != nullptr) delete m_resetButton;
if (m_rebootTargetButton != nullptr) delete m_rebootTargetButton;
if (m_visibilityButton != nullptr) delete m_visibilityButton;
if (m_bootTimeoutLabel != nullptr) delete m_bootTimeoutLabel;
if (m_detailButton != nullptr) delete m_detailButton;
}
Expand Down Expand Up @@ -192,6 +198,13 @@ void QEFIEntryView::updateButtonState()
m_detailButton->setDisabled(false);
m_saveButton->setDisabled(false);
m_resetButton->setDisabled(false);

m_visibilityButton->setDisabled(false);
// Set the visibility button
QEFIEntry &entry = m_entryItems[m_order[m_selectedItemIndex]];
bool visibility = entry.loadOption()->isVisible();
m_visibilityButton->setText(!visibility ? "Enable" : "Disable");

if (0 == m_selectedItemIndex) {
m_moveUpEntryButton->setDisabled(true);
}
Expand All @@ -206,6 +219,7 @@ void QEFIEntryView::updateButtonState()
m_detailButton->setDisabled(true);
m_saveButton->setDisabled(false);
m_resetButton->setDisabled(false);
m_visibilityButton->setDisabled(true);
}
}

Expand Down Expand Up @@ -247,6 +261,33 @@ void QEFIEntryView::rebootClicked(bool checked)
}
}

void QEFIEntryView::visibilityClicked(bool checked)
{
Q_UNUSED(checked);
if (m_selectedItemIndex >= 0 || m_selectedItemIndex < m_order.size()) {
qDebug() << "[EFIRebootView] Set " << m_order[m_selectedItemIndex] << " "
<< m_entryItems[m_order[m_selectedItemIndex]].name() << " visibility";
// Set Attribute
QEFIEntry &entry = m_entryItems[m_order[m_selectedItemIndex]];
bool visibility = entry.loadOption()->isVisible();
if (QEFIEntryStaticList::instance()->setBootVisibility(
m_order[m_selectedItemIndex], !visibility)) {
// Already set visibility successful

// Set the load option visibility
QEFIEntryStaticList::instance()->entries()[m_order[m_selectedItemIndex]].
setActive(!visibility);

// Set the activation state
QListWidgetItem *currentItem = m_entries->item(m_selectedItemIndex);
if (currentItem != nullptr) {
currentItem->setForeground(visibility ? Qt::gray : Qt::black);
m_visibilityButton->setText(visibility ? "Enable" : "Disable");
}
}
}
}

class DetailDialog : public QDialog
{
QEFIEntryDetailView m_view;
Expand Down
2 changes: 2 additions & 0 deletions qefientryview.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class QEFIEntryView: public QWidget
QPushButton *m_setCurrentButton;
QPushButton *m_saveButton;
QPushButton *m_resetButton;
QPushButton *m_visibilityButton;
QPushButton *m_rebootTargetButton;
QPushButton *m_detailButton;

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

Expand Down

0 comments on commit 01f18d0

Please sign in to comment.