From 3d98b3458f0417c068ca18eff172ae90ea6f6fbf Mon Sep 17 00:00:00 2001 From: Jens Persson Date: Thu, 21 Jul 2011 19:44:26 +0200 Subject: [PATCH] fixed support for wired headsets to qml --- src/panucci/qmlui/qmlmain.py | 50 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 41 insertions(+), 9 deletions(-) diff --git a/src/panucci/qmlui/qmlmain.py b/src/panucci/qmlui/qmlmain.py index 44cbb12..0500cd2 100644 --- a/src/panucci/qmlui/qmlmain.py +++ b/src/panucci/qmlui/qmlmain.py @@ -86,18 +86,29 @@ class PanucciGUI(QtCore.QObject, ObservableService): # self.handle_headset_button) system_bus = dbus.SystemBus() + self.headset_path = '/org/freedesktop/Hal/devices/computer_logicaldev_input' + self.headset_bt_path = '/org/freedesktop/Hal/devices/computer_logicaldev_input' if platform.HARMATTAN: - self.headset_path = '/org/freedesktop/Hal/devices/computer_logicaldev_input_0' + self.headset_bt_path = '/org/freedesktop/Hal/devices/computer_logicaldev_input_0' elif platform.FREMANTLE: - self.headset_path = '/org/freedesktop/Hal/devices/computer_logicaldev_input_1' + self.headset_bt_path = '/org/freedesktop/Hal/devices/computer_logicaldev_input_1' + + # Monitor connection state of headset + system_bus.add_signal_receiver(self.handle_headset_connection_state, 'DeviceAdded', \ + 'org.freedesktop.Hal.Manager', None, '/org/freedesktop/Hal/Manager') + # Monitor connection state of BT headset - system_bus.add_signal_receiver(self.handle_connection_state, 'DeviceAdded', \ + system_bus.add_signal_receiver(self.handle_headset_bt_connection_state, 'DeviceAdded', \ 'org.freedesktop.Hal.Manager', None, '/org/freedesktop/Hal/Manager') - # Monitor BT headset buttons - system_bus.add_signal_receiver(self.handle_bt_button, 'Condition', \ + # Monitor headset buttons + system_bus.add_signal_receiver(self.handle_headset_button, 'Condition', \ 'org.freedesktop.Hal.Device', None, self.headset_path) + # Monitor BT headset buttons + system_bus.add_signal_receiver(self.handle_headset_bt_button, 'Condition', \ + 'org.freedesktop.Hal.Device', None, self.headset_bt_path) + self.app.exec_() def create_actions(self): @@ -651,15 +662,36 @@ class PanucciGUI(QtCore.QObject, ObservableService): def open_external_url(self, url): os.system("xdg-open " + url) - def handle_connection_state(self, device_path): + def handle_headset_connection_state(self, device_path): if device_path == self.headset_path and self.config.getboolean("options", "play_on_headset") and not self.playlist.playing: self.playlist.play_pause_toggle() - def handle_bt_button(self, signal, button): + def handle_headset_button(self, signal, button): if signal == 'ButtonPressed': - if button == 'play-cd': + if button == 'play-pause': self.playlist.play_pause_toggle() - elif button == 'pause-cd': + elif button == 'rewind': + if self.config.get("options", "headset_button") == "short": + self.do_seek(-1*self.config.getint("options", "seek_short")) + elif self.config.get("options", "headset_button") == "long": + self.do_seek(-1*self.config.getint("options", "seek_long")) + else: + self.playlist.prev() + elif button == 'forward': + if self.config.get("options", "headset_button") == "short": + self.do_seek(self.config.getint("options", "seek_short")) + elif self.config.get("options", "headset_button") == "long": + self.do_seek(self.config.getint("options", "seek_long")) + else: + self.playlist.next() + + def handle_headset_bt_connection_state(self, device_path): + if device_path == self.headset_bt_path and self.config.getboolean("options", "play_on_headset") and not self.playlist.playing: + self.playlist.play_pause_toggle() + + def handle_headset_bt_button(self, signal, button): + if signal == 'ButtonPressed': + if button == 'play-cd' or button == 'pause-cd': self.playlist.play_pause_toggle() elif button == 'previous-song': if self.config.get("options", "headset_button") == "short": -- 2.11.4.GIT