Mercurial > libervia-desktop-kivy
changeset 9:7b0a53d2afd3
contact list: first draft
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 08 Jul 2016 18:30:30 +0200 |
parents | d9095d1dd7ae |
children | 8b2836b5b6c7 |
files | src/cagou.kv src/cagou.py src/config.py src/constants.py src/contact_list.kv src/contact_list.py |
diffstat | 6 files changed, 173 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/src/cagou.kv Fri Jul 08 18:30:30 2016 +0200 +++ b/src/cagou.kv Fri Jul 08 18:30:30 2016 +0200 @@ -15,3 +15,4 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. #:include profile_manager.kv +#:include contact_list.kv
--- a/src/cagou.py Fri Jul 08 18:30:30 2016 +0200 +++ b/src/cagou.py Fri Jul 08 18:30:30 2016 +0200 @@ -33,13 +33,29 @@ from kivy.app import App import xmlui from profile_manager import ProfileManager +from contact_list import ContactList +from kivy.uix.boxlayout import BoxLayout +import os.path + + +class CagouRootWidget(BoxLayout): + + def __init__(self, widgets): + super(CagouRootWidget, self).__init__(orientation=("vertical")) + for wid in widgets: + self.add_widget(wid) + + def change_widgets(self, widgets): + self.clear_widgets() + for wid in widgets: + self.add_widget(wid) class CagouApp(App): """Kivy App for Cagou""" def build(self): - return ProfileManager(self.host) + return CagouRootWidget([ProfileManager(self.host)]) class Cagou(QuickApp): @@ -49,10 +65,19 @@ super(Cagou, self).__init__(create_bridge=DBusBridgeFrontend, xmlui=xmlui) self.app = CagouApp() self.app.host = self + media_dir = self.app.media_dir = self.bridge.getConfig("", "media_dir") + self.app.default_avatar = os.path.join(media_dir, "misc/default_avatar.png") def run(self): self.app.run() + def plugging_profiles(self): + contact_list = self.widgets.getOrCreateWidget(ContactList, None, on_new_widget=None) + self.app.root.change_widgets([contact_list]) + + def setPresenceStatus(self, show='', status=None, profile=C.PROF_KEY_NONE): + log.info(u"Profile presence status set to {show}/{status}".format(show=show, status=status)) + if __name__ == '__main__': Cagou().run()
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/config.py Fri Jul 08 18:30:30 2016 +0200 @@ -0,0 +1,27 @@ +#!/usr//bin/env python2 +# -*- 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/>. + +"""This module keep an open instance of sat configuration""" + +from sat.tools import config +sat_conf = config.parseMainConf() + + +def getConfig(section, name, default): + return config.getConfig(sat_conf, section, name, default)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/constants.py Fri Jul 08 18:30:30 2016 +0200 @@ -0,0 +1,26 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +# Primitivus: a SAT frontend +# Copyright (C) 2009-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.quick_frontend import constants + + +class Const(constants.Const): + APP_NAME = "Cagou" + LOG_OPT_SECTION = APP_NAME.lower() + CONFIG_SECTION = APP_NAME.lower()
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/contact_list.kv Fri Jul 08 18:30:30 2016 +0200 @@ -0,0 +1,27 @@ +# 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/>. + +<ContactItem>: + spacing: 20 + Widget: + Avatar: + source: root.data.get('avatar', app.default_avatar) + size_hint: (None, None) + Label: + text: root.jid + bold: True + size_hint: (None, None) + Widget:
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/contact_list.py Fri Jul 08 18:30:30 2016 +0200 @@ -0,0 +1,66 @@ +#!/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.core import log as logging +log = logging.getLogger(__name__) +from sat_frontends.quick_frontend.quick_contact_list import QuickContactList +from kivy.uix.boxlayout import BoxLayout +from kivy.uix.listview import ListView +from kivy.adapters.listadapter import ListAdapter +from kivy import properties +import image + + +class Avatar(image.Image): + pass + + +class ContactItem(BoxLayout): + data = properties.DictProperty() + jid = properties.StringProperty('') + + def __init__(self, **kwargs): + BoxLayout.__init__(self, **kwargs) + + +class ContactList(QuickContactList, BoxLayout): + + def __init__(self, host, target, profiles): + QuickContactList.__init__(self, host, profiles) + BoxLayout.__init__(self, orientation="vertical") + self.adapter = ListAdapter(data={}, + cls=ContactItem, + args_converter=self.contactDataConverter, + selection_mode='multiple', + allow_empty_selection=True, + ) + self.add_widget(ListView(adapter=self.adapter)) + self.update() + + def contactDataConverter(self, idx, bare_jid): + return {"jid": bare_jid, "data": self._items_cache[bare_jid]} + + def update(self, entities=None, type_=None, profile=None): + log.info("update: %s %s %s" % (entities, type_, profile)) + # FIXME: for now we update on each event + # if entities is None and type_ is None: + self._items_cache = self.items + self.adapter.data = self.items_sorted +