Permalink
Browse files

razor-autosuspend watch for changes in settings

  • Loading branch information...
1 parent 2e67206 commit 128a5f20651ad2d79997413bb0d4601495e04745 @surlykke surlykke committed Oct 6, 2012
Showing with 12 additions and 13 deletions.
  1. +10 −12 razorqt-autosuspend/src/razorautosuspend.cpp
  2. +2 −1 razorqt-autosuspend/src/razorautosuspend.h
View
22 razorqt-autosuspend/src/razorautosuspend.cpp
@@ -33,15 +33,17 @@
RazorAutosuspendd::RazorAutosuspendd(QObject *parent) :
QObject(parent),
razorNotification(tr("Power low"), this),
- actionTime()
+ actionTime(),
+ m_Settings("razor-autosuspend")
{
razorNotification.setIcon("razor-autosuspend");
razorNotification.setUrgencyHint(RazorNotification::UrgencyCritical);
razorNotification.setTimeout(2000);
trayIcon.setStatus(battery.chargeLevel(), battery.onBattery(), battery.properties());
trayIcon.show();
connect(&lid, SIGNAL(changed(bool)), this, SLOT(lidChanged(bool)));
- connect(&battery, SIGNAL(batteryChanged()), this, SLOT(batteryChanged()));
+ connect(&battery, SIGNAL(somethingChanged()), this, SLOT(somethingChanged()));
@amoskvin
Razor-qt member
amoskvin added a line comment Oct 6, 2012

I think you did this in a rush, because Battery doesn't have a somethingChanged() signal.

Also, it doesn't check the settings to hide the icon on startup.

I committed a fix: 9f235d7

@surlykke
Razor-qt member
surlykke added a line comment Oct 6, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ connect(&m_Settings, SIGNAL(settingsChanged()), this, SLOT(somethingChanged()));
}
RazorAutosuspendd::~RazorAutosuspendd()
@@ -50,26 +52,22 @@ RazorAutosuspendd::~RazorAutosuspendd()
void RazorAutosuspendd::lidChanged(bool closed)
{
- RazorSettings settings("razor-autosuspend");
qDebug() << "LidChanged: " << closed;
- qDebug() << "Action: " << settings.value(LIDCLOSEDACTION_KEY).toInt();
+ qDebug() << "Action: " << m_Settings.value(LIDCLOSEDACTION_KEY).toInt();
if (closed)
{
- doAction(settings.value(LIDCLOSEDACTION_KEY).toInt());
+ doAction(m_Settings.value(LIDCLOSEDACTION_KEY).toInt());
}
}
-void RazorAutosuspendd::batteryChanged()
+void RazorAutosuspendd::somethingChanged()
{
qDebug() << "onBattery: " << battery.onBattery() <<
"chargeLevel:" << battery.chargeLevel() <<
"powerlow:" << battery.powerLow() <<
"actionTime:" << actionTime;
- RazorSettings settings("razor-autosuspend");
- qDebug() << "settingspath: " << settings.fileName() << ", Lidaction: " << settings.value(LIDCLOSEDACTION_KEY);
-
- if (settings.value(SHOWTRAYICON_KEY, true).toBool())
+ if (m_Settings.value(SHOWTRAYICON_KEY, true).toBool())
{
trayIcon.show();
}
@@ -82,7 +80,7 @@ void RazorAutosuspendd::batteryChanged()
if (battery.powerLow() && actionTime.isNull() && powerLowAction() > 0)
{
- int warningTimeMsecs = settings.value(POWERLOWWARNING_KEY, 30).toInt()*1000;
+ int warningTimeMsecs = m_Settings.value(POWERLOWWARNING_KEY, 30).toInt()*1000;
actionTime = QTime::currentTime().addMSecs(warningTimeMsecs);
startTimer(100);
// From here everything is handled by timerEvent below
@@ -142,6 +140,6 @@ void RazorAutosuspendd::doAction(int action)
int RazorAutosuspendd::powerLowAction()
{
- return RazorSettings("razor-autosuspend").value(POWERLOWACTION_KEY).toInt();
+ return m_Settings.value(POWERLOWACTION_KEY).toInt();
}
View
3 razorqt-autosuspend/src/razorautosuspend.h
@@ -48,7 +48,7 @@ class RazorAutosuspendd : public QObject
private slots:
void lidChanged(bool closed);
- void batteryChanged();
+ void somethingChanged();
private:
void doAction(int action);
@@ -60,6 +60,7 @@ private slots:
RazorNotification razorNotification;
QTime actionTime;
TrayIcon trayIcon;
+ RazorSettings m_Settings;
};
#endif // RAZORAUTOSUSPENDD_H

0 comments on commit 128a5f2

Please sign in to comment.