~ubuntu-branches/ubuntu/wily/blueman/wily

« back to all changes in this revision

Viewing changes to blueman/plugins/manager/PulseAudioProfile.py

  • Committer: Package Import Robot
  • Author(s): Sean Davis
  • Date: 2015-09-07 12:48:18 UTC
  • mfrom: (2.3.11 sid)
  • Revision ID: package-import@ubuntu.com-20150907124818-evulc0mhjotz8q29
Tags: 2.0-1ubuntu1
* Merge from Debian unstable (LP: #1482626). Remaining changes:
  - debian/patches/03_filemanage_fix.patch:
    + Dropped, no longer needed.
  - debian/patches/dhcpclient_priority
  - debian/patches/01_dont_autostart_lxde.patch
    + Refreshed patches

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from __future__ import print_function
 
2
from __future__ import division
 
3
from __future__ import absolute_import
 
4
from __future__ import unicode_literals
 
5
 
1
6
from blueman.plugins.ManagerPlugin import ManagerPlugin
2
7
from blueman.main.PulseAudioUtils import PulseAudioUtils, EventType
3
8
from blueman.main.SignalTracker import SignalTracker
4
9
from blueman.gui.manager.ManagerDeviceMenu import ManagerDeviceMenu
5
10
from blueman.gui.MessageArea import MessageArea
6
 
from blueman.Functions import get_icon, create_menuitem
 
11
from blueman.Functions import get_icon, create_menuitem, dprint
7
12
 
8
13
from gi.repository import Gtk
9
14
 
 
15
 
10
16
class PulseAudioProfile(ManagerPlugin):
11
17
    def on_load(self, user_data):
12
18
        self.devices = {}
36
42
        dprint(event, idx)
37
43
 
38
44
        def get_card_cb(card):
39
 
            if card["driver"] == "module-bluetooth-device.c":
 
45
            drivers = ("module-bluetooth-device.c",
 
46
                       "module-bluez4-device.c",
 
47
                       "module-bluez5-device.c")
 
48
 
 
49
            if card["driver"] in drivers:
40
50
                self.devices[card["proplist"]["device.string"]] = card
41
51
                self.regenerate_with_device(card["proplist"]["device.string"])
42
52
 
43
53
        if event & EventType.CARD:
44
 
            print "card",
 
54
            print("card")
45
55
            if event & EventType.CHANGE:
46
 
                print "change"
 
56
                print("change")
47
57
                utils.GetCard(idx, get_card_cb)
48
58
            elif event & EventType.REMOVE:
49
 
                print "remove"
 
59
                print("remove")
50
60
            else:
51
 
                print "add"
 
61
                print("add")
52
62
                utils.GetCard(idx, get_card_cb)
53
63
 
54
64
    def is_connected(self, device):
55
 
        props = device.get_properties()
56
 
        if 'Connected' in props:
57
 
            return props['Connected']
58
 
 
59
 
        # BlueZ 4 only
60
 
 
61
 
        try:
62
 
            s = device.Services["audiosink"]
63
 
            props = s.get_properties()
64
 
            if props["Connected"]:
65
 
                return True
66
 
        except KeyError:
67
 
            pass
68
 
 
69
 
        try:
70
 
            s = device.Services["audiosource"]
71
 
            props = s.get_properties()
72
 
            if props["State"] != "disconnected":
73
 
                return True
74
 
        except KeyError:
75
 
            pass
76
 
 
77
 
        try:
78
 
            s = device.Services["headset"]
79
 
            props = s.get_properties()
80
 
            if props["State"] != "disconnected":
81
 
                return True
82
 
        except KeyError:
83
 
            pass
84
 
 
 
65
        for audio_service in [service for service in device.get_services() if service.group == 'audio']:
 
66
            if audio_service.connected:
 
67
                return True
85
68
        return False
86
69
 
87
70
    def query_pa(self, device):
88
71
        def list_cb(cards):
89
 
            for c in cards.itervalues():
 
72
            for c in cards.values():
90
73
                if c["proplist"]["device.string"] == device.Address:
91
74
                    self.devices[device.Address] = c
92
75
                    self.generate_menu(device)