Mercurial > libervia-backend
annotate frontends/src/primitivus/chat.py @ 1967:de6faf9be715 refacoring_messages
primitivus (chat): fixed filters clearing when changing filter while one already exists
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 20 Jun 2016 23:07:53 +0200 |
parents | d727aab9a80e |
children | 200cd707a46d |
rev | line source |
---|---|
1934
2daf7b4c6756
use of /usr/bin/env instead of /usr/bin/python in shebang
Goffi <goffi@goffi.org>
parents:
1788
diff
changeset
|
1 #!/usr/bin/env python2 |
119
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2 # -*- coding: utf-8 -*- |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
3 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
607
diff
changeset
|
4 # Primitivus: a SAT frontend |
1766 | 5 # Copyright (C) 2009-2016 Jérôme Poisson (goffi@goffi.org) |
119
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
6 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
607
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:
607
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:
607
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:
607
diff
changeset
|
10 # (at your option) any later version. |
119
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
607
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:
607
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:
607
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:
607
diff
changeset
|
15 # GNU Affero General Public License for more details. |
119
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
607
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:
607
diff
changeset
|
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
119
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 |
771 | 20 from sat.core.i18n import _ |
1180
69aace10b46d
Primitivus (file transfer): an error popup is shown when bad unicode is used in path, and an info popup is show to indicate that the file request has been sent
Goffi <goffi@goffi.org>
parents:
1173
diff
changeset
|
21 from sat.core import log as logging |
69aace10b46d
Primitivus (file transfer): an error popup is shown when bad unicode is used in path, and an info popup is show to indicate that the file request has been sent
Goffi <goffi@goffi.org>
parents:
1173
diff
changeset
|
22 log = logging.getLogger(__name__) |
119
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
23 import urwid |
222
3198bfd66daa
primitivus: refactoring to use urwid-satext which is now a separate project
Goffi <goffi@goffi.org>
parents:
202
diff
changeset
|
24 from urwid_satext import sat_widgets |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1223
diff
changeset
|
25 from sat_frontends.quick_frontend import quick_widgets |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
26 from sat_frontends.quick_frontend import quick_chat |
1360
8ea8fa13c351
frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents:
1290
diff
changeset
|
27 from sat_frontends.quick_frontend import quick_games |
8ea8fa13c351
frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents:
1290
diff
changeset
|
28 from sat_frontends.primitivus import game_tarot |
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:
911
diff
changeset
|
29 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
|
30 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:
1223
diff
changeset
|
31 from sat_frontends.primitivus.widget import PrimitivusWidget |
124 | 32 import time |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
33 from sat_frontends.tools import jid |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
34 from functools import total_ordering |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
35 import bisect |
124 | 36 |
37 | |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
38 class MessageWidget(urwid.WidgetWrap): |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
39 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
40 def __init__(self, mess_data): |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
41 """ |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
42 @param mess_data(quick_chat.Message, None): message data |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
43 None: used only for non text widgets (e.g.: focus separator) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
44 """ |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
45 self.mess_data = mess_data |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
46 mess_data.widgets.add(self) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
47 self.timestamp = time.localtime(mess_data.timestamp) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
48 super(MessageWidget, self).__init__(urwid.Text(self.markup)) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
49 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
50 @property |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
51 def markup(self): |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
52 return self._generateInfoMarkup() if self.mess_data.type == C.MESS_TYPE_INFO else self._generateMarkup() |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
53 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
54 @property |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
55 def info_type(self): |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
56 return self.mess_data.info_type |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
57 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
58 @property |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
59 def parent(self): |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
60 return self.mess_data.parent |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
61 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
62 @property |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
63 def message(self): |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
64 """Return currently displayed message""" |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
65 message = self.mess_data.message |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
66 if self.parent.lang in message: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
67 self.selected_lang = self.parent.lang |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
68 return message[self.parent.lang] |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
69 try: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
70 self.selected_lang = '' |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
71 return message[''] |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
72 except KeyError: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
73 try: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
74 lang, mess = message.iteritems().next() |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
75 self.selected_lang = lang |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
76 return mess |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
77 except StopIteration: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
78 log.error(u"Can't find message for uid {}".format(self.mess_data.uid)) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
79 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
80 @message.setter |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
81 def message(self, value): |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
82 self.mess_data.message = {'':value} |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
83 self._w.set_text(self.markup) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
84 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
85 @property |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
86 def type(self): |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
87 try: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
88 return self.mess_data.type |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
89 except AttributeError: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
90 return C.MESS_TYPE_INFO |
124 | 91 |
92 def selectable(self): | |
93 return True | |
119
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
94 |
124 | 95 def keypress(self, size, key): |
96 return key | |
97 | |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
98 def get_cursor_coords(self, size): |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
99 return 0, 0 |
124 | 100 |
101 def render(self, size, focus=False): | |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
102 # Text widget doesn't render cursor, but we want one |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
103 # so we add it here |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
104 canvas = urwid.CompositeCanvas(self._w.render(size, focus)) |
125
8d611eb9ae48
primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents:
124
diff
changeset
|
105 if focus: |
8d611eb9ae48
primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents:
124
diff
changeset
|
106 canvas.set_cursor(self.get_cursor_coords(size)) |
8d611eb9ae48
primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents:
124
diff
changeset
|
107 return canvas |
8d611eb9ae48
primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents:
124
diff
changeset
|
108 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
109 def _generateInfoMarkup(self): |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
110 return ('info_msg', self.message) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
111 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
112 def _generateMarkup(self): |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
113 """Generate text markup according to message data and Widget options""" |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
114 markup = [] |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
115 d = self.mess_data |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
116 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
117 # timestamp |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
118 if self.parent.show_timestamp: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
119 # if the message was sent before today, we print the full date |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
120 time_format = "%c" if self.timestamp < self.parent.day_change else "%H:%M" |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
121 markup.append(('date', "[{}]".format(time.strftime(time_format, self.timestamp).decode('utf-8')))) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
122 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
123 # nickname |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
124 if self.parent.show_short_nick: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
125 markup.append(('my_nick' if d.own_mess else 'other_nick', "**" if d.own_mess else "*")) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
126 else: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
127 markup.append(('my_nick' if d.own_mess else 'other_nick', u"[{}] ".format(d.nick or ''))) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
128 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
129 msg = self.message # needed to generate self.selected_lang |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
130 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
131 if self.selected_lang: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
132 markup.append(("msg_lang", u"[{}] ".format(self.selected_lang))) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
133 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
134 # message body |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
135 markup.append(msg) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
136 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
137 return markup |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
138 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
139 @total_ordering |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
140 class OccupantWidget(urwid.WidgetWrap): |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
141 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
142 def __init__(self, occupant_data): |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
143 self.occupant_data = occupant_data |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
144 occupant_data.widgets.add(self) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
145 markup = self._generateMarkup() |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
146 super(OccupantWidget, self).__init__(urwid.Text(markup)) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
147 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
148 def __eq__(self, other): |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
149 return self.occupant_data.nick == other.occupant_data.nick |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
150 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
151 def __lt__(self, other): |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
152 return self.occupant_data.nick.lower() < other.occupant_data.nick.lower() |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
153 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
154 @property |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
155 def parent(self): |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
156 return self.mess_data.parent |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
157 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
158 def selectable(self): |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
159 return True |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
160 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
161 def keypress(self, size, key): |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
162 return key |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
163 |
125
8d611eb9ae48
primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents:
124
diff
changeset
|
164 def get_cursor_coords(self, size): |
8d611eb9ae48
primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents:
124
diff
changeset
|
165 return 0, 0 |
124 | 166 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
167 def render(self, size, focus=False): |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
168 # Text widget doesn't render cursor, but we want one |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
169 # so we add it here |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
170 canvas = urwid.CompositeCanvas(self._w.render(size, focus)) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
171 if focus: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
172 canvas.set_cursor(self.get_cursor_coords(size)) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
173 return canvas |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
174 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
175 def _generateMarkup(self): |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
176 # TODO: role and affiliation are shown in a Q&D way |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
177 # should be more intuitive and themable |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
178 o = self.occupant_data |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
179 markup = [] |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
180 markup.append(('info_msg', '{}{} '.format( |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
181 o.role[0].upper(), |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
182 o.affiliation[0].upper(), |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
183 ))) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
184 markup.append(o.nick) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
185 return markup |
119
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
186 |
638
6821fc06a324
misc: a few "cosmetic" changes (PEP 8...)
souliane <souliane@mailoo.org>
parents:
637
diff
changeset
|
187 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
188 class Chat(PrimitivusWidget, quick_chat.QuickChat): |
119
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
189 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
190 def __init__(self, host, target, type_=C.CHAT_ONE2ONE, occupants=None, subject=None, profiles=None): |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
191 quick_chat.QuickChat.__init__(self, host, target, type_, occupants, subject, profiles=profiles) |
1966
d727aab9a80e
primitivus: basic handling of filter, only language can filtered for now
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
192 self.filters = [] # list of filter callbacks to apply |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
193 self.mess_walker = urwid.SimpleListWalker([]) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
194 self.mess_widgets = urwid.ListBox(self.mess_walker) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
195 self.chat_widget = urwid.Frame(self.mess_widgets) |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
196 self.chat_colums = urwid.Columns([('weight', 8, self.chat_widget)]) |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
197 self.pile = urwid.Pile([self.chat_colums]) |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1223
diff
changeset
|
198 PrimitivusWidget.__init__(self, self.pile, self.target) |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1223
diff
changeset
|
199 |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
200 # we must adapt the behaviour with the type |
1762
2e2fb462729a
quick_frontend, primitivus (chat): printing the history is left to quick_frontend
souliane <souliane@mailoo.org>
parents:
1751
diff
changeset
|
201 if type_ == C.CHAT_GROUP: |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1223
diff
changeset
|
202 if len(self.chat_colums.contents) == 1: |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
203 self.occupants_walker = urwid.SimpleListWalker([]) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
204 # TODO: put a real ContactPanel class here, based on FocusWidget ? |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
205 self.occupants_widgets = urwid.ListBox(self.occupants_walker) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
206 # FIXME |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
207 # , option_type=sat_widgets.ClickableText, on_click=self._occupantsClicked) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
208 self.occupants_panel = sat_widgets.VerticalSeparator(self.occupants_widgets) |
1382
b01efa1c0f5e
quick_frontend, primitivus: better PEP-8 compliance + remove/rename some (Quick)Chat attributes:
souliane <souliane@mailoo.org>
parents:
1378
diff
changeset
|
209 self._appendOccupantsPanel() |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
210 occupants_list = sorted(self.occupants.keys(), key=lambda o:o.lower()) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
211 for occupant in occupants_list: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
212 occupant_data = self.occupants[occupant] |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
213 self.occupants_walker.append(OccupantWidget(occupant_data)) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
214 |
1388
a025242bebe7
quick_frontend, primitivus: remove QuickChat.updateEntityState and QuickChat.setContactStates, use more general QuickChat.update (also called when joining the room to initialise the occupants list)
souliane <souliane@mailoo.org>
parents:
1386
diff
changeset
|
215 self.host.addListener('presence', self.presenceListener, [profiles]) |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1223
diff
changeset
|
216 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
217 # focus marker is a separator indicated last visible message before focus was lost |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
218 self.focus_marker = None # link to current marker |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
219 self.focus_marker_set = None # True if a new marker has been inserted |
1382
b01efa1c0f5e
quick_frontend, primitivus: better PEP-8 compliance + remove/rename some (Quick)Chat attributes:
souliane <souliane@mailoo.org>
parents:
1378
diff
changeset
|
220 self.day_change = time.strptime(time.strftime("%a %b %d 00:00:00 %Y")) # struct_time of day changing time |
124 | 221 self.show_timestamp = True |
222 self.show_short_nick = False | |
1382
b01efa1c0f5e
quick_frontend, primitivus: better PEP-8 compliance + remove/rename some (Quick)Chat attributes:
souliane <souliane@mailoo.org>
parents:
1378
diff
changeset
|
223 self.show_title = 1 # 0: clip title; 1: full title; 2: no title |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
224 self.postInit() |
124 | 225 |
226 def keypress(self, size, key): | |
1382
b01efa1c0f5e
quick_frontend, primitivus: better PEP-8 compliance + remove/rename some (Quick)Chat attributes:
souliane <souliane@mailoo.org>
parents:
1378
diff
changeset
|
227 if key == a_key['OCCUPANTS_HIDE']: # user wants to (un)hide the occupants panel |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
228 if self.type == C.CHAT_GROUP: |
607
c123dddaea6b
primitivus: fixed urwid issues with recent urwid versions
Goffi <goffi@goffi.org>
parents:
587
diff
changeset
|
229 widgets = [widget for (widget, options) in self.chat_colums.contents] |
1382
b01efa1c0f5e
quick_frontend, primitivus: better PEP-8 compliance + remove/rename some (Quick)Chat attributes:
souliane <souliane@mailoo.org>
parents:
1378
diff
changeset
|
230 if self.occupants_panel in widgets: |
b01efa1c0f5e
quick_frontend, primitivus: better PEP-8 compliance + remove/rename some (Quick)Chat attributes:
souliane <souliane@mailoo.org>
parents:
1378
diff
changeset
|
231 self._removeOccupantsPanel() |
124 | 232 else: |
1382
b01efa1c0f5e
quick_frontend, primitivus: better PEP-8 compliance + remove/rename some (Quick)Chat attributes:
souliane <souliane@mailoo.org>
parents:
1378
diff
changeset
|
233 self._appendOccupantsPanel() |
b01efa1c0f5e
quick_frontend, primitivus: better PEP-8 compliance + remove/rename some (Quick)Chat attributes:
souliane <souliane@mailoo.org>
parents:
1378
diff
changeset
|
234 elif key == a_key['TIMESTAMP_HIDE']: # user wants to (un)hide timestamp |
124 | 235 self.show_timestamp = not self.show_timestamp |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
236 for wid in self.mess_walker: |
124 | 237 wid._invalidate() |
1382
b01efa1c0f5e
quick_frontend, primitivus: better PEP-8 compliance + remove/rename some (Quick)Chat attributes:
souliane <souliane@mailoo.org>
parents:
1378
diff
changeset
|
238 elif key == a_key['SHORT_NICKNAME']: # user wants to (not) use short nick |
124 | 239 self.show_short_nick = not self.show_short_nick |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
240 for wid in self.mess_walker: |
124 | 241 wid._invalidate() |
1382
b01efa1c0f5e
quick_frontend, primitivus: better PEP-8 compliance + remove/rename some (Quick)Chat attributes:
souliane <souliane@mailoo.org>
parents:
1378
diff
changeset
|
242 elif key == a_key['SUBJECT_SWITCH']: # user wants to (un)hide group's subject or change its apperance |
124 | 243 if self.subject: |
130
5a88ad24ccc0
Primitivus: subject in group chat can now be shown in 3 ways: clip, full, or hidden
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
244 self.show_title = (self.show_title + 1) % 3 |
5a88ad24ccc0
Primitivus: subject in group chat can now be shown in 3 ways: clip, full, or hidden
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
245 if self.show_title == 0: |
1382
b01efa1c0f5e
quick_frontend, primitivus: better PEP-8 compliance + remove/rename some (Quick)Chat attributes:
souliane <souliane@mailoo.org>
parents:
1378
diff
changeset
|
246 self.setSubject(self.subject, 'clip') |
130
5a88ad24ccc0
Primitivus: subject in group chat can now be shown in 3 ways: clip, full, or hidden
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
247 elif self.show_title == 1: |
1382
b01efa1c0f5e
quick_frontend, primitivus: better PEP-8 compliance + remove/rename some (Quick)Chat attributes:
souliane <souliane@mailoo.org>
parents:
1378
diff
changeset
|
248 self.setSubject(self.subject, 'space') |
130
5a88ad24ccc0
Primitivus: subject in group chat can now be shown in 3 ways: clip, full, or hidden
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
249 elif self.show_title == 2: |
124 | 250 self.chat_widget.header = None |
251 self._invalidate() | |
252 | |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
253 return super(Chat, self).keypress(size, key) |
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
254 |
137
227394eb080c
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
130
diff
changeset
|
255 def getMenu(self): |
227394eb080c
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
130
diff
changeset
|
256 """Return Menu bar""" |
222
3198bfd66daa
primitivus: refactoring to use urwid-satext which is now a separate project
Goffi <goffi@goffi.org>
parents:
202
diff
changeset
|
257 menu = sat_widgets.Menu(self.host.loop) |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
258 if self.type == C.CHAT_GROUP: |
1093
11e2bb20e896
core, frontends (menus): MENU_ROOM and MENU_SINGLE are now managed
Goffi <goffi@goffi.org>
parents:
1063
diff
changeset
|
259 self.host.addMenus(menu, C.MENU_ROOM, {'room_jid': self.target.bare}) |
137
227394eb080c
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
130
diff
changeset
|
260 game = _("Game") |
227394eb080c
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
130
diff
changeset
|
261 menu.addMenu(game, "Tarot", self.onTarotRequest) |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
262 elif self.type == C.CHAT_ONE2ONE: |
1634
95ea323e7d04
primitivus: removed all file menu + temporary workaround to send full jid on C.MENU_SINGLE menu action.
Goffi <goffi@goffi.org>
parents:
1580
diff
changeset
|
263 # FIXME: self.target is a bare jid, we need to check that |
95ea323e7d04
primitivus: removed all file menu + temporary workaround to send full jid on C.MENU_SINGLE menu action.
Goffi <goffi@goffi.org>
parents:
1580
diff
changeset
|
264 contact_list = self.host.contact_lists[self.profile] |
1637
7751b5a51586
primivitus: fixed crash when self.target is a full jid
Goffi <goffi@goffi.org>
parents:
1634
diff
changeset
|
265 if not self.target.resource: |
7751b5a51586
primivitus: fixed crash when self.target is a full jid
Goffi <goffi@goffi.org>
parents:
1634
diff
changeset
|
266 full_jid = contact_list.getFullJid(self.target) |
7751b5a51586
primivitus: fixed crash when self.target is a full jid
Goffi <goffi@goffi.org>
parents:
1634
diff
changeset
|
267 else: |
7751b5a51586
primivitus: fixed crash when self.target is a full jid
Goffi <goffi@goffi.org>
parents:
1634
diff
changeset
|
268 full_jid = self.target |
1634
95ea323e7d04
primitivus: removed all file menu + temporary workaround to send full jid on C.MENU_SINGLE menu action.
Goffi <goffi@goffi.org>
parents:
1580
diff
changeset
|
269 self.host.addMenus(menu, C.MENU_SINGLE, {'jid': full_jid}) |
137
227394eb080c
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
130
diff
changeset
|
270 return menu |
124 | 271 |
1966
d727aab9a80e
primitivus: basic handling of filter, only language can filtered for now
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
272 def setFilter(self, args): |
d727aab9a80e
primitivus: basic handling of filter, only language can filtered for now
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
273 """set filtering of messages |
d727aab9a80e
primitivus: basic handling of filter, only language can filtered for now
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
274 |
d727aab9a80e
primitivus: basic handling of filter, only language can filtered for now
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
275 @param args(list[unicode]): filters following syntax "[filter]=[value]" |
d727aab9a80e
primitivus: basic handling of filter, only language can filtered for now
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
276 empty list to clear all filters |
d727aab9a80e
primitivus: basic handling of filter, only language can filtered for now
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
277 only lang=XX is handled for now |
d727aab9a80e
primitivus: basic handling of filter, only language can filtered for now
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
278 """ |
1967
de6faf9be715
primitivus (chat): fixed filters clearing when changing filter while one already exists
Goffi <goffi@goffi.org>
parents:
1966
diff
changeset
|
279 del self.filters[:] |
1966
d727aab9a80e
primitivus: basic handling of filter, only language can filtered for now
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
280 if args: |
d727aab9a80e
primitivus: basic handling of filter, only language can filtered for now
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
281 if args[0].startswith("lang="): |
d727aab9a80e
primitivus: basic handling of filter, only language can filtered for now
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
282 lang = args[0][5:].strip() |
d727aab9a80e
primitivus: basic handling of filter, only language can filtered for now
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
283 self.filters.append(lambda mess_data: lang in mess_data.message) |
d727aab9a80e
primitivus: basic handling of filter, only language can filtered for now
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
284 |
d727aab9a80e
primitivus: basic handling of filter, only language can filtered for now
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
285 del self.mess_walker[:] |
d727aab9a80e
primitivus: basic handling of filter, only language can filtered for now
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
286 for message in self.messages.itervalues(): |
d727aab9a80e
primitivus: basic handling of filter, only language can filtered for now
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
287 self.appendMessage(message) |
d727aab9a80e
primitivus: basic handling of filter, only language can filtered for now
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
288 |
1388
a025242bebe7
quick_frontend, primitivus: remove QuickChat.updateEntityState and QuickChat.setContactStates, use more general QuickChat.update (also called when joining the room to initialise the occupants list)
souliane <souliane@mailoo.org>
parents:
1386
diff
changeset
|
289 def presenceListener(self, entity, show, priority, statuses, profile): |
a025242bebe7
quick_frontend, primitivus: remove QuickChat.updateEntityState and QuickChat.setContactStates, use more general QuickChat.update (also called when joining the room to initialise the occupants list)
souliane <souliane@mailoo.org>
parents:
1386
diff
changeset
|
290 """Update entity's presence status |
1378
3dae6964c071
quick_frontends, primitivus: move the chat states logic to quick_frontend
souliane <souliane@mailoo.org>
parents:
1377
diff
changeset
|
291 |
1388
a025242bebe7
quick_frontend, primitivus: remove QuickChat.updateEntityState and QuickChat.setContactStates, use more general QuickChat.update (also called when joining the room to initialise the occupants list)
souliane <souliane@mailoo.org>
parents:
1386
diff
changeset
|
292 @param entity (jid.JID): entity updated |
a025242bebe7
quick_frontend, primitivus: remove QuickChat.updateEntityState and QuickChat.setContactStates, use more general QuickChat.update (also called when joining the room to initialise the occupants list)
souliane <souliane@mailoo.org>
parents:
1386
diff
changeset
|
293 @param show: availability |
a025242bebe7
quick_frontend, primitivus: remove QuickChat.updateEntityState and QuickChat.setContactStates, use more general QuickChat.update (also called when joining the room to initialise the occupants list)
souliane <souliane@mailoo.org>
parents:
1386
diff
changeset
|
294 @param priority: resource's priority |
a025242bebe7
quick_frontend, primitivus: remove QuickChat.updateEntityState and QuickChat.setContactStates, use more general QuickChat.update (also called when joining the room to initialise the occupants list)
souliane <souliane@mailoo.org>
parents:
1386
diff
changeset
|
295 @param statuses: dict of statuses |
a025242bebe7
quick_frontend, primitivus: remove QuickChat.updateEntityState and QuickChat.setContactStates, use more general QuickChat.update (also called when joining the room to initialise the occupants list)
souliane <souliane@mailoo.org>
parents:
1386
diff
changeset
|
296 @param profile: %(doc_profile)s |
a025242bebe7
quick_frontend, primitivus: remove QuickChat.updateEntityState and QuickChat.setContactStates, use more general QuickChat.update (also called when joining the room to initialise the occupants list)
souliane <souliane@mailoo.org>
parents:
1386
diff
changeset
|
297 """ |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
298 # FIXME: disable for refactoring, need to be checked and re-enabled |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
299 return |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
300 # assert self.type == C.CHAT_GROUP |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
301 # if entity.bare != self.target: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
302 # return |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
303 # self.update(entity) |
1388
a025242bebe7
quick_frontend, primitivus: remove QuickChat.updateEntityState and QuickChat.setContactStates, use more general QuickChat.update (also called when joining the room to initialise the occupants list)
souliane <souliane@mailoo.org>
parents:
1386
diff
changeset
|
304 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
305 def createMessage(self, message): |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
306 self.appendMessage(message) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
307 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
308 def _user_moved(self, message): |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
309 """return true if message is a user left/joined message |
1388
a025242bebe7
quick_frontend, primitivus: remove QuickChat.updateEntityState and QuickChat.setContactStates, use more general QuickChat.update (also called when joining the room to initialise the occupants list)
souliane <souliane@mailoo.org>
parents:
1386
diff
changeset
|
310 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
311 @param message(quick_chat.Message): message to add |
1378
3dae6964c071
quick_frontends, primitivus: move the chat states logic to quick_frontend
souliane <souliane@mailoo.org>
parents:
1377
diff
changeset
|
312 """ |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
313 if message.type != C.MESS_TYPE_INFO: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
314 return False |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
315 try: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
316 info_type = message.extra['info_type'] |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
317 except KeyError: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
318 return False |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
319 else: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
320 return info_type in quick_chat.ROOM_USER_MOVED |
1388
a025242bebe7
quick_frontend, primitivus: remove QuickChat.updateEntityState and QuickChat.setContactStates, use more general QuickChat.update (also called when joining the room to initialise the occupants list)
souliane <souliane@mailoo.org>
parents:
1386
diff
changeset
|
321 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
322 def appendMessage(self, message): |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
323 """Create a MessageWidget and append it |
1388
a025242bebe7
quick_frontend, primitivus: remove QuickChat.updateEntityState and QuickChat.setContactStates, use more general QuickChat.update (also called when joining the room to initialise the occupants list)
souliane <souliane@mailoo.org>
parents:
1386
diff
changeset
|
324 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
325 Can merge messages together is desirable (e.g.: multiple joined/leave) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
326 @param message(quick_chat.Message): message to add |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
327 """ |
1966
d727aab9a80e
primitivus: basic handling of filter, only language can filtered for now
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
328 if self.filters: |
d727aab9a80e
primitivus: basic handling of filter, only language can filtered for now
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
329 if not all([f(message) for f in self.filters]): |
d727aab9a80e
primitivus: basic handling of filter, only language can filtered for now
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
330 return |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
331 if self._user_moved(message): |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
332 for wid in reversed(self.mess_walker): |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
333 # we merge in/out messages if no message was sent meanwhile |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
334 if not isinstance(wid, MessageWidget): |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
335 continue |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
336 if wid.mess_data.type != C.MESS_TYPE_INFO: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
337 break |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
338 if wid.info_type in quick_chat.ROOM_USER_MOVED and wid.mess_data.nick == message.nick: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
339 try: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
340 count = wid.reentered_count |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
341 except AttributeError: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
342 count = wid.reentered_count = 1 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
343 nick = wid.mess_data.nick |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
344 if message.info_type == quick_chat.ROOM_USER_LEFT: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
345 wid.message = _(u"<= {nick} has left the room ({count})").format(nick=nick, count=count) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
346 else: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
347 wid.message = _(u"<=> {nick} re-entered the room ({count})") .format(nick=nick, count=count) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
348 wid.reentered_count+=1 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
349 return |
637
3b02554d4c8b
primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents:
610
diff
changeset
|
350 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
351 if ((self.host.selected_widget != self or not self.host.x_notify.hasFocus()) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
352 and self.focus_marker_set is not None): |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
353 if not self.focus_marker_set and not self._locked and self.mess_walker: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
354 if self.focus_marker is not None: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
355 self.mess_walker.remove(self.focus_marker) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
356 self.focus_marker = urwid.Divider('—') |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
357 self.mess_walker.append(self.focus_marker) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
358 self.focus_marker_set = True |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
359 else: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
360 if self.focus_marker_set: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
361 self.focus_marker_set = False |
1388
a025242bebe7
quick_frontend, primitivus: remove QuickChat.updateEntityState and QuickChat.setContactStates, use more general QuickChat.update (also called when joining the room to initialise the occupants list)
souliane <souliane@mailoo.org>
parents:
1386
diff
changeset
|
362 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
363 if not message.message: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
364 log.error(u"Received an empty message for uid {}".format(message.uid)) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
365 else: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
366 self.mess_walker.append(MessageWidget(message)) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
367 self.mess_widgets.focus_position = len(self.mess_walker) - 1 # scroll down |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
368 self.host.redraw() # FIXME: should not be necessary |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
369 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
370 def addUser(self, nick): |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
371 occupant = super(Chat, self).addUser(nick) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
372 bisect.insort(self.occupants_walker, OccupantWidget(occupant)) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
373 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
374 def removeUser(self, occupant_data): |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
375 occupant = super(Chat, self).removeUser(occupant_data) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
376 if occupant is not None: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
377 for widget in occupant.widgets: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
378 self.occupants_walker.remove(widget) |
1388
a025242bebe7
quick_frontend, primitivus: remove QuickChat.updateEntityState and QuickChat.setContactStates, use more general QuickChat.update (also called when joining the room to initialise the occupants list)
souliane <souliane@mailoo.org>
parents:
1386
diff
changeset
|
379 |
1382
b01efa1c0f5e
quick_frontend, primitivus: better PEP-8 compliance + remove/rename some (Quick)Chat attributes:
souliane <souliane@mailoo.org>
parents:
1378
diff
changeset
|
380 def _occupantsClicked(self, list_wid, clicked_wid): |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
381 # FIXME: not called anymore after refactoring |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
382 assert self.type == C.CHAT_GROUP |
907
cd02f5ef30df
primitivus: display chat states (with symbols) for MUC participants
souliane <souliane@mailoo.org>
parents:
844
diff
changeset
|
383 nick = clicked_wid.getValue().value |
1386
1f3513cfb246
quick_frontend, primivitus: remove QuickChat.getUserNick + primivitus ChatText gets the user nick directly from parent Chat instance
souliane <souliane@mailoo.org>
parents:
1383
diff
changeset
|
384 if nick == self.nick: |
1382
b01efa1c0f5e
quick_frontend, primitivus: better PEP-8 compliance + remove/rename some (Quick)Chat attributes:
souliane <souliane@mailoo.org>
parents:
1378
diff
changeset
|
385 # We ignore clicks on our own nick |
511
62f7f2403093
Primitivus: present contacts in groups chat can now be clicked
Goffi <goffi@goffi.org>
parents:
510
diff
changeset
|
386 return |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1223
diff
changeset
|
387 contact_list = self.host.contact_lists[self.profile] |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
388 full_jid = jid.JID("%s/%s" % (self.target.bare, nick)) |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1223
diff
changeset
|
389 |
1382
b01efa1c0f5e
quick_frontend, primitivus: better PEP-8 compliance + remove/rename some (Quick)Chat attributes:
souliane <souliane@mailoo.org>
parents:
1378
diff
changeset
|
390 # we have a click on a nick, we need to create the widget if it doesn't exists |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1223
diff
changeset
|
391 self.getOrCreatePrivateWidget(full_jid) |
511
62f7f2403093
Primitivus: present contacts in groups chat can now be clicked
Goffi <goffi@goffi.org>
parents:
510
diff
changeset
|
392 |
1382
b01efa1c0f5e
quick_frontend, primitivus: better PEP-8 compliance + remove/rename some (Quick)Chat attributes:
souliane <souliane@mailoo.org>
parents:
1378
diff
changeset
|
393 # now we select the new window |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1223
diff
changeset
|
394 contact_list.setFocus(full_jid, True) |
124 | 395 |
1382
b01efa1c0f5e
quick_frontend, primitivus: better PEP-8 compliance + remove/rename some (Quick)Chat attributes:
souliane <souliane@mailoo.org>
parents:
1378
diff
changeset
|
396 def _appendOccupantsPanel(self): |
b01efa1c0f5e
quick_frontend, primitivus: better PEP-8 compliance + remove/rename some (Quick)Chat attributes:
souliane <souliane@mailoo.org>
parents:
1378
diff
changeset
|
397 self.chat_colums.contents.append((self.occupants_panel, ('weight', 2, False))) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
398 |
1382
b01efa1c0f5e
quick_frontend, primitivus: better PEP-8 compliance + remove/rename some (Quick)Chat attributes:
souliane <souliane@mailoo.org>
parents:
1378
diff
changeset
|
399 def _removeOccupantsPanel(self): |
607
c123dddaea6b
primitivus: fixed urwid issues with recent urwid versions
Goffi <goffi@goffi.org>
parents:
587
diff
changeset
|
400 for widget, options in self.chat_colums.contents: |
1382
b01efa1c0f5e
quick_frontend, primitivus: better PEP-8 compliance + remove/rename some (Quick)Chat attributes:
souliane <souliane@mailoo.org>
parents:
1378
diff
changeset
|
401 if widget is self.occupants_panel: |
607
c123dddaea6b
primitivus: fixed urwid issues with recent urwid versions
Goffi <goffi@goffi.org>
parents:
587
diff
changeset
|
402 self.chat_colums.contents.remove((widget, options)) |
c123dddaea6b
primitivus: fixed urwid issues with recent urwid versions
Goffi <goffi@goffi.org>
parents:
587
diff
changeset
|
403 break |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
404 |
1360
8ea8fa13c351
frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents:
1290
diff
changeset
|
405 def addGamePanel(self, widget): |
8ea8fa13c351
frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents:
1290
diff
changeset
|
406 """Insert a game panel to this Chat dialog. |
8ea8fa13c351
frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents:
1290
diff
changeset
|
407 |
8ea8fa13c351
frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents:
1290
diff
changeset
|
408 @param widget (Widget): the game panel |
8ea8fa13c351
frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents:
1290
diff
changeset
|
409 """ |
607
c123dddaea6b
primitivus: fixed urwid issues with recent urwid versions
Goffi <goffi@goffi.org>
parents:
587
diff
changeset
|
410 assert (len(self.pile.contents) == 1) |
1360
8ea8fa13c351
frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents:
1290
diff
changeset
|
411 self.pile.contents.insert(0, (widget, ('weight', 1))) |
8ea8fa13c351
frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents:
1290
diff
changeset
|
412 self.pile.contents.insert(1, (urwid.Filler(urwid.Divider('-'), ('fixed', 1)))) |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
413 self.host.redraw() |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
414 |
1360
8ea8fa13c351
frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents:
1290
diff
changeset
|
415 def removeGamePanel(self, widget): |
8ea8fa13c351
frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents:
1290
diff
changeset
|
416 """Remove the game panel from this Chat dialog. |
8ea8fa13c351
frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents:
1290
diff
changeset
|
417 |
8ea8fa13c351
frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents:
1290
diff
changeset
|
418 @param widget (Widget): the game panel |
8ea8fa13c351
frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents:
1290
diff
changeset
|
419 """ |
607
c123dddaea6b
primitivus: fixed urwid issues with recent urwid versions
Goffi <goffi@goffi.org>
parents:
587
diff
changeset
|
420 assert (len(self.pile.contents) == 3) |
c123dddaea6b
primitivus: fixed urwid issues with recent urwid versions
Goffi <goffi@goffi.org>
parents:
587
diff
changeset
|
421 del self.pile.contents[0] |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
422 self.host.redraw() |
124 | 423 |
130
5a88ad24ccc0
Primitivus: subject in group chat can now be shown in 3 ways: clip, full, or hidden
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
424 def setSubject(self, subject, wrap='space'): |
120 | 425 """Set title for a group chat""" |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
426 quick_chat.QuickChat.setSubject(self, subject) |
1382
b01efa1c0f5e
quick_frontend, primitivus: better PEP-8 compliance + remove/rename some (Quick)Chat attributes:
souliane <souliane@mailoo.org>
parents:
1378
diff
changeset
|
427 self.subj_wid = urwid.Text(unicode(subject.replace('\n', '|') if wrap == 'clip' else subject), |
b01efa1c0f5e
quick_frontend, primitivus: better PEP-8 compliance + remove/rename some (Quick)Chat attributes:
souliane <souliane@mailoo.org>
parents:
1378
diff
changeset
|
428 align='left' if wrap == 'clip' else 'center', wrap=wrap) |
b01efa1c0f5e
quick_frontend, primitivus: better PEP-8 compliance + remove/rename some (Quick)Chat attributes:
souliane <souliane@mailoo.org>
parents:
1378
diff
changeset
|
429 self.chat_widget.header = urwid.AttrMap(self.subj_wid, 'title') |
130
5a88ad24ccc0
Primitivus: subject in group chat can now be shown in 3 ways: clip, full, or hidden
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
430 self.host.redraw() |
124 | 431 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
432 ## Messages |
1125
d6c3fea5ecfe
quick_frontend, primitivus: add primitivus command ":history [limit]" (default value for limit is 50)
souliane <souliane@mailoo.org>
parents:
1120
diff
changeset
|
433 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
434 def updateHistory(self, size=C.HISTORY_LIMIT_DEFAULT, search='', profile='@NONE@'): |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
435 del self.mess_walker[:] |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
436 if search: |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
437 self.mess_walker.append(urwid.Text(_(u"Results for searching the globbing pattern: {}").format(search))) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
438 self.mess_walker.append(urwid.Text(_(u"Type ':history <lines>' to reset the chat history").format(search))) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
439 super(Chat, self).updateHistory(size, search, profile) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
440 |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
441 def _onHistoryPrinted(self): |
1125
d6c3fea5ecfe
quick_frontend, primitivus: add primitivus command ":history [limit]" (default value for limit is 50)
souliane <souliane@mailoo.org>
parents:
1120
diff
changeset
|
442 """Refresh or scroll down the focus after the history is printed""" |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
443 for message in self.messages.itervalues(): |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
444 self.appendMessage(message) |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
445 super(Chat, self)._onHistoryPrinted() |
1125
d6c3fea5ecfe
quick_frontend, primitivus: add primitivus command ":history [limit]" (default value for limit is 50)
souliane <souliane@mailoo.org>
parents:
1120
diff
changeset
|
446 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1223
diff
changeset
|
447 def onPrivateCreated(self, widget): |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1223
diff
changeset
|
448 self.host.contact_lists[widget.profile].specialResourceVisible(widget.target) |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1223
diff
changeset
|
449 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
450 def onSelected(self): |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
451 self.focus_marker_set = False |
678
a630b94280d5
primitivus: code factorization for user notification
souliane <souliane@mailoo.org>
parents:
638
diff
changeset
|
452 |
1786
104874018ab0
quick_frontend, primitivus (chat): move notification command to quick_frontend
souliane <souliane@mailoo.org>
parents:
1766
diff
changeset
|
453 def notify(self, contact="somebody", msg=""): |
678
a630b94280d5
primitivus: code factorization for user notification
souliane <souliane@mailoo.org>
parents:
638
diff
changeset
|
454 """Notify the user of a new message if primitivus doesn't have the focus. |
1748
3a6cd1c14974
frontends: small message refactorisation:
souliane <souliane@mailoo.org>
parents:
1637
diff
changeset
|
455 |
3a6cd1c14974
frontends: small message refactorisation:
souliane <souliane@mailoo.org>
parents:
1637
diff
changeset
|
456 @param contact (unicode): contact who wrote to the users |
3a6cd1c14974
frontends: small message refactorisation:
souliane <souliane@mailoo.org>
parents:
1637
diff
changeset
|
457 @param msg (unicode): the message that has been received |
678
a630b94280d5
primitivus: code factorization for user notification
souliane <souliane@mailoo.org>
parents:
638
diff
changeset
|
458 """ |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
459 # FIXME: not called anymore after refactoring |
739
7b72d5c30ebc
primivitus: do not notify when an empty message is received
souliane <souliane@mailoo.org>
parents:
688
diff
changeset
|
460 if msg == "": |
7b72d5c30ebc
primivitus: do not notify when an empty message is received
souliane <souliane@mailoo.org>
parents:
688
diff
changeset
|
461 return |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
462 if self.mess_widgets.get_focus()[1] == len(self.mess_walker) - 2: |
1382
b01efa1c0f5e
quick_frontend, primitivus: better PEP-8 compliance + remove/rename some (Quick)Chat attributes:
souliane <souliane@mailoo.org>
parents:
1378
diff
changeset
|
463 # we don't change focus if user is not at the bottom |
b01efa1c0f5e
quick_frontend, primitivus: better PEP-8 compliance + remove/rename some (Quick)Chat attributes:
souliane <souliane@mailoo.org>
parents:
1378
diff
changeset
|
464 # as that mean that he is probably watching discussion history |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
465 self.mess_widgets.focus_position = len(self.mess_walker) - 1 |
119
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
466 self.host.redraw() |
507
f98bef71a918
frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents:
501
diff
changeset
|
467 if not self.host.x_notify.hasFocus(): |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
468 if self.type == C.CHAT_ONE2ONE: |
1748
3a6cd1c14974
frontends: small message refactorisation:
souliane <souliane@mailoo.org>
parents:
1637
diff
changeset
|
469 self.host.x_notify.sendNotification(_("Primitivus: %s is talking to you") % contact) |
1410
e2e75c3c7c7b
quick_frontend, primitivus: fixes a couple of issues:
souliane <souliane@mailoo.org>
parents:
1396
diff
changeset
|
470 elif self.nick is not None and self.nick.lower() in msg.lower(): |
1748
3a6cd1c14974
frontends: small message refactorisation:
souliane <souliane@mailoo.org>
parents:
1637
diff
changeset
|
471 self.host.x_notify.sendNotification(_("Primitivus: %(user)s mentioned you in room '%(room)s'") % {'user': contact, 'room': self.target}) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
472 |
1382
b01efa1c0f5e
quick_frontend, primitivus: better PEP-8 compliance + remove/rename some (Quick)Chat attributes:
souliane <souliane@mailoo.org>
parents:
1378
diff
changeset
|
473 # MENU EVENTS # |
137
227394eb080c
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
130
diff
changeset
|
474 def onTarotRequest(self, menu): |
1093
11e2bb20e896
core, frontends (menus): MENU_ROOM and MENU_SINGLE are now managed
Goffi <goffi@goffi.org>
parents:
1063
diff
changeset
|
475 # TODO: move this to plugin_misc_tarot with dynamic menu |
137
227394eb080c
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
130
diff
changeset
|
476 if len(self.occupants) != 4: |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
477 self.host.showPopUp(sat_widgets.Alert(_("Can't start game"), _("You need to be exactly 4 peoples in the room to start a Tarot game"), ok_cb=self.host.removePopUp)) |
137
227394eb080c
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
130
diff
changeset
|
478 else: |
1382
b01efa1c0f5e
quick_frontend, primitivus: better PEP-8 compliance + remove/rename some (Quick)Chat attributes:
souliane <souliane@mailoo.org>
parents:
1378
diff
changeset
|
479 self.host.bridge.tarotGameCreate(self.target, list(self.occupants), self.profile) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
480 |
1382
b01efa1c0f5e
quick_frontend, primitivus: better PEP-8 compliance + remove/rename some (Quick)Chat attributes:
souliane <souliane@mailoo.org>
parents:
1378
diff
changeset
|
481 # MISC EVENTS # |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1223
diff
changeset
|
482 |
1388
a025242bebe7
quick_frontend, primitivus: remove QuickChat.updateEntityState and QuickChat.setContactStates, use more general QuickChat.update (also called when joining the room to initialise the occupants list)
souliane <souliane@mailoo.org>
parents:
1386
diff
changeset
|
483 def onDelete(self): |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
484 # FIXME: to be checked after refactoring |
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
485 quick_chat.QuickChat.onDelete(self) |
1388
a025242bebe7
quick_frontend, primitivus: remove QuickChat.updateEntityState and QuickChat.setContactStates, use more general QuickChat.update (also called when joining the room to initialise the occupants list)
souliane <souliane@mailoo.org>
parents:
1386
diff
changeset
|
486 if self.type == C.CHAT_GROUP: |
a025242bebe7
quick_frontend, primitivus: remove QuickChat.updateEntityState and QuickChat.setContactStates, use more general QuickChat.update (also called when joining the room to initialise the occupants list)
souliane <souliane@mailoo.org>
parents:
1386
diff
changeset
|
487 self.host.removeListener('presence', self.presenceListener) |
a025242bebe7
quick_frontend, primitivus: remove QuickChat.updateEntityState and QuickChat.setContactStates, use more general QuickChat.update (also called when joining the room to initialise the occupants list)
souliane <souliane@mailoo.org>
parents:
1386
diff
changeset
|
488 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1223
diff
changeset
|
489 |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
490 quick_widgets.register(quick_chat.QuickChat, Chat) |
1360
8ea8fa13c351
frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents:
1290
diff
changeset
|
491 quick_widgets.register(quick_games.Tarot, game_tarot.TarotGame) |