annotate frontends/src/primitivus/contact_list.py @ 2009:90134b2e3dc4

primitivus, quick_frontends: show global notifications counter in contact_list + method to get these notifications in QuickApp
author Goffi <goffi@goffi.org>
date Sun, 17 Jul 2016 17:32:46 +0200
parents a9908e751c42
children 20fb71b656e3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1934
2daf7b4c6756 use of /usr/bin/env instead of /usr/bin/python in shebang
Goffi <goffi@goffi.org>
parents: 1766
diff changeset
1 #!/usr/bin/env python2
116
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
1766
d17772b0fe22 copyright update
Goffi <goffi@goffi.org>
parents: 1658
diff changeset
5 # Copyright (C) 2009-2016 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
737
378af36155c2 frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents: 736
diff changeset
24 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
25 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
26 from sat_frontends.primitivus.keys import action_key_map as a_key
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
27 from sat_frontends.primitivus.widget import PrimitivusWidget
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
28 from sat_frontends.tools import jid
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__)
1938
011eff37e21d quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
31 from sat_frontends.quick_frontend import quick_widgets
1158
c0f15e52695a primitivus: use of new keys modules from Urwid SàText
Goffi <goffi@goffi.org>
parents: 1139
diff changeset
32
116
7c482ecac0ff primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
33
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
34 class ContactList(PrimitivusWidget, QuickContactList):
1938
011eff37e21d quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
35 PROFILES_MULTIPLE=False
011eff37e21d quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
36 PROFILES_ALLOW_NONE=False
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 116
diff changeset
37 signals = ['click','change']
1938
011eff37e21d quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
38 # FIXME: Only single profile is managed so far
116
7c482ecac0ff primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
39
1938
011eff37e21d quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
40 def __init__(self, host, target, on_click=None, on_change=None, user_data=None, profiles=None):
011eff37e21d quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
41 QuickContactList.__init__(self, host, profiles)
011eff37e21d quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
42 self.contact_list = self.host.contact_lists[self.profile]
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
43
116
7c482ecac0ff primitivus: basic contact list, connexion now work \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
44 #we now build the widget
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
45 self.status_bar = StatusBar(host)
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
46 self.frame = sat_widgets.FocusFrame(self._buildList(), None, self.status_bar)
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
47 PrimitivusWidget.__init__(self, self.frame, _(u'Contacts'))
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 116
diff changeset
48 if on_click:
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 116
diff changeset
49 urwid.connect_signal(self, 'click', on_click, user_data)
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 116
diff changeset
50 if on_change:
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 116
diff changeset
51 urwid.connect_signal(self, 'change', on_change, user_data)
2009
90134b2e3dc4 primitivus, quick_frontends: show global notifications counter in contact_list + method to get these notifications in QuickApp
Goffi <goffi@goffi.org>
parents: 1973
diff changeset
52 self.host.addListener('notification', self.onNotification, [self.profile])
90134b2e3dc4 primitivus, quick_frontends: show global notifications counter in contact_list + method to get these notifications in QuickApp
Goffi <goffi@goffi.org>
parents: 1973
diff changeset
53 self.host.addListener('notificationsClear', self.onNotification, [self.profile])
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 116
diff changeset
54
1938
011eff37e21d quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
55 def update(self, entities=None, type_=None, profile=None):
500
00d3679976ab primitivus: keep focus position in contacts list on redraw
Goffi <goffi@goffi.org>
parents: 499
diff changeset
56 """Update display, keep focus"""
1938
011eff37e21d quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
57 # FIXME: full update is done each time, must handle entities, type_ and profile
500
00d3679976ab primitivus: keep focus position in contacts list on redraw
Goffi <goffi@goffi.org>
parents: 499
diff changeset
58 widget, position = self.frame.body.get_focus()
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
59 self.frame.body = self._buildList()
500
00d3679976ab primitivus: keep focus position in contacts list on redraw
Goffi <goffi@goffi.org>
parents: 499
diff changeset
60 if position:
646
f7804c52c754 primitivus: disconnected contact crash fix
Goffi <goffi@goffi.org>
parents: 609
diff changeset
61 try:
911
b12706d164d7 primitivus: removed deprecated use of set_focus
Goffi <goffi@goffi.org>
parents: 812
diff changeset
62 self.frame.body.focus_position = position
646
f7804c52c754 primitivus: disconnected contact crash fix
Goffi <goffi@goffi.org>
parents: 609
diff changeset
63 except IndexError:
f7804c52c754 primitivus: disconnected contact crash fix
Goffi <goffi@goffi.org>
parents: 609
diff changeset
64 pass
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
65 self._invalidate()
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
66 self.host.redraw() # FIXME: check if can be avoided
501
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 500
diff changeset
67
497
50dd2a0196c0 primitivus: contacts list improvments:
Goffi <goffi@goffi.org>
parents: 480
diff changeset
68 def keypress(self, size, key):
1183
f36d7068a44b Primitivus: fixed focus in ContactList:
Goffi <goffi@goffi.org>
parents: 1158
diff changeset
69 # 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
70 # 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
71 if key in sat_widgets.FOCUS_KEYS:
f36d7068a44b Primitivus: fixed focus in ContactList:
Goffi <goffi@goffi.org>
parents: 1158
diff changeset
72 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
73 (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
74 return key
1158
c0f15e52695a primitivus: use of new keys modules from Urwid SàText
Goffi <goffi@goffi.org>
parents: 1139
diff changeset
75 if key == a_key['STATUS_HIDE']: #user wants to (un)hide contacts' statuses
1938
011eff37e21d quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
76 self.contact_list.show_status = not self.contact_list.show_status
501
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 500
diff changeset
77 self.update()
1158
c0f15e52695a primitivus: use of new keys modules from Urwid SàText
Goffi <goffi@goffi.org>
parents: 1139
diff changeset
78 elif key == a_key['DISCONNECTED_HIDE']: #user wants to (un)hide disconnected contacts
1938
011eff37e21d quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
79 self.host.bridge.setParam(C.SHOW_OFFLINE_CONTACTS, C.boolConst(not self.contact_list.show_disconnected), "General", profile_key=self.profile)
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
80 elif key == a_key['RESOURCES_HIDE']: #user wants to (un)hide contacts resources
1938
011eff37e21d quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
81 self.contact_list.showResources(not self.contact_list.show_resources)
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
82 self.update()
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
83 return super(ContactList, self).keypress(size, key)
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
84
1938
011eff37e21d quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
85 # QuickWidget methods
011eff37e21d quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
86
011eff37e21d quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
87 @staticmethod
011eff37e21d quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
88 def getWidgetHash(target, profiles):
011eff37e21d quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
89 profiles = sorted(profiles)
011eff37e21d quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
90 return tuple(profiles)
011eff37e21d quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
91
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
92 # modify the contact list
125
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
93
685
0b9bd47dffcd primitivus, wix: auto-display MUC dialog after it has been joined:
souliane <souliane@mailoo.org>
parents: 646
diff changeset
94 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
95 """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
96 pass in text a sat_frontends.tools.jid.JID (it's a subclass of unicode).
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
97
685
0b9bd47dffcd primitivus, wix: auto-display MUC dialog after it has been joined:
souliane <souliane@mailoo.org>
parents: 646
diff changeset
98 @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
99 @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
100 """
125
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
101 idx = 0
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
102 for widget in self.frame.body.body:
502
debcf5dd404a QuickFrontend, Primitivus, Wix: special entities management:
Goffi <goffi@goffi.org>
parents: 501
diff changeset
103 try:
685
0b9bd47dffcd primitivus, wix: auto-display MUC dialog after it has been joined:
souliane <souliane@mailoo.org>
parents: 646
diff changeset
104 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
105 # contact group
0b9bd47dffcd primitivus, wix: auto-display MUC dialog after it has been joined:
souliane <souliane@mailoo.org>
parents: 646
diff changeset
106 value = widget.getValue()
0b9bd47dffcd primitivus, wix: auto-display MUC dialog after it has been joined:
souliane <souliane@mailoo.org>
parents: 646
diff changeset
107 elif isinstance(widget, sat_widgets.SelectableText):
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
108 # contact or muc
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
109 value = widget.data
685
0b9bd47dffcd primitivus, wix: auto-display MUC dialog after it has been joined:
souliane <souliane@mailoo.org>
parents: 646
diff changeset
110 else:
0b9bd47dffcd primitivus, wix: auto-display MUC dialog after it has been joined:
souliane <souliane@mailoo.org>
parents: 646
diff changeset
111 # Divider instance
0b9bd47dffcd primitivus, wix: auto-display MUC dialog after it has been joined:
souliane <souliane@mailoo.org>
parents: 646
diff changeset
112 continue
0b9bd47dffcd primitivus, wix: auto-display MUC dialog after it has been joined:
souliane <souliane@mailoo.org>
parents: 646
diff changeset
113 # 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
114 if text.strip() == value.strip():
911
b12706d164d7 primitivus: removed deprecated use of set_focus
Goffi <goffi@goffi.org>
parents: 812
diff changeset
115 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
116 if select:
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
117 self._contactClicked(False, widget, True)
502
debcf5dd404a QuickFrontend, Primitivus, Wix: special entities management:
Goffi <goffi@goffi.org>
parents: 501
diff changeset
118 return
debcf5dd404a QuickFrontend, Primitivus, Wix: special entities management:
Goffi <goffi@goffi.org>
parents: 501
diff changeset
119 except AttributeError:
debcf5dd404a QuickFrontend, Primitivus, Wix: special entities management:
Goffi <goffi@goffi.org>
parents: 501
diff changeset
120 pass
685
0b9bd47dffcd primitivus, wix: auto-display MUC dialog after it has been joined:
souliane <souliane@mailoo.org>
parents: 646
diff changeset
121 idx += 1
125
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
122
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
123 log.debug(u"Not element found for {} in setFocus".format(text))
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
124
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
125 def specialResourceVisible(self, entity):
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
126 """Assure a resource of a special entity is visible and clickable
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
127
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
128 Mainly used to display private conversation in MUC rooms
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
129 @param entity: full jid of the resource to show
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
130 """
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
131 assert isinstance(entity, jid.JID)
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
132 if entity not in self._special_extras:
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
133 self._special_extras.add(entity)
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
134 self.update()
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
135
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
136 # events
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
137
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
138 def _groupClicked(self, group_wid):
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
139 group = group_wid.getValue()
1938
011eff37e21d quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
140 data = self.contact_list.getGroupData(group)
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
141 data[C.GROUP_DATA_FOLDED] = not data.setdefault(C.GROUP_DATA_FOLDED, False)
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
142 self.setFocus(group)
501
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 500
diff changeset
143 self.update()
125
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
144
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
145 def _contactClicked(self, use_bare_jid, contact_wid, selected):
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
146 """Method called when a contact is clicked
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
147
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
148 @param use_bare_jid: True if use_bare_jid is set in self._buildEntityWidget.
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
149 @param contact_wid: widget of the contact, must have the entity set in data attribute
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
150 @param selected: boolean returned by the widget, telling if it is selected
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
151 """
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
152 entity = contact_wid.data
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
153 self.host.modeHint(C.MODE_INSERTION)
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
154 self._emit('click', entity)
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
155
2009
90134b2e3dc4 primitivus, quick_frontends: show global notifications counter in contact_list + method to get these notifications in QuickApp
Goffi <goffi@goffi.org>
parents: 1973
diff changeset
156 def onNotification(self, entity, notif, profile):
90134b2e3dc4 primitivus, quick_frontends: show global notifications counter in contact_list + method to get these notifications in QuickApp
Goffi <goffi@goffi.org>
parents: 1973
diff changeset
157 notifs = self.host.getNotifs(C.ENTITY_ALL, profile=self.profile)
90134b2e3dc4 primitivus, quick_frontends: show global notifications counter in contact_list + method to get these notifications in QuickApp
Goffi <goffi@goffi.org>
parents: 1973
diff changeset
158 if notifs:
90134b2e3dc4 primitivus, quick_frontends: show global notifications counter in contact_list + method to get these notifications in QuickApp
Goffi <goffi@goffi.org>
parents: 1973
diff changeset
159 self.title_dynamic = u"({})".format(len(notifs))
90134b2e3dc4 primitivus, quick_frontends: show global notifications counter in contact_list + method to get these notifications in QuickApp
Goffi <goffi@goffi.org>
parents: 1973
diff changeset
160 else:
90134b2e3dc4 primitivus, quick_frontends: show global notifications counter in contact_list + method to get these notifications in QuickApp
Goffi <goffi@goffi.org>
parents: 1973
diff changeset
161 self.title_dynamic = None
90134b2e3dc4 primitivus, quick_frontends: show global notifications counter in contact_list + method to get these notifications in QuickApp
Goffi <goffi@goffi.org>
parents: 1973
diff changeset
162 self.host.redraw() # FIXME: should not be necessary
90134b2e3dc4 primitivus, quick_frontends: show global notifications counter in contact_list + method to get these notifications in QuickApp
Goffi <goffi@goffi.org>
parents: 1973
diff changeset
163
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
164 # Methods to build the widget
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
165
1972
02d21a589be2 quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents: 1938
diff changeset
166 def _buildEntityWidget(self, entity, keys=None, use_bare_jid=False, with_notifs=True, with_show_attr=True, markup_prepend=None, markup_append = None):
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
167 """Build one contact markup data
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 121
diff changeset
168
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
169 @param entity (jid.JID): entity to build
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
170 @param keys (iterable): value to markup, in preferred order.
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
171 The first available key will be used.
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
172 If key starts with "cache_", it will be checked in cache,
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
173 else, getattr will be done on entity with the key (e.g. getattr(entity, 'node')).
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
174 If nothing full or keys is None, full entity is used.
1972
02d21a589be2 quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents: 1938
diff changeset
175 @param use_bare_jid (bool): if True, use bare jid for selected comparisons
02d21a589be2 quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents: 1938
diff changeset
176 @param with_notifs (bool): if True, show notification count
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
177 @param with_show_attr (bool): if True, show color corresponding to presence status
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
178 @param markup_prepend (list): markup to prepend to the generated one before building the widget
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
179 @param markup_append (list): markup to append to the generated one before building the widget
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
180 @return (list): markup data are expected by Urwid text widgets
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
181 """
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
182 markup = []
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
183 if use_bare_jid:
1938
011eff37e21d quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
184 selected = {entity.bare for entity in self.contact_list._selected}
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
185 else:
1938
011eff37e21d quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
186 selected = self.contact_list._selected
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
187 if keys is None:
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
188 entity_txt = entity
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
189 else:
1938
011eff37e21d quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
190 cache = self.contact_list.getCache(entity)
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
191 for key in keys:
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
192 if key.startswith('cache_'):
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
193 entity_txt = cache.get(key[6:])
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
194 else:
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
195 entity_txt = getattr(entity, key)
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
196 if entity_txt:
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
197 break
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
198 if not entity_txt:
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
199 entity_txt = entity
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 116
diff changeset
200
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
201 if with_show_attr:
1938
011eff37e21d quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
202 show = self.contact_list.getCache(entity, C.PRESENCE_SHOW)
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
203 if show is None:
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
204 show = C.PRESENCE_UNAVAILABLE
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
205 show_icon, entity_attr = C.PRESENCE.get(show, ('', 'default'))
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
206 markup.insert(0, u"{} ".format(show_icon))
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
207 else:
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
208 entity_attr = 'default'
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
209
1972
02d21a589be2 quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents: 1938
diff changeset
210 notifs = self.host.getNotifs(entity.bare, profile=self.profile)
02d21a589be2 quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents: 1938
diff changeset
211 if notifs:
02d21a589be2 quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents: 1938
diff changeset
212 entity_attr = 'cl_notifs'
02d21a589be2 quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents: 1938
diff changeset
213 header = u'({}) '.format(len(notifs))
1973
a9908e751c42 quick_frontend, primitivus (chat): mention detection in group chat + notification (mention and messages)
Goffi <goffi@goffi.org>
parents: 1972
diff changeset
214 if self.host.getNotifs(entity.bare, C.NOTIFY_MENTION, profile=self.profile):
a9908e751c42 quick_frontend, primitivus (chat): mention detection in group chat + notification (mention and messages)
Goffi <goffi@goffi.org>
parents: 1972
diff changeset
215 header = ('cl_mention', header)
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
216 else:
1972
02d21a589be2 quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents: 1938
diff changeset
217 header = u''
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
218
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
219 markup.append((entity_attr, entity_txt))
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
220 if markup_prepend:
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
221 markup.insert(0, markup_prepend)
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
222 if markup_append:
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
223 markup.extend(markup_append)
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
224
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
225 widget = sat_widgets.SelectableText(markup,
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
226 selected = entity in selected,
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
227 header = header)
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
228 widget.data = entity
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
229 widget.comp = entity_txt.lower() # value to use for sorting
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
230 urwid.connect_signal(widget, 'change', self._contactClicked, user_args=[use_bare_jid])
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
231 return widget
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
232
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
233 def _buildEntities(self, content, entities):
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
234 """Add entity representation in widget list
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
235
125
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
236 @param content: widget list, e.g. SimpleListWalker
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
237 @param entities (iterable): iterable of JID to display
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
238 """
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
239 if not entities:
1230
3abc6563a0d2 primitivus: implement parameter "Show empty groups"
souliane <souliane@mailoo.org>
parents: 1229
diff changeset
240 return
3abc6563a0d2 primitivus: implement parameter "Show empty groups"
souliane <souliane@mailoo.org>
parents: 1229
diff changeset
241 widgets = [] # list of built widgets
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
242
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
243 for entity in entities:
1938
011eff37e21d quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
244 if entity in self.contact_list._specials or not self.contact_list.entityToShow(entity):
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
245 continue
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
246 markup_extra = []
1938
011eff37e21d quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
247 if self.contact_list.show_resources:
011eff37e21d quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
248 for resource in self.contact_list.getCache(entity, C.CONTACT_RESOURCES):
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
249 resource_disp = ('resource_main' if resource == self.getCache(entity, C.CONTACT_MAIN_RESOURCE) else 'resource', "\n " + resource)
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
250 markup_extra.append(resource_disp)
1938
011eff37e21d quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
251 if self.contact_list.show_status:
011eff37e21d quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
252 status = self.contact_list.getCache(jid.JID('%s/%s' % (entity, resource)), 'status')
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
253 status_disp = ('status', "\n " + status) if status else ""
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
254 markup_extra.append(status_disp)
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
255
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
256
510
886754295efe quick frontend, primitivus, wix: MUC private messages management
Goffi <goffi@goffi.org>
parents: 507
diff changeset
257 else:
1938
011eff37e21d quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
258 if self.contact_list.show_status:
011eff37e21d quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
259 status = self.contact_list.getCache(entity, 'status')
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
260 status_disp = ('status', "\n " + status) if status else ""
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
261 markup_extra.append(status_disp)
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
262 widget = self._buildEntityWidget(entity, ('cache_nick', 'cache_name', 'node'), use_bare_jid=True, markup_append=markup_extra)
501
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 500
diff changeset
263 widgets.append(widget)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
264
501
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 500
diff changeset
265 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
266
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 500
diff changeset
267 for widget in widgets:
125
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
268 content.append(widget)
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
269
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
270 def _buildSpecials(self, content):
502
debcf5dd404a QuickFrontend, Primitivus, Wix: special entities management:
Goffi <goffi@goffi.org>
parents: 501
diff changeset
271 """Build the special entities"""
1938
011eff37e21d quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
272 specials = list(self.contact_list._specials)
502
debcf5dd404a QuickFrontend, Primitivus, Wix: special entities management:
Goffi <goffi@goffi.org>
parents: 501
diff changeset
273 specials.sort()
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
274 extra_shown = set()
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
275 for entity in specials:
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
276 # the special widgets
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
277 widget = self._buildEntityWidget(entity, ('cache_nick', 'cache_name', 'node'), with_show_attr=False)
502
debcf5dd404a QuickFrontend, Primitivus, Wix: special entities management:
Goffi <goffi@goffi.org>
parents: 501
diff changeset
278 content.append(widget)
debcf5dd404a QuickFrontend, Primitivus, Wix: special entities management:
Goffi <goffi@goffi.org>
parents: 501
diff changeset
279
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
280 # resources which must be displayed (e.g. MUC private conversations)
1938
011eff37e21d quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
281 extras = [extra for extra in self.contact_list._special_extras if extra.bare == entity.bare]
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
282 extras.sort()
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
283 for extra in extras:
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
284 widget = self._buildEntityWidget(extra, ('resource',), markup_prepend = ' ')
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
285 content.append(widget)
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
286 extra_shown.add(extra)
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
287
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
288 # entities which must be visible but not resource of current special entities
1938
011eff37e21d quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
289 for extra in self.contact_list._special_extras.difference(extra_shown):
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
290 widget = self._buildEntityWidget(extra, ('resource',))
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
291 content.append(widget)
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
292
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
293 def _buildList(self):
125
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
294 """Build the main contact list widget"""
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
295 content = urwid.SimpleListWalker([])
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
296
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
297 self._buildSpecials(content)
1938
011eff37e21d quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
298 if self.contact_list._specials:
502
debcf5dd404a QuickFrontend, Primitivus, Wix: special entities management:
Goffi <goffi@goffi.org>
parents: 501
diff changeset
299 content.append(urwid.Divider('='))
debcf5dd404a QuickFrontend, Primitivus, Wix: special entities management:
Goffi <goffi@goffi.org>
parents: 501
diff changeset
300
1938
011eff37e21d quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
301 groups = list(self.contact_list._groups)
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
302 groups.sort(key=lambda x: x.lower() if x else x)
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
303 for group in groups:
1938
011eff37e21d quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
304 data = self.contact_list.getGroupData(group)
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
305 folded = data.get(C.GROUP_DATA_FOLDED, False)
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
306 jids = list(data['jids'])
1938
011eff37e21d quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
307 if group is not None and (self.contact_list.anyEntityToShow(jids) or self.contact_list.show_empty_groups):
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
308 header = '[-]' if not folded else '[+]'
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
309 widget = sat_widgets.ClickableText(group, header=header + ' ')
125
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
310 content.append(widget)
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
311 urwid.connect_signal(widget, 'click', self._groupClicked)
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
312 if not folded:
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
313 self._buildEntities(content, jids)
1938
011eff37e21d quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
314 not_in_roster = set(self.contact_list._cache).difference(self.contact_list._roster).difference(self.contact_list._specials).difference((self.contact_list.whoami.bare,))
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
315 if not_in_roster:
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
316 content.append(urwid.Divider('-'))
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
317 self._buildEntities(content, not_in_roster)
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
318
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1231
diff changeset
319 return urwid.ListBox(content)
1938
011eff37e21d quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
320
011eff37e21d quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
321 quick_widgets.register(QuickContactList, ContactList)