libervia-backend/frontends/primitivus/contact_list.py
Goffi 61f6edae54 primitivus chat window
- management of one 2 one / group chat
- timestamp displayed
- added shortcuts for showing/hiding panels
- color used
- fixed vcard bug (contact displayed even if not from current profile if vcard changed/not in cache)
- added VerticalSeparator widget
- *List widgets can now use an other widget than SelectableText
- new UnselectableText widget
2010-07-08 19:47:54 +08:00

81 lines
2.8 KiB
Python

#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
Primitivus: a SAT frontend
Copyright (C) 2009, 2010 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 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
import urwid
from quick_frontend.quick_contact_list import QuickContactList
import custom_widgets
class ContactList(urwid.WidgetWrap, QuickContactList):
signals = ['click','change']
def __init__(self, host, CM, on_click=None, on_change=None, user_data=None):
self.host = host
self.list_wid = custom_widgets.GenericList([], style=['single','no_first_select'], align='left', on_click=self.__contactClicked, on_change=on_change)
#we now build the widget
frame_body = self.list_wid
frame = urwid.Frame(frame_body)
self.main_widget = custom_widgets.LabelLine(frame, custom_widgets.SurroundedText(_("Contacts")))
urwid.WidgetWrap.__init__(self, self.main_widget)
if on_click:
urwid.connect_signal(self, 'click', on_click, user_data)
if on_change:
urwid.connect_signal(self, 'change', on_change, user_data)
QuickContactList.__init__(self, CM)
def __contains__(self, jid):
contacts = self.list_wid.getAllValues()
return jid.short in contacts
def __contactClicked(self, list_wid):
self._emit('click')
def get_contact(self):
"""Return contact currently selected"""
return self.list_wid.getSelectedValue()
def clear_contacts(self):
"""clear all the contact list"""
self.list_wid.changeValues([])
def replace(self, jid, groups=None):
"""add a contact to the list if doesn't exist, else update it"""
contacts = self.list_wid.getAllValues()
if jid.short not in contacts:
contacts.append(jid.short)
contacts.sort()
self.list_wid.changeValues(contacts)
self._emit('change')
def disconnect(self, jid):
"""mark a contact disconnected"""
self.remove(jid)
def remove(self, jid):
"""remove a contact from the list"""
self.list_wid.deleteValue(jid.short)
def add(self, jid, param_groups=None):
"""add a contact to the list"""
self.replace(jid)