diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/profile_manager.py	Sat Mar 26 16:20:52 2016 +0100
@@ -0,0 +1,97 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+
+# 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/>.
+
+
+from sat_frontends.constants import Const as C
+from sat_frontends.quick_frontend.quick_profile_manager import QuickProfileManager
+from kivy.uix.boxlayout import BoxLayout
+from kivy.uix import listview
+from kivy.uix.button import Button
+from kivy.uix.screenmanager import ScreenManager, Screen
+from kivy.adapters import listadapter
+from kivy.properties import ObjectProperty
+
+
+class ProfileItem(listview.ListItemButton):
+    pass
+
+
+class ProfileListAdapter(listadapter.ListAdapter):
+
+    def __init__(self, pm, *args, **kwargs):
+        super(ProfileListAdapter, self).__init__(*args, **kwargs)
+        self.pm = pm
+        self.host = pm.host
+
+    def closeUI(self, xmlui):
+        self.pm.screen_manager.transition.direction = 'right'
+        self.pm.screen_manager.current = 'profiles'
+
+    def showUI(self, xmlui):
+        xmlui.setCloseCb(self.closeUI)
+        if xmlui.type == 'popup':
+            xmlui.bind(on_touch_up=lambda obj, value: self.closeUI(xmlui))
+        self.pm.xmlui_screen.clear_widgets()
+        self.pm.xmlui_screen.add_widget(xmlui)
+        self.pm.screen_manager.transition.direction = 'left'
+        self.pm.screen_manager.current = 'xmlui'
+
+    def select_item_view(self, view):
+        def authenticate_cb(data, cb_id, profile):
+            if C.bool(data.pop('validated', C.BOOL_FALSE)):
+                super(ProfileListAdapter, self).select_item_view(view)
+            self.host.actionManager(data, callback=authenticate_cb, ui_show_cb=self.showUI, profile=profile)
+
+        self.host.launchAction(C.AUTHENTICATE_PROFILE_ID, callback=authenticate_cb, profile=view.text)
+
+
+class ConnectButton(Button):
+    pass
+
+
+class ProfileScreen(Screen):
+    layout = ObjectProperty(None)
+
+    def __init__(self, pm):
+        super(ProfileScreen, self).__init__(name=u'profiles')
+        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))
+        connect_btn = ConnectButton()
+        self.layout.add_widget(connect_btn)
+
+
+class ProfileManager(QuickProfileManager, BoxLayout):
+
+    def __init__(self, host, autoconnect=None):
+        QuickProfileManager.__init__(self, host, autoconnect)
+        BoxLayout.__init__(self, orientation="vertical")
+        self.screen_manager = ScreenManager()
+        self.profiles_screen = ProfileScreen(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.add_widget(self.screen_manager)
+