Mercurial > libervia-backend
annotate frontends/src/primitivus/contact_list.py @ 2016:f09562b0704d
quick_frontend, primitivus: better notifications handling
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 24 Jul 2016 17:56:14 +0200 |
parents | 20fb71b656e3 |
children | 7aa58b7a47e2 |
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 | 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 | 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 # events |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
126 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
127 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
|
128 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
|
129 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
|
130 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
|
131 self.setFocus(group) |
501
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
132 self.update() |
125
8d611eb9ae48
primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents:
124
diff
changeset
|
133 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
134 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
|
135 """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
|
136 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
137 @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
|
138 @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
|
139 @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
|
140 """ |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
141 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
|
142 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
|
143 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
|
144 |
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
|
145 def onNotification(self, entity, notif, profile): |
2016
f09562b0704d
quick_frontend, primitivus: better notifications handling
Goffi <goffi@goffi.org>
parents:
2015
diff
changeset
|
146 notifs = list(self.host.getNotifs(C.ENTITY_ALL, profile=self.profile)) |
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
|
147 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
|
148 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
|
149 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
|
150 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
|
151 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
|
152 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
153 # 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
|
154 |
2015
20fb71b656e3
quick_frontend, primitivus (contact_list): improved and simplified handling of "special" entities:
Goffi <goffi@goffi.org>
parents:
2009
diff
changeset
|
155 def _buildEntityWidget(self, entity, keys=None, use_bare_jid=False, with_notifs=True, with_show_attr=True, markup_prepend=None, markup_append=None, special=False): |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
156 """Build one contact markup data |
124 | 157 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
158 @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
|
159 @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
|
160 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
|
161 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
|
162 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
|
163 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
|
164 @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
|
165 @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
|
166 @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
|
167 @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
|
168 @param markup_append (list): markup to append to the generated one before building the widget |
2015
20fb71b656e3
quick_frontend, primitivus (contact_list): improved and simplified handling of "special" entities:
Goffi <goffi@goffi.org>
parents:
2009
diff
changeset
|
169 @param special (bool): True if entity is a special one |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
170 @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
|
171 """ |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
172 markup = [] |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
173 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
|
174 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
|
175 else: |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
176 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
|
177 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
|
178 entity_txt = entity |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
179 else: |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
180 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
|
181 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
|
182 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
|
183 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
|
184 else: |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
185 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
|
186 if entity_txt: |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
187 break |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
188 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
|
189 entity_txt = entity |
119
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
116
diff
changeset
|
190 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
191 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
|
192 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
|
193 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
|
194 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
|
195 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
|
196 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
|
197 else: |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
198 entity_attr = 'default' |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
199 |
2016
f09562b0704d
quick_frontend, primitivus: better notifications handling
Goffi <goffi@goffi.org>
parents:
2015
diff
changeset
|
200 notifs = list(self.host.getNotifs(entity, exact_jid=special, profile=self.profile)) |
1972
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1938
diff
changeset
|
201 if notifs: |
2016
f09562b0704d
quick_frontend, primitivus: better notifications handling
Goffi <goffi@goffi.org>
parents:
2015
diff
changeset
|
202 header = [('cl_notifs', u'({})'.format(len(notifs))), u' '] |
f09562b0704d
quick_frontend, primitivus: better notifications handling
Goffi <goffi@goffi.org>
parents:
2015
diff
changeset
|
203 if list(self.host.getNotifs(entity.bare, C.NOTIFY_MENTION, profile=self.profile)): |
1973
a9908e751c42
quick_frontend, primitivus (chat): mention detection in group chat + notification (mention and messages)
Goffi <goffi@goffi.org>
parents:
1972
diff
changeset
|
204 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
|
205 else: |
1972
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1938
diff
changeset
|
206 header = u'' |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
207 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
208 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
|
209 if markup_prepend: |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
210 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
|
211 if markup_append: |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
212 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
|
213 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
214 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
|
215 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
|
216 header = header) |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
217 widget.data = entity |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
218 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
|
219 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
|
220 return widget |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
221 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
222 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
|
223 """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
|
224 |
125
8d611eb9ae48
primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents:
124
diff
changeset
|
225 @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
|
226 @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
|
227 """ |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
228 if not entities: |
1230
3abc6563a0d2
primitivus: implement parameter "Show empty groups"
souliane <souliane@mailoo.org>
parents:
1229
diff
changeset
|
229 return |
3abc6563a0d2
primitivus: implement parameter "Show empty groups"
souliane <souliane@mailoo.org>
parents:
1229
diff
changeset
|
230 widgets = [] # list of built widgets |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
231 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
232 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
|
233 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
|
234 continue |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
235 markup_extra = [] |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
236 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
|
237 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
|
238 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
|
239 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
|
240 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
|
241 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
|
242 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
|
243 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
|
244 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
245 |
510
886754295efe
quick frontend, primitivus, wix: MUC private messages management
Goffi <goffi@goffi.org>
parents:
507
diff
changeset
|
246 else: |
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_status: |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
248 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
|
249 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
|
250 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
|
251 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
|
252 widgets.append(widget) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
253 |
501
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
254 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
|
255 |
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
500
diff
changeset
|
256 for widget in widgets: |
125
8d611eb9ae48
primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents:
124
diff
changeset
|
257 content.append(widget) |
8d611eb9ae48
primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents:
124
diff
changeset
|
258 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
259 def _buildSpecials(self, content): |
502
debcf5dd404a
QuickFrontend, Primitivus, Wix: special entities management:
Goffi <goffi@goffi.org>
parents:
501
diff
changeset
|
260 """Build the special entities""" |
2015
20fb71b656e3
quick_frontend, primitivus (contact_list): improved and simplified handling of "special" entities:
Goffi <goffi@goffi.org>
parents:
2009
diff
changeset
|
261 specials = sorted(self.contact_list.getSpecials()) |
20fb71b656e3
quick_frontend, primitivus (contact_list): improved and simplified handling of "special" entities:
Goffi <goffi@goffi.org>
parents:
2009
diff
changeset
|
262 current = None |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
263 for entity in specials: |
2015
20fb71b656e3
quick_frontend, primitivus (contact_list): improved and simplified handling of "special" entities:
Goffi <goffi@goffi.org>
parents:
2009
diff
changeset
|
264 if current is not None and current.bare == entity.bare: |
20fb71b656e3
quick_frontend, primitivus (contact_list): improved and simplified handling of "special" entities:
Goffi <goffi@goffi.org>
parents:
2009
diff
changeset
|
265 # nested entity (e.g. MUC private conversations) |
20fb71b656e3
quick_frontend, primitivus (contact_list): improved and simplified handling of "special" entities:
Goffi <goffi@goffi.org>
parents:
2009
diff
changeset
|
266 widget = self._buildEntityWidget(entity, ('resource',), markup_prepend=' ', special=True) |
20fb71b656e3
quick_frontend, primitivus (contact_list): improved and simplified handling of "special" entities:
Goffi <goffi@goffi.org>
parents:
2009
diff
changeset
|
267 else: |
20fb71b656e3
quick_frontend, primitivus (contact_list): improved and simplified handling of "special" entities:
Goffi <goffi@goffi.org>
parents:
2009
diff
changeset
|
268 # the special widgets |
20fb71b656e3
quick_frontend, primitivus (contact_list): improved and simplified handling of "special" entities:
Goffi <goffi@goffi.org>
parents:
2009
diff
changeset
|
269 if entity.resource: |
20fb71b656e3
quick_frontend, primitivus (contact_list): improved and simplified handling of "special" entities:
Goffi <goffi@goffi.org>
parents:
2009
diff
changeset
|
270 widget = self._buildEntityWidget(entity, ('resource',), special=True) |
20fb71b656e3
quick_frontend, primitivus (contact_list): improved and simplified handling of "special" entities:
Goffi <goffi@goffi.org>
parents:
2009
diff
changeset
|
271 else: |
20fb71b656e3
quick_frontend, primitivus (contact_list): improved and simplified handling of "special" entities:
Goffi <goffi@goffi.org>
parents:
2009
diff
changeset
|
272 widget = self._buildEntityWidget(entity, ('cache_nick', 'cache_name', 'node'), with_show_attr=False, special=True) |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
273 content.append(widget) |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
274 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
275 def _buildList(self): |
125
8d611eb9ae48
primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents:
124
diff
changeset
|
276 """Build the main contact list widget""" |
8d611eb9ae48
primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents:
124
diff
changeset
|
277 content = urwid.SimpleListWalker([]) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
278 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
279 self._buildSpecials(content) |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
280 if self.contact_list._specials: |
502
debcf5dd404a
QuickFrontend, Primitivus, Wix: special entities management:
Goffi <goffi@goffi.org>
parents:
501
diff
changeset
|
281 content.append(urwid.Divider('=')) |
debcf5dd404a
QuickFrontend, Primitivus, Wix: special entities management:
Goffi <goffi@goffi.org>
parents:
501
diff
changeset
|
282 |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
283 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
|
284 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
|
285 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
|
286 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
|
287 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
|
288 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
|
289 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
|
290 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
|
291 widget = sat_widgets.ClickableText(group, header=header + ' ') |
125
8d611eb9ae48
primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents:
124
diff
changeset
|
292 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
|
293 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
|
294 if not folded: |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
295 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
|
296 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
|
297 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
|
298 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
|
299 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
|
300 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1231
diff
changeset
|
301 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
|
302 |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
303 quick_widgets.register(QuickContactList, ContactList) |