Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/xopower.py
diff options
context:
space:
mode:
authorJames Simmons <jim@localhost.simmons>2009-03-15 19:50:15 (GMT)
committer James Simmons <jim@localhost.simmons>2009-03-15 19:50:15 (GMT)
commita0b992a9fc1a2b5bbb061dac399c86d14db328ec (patch)
treee3c5c7c11f840440e504acb14bc644f5ffc4d713 /xopower.py
parentc8bc9f77788327db3a1b4782b09d0159b5cea6c8 (diff)
new file: xopower.py
Try to make the power management code a reuseable routine. Replace file sharing code with the latest code from the core Read activity.
Diffstat (limited to 'xopower.py')
-rw-r--r--xopower.py75
1 files changed, 75 insertions, 0 deletions
diff --git a/xopower.py b/xopower.py
new file mode 100644
index 0000000..171d14f
--- /dev/null
+++ b/xopower.py
@@ -0,0 +1,75 @@
+#! /usr/bin/env python
+
+# Copyright (C) 2009 James D. Simmons
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+_HARDWARE_MANAGER_INTERFACE = 'org.laptop.HardwareManager'
+_HARDWARE_MANAGER_SERVICE = 'org.laptop.HardwareManager'
+_HARDWARE_MANAGER_OBJECT_PATH = '/org/laptop/HardwareManager'
+
+_logger = logging.getLogger('read-etexts-activity')
+
+# start with sleep off
+sleep_inhibit = True
+
+def setup_idle_timeout():
+ # Set up for idle suspend
+ _idle_timer = 0
+ _service = None
+
+ fname = os.path.join('/etc', 'inhibit-ebook-sleep')
+ if not os.path.exists(fname):
+ try:
+ bus = dbus.SystemBus()
+ proxy = bus.get_object(_HARDWARE_MANAGER_SERVICE,
+ _HARDWARE_MANAGER_OBJECT_PATH)
+ _service = dbus.Interface(proxy, _HARDWARE_MANAGER_INTERFACE)
+ logging.debug('Suspend on idle enabled')
+ except dbus.DBusException, e:
+ _logger.info('Hardware manager service not found, no idle suspend.')
+ else:
+ logging.debug('Suspend on idle disabled')
+
+def _now_active_cb(widget, pspec):
+ if props.active:
+ # Now active, start initial suspend timeout
+ if _idle_timer > 0:
+ gobject.source_remove(_idle_timer)
+ _idle_timer = gobject.timeout_add(15000, _suspend_cb)
+ sleep_inhibit = False
+ else:
+ # Now inactive
+ sleep_inhibit = True
+
+def turn_on_sleep_timer():
+ sleep_inhibit = False
+ reset_sleep_timer()
+
+def turn_off_sleep_timer():
+ sleep_inhibit = True
+
+def reset_sleep_timer():
+ if _idle_timer > 0:
+ gobject.source_remove(_idle_timer)
+ _idle_timer = gobject.timeout_add(5000, _suspend_cb)
+
+def _suspend_cb():
+ # If the machine has been idle for 5 seconds, suspend
+ _idle_timer = 0
+ if not sleep_inhibit:
+ _service.set_kernel_suspend()
+ return False
+