X-Git-Url: http://git.maemo.org/git/?p=bluehi;a=blobdiff_plain;f=plugins%2Fcanola-bluehi%2Fbluehi%2Fbluetooth_manager.py;fp=plugins%2Fcanola-bluehi%2Fbluehi%2Fbluetooth_manager.py;h=53c211711a21ad550249864e3cd222db9b77d02f;hp=0000000000000000000000000000000000000000;hb=0bfe84bfd7511a83902e3d6dbbaca7dce1f954e8;hpb=07f0167fd737855c37e5b80d7fbb316df3c9472f diff --git a/plugins/canola-bluehi/bluehi/bluetooth_manager.py b/plugins/canola-bluehi/bluehi/bluetooth_manager.py new file mode 100755 index 0000000..53c2117 --- /dev/null +++ b/plugins/canola-bluehi/bluehi/bluetooth_manager.py @@ -0,0 +1,89 @@ +""" +Project: BlueHi: A plugin for Canola +File name: bluetooth_manager.py + +Description: This software was developed in Zagaia Project + +Copyright (C) 2009 + Antonio R. de C. Junior + Henry Miller M. Bilby + Mauricio Figueiredo + Samuel de Oliveira Fagundes + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +""" + + +import lightblue +import os +from lightblue import BluetoothError +from lightblue.obex import OBEXError + +class BluetoothManager: + + def search_devices(self): + print "def search_devices(self):" + self.devices = lightblue.finddevices() + return self.devices + + def connect(self, address): + port = self.find_port(address) + if port: + self.list = [address, port] + else: + print "Nao foi possivel estabelecer conexao com o dispositivo" + return port + + def send_file(self, path): + address = self.list[0] + port = self.list[1] + file_length = self.get_file_lenght(path) + file_name = self.get_file_name(path) + + client = lightblue.obex.OBEXClient(address, port) + client.connect() + try: + put_response = client.put({"name": file_name, "length": file_length}, file(path)) + if put_response.code != lightblue.obex.OK: + print "Cancelado pelo usuario" + return False + else: + return True + client.disconnect() + except OBEXError: + print "Erro!" + client.disconnect() + + + + def find_services(self, address): + return lightblue.findservices(address) + + def find_port(self, address): + port = None + services = self.find_services(address) + for i in services: + print i + if i[2] == "OBEX Object Push": + port = i[1] + return port + + def get_file_lenght(self, file): + return int(os.path.getsize(file)) + + def get_file_name(self, file): + file = file.split("/") + tam = len(file) + return file[tam - 1]