Mercurial > libervia-desktop-kivy
changeset 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 |
files | src/cagou.kv src/profile_manager.kv src/profile_manager.py |
diffstat | 3 files changed, 173 insertions(+), 46 deletions(-) [+] |
line wrap: on
line diff
--- a/src/cagou.kv Sat Mar 26 16:20:52 2016 +0100 +++ b/src/cagou.kv Sat Mar 26 18:58:13 2016 +0100 @@ -14,37 +14,4 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. -<ProfileManager>: - Label: - text: "Profile Manager" - size_hint: 1,0.05 - -<ProfileScreen>: - layout: layout - BoxLayout: - id: layout - orientation: 'vertical' - - Label: - text: "Select a profile to connect with, or create a new one" - size_hint: 1,0.05 - - GridLayout: - cols: 2 - size_hint: 1, 0.1 - Button: - size_hint: 1, 0.1 - text: "New" - Button: - text: "Delete" - size_hint: 1, 0.1 - -<ConnectButton>: - text: "Connect" - size_hint: 1, 0.1 - -<ProfileItem>: - background_normal: "button_selected.png" if self.is_selected else "button.png" - deselected_color: 1,1,1,1 - selected_color: 1,1,1,1 - color: 0,0,0,1 +#:include profile_manager.kv
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/profile_manager.kv Sat Mar 26 18:58:13 2016 +0100 @@ -0,0 +1,118 @@ +# Cagou: desktop/mobile frontend for Salut à Toi XMPP client +# Copyright (C) 2016 Jérôme Poisson (goffi@goffi.org) + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 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 Affero General Public License for more details. + +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +<ProfileManager>: + Label: + text: "Profile Manager" + size_hint: 1,0.05 + +<PMLabel@Label>: + size_hint: 1, 0.1 + +<PMInput@TextInput>: + multiline: False + size_hint: 1, 0.1 + write_tab: False + +<PMButton@Button>: + size_hint: 1, 0.2 + +<NewProfileScreen>: + profile_name: profile_name + jid: jid + password: password + + BoxLayout: + orientation: "vertical" + + Label: + text: "Creation of a new profile" + bold: True + size_hint: 1, 0.1 + Label: + text: root.error_msg + bold: True + size_hint: 1, 0.1 + color: 1,0,0,1 + GridLayout: + cols: 2 + + PMLabel: + text: "Profile name" + PMInput: + id: profile_name + + PMLabel: + text: "JID" + PMInput: + id: jid + + PMLabel: + text: "Password" + PMInput: + id: password + password: True + + Widget: + size_hint: 1, 0.2 + + Widget: + size_hint: 1, 0.2 + + PMButton: + text: "Cancel" + on_press: + root.pm.screen_manager.transition.direction = 'right' + root.pm.screen_manager.current = 'profiles' + + PMButton: + text: "OK" + on_press: root.doCreate() + + Widget: + +<ProfilesScreen>: + layout: layout + BoxLayout: + id: layout + orientation: 'vertical' + + Label: + text: "Select a profile to connect with, or create a new one" + size_hint: 1,0.05 + + GridLayout: + cols: 2 + size_hint: 1, 0.1 + Button: + size_hint: 1, 0.1 + text: "New" + on_press: + root.pm.screen_manager.transition.direction = 'left' + root.pm.screen_manager.current = 'new_profile' + Button: + text: "Delete" + size_hint: 1, 0.1 + +<ConnectButton>: + text: "Connect" + size_hint: 1, 0.1 + +<ProfileItem>: + background_normal: "button_selected.png" if self.is_selected else "button.png" + deselected_color: 1,1,1,1 + selected_color: 1,1,1,1 + color: 0,0,0,1
--- a/src/profile_manager.py Sat Mar 26 16:20:52 2016 +0100 +++ b/src/profile_manager.py Sat Mar 26 18:58:13 2016 +0100 @@ -25,7 +25,7 @@ from kivy.uix.button import Button from kivy.uix.screenmanager import ScreenManager, Screen from kivy.adapters import listadapter -from kivy.properties import ObjectProperty +from kivy import properties class ProfileItem(listview.ListItemButton): @@ -65,23 +65,63 @@ pass -class ProfileScreen(Screen): - layout = ObjectProperty(None) +class NewProfileScreen(Screen): + profile_name = properties.ObjectProperty(None) + jid = properties.ObjectProperty(None) + password = properties.ObjectProperty(None) + error_msg = properties.StringProperty('') def __init__(self, pm): - super(ProfileScreen, self).__init__(name=u'profiles') + super(NewProfileScreen, self).__init__(name=u'new_profile') + self.pm = pm + self.host = pm.host + + def onCreationFailure(self, failure): + msg = [l for l in unicode(failure).split('\n') if l][-1] + self.error_msg = unicode(msg) + + def onCreationSuccess(self, profile): + self.pm.profiles_screen.reload() + self.host.bridge.profileStartSession(self.password.text, profile, callback=lambda dummy: self._sessionStarted(profile), errback=self.onCreationFailure) + + def _sessionStarted(self, profile): + jid = self.jid.text.strip() + self.host.bridge.setParam("JabberID", jid, "Connection", -1, profile) + self.host.bridge.setParam("Password", self.password.text, "Connection", -1, profile) + self.pm.screen_manager.transition.direction = 'right' + self.pm.screen_manager.current = 'profiles' + + def doCreate(self): + name = self.profile_name.text.strip() + # XXX: we use XMPP password for profile password to simplify + # if user want to change profile password, he can do it in preferences + self.host.bridge.asyncCreateProfile(name, self.password.text, callback=lambda: self.onCreationSuccess(name), errback=self.onCreationFailure) + + +class ProfilesScreen(Screen): + layout = properties.ObjectProperty(None) + + def __init__(self, pm): + super(ProfilesScreen, self).__init__(name=u'profiles') + self.pm = pm profiles = pm.host.bridge.getProfilesList() profiles.sort() - list_adapter = ProfileListAdapter(pm, - data=profiles, - cls=ProfileItem, - selection_mode='multiple', - allow_empty_selection=True, - ) - self.layout.add_widget(listview.ListView(adapter=list_adapter)) + self.list_adapter = ProfileListAdapter(pm, + data=profiles, + cls=ProfileItem, + selection_mode='multiple', + allow_empty_selection=True, + ) + self.layout.add_widget(listview.ListView(adapter=self.list_adapter)) connect_btn = ConnectButton() self.layout.add_widget(connect_btn) + def reload(self): + """Reload profiles list""" + profiles = self.pm.host.bridge.getProfilesList() + profiles.sort() + self.list_adapter.data = profiles + class ProfileManager(QuickProfileManager, BoxLayout): @@ -89,9 +129,11 @@ QuickProfileManager.__init__(self, host, autoconnect) BoxLayout.__init__(self, orientation="vertical") self.screen_manager = ScreenManager() - self.profiles_screen = ProfileScreen(self) + self.profiles_screen = ProfilesScreen(self) + self.new_profile_screen = NewProfileScreen(self) self.xmlui_screen = Screen(name=u'xmlui') self.screen_manager.add_widget(self.profiles_screen) self.screen_manager.add_widget(self.xmlui_screen) + self.screen_manager.add_widget(self.new_profile_screen) self.add_widget(self.screen_manager)