Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for the battery widget on BSD systems (via upower) #2147

Merged
merged 1 commit into from
Jun 8, 2019
Merged
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
4 changes: 2 additions & 2 deletions build/depends.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ def configure(self, build, conf):
build.env.Append(LINKFLAGS='-framework IOKit')

class UPower(Dependence):
"""UPower is used to get battery measurements on Linux."""
"""UPower is used to get battery measurements on Linux and BSD."""
def configure(self, build, conf):
if not build.platform_is_linux:
if not build.platform_is_linux and not build.platform_is_bsd:
return
build.env.ParseConfig(
'pkg-config upower-glib --silence-errors --cflags --libs')
Expand Down
2 changes: 1 addition & 1 deletion build/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -1179,7 +1179,7 @@ def sources(self, build):
return ["src/util/battery/batterywindows.cpp"]
elif build.platform_is_osx:
return ["src/util/battery/batterymac.cpp"]
elif build.platform_is_linux:
elif build.platform_is_linux or build.platform_is_bsd:
return ["src/util/battery/batterylinux.cpp"]
else:
raise Exception('Battery support is not implemented for the target platform.')
Expand Down
12 changes: 6 additions & 6 deletions src/util/battery/battery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
// Do not include platform-specific battery implementation unless we are built
// with battery support (__BATTERY__).
#ifdef __BATTERY__
#ifdef Q_OS_LINUX
#include "util/battery/batterylinux.h"
#elif defined(Q_OS_WIN)
#if defined(Q_OS_WIN)
#include "util/battery/batterywindows.h"
#elif defined(Q_OS_MAC)
#include "util/battery/batterymac.h"
#else
#include "util/battery/batterylinux.h"
#endif
#endif
#include "util/math.h"
Expand All @@ -31,12 +31,12 @@ Battery::~Battery() {

Battery* Battery::getBattery(QObject* parent) {
#ifdef __BATTERY__
#ifdef Q_OS_LINUX
return new BatteryLinux(parent);
#elif defined(Q_OS_WIN)
#if defined(Q_OS_WIN)
return new BatteryWindows(parent);
#elif defined(Q_OS_MAC)
return new BatteryMac(parent);
#else
return new BatteryLinux(parent);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made BatteryLinux the default here because otherwise we'd have to enumerate
Q_OS_LINUX, Q_OS_FREEBSD, Q_OS_OPENBSD and so on..

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with this pragmatic approach. If this should ever fail in the future we could add a more fine-grained distinction for the "other" OSes.

#endif
#else
Q_UNUSED(parent);
Expand Down