~ubuntu-branches/ubuntu/vivid/blueman/vivid-proposed

« back to all changes in this revision

Viewing changes to blueman/gui/manager/ManagerDeviceMenu.py

  • Committer: Package Import Robot
  • Author(s): Artur Rona
  • Date: 2014-12-24 18:33:36 UTC
  • mfrom: (2.3.8 sid)
  • Revision ID: package-import@ubuntu.com-20141224183336-cyb82ot0y8tz8flq
Tags: 1.99~alpha1-1ubuntu1
* Merge from Debian unstable.  Remaining changes:
  - debian/patches/01_dont_autostart_lxde.patch:
    + Don't autostart the applet in LXDE.
  - debian/patches/03_filemanager_fix.patch:
    + Add support for more filemanagers.
* debian/patches/02_dont_crash_on_non-bluetooth_card.patch:
  - Dropped, no longer applicable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
import gobject
2
 
import gtk
 
1
from gi.repository import GObject
 
2
from gi.repository import Gtk
3
3
from blueman.Sdp import *
4
4
from blueman.Functions import *
5
5
from blueman.main.SignalTracker import SignalTracker
7
7
from blueman.main.Config import Config
8
8
from blueman.main.AppletService import AppletService
9
9
from blueman.gui.MessageArea import MessageArea
 
10
from blueman.bluez.BlueZInterface import BlueZInterface
10
11
 
11
12
from blueman.Lib import rfcomm_list
12
13
 
19
20
    return pixbuf
20
21
 
21
22
 
22
 
class ManagerDeviceMenu(gtk.Menu):
 
23
class ManagerDeviceMenu(Gtk.Menu):
23
24
    __ops__ = {}
24
25
    __instances__ = []
25
26
 
26
27
    def __init__(self, blueman):
27
 
        gtk.Menu.__init__(self)
 
28
        GObject.GObject.__init__(self)
28
29
        self.Blueman = blueman
29
30
        self.SelectedDevice = None
30
31
 
44
45
    def __del__(self):
45
46
        dprint("deleting devicemenu")
46
47
 
47
 
    #   gobject.GObject.__del__(self)
 
48
    #   GObject.GObject.__del__(self)
48
49
 
49
50
 
50
51
    def popup(self, *args):
61
62
 
62
63
        self.Generate()
63
64
 
64
 
        gtk.Menu.popup(self, *args)
 
65
        Gtk.Menu.popup(self, *args)
65
66
 
66
67
    def clear(self):
67
68
        self.Signals.DisconnectAll()
68
69
 
69
 
        def each(child):
 
70
        def each(child, data):
70
71
            self.remove(child)
71
72
            child.destroy()
72
73
 
73
 
        self.foreach(each)
 
74
        self.foreach(each, None)
74
75
 
75
76
    def set_op(self, device, message):
76
 
        ManagerDeviceMenu.__ops__[device.GetObjectPath()] = message
 
77
        ManagerDeviceMenu.__ops__[device.get_object_path()] = message
77
78
        for inst in ManagerDeviceMenu.__instances__:
78
79
            dprint("op: regenerating instance", inst)
79
80
            if inst.SelectedDevice == self.SelectedDevice and not (inst.is_popup and not inst.props.visible):
82
83
 
83
84
    def get_op(self, device):
84
85
        try:
85
 
            return ManagerDeviceMenu.__ops__[device.GetObjectPath()]
 
86
            return ManagerDeviceMenu.__ops__[device.get_object_path()]
86
87
        except:
87
88
            return None
88
89
 
89
90
    def unset_op(self, device):
90
 
        del ManagerDeviceMenu.__ops__[device.GetObjectPath()]
 
91
        del ManagerDeviceMenu.__ops__[device.get_object_path()]
91
92
        for inst in ManagerDeviceMenu.__instances__:
92
93
            dprint("op: regenerating instance", inst)
93
94
            if inst.SelectedDevice == self.SelectedDevice and not (inst.is_popup and not inst.props.visible):
99
100
            self.Generate()
100
101
 
101
102
 
102
 
    def on_connect(self, item, device, service_id, *args):
 
103
    def on_connect(self, item, device, service_id=None, *args):
103
104
        def success(*args2):
104
105
            try:
105
106
                uuid16 = sdp_get_serial_type(device.Address, args[0])
110
111
            prog.message(_("Success!"))
111
112
 
112
113
            if service_id == "serial" and SERIAL_PORT_SVCLASS_ID in uuid16:
113
 
                MessageArea.show_message(_("Serial port connected to %s") % args2[0], gtk.STOCK_DIALOG_INFO)
 
114
                MessageArea.show_message(_("Serial port connected to %s") % args2[0], Gtk.STOCK_DIALOG_INFO)
114
115
            else:
115
116
                MessageArea.close()
116
117
 
123
124
            dprint("fail", args)
124
125
            MessageArea.show_message(_("Connection Failed: ") + e_(str(args[0])))
125
126
 
126
 
        def cancel(prog, *args):
127
 
            try:
128
 
                svc.Disconnect(*args)
129
 
            except:
130
 
                pass
131
 
            prog.message(_("Cancelled"))
132
 
            self.unset_op(device)
133
 
 
134
 
        svc = device.Services[service_id]
135
127
        self.set_op(device, _("Connecting..."))
136
128
        prog = ManagerProgressbar(self.Blueman, False)
137
129
 
142
134
            fail()
143
135
            return
144
136
        try:
145
 
            appl.SetTimeHint(gtk.get_current_event_time())
 
137
            appl.SetTimeHint(Gtk.get_current_event_time())
146
138
        except:
147
139
            pass
148
140
 
149
 
        if service_id == "network":
150
 
            uuid = args[0]
151
 
            appl.ServiceProxy(svc.GetInterfaceName(),
152
 
                              svc.GetObjectPath(),
153
 
                              "Connect",
154
 
                              [uuid],
155
 
                              reply_handler=success,
156
 
                              error_handler=fail, timeout=200)
157
 
        #prog.set_cancellable(True)
158
 
        #prog.connect("cancelled", cancel)
159
 
 
160
 
        elif service_id == "input":
161
 
            appl.ServiceProxy(svc.GetInterfaceName(),
162
 
                              svc.GetObjectPath(),
163
 
                              "Connect", [],
164
 
                              reply_handler=success,
165
 
                              error_handler=fail, timeout=200)
166
 
        #prog.connect("cancelled", cancel)
167
 
 
168
 
        elif service_id == "serial":
169
 
            uuid = str(args[0])
170
 
 
171
 
            appl.RfcommConnect(device.GetObjectPath(),
172
 
                               uuid,
173
 
                               reply_handler=success,
174
 
                               error_handler=fail, timeout=200)
175
 
 
 
141
        if service_id:
 
142
            svc = device.Services[service_id]
 
143
 
 
144
            if service_id == "network":
 
145
                uuid = args[0]
 
146
                appl.ServiceProxy(svc.get_interface_name(),
 
147
                                  svc.get_object_path(),
 
148
                                  "Connect",
 
149
                                  [uuid],
 
150
                                  reply_handler=success,
 
151
                                  error_handler=fail, timeout=200)
 
152
 
 
153
            elif service_id == "input":
 
154
                appl.ServiceProxy(svc.get_interface_name(),
 
155
                                  svc.get_object_path(),
 
156
                                  "Connect", [],
 
157
                                  reply_handler=success,
 
158
                                  error_handler=fail, timeout=200)
 
159
 
 
160
            elif service_id == "serial":
 
161
                uuid = str(args[0])
 
162
 
 
163
                appl.RfcommConnect(device.get_object_path(),
 
164
                                   uuid,
 
165
                                   reply_handler=success,
 
166
                                   error_handler=fail, timeout=200)
 
167
 
 
168
            else:
 
169
                appl.ServiceProxy(svc.get_interface_name(),
 
170
                                  svc.get_object_path(),
 
171
                                  "Connect", [],
 
172
                                  reply_handler=success,
 
173
                                  error_handler=fail, timeout=200)
176
174
        else:
177
 
            appl.ServiceProxy(svc.GetInterfaceName(),
178
 
                              svc.GetObjectPath(),
179
 
                              "Connect", [],
180
 
                              reply_handler=success,
181
 
                              error_handler=fail, timeout=200)
 
175
            appl.ServiceProxy(device.get_interface_name(), device.get_object_path(), 'Connect', [],
 
176
                              reply_handler=success, error_handler=fail, timeout=200)
182
177
 
183
178
        prog.start()
184
179
 
185
 
    def on_disconnect(self, item, device, service_id, *args):
186
 
        svc = device.Services[service_id]
 
180
    def on_disconnect(self, item, device, service_id=None, *args):
187
181
        if service_id == "serial":
188
182
            try:
189
183
                appl = AppletService()
190
184
            except:
191
185
                dprint("** Failed to connect to applet")
192
186
            else:
193
 
                appl.RfcommDisconnect(device.GetObjectPath(), args[0])
 
187
                appl.RfcommDisconnect(device.get_object_path(), args[0])
194
188
                self.Generate()
195
189
        else:
196
190
            try:
198
192
            except:
199
193
                dprint("** Failed to connect to applet")
200
194
                return
201
 
            appl.ServiceProxy(svc.GetInterfaceName(),
202
 
                              svc.GetObjectPath(), "Disconnect", [])
 
195
            if service_id:
 
196
                connection_object = device.Services[service_id]
 
197
            else:
 
198
                connection_object = device
 
199
            appl.ServiceProxy(connection_object.get_interface_name(),
 
200
                              connection_object.get_object_path(), "Disconnect", [])
203
201
 
204
202
 
205
203
    def on_device_property_changed(self, List, device, iter, (key, value)):
220
218
        items = []
221
219
 
222
220
        if not self.is_popup or self.props.visible:
223
 
            device = self.Blueman.List.get(self.Blueman.List.selected(), "device")["device"]
 
221
            selected = self.Blueman.List.selected()
 
222
            if not selected:
 
223
                return
 
224
            device = self.Blueman.List.get(selected, "device")["device"]
224
225
        else:
225
226
            (x, y) = self.Blueman.List.get_pointer()
226
227
            path = self.Blueman.List.get_path_at_pos(x, y)
227
228
            if path != None:
228
 
                device = self.Blueman.List.get(path[0][0], "device")["device"]
 
229
                device = self.Blueman.List.get(path[0], "device")["device"]
229
230
            else:
230
231
                return
231
232
 
271
272
            item.show()
272
273
            item.props.tooltip_text = _("Pair with the device")
273
274
 
274
 
            item = gtk.SeparatorMenuItem()
 
275
            item = Gtk.SeparatorMenuItem()
275
276
            item.show()
276
277
            self.append(item)
277
278
 
298
299
                have_connectables = True
299
300
 
300
301
            if True in map(lambda x: x[0] >= 200, items) and (have_connectables or have_disconnectables):
301
 
                item = gtk.SeparatorMenuItem()
 
302
                item = Gtk.SeparatorMenuItem()
302
303
                item.show()
303
304
                items.append((199, item))
304
305
 
305
306
            if have_connectables:
306
 
                item = gtk.MenuItem()
307
 
                label = gtk.Label()
 
307
                item = Gtk.MenuItem()
 
308
                label = Gtk.Label()
308
309
                label.set_markup(_("<b>Connect To:</b>"))
309
310
                label.props.xalign = 0.0
310
311
 
315
316
                items.append((0, item))
316
317
 
317
318
            if have_disconnectables:
318
 
                item = gtk.MenuItem()
319
 
                label = gtk.Label()
 
319
                item = Gtk.MenuItem()
 
320
                label = Gtk.Label()
320
321
                label.set_markup(_("<b>Disconnect:</b>"))
321
322
                label.props.xalign = 0.0
322
323
 
331
332
                self.append(item)
332
333
 
333
334
            if items != []:
334
 
                item = gtk.SeparatorMenuItem()
 
335
                item = Gtk.SeparatorMenuItem()
335
336
                item.show()
336
337
                self.append(item)
337
338
 
358
359
                    self.Signals.Handle("gobject", browse_item, "activate", lambda x: self.Blueman.browse(device))
359
360
                    browse_item.props.sensitive = True
360
361
 
361
 
            item = gtk.SeparatorMenuItem()
 
362
            item = Gtk.SeparatorMenuItem()
362
363
            item.show()
363
364
            self.append(item)
364
365
 
389
390
            item.show()
390
391
            item.props.tooltip_text = _("Run the setup assistant for this device")
391
392
 
392
 
            def update_services(item):
393
 
                def reply():
394
 
                    self.unset_op(device)
395
 
                    prog.message(_("Success!"))
396
 
                    MessageArea.close()
397
 
 
398
 
                def error(*args):
399
 
                    self.unset_op(device)
400
 
                    prog.message(_("Fail"))
401
 
                    MessageArea.show_message(e_(str(args[0])))
402
 
 
403
 
                prog = ManagerProgressbar(self.Blueman, False, _("Refreshing"))
404
 
                prog.start()
405
 
                self.set_op(device, _("Refreshing Services..."))
406
 
                appl.RefreshServices(device.GetObjectPath(), reply_handler=reply, error_handler=error)
407
 
 
408
 
            item = create_menuitem(_("Refresh Services"), get_icon("gtk-refresh", 16))
409
 
            self.append(item)
410
 
            self.Signals.Handle(item, "activate", update_services)
411
 
            item.show()
412
 
 
413
 
            item = gtk.SeparatorMenuItem()
 
393
            if BlueZInterface.get_interface_version()[0] < 5:
 
394
                def update_services(item):
 
395
                    def reply():
 
396
                        self.unset_op(device)
 
397
                        prog.message(_("Success!"))
 
398
                        MessageArea.close()
 
399
 
 
400
                    def error(*args):
 
401
                        self.unset_op(device)
 
402
                        prog.message(_("Fail"))
 
403
                        MessageArea.show_message(e_(str(args[0])))
 
404
 
 
405
                    prog = ManagerProgressbar(self.Blueman, False, _("Refreshing"))
 
406
                    prog.start()
 
407
                    self.set_op(device, _("Refreshing Services..."))
 
408
                    appl.RefreshServices(device.get_object_path(), reply_handler=reply, error_handler=error)
 
409
 
 
410
                item = create_menuitem(_("Refresh Services"), get_icon("gtk-refresh", 16))
 
411
                self.append(item)
 
412
                self.Signals.Handle(item, "activate", update_services)
 
413
                item.show()
 
414
 
 
415
            item = Gtk.SeparatorMenuItem()
414
416
            item.show()
415
417
            self.append(item)
416
418
 
420
422
            item.show()
421
423
            item.props.tooltip_text = _("Remove this device from the known devices list")
422
424
 
423
 
            item = gtk.SeparatorMenuItem()
 
425
            item = Gtk.SeparatorMenuItem()
424
426
            item.show()
425
427
            self.append(item)
426
428
 
444
446
 
445
447
            else:
446
448
                item.props.sensitive = False
447
 
 
448