Skip to content

Commit

Permalink
Merge pull request #16 from rodlie/master
Browse files Browse the repository at this point in the history
1.0.0 RC2
  • Loading branch information
rodlie authored Nov 4, 2018
2 parents f158c77 + 41c5aaf commit a50621a
Show file tree
Hide file tree
Showing 159 changed files with 591 additions and 216 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ script:
- export CWD=`pwd`
- mkdir $CWD/qt5
- cd $CWD/qt5
- qmake -qt=qt5 CONFIG+=release PREFIX=/usr ..
- qmake -qt=qt5 CONFIG+=release CONFIG+=install_lib PREFIX=/usr ..
- make
- make INSTALL_ROOT=`pwd`/pkg install
- tree pkg
- cd $CWD
- mkdir $CWD/qt4
- cd $CWD/qt4
- qmake -qt=qt4 CONFIG+=release PREFIX=/usr ..
- qmake -qt=qt4 CONFIG+=release CONFIG+=bundle_icons PREFIX=/usr ..
- make
- make INSTALL_ROOT=`pwd`/pkg install
- tree pkg
Expand Down
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
## 1.0.0rc2 - 20181103
* Added more configuration options
* Added option to bundle failsafe icons

## 1.0.0rc1 - 20181025
* first public release
1 change: 0 additions & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
PowerKit <https://github.com/rodlie/powerkit>

Copyright (c) 2018, Ole-André Rodlie <[email protected]>
All rights reserved.
Expand Down
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,13 @@ powerkit requires the following dependencies to work:
* [ConsoleKit](https://www.freedesktop.org/wiki/Software/ConsoleKit/) (or logind)
* [UPower](https://upower.freedesktop.org/) 0.9.23(+)
* [XScreenSaver](https://www.jwz.org/xscreensaver/)
* [adwaita-icon-theme](https://github.com/GNOME/adwaita-icon-theme) (or similar)
* [adwaita-icon-theme](https://github.com/GNOME/adwaita-icon-theme) (if built without ``CONFIG+=bundle_icons``)

### Icons

powerkit does not bundle any icons, so you will need a compatible theme installed. powerkit will use the existing icon theme from your running DE/WM or fallback to a known theme:
powerkit will use the existing icon theme from the running DE/WM, else check the GTK settings then fallback to Adwaita if no theme was found. So you should have (a proper version) of Adwaita installed or enable ``CONFIG+=bundle_icons`` when building powerkit.

* Adwaita
* Gnome
* Oxygen
* Tango (not recommended)
You can override the icon theme in the `~/.config/powerkit/powerkit.conf` file, see ``icon_theme=<theme_name>``.

## Build

Expand All @@ -137,6 +134,7 @@ First make sure you have the required dependencies installed, then review the bu
* **``CONFIG+=install_lib``**: Build and install shared library.
* **``CONFIG+=no_include_install``**: Do not install include files.
* **``CONFIG+=no_pkgconfig_install``**: Do not install pkgconfig file.
* **``CONFIG+=bundle_icons``**: Bundle a set of fallback icons (Adwaita), this will add 200k to the binary size.

### Build application

Expand Down
7 changes: 7 additions & 0 deletions app/app.pro
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,26 @@ TEMPLATE = app

SOURCES += main.cpp systray.cpp dialog.cpp common.cpp
HEADERS += systray.h dialog.h common.h

LIBS += -L../lib -lPowerKit
INCLUDEPATH += ../lib

include(../powerkit.pri)
DEFINES += APP_VERSION=\"\\\"$${VERSION}\\\"\"
DEFINES += APP_VERSION_EXTRA=\"\\\"$${VERSION_EXTRA}\\\"\"

CONFIG(bundle_icons) {
RESOURCES += icons.qrc
DEFINES += BUNDLE_ICONS
}
!CONFIG(no_app_install) {
target.path = $${PREFIX}/bin
INSTALLS += target
!CONFIG(no_doc_install) {
target_docs.path = $${DOCDIR}/$${TARGET}-$${VERSION}$${VERSION_EXTRA}
target_docs.files = ../LICENSE ../README.md ../ChangeLog
CONFIG(bundle_icons): target_docs.files += icons/Adwaita/LICENSE.Adwaita
exists(../ChangeLog.git): target_docs.files += ../ChangeLog.git
INSTALLS += target_docs
}
!CONFIG(no_man_install) {
Expand Down
58 changes: 24 additions & 34 deletions app/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ void Common::saveDefaultSettings()
true);
savePowerSettings(CONF_NOTIFY_ON_AC,
true);
savePowerSettings(CONF_BACKLIGHT_MOUSE_WHEEL,
true);
savePowerSettings(CONF_SUSPEND_LOCK_SCREEN,
true);
savePowerSettings(CONF_RESUME_LOCK_SCREEN,
false);
}

void Common::setIconTheme()
Expand All @@ -90,59 +96,43 @@ void Common::setIconTheme()
QStringList iconsPath = QIcon::themeSearchPaths();
QString iconsHomeLocal = QString("%1/.local/share/icons").arg(QDir::homePath());
QString iconsHome = QString("%1/.icons").arg(QDir::homePath());
if (QFile::exists(iconsHomeLocal) && !iconsPath.contains(iconsHomeLocal)) { iconsPath.prepend(iconsHomeLocal); }
if (QFile::exists(iconsHome) && !iconsPath.contains(iconsHome)) { iconsPath.prepend(iconsHome); }
if (QFile::exists(iconsHomeLocal) &&
!iconsPath.contains(iconsHomeLocal)) { iconsPath.prepend(iconsHomeLocal); }
if (QFile::exists(iconsHome) &&
!iconsPath.contains(iconsHome)) { iconsPath.prepend(iconsHome); }
iconsPath << QString("%1/../share/icons").arg(qApp->applicationDirPath());
QIcon::setThemeSearchPaths(iconsPath);
qDebug() << "using icon theme search path" << QIcon::themeSearchPaths();

QString theme = QIcon::themeName();
if (theme.isEmpty() || theme == "hicolor") { // try to load saved theme
qDebug() << "checking for icon theme in settings";
theme = loadPowerSettings("icon_theme").toString();
theme = loadPowerSettings(CONF_ICON_THEME).toString();
}
if(theme.isEmpty() || theme == "hicolor") { // Nope, then scan for first available
// gtk
if(QFile::exists(QDir::homePath() + "/" + ".gtkrc-2.0")) {
qDebug() << "checking for icon theme in gtkrc-2.0";
QSettings gtkFile(QDir::homePath() + "/.gtkrc-2.0", QSettings::IniFormat);
theme = gtkFile.value("gtk-icon-theme-name").toString().remove("\"");
} else {
qDebug() << "checking for icon theme in gtk-3.0";
QSettings gtkFile(QDir::homePath() + "/.config/gtk-3.0/settings.ini", QSettings::IniFormat);
theme = gtkFile.value("gtk-fallback-icon-theme").toString().remove("\"");
}
// fallback
if(theme.isNull()) {
qDebug() << "checking for icon theme in static fallback";
QStringList themes;
themes << QString("%1/../share/icons/Humanity").arg(qApp->applicationFilePath());
themes << "/usr/share/icons/Humanity" << "/usr/local/share/icons/Humanity";
themes << QString("%1/../share/icons/Adwaita").arg(qApp->applicationFilePath());
themes << "/usr/share/icons/Adwaita" << "/usr/local/share/icons/Adwaita";
themes << QString("%1/../share/icons/gnome").arg(qApp->applicationFilePath());
themes << "/usr/share/icons/gnome" << "/usr/local/share/icons/gnome";
themes << QString("%1/../share/icons/oxygen").arg(qApp->applicationFilePath());
themes << "/usr/share/icons/oxygen" << "/usr/local/share/icons/oxygen";
themes << QString("%1/../share/icons/hicolor").arg(qApp->applicationFilePath());
themes << QString("%1/../share/icons/Tango").arg(qApp->applicationFilePath());
themes << "/usr/share/icons/Tango" << "/usr/local/share/icons/Tango";
themes << "/usr/share/icons/hicolor" << "/usr/local/share/icons/hicolor";
for (int i=0;i<themes.size();++i) {
if (QFile::exists(themes.at(i))) {
theme = QString(themes.at(i)).split("/").takeLast();
break;
}
}
}
if (theme != "hicolor" && !theme.isEmpty()) {
qDebug() << "save icon theme for later use";
savePowerSettings("icon_theme", theme);
} else {
qDebug() << "No icons available!";
}
if(theme.isNull()) { theme = DEFAULT_THEME; }
if (!theme.isEmpty()) { savePowerSettings(CONF_ICON_THEME, theme); }
}
qDebug() << "Using icon theme" << theme;
QIcon::setThemeName(theme);
#ifdef BUNDLE_ICONS
if (theme != DEFAULT_THEME) { // validate theme
QIcon testTheme = QIcon::fromTheme(DEFAULT_AC_ICON);
if (testTheme.isNull()) {
qDebug() << "icon theme is broken, use failsafe!";
QIcon::setThemeName(DEFAULT_THEME);
savePowerSettings(CONF_ICON_THEME, DEFAULT_THEME);
}
}
#endif
}

QString Common::confFile()
Expand Down
92 changes: 86 additions & 6 deletions app/dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ Dialog::Dialog(QWidget *parent)
, lidActionBatteryLabel(0)
, batteryBacklightLabel(0)
, acBacklightLabel(0)
, backlightMouseWheel(0)
, suspendLockScreen(0)
, resumeLockScreen(0)
{
// setup dialog
setAttribute(Qt::WA_QuitOnClose, true);
Expand Down Expand Up @@ -410,9 +413,33 @@ Dialog::Dialog(QWidget *parent)
disableLidAction->setToolTip(tr("Disable lid action if an external monitor is connected"
" to your laptop."));

backlightMouseWheel = new QCheckBox(this);
backlightMouseWheel->setIcon(QIcon::fromTheme(DEFAULT_TRAY_ICON));
backlightMouseWheel->setText(tr("Adjust backlight in system tray"));
backlightMouseWheel->setToolTip(tr("Adjust the display backlight with the mouse wheel on the system tray icon."));

daemonContainerLayout->addWidget(showSystemTray);
daemonContainerLayout->addWidget(showNotifications);
daemonContainerLayout->addWidget(disableLidAction);
daemonContainerLayout->addWidget(backlightMouseWheel);

// screensaver
QGroupBox *ssContainer = new QGroupBox(this);
ssContainer->setTitle(tr("Screensaver"));
QVBoxLayout *ssContainerLayout = new QVBoxLayout(ssContainer);

suspendLockScreen = new QCheckBox(this);
suspendLockScreen->setIcon(QIcon::fromTheme(DEFAULT_LOCK_ICON));
suspendLockScreen->setText(tr("Lock screen on suspend"));
suspendLockScreen->setToolTip(tr("Lock the screen before suspending the computer"));

resumeLockScreen = new QCheckBox(this);
resumeLockScreen->setIcon(QIcon::fromTheme(DEFAULT_LOCK_ICON));
resumeLockScreen->setText(tr("Lock screen on resume"));
resumeLockScreen->setToolTip(tr("Lock the screen before resuming the computer."));

ssContainerLayout->addWidget(suspendLockScreen);
ssContainerLayout->addWidget(resumeLockScreen);

// notify
QGroupBox *notifyContainer = new QGroupBox(this);
Expand Down Expand Up @@ -563,6 +590,7 @@ Dialog::Dialog(QWidget *parent)
settingsLayout->addWidget(batteryContainer);
settingsLayout->addWidget(acContainer);
settingsLayout->addWidget(daemonContainer);
settingsLayout->addWidget(ssContainer);
settingsLayout->addWidget(notifyContainer);
settingsLayout->addWidget(advContainer);
settingsLayout->addStretch();
Expand Down Expand Up @@ -653,6 +681,12 @@ Dialog::Dialog(QWidget *parent)
this, SLOT(handleNotifyBattery(bool)));
connect(notifyOnAC, SIGNAL(toggled(bool)),
this, SLOT(handleNotifyAC(bool)));
connect(backlightMouseWheel, SIGNAL(toggled(bool)),
this, SLOT(handleBacklightMouseWheel(bool)));
connect(suspendLockScreen, SIGNAL(toggled(bool)),
this, SLOT(handleSuspendLockScreen(bool)));
connect(resumeLockScreen, SIGNAL(toggled(bool)),
this, SLOT(handleResumeLockScreen(bool)));
}

Dialog::~Dialog()
Expand Down Expand Up @@ -834,6 +868,18 @@ void Dialog::loadSettings()
}
notifyOnAC->setChecked(defaultNotifyOnAC);

bool defaultSuspendLockScreen = true;
if (Common::validPowerSettings(CONF_SUSPEND_LOCK_SCREEN)) {
defaultSuspendLockScreen = Common::loadPowerSettings(CONF_SUSPEND_LOCK_SCREEN).toBool();
}
suspendLockScreen->setChecked(defaultSuspendLockScreen);

bool defaultResumeLockScreen = false;
if (Common::validPowerSettings(CONF_RESUME_LOCK_SCREEN)) {
defaultResumeLockScreen = Common::loadPowerSettings(CONF_RESUME_LOCK_SCREEN).toBool();
}
resumeLockScreen->setChecked(defaultResumeLockScreen);

// power actions
bool canSuspend = man->CanSuspend();
bool canHibernate = man->CanHibernate() && Common::kernelCanResume();
Expand Down Expand Up @@ -901,6 +947,11 @@ void Dialog::loadSettings()
Common::loadPowerSettings(CONF_BACKLIGHT_AC_DISABLE_IF_HIGHER)
.toBool());
}
bool defaultBacklightMouseWheel = true;
if (Common::validPowerSettings(CONF_BACKLIGHT_MOUSE_WHEEL)) {
defaultBacklightMouseWheel = Common::loadPowerSettings(CONF_BACKLIGHT_MOUSE_WHEEL).toBool();
}
backlightMouseWheel->setChecked(defaultBacklightMouseWheel);

enableBacklight(hasBacklight);
enableLid(man->LidIsPresent());
Expand Down Expand Up @@ -962,6 +1013,12 @@ void Dialog::saveSettings()
notifyOnBattery->isChecked());
Common::savePowerSettings(CONF_NOTIFY_ON_AC,
notifyOnAC->isChecked());
Common::savePowerSettings(CONF_BACKLIGHT_MOUSE_WHEEL,
backlightMouseWheel->isChecked());
Common::savePowerSettings(CONF_SUSPEND_LOCK_SCREEN,
suspendLockScreen->isChecked());
Common::savePowerSettings(CONF_RESUME_LOCK_SCREEN,
resumeLockScreen->isChecked());
}

// set default action in combobox
Expand Down Expand Up @@ -1248,15 +1305,15 @@ void Dialog::checkDevices()
devicesProg[uid] = new QProgressBar(this);
devicesProg[uid]->setMinimum(0);
devicesProg[uid]->setMaximum(100);
devicesProg[uid]->setValue(i.value()->percentage);
devicesProg[uid]->setValue((int)i.value()->percentage);
deviceTree->setItemWidget(item, 1, devicesProg[uid]);
} else {
devicesProg[i.value()->path]->setValue(i.value()->percentage);
devicesProg[i.value()->path]->setValue((int)i.value()->percentage);
}
}

QIcon icon = QIcon::fromTheme(DEFAULT_AC_ICON);
if (left == 0 || !man->HasBattery()) {
if (left <1 || !man->HasBattery()) {
batteryIcon->setPixmap(icon.pixmap(QSize(48, 48)));
return;
}
Expand All @@ -1270,7 +1327,7 @@ void Dialog::checkDevices()
icon = QIcon::fromTheme(man->OnBattery()?DEFAULT_BATTERY_ICON_FULL:DEFAULT_BATTERY_ICON_FULL_AC);
} else {
icon = QIcon::fromTheme(man->OnBattery()?DEFAULT_BATTERY_ICON_FULL:DEFAULT_BATTERY_ICON_CHARGED);
if (left == 100 && !man->OnBattery()) {
if (left > 99 && !man->OnBattery()) {
icon = QIcon::fromTheme(DEFAULT_AC_ICON);
}
}
Expand Down Expand Up @@ -1373,15 +1430,15 @@ void Dialog::getInhibitors()
QTreeWidgetItem *item = new QTreeWidgetItem(inhibitorTree);
item->setText(0, inhibitor);
item->setFlags(Qt::ItemIsEnabled);
item->setIcon(0, QIcon::fromTheme("application-x-executable"));
item->setIcon(0, QIcon::fromTheme(DEFAULT_TRAY_ICON));
}
for (int i=0;i<pmList.size();++i) {
QString inhibitor = pmList.at(i);
if (inhibitor.isEmpty()) { continue; }
QTreeWidgetItem *item = new QTreeWidgetItem(inhibitorTree);
item->setText(0, inhibitor);
item->setFlags(Qt::ItemIsEnabled);
item->setIcon(0, QIcon::fromTheme("application-x-executable"));
item->setIcon(0, QIcon::fromTheme(DEFAULT_TRAY_ICON));
}
}

Expand All @@ -1396,6 +1453,7 @@ void Dialog::enableBacklight(bool enabled)
backlightACHigherCheck->setEnabled(enabled);
batteryBacklightLabel->setEnabled(enabled);
acBacklightLabel->setEnabled(enabled);
backlightMouseWheel->setEnabled(enabled);
}

void Dialog::showAboutDialog()
Expand All @@ -1421,6 +1479,13 @@ void Dialog::showAboutDialog()
.arg(tr("file for full details."))
.arg(tr("Available on"))
.arg(tr("and")));
#ifdef BUNDLE_ICONS
about.setDetailedText(tr("Includes icons from the GNOME project <http://www.gnome.org>.\n\n"
"This work is licenced under the Creative Commons Attribution-Share Alike 3.0 "
"United States License.\n\nTo view a copy of this licence, visit "
"http://creativecommons.org/licenses/by-sa/3.0/ or send a letter to Creative "
"Commons, 171 Second Street, Suite 300, San Francisco, California 94105, USA."));
#endif
about.exec();
}

Expand Down Expand Up @@ -1452,3 +1517,18 @@ void Dialog::enableLid(bool enabled)
lidActionBatteryLabel->setEnabled(enabled);
disableLidAction->setEnabled(enabled);
}

void Dialog::handleBacklightMouseWheel(bool triggered)
{
Common::savePowerSettings(CONF_BACKLIGHT_MOUSE_WHEEL, triggered);
}

void Dialog::handleSuspendLockScreen(bool triggered)
{
Common::savePowerSettings(CONF_SUSPEND_LOCK_SCREEN, triggered);
}

void Dialog::handleResumeLockScreen(bool triggered)
{
Common::savePowerSettings(CONF_RESUME_LOCK_SCREEN, triggered);
}
6 changes: 6 additions & 0 deletions app/dialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ class Dialog : public QDialog
QLabel *lidActionBatteryLabel;
QLabel *batteryBacklightLabel;
QLabel *acBacklightLabel;
QCheckBox *backlightMouseWheel;
QCheckBox *suspendLockScreen;
QCheckBox *resumeLockScreen;

private slots:
void populate();
Expand Down Expand Up @@ -158,6 +161,9 @@ private slots:
void handleNotifyBattery(bool triggered);
void handleNotifyAC(bool triggered);
void enableLid(bool enabled);
void handleBacklightMouseWheel(bool triggered);
void handleSuspendLockScreen(bool triggered);
void handleResumeLockScreen(bool triggered);
};

#endif // DIALOG_H
Loading

0 comments on commit a50621a

Please sign in to comment.