Skip to content

Commit

Permalink
Misc
Browse files Browse the repository at this point in the history
* handle some errors/warnings
* minor dialog fixes
* other minor
  • Loading branch information
rodlie committed Feb 6, 2024
1 parent d1bb487 commit 3b37aa8
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 28 deletions.
44 changes: 32 additions & 12 deletions src/powerkit_app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,14 @@ App::App(QObject *parent)
SIGNAL(Update()),
this,
SLOT(loadSettings()));
connect(man,
SIGNAL(Error(QString)),
this,
SLOT(handleError(QString)));
connect(man,
SIGNAL(Warning(QString)),
this,
SLOT(handleWarning(QString)));

// setup org.freedesktop.PowerManagement
pm = new PowerManagement(this);
Expand Down Expand Up @@ -570,6 +578,8 @@ void App::registerService()
qWarning() << "Enabled org.freedesktop.PowerKit" << hasDesktopPK;

if (!hasDesktopPK || !hasDesktopPM || !hasScreenSaver) { hasService = false; }

if (!hasService) { handleWarning(tr("Failed to setup and/or connect required services!")); }
}

// dbus session inhibit status handler
Expand Down Expand Up @@ -795,13 +805,13 @@ void App::handleNewInhibitPowerManagement(const QString &application,

void App::handleDelInhibitScreenSaver(quint32 cookie)
{
qDebug() << "SS INHIBITOR REMOVED" << cookie;
Q_UNUSED(cookie)
checkDevices();
}

void App::handleDelInhibitPowerManagement(quint32 cookie)
{
qDebug() << "PM INHIBITOR REMOVED" << cookie;
Q_UNUSED(cookie)
checkDevices();
}

Expand Down Expand Up @@ -830,7 +840,6 @@ void App::showMessage(const QString &title,
void App::handleConfChanged(const QString &file)
{
Q_UNUSED(file)
qDebug() << "CONFIG CHANGED" << file;
loadSettings();
}

Expand Down Expand Up @@ -876,25 +885,25 @@ void App::disableSuspend()
qWarning() << "reset lid battery action to lock";
lidActionBattery = lidLock;
Settings::setValue(CONF_LID_BATTERY_ACTION,
lidActionBattery);
lidActionBattery);
}
if (lidActionAC == lidSleep) {
qWarning() << "reset lid ac action to lock";
lidActionAC = lidLock;
Settings::setValue(CONF_LID_AC_ACTION,
lidActionAC);
lidActionAC);
}
if (autoSuspendBatteryAction == suspendSleep) {
qWarning() << "reset auto suspend battery action to none";
autoSuspendBatteryAction = suspendNone;
Settings::setValue(CONF_SUSPEND_BATTERY_ACTION,
autoSuspendBatteryAction);
autoSuspendBatteryAction);
}
if (autoSuspendACAction == suspendSleep) {
qWarning() << "reset auto suspend ac action to none";
autoSuspendACAction = suspendNone;
Settings::setValue(CONF_SUSPEND_AC_ACTION,
autoSuspendACAction);
autoSuspendACAction);
}
}

Expand All @@ -912,15 +921,14 @@ void App::handlePrepareForResume()
{
qDebug() << "prepare for resume ...";
resetTimer();
tray->showMessage(QString(), QString());
ss->SimulateUserActivity();
}

// turn off/on monitor using xrandr
void App::switchInternalMonitor(bool toggle)
{
if (!lidXrandr) { return; }
qDebug() << "using xrandr to turn on/off internal monitor" << toggle;
qDebug() << "using xrandr to turn on/off internal monitor" << internalMonitor << toggle;
QStringList args;
args << "--output" << internalMonitor << (toggle ? "--auto" : "--off");
QProcess::startDetached("xrandr", args);
Expand Down Expand Up @@ -953,9 +961,21 @@ void App::handleDeviceChanged(const QString &path)

void App::openSettings()
{
QProcess proc;
proc.startDetached(qApp->applicationFilePath(),
QStringList() << "--config");
QProcess::startDetached(qApp->applicationFilePath(),
QStringList() << "--config");
}

void App::handleError(const QString &message)
{
qWarning() << "error" << message;
showMessage(tr("Error"), message, true);
QTimer::singleShot(5000, qApp, SLOT(quit()));
}

void App::handleWarning(const QString &message)
{
qWarning() << "warning" << message;
showMessage(tr("Warning"), message, true);
}

// catch wheel events
Expand Down
2 changes: 2 additions & 0 deletions src/powerkit_app.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ namespace PowerKit
void handleTrayWheel(TrayIcon::WheelAction action);
void handleDeviceChanged(const QString &path);
void openSettings();
void handleError(const QString &message);
void handleWarning(const QString &message);
};
}

Expand Down
7 changes: 6 additions & 1 deletion src/powerkit_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,11 @@ Dialog::Dialog(QWidget *parent,

Dialog::~Dialog()
{
Settings::setValue(CONF_DIALOG, saveGeometry());
const auto lastGeo = Settings::getValue(CONF_DIALOG).toByteArray();
const auto newGeo = saveGeometry();
if (lastGeo != newGeo) {
Settings::setValue(CONF_DIALOG, newGeo);
}
}

void Dialog::setupWidgets()
Expand Down Expand Up @@ -928,6 +932,7 @@ void Dialog::handleUpdatedDevices()
hasBattery = Client::hasBattery(dbus);
batteryStatusLabel->setVisible(hasBattery);
drawBattery();
drawCpu();
}

// save current value and update power manager
Expand Down
37 changes: 22 additions & 15 deletions src/powerkit_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,16 +325,21 @@ void Manager::setup()
SIGNAL(PrepareForSleep(bool)),
this,
SLOT(handlePrepareForSuspend(bool)));
emit Error(tr("Failed to connect to logind"));
}
if (!suspendLock) { registerSuspendLock(); }
if (!lidLock) { registerLidLock(); }
scan();
} else { qWarning() << "Failed to connect to system bus"; }
} else {
emit Error(tr("Failed to connect to the system bus"));
}
}

void Manager::check()
{
if (!QDBusConnection::systemBus().isConnected()) {
if (!QDBusConnection::systemBus().isConnected() ||
!upower ||
!logind) {
setup();
return;
}
Expand Down Expand Up @@ -395,7 +400,6 @@ void Manager::deviceRemoved(const QString &path)

void Manager::deviceChanged()
{
qDebug() << "a device changed, tell the world!";
emit UpdatedDevices();
}

Expand All @@ -410,10 +414,10 @@ void Manager::propertiesChanged()

if (wasLidClosed != isLidClosed) {
if (!wasLidClosed && isLidClosed) {
qDebug() << "lid changed status to closed";
qDebug() << "lid changed to closed";
emit LidClosed();
} else if (wasLidClosed && !isLidClosed) {
qDebug() << "lid changed status to open";
qDebug() << "lid changed to open";
emit LidOpened();
}
}
Expand Down Expand Up @@ -451,8 +455,7 @@ void Manager::handleSuspend()
{
if (HasLogind()) { return; }
qDebug() << "handle suspend from upower";
LockScreen();
emit PrepareForSuspend();
handlePrepareForSuspend(true);
}

void Manager::handlePrepareForSuspend(bool prepare)
Expand Down Expand Up @@ -496,25 +499,29 @@ void Manager::clearDevices()
devices.clear();
}

void Manager::handleNewInhibitScreenSaver(const QString &application, const QString &reason, quint32 cookie)
void Manager::handleNewInhibitScreenSaver(const QString &application,
const QString &reason,
quint32 cookie)
{
qDebug() << "PK HANDLE NEW SCREEN SAVER INHIBITOR" << application << reason << cookie;
qDebug() << "new screensaver cookie" << application << reason << cookie;
Q_UNUSED(reason)
ssInhibitors[cookie] = application;
emit UpdatedInhibitors();
}

void Manager::handleNewInhibitPowerManagement(const QString &application, const QString &reason, quint32 cookie)
void Manager::handleNewInhibitPowerManagement(const QString &application,
const QString &reason,
quint32 cookie)
{
qDebug() << "PK HANDLE NEW POWER INHIBITOR" << application << reason << cookie;
qDebug() << "new power cookie" << application << reason << cookie;
Q_UNUSED(reason)
pmInhibitors[cookie] = application;
emit UpdatedInhibitors();
}

void Manager::handleDelInhibitScreenSaver(quint32 cookie)
{
qDebug() << "PK HANDLE REMOVE SCREEN SAVER COOKIE" << cookie;
qDebug() << "remove screensaver cookie" << cookie;
if (ssInhibitors.contains(cookie)) {
ssInhibitors.remove(cookie);
emit UpdatedInhibitors();
Expand All @@ -523,7 +530,7 @@ void Manager::handleDelInhibitScreenSaver(quint32 cookie)

void Manager::handleDelInhibitPowerManagement(quint32 cookie)
{
qDebug() << "PK HANDLE REMOVE POWER COOKIE" << cookie;
qDebug() << "remove power cookie" << cookie;
if (pmInhibitors.contains(cookie)) {
pmInhibitors.remove(cookie);
emit UpdatedInhibitors();
Expand All @@ -546,7 +553,7 @@ bool Manager::registerSuspendLock()
suspendLock.reset(new QDBusUnixFileDescriptor(reply.value()));
return true;
} else {
qWarning() << reply.error();
emit Warning(tr("Failed to set suspend lock: %1").arg(reply.error().message()));
}
return false;
}
Expand All @@ -568,7 +575,7 @@ bool Manager::registerLidLock()
qDebug() << "lidLock" << lidLock->fileDescriptor();
return true;
} else {
qWarning() << reply.error();
emit Warning(tr("Failed to set lid lock: %1").arg(reply.error().message()));
}
return false;
}
Expand Down
2 changes: 2 additions & 0 deletions src/powerkit_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ namespace PowerKit
void DeviceWasRemoved(const QString &path);
void DeviceWasAdded(const QString &path);
void UpdatedInhibitors();
void Error(const QString &message);
void Warning(const QString &message);

private slots:
bool availableService(const QString &service,
Expand Down

0 comments on commit 3b37aa8

Please sign in to comment.