diff --git a/src/powerkit_app.cpp b/src/powerkit_app.cpp index 3bd9e6e..0148269 100644 --- a/src/powerkit_app.cpp +++ b/src/powerkit_app.cpp @@ -79,7 +79,7 @@ App::App(QObject *parent) this, SLOT(handleTrayWheel(TrayIcon::WheelAction))); - // setup manager + // setup org.freedesktop.PowerKit.Manager man = new Manager(this); connect(man, SIGNAL(UpdatedDevices()), @@ -191,7 +191,6 @@ App::App(QObject *parent) tray->setIcon(QIcon::fromTheme(DEFAULT_AC_ICON)); } - // load settings and register service loadSettings(); registerService(); @@ -221,7 +220,6 @@ App::~App() { } -// what to do when user clicks systray void App::trayActivated(QSystemTrayIcon::ActivationReason reason) { Q_UNUSED(reason) @@ -231,12 +229,7 @@ void App::trayActivated(QSystemTrayIcon::ActivationReason reason) void App::checkDevices() { - // show/hide tray - if (tray->isSystemTrayAvailable() && - !tray->isVisible() && - showTray) { tray->show(); } - if (!showTray && - tray->isVisible()) { tray->hide(); } + updateTrayVisibility(); double batteryLeft = man->BatteryLeft(); qDebug() << "battery at" << batteryLeft; @@ -653,15 +646,20 @@ void App::updateToolTip() } else { tray->setToolTip(tr("On AC")); } } -// timeout, check if idle -// timeouts and xss must be >= user value and service has to be empty before suspend -void App::timeout() +void App::updateTrayVisibility() { if (!showTray && tray->isVisible()) { tray->hide(); } if (tray->isSystemTrayAvailable() && !tray->isVisible() && showTray) { tray->show(); } +} + +// timeout, check if idle +// timeouts and xss must be >= user value and service has to be empty before suspend +void App::timeout() +{ + updateTrayVisibility(); int uIdle = ss->GetSessionIdleTime() / 60; diff --git a/src/powerkit_app.h b/src/powerkit_app.h index 9df97d8..423d207 100644 --- a/src/powerkit_app.h +++ b/src/powerkit_app.h @@ -107,6 +107,7 @@ namespace PowerKit void handleCritical(double left); void drawBattery(double left); void updateToolTip(); + void updateTrayVisibility(); void timeout(); void resetTimer(); void setInternalMonitor(); diff --git a/src/powerkit_manager.cpp b/src/powerkit_manager.cpp index 6910dcc..2248262 100644 --- a/src/powerkit_manager.cpp +++ b/src/powerkit_manager.cpp @@ -280,34 +280,46 @@ void Manager::deviceChanged() void Manager::propertiesChanged() { - bool isLidClosed = LidIsClosed(); - bool isOnBattery = OnBattery(); + bool closed = LidIsClosed(); + bool battery = OnBattery(); + bool docked = IsDocked(); qDebug() << "properties changed:" - << "lid closed?" << wasLidClosed << isLidClosed - << "on battery?" << wasOnBattery << isOnBattery; + << "lid closed?" << wasLidClosed << closed + << "on battery?" << wasOnBattery << battery + << "is docked?" << wasDocked << docked; - if (wasLidClosed != isLidClosed) { - if (!wasLidClosed && isLidClosed) { + if (wasLidClosed != closed) { + if (!wasLidClosed && closed) { qDebug() << "lid changed to closed"; emit LidClosed(); - } else if (wasLidClosed && !isLidClosed) { + } else if (wasLidClosed && !closed) { qDebug() << "lid changed to open"; emit LidOpened(); } + emit isLidClosedChanged(closed); + qDebug() << "is lid closed changed" << closed; } - wasLidClosed = isLidClosed; + wasLidClosed = closed; - if (wasOnBattery != isOnBattery) { - if (!wasOnBattery && isOnBattery) { + if (wasOnBattery != battery) { + if (!wasOnBattery && battery) { qDebug() << "switched to battery power"; emit SwitchedToBattery(); - } else if (wasOnBattery && !isOnBattery) { + } else if (wasOnBattery && !battery) { qDebug() << "switched to ac power"; emit SwitchedToAC(); } + qDebug() << "is on battery changed" << battery; + emit isOnBatteryChanged(battery); } - wasOnBattery = isOnBattery; + wasOnBattery = battery; + + if (wasDocked != docked) { + qDebug() << "is docked changed" << docked; + emit isDockedChanged(docked); + } + wasDocked = docked; deviceChanged(); } diff --git a/src/powerkit_manager.h b/src/powerkit_manager.h index a56382d..af1cab3 100644 --- a/src/powerkit_manager.h +++ b/src/powerkit_manager.h @@ -64,6 +64,11 @@ namespace PowerKit void Error(const QString &message); void Warning(const QString &message); + void isDockedChanged(bool isDocked); + void isLidClosedChanged(bool isClosed); + void isOnBatteryChanged(bool onBattery); + + private slots: bool canLogind(const QString &method); const QDBusMessage callLogind(const QString &method);