annotate frontends/primitivus/contact_list.py @ 168:a2655a0a4eac

Primitivus: 2 bugs fixes - fixed bad focus when using removeWindow - UnselectAll was incomplete in contactList
author Goffi <goffi@goffi.org>
date Mon, 09 Aug 2010 22:06:56 +0800
parents 5d7a011d78ba
children 8ea1510d474b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
116
7c482ecac0ff primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/python
7c482ecac0ff primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
7c482ecac0ff primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
3
7c482ecac0ff primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
4 """
7c482ecac0ff primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
5 Primitivus: a SAT frontend
7c482ecac0ff primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
6 Copyright (C) 2009, 2010 Jérôme Poisson (goffi@goffi.org)
7c482ecac0ff primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
7
7c482ecac0ff primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
8 This program is free software: you can redistribute it and/or modify
7c482ecac0ff primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
9 it under the terms of the GNU General Public License as published by
7c482ecac0ff primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
10 the Free Software Foundation, either version 3 of the License, or
7c482ecac0ff primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
11 (at your option) any later version.
7c482ecac0ff primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
12
7c482ecac0ff primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
13 This program is distributed in the hope that it will be useful,
7c482ecac0ff primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
7c482ecac0ff primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7c482ecac0ff primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
16 GNU General Public License for more details.
7c482ecac0ff primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
17
7c482ecac0ff primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
7c482ecac0ff primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
7c482ecac0ff primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
20 """
7c482ecac0ff primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
21
7c482ecac0ff primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
22 import urwid
7c482ecac0ff primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
23 from quick_frontend.quick_contact_list import QuickContactList
125
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
24 from tools.jid import JID
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 121
diff changeset
25 import custom_widgets
116
7c482ecac0ff primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
26
7c482ecac0ff primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
27
7c482ecac0ff primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
28 class ContactList(urwid.WidgetWrap, QuickContactList):
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 116
diff changeset
29 signals = ['click','change']
116
7c482ecac0ff primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
30
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 116
diff changeset
31 def __init__(self, host, CM, on_click=None, on_change=None, user_data=None):
116
7c482ecac0ff primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
32 self.host = host
125
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
33 self.selected = None
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
34 self.groups={}
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
35 self.alert_jid=set()
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
36
116
7c482ecac0ff primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
37 #we now build the widget
125
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
38 self.frame = urwid.Frame(self.__buildList())
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
39 self.main_widget = custom_widgets.LabelLine(self.frame, custom_widgets.SurroundedText(_("Contacts")))
116
7c482ecac0ff primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
40 urwid.WidgetWrap.__init__(self, self.main_widget)
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 116
diff changeset
41 if on_click:
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 116
diff changeset
42 urwid.connect_signal(self, 'click', on_click, user_data)
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 116
diff changeset
43 if on_change:
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 116
diff changeset
44 urwid.connect_signal(self, 'change', on_change, user_data)
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 116
diff changeset
45 QuickContactList.__init__(self, CM)
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 116
diff changeset
46
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 121
diff changeset
47 def __contains__(self, jid):
125
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
48 for group in self.groups:
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
49 if jid.short in self.groups[group][1]:
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
50 return True
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
51 return False
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
52
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
53 def setFocus(self, name):
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
54 """give focus to the first group or contact with the given name"""
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
55 idx = 0
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
56 for widget in self.frame.body.body:
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
57 if widget.getValue() == name:
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
58 self.frame.body.set_focus(idx)
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
59 return
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
60 idx+=1
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
61
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
62 def putAlert(self, jid):
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
63 """Put an alert on the jid to get attention from user (e.g. for new message)"""
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
64 self.alert_jid.add(jid.short)
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
65 self.frame.body = self.__buildList()
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
66 self.host.redraw()
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
67
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
68 def __groupClicked(self, group_wid):
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
69 group = self.groups[group_wid.getValue()]
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
70 group[0] = not group[0]
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
71 self.frame.body = self.__buildList()
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
72 self.host.redraw()
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
73 self.setFocus(group_wid.getValue())
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 121
diff changeset
74
125
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
75 def __contactClicked(self, contact_wid, selected):
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
76 self.selected = contact_wid.data
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
77 for widget in self.frame.body.body:
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
78 if widget.__class__ == custom_widgets.SelectableText:
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
79 widget.setState(widget.data == self.selected, invisible=True)
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
80 if self.selected in self.alert_jid:
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
81 self.alert_jid.remove(self.selected)
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
82 self.frame.body = self.__buildList()
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
83 self.host.redraw()
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 116
diff changeset
84 self._emit('click')
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 116
diff changeset
85
125
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
86 def __buildContact(self, content, param_contacts):
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
87 """Add contact representation in widget list
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
88 @param content: widget list, e.g. SimpleListWalker
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
89 @param contacts: list of JID"""
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
90 contacts = list(param_contacts)
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
91 contacts.sort()
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
92 for contact in contacts:
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
93 jid=JID(contact)
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
94 name = self.CM.getAttr(jid,'name')
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
95 nick = self.CM.getAttr(jid,'nick')
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
96 display = nick or name or jid.node or jid.short
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
97 header = '(*) ' if contact in self.alert_jid else ''
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
98 widget = custom_widgets.SelectableText(display, selected = contact==self.selected, header=header, data=contact)
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
99 if contact in self.alert_jid:
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
100 widget.setAttribute('default','alert')
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
101 content.append(widget)
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
102 urwid.connect_signal(widget, 'change', self.__contactClicked)
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
103
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
104 def __buildList(self):
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
105 """Build the main contact list widget"""
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
106 content = urwid.SimpleListWalker([])
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
107 group_keys = self.groups.keys()
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
108 group_keys.sort()
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
109 for key in group_keys:
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
110 unfolded = self.groups[key][0]
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
111 if key!=None:
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
112 header = '[-]' if unfolded else '[+]'
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
113 widget = custom_widgets.ClickableText(key,header=header+' ')
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
114 content.append(widget)
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
115 urwid.connect_signal(widget, 'click', self.__groupClicked)
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
116 if unfolded:
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
117 self.__buildContact(content, self.groups[key][1])
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
118 return urwid.ListBox(content)
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
119
164
5d7a011d78ba Primitivus: contact list: new method UnselectAll
Goffi <goffi@goffi.org>
parents: 153
diff changeset
120 def unselectAll(self):
5d7a011d78ba Primitivus: contact list: new method UnselectAll
Goffi <goffi@goffi.org>
parents: 153
diff changeset
121 """Unselect all contacts"""
168
a2655a0a4eac Primitivus: 2 bugs fixes
Goffi <goffi@goffi.org>
parents: 164
diff changeset
122 self.selected = None
164
5d7a011d78ba Primitivus: contact list: new method UnselectAll
Goffi <goffi@goffi.org>
parents: 153
diff changeset
123 for widget in self.frame.body.body:
5d7a011d78ba Primitivus: contact list: new method UnselectAll
Goffi <goffi@goffi.org>
parents: 153
diff changeset
124 if widget.__class__ == custom_widgets.SelectableText:
5d7a011d78ba Primitivus: contact list: new method UnselectAll
Goffi <goffi@goffi.org>
parents: 153
diff changeset
125 widget.setState(False, invisible=True)
5d7a011d78ba Primitivus: contact list: new method UnselectAll
Goffi <goffi@goffi.org>
parents: 153
diff changeset
126
5d7a011d78ba Primitivus: contact list: new method UnselectAll
Goffi <goffi@goffi.org>
parents: 153
diff changeset
127
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 116
diff changeset
128 def get_contact(self):
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 116
diff changeset
129 """Return contact currently selected"""
125
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
130 return self.selected
116
7c482ecac0ff primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
131
7c482ecac0ff primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
132 def clear_contacts(self):
7c482ecac0ff primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
133 """clear all the contact list"""
125
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
134 self.groups={}
153
f197b52796ee Primitivus: begining of management for actionResult
Goffi <goffi@goffi.org>
parents: 128
diff changeset
135 self.selected = None
116
7c482ecac0ff primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
136
125
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
137 def replace(self, jid, groups=[None]):
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 116
diff changeset
138 """add a contact to the list if doesn't exist, else update it"""
153
f197b52796ee Primitivus: begining of management for actionResult
Goffi <goffi@goffi.org>
parents: 128
diff changeset
139 assert isinstance(groups, list)
f197b52796ee Primitivus: begining of management for actionResult
Goffi <goffi@goffi.org>
parents: 128
diff changeset
140 assert isinstance(jid, JID)
125
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
141 if not groups:
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
142 groups=[None]
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
143 for group in groups:
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
144 if not self.groups.has_key(group):
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
145 self.groups[group] = [True,set()] #[unfold,list_of_contacts]
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
146 self.groups[group][1].add(jid.short)
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
147 self.frame.body = self.__buildList()
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
148 self.host.redraw()
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
149
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
150
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
151 """contacts = self.list_wid.getAllValues()
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 116
diff changeset
152 if jid.short not in contacts:
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 116
diff changeset
153 contacts.append(jid.short)
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 116
diff changeset
154 contacts.sort()
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 116
diff changeset
155 self.list_wid.changeValues(contacts)
125
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
156 self._emit('change')"""
116
7c482ecac0ff primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
157
7c482ecac0ff primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
158 def disconnect(self, jid):
7c482ecac0ff primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
159 """mark a contact disconnected"""
125
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
160 self.remove(jid.short)
116
7c482ecac0ff primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
161
128
2240f34f6452 Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents: 125
diff changeset
162 def remove(self, param_jid):
116
7c482ecac0ff primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
163 """remove a contact from the list"""
125
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
164 groups_to_remove = []
128
2240f34f6452 Primitivus: misc fixes + menubar first draft
Goffi <goffi@goffi.org>
parents: 125
diff changeset
165 jid = JID(param_jid)
125
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
166 for group in self.groups:
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
167 contacts = self.groups[group][1]
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
168 if jid.short in contacts:
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
169 contacts.remove(jid.short)
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
170 if not len(contacts):
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
171 groups_to_remove.append(group)
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
172 for group in groups_to_remove:
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
173 del self.groups[group]
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
174 self.frame.body = self.__buildList()
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
175 self.host.redraw()
116
7c482ecac0ff primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
176
125
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
177 def add(self, jid, param_groups=[None]):
116
7c482ecac0ff primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
178 """add a contact to the list"""
125
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
179 self.replace(jid,param_groups)
116
7c482ecac0ff primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
180