2 Project: BlueHi: A plugin for Canola
5 Description: This software was developed in Zagaia Project
8 Antonio R. de C. Junior <brankinhu@gmail.com>
9 Henry Miller M. Bilby <henrymiller.engenheiro@gmail.com>
10 Mauricio Figueiredo <mauricio.figueiredo@fucapi.br>
11 Samuel de Oliveira Fagundes <sf.oliveira@gmail.com>
13 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2 of the License, or
16 (at your option) any later version.
18 This program is distributed in the hope that it will be useful, but
19 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
23 You should have received a copy of the GNU General Public License along
24 with this program; if not, write to the Free Software Foundation, Inc.,
25 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
32 from terra.core.manager import Manager
33 from terra.core.task import Task
34 from terra.core.model import ModelFolder, Model
35 from terra.ui.throbber import ThrobberWidget
36 from terra.core.threaded_model import ThreadedModelFolder
37 from terra.core.threaded_func import ThreadedFunction
38 from terra.core.plugin_prefs import PluginPrefs
39 from bluetooth_manager import BluetoothManager
42 blue = BluetoothManager()
45 WaitNotify = manager.get_class("Model/WaitNotify")
46 system_properties = manager.get_class("SystemProperties")
47 PluginDefaultIcon = manager.get_class("Icon/Plugin")
48 canola_prefs = PluginPrefs("settings")
49 CanolaError = manager.get_class("Model/Notify/Error")
52 """Create plugin and icon"""
53 class Icon(PluginDefaultIcon):
54 terra_type = "Icon/Folder/Task/Apps/Bluetooth"
55 icon = "icon/main_item/bluehi"
58 class MainFolder(ModelFolder):
60 This class is loaded when the plugin starts.
62 terra_type = "Model/Folder/Task/Apps/Bluetooth"
63 terra_task_type = "Task/Folder/Task/Apps/Bluetooth"
65 def __init__(self, parent):
67 ModelFolder.__init__(self, "BlueHi", parent)
68 self.callback_notify = None
71 BluetoothDeviceFolder("Search devices", self)
73 class BluetoothDeviceFolder(ModelFolder):
75 This class search and detect the devices with bluetooth
78 terra_type = "Model/Folder/Task/Apps/Bluetooth/FolderDevice"
80 def __init__(self, name, parent):
81 ModelFolder.__init__(self, name, parent, None)
82 self.callback_notify = None
88 def search(self, end_callback=None):
89 #Verifica se o bluetooth esta ativado senao estiver, ativa-o
90 #This method verify the status of device's bluetooth,if it's disable, enable it.
91 bus = dbus.SystemBus()
92 bus_adapter = dbus.Interface(bus.get_object('org.bluez',\
93 '/org/bluez/hci0'), 'org.bluez.Adapter')
95 if not bus_adapter.IsConnectable():
96 bus_adapter.SetMode("connectable")
101 devices = blue.search_devices()
102 except BluetoothError:
103 self.msg = "Bluetooth error."
107 def end(exception,devices):
108 if self.msg is not None:
109 self.callback_notify(CanolaError(self.msg))
114 self.msg = "Devices not found"
115 self.callback_notify(CanolaError(self.msg))
125 BluetoothListDevice([addr, name], self)
129 self.is_loading = True
130 ThreadedFunction(end,load).start()
132 class BluetoothListDevice(ModelFolder):
134 This class list all of devices founded, detect the device's port of
135 comunication, try to connect with other device by bluetooth and create an
136 OBEXClient to transfer the medias.
138 terra_type = "Model/Folder/Task/Apps/Bluetooth/ListDevice"
140 def __init__(self, list_device, parent):
141 self.list_device = list_device
142 ModelFolder.__init__(self, list_device[1], parent)
143 self.callback_notify = None
144 self.device_addr = list_device[0]
149 port = blue.connect(self.device_addr)
152 def end(exception,port):
155 self.callback_notify(CanolaError("Unable to connect to the\
161 BluetoothAudio("Audio", self)
162 BluetoothVideo("Video", self)
163 BluetoothImage("Image", self)
165 self.is_loading = True
166 ThreadedFunction(end,load).start()
168 class BluetoothAudio(ModelFolder):
170 This class list audio medias
172 terra_type = "Model/Folder/Task/Apps/Bluetooth/Choice/Audio"
174 def __init__(self, type, parent):
175 ModelFolder.__init__(self, type, parent)
176 self.callback_notify = None
180 self.path_audio = canola_prefs["audio"]
181 albuns = os.listdir(self.path_audio[0])
182 aux = Is_Directory(' ')
184 if aux.search(self.path_audio[0]+'/'+album):
185 BrowseByFolder(album, self.path_audio[0], self)
187 FileFolder(album,self)
189 def send(self, file):
190 self.path = self.path_audio[0] + "/" + file
191 if blue.send_file(self.path):
192 self.callback_notify = CanolaError("File sent successfully")
194 self.callback_notify(CanolaError("Connection failed!\
195 \nDetecting devices again"))
197 class BluetoothVideo(ModelFolder):
199 This class list video medias
201 terra_type = "Model/Folder/Task/Apps/Bluetooth/Choice/Video"
203 def __init__(self, type, parent):
204 ModelFolder.__init__(self, type, parent)
205 self.callback_notify = None
209 self.path_video = canola_prefs["video"]
210 albuns = os.listdir(self.path_video[0])
211 aux = Is_Directory(' ')
213 if aux.search(self.path_video[0]+'/'+album):
214 BrowseByFolder(album, self.path_video[0], self)
216 FileFolder(album,self)
218 def enviar(self,file):
219 self.path = self.path_video[0]+"/"+file
220 if blue.send_file(self.path):
221 self.callback_notify = CanolaError("File sent successfully")
223 self.callback_notify(CanolaError("Connection failed!\
224 \nDetecting devices again"))
226 class BluetoothImage(ModelFolder, Task):
228 This class list image medias
230 terra_type = "Model/Folder/Task/Apps/Bluetooth/Choice/Image"
232 def __init__(self, type, parent):
233 ModelFolder.__init__(self, type, parent)
234 self.callback_notify = None
238 self.path_photo=canola_prefs["photo"]
239 albuns=os.listdir(self.path_photo[0])
240 aux = Is_Directory(' ')
242 if aux.search(self.path_photo[0]+'/'+album):
243 BrowseByFolder(album, self.path_photo[0], self)
245 FileFolder(album,self)
248 self.path = self.path_photo[0]+"/"+file
249 if blue.send_file(self.path):
250 self.callback_notify = CanolaError("File sent successfully")
252 self.callback_notify(CanolaError("Connection failed!\
253 \nDetecting devices again"))
255 class BrowseByFolder(ModelFolder):
257 Generic class to list folders from audio , video and photo directories
259 terra_type = "Model/Folder/Task/Apps/Bluetooth/Choice/File/BrowseByFolder"
261 def __init__(self, album, path, parent):
262 ModelFolder.__init__(self, album, parent)
263 self.callback_notify_conf = False
264 self.device_name = album
265 self.callback_notify = None
270 self.sub_path = self.path+"/"+self.device_name
271 aux = Is_Directory(' ')
272 if aux.search(self.sub_path):
273 files = os.listdir(self.sub_path)
274 aux = Is_Directory(' ')
276 if aux.search(self.sub_path+"/"+file):
277 BrowseByFolder(file, self.sub_path, self)
279 FileFolder(file,self)
282 self.path = self.sub_path+"/"+file
283 if blue.send_file(self.path):
284 self.callback_notify = CanolaError("File sent successfully")
286 self.callback_notify(CanolaError("Connection failed!\
287 \nDetecting devices again"))
289 class FileFolder(ModelFolder):
290 terra_type = "Model/Folder/Task/Apps/Bluetooth/Choice/File/FileFolder"
292 def __init__(self, name, parent):
293 ModelFolder.__init__(self, name, parent)
294 self.device_name = name
295 self.callback_notify = None
301 def __init__(self, path):
304 def search(self, path):
306 files = os.listdir(path)