Skip to content

Commit

Permalink
fix up the power management dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
Arisotura committed Mar 7, 2022
1 parent 9394dde commit 532b1c9
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
30 changes: 29 additions & 1 deletion src/frontend/qt_sdl/PowerManagement/PowerManagementDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,25 @@ PowerManagementDialog* PowerManagementDialog::currentDlg = nullptr;

PowerManagementDialog::PowerManagementDialog(QWidget* parent) : QDialog(parent), ui(new Ui::PowerManagementDialog)
{
inited = false;

ui->setupUi(this);
setAttribute(Qt::WA_DeleteOnClose);

if (NDS::ConsoleType)
if (NDS::ConsoleType == 1)
{
ui->grpDSBattery->setEnabled(false);

oldDSiBatteryCharging = DSi_BPTWL::GetBatteryCharging();
oldDSiBatteryLevel = DSi_BPTWL::GetBatteryLevel();
}
else
{
ui->grpDSiBattery->setEnabled(false);

oldDSBatteryLevel = SPI_Powerman::GetBatteryLevelOkay();
}

updateDSBatteryLevelControls();

ui->cbDSiBatteryCharging->setChecked(DSi_BPTWL::GetBatteryCharging());
Expand All @@ -52,6 +63,8 @@ PowerManagementDialog::PowerManagementDialog(QWidget* parent) : QDialog(parent),
case DSi_BPTWL::batteryLevel_Full: dsiBatterySliderPos = 4; break;
}
ui->sliderDSiBatteryLevel->setValue(dsiBatterySliderPos);

inited = true;
}

PowerManagementDialog::~PowerManagementDialog()
Expand All @@ -61,6 +74,19 @@ PowerManagementDialog::~PowerManagementDialog()

void PowerManagementDialog::done(int r)
{
if (r != QDialog::Accepted)
{
if (NDS::ConsoleType == 1)
{
DSi_BPTWL::SetBatteryCharging(oldDSiBatteryCharging);
DSi_BPTWL::SetBatteryLevel(oldDSiBatteryLevel);
}
else
{
SPI_Powerman::SetBatteryLevelOkay(oldDSBatteryLevel);
}
}

QDialog::done(r);

closeDlg();
Expand Down Expand Up @@ -91,6 +117,8 @@ void PowerManagementDialog::on_cbDSiBatteryCharging_toggled()

void PowerManagementDialog::on_sliderDSiBatteryLevel_valueChanged(int value)
{
if (!inited) return;

u8 newBatteryLevel;
switch (value)
{
Expand Down
7 changes: 7 additions & 0 deletions src/frontend/qt_sdl/PowerManagement/PowerManagementDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#include <QDialog>
#include <QAbstractButton>

#include "types.h"

namespace Ui { class PowerManagementDialog; }
class PowerManagementDialog;

Expand Down Expand Up @@ -63,6 +65,11 @@ private slots:
private:
Ui::PowerManagementDialog* ui;

bool inited;
bool oldDSBatteryLevel;
bool oldDSiBatteryCharging;
u8 oldDSiBatteryLevel;

void updateDSBatteryLevelControls();
};

Expand Down
3 changes: 3 additions & 0 deletions src/frontend/qt_sdl/PowerManagement/PowerManagementDialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
<string>Power management - melonDS</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<property name="sizeConstraint">
<enum>QLayout::SetFixedSize</enum>
</property>
<item row="0" column="0">
<widget class="QGroupBox" name="grpDSBattery">
<property name="title">
Expand Down

0 comments on commit 532b1c9

Please sign in to comment.