annotate frontends/src/primitivus/contact_list.py @ 1235:80d2ed788b40

core (config): added the Exception default value which raise an exception instead of returning the default in getConfig
author Goffi <goffi@goffi.org>
date Sat, 11 Oct 2014 16:26:43 +0200
parents 93a5e2673929
children e3a9ea76de35
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
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 587
diff changeset
4 # Primitivus: a SAT frontend
811
1fe00f0c9a91 dates update
Goffi <goffi@goffi.org>
parents: 771
diff changeset
5 # Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014 Jérôme Poisson (goffi@goffi.org)
116
7c482ecac0ff primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
6
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 587
diff changeset
7 # This program is free software: you can redistribute it and/or modify
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 587
diff changeset
8 # it under the terms of the GNU Affero General Public License as published by
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 587
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 587
diff changeset
10 # (at your option) any later version.
116
7c482ecac0ff primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
11
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 587
diff changeset
12 # This program is distributed in the hope that it will be useful,
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 587
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 587
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 587
diff changeset
15 # GNU Affero General Public License for more details.
116
7c482ecac0ff primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
16
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 587
diff changeset
17 # You should have received a copy of the GNU Affero General Public License
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 587
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
116
7c482ecac0ff primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
19
771
bfabeedbf32e core: i18n refactoring:
Goffi <goffi@goffi.org>
parents: 737
diff changeset
20 from sat.core.i18n import _
116
7c482ecac0ff primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
21 import urwid
222
3198bfd66daa primitivus: refactoring to use urwid-satext which is now a separate project
Goffi <goffi@goffi.org>
parents: 201
diff changeset
22 from urwid_satext import sat_widgets
225
fd9b7834d98a distutils installation script, draft
Goffi <goffi@goffi.org>
parents: 223
diff changeset
23 from sat_frontends.quick_frontend.quick_contact_list import QuickContactList
1158
c0f15e52695a primitivus: use of new keys modules from Urwid SàText
Goffi <goffi@goffi.org>
parents: 1139
diff changeset
24 from sat_frontends.quick_frontend.quick_utils import unescapePrivate
1139
75025461141f move sat.tools.jid to sat_frontends.tools.jid
souliane <souliane@mailoo.org>
parents: 1058
diff changeset
25 from sat_frontends.tools.jid import JID
737
378af36155c2 frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents: 736
diff changeset
26 from sat_frontends.primitivus.status import StatusBar
1229
03661d1b216a primitivus: implement "Show offline contacts" parameter (sync with "DISCONNECTED_HIDE" action key)
souliane <souliane@mailoo.org>
parents: 1183
diff changeset
27 from sat_frontends.primitivus.constants import Const as C
1158
c0f15e52695a primitivus: use of new keys modules from Urwid SàText
Goffi <goffi@goffi.org>
parents: 1139
diff changeset
28 from sat_frontends.primitivus.keys import action_key_map as a_key
1183
f36d7068a44b Primitivus: fixed focus in ContactList:
Goffi <goffi@goffi.org>
parents: 1158
diff changeset
29 from sat.core import log as logging
f36d7068a44b Primitivus: fixed focus in ContactList:
Goffi <goffi@goffi.org>
parents: 1158
diff changeset
30 log = logging.getLogger(__name__)
1158
c0f15e52695a primitivus: use of new keys modules from Urwid SàText
Goffi <goffi@goffi.org>
parents: 1139
diff changeset
31
116
7c482ecac0ff primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
32
7c482ecac0ff primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
33 class ContactList(urwid.WidgetWrap, QuickContactList):
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 116
diff changeset
34 signals = ['click','change']
116
7c482ecac0ff primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
35
501
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 500
diff changeset
36 def __init__(self, host, on_click=None, on_change=None, user_data=None):
510
886754295efe quick frontend, primitivus, wix: MUC private messages management
Goffi <goffi@goffi.org>
parents: 507
diff changeset
37 QuickContactList.__init__(self)
116
7c482ecac0ff primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
38 self.host = host
125
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
39 self.selected = None
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
40 self.groups={}
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
41 self.alert_jid=set()
497
50dd2a0196c0 primitivus: contacts list improvments:
Goffi <goffi@goffi.org>
parents: 480
diff changeset
42 self.show_status = False
501
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 500
diff changeset
43 self.show_disconnected = False
1230
3abc6563a0d2 primitivus: implement parameter "Show empty groups"
souliane <souliane@mailoo.org>
parents: 1229
diff changeset
44 self.show_empty_groups = True
3abc6563a0d2 primitivus: implement parameter "Show empty groups"
souliane <souliane@mailoo.org>
parents: 1229
diff changeset
45 # TODO: this may lead to two successive UI refresh and needs an optimization
3abc6563a0d2 primitivus: implement parameter "Show empty groups"
souliane <souliane@mailoo.org>
parents: 1229
diff changeset
46 self.host.bridge.asyncGetParamA(C.SHOW_EMPTY_GROUPS, "General", profile_key=host.profile, callback=self.showEmptyGroups)
1229
03661d1b216a primitivus: implement "Show offline contacts" parameter (sync with "DISCONNECTED_HIDE" action key)
souliane <souliane@mailoo.org>
parents: 1183
diff changeset
47 self.host.bridge.asyncGetParamA(C.SHOW_OFFLINE_CONTACTS, "General", profile_key=host.profile, callback=self.showOfflineContacts)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
48
116
7c482ecac0ff primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
49 #we now build the widget
737
378af36155c2 frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents: 736
diff changeset
50 self.host.status_bar = StatusBar(host)
1183
f36d7068a44b Primitivus: fixed focus in ContactList:
Goffi <goffi@goffi.org>
parents: 1158
diff changeset
51 self.frame = sat_widgets.FocusFrame(self.__buildList(), None, self.host.status_bar)
222
3198bfd66daa primitivus: refactoring to use urwid-satext which is now a separate project
Goffi <goffi@goffi.org>
parents: 201
diff changeset
52 self.main_widget = sat_widgets.LabelLine(self.frame, sat_widgets.SurroundedText(_("Contacts")))
116
7c482ecac0ff primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
53 urwid.WidgetWrap.__init__(self, self.main_widget)
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 116
diff changeset
54 if on_click:
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 116
diff changeset
55 urwid.connect_signal(self, 'click', on_click, user_data)
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 116
diff changeset
56 if on_change:
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 116
diff changeset
57 urwid.connect_signal(self, 'change', on_change, user_data)
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 116
diff changeset
58
501
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 500
diff changeset
59 def update(self):
500
00d3679976ab primitivus: keep focus position in contacts list on redraw
Goffi <goffi@goffi.org>
parents: 499
diff changeset
60 """Update display, keep focus"""
00d3679976ab primitivus: keep focus position in contacts list on redraw
Goffi <goffi@goffi.org>
parents: 499
diff changeset
61 widget, position = self.frame.body.get_focus()
00d3679976ab primitivus: keep focus position in contacts list on redraw
Goffi <goffi@goffi.org>
parents: 499
diff changeset
62 self.frame.body = self.__buildList()
00d3679976ab primitivus: keep focus position in contacts list on redraw
Goffi <goffi@goffi.org>
parents: 499
diff changeset
63 if position:
646
f7804c52c754 primitivus: disconnected contact crash fix
Goffi <goffi@goffi.org>
parents: 609
diff changeset
64 try:
911
b12706d164d7 primitivus: removed deprecated use of set_focus
Goffi <goffi@goffi.org>
parents: 812
diff changeset
65 self.frame.body.focus_position = position
646
f7804c52c754 primitivus: disconnected contact crash fix
Goffi <goffi@goffi.org>
parents: 609
diff changeset
66 except IndexError:
f7804c52c754 primitivus: disconnected contact crash fix
Goffi <goffi@goffi.org>
parents: 609
diff changeset
67 pass
500
00d3679976ab primitivus: keep focus position in contacts list on redraw
Goffi <goffi@goffi.org>
parents: 499
diff changeset
68 self.host.redraw()
00d3679976ab primitivus: keep focus position in contacts list on redraw
Goffi <goffi@goffi.org>
parents: 499
diff changeset
69
501
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 500
diff changeset
70 def update_jid(self, jid):
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 500
diff changeset
71 self.update()
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 500
diff changeset
72
497
50dd2a0196c0 primitivus: contacts list improvments:
Goffi <goffi@goffi.org>
parents: 480
diff changeset
73 def keypress(self, size, key):
1183
f36d7068a44b Primitivus: fixed focus in ContactList:
Goffi <goffi@goffi.org>
parents: 1158
diff changeset
74 # FIXME: we have a temporary behaviour here: FOCUS_SWITCH change focus globally in the parent,
f36d7068a44b Primitivus: fixed focus in ContactList:
Goffi <goffi@goffi.org>
parents: 1158
diff changeset
75 # and FOCUS_UP/DOWN is transwmitter to parent if we are respectively on the first or last element
f36d7068a44b Primitivus: fixed focus in ContactList:
Goffi <goffi@goffi.org>
parents: 1158
diff changeset
76 if key in sat_widgets.FOCUS_KEYS:
f36d7068a44b Primitivus: fixed focus in ContactList:
Goffi <goffi@goffi.org>
parents: 1158
diff changeset
77 if (key == a_key['FOCUS_SWITCH'] or (key == a_key['FOCUS_UP'] and self.frame.focus_position == 'body') or
f36d7068a44b Primitivus: fixed focus in ContactList:
Goffi <goffi@goffi.org>
parents: 1158
diff changeset
78 (key == a_key['FOCUS_DOWN'] and self.frame.focus_position == 'footer')):
f36d7068a44b Primitivus: fixed focus in ContactList:
Goffi <goffi@goffi.org>
parents: 1158
diff changeset
79 return key
1158
c0f15e52695a primitivus: use of new keys modules from Urwid SàText
Goffi <goffi@goffi.org>
parents: 1139
diff changeset
80 if key == a_key['STATUS_HIDE']: #user wants to (un)hide contacts' statuses
497
50dd2a0196c0 primitivus: contacts list improvments:
Goffi <goffi@goffi.org>
parents: 480
diff changeset
81 self.show_status = not self.show_status
501
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 500
diff changeset
82 self.update()
1158
c0f15e52695a primitivus: use of new keys modules from Urwid SàText
Goffi <goffi@goffi.org>
parents: 1139
diff changeset
83 elif key == a_key['DISCONNECTED_HIDE']: #user wants to (un)hide disconnected contacts
1229
03661d1b216a primitivus: implement "Show offline contacts" parameter (sync with "DISCONNECTED_HIDE" action key)
souliane <souliane@mailoo.org>
parents: 1183
diff changeset
84 self.host.bridge.setParam(C.SHOW_OFFLINE_CONTACTS, C.str(not self.show_disconnected), "General", profile_key=self.host.profile)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
85 return super(ContactList, self).keypress(size, key)
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
86
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 121
diff changeset
87 def __contains__(self, jid):
125
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
88 for group in self.groups:
688
f7878ad3c846 tools: renamed tools.jid.JID attribute "short" to "bare"
souliane <souliane@mailoo.org>
parents: 685
diff changeset
89 if jid.bare in self.groups[group][1]:
125
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
90 return True
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
91 return False
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
92
685
0b9bd47dffcd primitivus, wix: auto-display MUC dialog after it has been joined:
souliane <souliane@mailoo.org>
parents: 646
diff changeset
93 def setFocus(self, text, select=False):
0b9bd47dffcd primitivus, wix: auto-display MUC dialog after it has been joined:
souliane <souliane@mailoo.org>
parents: 646
diff changeset
94 """give focus to the first element that matches the given text. You can also
1139
75025461141f move sat.tools.jid to sat_frontends.tools.jid
souliane <souliane@mailoo.org>
parents: 1058
diff changeset
95 pass in text a sat_frontends.tools.jid.JID (it's a subclass of unicode).
685
0b9bd47dffcd primitivus, wix: auto-display MUC dialog after it has been joined:
souliane <souliane@mailoo.org>
parents: 646
diff changeset
96 @param text: contact group name, contact or muc userhost, muc private dialog jid
0b9bd47dffcd primitivus, wix: auto-display MUC dialog after it has been joined:
souliane <souliane@mailoo.org>
parents: 646
diff changeset
97 @param select: if True, the element is also clicked
0b9bd47dffcd primitivus, wix: auto-display MUC dialog after it has been joined:
souliane <souliane@mailoo.org>
parents: 646
diff changeset
98 """
125
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
99 idx = 0
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
100 for widget in self.frame.body.body:
502
debcf5dd404a QuickFrontend, Primitivus, Wix: special entities management:
Goffi <goffi@goffi.org>
parents: 501
diff changeset
101 try:
685
0b9bd47dffcd primitivus, wix: auto-display MUC dialog after it has been joined:
souliane <souliane@mailoo.org>
parents: 646
diff changeset
102 if isinstance(widget, sat_widgets.ClickableText):
0b9bd47dffcd primitivus, wix: auto-display MUC dialog after it has been joined:
souliane <souliane@mailoo.org>
parents: 646
diff changeset
103 # contact group
0b9bd47dffcd primitivus, wix: auto-display MUC dialog after it has been joined:
souliane <souliane@mailoo.org>
parents: 646
diff changeset
104 value = widget.getValue()
0b9bd47dffcd primitivus, wix: auto-display MUC dialog after it has been joined:
souliane <souliane@mailoo.org>
parents: 646
diff changeset
105 elif isinstance(widget, sat_widgets.SelectableText):
1229
03661d1b216a primitivus: implement "Show offline contacts" parameter (sync with "DISCONNECTED_HIDE" action key)
souliane <souliane@mailoo.org>
parents: 1183
diff changeset
106 if widget.data.startswith(C.PRIVATE_PREFIX):
685
0b9bd47dffcd primitivus, wix: auto-display MUC dialog after it has been joined:
souliane <souliane@mailoo.org>
parents: 646
diff changeset
107 # muc private dialog
0b9bd47dffcd primitivus, wix: auto-display MUC dialog after it has been joined:
souliane <souliane@mailoo.org>
parents: 646
diff changeset
108 value = widget.getValue()
0b9bd47dffcd primitivus, wix: auto-display MUC dialog after it has been joined:
souliane <souliane@mailoo.org>
parents: 646
diff changeset
109 else:
0b9bd47dffcd primitivus, wix: auto-display MUC dialog after it has been joined:
souliane <souliane@mailoo.org>
parents: 646
diff changeset
110 # contact or muc
0b9bd47dffcd primitivus, wix: auto-display MUC dialog after it has been joined:
souliane <souliane@mailoo.org>
parents: 646
diff changeset
111 value = widget.data
0b9bd47dffcd primitivus, wix: auto-display MUC dialog after it has been joined:
souliane <souliane@mailoo.org>
parents: 646
diff changeset
112 else:
0b9bd47dffcd primitivus, wix: auto-display MUC dialog after it has been joined:
souliane <souliane@mailoo.org>
parents: 646
diff changeset
113 # Divider instance
0b9bd47dffcd primitivus, wix: auto-display MUC dialog after it has been joined:
souliane <souliane@mailoo.org>
parents: 646
diff changeset
114 continue
0b9bd47dffcd primitivus, wix: auto-display MUC dialog after it has been joined:
souliane <souliane@mailoo.org>
parents: 646
diff changeset
115 # there's sometimes a leading space
0b9bd47dffcd primitivus, wix: auto-display MUC dialog after it has been joined:
souliane <souliane@mailoo.org>
parents: 646
diff changeset
116 if text.strip() == value.strip():
911
b12706d164d7 primitivus: removed deprecated use of set_focus
Goffi <goffi@goffi.org>
parents: 812
diff changeset
117 self.frame.body.focus_position = idx
511
62f7f2403093 Primitivus: present contacts in groups chat can now be clicked
Goffi <goffi@goffi.org>
parents: 510
diff changeset
118 if select:
62f7f2403093 Primitivus: present contacts in groups chat can now be clicked
Goffi <goffi@goffi.org>
parents: 510
diff changeset
119 self.__contactClicked(widget, True)
502
debcf5dd404a QuickFrontend, Primitivus, Wix: special entities management:
Goffi <goffi@goffi.org>
parents: 501
diff changeset
120 return
debcf5dd404a QuickFrontend, Primitivus, Wix: special entities management:
Goffi <goffi@goffi.org>
parents: 501
diff changeset
121 except AttributeError:
debcf5dd404a QuickFrontend, Primitivus, Wix: special entities management:
Goffi <goffi@goffi.org>
parents: 501
diff changeset
122 pass
685
0b9bd47dffcd primitivus, wix: auto-display MUC dialog after it has been joined:
souliane <souliane@mailoo.org>
parents: 646
diff changeset
123 idx += 1
125
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
124
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
125 def putAlert(self, jid):
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
126 """Put an alert on the jid to get attention from user (e.g. for new message)"""
688
f7878ad3c846 tools: renamed tools.jid.JID attribute "short" to "bare"
souliane <souliane@mailoo.org>
parents: 685
diff changeset
127 self.alert_jid.add(jid.bare)
501
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 500
diff changeset
128 self.update()
125
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
129
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
130 def __groupClicked(self, group_wid):
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
131 group = self.groups[group_wid.getValue()]
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
132 group[0] = not group[0]
501
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 500
diff changeset
133 self.update()
125
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
134 self.setFocus(group_wid.getValue())
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 121
diff changeset
135
125
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
136 def __contactClicked(self, contact_wid, selected):
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
137 self.selected = contact_wid.data
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
138 for widget in self.frame.body.body:
222
3198bfd66daa primitivus: refactoring to use urwid-satext which is now a separate project
Goffi <goffi@goffi.org>
parents: 201
diff changeset
139 if widget.__class__ == sat_widgets.SelectableText:
125
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
140 widget.setState(widget.data == self.selected, invisible=True)
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
141 if self.selected in self.alert_jid:
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
142 self.alert_jid.remove(self.selected)
524
0bb595eff25b primitivus: Primitivus is now modal (vi-like behaviour):
Goffi <goffi@goffi.org>
parents: 511
diff changeset
143 self.host.modeHint('INSERTION')
501
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 500
diff changeset
144 self.update()
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 116
diff changeset
145 self._emit('click')
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 116
diff changeset
146
1230
3abc6563a0d2 primitivus: implement parameter "Show empty groups"
souliane <souliane@mailoo.org>
parents: 1229
diff changeset
147 def __buildContact(self, content, contacts):
125
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
148 """Add contact representation in widget list
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
149 @param content: widget list, e.g. SimpleListWalker
1230
3abc6563a0d2 primitivus: implement parameter "Show empty groups"
souliane <souliane@mailoo.org>
parents: 1229
diff changeset
150 @param contacts (list): list of JID userhosts"""
3abc6563a0d2 primitivus: implement parameter "Show empty groups"
souliane <souliane@mailoo.org>
parents: 1229
diff changeset
151 if not contacts:
3abc6563a0d2 primitivus: implement parameter "Show empty groups"
souliane <souliane@mailoo.org>
parents: 1229
diff changeset
152 return
3abc6563a0d2 primitivus: implement parameter "Show empty groups"
souliane <souliane@mailoo.org>
parents: 1229
diff changeset
153 widgets = [] # list of built widgets
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
154
125
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
155 for contact in contacts:
1229
03661d1b216a primitivus: implement "Show offline contacts" parameter (sync with "DISCONNECTED_HIDE" action key)
souliane <souliane@mailoo.org>
parents: 1183
diff changeset
156 if contact.startswith(C.PRIVATE_PREFIX):
510
886754295efe quick frontend, primitivus, wix: MUC private messages management
Goffi <goffi@goffi.org>
parents: 507
diff changeset
157 contact_disp = ('alert' if contact in self.alert_jid else "show_normal", unescapePrivate(contact))
886754295efe quick frontend, primitivus, wix: MUC private messages management
Goffi <goffi@goffi.org>
parents: 507
diff changeset
158 show_icon = ''
886754295efe quick frontend, primitivus, wix: MUC private messages management
Goffi <goffi@goffi.org>
parents: 507
diff changeset
159 status = ''
886754295efe quick frontend, primitivus, wix: MUC private messages management
Goffi <goffi@goffi.org>
parents: 507
diff changeset
160 else:
1230
3abc6563a0d2 primitivus: implement parameter "Show empty groups"
souliane <souliane@mailoo.org>
parents: 1229
diff changeset
161 jid = JID(contact)
510
886754295efe quick frontend, primitivus, wix: MUC private messages management
Goffi <goffi@goffi.org>
parents: 507
diff changeset
162 name = self.getCache(jid, 'name')
886754295efe quick frontend, primitivus, wix: MUC private messages management
Goffi <goffi@goffi.org>
parents: 507
diff changeset
163 nick = self.getCache(jid, 'nick')
886754295efe quick frontend, primitivus, wix: MUC private messages management
Goffi <goffi@goffi.org>
parents: 507
diff changeset
164 status = self.getCache(jid, 'status')
886754295efe quick frontend, primitivus, wix: MUC private messages management
Goffi <goffi@goffi.org>
parents: 507
diff changeset
165 show = self.getCache(jid, 'show')
1230
3abc6563a0d2 primitivus: implement parameter "Show empty groups"
souliane <souliane@mailoo.org>
parents: 1229
diff changeset
166 if show is None:
510
886754295efe quick frontend, primitivus, wix: MUC private messages management
Goffi <goffi@goffi.org>
parents: 507
diff changeset
167 show = "unavailable"
1230
3abc6563a0d2 primitivus: implement parameter "Show empty groups"
souliane <souliane@mailoo.org>
parents: 1229
diff changeset
168 if not self.contactToShow(contact):
510
886754295efe quick frontend, primitivus, wix: MUC private messages management
Goffi <goffi@goffi.org>
parents: 507
diff changeset
169 continue
1229
03661d1b216a primitivus: implement "Show offline contacts" parameter (sync with "DISCONNECTED_HIDE" action key)
souliane <souliane@mailoo.org>
parents: 1183
diff changeset
170 show_icon, show_attr = C.PRESENCE.get(show, ('', 'default'))
688
f7878ad3c846 tools: renamed tools.jid.JID attribute "short" to "bare"
souliane <souliane@mailoo.org>
parents: 685
diff changeset
171 contact_disp = ('alert' if contact in self.alert_jid else show_attr, nick or name or jid.node or jid.bare)
1230
3abc6563a0d2 primitivus: implement parameter "Show empty groups"
souliane <souliane@mailoo.org>
parents: 1229
diff changeset
172 display = [show_icon + " ", contact_disp]
497
50dd2a0196c0 primitivus: contacts list improvments:
Goffi <goffi@goffi.org>
parents: 480
diff changeset
173 if self.show_status:
1230
3abc6563a0d2 primitivus: implement parameter "Show empty groups"
souliane <souliane@mailoo.org>
parents: 1229
diff changeset
174 status_disp = ('status', "\n " + status) if status else ""
497
50dd2a0196c0 primitivus: contacts list improvments:
Goffi <goffi@goffi.org>
parents: 480
diff changeset
175 display.append(status_disp)
125
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
176 header = '(*) ' if contact in self.alert_jid else ''
497
50dd2a0196c0 primitivus: contacts list improvments:
Goffi <goffi@goffi.org>
parents: 480
diff changeset
177 widget = sat_widgets.SelectableText(display,
1230
3abc6563a0d2 primitivus: implement parameter "Show empty groups"
souliane <souliane@mailoo.org>
parents: 1229
diff changeset
178 selected=contact == self.selected,
497
50dd2a0196c0 primitivus: contacts list improvments:
Goffi <goffi@goffi.org>
parents: 480
diff changeset
179 header=header)
192
879beacb8e16 Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents: 184
diff changeset
180 widget.data = contact
1230
3abc6563a0d2 primitivus: implement parameter "Show empty groups"
souliane <souliane@mailoo.org>
parents: 1229
diff changeset
181 widget.comp = contact_disp[1].lower() # value to use for sorting
501
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 500
diff changeset
182 widgets.append(widget)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
183
501
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 500
diff changeset
184 widgets.sort(key=lambda widget: widget.comp)
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 500
diff changeset
185
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 500
diff changeset
186 for widget in widgets:
125
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
187 content.append(widget)
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
188 urwid.connect_signal(widget, 'change', self.__contactClicked)
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
189
502
debcf5dd404a QuickFrontend, Primitivus, Wix: special entities management:
Goffi <goffi@goffi.org>
parents: 501
diff changeset
190 def __buildSpecials(self, content):
debcf5dd404a QuickFrontend, Primitivus, Wix: special entities management:
Goffi <goffi@goffi.org>
parents: 501
diff changeset
191 """Build the special entities"""
510
886754295efe quick frontend, primitivus, wix: MUC private messages management
Goffi <goffi@goffi.org>
parents: 507
diff changeset
192 specials = self.specials.keys()
502
debcf5dd404a QuickFrontend, Primitivus, Wix: special entities management:
Goffi <goffi@goffi.org>
parents: 501
diff changeset
193 specials.sort()
debcf5dd404a QuickFrontend, Primitivus, Wix: special entities management:
Goffi <goffi@goffi.org>
parents: 501
diff changeset
194 for special in specials:
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
195 jid=JID(special)
502
debcf5dd404a QuickFrontend, Primitivus, Wix: special entities management:
Goffi <goffi@goffi.org>
parents: 501
diff changeset
196 name = self.getCache(jid, 'name')
debcf5dd404a QuickFrontend, Primitivus, Wix: special entities management:
Goffi <goffi@goffi.org>
parents: 501
diff changeset
197 nick = self.getCache(jid, 'nick')
688
f7878ad3c846 tools: renamed tools.jid.JID attribute "short" to "bare"
souliane <souliane@mailoo.org>
parents: 685
diff changeset
198 special_disp = ('alert' if special in self.alert_jid else 'default', nick or name or jid.node or jid.bare)
502
debcf5dd404a QuickFrontend, Primitivus, Wix: special entities management:
Goffi <goffi@goffi.org>
parents: 501
diff changeset
199 display = [ " " , special_disp]
debcf5dd404a QuickFrontend, Primitivus, Wix: special entities management:
Goffi <goffi@goffi.org>
parents: 501
diff changeset
200 header = '(*) ' if special in self.alert_jid else ''
debcf5dd404a QuickFrontend, Primitivus, Wix: special entities management:
Goffi <goffi@goffi.org>
parents: 501
diff changeset
201 widget = sat_widgets.SelectableText(display,
debcf5dd404a QuickFrontend, Primitivus, Wix: special entities management:
Goffi <goffi@goffi.org>
parents: 501
diff changeset
202 selected = special==self.selected,
debcf5dd404a QuickFrontend, Primitivus, Wix: special entities management:
Goffi <goffi@goffi.org>
parents: 501
diff changeset
203 header=header)
debcf5dd404a QuickFrontend, Primitivus, Wix: special entities management:
Goffi <goffi@goffi.org>
parents: 501
diff changeset
204 widget.data = special
debcf5dd404a QuickFrontend, Primitivus, Wix: special entities management:
Goffi <goffi@goffi.org>
parents: 501
diff changeset
205 content.append(widget)
debcf5dd404a QuickFrontend, Primitivus, Wix: special entities management:
Goffi <goffi@goffi.org>
parents: 501
diff changeset
206 urwid.connect_signal(widget, 'change', self.__contactClicked)
debcf5dd404a QuickFrontend, Primitivus, Wix: special entities management:
Goffi <goffi@goffi.org>
parents: 501
diff changeset
207
125
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
208 def __buildList(self):
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
209 """Build the main contact list widget"""
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
210 content = urwid.SimpleListWalker([])
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
211
502
debcf5dd404a QuickFrontend, Primitivus, Wix: special entities management:
Goffi <goffi@goffi.org>
parents: 501
diff changeset
212 self.__buildSpecials(content)
510
886754295efe quick frontend, primitivus, wix: MUC private messages management
Goffi <goffi@goffi.org>
parents: 507
diff changeset
213 if self.specials:
502
debcf5dd404a QuickFrontend, Primitivus, Wix: special entities management:
Goffi <goffi@goffi.org>
parents: 501
diff changeset
214 content.append(urwid.Divider('='))
debcf5dd404a QuickFrontend, Primitivus, Wix: special entities management:
Goffi <goffi@goffi.org>
parents: 501
diff changeset
215
125
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
216 group_keys = self.groups.keys()
1230
3abc6563a0d2 primitivus: implement parameter "Show empty groups"
souliane <souliane@mailoo.org>
parents: 1229
diff changeset
217 group_keys.sort(key=lambda x: x.lower() if x else x)
125
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
218 for key in group_keys:
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
219 unfolded = self.groups[key][0]
1230
3abc6563a0d2 primitivus: implement parameter "Show empty groups"
souliane <souliane@mailoo.org>
parents: 1229
diff changeset
220 contacts = list(self.groups[key][1])
3abc6563a0d2 primitivus: implement parameter "Show empty groups"
souliane <souliane@mailoo.org>
parents: 1229
diff changeset
221 if key is not None and (self.nonEmptyGroup(contacts) or self.show_empty_groups):
125
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
222 header = '[-]' if unfolded else '[+]'
1230
3abc6563a0d2 primitivus: implement parameter "Show empty groups"
souliane <souliane@mailoo.org>
parents: 1229
diff changeset
223 widget = sat_widgets.ClickableText(key, header=header + ' ')
125
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
224 content.append(widget)
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
225 urwid.connect_signal(widget, 'click', self.__groupClicked)
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
226 if unfolded:
1230
3abc6563a0d2 primitivus: implement parameter "Show empty groups"
souliane <souliane@mailoo.org>
parents: 1229
diff changeset
227 self.__buildContact(content, contacts)
125
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
228 return urwid.ListBox(content)
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
229
1230
3abc6563a0d2 primitivus: implement parameter "Show empty groups"
souliane <souliane@mailoo.org>
parents: 1229
diff changeset
230 def contactToShow(self, contact):
3abc6563a0d2 primitivus: implement parameter "Show empty groups"
souliane <souliane@mailoo.org>
parents: 1229
diff changeset
231 """Tell if the contact should be showed or hidden.
3abc6563a0d2 primitivus: implement parameter "Show empty groups"
souliane <souliane@mailoo.org>
parents: 1229
diff changeset
232
3abc6563a0d2 primitivus: implement parameter "Show empty groups"
souliane <souliane@mailoo.org>
parents: 1229
diff changeset
233 @param contact (str): JID userhost of the contact
3abc6563a0d2 primitivus: implement parameter "Show empty groups"
souliane <souliane@mailoo.org>
parents: 1229
diff changeset
234 @return: True if that contact should be showed in the list"""
1231
93a5e2673929 primitivus: fixes displaying online contacts when "Show offline contacts" is False
souliane <souliane@mailoo.org>
parents: 1230
diff changeset
235 show = self.getCache(JID(contact), 'show')
93a5e2673929 primitivus: fixes displaying online contacts when "Show offline contacts" is False
souliane <souliane@mailoo.org>
parents: 1230
diff changeset
236 return (show is not None and show != "unavailable") or \
93a5e2673929 primitivus: fixes displaying online contacts when "Show offline contacts" is False
souliane <souliane@mailoo.org>
parents: 1230
diff changeset
237 self.show_disconnected or contact in self.alert_jid or contact == self.selected
1230
3abc6563a0d2 primitivus: implement parameter "Show empty groups"
souliane <souliane@mailoo.org>
parents: 1229
diff changeset
238
3abc6563a0d2 primitivus: implement parameter "Show empty groups"
souliane <souliane@mailoo.org>
parents: 1229
diff changeset
239 def nonEmptyGroup(self, contacts):
3abc6563a0d2 primitivus: implement parameter "Show empty groups"
souliane <souliane@mailoo.org>
parents: 1229
diff changeset
240 """Tell if a contact group contains some contacts to show.
3abc6563a0d2 primitivus: implement parameter "Show empty groups"
souliane <souliane@mailoo.org>
parents: 1229
diff changeset
241
3abc6563a0d2 primitivus: implement parameter "Show empty groups"
souliane <souliane@mailoo.org>
parents: 1229
diff changeset
242 @param contacts (list[str]): list of JID userhosts
3abc6563a0d2 primitivus: implement parameter "Show empty groups"
souliane <souliane@mailoo.org>
parents: 1229
diff changeset
243 @return: bool
3abc6563a0d2 primitivus: implement parameter "Show empty groups"
souliane <souliane@mailoo.org>
parents: 1229
diff changeset
244 """
3abc6563a0d2 primitivus: implement parameter "Show empty groups"
souliane <souliane@mailoo.org>
parents: 1229
diff changeset
245 for contact in contacts:
3abc6563a0d2 primitivus: implement parameter "Show empty groups"
souliane <souliane@mailoo.org>
parents: 1229
diff changeset
246 if self.contactToShow(contact):
3abc6563a0d2 primitivus: implement parameter "Show empty groups"
souliane <souliane@mailoo.org>
parents: 1229
diff changeset
247 return True
3abc6563a0d2 primitivus: implement parameter "Show empty groups"
souliane <souliane@mailoo.org>
parents: 1229
diff changeset
248 return False
3abc6563a0d2 primitivus: implement parameter "Show empty groups"
souliane <souliane@mailoo.org>
parents: 1229
diff changeset
249
164
5d7a011d78ba Primitivus: contact list: new method UnselectAll
Goffi <goffi@goffi.org>
parents: 153
diff changeset
250 def unselectAll(self):
5d7a011d78ba Primitivus: contact list: new method UnselectAll
Goffi <goffi@goffi.org>
parents: 153
diff changeset
251 """Unselect all contacts"""
168
a2655a0a4eac Primitivus: 2 bugs fixes
Goffi <goffi@goffi.org>
parents: 164
diff changeset
252 self.selected = None
164
5d7a011d78ba Primitivus: contact list: new method UnselectAll
Goffi <goffi@goffi.org>
parents: 153
diff changeset
253 for widget in self.frame.body.body:
222
3198bfd66daa primitivus: refactoring to use urwid-satext which is now a separate project
Goffi <goffi@goffi.org>
parents: 201
diff changeset
254 if widget.__class__ == sat_widgets.SelectableText:
164
5d7a011d78ba Primitivus: contact list: new method UnselectAll
Goffi <goffi@goffi.org>
parents: 153
diff changeset
255 widget.setState(False, invisible=True)
5d7a011d78ba Primitivus: contact list: new method UnselectAll
Goffi <goffi@goffi.org>
parents: 153
diff changeset
256
501
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 500
diff changeset
257 def getContact(self):
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 116
diff changeset
258 """Return contact currently selected"""
125
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
259 return self.selected
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
260
501
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 500
diff changeset
261 def clearContacts(self):
116
7c482ecac0ff primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
262 """clear all the contact list"""
510
886754295efe quick frontend, primitivus, wix: MUC private messages management
Goffi <goffi@goffi.org>
parents: 507
diff changeset
263 QuickContactList.clearContacts(self)
125
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
264 self.groups={}
153
f197b52796ee Primitivus: begining of management for actionResult
Goffi <goffi@goffi.org>
parents: 128
diff changeset
265 self.selected = None
184
8ea1510d474b Primitivus: fixed contact list clear
Goffi <goffi@goffi.org>
parents: 168
diff changeset
266 self.unselectAll()
501
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 500
diff changeset
267 self.update()
116
7c482ecac0ff primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
268
501
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 500
diff changeset
269 def replace(self, jid, groups=None, attributes=None):
1000
6f1e03068b5f primitivus: fixes contact group update
souliane <souliane@mailoo.org>
parents: 911
diff changeset
270 """Add a contact to the list if doesn't exist, else update it.
6f1e03068b5f primitivus: fixes contact group update
souliane <souliane@mailoo.org>
parents: 911
diff changeset
271
1058
0a9986452bba frontends: fixes bug with private message introduced with revision 1000 (6f1e03068b5f) + display messages from contacts not in roster
souliane <souliane@mailoo.org>
parents: 1000
diff changeset
272 This method can be called with groups=None for the purpose of updating
0a9986452bba frontends: fixes bug with private message introduced with revision 1000 (6f1e03068b5f) + display messages from contacts not in roster
souliane <souliane@mailoo.org>
parents: 1000
diff changeset
273 the contact's attributes (e.g. nickname). In that case, the groups
0a9986452bba frontends: fixes bug with private message introduced with revision 1000 (6f1e03068b5f) + display messages from contacts not in roster
souliane <souliane@mailoo.org>
parents: 1000
diff changeset
274 attribute must not be set to the default group but ignored. If not,
0a9986452bba frontends: fixes bug with private message introduced with revision 1000 (6f1e03068b5f) + display messages from contacts not in roster
souliane <souliane@mailoo.org>
parents: 1000
diff changeset
275 you may move your contact from its actual group(s) to the default one.
0a9986452bba frontends: fixes bug with private message introduced with revision 1000 (6f1e03068b5f) + display messages from contacts not in roster
souliane <souliane@mailoo.org>
parents: 1000
diff changeset
276
0a9986452bba frontends: fixes bug with private message introduced with revision 1000 (6f1e03068b5f) + display messages from contacts not in roster
souliane <souliane@mailoo.org>
parents: 1000
diff changeset
277 None value for 'groups' has a different meaning than [None] which is for the default group.
0a9986452bba frontends: fixes bug with private message introduced with revision 1000 (6f1e03068b5f) + display messages from contacts not in roster
souliane <souliane@mailoo.org>
parents: 1000
diff changeset
278
1000
6f1e03068b5f primitivus: fixes contact group update
souliane <souliane@mailoo.org>
parents: 911
diff changeset
279 @param jid (JID)
6f1e03068b5f primitivus: fixes contact group update
souliane <souliane@mailoo.org>
parents: 911
diff changeset
280 @param groups (list): list of groups or None to ignore the groups membership.
6f1e03068b5f primitivus: fixes contact group update
souliane <souliane@mailoo.org>
parents: 911
diff changeset
281 @param attributes (dict)
6f1e03068b5f primitivus: fixes contact group update
souliane <souliane@mailoo.org>
parents: 911
diff changeset
282 """
1058
0a9986452bba frontends: fixes bug with private message introduced with revision 1000 (6f1e03068b5f) + display messages from contacts not in roster
souliane <souliane@mailoo.org>
parents: 1000
diff changeset
283 QuickContactList.replace(self, jid, groups, attributes) # eventually change the nickname
688
f7878ad3c846 tools: renamed tools.jid.JID attribute "short" to "bare"
souliane <souliane@mailoo.org>
parents: 685
diff changeset
284 if jid.bare in self.specials:
502
debcf5dd404a QuickFrontend, Primitivus, Wix: special entities management:
Goffi <goffi@goffi.org>
parents: 501
diff changeset
285 return
1058
0a9986452bba frontends: fixes bug with private message introduced with revision 1000 (6f1e03068b5f) + display messages from contacts not in roster
souliane <souliane@mailoo.org>
parents: 1000
diff changeset
286 if groups is None:
0a9986452bba frontends: fixes bug with private message introduced with revision 1000 (6f1e03068b5f) + display messages from contacts not in roster
souliane <souliane@mailoo.org>
parents: 1000
diff changeset
287 self.update()
0a9986452bba frontends: fixes bug with private message introduced with revision 1000 (6f1e03068b5f) + display messages from contacts not in roster
souliane <souliane@mailoo.org>
parents: 1000
diff changeset
288 return
153
f197b52796ee Primitivus: begining of management for actionResult
Goffi <goffi@goffi.org>
parents: 128
diff changeset
289 assert isinstance(jid, JID)
1058
0a9986452bba frontends: fixes bug with private message introduced with revision 1000 (6f1e03068b5f) + display messages from contacts not in roster
souliane <souliane@mailoo.org>
parents: 1000
diff changeset
290 assert isinstance(groups, list)
0a9986452bba frontends: fixes bug with private message introduced with revision 1000 (6f1e03068b5f) + display messages from contacts not in roster
souliane <souliane@mailoo.org>
parents: 1000
diff changeset
291 if groups == []:
0a9986452bba frontends: fixes bug with private message introduced with revision 1000 (6f1e03068b5f) + display messages from contacts not in roster
souliane <souliane@mailoo.org>
parents: 1000
diff changeset
292 groups = [None] # [None] is the default group
0a9986452bba frontends: fixes bug with private message introduced with revision 1000 (6f1e03068b5f) + display messages from contacts not in roster
souliane <souliane@mailoo.org>
parents: 1000
diff changeset
293 for group in [group for group in self.groups if group not in groups]:
0a9986452bba frontends: fixes bug with private message introduced with revision 1000 (6f1e03068b5f) + display messages from contacts not in roster
souliane <souliane@mailoo.org>
parents: 1000
diff changeset
294 try: # remove the contact from a previous group
0a9986452bba frontends: fixes bug with private message introduced with revision 1000 (6f1e03068b5f) + display messages from contacts not in roster
souliane <souliane@mailoo.org>
parents: 1000
diff changeset
295 self.groups[group][1].remove(jid.bare)
0a9986452bba frontends: fixes bug with private message introduced with revision 1000 (6f1e03068b5f) + display messages from contacts not in roster
souliane <souliane@mailoo.org>
parents: 1000
diff changeset
296 except KeyError:
0a9986452bba frontends: fixes bug with private message introduced with revision 1000 (6f1e03068b5f) + display messages from contacts not in roster
souliane <souliane@mailoo.org>
parents: 1000
diff changeset
297 pass
0a9986452bba frontends: fixes bug with private message introduced with revision 1000 (6f1e03068b5f) + display messages from contacts not in roster
souliane <souliane@mailoo.org>
parents: 1000
diff changeset
298 for group in groups:
0a9986452bba frontends: fixes bug with private message introduced with revision 1000 (6f1e03068b5f) + display messages from contacts not in roster
souliane <souliane@mailoo.org>
parents: 1000
diff changeset
299 if group not in self.groups:
0a9986452bba frontends: fixes bug with private message introduced with revision 1000 (6f1e03068b5f) + display messages from contacts not in roster
souliane <souliane@mailoo.org>
parents: 1000
diff changeset
300 self.groups[group] = [True, set()] # [unfold, list_of_contacts]
0a9986452bba frontends: fixes bug with private message introduced with revision 1000 (6f1e03068b5f) + display messages from contacts not in roster
souliane <souliane@mailoo.org>
parents: 1000
diff changeset
301 self.groups[group][1].add(jid.bare)
501
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 500
diff changeset
302 self.update()
125
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
303
510
886754295efe quick frontend, primitivus, wix: MUC private messages management
Goffi <goffi@goffi.org>
parents: 507
diff changeset
304 def remove(self, jid):
116
7c482ecac0ff primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
305 """remove a contact from the list"""
510
886754295efe quick frontend, primitivus, wix: MUC private messages management
Goffi <goffi@goffi.org>
parents: 507
diff changeset
306 QuickContactList.remove(self, jid)
125
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
307 groups_to_remove = []
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
308 for group in self.groups:
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
309 contacts = self.groups[group][1]
688
f7878ad3c846 tools: renamed tools.jid.JID attribute "short" to "bare"
souliane <souliane@mailoo.org>
parents: 685
diff changeset
310 if jid.bare in contacts:
f7878ad3c846 tools: renamed tools.jid.JID attribute "short" to "bare"
souliane <souliane@mailoo.org>
parents: 685
diff changeset
311 contacts.remove(jid.bare)
125
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
312 if not len(contacts):
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
313 groups_to_remove.append(group)
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
314 for group in groups_to_remove:
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
315 del self.groups[group]
501
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 500
diff changeset
316 self.update()
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
317
1000
6f1e03068b5f primitivus: fixes contact group update
souliane <souliane@mailoo.org>
parents: 911
diff changeset
318 def add(self, jid, param_groups=None):
116
7c482ecac0ff primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
319 """add a contact to the list"""
1058
0a9986452bba frontends: fixes bug with private message introduced with revision 1000 (6f1e03068b5f) + display messages from contacts not in roster
souliane <souliane@mailoo.org>
parents: 1000
diff changeset
320 self.replace(jid, param_groups if param_groups else [None])
116
7c482ecac0ff primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
321
685
0b9bd47dffcd primitivus, wix: auto-display MUC dialog after it has been joined:
souliane <souliane@mailoo.org>
parents: 646
diff changeset
322 def setSpecial(self, special_jid, special_type, show=False):
502
debcf5dd404a QuickFrontend, Primitivus, Wix: special entities management:
Goffi <goffi@goffi.org>
parents: 501
diff changeset
323 """Set entity as a special
812
084b52afdceb frontends: fixed /me usage + renamed a couple of "type" parameters to type_
Goffi <goffi@goffi.org>
parents: 811
diff changeset
324 @param special_jid: jid of the entity
084b52afdceb frontends: fixed /me usage + renamed a couple of "type" parameters to type_
Goffi <goffi@goffi.org>
parents: 811
diff changeset
325 @param special_type: special type (e.g.: "MUC")
685
0b9bd47dffcd primitivus, wix: auto-display MUC dialog after it has been joined:
souliane <souliane@mailoo.org>
parents: 646
diff changeset
326 @param show: True to display the dialog to chat with this entity
502
debcf5dd404a QuickFrontend, Primitivus, Wix: special entities management:
Goffi <goffi@goffi.org>
parents: 501
diff changeset
327 """
685
0b9bd47dffcd primitivus, wix: auto-display MUC dialog after it has been joined:
souliane <souliane@mailoo.org>
parents: 646
diff changeset
328 QuickContactList.setSpecial(self, special_jid, special_type, show)
502
debcf5dd404a QuickFrontend, Primitivus, Wix: special entities management:
Goffi <goffi@goffi.org>
parents: 501
diff changeset
329 if None in self.groups:
685
0b9bd47dffcd primitivus, wix: auto-display MUC dialog after it has been joined:
souliane <souliane@mailoo.org>
parents: 646
diff changeset
330 folded, group_jids = self.groups[None]
502
debcf5dd404a QuickFrontend, Primitivus, Wix: special entities management:
Goffi <goffi@goffi.org>
parents: 501
diff changeset
331 for group_jid in group_jids:
688
f7878ad3c846 tools: renamed tools.jid.JID attribute "short" to "bare"
souliane <souliane@mailoo.org>
parents: 685
diff changeset
332 if JID(group_jid).bare == special_jid.bare:
502
debcf5dd404a QuickFrontend, Primitivus, Wix: special entities management:
Goffi <goffi@goffi.org>
parents: 501
diff changeset
333 group_jids.remove(group_jid)
debcf5dd404a QuickFrontend, Primitivus, Wix: special entities management:
Goffi <goffi@goffi.org>
parents: 501
diff changeset
334 break
debcf5dd404a QuickFrontend, Primitivus, Wix: special entities management:
Goffi <goffi@goffi.org>
parents: 501
diff changeset
335 self.update()
685
0b9bd47dffcd primitivus, wix: auto-display MUC dialog after it has been joined:
souliane <souliane@mailoo.org>
parents: 646
diff changeset
336 if show:
0b9bd47dffcd primitivus, wix: auto-display MUC dialog after it has been joined:
souliane <souliane@mailoo.org>
parents: 646
diff changeset
337 # also display the dialog for this room
0b9bd47dffcd primitivus, wix: auto-display MUC dialog after it has been joined:
souliane <souliane@mailoo.org>
parents: 646
diff changeset
338 self.setFocus(special_jid, True)
0b9bd47dffcd primitivus, wix: auto-display MUC dialog after it has been joined:
souliane <souliane@mailoo.org>
parents: 646
diff changeset
339 self.host.redraw()
502
debcf5dd404a QuickFrontend, Primitivus, Wix: special entities management:
Goffi <goffi@goffi.org>
parents: 501
diff changeset
340
debcf5dd404a QuickFrontend, Primitivus, Wix: special entities management:
Goffi <goffi@goffi.org>
parents: 501
diff changeset
341 def updatePresence(self, jid, show, priority, statuses):
debcf5dd404a QuickFrontend, Primitivus, Wix: special entities management:
Goffi <goffi@goffi.org>
parents: 501
diff changeset
342 #XXX: for the moment, we ignore presence updates for special entities
688
f7878ad3c846 tools: renamed tools.jid.JID attribute "short" to "bare"
souliane <souliane@mailoo.org>
parents: 685
diff changeset
343 if jid.bare not in self.specials:
502
debcf5dd404a QuickFrontend, Primitivus, Wix: special entities management:
Goffi <goffi@goffi.org>
parents: 501
diff changeset
344 QuickContactList.updatePresence(self, jid, show, priority, statuses)
1229
03661d1b216a primitivus: implement "Show offline contacts" parameter (sync with "DISCONNECTED_HIDE" action key)
souliane <souliane@mailoo.org>
parents: 1183
diff changeset
345
03661d1b216a primitivus: implement "Show offline contacts" parameter (sync with "DISCONNECTED_HIDE" action key)
souliane <souliane@mailoo.org>
parents: 1183
diff changeset
346 def showOfflineContacts(self, show):
03661d1b216a primitivus: implement "Show offline contacts" parameter (sync with "DISCONNECTED_HIDE" action key)
souliane <souliane@mailoo.org>
parents: 1183
diff changeset
347 show = C.bool(show)
03661d1b216a primitivus: implement "Show offline contacts" parameter (sync with "DISCONNECTED_HIDE" action key)
souliane <souliane@mailoo.org>
parents: 1183
diff changeset
348 if self.show_disconnected == show:
03661d1b216a primitivus: implement "Show offline contacts" parameter (sync with "DISCONNECTED_HIDE" action key)
souliane <souliane@mailoo.org>
parents: 1183
diff changeset
349 return
03661d1b216a primitivus: implement "Show offline contacts" parameter (sync with "DISCONNECTED_HIDE" action key)
souliane <souliane@mailoo.org>
parents: 1183
diff changeset
350 self.show_disconnected = show
03661d1b216a primitivus: implement "Show offline contacts" parameter (sync with "DISCONNECTED_HIDE" action key)
souliane <souliane@mailoo.org>
parents: 1183
diff changeset
351 self.update()
1230
3abc6563a0d2 primitivus: implement parameter "Show empty groups"
souliane <souliane@mailoo.org>
parents: 1229
diff changeset
352
3abc6563a0d2 primitivus: implement parameter "Show empty groups"
souliane <souliane@mailoo.org>
parents: 1229
diff changeset
353 def showEmptyGroups(self, show):
3abc6563a0d2 primitivus: implement parameter "Show empty groups"
souliane <souliane@mailoo.org>
parents: 1229
diff changeset
354 show = C.bool(show)
3abc6563a0d2 primitivus: implement parameter "Show empty groups"
souliane <souliane@mailoo.org>
parents: 1229
diff changeset
355 if self.show_empty_groups == show:
3abc6563a0d2 primitivus: implement parameter "Show empty groups"
souliane <souliane@mailoo.org>
parents: 1229
diff changeset
356 return
3abc6563a0d2 primitivus: implement parameter "Show empty groups"
souliane <souliane@mailoo.org>
parents: 1229
diff changeset
357 self.show_empty_groups = show
3abc6563a0d2 primitivus: implement parameter "Show empty groups"
souliane <souliane@mailoo.org>
parents: 1229
diff changeset
358 self.update()