예제 #1
0
class MyBluetooth():
    def __init__(self,
                 adapter_removed_cb=None,
                 default_adapter_changed_cb=None,
                 device_found_cb=None):
        self.__adapter_removed_cb = adapter_removed_cb
        self.__default_adapter_changed_cb = default_adapter_changed_cb

        self.manager = Manager()
        if self.__adapter_removed_cb:
            self.manager.connect("adapter-removed", self.__adapter_removed)
        if self.__default_adapter_changed_cb:
            self.manager.connect("default-adapter-changed", self.__default_adapter_changed)
        self.adapter = None
        self.default_adapter = self.manager.get_default_adapter()

        if self.default_adapter != "None":
            self.adapter = Adapter(self.default_adapter)
            # self.adapter.set_powered(True)
            self.adapter.set_discoverable(False)
            self.adapter.set_pairable(True)
            if device_found_cb:
                self.adapter.connect("device-found", device_found_cb)

    def get_devices(self):
        ret = []

        if self.adapter == None:
            return ret

        devices = self.adapter.get_devices()
        i = 0
        ret = []

        while i < len(devices):
            ret.append(Device(devices[i]))
            i += 1

        return ret

    def register_agent(self, agent_path):
        if self.adapter:
            try:
                self.adapter.register_agent(agent_path, "")
            except Exception,e:
                print e
 def on_transfer_started(self, session, filename, local_path, total_bytes):
     session.transfer["progress_dialog"] = BluetoothProgressDialog()
     session.transfer["progress_dialog"].set_keep_above(True)
     info = session.server.GetServerSessionInfo(session.object_path)
     try:
         dev = Device(
             Adapter(Manager().get_default_adapter()).create_device(
                 info["BluetoothAddress"]))
         name = dev.get_alias()
     except Exception, e:
         print e
         name = info["BluetoothAddress"]
예제 #3
0
    def __init__(self,
                 adapter_removed_cb=None,
                 default_adapter_changed_cb=None,
                 device_found_cb=None):
        self.__adapter_removed_cb = adapter_removed_cb
        self.__default_adapter_changed_cb = default_adapter_changed_cb

        self.manager = Manager()
        if self.__adapter_removed_cb:
            self.manager.connect("adapter-removed", self.__adapter_removed)
        if self.__default_adapter_changed_cb:
            self.manager.connect("default-adapter-changed", self.__default_adapter_changed)
        self.adapter = None
        self.default_adapter = self.manager.get_default_adapter()

        if self.default_adapter != "None":
            self.adapter = Adapter(self.default_adapter)
            # self.adapter.set_powered(True)
            self.adapter.set_discoverable(False)
            self.adapter.set_pairable(True)
            if device_found_cb:
                self.adapter.connect("device-found", device_found_cb)
예제 #4
0
import os
import sys
import gtk
import dbus.mainloop.glib
from deepin_utils.file import get_parent_dir
sys.path.append(os.path.join(get_parent_dir(__file__, 4), "dss"))

from bt.agent import Agent
from bt.adapter import Adapter
from bt.manager import Manager
from bluetooth_transfer import BluetoothTransfer

dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)

# gtk.gdk.threads_init()

bus = dbus.SystemBus()
path = "/com/deepin/bluetooth/agent"

agent = Agent(path, bus)

default_adapter = Manager().get_default_adapter()
if default_adapter != "None":
    adptr = Adapter(default_adapter)
    adptr.register_agent(path, "")
    
    transfer = BluetoothTransfer()
    transfer.create_server()
    
gtk.main()