+
#include "trayicon.h"
+#include "batteryhelper.h"
#include "../config/powermanagementsettings.h"
-TrayIcon::TrayIcon(Battery *battery, QObject *parent) : QSystemTrayIcon(parent), mIconProducer(battery), mContextMenu()
+TrayIcon::TrayIcon(Solid::Battery *battery, QObject *parent)
+ : QSystemTrayIcon(parent),
+ mBattery(battery),
+ mIconProducer(battery),
+ mContextMenu()
{
- connect(battery, SIGNAL(summaryChanged(QString)), this, SLOT(updateTooltip(QString)));
- updateTooltip(battery->summary);
+ connect(mBattery, &Solid::Battery::chargePercentChanged, this, &TrayIcon::updateTooltip);
+ connect(mBattery, &Solid::Battery::chargeStateChanged, this, &TrayIcon::updateTooltip);
+ updateTooltip();
connect(&mIconProducer, SIGNAL(iconChanged()), this, SLOT(iconChanged()));
iconChanged();
- connect(this, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), SLOT(onActivated(QSystemTrayIcon::ActivationReason)));
+ connect(this, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
+ SLOT(onActivated(QSystemTrayIcon::ActivationReason)));
- mContextMenu.addAction(tr("Configure"), this, SLOT(onConfigureTriggered()));
- mContextMenu.addAction(tr("About"), this, SLOT(onAboutTriggered()));
- mContextMenu.addAction(tr("Disable icon"), this, SLOT(onDisableIconTriggered()));
+ mContextMenu.addAction(XdgIcon::fromTheme(QStringLiteral("configure")), tr("Configure"),
+ this, SLOT(onConfigureTriggered()));
+ mContextMenu.addAction(XdgIcon::fromTheme(QStringLiteral("help-about")), tr("About"),
+ this, SLOT(onAboutTriggered()));
+ mContextMenu.addAction(XdgIcon::fromTheme(QStringLiteral("edit-delete")), tr("Disable icon"),
+ this, SLOT(onDisableIconTriggered()));
setContextMenu(&mContextMenu);
}
-TrayIcon::~TrayIcon() {}
+TrayIcon::~TrayIcon()
+{
+}
void TrayIcon::iconChanged()
{
setIcon(mIconProducer.mIcon);
}
-void TrayIcon::updateTooltip(QString newTooltip)
+void TrayIcon::updateTooltip()
{
- setToolTip(newTooltip);
+ QString tooltip = BatteryHelper::stateToString(mBattery->chargeState());
+ tooltip += QString(" (%1 %)").arg(mBattery->chargePercent());
+ setToolTip(tooltip);
}
void TrayIcon::onConfigureTriggered()
@@ -70,8 +90,8 @@ void TrayIcon::onAboutTriggered()
QMessageBox::about(0,
tr("About"),
tr( ""
- " LXQt Powermanagement
"
- " - Powermanagement for the LXQt Desktop Environment"
+ " LXQt Power Management
"
+ " - Power Management for the LXQt Desktop Environment"
"
"
""
" Authors:
"
diff --git a/src/trayicon.h b/src/trayicon.h
index b9050af..f00c70e 100644
--- a/src/trayicon.h
+++ b/src/trayicon.h
@@ -30,8 +30,8 @@
#include
#include
+#include
-#include "battery.h"
#include "iconproducer.h"
#include "../config/powermanagementsettings.h"
@@ -40,7 +40,7 @@ class TrayIcon : public QSystemTrayIcon
Q_OBJECT
public:
- TrayIcon(Battery *battery, QObject *parent = 0);
+ TrayIcon(Solid::Battery *battery, QObject *parent = 0);
~TrayIcon();
signals:
@@ -48,7 +48,7 @@ signals:
public slots:
void iconChanged();
- void updateTooltip(QString newTooltip);
+ void updateTooltip();
private slots:
void onConfigureTriggered();
@@ -57,6 +57,7 @@ private slots:
void onActivated(QSystemTrayIcon::ActivationReason reason);
private:
+ Solid::Battery *mBattery;
IconProducer mIconProducer;
QMenu mContextMenu;
};
diff --git a/src/watcher.cpp b/src/watcher.cpp
index 2bbb240..217399e 100644
--- a/src/watcher.cpp
+++ b/src/watcher.cpp
@@ -24,13 +24,14 @@
* END_COMMON_COPYRIGHT_HEADER */
#include
-
#include "../config/powermanagementsettings.h"
#include "watcher.h"
Watcher::Watcher(QObject *parent) :
- QObject(parent)
+ QObject(parent),
+ mScreenSaver(this)
{
+ connect(&mScreenSaver, SIGNAL(done()), &mLoop, SLOT(quit()));
}
Watcher::~Watcher()
@@ -39,9 +40,14 @@ Watcher::~Watcher()
void Watcher::doAction(int action)
{
- if (action > -1)
- {
- mPower.doAction((LxQt::Power::Action) action);
+ // if (action == -1) { }
+ if (action == -2)
+ {
+ mScreenSaver.lockScreen();
+ mLoop.exec();
}
-}
+ else if (action >= 0)
+ mPower.doAction((LxQt::Power::Action) action);
+ emit done();
+}
diff --git a/src/watcher.h b/src/watcher.h
index 2f9f36d..1cb58c0 100644
--- a/src/watcher.h
+++ b/src/watcher.h
@@ -1,12 +1,13 @@
#ifndef WATCHER_H
-#define WATCHER_H
+#define WATCHER_H
#include
+#include
#include
+#include
class Watcher : public QObject
{
-
Q_OBJECT
public:
@@ -16,10 +17,13 @@ public:
protected:
void doAction(int action);
+signals:
+ void done();
+
private:
LxQt::Power mPower;
-
+ LxQt::ScreenSaver mScreenSaver;
+ QEventLoop mLoop;
};
-#endif /* WATCHER_H */
-
+#endif // WATCHER_H