Fix build with gcc 4.7
[cadence.git] / src / cadence-unity-support
blobcef2e94e75758317825eae4999a57c8583724296
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
4 # Imports (Global)
5 import dbus, os, signal, sys
6 from PyQt4.QtCore import QCoreApplication, QObject
8 # DBus
9 class DBus(object):
10 __slots__ = [
11 'bus',
12 'jack'
14 DBus = DBus()
15 DBus.bus = None
16 DBus.jack = None
18 def quit_(sig=0, frame=0):
19 app.exit(1)
21 # Main Application
22 class CadenceUnityApp(QObject):
23 def __init__(self, parent=None):
24 super(CadenceUnityApp, self).__init__(parent)
26 self._load = None
27 self._xruns = None
29 self.TIMER_DBUS = self.startTimer(5000)
30 self.TIMER_LAUNCHER = self.startTimer(1000)
32 self.timer_dbus_check()
33 self.timer_launcher_check()
35 def timer_dbus_check(self):
36 if not DBus.jack:
37 self.refresh_dbus()
39 def timer_launcher_check(self):
40 load = self.jack_get_load()
41 xruns = self.jack_get_xruns()
43 if (load != self._load):
44 if (load != None):
45 launcher.set_property("progress", load/100)
46 launcher.set_property("progress_visible", True)
47 else:
48 launcher.set_property("progress", 0.0)
49 launcher.set_property("progress_visible", False)
51 if (xruns != self._xruns):
52 if (xruns != None):
53 launcher.set_property("count", xruns)
54 launcher.set_property("count_visible", True)
55 else:
56 launcher.set_property("count", 0)
57 launcher.set_property("count_visible", False)
59 self._load = load
60 self._xruns = xruns
62 def refresh_dbus(self):
63 DBus.bus = dbus.SessionBus()
65 try:
66 DBus.jack = DBus.bus.get_object("org.jackaudio.service", "/org/jackaudio/Controller")
67 except:
68 DBus.jack = None
70 def jack_get_load(self):
71 if (DBus.jack):
72 try:
73 return DBus.jack.GetLoad()
74 except:
75 DBus.jack = None
76 return None
77 else:
78 return None
80 def jack_get_xruns(self):
81 if (DBus.jack):
82 try:
83 return DBus.jack.GetXruns()
84 except:
85 DBus.jack = None
86 return None
87 else:
88 return None
90 def timerEvent(self, event):
91 if (event.timerId() == self.TIMER_DBUS):
92 self.timer_dbus_check()
93 elif (event.timerId() == self.TIMER_LAUNCHER):
94 self.timer_launcher_check()
95 return QObject.timerEvent(self, event)
98 #--------------- main ------------------
99 if __name__ == '__main__':
101 # Imports (Unity)
102 from gi.repository import Unity
104 # App initialization
105 app = QCoreApplication(sys.argv)
106 app.setApplicationName("Cadence-Unity-Support")
107 app.setApplicationVersion("0.0.3")
108 app.setOrganizationName("falkTX")
110 launcher = Unity.LauncherEntry.get_for_desktop_id("cadence.desktop")
112 qtLoop = CadenceUnityApp()
114 signal.signal(signal.SIGTERM, quit_)
115 signal.signal(signal.SIGINT, quit_)
117 # App-Loop
118 ret = app.exec_()
119 sys.exit(ret)