Mercurial > libervia-desktop-kivy
comparison src/profile_manager.py @ 1:189b76859110
Profile manager: new profile creation is handled
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 26 Mar 2016 18:58:13 +0100 |
parents | 160cc95ad7ea |
children | 8f9ed634a5eb |
comparison
equal
deleted
inserted
replaced
0:160cc95ad7ea | 1:189b76859110 |
---|---|
23 from kivy.uix.boxlayout import BoxLayout | 23 from kivy.uix.boxlayout import BoxLayout |
24 from kivy.uix import listview | 24 from kivy.uix import listview |
25 from kivy.uix.button import Button | 25 from kivy.uix.button import Button |
26 from kivy.uix.screenmanager import ScreenManager, Screen | 26 from kivy.uix.screenmanager import ScreenManager, Screen |
27 from kivy.adapters import listadapter | 27 from kivy.adapters import listadapter |
28 from kivy.properties import ObjectProperty | 28 from kivy import properties |
29 | 29 |
30 | 30 |
31 class ProfileItem(listview.ListItemButton): | 31 class ProfileItem(listview.ListItemButton): |
32 pass | 32 pass |
33 | 33 |
63 | 63 |
64 class ConnectButton(Button): | 64 class ConnectButton(Button): |
65 pass | 65 pass |
66 | 66 |
67 | 67 |
68 class ProfileScreen(Screen): | 68 class NewProfileScreen(Screen): |
69 layout = ObjectProperty(None) | 69 profile_name = properties.ObjectProperty(None) |
70 jid = properties.ObjectProperty(None) | |
71 password = properties.ObjectProperty(None) | |
72 error_msg = properties.StringProperty('') | |
70 | 73 |
71 def __init__(self, pm): | 74 def __init__(self, pm): |
72 super(ProfileScreen, self).__init__(name=u'profiles') | 75 super(NewProfileScreen, self).__init__(name=u'new_profile') |
76 self.pm = pm | |
77 self.host = pm.host | |
78 | |
79 def onCreationFailure(self, failure): | |
80 msg = [l for l in unicode(failure).split('\n') if l][-1] | |
81 self.error_msg = unicode(msg) | |
82 | |
83 def onCreationSuccess(self, profile): | |
84 self.pm.profiles_screen.reload() | |
85 self.host.bridge.profileStartSession(self.password.text, profile, callback=lambda dummy: self._sessionStarted(profile), errback=self.onCreationFailure) | |
86 | |
87 def _sessionStarted(self, profile): | |
88 jid = self.jid.text.strip() | |
89 self.host.bridge.setParam("JabberID", jid, "Connection", -1, profile) | |
90 self.host.bridge.setParam("Password", self.password.text, "Connection", -1, profile) | |
91 self.pm.screen_manager.transition.direction = 'right' | |
92 self.pm.screen_manager.current = 'profiles' | |
93 | |
94 def doCreate(self): | |
95 name = self.profile_name.text.strip() | |
96 # XXX: we use XMPP password for profile password to simplify | |
97 # if user want to change profile password, he can do it in preferences | |
98 self.host.bridge.asyncCreateProfile(name, self.password.text, callback=lambda: self.onCreationSuccess(name), errback=self.onCreationFailure) | |
99 | |
100 | |
101 class ProfilesScreen(Screen): | |
102 layout = properties.ObjectProperty(None) | |
103 | |
104 def __init__(self, pm): | |
105 super(ProfilesScreen, self).__init__(name=u'profiles') | |
106 self.pm = pm | |
73 profiles = pm.host.bridge.getProfilesList() | 107 profiles = pm.host.bridge.getProfilesList() |
74 profiles.sort() | 108 profiles.sort() |
75 list_adapter = ProfileListAdapter(pm, | 109 self.list_adapter = ProfileListAdapter(pm, |
76 data=profiles, | 110 data=profiles, |
77 cls=ProfileItem, | 111 cls=ProfileItem, |
78 selection_mode='multiple', | 112 selection_mode='multiple', |
79 allow_empty_selection=True, | 113 allow_empty_selection=True, |
80 ) | 114 ) |
81 self.layout.add_widget(listview.ListView(adapter=list_adapter)) | 115 self.layout.add_widget(listview.ListView(adapter=self.list_adapter)) |
82 connect_btn = ConnectButton() | 116 connect_btn = ConnectButton() |
83 self.layout.add_widget(connect_btn) | 117 self.layout.add_widget(connect_btn) |
118 | |
119 def reload(self): | |
120 """Reload profiles list""" | |
121 profiles = self.pm.host.bridge.getProfilesList() | |
122 profiles.sort() | |
123 self.list_adapter.data = profiles | |
84 | 124 |
85 | 125 |
86 class ProfileManager(QuickProfileManager, BoxLayout): | 126 class ProfileManager(QuickProfileManager, BoxLayout): |
87 | 127 |
88 def __init__(self, host, autoconnect=None): | 128 def __init__(self, host, autoconnect=None): |
89 QuickProfileManager.__init__(self, host, autoconnect) | 129 QuickProfileManager.__init__(self, host, autoconnect) |
90 BoxLayout.__init__(self, orientation="vertical") | 130 BoxLayout.__init__(self, orientation="vertical") |
91 self.screen_manager = ScreenManager() | 131 self.screen_manager = ScreenManager() |
92 self.profiles_screen = ProfileScreen(self) | 132 self.profiles_screen = ProfilesScreen(self) |
133 self.new_profile_screen = NewProfileScreen(self) | |
93 self.xmlui_screen = Screen(name=u'xmlui') | 134 self.xmlui_screen = Screen(name=u'xmlui') |
94 self.screen_manager.add_widget(self.profiles_screen) | 135 self.screen_manager.add_widget(self.profiles_screen) |
95 self.screen_manager.add_widget(self.xmlui_screen) | 136 self.screen_manager.add_widget(self.xmlui_screen) |
137 self.screen_manager.add_widget(self.new_profile_screen) | |
96 self.add_widget(self.screen_manager) | 138 self.add_widget(self.screen_manager) |
97 | 139 |