Adding plugin files to version control system.
[bluehi] / plugins / canola-bluehi / bluehi / ui.py
1 """
2 Project: BlueHi: A plugin for Canola
3 File name: ui.py
4
5 Description: This software was developed in Zagaia Project
6
7 Copyright (C) 2009
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>
12
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.
17     
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 
21     for more details.
22     
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
26 """
27 from terra.core.manager import Manager
28 from model import FileFolder, BrowseByFolder
29
30 manager = Manager()
31 WaitNotifyController = manager.get_class("Model/WaitNotify")
32 YesNoDialogModel = manager.get_class("Model/YesNoDialog")
33 BaseListController = manager.get_class("Controller/Folder")
34 BaseRowRenderer = manager.get_class("Widget/RowRenderer")
35 ResizableRowRenderer = manager.get_class("Widget/ResizableRowRenderer")
36
37 """Manager list devices"""
38 class DeviceListController(BaseListController):
39     """
40     This class is controller for class MainFolder, BluetoothDeviceFolder
41     and BluetoothListDevice.
42     """
43     terra_type = "Controller/Folder/Task/Apps/Bluetooth"
44
45     def __init__(self, model, canvas, parent):
46         BaseListController.__init__(self, model, canvas, parent)
47         self.model.callback_notify = self._show_notify
48
49     def _show_notify(self, err):
50         """Popup a modal with a notify message."""
51         self.parent.show_notify(err)
52
53     def cb_on_clicked(self,view, index):
54         model=self.model.children[index]
55         BaseListController.cb_on_clicked(self, view, index)
56
57 class DiretorioListController(BaseListController):
58     terra_type = "Controller/Folder/Task/Apps/Bluetooth/Choice"
59
60     def __init__(self, model, canvas, parent):
61         BaseListController.__init__(self, model, canvas, parent)
62         self.vmodel = None
63         self.model.callback_notify = self._show_notify
64
65     def _show_notify(self, err):
66         """Popup a modal with a notify message."""
67         self.parent.show_notify(err)
68
69     def _show_notify_conf(self, msg):
70         def confirme(dialog, ok):
71             if ok:
72                 self.loading()
73
74         self.parent.show_notify(YesNoDialogModel("%s" % msg, confirme))
75
76     def loading(self):
77         def wait(value, ok):
78             self.model.send(self.vmodel.name)
79         self.parent.show_notify(WaitNotifyController("Sending file...", 5, wait))
80
81     def cb_on_clicked(self, view, index):
82         self.vmodel=self.model.children[index]
83
84         if type(self.vmodel) is FileFolder:
85             self._show_notify_conf("Do you want to send this file?\n%s"\
86                     % self.vmodel.name)
87             return
88
89         if type(self.vmodel) is BrowseByFolder:
90             BaseListController.cb_on_clicked(self, view, index)
91             return
92