comparison frontends/primitivus/contact_list.py @ 116:7c482ecac0ff

primitivus: basic contact list, connexion now work \o/
author Goffi <goffi@goffi.org>
date Thu, 01 Jul 2010 18:52:51 +0800
parents
children ded2431cea5a
comparison
equal deleted inserted replaced
115:eed4f77c942e 116:7c482ecac0ff
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 """
5 Primitivus: a SAT frontend
6 Copyright (C) 2009, 2010 Jérôme Poisson (goffi@goffi.org)
7
8 This program is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 """
21
22 import urwid
23 from quick_frontend.quick_contact_list import QuickContactList
24 from custom_widgets import Password,List,InputDialog,ConfirmDialog,Alert
25
26
27 class ContactList(urwid.WidgetWrap, QuickContactList):
28
29 def __init__(self, host, CM):
30 QuickContactList.__init__(self, CM)
31 self.host = host
32
33 self.list_wid = List([], style=['single'], align='left')
34
35 #we now build the widget
36 body_content = urwid.SimpleListWalker([self.list_wid])
37 frame_body = urwid.ListBox(body_content)
38 frame = urwid.Frame(frame_body,urwid.AttrMap(urwid.Text(_("Contacts"),align='center'),'title'))
39 self.main_widget = urwid.LineBox(frame)
40 urwid.WidgetWrap.__init__(self, self.main_widget)
41
42 def clear_contacts(self):
43 """clear all the contact list"""
44 self.list_wid.changeValues([])
45
46 def replace(self, jid, groups=None):
47 """add a contact to the list if doesn't exist, else update it"""
48 contacts = self.list_wid.getValues()
49 if jid.short not in contacts:
50 contacts.append(jid.short)
51 contacts.sort()
52 self.list_wid.changeValues(contacts)
53
54 def disconnect(self, jid):
55 """mark a contact disconnected"""
56 self.remove(jid)
57
58 def remove(self, jid):
59 """remove a contact from the list"""
60 self.list_wid.deleteValue(jid.short)
61
62 def add(self, jid, param_groups=None):
63 """add a contact to the list"""
64 self.replace(jid)
65