Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ set(PROJECT_SOURCES
src/mainwindow.ui
src/mainwindow.cpp src/mainwindow.h
src/operate.cpp src/operate.h
src/powermonitor.cpp src/powermonitor.h
src/helper.cpp src/helper.h
src/msi-ec_helper.cpp src/msi-ec_helper.h
src/settings.cpp src/settings.h
Expand Down
26 changes: 26 additions & 0 deletions src/i18n/MControlCenter_en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,16 @@
<source>rpm</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Couldn&apos;t connect to UPower to get charger status.
Make sure that UPower is installed and running then restart the app.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Couldn&apos;t connect to Power Profiles Daemon.
Make sure that either Power Profiles Daemon or TuneD is installed and restart the app.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Mode</source>
<translation type="unfinished"></translation>
Expand Down Expand Up @@ -215,6 +225,10 @@
<source>Current fan Mode:</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Automatic Profile Switching</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Keyboard</source>
<translation type="unfinished"></translation>
Expand Down Expand Up @@ -243,6 +257,10 @@
<source>Maximum performance at the cost of heat and increased power consumption</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Follow system&apos;s power profile</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>If you mainly use your laptop with the charger plugged most of the time, it is recommended to set the charge capacity at a lower percentage (60% or 80%) to prolong your battery lifecycle.</source>
<translation type="unfinished"></translation>
Expand All @@ -251,6 +269,14 @@
<source>Charge the battery when under 90%, stop at 100%</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>On Charger:</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>On Battery:</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Keyboard Backlight</source>
<translation type="unfinished"></translation>
Expand Down
126 changes: 126 additions & 0 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <QMessageBox>

Operate operate;
PowerMonitor powerMonitor;

bool isActive = false;
bool isUpdateDataError = false;
Expand Down Expand Up @@ -136,6 +137,8 @@ MainWindow::MainWindow(QWidget *parent)

connect(ui->fanSpeedResetButton, &QPushButton::clicked, this, &MainWindow::updateFanSpeedSettings);
connect(ui->fanSpeedApplyButton, &QPushButton::clicked, this, &MainWindow::setFanSpeedSettings);
connect(&powerMonitor, &PowerMonitor::currentChargerState, this, &MainWindow::on_ChargerStateChange);
connect(&powerMonitor, &PowerMonitor::currentPowerProfile, this, &MainWindow::on_PowerProfileChange);

connect(qApp, &QGuiApplication::saveStateRequest, this, &MainWindow::saveStateRequest);

Expand Down Expand Up @@ -174,6 +177,10 @@ MainWindow::MainWindow(QWidget *parent)

ui->QtVersionValue->setText(QT_VERSION_STR);
ui->versionValueLabel->setText(MControlCenter_VERSION);
ui->autoAcDcProfilesGroupBox->setChecked(s.getValue("Settings/autoAcDcProfilesState").toBool());
ui->userModeOnBatteryComboBox->setCurrentIndex(s.getValue("Settings/UserModeOnBattery").toInt());
ui->userModeOnChargerComboBox->setCurrentIndex(s.getValue("Settings/UserModeOnCharger").toInt());
ui->autoPPDCheckBox->setChecked(s.getValue("Settings/autoPPDstate").toBool());
}

MainWindow::~MainWindow() {
Expand Down Expand Up @@ -679,6 +686,65 @@ void MainWindow::timerSleepTimeout() {
}
}

void MainWindow::setModeFromSelection(PowerProfile profile) {
switch (profile) {
case PowerProfile::Performance:
setHighPerformanceMode();
break;
case PowerProfile::Balanced:
setBalancedMode();
break;
case PowerProfile::Silent:
setSilentMode();
break;
case PowerProfile::PowerSaver:
setSuperBatteryMode();
break;
case PowerProfile::Unknown:
default:;
}
}

void MainWindow::on_ChargerStateChange(bool isCharging) {
if (ui->autoAcDcProfilesGroupBox->isChecked()) {
Settings s;
int SelectedModeOnBattery = s.getValue("Settings/UserModeOnBattery").toInt();
int SelectedModeOnCharger = s.getValue("Settings/UserModeOnCharger").toInt();

PowerProfile batteryProfile = static_cast<PowerProfile>(SelectedModeOnBattery);
PowerProfile chargerProfile = static_cast<PowerProfile>(SelectedModeOnCharger);

if (isCharging) {
setModeFromSelection(chargerProfile);
} else {
setModeFromSelection(batteryProfile);
}
} else {
ui->autoPPDCheckBox->setEnabled(1);
}
}

void MainWindow::on_PowerProfileChange(const PowerProfile profile) {
if (ui->autoPPDCheckBox->isChecked()) {
switch (profile) {
case PowerProfile::Performance:
setHighPerformanceMode();
ui->highPerformanceModeRadioButton->setChecked(true);
break;
case PowerProfile::Balanced:
setBalancedMode();
ui->balancedModeRadioButton->setChecked(true);
break;
case PowerProfile::PowerSaver:
setSuperBatteryMode();
ui->superBatteryModeRadioButton->setChecked(true);
break;
case PowerProfile::Unknown:
default:;
}
}
}

void MainWindow::on_bestMobilityRadioButton_toggled(bool checked) {
if (checked)
setBestMobility();
Expand Down Expand Up @@ -756,6 +822,66 @@ void MainWindow::on_keyboardBacklightModeComboBox_currentIndexChanged(int index)
operate.setKeyboardBacklightMode(index);
}

void MainWindow::on_userModeOnBatteryComboBox_currentIndexChanged(int index) const {
Settings::setValue("Settings/UserModeOnBattery", index);
powerMonitor.queryChargerState();
}

void MainWindow::on_userModeOnChargerComboBox_currentIndexChanged(int index) const {
Settings::setValue("Settings/UserModeOnCharger", index);
powerMonitor.queryChargerState();
}

void MainWindow::on_autoAcDcProfilesGroupBox_toggled(bool checked) {
if(checked) {
if (!powerMonitor.connectToUpower()) {
QMessageBox::critical(nullptr, this->windowTitle(), tr("Couldn't connect to UPower to get charger status.\n"
"Make sure that UPower is installed and running then restart the system."));
ui->autoAcDcProfilesGroupBox->setChecked(0);
ui->autoAcDcProfilesGroupBox->setEnabled(0);
return;
}

powerMonitor.disconnectFromPowerProfiles();
ui->autoPPDCheckBox->setChecked(0);
ui->autoPPDCheckBox->setEnabled(0);
powerMonitor.queryChargerState();
} else {
ui->autoPPDCheckBox->setEnabled(1);
powerMonitor.disconnectFromUpower();
}

Settings::setValue("Settings/autoAcDcProfilesState", checked);
}

void MainWindow::on_autoPPDCheckBox_toggled(bool checked) {
if (checked) {

if (!powerMonitor.connectToPowerProfiles()) {
QMessageBox::critical(nullptr, this->windowTitle(), tr("Couldn't connect to Power Profiles Daemon.\n"
"Make sure that either Power Profiles Daemon or TuneD is installed and restart the system."));
ui->autoPPDCheckBox->setChecked(0);
return;
}

powerMonitor.disconnectFromUpower();
ui->highPerformanceModeRadioButton->setEnabled(0);
ui->balancedModeRadioButton->setEnabled(0);
ui->silentModeRadioButton->setEnabled(0);
ui->superBatteryModeRadioButton->setEnabled(0);
ui->autoAcDcProfilesGroupBox->setChecked(0);
ui->autoAcDcProfilesGroupBox->setEnabled(0);
powerMonitor.queryPowerProfile();
} else {
ui->highPerformanceModeRadioButton->setEnabled(1);
ui->balancedModeRadioButton->setEnabled(1);
ui->silentModeRadioButton->setEnabled(1);
ui->superBatteryModeRadioButton->setEnabled(1);
ui->autoAcDcProfilesGroupBox->setEnabled(1);
}
Settings::setValue("Settings/autoPPDstate", checked);
}

void MainWindow::on_highPerformanceModeRadioButton_toggled(bool checked) {
if (checked)
setHighPerformanceMode();
Expand Down
10 changes: 10 additions & 0 deletions src/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include "powermonitor.h"
#include <QMainWindow>
#include <QCloseEvent>
#include <QSystemTrayIcon>
Expand All @@ -45,6 +46,7 @@ Q_OBJECT
void startRealtimeUpdate() const;
void stopRealtimeUpdate() const;
void setUpdateInterval(int msec) const;
void setModeFromSelection(PowerProfile profile);
void realtimeUpdate();
void loadConfigs();

Expand Down Expand Up @@ -120,6 +122,9 @@ Q_OBJECT
QAction *quitAction = nullptr;

private slots:
void on_ChargerStateChange(bool isCharging);
void on_PowerProfileChange(const PowerProfile profile);

void on_bestMobilityRadioButton_toggled(bool checked);
void on_balancedBatteryRadioButton_toggled(bool checked);
void on_bestBatteryRadioButton_toggled(bool checked);
Expand All @@ -141,6 +146,11 @@ private slots:

void on_keyboardBacklightModeComboBox_currentIndexChanged(int index) const;

void on_userModeOnBatteryComboBox_currentIndexChanged(int index) const;
void on_userModeOnChargerComboBox_currentIndexChanged(int index) const;
void on_autoPPDCheckBox_toggled(bool checked);
void on_autoAcDcProfilesGroupBox_toggled(bool active);

void on_highPerformanceModeRadioButton_toggled(bool checked);
void on_balancedModeRadioButton_toggled(bool checked);
void on_silentModeRadioButton_toggled(bool checked);
Expand Down
Loading