Bump to 1.3.11-2
[gc-dialer] / dialcentral / alarm_handler.py
index bf14f82..ce19e58 100644 (file)
@@ -10,9 +10,9 @@ import logging
 
 import dbus
 
-import util.qt_compat as qt_compat
+import dialcentral.util.qt_compat as qt_compat
 QtCore = qt_compat.QtCore
-from util import linux as linux_utils
+import dialcentral.util.linux as linux_utils
 
 
 _FREMANTLE_ALARM = "Fremantle"
@@ -98,7 +98,7 @@ class _FremantleAlarmHandler(object):
        _INVALID_COOKIE = -1
        _REPEAT_FOREVER = -1
        _TITLE = "Dialcentral Notifications"
-       _LAUNCHER = os.path.abspath(os.path.join(os.path.dirname(__file__), "alarm_notify.py"))
+       _LAUNCHER = "python %s" % os.path.abspath(os.path.join(os.path.dirname(__file__), "alarm_notify.py"))
 
        def __init__(self):
                self._recurrence = 5
@@ -106,6 +106,10 @@ class _FremantleAlarmHandler(object):
                self._alarmCookie = self._INVALID_COOKIE
                self._launcher = self._LAUNCHER
 
+       @property
+       def alarmCookie(self):
+               return self._alarmCookie
+
        def load_settings(self, config, sectionName):
                try:
                        self._recurrence = config.getint(sectionName, "recurrence")
@@ -180,7 +184,7 @@ class _DiabloAlarmHandler(object):
 
        _INVALID_COOKIE = -1
        _TITLE = "Dialcentral Notifications"
-       _LAUNCHER = os.path.abspath(os.path.join(os.path.dirname(__file__), "alarm_notify.py"))
+       _LAUNCHER = "python %s" % os.path.abspath(os.path.join(os.path.dirname(__file__), "alarm_notify.py"))
        _REPEAT_FOREVER = -1
 
        def __init__(self):
@@ -191,6 +195,10 @@ class _DiabloAlarmHandler(object):
                self._alarmCookie = self._INVALID_COOKIE
                self._launcher = self._LAUNCHER
 
+       @property
+       def alarmCookie(self):
+               return self._alarmCookie
+
        def load_settings(self, config, sectionName):
                try:
                        self._recurrence = config.getint(sectionName, "recurrence")
@@ -276,6 +284,10 @@ class _ApplicationAlarmHandler(object):
                self._timer.setSingleShot(False)
                self._timer.setInterval(5 * self._MIN_TO_MS_FACTORY)
 
+       @property
+       def alarmCookie(self):
+               return 0
+
        def load_settings(self, config, sectionName):
                try:
                        self._timer.setInterval(config.getint(sectionName, "recurrence") * self._MIN_TO_MS_FACTORY)
@@ -314,6 +326,10 @@ class _NoneAlarmHandler(object):
                self._enabled = False
                self._recurrence = 5
 
+       @property
+       def alarmCookie(self):
+               return 0
+
        def load_settings(self, config, sectionName):
                try:
                        self._recurrence = config.getint(sectionName, "recurrence")
@@ -415,15 +431,19 @@ class AlarmHandler(object):
        def isEnabled(self):
                return self._currentAlarmType != self.ALARM_NONE
 
+       @property
+       def alarmCookie(self):
+               return self._alarms[self._currentAlarmType].alarmCookie
+
        def _init_alarm(self, t):
                if t not in self._alarms and self.ALARM_FACTORY[t] is not None:
                        self._alarms[t] = self.ALARM_FACTORY[t]()
 
 
-def main():
+def run():
        logFormat = '(%(relativeCreated)5d) %(levelname)-5s %(threadName)s.%(name)s.%(funcName)s: %(message)s'
        logging.basicConfig(level=logging.DEBUG, format=logFormat)
-       import constants
+       from dialcentral import constants
        try:
                import optparse
        except ImportError:
@@ -445,14 +465,19 @@ def main():
 
        if commandOptions.display:
                print "Alarm (%s) is %s for every %d minutes" % (
-                       alarmHandler._alarmCookie,
+                       alarmHandler.alarmCookie,
                        "enabled" if alarmHandler.isEnabled else "disabled",
                        alarmHandler.recurrence,
                )
        else:
                isEnabled = commandOptions.enabled
                recurrence = commandOptions.recurrence
-               alarmHandler.apply_settings(isEnabled, recurrence)
+
+               if alarmHandler.backgroundNotificationsSupported:
+                       enableType = AlarmHandler.ALARM_BACKGROUND
+               else:
+                       enableType = AlarmHandler.ALARM_APPLICATION
+               alarmHandler.apply_settings(enableType if isEnabled else AlarmHandler.ALARM_NONE, recurrence)
 
                alarmHandler.save_settings(config, "alarm")
                with open(settingsPath, "wb") as configFile:
@@ -460,4 +485,4 @@ def main():
 
 
 if __name__ == "__main__":
-       main()
+       run()