예제 #1
0
파일: Manager.py 프로젝트: infirit/blueman
    def inquiry(self):
        def prop_changed(lst, adapter, key_value):
            key, value = key_value
            if key == "Discovering" and not value:
                prog.finalize()
                self.List.disconnect(s1)
                self.List.disconnect(s2)

        def on_progress(lst, frac):
            if abs(1.0 - frac) <= 0.00001:
                if not prog.started():
                    prog.start()
            else:
                prog.fraction(frac)

        prog = ManagerProgressbar(self, text=_("Searching"))
        prog.connect("cancelled", lambda x: self.List.stop_discovery())
        try:
            self.List.discover_devices()
        except Exception as e:
            prog.finalize()
            MessageArea.show_message(*e_(e))

        s1 = self.List.connect("discovery-progress", on_progress)
        s2 = self.List.connect("adapter-property-changed", prop_changed)
예제 #2
0
    def inquiry(self) -> None:
        def prop_changed(_lst: ManagerDeviceList, _adapter: Adapter,
                         key_value: Tuple[str, Any]) -> None:
            key, value = key_value
            if key == "Discovering" and not value:
                prog.finalize()

                self.List.disconnect(s1)
                self.List.disconnect(s2)

        def on_progress(_lst: ManagerDeviceList, frac: float) -> None:
            if abs(1.0 - frac) <= 0.00001:
                if not prog.started():
                    prog.start()
            else:
                prog.fraction(frac)

        prog = ManagerProgressbar(self, text=_("Searching"))
        prog.connect("cancelled", lambda x: self.List.stop_discovery())

        def on_error(e: Exception) -> None:
            prog.finalize()
            MessageArea.show_message(*e_(e))

        self.List.discover_devices(error_handler=on_error)

        s1 = self.List.connect("discovery-progress", on_progress)
        s2 = self.List.connect("adapter-property-changed", prop_changed)
예제 #3
0
    def on_connect(self, _item, service):
        device = service.device

        def success(obj, result, _user_data):
            logging.info("success")
            prog.message(_("Success!"))

            if isinstance(service, SerialPort) and SERIAL_PORT_SVCLASS_ID == service.short_uuid:
                MessageArea.show_message(_("Serial port connected to %s") % result, None, "dialog-information")
            else:
                MessageArea.close()

            self.unset_op(device)

        def fail(obj, result, _user_data):
            prog.message(_("Failed"))

            self.unset_op(device)
            logging.warning("fail %s" % result)
            msg, tb = e_(result.message)
            MessageArea.show_message(_("Connection Failed: ") + msg, tb)

        self.set_op(device, _("Connecting..."))
        prog = ManagerProgressbar(self.Blueman, False)

        if self._appl is None:
            fail(None, GLib.Error('Applet DBus Service not available'), None)
            return

        self._appl.ConnectService('(os)', device.get_object_path(), service.uuid,
                                  result_handler=success, error_handler=fail,
                                  timeout=GLib.MAXINT)

        prog.start()
예제 #4
0
파일: Manager.py 프로젝트: geosp/blueman
    def inquiry(self):
        def prop_changed(lst, adapter, key_value):
            key, value = key_value
            if key == "Discovering" and not value:
                prog.finalize()
                # FIXME for some reason the signal handler is None
                if proghandler is not None:
                    prog.disconnect(proghandler)

                self.List.disconnect(s1)
                self.List.disconnect(s2)

        def on_progress(lst, frac):
            if abs(1.0 - frac) <= 0.00001:
                if not prog.started():
                    prog.start()
            else:
                prog.fraction(frac)

        prog = ManagerProgressbar(self, text=_("Searching"))
        proghandler = prog.connect("cancelled",
                                   lambda x: self.List.stop_discovery())
        try:
            self.List.discover_devices()
        except Exception as e:
            prog.finalize()
            MessageArea.show_message(*e_(e))

        s1 = self.List.connect("discovery-progress", on_progress)
        s2 = self.List.connect("adapter-property-changed", prop_changed)
예제 #5
0
    def on_connect(self, _item, service):
        device = service.device

        def success(obj, result, _user_data):
            logging.info("success")
            prog.message(_("Success!"))

            if isinstance(service, SerialPort) and SERIAL_PORT_SVCLASS_ID == service.short_uuid:
                MessageArea.show_message(_("Serial port connected to %s") % result, None, "dialog-information")
            else:
                MessageArea.close()

            self.unset_op(device)

        def fail(obj, result, _user_data):
            prog.message(_("Failed"))

            self.unset_op(device)
            logging.warning("fail %s" % result)
            msg, tb = e_(result.message)
            MessageArea.show_message(_("Connection Failed: ") + msg, tb)

        self.set_op(device, _("Connecting..."))
        prog = ManagerProgressbar(self.Blueman, False)

        if self._appl is None:
            fail(None, GLib.Error('Applet DBus Service not available'), None)
            return

        self._appl.ConnectService('(os)', device.get_object_path(), service.uuid,
                                  result_handler=success, error_handler=fail,
                                  timeout=GLib.MAXINT)

        prog.start()
예제 #6
0
    def _generic_connect(self, item, device, connect):
        def fail(obj, result, user_date):
            logging.info("fail", result)
            prog.message(_("Failed"))
            self.unset_op(device)
            msg, tb = e_(result.message)
            MessageArea.show_message(_("Connection Failed: ") + msg)

        def success(obj, result, user_data):
            logging.info("success")
            prog.message(_("Success!"))
            MessageArea.close()
            self.unset_op(device)

        if connect:
            self.set_op(self.SelectedDevice, _("Connecting..."))
            self._appl.connect_service("(os)",
                                       device.get_object_path(),
                                       '00000000-0000-0000-0000-000000000000',
                                       result_handler=success,
                                       error_handler=fail,
                                       timeout=GLib.MAXINT)
        else:
            self.set_op(self.SelectedDevice, _("Disconnecting..."))
            self._appl.disconnect_service(
                "(osd)",
                device.get_object_path(),
                '00000000-0000-0000-0000-000000000000',
                0,
                result_handler=success,
                error_handler=fail,
                timeout=GLib.MAXINT)

        prog = ManagerProgressbar(self.Blueman, False)
        prog.start()
예제 #7
0
    def _generic_connect(self, item, device, connect):
        def fail(obj, result, user_date):
            logging.info("fail", result)
            prog.message(_("Failed"))
            self.unset_op(device)
            msg, tb = e_(result.message)
            MessageArea.show_message(_("Connection Failed: ") + msg)

        def success(obj, result, user_data):
            logging.info("success")
            prog.message(_("Success!"))
            MessageArea.close()
            self.unset_op(device)

        if connect:
            self.set_op(self.SelectedDevice, _("Connecting..."))
            self._appl.connect_service("(os)",
                                       device.get_object_path(),
                                       '00000000-0000-0000-0000-000000000000',
                                       result_handler=success, error_handler=fail,
                                       timeout=GLib.MAXINT)
        else:
            self.set_op(self.SelectedDevice, _("Disconnecting..."))
            self._appl.disconnect_service("(osd)",
                                          device.get_object_path(),
                                          '00000000-0000-0000-0000-000000000000',
                                          0,
                                          result_handler=success, error_handler=fail,
                                          timeout=GLib.MAXINT)

        prog = ManagerProgressbar(self.Blueman, False)
        prog.start()
예제 #8
0
			def update_services(item):		
				def reply():
					self.unset_op(device)
					prog.message(_("Success!"))
					MessageArea.close()
					
				def error(*args):
					self.unset_op(device)
					prog.message(_("Fail"))
					MessageArea.show_message(e_(str(args[0])))					
					
				prog = ManagerProgressbar(self.Blueman, False, _("Refreshing"))
				prog.start()
				self.set_op(device, _("Refreshing Services..."))
				appl.RefreshServices(device.GetObjectPath(), reply_handler=reply, error_handler=error)
예제 #9
0
    def on_connect(self, _item, service):
        device = service.device

        def success(*args2):
            dprint("success", args2)
            prog.message(_("Success!"))

            if isinstance(service, SerialPort
                          ) and SERIAL_PORT_SVCLASS_ID == uuid128_to_uuid16(
                              service.uuid):
                MessageArea.show_message(
                    _("Serial port connected to %s") % args2[0],
                    "dialog-information")
            else:
                MessageArea.close()

            self.unset_op(device)

        def fail(*args):
            prog.message(_("Failed"))

            self.unset_op(device)
            dprint("fail", args)
            MessageArea.show_message(
                _("Connection Failed: ") + e_(str(args[0])))

        self.set_op(device, _("Connecting..."))
        prog = ManagerProgressbar(self.Blueman, False)

        try:
            appl = AppletService()
        except:
            dprint("** Failed to connect to applet")
            fail()
            return
        try:
            appl.SetTimeHint(Gtk.get_current_event_time())
        except:
            pass

        appl.connect_service(device.get_object_path(),
                             service.uuid,
                             reply_handler=success,
                             error_handler=fail,
                             timeout=200)

        prog.start()
예제 #10
0
            def update_services(item):
                def reply():
                    self.unset_op(device)
                    prog.message(_("Success!"))
                    MessageArea.close()

                def error(*args):
                    self.unset_op(device)
                    prog.message(_("Fail"))
                    MessageArea.show_message(e_(str(args[0])))

                prog = ManagerProgressbar(self.Blueman, False, _("Refreshing"))
                prog.start()
                self.set_op(device, _("Refreshing Services..."))
                appl.RefreshServices(device.GetObjectPath(),
                                     reply_handler=reply,
                                     error_handler=error)
예제 #11
0
			def update_services(item):
				def prog_msg(msg):
					prog.stop()
					prog.set_label(msg)
					prog.set_cancellable(False)
					self.unset_op(device)
					gobject.timeout_add(1500, prog.finalize)
				
				def reply():
					prog_msg(_("Success!"))
					MessageArea.close()
					
				def error(*args):
					dprint("err", args)
					prog_msg(_("Fail"))
					MessageArea.show_message(e_(str(args[0])))					
					
				prog = ManagerProgressbar(self.Blueman, False, _("Refreshing"))
				prog.start()
				self.set_op(device, _("Refreshing Services..."))
				appl.RefreshServices(device.GetObjectPath(), reply_handler=reply, error_handler=error)
예제 #12
0
    def generic_connect(self, _item: Gtk.MenuItem, device: Device,
                        connect: bool) -> None:
        def fail(_obj: AppletService, result: GLib.Error,
                 _user_data: None) -> None:
            logging.info(f"fail: {result}")
            prog.message(_("Failed"))
            self.unset_op(device)
            msg, tb = e_(result.message)
            MessageArea.show_message(_("Connection Failed: ") + msg)

        def success(_obj: AppletService, _result: None,
                    _user_data: None) -> None:
            logging.info("success")
            prog.message(_("Success!"))
            MessageArea.close()
            self.unset_op(device)

        assert self._appl

        if connect:
            self.set_op(self.SelectedDevice, _("Connecting…"))
            self._appl.ConnectService("(os)",
                                      device.get_object_path(),
                                      '00000000-0000-0000-0000-000000000000',
                                      result_handler=success,
                                      error_handler=fail,
                                      timeout=GLib.MAXINT)
        else:
            self.set_op(self.SelectedDevice, _("Disconnecting…"))
            self._appl.DisconnectService(
                "(osd)",
                device.get_object_path(),
                '00000000-0000-0000-0000-000000000000',
                0,
                result_handler=success,
                error_handler=fail,
                timeout=GLib.MAXINT)

        prog = ManagerProgressbar(self.Blueman, False)
        prog.start()
예제 #13
0
    def on_connect(self, _item, service):
        device = service.device

        def success(*args2):
            dprint("success", " ".join(args2))
            prog.message(_("Success!"))

            if isinstance(service, SerialPort) and SERIAL_PORT_SVCLASS_ID == uuid128_to_uuid16(service.uuid):
                MessageArea.show_message(_("Serial port connected to %s") % args2[0], "dialog-information")
            else:
                MessageArea.close()

            self.unset_op(device)

        def fail(*args):
            prog.message(_("Failed"))

            self.unset_op(device)
            dprint("fail", args)
            MessageArea.show_message(_("Connection Failed: ") + e_(str(args[0])))

        self.set_op(device, _("Connecting..."))
        prog = ManagerProgressbar(self.Blueman, False)

        try:
            appl = AppletService()
        except:
            dprint("** Failed to connect to applet")
            fail()
            return
        try:
            appl.SetTimeHint(Gtk.get_current_event_time())
        except:
            pass

        appl.connect_service(device.get_object_path(), service.uuid,
                             reply_handler=success, error_handler=fail,
                             timeout=200)

        prog.start()
예제 #14
0
    def on_connect(self, _item, service):
        device = service.device

        def success(obj, result, _user_data):
            dprint("success")
            prog.message(_("Success!"))

            if isinstance(service, SerialPort) and SERIAL_PORT_SVCLASS_ID == uuid128_to_uuid16(service.uuid):
                MessageArea.show_message(_("Serial port connected to %s") % result, "dialog-information")
            else:
                MessageArea.close()

            self.unset_op(device)

        def fail(obj, result, _user_data):
            prog.message(_("Failed"))

            self.unset_op(device)
            dprint("fail", result)
            MessageArea.show_message(_("Connection Failed: ") + e_(str(result.message)))

        self.set_op(device, _("Connecting..."))
        prog = ManagerProgressbar(self.Blueman, False)

        try:
            appl = AppletService()
        except:
            dprint("** Failed to connect to applet")
            fail()
            return
        try:
            appl.SetTimeHint(str('(u)'), Gtk.get_current_event_time())
        except:
            pass

        appl.connect_service(str('(ss)'), device.get_object_path(), service.uuid,
                             result_handler=success, error_handler=fail,
                             timeout=GLib.MAXINT)

        prog.start()
예제 #15
0
    def on_connect(self, _item: Gtk.MenuItem, service: Service) -> None:
        device = service.device

        def success(_obj: AppletService, _result: None,
                    _user_data: None) -> None:
            logging.info("success")
            prog.message(_("Success!"))

            MessageArea.close()

            self.unset_op(device)

        def fail(_obj: Optional[AppletService], result: GLib.Error,
                 _user_data: None) -> None:
            prog.message(_("Failed"))

            self.unset_op(device)
            logging.warning(f"fail {result}")
            msg, tb = e_(result.message)
            MessageArea.show_message(_("Connection Failed: ") + msg, tb)

        self.set_op(device, _("Connecting…"))
        prog = ManagerProgressbar(self.Blueman, False)

        if self._appl is None:
            fail(None, GLib.Error('Applet DBus Service not available'), None)
            return

        self._appl.ConnectService('(os)',
                                  device.get_object_path(),
                                  service.uuid,
                                  result_handler=success,
                                  error_handler=fail,
                                  timeout=GLib.MAXINT)

        prog.start()
예제 #16
0
    def connect_service(self,
                        device: Device,
                        uuid: str = GENERIC_CONNECT) -> None:
        def success(_obj: AppletService, _result: None,
                    _user_data: None) -> None:
            logging.info("success")
            prog.message(_("Success!"))

            MessageArea.close()

            self.unset_op(device)

        def fail(_obj: Optional[AppletService], result: GLib.Error,
                 _user_data: None) -> None:
            prog.message(_("Failed"))

            self.unset_op(device)
            logging.warning(f"fail {result}")
            self._handle_error_message(result)

        self.set_op(device, _("Connecting…"))
        prog = ManagerProgressbar(self.Blueman,
                                  cancellable=uuid == self.GENERIC_CONNECT)
        if uuid == self.GENERIC_CONNECT:
            prog.connect("cancelled",
                         lambda x: self.disconnect_service(device))

        if self._appl is None:
            fail(None, GLib.Error('Applet DBus Service not available'), None)
            return

        def connect(
            error_handler: Callable[[AppletService, GLib.Error, None], None]
        ) -> None:
            assert self._appl is not None  # https://github.com/python/mypy/issues/2608
            self._appl.ConnectService('(os)',
                                      device.get_object_path(),
                                      uuid,
                                      result_handler=success,
                                      error_handler=error_handler,
                                      timeout=GLib.MAXINT)

        def initial_error_handler(obj: AppletService, result: GLib.Error,
                                  user_date: None) -> None:
            # There are (Intel) drivers that fail to connect while a discovery is running
            if self._get_errno(result) == errno.EAGAIN:
                assert self.Blueman.List.Adapter is not None
                self.Blueman.List.Adapter.stop_discovery()
                connect(fail)
            else:
                fail(obj, result, user_date)

        connect(initial_error_handler)

        prog.start()
예제 #17
0
    def generic_connect(self, _item: Optional[Gtk.MenuItem], device: Device,
                        connect: bool) -> None:
        def fail(_obj: AppletService, result: GLib.Error,
                 _user_data: None) -> None:
            logging.info(f"fail: {result}")
            prog.message(_("Failed"))
            self.unset_op(device)
            self._handle_error_message(result.message)

        def success(_obj: AppletService, _result: None,
                    _user_data: None) -> None:
            logging.info("success")
            prog.message(_("Success!"))
            MessageArea.close()
            self.unset_op(device)

        assert self._appl

        if connect:
            self.set_op(self.SelectedDevice, _("Connecting…"))
            self._appl.ConnectService("(os)",
                                      device.get_object_path(),
                                      '00000000-0000-0000-0000-000000000000',
                                      result_handler=success,
                                      error_handler=fail,
                                      timeout=GLib.MAXINT)
        else:
            self.set_op(self.SelectedDevice, _("Disconnecting…"))
            self._appl.DisconnectService(
                "(osd)",
                device.get_object_path(),
                '00000000-0000-0000-0000-000000000000',
                0,
                result_handler=success,
                error_handler=fail,
                timeout=GLib.MAXINT)

        prog = ManagerProgressbar(self.Blueman)

        def abort() -> None:
            assert self._appl is not None  # https://github.com/python/mypy/issues/2608
            self._appl.DisconnectService(
                "(osd)", device.get_object_path(),
                '00000000-0000-0000-0000-000000000000', 0)

        prog.connect("cancelled", lambda x: abort())
        prog.start()
예제 #18
0
    def on_connect(self, item, device, service_id=None, *args):
        def success(*args2):
            try:
                uuid16 = sdp_get_serial_type(device.Address, args[0])
            except:
                uuid16 = 0

            dprint("success", args2)
            prog.message(_("Success!"))

            if service_id == "serial" and SERIAL_PORT_SVCLASS_ID in uuid16:
                MessageArea.show_message(
                    _("Serial port connected to %s") % args2[0],
                    "dialog-information")
            else:
                MessageArea.close()

            self.unset_op(device)

        def fail(*args):
            prog.message(_("Failed"))

            self.unset_op(device)
            dprint("fail", args)
            MessageArea.show_message(
                _("Connection Failed: ") + e_(str(args[0])))

        self.set_op(device, _("Connecting..."))
        prog = ManagerProgressbar(self.Blueman, False)

        try:
            appl = AppletService()
        except:
            dprint("** Failed to connect to applet")
            fail()
            return
        try:
            appl.SetTimeHint(Gtk.get_current_event_time())
        except:
            pass

        if service_id:
            svc = device.Services[service_id]

            if service_id == "network":
                uuid = args[0]
                appl.ServiceProxy(svc.get_interface_name(),
                                  svc.get_object_path(),
                                  "Connect", [uuid],
                                  reply_handler=success,
                                  error_handler=fail,
                                  timeout=200)

            elif service_id == "input":
                appl.ServiceProxy(svc.get_interface_name(),
                                  svc.get_object_path(),
                                  "Connect", [],
                                  reply_handler=success,
                                  error_handler=fail,
                                  timeout=200)

            elif service_id == "serial":
                uuid = str(args[0])

                appl.RfcommConnect(device.get_object_path(),
                                   uuid,
                                   reply_handler=success,
                                   error_handler=fail,
                                   timeout=200)

            else:
                appl.ServiceProxy(svc.get_interface_name(),
                                  svc.get_object_path(),
                                  "Connect", [],
                                  reply_handler=success,
                                  error_handler=fail,
                                  timeout=200)
        else:
            appl.ServiceProxy(device.get_interface_name(),
                              device.get_object_path(),
                              'Connect', [],
                              reply_handler=success,
                              error_handler=fail,
                              timeout=200)

        prog.start()
예제 #19
0
	def on_connect(self, item, device, service_id, *args):
		def success(*args2):
			try:
				uuid16 = sdp_get_serial_type(device.Address, args[0])
			except:
				uuid16 = 0
			
			dprint("success", args2)
			prog.message(_("Success!"))
			
			
			if service_id == "serial" and SERIAL_PORT_SVCLASS_ID in uuid16:
				MessageArea.show_message(_("Serial port connected to %s") % args2[0], gtk.STOCK_DIALOG_INFO)
			else:
				MessageArea.close()
			
			self.unset_op(device)
			
		def fail(*args):
			prog.message(_("Failed"))
			
			self.unset_op(device)
			dprint("fail", args)
			MessageArea.show_message(_("Connection Failed: ") + e_(str(args[0])))
			
		def cancel(prog, *args):
			try:
				svc.Disconnect(*args)
			except:
				pass
			prog.message(_("Cancelled"))
			self.unset_op(device)
		
		svc = device.Services[service_id]
		self.set_op(device, _("Connecting..."))
		prog = ManagerProgressbar(self.Blueman, False)
		
		try:
			appl = AppletService()
		except:
			dprint("** Failed to connect to applet")
			fail()
			return
		try:
			appl.SetTimeHint(gtk.get_current_event_time())
		except:
			pass
			
		if service_id == "network":
			uuid = args[0]
			appl.ServiceProxy(svc.GetInterfaceName(), 
							  svc.GetObjectPath(), 
							  "Connect", 
							  [uuid], 
							  reply_handler=success, 
							  error_handler=fail, timeout=200)
			#prog.set_cancellable(True)
			#prog.connect("cancelled", cancel)
			
		elif service_id == "input":
			appl.ServiceProxy(svc.GetInterfaceName(), 
							  svc.GetObjectPath(), 
							  "Connect", [], 
							  reply_handler=success, 
							  error_handler=fail, timeout=200)
			#prog.connect("cancelled", cancel)
			
		elif service_id == "serial":
			uuid = str(args[0])

			appl.RfcommConnect(device.GetObjectPath(), 
							   uuid, 
							   reply_handler=success, 
							   error_handler=fail, timeout=200)
		
		else:
			appl.ServiceProxy(svc.GetInterfaceName(), 
							  svc.GetObjectPath(), 
							  "Connect", [], 
							  reply_handler=success, 
							  error_handler=fail, timeout=200)
			
		prog.start()
예제 #20
0
    def on_connect(self, item, device, service_id=None, *args):
        def success(*args2):
            try:
                uuid16 = sdp_get_serial_type(device.Address, args[0])
            except:
                uuid16 = 0

            dprint("success", args2)
            prog.message(_("Success!"))

            if service_id == "serial" and SERIAL_PORT_SVCLASS_ID in uuid16:
                MessageArea.show_message(_("Serial port connected to %s") % args2[0], "dialog-information")
            else:
                MessageArea.close()

            self.unset_op(device)

        def fail(*args):
            prog.message(_("Failed"))

            self.unset_op(device)
            dprint("fail", args)
            MessageArea.show_message(_("Connection Failed: ") + e_(str(args[0])))

        self.set_op(device, _("Connecting..."))
        prog = ManagerProgressbar(self.Blueman, False)

        try:
            appl = AppletService()
        except:
            dprint("** Failed to connect to applet")
            fail()
            return
        try:
            appl.SetTimeHint(Gtk.get_current_event_time())
        except:
            pass

        if service_id:
            svc = device.Services[service_id]

            if service_id == "network":
                uuid = args[0]
                appl.ServiceProxy(svc.get_interface_name(),
                                  svc.get_object_path(),
                                  "Connect",
                                  [uuid],
                                  reply_handler=success,
                                  error_handler=fail, timeout=200)

            elif service_id == "input":
                appl.ServiceProxy(svc.get_interface_name(),
                                  svc.get_object_path(),
                                  "Connect", [],
                                  reply_handler=success,
                                  error_handler=fail, timeout=200)

            elif service_id == "serial":
                uuid = str(args[0])

                appl.RfcommConnect(device.get_object_path(),
                                   uuid,
                                   reply_handler=success,
                                   error_handler=fail, timeout=200)

            else:
                appl.ServiceProxy(svc.get_interface_name(),
                                  svc.get_object_path(),
                                  "Connect", [],
                                  reply_handler=success,
                                  error_handler=fail, timeout=200)
        else:
            appl.ServiceProxy(device.get_interface_name(), device.get_object_path(), 'Connect', [],
                              reply_handler=success, error_handler=fail, timeout=200)

        prog.start()
예제 #21
0
    def on_connect(self, item, device, service_id, *args):
        def success(*args2):
            try:
                uuid16 = sdp_get_serial_type(device.Address, args[0])
            except:
                uuid16 = 0

            dprint("success", args2)
            prog.message(_("Success!"))

            if service_id == "serial" and SERIAL_PORT_SVCLASS_ID in uuid16:
                MessageArea.show_message(
                    _("Serial port connected to %s") % args2[0],
                    gtk.STOCK_DIALOG_INFO)
            else:
                MessageArea.close()

            self.unset_op(device)

        def fail(*args):
            prog.message(_("Failed"))

            self.unset_op(device)
            dprint("fail", args)
            MessageArea.show_message(
                _("Connection Failed: ") + e_(str(args[0])))

        def cancel(prog, *args):
            try:
                svc.Disconnect(*args)
            except:
                pass
            prog.message(_("Cancelled"))
            self.unset_op(device)

        svc = device.Services[service_id]
        self.set_op(device, _("Connecting..."))
        prog = ManagerProgressbar(self.Blueman, False)

        try:
            appl = AppletService()
        except:
            dprint("** Failed to connect to applet")
            fail()
            return
        try:
            appl.SetTimeHint(gtk.get_current_event_time())
        except:
            pass

        if service_id == "network":
            uuid = args[0]
            appl.ServiceProxy(svc.GetInterfaceName(),
                              svc.GetObjectPath(),
                              "Connect", [uuid],
                              reply_handler=success,
                              error_handler=fail,
                              timeout=200)
        #prog.set_cancellable(True)
        #prog.connect("cancelled", cancel)

        elif service_id == "input":
            appl.ServiceProxy(svc.GetInterfaceName(),
                              svc.GetObjectPath(),
                              "Connect", [],
                              reply_handler=success,
                              error_handler=fail,
                              timeout=200)
        #prog.connect("cancelled", cancel)

        elif service_id == "serial":
            uuid = str(args[0])

            appl.RfcommConnect(device.GetObjectPath(),
                               uuid,
                               reply_handler=success,
                               error_handler=fail,
                               timeout=200)

        else:
            appl.ServiceProxy(svc.GetInterfaceName(),
                              svc.GetObjectPath(),
                              "Connect", [],
                              reply_handler=success,
                              error_handler=fail,
                              timeout=200)

        prog.start()