Skip to content

Commit

Permalink
Merge pull request #9 from rodlie/master
Browse files Browse the repository at this point in the history
misc
  • Loading branch information
rodlie authored Oct 25, 2018
2 parents 63eb6e3 + e8cdc75 commit 1192ede
Show file tree
Hide file tree
Showing 10 changed files with 135 additions and 33 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
# PowerKit

![screenshot](app/share/images/screenshot-03.png)

powerkit is an lightweight desktop independent full featured power manager, originally created for [Slackware](http://www.slackware.com/) for use with alternative desktop environments and window managers, like [Fluxbox](http://fluxbox.org/), [Blackbox](https://en.wikipedia.org/wiki/Blackbox), [FVWM](http://www.fvwm.org/), [WindowMaker](https://www.windowmaker.org/), [Openbox](http://openbox.org/wiki/Main_Page), [Lumina](https://lumina-desktop.org/) and others.

![screenshot](app/share/images/screenshot-01.png)
![screenshot](app/share/images/screenshot-02.png)

## Features

* Enables applications to inhibit the screen saver
Expand Down
4 changes: 4 additions & 0 deletions app/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ void Common::saveDefaultSettings()
false);
savePowerSettings(CONF_BACKLIGHT_AC_DISABLE_IF_HIGHER,
false);
savePowerSettings(CONF_WARN_ON_LOW_BATTERY,
true);
savePowerSettings(CONF_WARN_ON_VERYLOW_BATTERY,
true);
}

void Common::setIconTheme()
Expand Down
140 changes: 107 additions & 33 deletions app/dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ Dialog::Dialog(QWidget *parent)
, sleepButton(0)
, hibernateButton(0)
, poweroffButton(0)
// , lidXrandr(0)
, hasBacklight(false)
, backlightSlider(0)
, backlightWatcher(0)
Expand All @@ -44,6 +43,9 @@ Dialog::Dialog(QWidget *parent)
, backlightBatteryLowerCheck(0)
, backlightACHigherCheck(0)
, inhibitorTree(0)
, warnOnLowBattery(0)
, warnOnVeryLowBattery(0)
, aboutButton(0)
{
// setup dialog
setAttribute(Qt::WA_QuitOnClose, true);
Expand Down Expand Up @@ -358,20 +360,9 @@ Dialog::Dialog(QWidget *parent)

// advanced
QGroupBox *advContainer = new QGroupBox(this);
advContainer->setTitle(tr("Advanced"));
advContainer->setTitle(tr("Services"));
QVBoxLayout *advContainerLayout = new QVBoxLayout(advContainer);

showSystemTray = new QCheckBox(this);
showSystemTray->setIcon(QIcon::fromTheme(DEFAULT_TRAY_ICON));
showSystemTray->setText(tr("Show system tray"));
showSystemTray->setToolTip(tr("Enable/Disable the system tray icon."
" Note that notifications will not work when the systemtray is disabled."));

showNotifications = new QCheckBox(this);
showNotifications->setIcon(QIcon::fromTheme(DEFAULT_NOTIFY_ICON));
showNotifications->setText(tr("Show notifications"));
showNotifications->setToolTip(tr("Show notifications for power related events."));

desktopSS = new QCheckBox(this);
desktopSS->setIcon(QIcon::fromTheme(DEFAULT_VIDEO_ICON));
desktopSS->setText("org.freedesktop.ScreenSaver");
Expand All @@ -384,31 +375,69 @@ Dialog::Dialog(QWidget *parent)
desktopPM->setToolTip(tr("Enable/Disable the power management D-Bus service."
" Needed for applications to inhibit auto suspend action."));

/*lidXrandr = new QCheckBox(this);
lidXrandr->setIcon(QIcon::fromTheme(DEFAULT_VIDEO_ICON));
lidXrandr->setText(tr("Switch internal monitor on/off"
"\nwith xrandr if lid action disabled"));*/
// add widgets to advanced
advContainerLayout->addWidget(desktopSS);
advContainerLayout->addWidget(desktopPM);
advContainerLayout->addStretch();

// common
QGroupBox *daemonContainer = new QGroupBox(this);
daemonContainer->setTitle(tr("Common"));
QVBoxLayout *daemonContainerLayout = new QVBoxLayout(daemonContainer);

showSystemTray = new QCheckBox(this);
showSystemTray->setIcon(QIcon::fromTheme(DEFAULT_TRAY_ICON));
showSystemTray->setText(tr("Show system tray"));
showSystemTray->setToolTip(tr("Enable/Disable the system tray icon."
" Note that notifications will not work when the systemtray is disabled."));

showNotifications = new QCheckBox(this);
showNotifications->setIcon(QIcon::fromTheme(DEFAULT_NOTIFY_ICON));
showNotifications->setText(tr("Show notifications"));
showNotifications->setToolTip(tr("Show notifications for power related events."));

disableLidAction = new QCheckBox(this);
disableLidAction->setIcon(QIcon::fromTheme(DEFAULT_VIDEO_ICON));
disableLidAction->setText(tr("Disable lid action if external"
"\nmonitor(s) is connected"));
disableLidAction->setToolTip(tr("If an external monitor (HDMI/VGA/DVI/DP etc) is connected"
" to your laptop, disable/enable lid action."));
disableLidAction->setToolTip(tr("Disable lid action if an external monitor is connected"
" to your laptop."));

// add widgets to advanced
advContainerLayout->addWidget(showSystemTray);
advContainerLayout->addWidget(showNotifications);
advContainerLayout->addWidget(disableLidAction);
advContainerLayout->addWidget(desktopSS);
advContainerLayout->addWidget(desktopPM);
//advContainerLayout->addWidget(lidXrandr);
advContainerLayout->addStretch();
daemonContainerLayout->addWidget(showSystemTray);
daemonContainerLayout->addWidget(showNotifications);
daemonContainerLayout->addWidget(disableLidAction);

// notify
QGroupBox *notifyContainer = new QGroupBox(this);
notifyContainer->setTitle(tr("Notifications"));
QVBoxLayout *notifyContainerLayout = new QVBoxLayout(notifyContainer);

warnOnLowBattery = new QCheckBox(this);
warnOnLowBattery->setIcon(QIcon::fromTheme(DEFAULT_NOTIFY_ICON));
warnOnLowBattery->setText(tr("Notify on low battery"));
warnOnLowBattery->setToolTip(tr("Show a notification when on low battery (%1% over critical)")
.arg(LOW_BATTERY));

warnOnVeryLowBattery = new QCheckBox(this);
warnOnVeryLowBattery->setIcon(QIcon::fromTheme(DEFAULT_NOTIFY_ICON));
warnOnVeryLowBattery->setText(tr("Notify on very low battery"));
warnOnVeryLowBattery->setToolTip(tr("Show a notification when on very low battery (1% over critical)"));

notifyContainerLayout->addWidget(warnOnLowBattery);
notifyContainerLayout->addWidget(warnOnVeryLowBattery);

// extra
QWidget *extraContainer = new QWidget(this);
QHBoxLayout *extraContainerLayout = new QHBoxLayout(extraContainer);

aboutButton = new QPushButton(this);
aboutButton->setIcon(QIcon::fromTheme(DEFAULT_ABOUT_ICON));
aboutButton->setIconSize(QSize(24, 24));
aboutButton->setToolTip(tr("About"));
if (aboutButton->icon().isNull()) {
aboutButton->setText(tr("About"));
}

lockscreenButton = new QPushButton(this);
lockscreenButton->setIcon(QIcon::fromTheme(DEFAULT_LOCK_ICON));
lockscreenButton->setIconSize(QSize(24, 24));
Expand Down Expand Up @@ -455,6 +484,7 @@ Dialog::Dialog(QWidget *parent)
extraContainerLayout->addWidget(backlightLabel);
extraContainerLayout->addWidget(backlightSlider);
extraContainerLayout->addStretch();
extraContainerLayout->addWidget(aboutButton);
extraContainerLayout->addWidget(lockscreenButton);
extraContainerLayout->addWidget(sleepButton);
extraContainerLayout->addWidget(hibernateButton);
Expand Down Expand Up @@ -489,11 +519,11 @@ Dialog::Dialog(QWidget *parent)
deviceTree->setHeaderLabels(QStringList() << "1" << "2");
deviceTree->setColumnWidth(0, 150);

QLabel *aboutLabel = new QLabel(this);
/*QLabel *aboutLabel = new QLabel(this);
aboutLabel->setText(QString("<p style=\"font-size:small;\">"
"<a href=\"https://github.com/rodlie/powerkit\">"
"PowerKit</a> %1 &copy;2018 Ole-Andr&eacute; Rodlie")
.arg(qApp->applicationVersion()));
.arg(qApp->applicationVersion()));*/

batteryStatusLayout->addWidget(batteryIcon);
batteryStatusLayout->addWidget(batteryLabel);
Expand All @@ -503,7 +533,7 @@ Dialog::Dialog(QWidget *parent)
statusContainerLayout->addWidget(batteryStatusBox);
statusContainerLayout->addWidget(deviceTree);
statusContainerLayout->addStretch();
statusContainerLayout->addWidget(aboutLabel);
//statusContainerLayout->addWidget(aboutLabel);

layout->addWidget(wrapper);
layout->addWidget(extraContainer);
Expand All @@ -520,7 +550,8 @@ Dialog::Dialog(QWidget *parent)
// add widgets to settings
settingsLayout->addWidget(batteryContainer);
settingsLayout->addWidget(acContainer);
//settingsLayout->addWidget(backlightContainer);
settingsLayout->addWidget(daemonContainer);
settingsLayout->addWidget(notifyContainer);
settingsLayout->addWidget(advContainer);
settingsLayout->addStretch();

Expand Down Expand Up @@ -577,8 +608,6 @@ Dialog::Dialog(QWidget *parent)
this, SLOT(handleAutoSleepBatteryAction(int)));
connect(autoSleepACAction, SIGNAL(currentIndexChanged(int)),
this, SLOT(handleAutoSleepACAction(int)));
/*connect(lidXrandr, SIGNAL(toggled(bool)),
this, SLOT(handleLidXrandr(bool)));*/
connect(backlightSlider, SIGNAL(valueChanged(int)),
this, SLOT(handleBacklightSlider(int)));
connect(backlightWatcher, SIGNAL(fileChanged(QString)),
Expand All @@ -601,6 +630,8 @@ Dialog::Dialog(QWidget *parent)
this, SLOT(handleBacklightBatteryCheckLower(bool)));
connect(backlightACHigherCheck, SIGNAL(toggled(bool)),
this, SLOT(handleBacklightACCheckHigher(bool)));
connect(aboutButton, SIGNAL(released()),
this, SLOT(showAboutDialog()));
}

Dialog::~Dialog()
Expand Down Expand Up @@ -763,6 +794,18 @@ void Dialog::loadSettings()
}
disableLidAction->setChecked(defaultDisableLidAction);

bool defaultWarnOnLowBattery = true;
if (Common::validPowerSettings(CONF_WARN_ON_LOW_BATTERY)) {
defaultWarnOnLowBattery = Common::loadPowerSettings(CONF_WARN_ON_LOW_BATTERY).toBool();
}
warnOnLowBattery->setChecked(defaultWarnOnLowBattery);

bool defaultWarnOnVeryLowBattery = true;
if (Common::validPowerSettings(CONF_WARN_ON_VERYLOW_BATTERY)) {
defaultWarnOnVeryLowBattery = Common::loadPowerSettings(CONF_WARN_ON_VERYLOW_BATTERY).toBool();
}
warnOnVeryLowBattery->setChecked(defaultWarnOnVeryLowBattery);

// power actions
bool canSuspend = man->CanSuspend();
bool canHibernate = man->CanHibernate();
Expand Down Expand Up @@ -1005,6 +1048,10 @@ void Dialog::handleLockscreenButton()

void Dialog::handleSleepButton()
{
if (QMessageBox::question(this,
tr("Suspend computer"),
tr("Are you sure you want to suspend?")
) == QMessageBox::No) { return; }
if (man->CanSuspend()) { man->Suspend(); }
else {
QMessageBox::information(this,
Expand All @@ -1017,6 +1064,10 @@ void Dialog::handleSleepButton()

void Dialog::handleHibernateButton()
{
if (QMessageBox::question(this,
tr("Hibernate computer"),
tr("Are you sure you want to hibernate?")
) == QMessageBox::No) { return; }
if (man->CanHibernate() &&
Common::kernelCanResume()) { man->Hibernate(); }
else {
Expand All @@ -1030,6 +1081,10 @@ void Dialog::handleHibernateButton()

void Dialog::handlePoweroffButton()
{
if (QMessageBox::question(this,
tr("Shutdown computer"),
tr("Are you sure you want to shutdown?")
) == QMessageBox::No) { return; }
if (man->CanPowerOff()) { man->PowerOff(); }
else {
QMessageBox::information(this,
Expand Down Expand Up @@ -1309,3 +1364,22 @@ void Dialog::enableBacklight(bool enabled)
backlightBatteryLowerCheck->setEnabled(enabled);
backlightACHigherCheck->setEnabled(enabled);
}

void Dialog::showAboutDialog()
{
QMessageBox about;
about.setWindowIcon(QIcon::fromTheme(DEFAULT_AC_ICON));
about.setIconPixmap(QIcon::fromTheme(DEFAULT_AC_ICON).pixmap(48, 48));
about.setWindowTitle(tr("About PowerKit"));
about.setText(QString("<h1 style=\"font-weight:normal;\">PowerKit %1</h1>"
"<h3>Desktop independent power manager.</h3>"
"<p>&copy;2018 Ole-Andr&eacute; Rodlie. All rights reserved.<br>"
"Available under the 3-clause BSD license.<br> See the"
" <a href=\"https://github.com/rodlie/powerkit/blob/master/LICENSE\">LICENSE</a>"
" file for full details.</p>"
"<p>Available on <a href=\"https://github.com/rodlie/powerkit\">Github</a>,"
" <a href=\"https://gitlab.com/rodlie/powerkit\">Gitlab</a> or"
" <a href=\"https://sourceforge.net/p/powerkit\">SourceForge</a>.</p>")
.arg(qApp->applicationVersion()));
about.exec();
}
4 changes: 4 additions & 0 deletions app/dialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ class Dialog : public QDialog
QCheckBox *backlightBatteryLowerCheck;
QCheckBox *backlightACHigherCheck;
QTreeWidget *inhibitorTree;
QCheckBox *warnOnLowBattery;
QCheckBox *warnOnVeryLowBattery;
QPushButton *aboutButton;

private slots:
void populate();
Expand Down Expand Up @@ -145,6 +148,7 @@ private slots:
void handleUpdatedInhibitors();
void getInhibitors();
void enableBacklight(bool enabled);
void showAboutDialog();
};

#endif // DIALOG_H
Binary file added app/share/images/screenshot-01.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/share/images/screenshot-02.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/share/images/screenshot-03.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions app/systray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ SysTray::SysTray(QObject *parent)
, backlightBatteryDisableIfLower(false)
, backlightACDisableIfHigher(false)
, configDialog(0)
, warnOnLowBattery(true)
, warnOnVeryLowBattery(true)
{
// setup tray
tray = new TrayIcon(this);
Expand Down Expand Up @@ -445,6 +447,12 @@ void SysTray::loadSettings()
backlightACDisableIfHigher = Common::loadPowerSettings(CONF_BACKLIGHT_AC_DISABLE_IF_HIGHER)
.toBool();
}
if (Common::validPowerSettings(CONF_WARN_ON_LOW_BATTERY)) {
warnOnLowBattery = Common::loadPowerSettings(CONF_WARN_ON_LOW_BATTERY).toBool();
}
if (Common::validPowerSettings(CONF_WARN_ON_VERYLOW_BATTERY)) {
warnOnVeryLowBattery = Common::loadPowerSettings(CONF_WARN_ON_VERYLOW_BATTERY).toBool();
}

// verify
if (!Common::kernelCanResume()) {
Expand Down Expand Up @@ -537,6 +545,7 @@ void SysTray::handleHasInhibitChanged(bool has_inhibit)

void SysTray::handleLow(double left)
{
if (!warnOnLowBattery) { return; }
double batteryLow = (double)(lowBatteryValue+critBatteryValue);
if (left<=batteryLow && man->OnBattery()) {
if (!wasLowBattery) {
Expand All @@ -552,6 +561,7 @@ void SysTray::handleLow(double left)

void SysTray::handleVeryLow(double left)
{
if (!warnOnVeryLowBattery) { return; }
double batteryVeryLow = (double)(critBatteryValue+1);
if (left<=batteryVeryLow && man->OnBattery()) {
if (!wasVeryLowBattery) {
Expand Down
2 changes: 2 additions & 0 deletions app/systray.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ class SysTray : public QObject
bool backlightBatteryDisableIfLower;
bool backlightACDisableIfHigher;
QProcess *configDialog;
bool warnOnLowBattery;
bool warnOnVeryLowBattery;

private slots:
void trayActivated(QSystemTrayIcon::ActivationReason reason);
Expand Down
3 changes: 3 additions & 0 deletions lib/def.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ enum criticalAction
#define DEFAULT_INFO_ICON "dialog-information"
#define DEFAULT_KEYBOARD_ICON "input-keyboard"
#define DEFAULT_MOUSE_ICON "input-mouse"
#define DEFAULT_ABOUT_ICON "dialog-question"

#define DEFAULT_SUSPEND_BATTERY_ACTION suspendSleep
#define DEFAULT_SUSPEND_AC_ACTION suspendNone
Expand Down Expand Up @@ -124,5 +125,7 @@ enum criticalAction
#define CONF_BACKLIGHT_AC_ENABLE "backlight_ac_enable"
#define CONF_BACKLIGHT_AC_DISABLE_IF_HIGHER "backlight_ac_disable_if_higher"
#define CONF_DIALOG "dialog_geometry"
#define CONF_WARN_ON_LOW_BATTERY "warn_on_low_battery"
#define CONF_WARN_ON_VERYLOW_BATTERY "warn_on_verylow_battery"

#endif // DEF_H

0 comments on commit 1192ede

Please sign in to comment.