annotate src/profile_manager.py @ 0:160cc95ad7ea

initial commit: - basic SàT/QuickApp integration - basic XMLUI - profile manager first draft
author Goffi <goffi@goffi.org>
date Sat, 26 Mar 2016 16:20:52 +0100
parents
children 189b76859110
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/python
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
3
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
4 # Cagou: desktop/mobile frontend for Salut à Toi XMPP client
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
5 # Copyright (C) 2016 Jérôme Poisson (goffi@goffi.org)
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
6
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
7 # This program is free software: you can redistribute it and/or modify
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
8 # it under the terms of the GNU Affero General Public License as published by
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
10 # (at your option) any later version.
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
11
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
12 # This program is distributed in the hope that it will be useful,
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
15 # GNU Affero General Public License for more details.
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
16
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
17 # You should have received a copy of the GNU Affero General Public License
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
19
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
20
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
21 from sat_frontends.constants import Const as C
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
22 from sat_frontends.quick_frontend.quick_profile_manager import QuickProfileManager
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
23 from kivy.uix.boxlayout import BoxLayout
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
24 from kivy.uix import listview
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
25 from kivy.uix.button import Button
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
26 from kivy.uix.screenmanager import ScreenManager, Screen
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
27 from kivy.adapters import listadapter
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
28 from kivy.properties import ObjectProperty
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
29
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
30
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
31 class ProfileItem(listview.ListItemButton):
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
32 pass
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
33
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
34
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
35 class ProfileListAdapter(listadapter.ListAdapter):
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
36
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
37 def __init__(self, pm, *args, **kwargs):
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
38 super(ProfileListAdapter, self).__init__(*args, **kwargs)
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
39 self.pm = pm
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
40 self.host = pm.host
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
41
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
42 def closeUI(self, xmlui):
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
43 self.pm.screen_manager.transition.direction = 'right'
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
44 self.pm.screen_manager.current = 'profiles'
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
45
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
46 def showUI(self, xmlui):
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
47 xmlui.setCloseCb(self.closeUI)
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
48 if xmlui.type == 'popup':
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
49 xmlui.bind(on_touch_up=lambda obj, value: self.closeUI(xmlui))
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
50 self.pm.xmlui_screen.clear_widgets()
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
51 self.pm.xmlui_screen.add_widget(xmlui)
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
52 self.pm.screen_manager.transition.direction = 'left'
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
53 self.pm.screen_manager.current = 'xmlui'
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
54
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
55 def select_item_view(self, view):
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
56 def authenticate_cb(data, cb_id, profile):
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
57 if C.bool(data.pop('validated', C.BOOL_FALSE)):
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
58 super(ProfileListAdapter, self).select_item_view(view)
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
59 self.host.actionManager(data, callback=authenticate_cb, ui_show_cb=self.showUI, profile=profile)
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
60
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
61 self.host.launchAction(C.AUTHENTICATE_PROFILE_ID, callback=authenticate_cb, profile=view.text)
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
62
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
63
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
64 class ConnectButton(Button):
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
65 pass
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
66
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
67
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
68 class ProfileScreen(Screen):
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
69 layout = ObjectProperty(None)
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
70
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
71 def __init__(self, pm):
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
72 super(ProfileScreen, self).__init__(name=u'profiles')
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
73 profiles = pm.host.bridge.getProfilesList()
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
74 profiles.sort()
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
75 list_adapter = ProfileListAdapter(pm,
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
76 data=profiles,
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
77 cls=ProfileItem,
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
78 selection_mode='multiple',
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
79 allow_empty_selection=True,
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
80 )
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
81 self.layout.add_widget(listview.ListView(adapter=list_adapter))
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
82 connect_btn = ConnectButton()
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
83 self.layout.add_widget(connect_btn)
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
84
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
85
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
86 class ProfileManager(QuickProfileManager, BoxLayout):
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
87
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
88 def __init__(self, host, autoconnect=None):
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
89 QuickProfileManager.__init__(self, host, autoconnect)
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
90 BoxLayout.__init__(self, orientation="vertical")
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
91 self.screen_manager = ScreenManager()
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
92 self.profiles_screen = ProfileScreen(self)
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
93 self.xmlui_screen = Screen(name=u'xmlui')
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
94 self.screen_manager.add_widget(self.profiles_screen)
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
95 self.screen_manager.add_widget(self.xmlui_screen)
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
96 self.add_widget(self.screen_manager)
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
97