--- /dev/null
+"""
+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 <brankinhu@gmail.com>
+ Henry Miller M. Bilby <henrymiller.engenheiro@gmail.com>
+ Mauricio Figueiredo <mauricio.figueiredo@fucapi.br>
+ Samuel de Oliveira Fagundes <sf.oliveira@gmail.com>
+
+ 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]