Skip to content
Browse files

Autosuspend: Perform a first-run check for a battery

  • Loading branch information...
1 parent cc1f6b9 commit 565db0c18b762e421139e1699eba0e2e967eb8b7 @amoskvin amoskvin committed Dec 25, 2012
View
1 .gitignore
@@ -15,6 +15,7 @@ razorqt-appswitcher/razor-appswitcher
razorqt-desktop/razor-desktop
razorqt-panel/panel/razor-panel
*~
+*.autosave
CMakeLists.txt.user*
/build
nbproject/
View
1 razorqt-autosuspend/config/constants.h
@@ -33,6 +33,7 @@
#define POWERLOWLEVEL_KEY "powerLowLevel"
#define SHOWTRAYICON_KEY "showTrayIcon"
#define USETHEMEICONS_KEY "useThemeIcons"
+#define FIRSTRUNCHECK_KEY "performFirstRunCheck"
enum
{
View
4 razorqt-autosuspend/src/CMakeLists.txt
@@ -39,6 +39,9 @@ set(DESKTOP_FILES_IN
# razor-autosuspend.desktop.in
)
+set(CONFIG_FILES
+ razor-autosuspend.conf
+ )
QT4_WRAP_CPP(MOCS ${razor-autosuspend_MOCS})
@@ -71,3 +74,4 @@ target_link_libraries ( razor-autosuspend razorqt ${QT_QTCORE_LIBRARY} ${QT_QTG
install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION bin)
install(FILES ${DESKTOP_FILES} DESTINATION share/applications)
install(FILES ${ICON_FILES} DESTINATION share/icons/hicolor/scalable/apps)
+install(FILES ${CONFIG_FILES} DESTINATION ${RAZOR_ETC_XDG_DIRECTORY}/razor)
View
12 razorqt-autosuspend/src/battery.cpp
@@ -32,7 +32,6 @@
#include <QDebug>
#include <QMetaObject>
#include <QMetaProperty>
-#include <razorqt/razornotification.h>
#include <razorqt/razorsettings.h>
#include "../config/constants.h"
@@ -68,12 +67,6 @@ Battery::Battery(QObject* parent)
delete device;
}
}
- if (mUPowerBatteryDeviceInterface == 0)
- {
- RazorNotification::notify(tr("No battery!"),
- tr("Razor autosuspend could not find data about any battery - actions on power low will not work"),
- "razor-autosuspend");
- }
}
Battery::~Battery()
@@ -110,6 +103,11 @@ bool Battery::discharging()
return 2 == state();
}
+bool Battery::haveBattery()
+{
+ return mUPowerBatteryDeviceInterface != 0;
+}
+
uint Battery::state()
{
return mProperties.value("State").toUInt();
View
1 razorqt-autosuspend/src/battery.h
@@ -45,6 +45,7 @@ class Battery : public QObject
double chargeLevel();
bool powerLow();
bool discharging();
+ bool haveBattery();
uint state();
QString stateAsString();
QVariantMap properties();
View
2 razorqt-autosuspend/src/razor-autosuspend.conf
@@ -0,0 +1,2 @@
+[General]
+performFirstRunCheck=true
View
34 razorqt-autosuspend/src/razorautosuspend.cpp
@@ -24,8 +24,10 @@
* Boston, MA 02110-1301 USA
*
* END_COMMON_COPYRIGHT_HEADER */
-#include <QDebug>
-#include <QTimerEvent>
+#include <QtCore/QDebug>
+#include <QtCore/QTimer>
+#include <QtCore/QCoreApplication>
+#include <razorqt/razorautostartentry.h>
#include "razorautosuspend.h"
#include "../config/constants.h"
@@ -36,10 +38,36 @@ RazorAutosuspendd::RazorAutosuspendd(QObject *parent) :
mActionTime(),
mSettings("razor-autosuspend")
{
+ bool performFirstRunCheck = mSettings.value(FIRSTRUNCHECK_KEY, false).toBool();
+ if (performFirstRunCheck)
+ {
+ mSettings.setValue(FIRSTRUNCHECK_KEY, false);
+ }
+
+ mBattery = new Battery(this);
+ if (!mBattery->haveBattery())
+ {
+ if (performFirstRunCheck)
+ {
+ qWarning() << "No battery detected - disabling Razor Autosuspend";
+ RazorAutostartEntry autostartEntry("razor-autosuspend.desktop");
+ autostartEntry.setEnabled(false);
+ autostartEntry.commit();
+
+ // We can't quit if the event loop did not start yet
+ QTimer::singleShot(0, qApp, SLOT(quit()));
+ return;
+ }
+
+ RazorNotification::notify(tr("No battery!"),
+ tr("Razor autosuspend could not find data about any battery - actions on power low will not work"),
+ "razor-autosuspend");
+ }
+
mRazorNotification.setIcon("razor-autosuspend");
mRazorNotification.setUrgencyHint(RazorNotification::UrgencyCritical);
mRazorNotification.setTimeout(2000);
- mBattery = new Battery(this);
+
new TrayIcon(mBattery, this);
connect(&mLid, SIGNAL(changed(bool)), this, SLOT(lidChanged(bool)));
View
1 razorqt-resources/autostart/razor-autosuspend.desktop.in
@@ -5,7 +5,6 @@ Name=Razor Autosuspend
TryExec=razor-autosuspend
Exec=razor-autosuspend
OnlyShowIn=Razor;
-Hidden=true
X-Razor-Need-Tray=true
X-Razor-Module=true

0 comments on commit 565db0c

Please sign in to comment.
Something went wrong with that request. Please try again.