annotate frontends/src/primitivus/chat.py @ 1580:641cfd2faefe

Primitivus: better popups handling: - widget to remove can now be specified in removePopUp: if it is not the current one, it will be removed from queue - Primitivus.Alert method is a shortcut to display an Alert which will be removed on "OK" press - showDialog is now obsolete and removed, if generic dialog creation is needed, XMLUI can be used
author Goffi <goffi@goffi.org>
date Wed, 11 Nov 2015 18:32:59 +0100
parents e2e75c3c7c7b
children 95ea323e7d04
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/python
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
1396
069ad98b360d 2015 copyright dates update
Goffi <goffi@goffi.org>
parents: 1393
diff changeset
5 # Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014, 2015 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
bfabeedbf32e core: i18n refactoring:
Goffi <goffi@goffi.org>
parents: 739
diff changeset
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
1580
641cfd2faefe Primitivus: better popups handling:
Goffi <goffi@goffi.org>
parents: 1410
diff changeset
25 # from urwid_satext.files_management import FileDialog # FIXME
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1223
diff changeset
26 from sat_frontends.quick_frontend import quick_widgets
225
fd9b7834d98a distutils installation script, draft
Goffi <goffi@goffi.org>
parents: 223
diff changeset
27 from sat_frontends.quick_frontend.quick_chat import QuickChat
1360
8ea8fa13c351 frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents: 1290
diff changeset
28 from sat_frontends.quick_frontend import quick_games
8ea8fa13c351 frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents: 1290
diff changeset
29 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
30 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
31 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
32 from sat_frontends.primitivus.widget import PrimitivusWidget
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
33 import time
1290
faa1129559b8 core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents: 1265
diff changeset
34 from sat_frontends.tools import jid
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
35
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
36
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
37 class ChatText(urwid.FlowWidget):
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
38 """Manage the printing of chat message"""
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
39
1389
eb907923dce9 quick_frontend, primivitus: revert changes made in rev 1386 (1f3513cfb246) concerning ChatText.nick: was mixing MUC occupant nick and roster contact nick/node
souliane <souliane@mailoo.org>
parents: 1388
diff changeset
40 def __init__(self, parent, timestamp, nick, my_mess, message, align='left', is_info=False):
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
41 self.parent = parent
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
42 self.timestamp = time.localtime(timestamp)
1389
eb907923dce9 quick_frontend, primivitus: revert changes made in rev 1386 (1f3513cfb246) concerning ChatText.nick: was mixing MUC occupant nick and roster contact nick/node
souliane <souliane@mailoo.org>
parents: 1388
diff changeset
43 self.nick = nick
190
31632472e857 quick_frontend, wix, primitivus: informations in chat window
Goffi <goffi@goffi.org>
parents: 181
diff changeset
44 self.my_mess = my_mess
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
45 self.message = unicode(message)
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
46 self.align = align
531
3bd8f84f920d primitivus: fixed info messages timestamp
Goffi <goffi@goffi.org>
parents: 521
diff changeset
47 self.is_info = is_info
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
48
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
49 def selectable(self):
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
50 return True
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff changeset
51
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
52 def keypress(self, size, key):
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
53 return key
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
54
1382
b01efa1c0f5e quick_frontend, primitivus: better PEP-8 compliance + remove/rename some (Quick)Chat attributes:
souliane <souliane@mailoo.org>
parents: 1378
diff changeset
55 def rows(self, size, focus=False):
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
56 return self.display_widget(size, focus).rows(size, focus)
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
57
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
58 def render(self, size, focus=False):
125
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
59 canvas = urwid.CompositeCanvas(self.display_widget(size, focus).render(size, focus))
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
60 if focus:
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
61 canvas.set_cursor(self.get_cursor_coords(size))
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
62 return canvas
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
63
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
64 def get_cursor_coords(self, size):
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
65 return 0, 0
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
66
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
67 def display_widget(self, size, focus):
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
68 render_txt = []
531
3bd8f84f920d primitivus: fixed info messages timestamp
Goffi <goffi@goffi.org>
parents: 521
diff changeset
69 if not self.is_info:
3bd8f84f920d primitivus: fixed info messages timestamp
Goffi <goffi@goffi.org>
parents: 521
diff changeset
70 if self.parent.show_timestamp:
1382
b01efa1c0f5e quick_frontend, primitivus: better PEP-8 compliance + remove/rename some (Quick)Chat attributes:
souliane <souliane@mailoo.org>
parents: 1378
diff changeset
71 time_format = "%c" if self.timestamp < self.parent.day_change else "%H:%M" # if the message was sent before today, we print the full date
b01efa1c0f5e quick_frontend, primitivus: better PEP-8 compliance + remove/rename some (Quick)Chat attributes:
souliane <souliane@mailoo.org>
parents: 1378
diff changeset
72 render_txt.append(('date', "[%s]" % time.strftime(time_format, self.timestamp).decode('utf-8')))
531
3bd8f84f920d primitivus: fixed info messages timestamp
Goffi <goffi@goffi.org>
parents: 521
diff changeset
73 if self.parent.show_short_nick:
1382
b01efa1c0f5e quick_frontend, primitivus: better PEP-8 compliance + remove/rename some (Quick)Chat attributes:
souliane <souliane@mailoo.org>
parents: 1378
diff changeset
74 render_txt.append(('my_nick' if self.my_mess else 'other_nick', "**" if self.my_mess else "*"))
531
3bd8f84f920d primitivus: fixed info messages timestamp
Goffi <goffi@goffi.org>
parents: 521
diff changeset
75 else:
1393
50d5d6325f62 quick_frontend, primitivus: various fixes (MUC and cached signals):
souliane <souliane@mailoo.org>
parents: 1390
diff changeset
76 render_txt.append(('my_nick' if self.my_mess else 'other_nick', "[%s] " % (self.nick or '')))
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
77 render_txt.append(self.message)
1173
cae023216bba primivitus: info messages now use "info_msg" attribute (yellow)
Goffi <goffi@goffi.org>
parents: 1158
diff changeset
78 txt_widget = urwid.Text(render_txt, align=self.align)
cae023216bba primivitus: info messages now use "info_msg" attribute (yellow)
Goffi <goffi@goffi.org>
parents: 1158
diff changeset
79 if self.is_info:
cae023216bba primivitus: info messages now use "info_msg" attribute (yellow)
Goffi <goffi@goffi.org>
parents: 1158
diff changeset
80 return urwid.AttrMap(txt_widget, 'info_msg')
cae023216bba primivitus: info messages now use "info_msg" attribute (yellow)
Goffi <goffi@goffi.org>
parents: 1158
diff changeset
81 return txt_widget
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff changeset
82
638
6821fc06a324 misc: a few "cosmetic" changes (PEP 8...)
souliane <souliane@mailoo.org>
parents: 637
diff changeset
83
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1223
diff changeset
84 class Chat(PrimitivusWidget, QuickChat):
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff changeset
85
1290
faa1129559b8 core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents: 1265
diff changeset
86 def __init__(self, host, target, type_=C.CHAT_ONE2ONE, profiles=None):
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1223
diff changeset
87 QuickChat.__init__(self, host, target, type_, profiles=profiles)
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff changeset
88 self.content = urwid.SimpleListWalker([])
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff changeset
89 self.text_list = urwid.ListBox(self.content)
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
90 self.chat_widget = urwid.Frame(self.text_list)
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents: 137
diff changeset
91 self.chat_colums = urwid.Columns([('weight', 8, self.chat_widget)])
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents: 137
diff changeset
92 self.chat_colums = urwid.Columns([('weight', 8, self.chat_widget)])
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents: 137
diff changeset
93 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
94 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
95
1290
faa1129559b8 core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents: 1265
diff changeset
96 # we must adapt the behaviour with the type
faa1129559b8 core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents: 1265
diff changeset
97 if type_ == C.CHAT_ONE2ONE:
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1223
diff changeset
98 self.historyPrint(profile=self.profile)
1290
faa1129559b8 core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents: 1265
diff changeset
99 elif 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
100 if len(self.chat_colums.contents) == 1:
1382
b01efa1c0f5e quick_frontend, primitivus: better PEP-8 compliance + remove/rename some (Quick)Chat attributes:
souliane <souliane@mailoo.org>
parents: 1378
diff changeset
101 self.occupants_list = sat_widgets.GenericList([], option_type=sat_widgets.ClickableText, on_click=self._occupantsClicked)
b01efa1c0f5e quick_frontend, primitivus: better PEP-8 compliance + remove/rename some (Quick)Chat attributes:
souliane <souliane@mailoo.org>
parents: 1378
diff changeset
102 self.occupants_panel = sat_widgets.VerticalSeparator(self.occupants_list)
b01efa1c0f5e quick_frontend, primitivus: better PEP-8 compliance + remove/rename some (Quick)Chat attributes:
souliane <souliane@mailoo.org>
parents: 1378
diff changeset
103 self._appendOccupantsPanel()
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
104 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
105
1382
b01efa1c0f5e quick_frontend, primitivus: better PEP-8 compliance + remove/rename some (Quick)Chat attributes:
souliane <souliane@mailoo.org>
parents: 1378
diff changeset
106 self.day_change = time.strptime(time.strftime("%a %b %d 00:00:00 %Y")) # struct_time of day changing time
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
107 self.show_timestamp = True
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
108 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
109 self.show_title = 1 # 0: clip title; 1: full title; 2: no title
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
110 self.subject = None
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
111
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
112 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
113 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
114 if self.type == C.CHAT_GROUP:
607
c123dddaea6b primitivus: fixed urwid issues with recent urwid versions
Goffi <goffi@goffi.org>
parents: 587
diff changeset
115 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
116 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
117 self._removeOccupantsPanel()
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
118 else:
1382
b01efa1c0f5e quick_frontend, primitivus: better PEP-8 compliance + remove/rename some (Quick)Chat attributes:
souliane <souliane@mailoo.org>
parents: 1378
diff changeset
119 self._appendOccupantsPanel()
b01efa1c0f5e quick_frontend, primitivus: better PEP-8 compliance + remove/rename some (Quick)Chat attributes:
souliane <souliane@mailoo.org>
parents: 1378
diff changeset
120 elif key == a_key['TIMESTAMP_HIDE']: # user wants to (un)hide timestamp
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
121 self.show_timestamp = not self.show_timestamp
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
122 for wid in self.content:
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
123 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
124 elif key == a_key['SHORT_NICKNAME']: # user wants to (not) use short nick
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
125 self.show_short_nick = not self.show_short_nick
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
126 for wid in self.content:
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
127 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
128 elif key == a_key['SUBJECT_SWITCH']: # user wants to (un)hide group's subject or change its apperance
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
129 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
130 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
131 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
132 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
133 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
134 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
135 elif self.show_title == 2:
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
136 self.chat_widget.header = None
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
137 self._invalidate()
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
138
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
139 return super(Chat, self).keypress(size, key)
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
140
137
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 130
diff changeset
141 def getMenu(self):
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 130
diff changeset
142 """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
143 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
144 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
145 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
146 game = _("Game")
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 130
diff changeset
147 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
148 elif self.type == C.CHAT_ONE2ONE:
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1223
diff changeset
149 self.host.addMenus(menu, C.MENU_SINGLE, {'jid': self.target})
176
a50953ac6191 Primitivus: send_file first draft
Goffi <goffi@goffi.org>
parents: 153
diff changeset
150 menu.addMenu(_("Action"), _("Send file"), self.onSendFileRequest)
137
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 130
diff changeset
151 return menu
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
152
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
153 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
154 """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
155
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
156 @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
157 @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
158 @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
159 @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
160 @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
161 """
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
162 assert 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
163 if entity.bare != self.target:
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
164 return
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
165 self.update(entity)
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
166
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
167 def update(self, entity=None):
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
168 """Update one or all entities.
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
169
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
170 @param entity (jid.JID): entity to update
1378
3dae6964c071 quick_frontends, primitivus: move the chat states logic to quick_frontend
souliane <souliane@mailoo.org>
parents: 1377
diff changeset
171 """
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
172 contact_list = self.host.contact_lists[self.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
173
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
174 if self.type == C.CHAT_ONE2ONE: # only update the chat title
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
175 states = self.getEntityStates(self.target)
1383
59c48796759e quick_frontend, primitivus (chat): merge setOccupantStates and setContactStates
souliane <souliane@mailoo.org>
parents: 1382
diff changeset
176 self.title_dynamic = ' '.join([u'({})'.format(state) for state in states.values()])
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
177 self.host.redraw()
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
178 return
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
179
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
180 nicks = list(self.occupants)
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
181 if entity is None: # rebuild all the occupants list
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
182 values = []
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
183 nicks.sort()
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
184 for nick in nicks:
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
185 values.append(self._buildOccupantMarkup(jid.newResource(self.target, nick)))
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
186 self.occupants_list.changeValues(values)
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
187 else: # add, remove or update only one occupant
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
188 nick = entity.resource
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
189 show = contact_list.getCache(entity, C.PRESENCE_SHOW)
1390
337be5318177 primitivus (Chat): fixes updating the occupant list when someone leaves, changes his nick or is added in last position
souliane <souliane@mailoo.org>
parents: 1389
diff changeset
190 if show == C.PRESENCE_UNAVAILABLE or show is None:
1393
50d5d6325f62 quick_frontend, primitivus: various fixes (MUC and cached signals):
souliane <souliane@mailoo.org>
parents: 1390
diff changeset
191 try:
50d5d6325f62 quick_frontend, primitivus: various fixes (MUC and cached signals):
souliane <souliane@mailoo.org>
parents: 1390
diff changeset
192 self.occupants_list.deleteValue(nick)
50d5d6325f62 quick_frontend, primitivus: various fixes (MUC and cached signals):
souliane <souliane@mailoo.org>
parents: 1390
diff changeset
193 except ValueError:
50d5d6325f62 quick_frontend, primitivus: various fixes (MUC and cached signals):
souliane <souliane@mailoo.org>
parents: 1390
diff changeset
194 pass
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
195 else:
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
196 values = self.occupants_list.getAllValues()
1390
337be5318177 primitivus (Chat): fixes updating the occupant list when someone leaves, changes his nick or is added in last position
souliane <souliane@mailoo.org>
parents: 1389
diff changeset
197 markup = self._buildOccupantMarkup(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
198 if not values: # room has just been created
1390
337be5318177 primitivus (Chat): fixes updating the occupant list when someone leaves, changes his nick or is added in last position
souliane <souliane@mailoo.org>
parents: 1389
diff changeset
199 values = [markup]
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
200 else: # add or update the occupant, keep the list sorted
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
201 index = 0
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
202 for entry in values:
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
203 order = cmp(entry.value if hasattr(entry, 'value') else entry, nick)
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
204 if order < 0:
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
205 index += 1
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
206 continue
1390
337be5318177 primitivus (Chat): fixes updating the occupant list when someone leaves, changes his nick or is added in last position
souliane <souliane@mailoo.org>
parents: 1389
diff changeset
207 if order > 0: # insert the occupant
337be5318177 primitivus (Chat): fixes updating the occupant list when someone leaves, changes his nick or is added in last position
souliane <souliane@mailoo.org>
parents: 1389
diff changeset
208 values.insert(index, markup)
337be5318177 primitivus (Chat): fixes updating the occupant list when someone leaves, changes his nick or is added in last position
souliane <souliane@mailoo.org>
parents: 1389
diff changeset
209 else: # update an existing occupant
337be5318177 primitivus (Chat): fixes updating the occupant list when someone leaves, changes his nick or is added in last position
souliane <souliane@mailoo.org>
parents: 1389
diff changeset
210 values[index] = markup
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
211 break
1390
337be5318177 primitivus (Chat): fixes updating the occupant list when someone leaves, changes his nick or is added in last position
souliane <souliane@mailoo.org>
parents: 1389
diff changeset
212 if index == len(values): # add to the end of the list
337be5318177 primitivus (Chat): fixes updating the occupant list when someone leaves, changes his nick or is added in last position
souliane <souliane@mailoo.org>
parents: 1389
diff changeset
213 values.append(markup)
337be5318177 primitivus (Chat): fixes updating the occupant list when someone leaves, changes his nick or is added in last position
souliane <souliane@mailoo.org>
parents: 1389
diff changeset
214 self.occupants_list.changeValues(values)
1378
3dae6964c071 quick_frontends, primitivus: move the chat states logic to quick_frontend
souliane <souliane@mailoo.org>
parents: 1377
diff changeset
215 self.host.redraw()
637
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 610
diff changeset
216
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
217 def _buildOccupantMarkup(self, entity):
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
218 """Return the option attributes for a MUC occupant.
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
219
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
220 @param nick (unicode): occupant nickname
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
221 """
1390
337be5318177 primitivus (Chat): fixes updating the occupant list when someone leaves, changes his nick or is added in last position
souliane <souliane@mailoo.org>
parents: 1389
diff changeset
222 # TODO: for now it's not a markup but a simple text, the problem is that ListOption is unicode and not urwid.Text
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
223 contact_list = self.host.contact_lists[self.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
224 show = contact_list.getCache(entity, C.PRESENCE_SHOW)
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
225 states = self.getEntityStates(entity)
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
226 nick = entity.resource
1390
337be5318177 primitivus (Chat): fixes updating the occupant list when someone leaves, changes his nick or is added in last position
souliane <souliane@mailoo.org>
parents: 1389
diff changeset
227 show_icon, entity_attr = C.PRESENCE.get(show, (u'', u'default')) # TODO: use entity_attr and return (nick, markup)
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
228 text = "%s%s %s" % (u''.join(states.values()), show_icon, nick)
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
229 return (nick, text)
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
230
1382
b01efa1c0f5e quick_frontend, primitivus: better PEP-8 compliance + remove/rename some (Quick)Chat attributes:
souliane <souliane@mailoo.org>
parents: 1378
diff changeset
231 def _occupantsClicked(self, list_wid, clicked_wid):
1290
faa1129559b8 core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents: 1265
diff changeset
232 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
233 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
234 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
235 # 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
236 return
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1223
diff changeset
237 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
238 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
239
1382
b01efa1c0f5e quick_frontend, primitivus: better PEP-8 compliance + remove/rename some (Quick)Chat attributes:
souliane <souliane@mailoo.org>
parents: 1378
diff changeset
240 # 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
241 self.getOrCreatePrivateWidget(full_jid)
511
62f7f2403093 Primitivus: present contacts in groups chat can now be clicked
Goffi <goffi@goffi.org>
parents: 510
diff changeset
242
1382
b01efa1c0f5e quick_frontend, primitivus: better PEP-8 compliance + remove/rename some (Quick)Chat attributes:
souliane <souliane@mailoo.org>
parents: 1378
diff changeset
243 # 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
244 contact_list.setFocus(full_jid, True)
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
245
1382
b01efa1c0f5e quick_frontend, primitivus: better PEP-8 compliance + remove/rename some (Quick)Chat attributes:
souliane <souliane@mailoo.org>
parents: 1378
diff changeset
246 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
247 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
248
1382
b01efa1c0f5e quick_frontend, primitivus: better PEP-8 compliance + remove/rename some (Quick)Chat attributes:
souliane <souliane@mailoo.org>
parents: 1378
diff changeset
249 def _removeOccupantsPanel(self):
607
c123dddaea6b primitivus: fixed urwid issues with recent urwid versions
Goffi <goffi@goffi.org>
parents: 587
diff changeset
250 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
251 if widget is self.occupants_panel:
607
c123dddaea6b primitivus: fixed urwid issues with recent urwid versions
Goffi <goffi@goffi.org>
parents: 587
diff changeset
252 self.chat_colums.contents.remove((widget, options))
c123dddaea6b primitivus: fixed urwid issues with recent urwid versions
Goffi <goffi@goffi.org>
parents: 587
diff changeset
253 break
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
254
1360
8ea8fa13c351 frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents: 1290
diff changeset
255 def addGamePanel(self, widget):
8ea8fa13c351 frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents: 1290
diff changeset
256 """Insert a game panel to this Chat dialog.
8ea8fa13c351 frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents: 1290
diff changeset
257
8ea8fa13c351 frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents: 1290
diff changeset
258 @param widget (Widget): the game panel
8ea8fa13c351 frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents: 1290
diff changeset
259 """
607
c123dddaea6b primitivus: fixed urwid issues with recent urwid versions
Goffi <goffi@goffi.org>
parents: 587
diff changeset
260 assert (len(self.pile.contents) == 1)
1360
8ea8fa13c351 frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents: 1290
diff changeset
261 self.pile.contents.insert(0, (widget, ('weight', 1)))
8ea8fa13c351 frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents: 1290
diff changeset
262 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
263 self.host.redraw()
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents: 137
diff changeset
264
1360
8ea8fa13c351 frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents: 1290
diff changeset
265 def removeGamePanel(self, widget):
8ea8fa13c351 frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents: 1290
diff changeset
266 """Remove the game panel from this Chat dialog.
8ea8fa13c351 frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents: 1290
diff changeset
267
8ea8fa13c351 frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents: 1290
diff changeset
268 @param widget (Widget): the game panel
8ea8fa13c351 frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents: 1290
diff changeset
269 """
607
c123dddaea6b primitivus: fixed urwid issues with recent urwid versions
Goffi <goffi@goffi.org>
parents: 587
diff changeset
270 assert (len(self.pile.contents) == 3)
c123dddaea6b primitivus: fixed urwid issues with recent urwid versions
Goffi <goffi@goffi.org>
parents: 587
diff changeset
271 del self.pile.contents[0]
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents: 137
diff changeset
272 self.host.redraw()
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
273
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
274 def setSubject(self, subject, wrap='space'):
120
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
275 """Set title for a group chat"""
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
276 QuickChat.setSubject(self, subject)
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
277 self.subject = subject
1382
b01efa1c0f5e quick_frontend, primitivus: better PEP-8 compliance + remove/rename some (Quick)Chat attributes:
souliane <souliane@mailoo.org>
parents: 1378
diff changeset
278 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
279 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
280 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
281 self.host.redraw()
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
282
1125
d6c3fea5ecfe quick_frontend, primitivus: add primitivus command ":history [limit]" (default value for limit is 50)
souliane <souliane@mailoo.org>
parents: 1120
diff changeset
283 def clearHistory(self):
d6c3fea5ecfe quick_frontend, primitivus: add primitivus command ":history [limit]" (default value for limit is 50)
souliane <souliane@mailoo.org>
parents: 1120
diff changeset
284 """Clear the content of this chat."""
d6c3fea5ecfe quick_frontend, primitivus: add primitivus command ":history [limit]" (default value for limit is 50)
souliane <souliane@mailoo.org>
parents: 1120
diff changeset
285 del self.content[:]
d6c3fea5ecfe quick_frontend, primitivus: add primitivus command ":history [limit]" (default value for limit is 50)
souliane <souliane@mailoo.org>
parents: 1120
diff changeset
286
d6c3fea5ecfe quick_frontend, primitivus: add primitivus command ":history [limit]" (default value for limit is 50)
souliane <souliane@mailoo.org>
parents: 1120
diff changeset
287 def afterHistoryPrint(self):
d6c3fea5ecfe quick_frontend, primitivus: add primitivus command ":history [limit]" (default value for limit is 50)
souliane <souliane@mailoo.org>
parents: 1120
diff changeset
288 """Refresh or scroll down the focus after the history is printed"""
d6c3fea5ecfe quick_frontend, primitivus: add primitivus command ":history [limit]" (default value for limit is 50)
souliane <souliane@mailoo.org>
parents: 1120
diff changeset
289 if len(self.content):
d6c3fea5ecfe quick_frontend, primitivus: add primitivus command ":history [limit]" (default value for limit is 50)
souliane <souliane@mailoo.org>
parents: 1120
diff changeset
290 self.text_list.focus_position = len(self.content) - 1 # scroll down
d6c3fea5ecfe quick_frontend, primitivus: add primitivus command ":history [limit]" (default value for limit is 50)
souliane <souliane@mailoo.org>
parents: 1120
diff changeset
291 self.host.redraw()
d6c3fea5ecfe quick_frontend, primitivus: add primitivus command ":history [limit]" (default value for limit is 50)
souliane <souliane@mailoo.org>
parents: 1120
diff changeset
292
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1223
diff changeset
293 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
294 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
295
1290
faa1129559b8 core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents: 1265
diff changeset
296 def printMessage(self, from_jid, msg, extra=None, profile=C.PROF_KEY_NONE):
faa1129559b8 core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents: 1265
diff changeset
297 assert isinstance(from_jid, jid.JID)
faa1129559b8 core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents: 1265
diff changeset
298 if extra is None:
faa1129559b8 core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents: 1265
diff changeset
299 extra = {}
190
31632472e857 quick_frontend, wix, primitivus: informations in chat window
Goffi <goffi@goffi.org>
parents: 181
diff changeset
300 try:
1290
faa1129559b8 core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents: 1265
diff changeset
301 timestamp = float(extra['timestamp'])
faa1129559b8 core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents: 1265
diff changeset
302 except KeyError:
1382
b01efa1c0f5e quick_frontend, primitivus: better PEP-8 compliance + remove/rename some (Quick)Chat attributes:
souliane <souliane@mailoo.org>
parents: 1378
diff changeset
303 timestamp = None
1290
faa1129559b8 core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents: 1265
diff changeset
304 try:
faa1129559b8 core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents: 1265
diff changeset
305 nick, mymess = QuickChat.printMessage(self, from_jid, msg, extra, profile)
190
31632472e857 quick_frontend, wix, primitivus: informations in chat window
Goffi <goffi@goffi.org>
parents: 181
diff changeset
306 except TypeError:
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1223
diff changeset
307 # None is returned, the message is managed
190
31632472e857 quick_frontend, wix, primitivus: informations in chat window
Goffi <goffi@goffi.org>
parents: 181
diff changeset
308 return
1389
eb907923dce9 quick_frontend, primivitus: revert changes made in rev 1386 (1f3513cfb246) concerning ChatText.nick: was mixing MUC occupant nick and roster contact nick/node
souliane <souliane@mailoo.org>
parents: 1388
diff changeset
309 new_text = ChatText(self, timestamp, nick, mymess, msg)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
310
520
4d7248f4c577 primitivus: better chat text insertion in chat window
Goffi <goffi@goffi.org>
parents: 518
diff changeset
311 if timestamp and self.content:
678
a630b94280d5 primitivus: code factorization for user notification
souliane <souliane@mailoo.org>
parents: 638
diff changeset
312 for idx in range(len(self.content) - 1, -1, -1):
520
4d7248f4c577 primitivus: better chat text insertion in chat window
Goffi <goffi@goffi.org>
parents: 518
diff changeset
313 current_text = self.content[idx]
1126
8870417c8e8c primitivus (chat): fixes the messages display when opening a new chat window
souliane <souliane@mailoo.org>
parents: 1125
diff changeset
314 older = new_text.timestamp < current_text.timestamp
8870417c8e8c primitivus (chat): fixes the messages display when opening a new chat window
souliane <souliane@mailoo.org>
parents: 1125
diff changeset
315 if older and idx > 0:
678
a630b94280d5 primitivus: code factorization for user notification
souliane <souliane@mailoo.org>
parents: 638
diff changeset
316 continue # the new message is older, we need to insert it upper
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
317
1382
b01efa1c0f5e quick_frontend, primitivus: better PEP-8 compliance + remove/rename some (Quick)Chat attributes:
souliane <souliane@mailoo.org>
parents: 1378
diff changeset
318 # we discard double messages, to avoid backlog / history conflict
1223
802b7e6bf098 frontends: printInfo and printMessage timestamp attribute defaults to None instead of ''
souliane <souliane@mailoo.org>
parents: 1185
diff changeset
319 # FIXME: messages that have been sent several times will be displayed only once
678
a630b94280d5 primitivus: code factorization for user notification
souliane <souliane@mailoo.org>
parents: 638
diff changeset
320 if ((idx and self.content[idx - 1].message == msg) or
521
3f8c2a0f20e5 primitivus: fixed double messages discarding
Goffi <goffi@goffi.org>
parents: 520
diff changeset
321 (self.content[idx].message == msg) or
678
a630b94280d5 primitivus: code factorization for user notification
souliane <souliane@mailoo.org>
parents: 638
diff changeset
322 (idx < len(self.content) - 2 and self.content[idx + 1].message)):
520
4d7248f4c577 primitivus: better chat text insertion in chat window
Goffi <goffi@goffi.org>
parents: 518
diff changeset
323 return
4d7248f4c577 primitivus: better chat text insertion in chat window
Goffi <goffi@goffi.org>
parents: 518
diff changeset
324
1126
8870417c8e8c primitivus (chat): fixes the messages display when opening a new chat window
souliane <souliane@mailoo.org>
parents: 1125
diff changeset
325 self.content.insert(0 if older else idx + 1, new_text)
520
4d7248f4c577 primitivus: better chat text insertion in chat window
Goffi <goffi@goffi.org>
parents: 518
diff changeset
326 break
4d7248f4c577 primitivus: better chat text insertion in chat window
Goffi <goffi@goffi.org>
parents: 518
diff changeset
327 else:
4d7248f4c577 primitivus: better chat text insertion in chat window
Goffi <goffi@goffi.org>
parents: 518
diff changeset
328 self.content.append(new_text)
1120
d1f6b927131e primitivus: prevent a notification flood when displaying the history
souliane <souliane@mailoo.org>
parents: 1106
diff changeset
329 if not timestamp:
d1f6b927131e primitivus: prevent a notification flood when displaying the history
souliane <souliane@mailoo.org>
parents: 1106
diff changeset
330 # XXX: do not send notifications for each line of the history being displayed
d1f6b927131e primitivus: prevent a notification flood when displaying the history
souliane <souliane@mailoo.org>
parents: 1106
diff changeset
331 # FIXME: this must be changed in the future if the timestamp is passed with
d1f6b927131e primitivus: prevent a notification flood when displaying the history
souliane <souliane@mailoo.org>
parents: 1106
diff changeset
332 # all messages and not only with the messages coming from the history.
d1f6b927131e primitivus: prevent a notification flood when displaying the history
souliane <souliane@mailoo.org>
parents: 1106
diff changeset
333 self._notify(from_jid, msg)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
334
1290
faa1129559b8 core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents: 1265
diff changeset
335 def printInfo(self, msg, type_='normal', extra=None):
190
31632472e857 quick_frontend, wix, primitivus: informations in chat window
Goffi <goffi@goffi.org>
parents: 181
diff changeset
336 """Print general info
31632472e857 quick_frontend, wix, primitivus: informations in chat window
Goffi <goffi@goffi.org>
parents: 181
diff changeset
337 @param msg: message to print
812
084b52afdceb frontends: fixed /me usage + renamed a couple of "type" parameters to type_
Goffi <goffi@goffi.org>
parents: 811
diff changeset
338 @type_: one of:
190
31632472e857 quick_frontend, wix, primitivus: informations in chat window
Goffi <goffi@goffi.org>
parents: 181
diff changeset
339 normal: general info like "toto has joined the room"
31632472e857 quick_frontend, wix, primitivus: informations in chat window
Goffi <goffi@goffi.org>
parents: 181
diff changeset
340 me: "/me" information like "/me clenches his fist" ==> "toto clenches his fist"
1223
802b7e6bf098 frontends: printInfo and printMessage timestamp attribute defaults to None instead of ''
souliane <souliane@mailoo.org>
parents: 1185
diff changeset
341 @param timestamp (float): number of seconds since epoch
190
31632472e857 quick_frontend, wix, primitivus: informations in chat window
Goffi <goffi@goffi.org>
parents: 181
diff changeset
342 """
1290
faa1129559b8 core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents: 1265
diff changeset
343 if extra is None:
faa1129559b8 core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents: 1265
diff changeset
344 extra = {}
faa1129559b8 core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents: 1265
diff changeset
345 try:
faa1129559b8 core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents: 1265
diff changeset
346 timestamp = float(extra['timestamp'])
faa1129559b8 core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents: 1265
diff changeset
347 except KeyError:
1382
b01efa1c0f5e quick_frontend, primitivus: better PEP-8 compliance + remove/rename some (Quick)Chat attributes:
souliane <souliane@mailoo.org>
parents: 1378
diff changeset
348 timestamp = None
1389
eb907923dce9 quick_frontend, primivitus: revert changes made in rev 1386 (1f3513cfb246) concerning ChatText.nick: was mixing MUC occupant nick and roster contact nick/node
souliane <souliane@mailoo.org>
parents: 1388
diff changeset
349 _widget = ChatText(self, timestamp, None, False, msg, is_info=True)
531
3bd8f84f920d primitivus: fixed info messages timestamp
Goffi <goffi@goffi.org>
parents: 521
diff changeset
350 self.content.append(_widget)
678
a630b94280d5 primitivus: code factorization for user notification
souliane <souliane@mailoo.org>
parents: 638
diff changeset
351 self._notify(msg=msg)
a630b94280d5 primitivus: code factorization for user notification
souliane <souliane@mailoo.org>
parents: 638
diff changeset
352
a630b94280d5 primitivus: code factorization for user notification
souliane <souliane@mailoo.org>
parents: 638
diff changeset
353 def _notify(self, from_jid="somebody", msg=""):
a630b94280d5 primitivus: code factorization for user notification
souliane <souliane@mailoo.org>
parents: 638
diff changeset
354 """Notify the user of a new message if primitivus doesn't have the focus.
a630b94280d5 primitivus: code factorization for user notification
souliane <souliane@mailoo.org>
parents: 638
diff changeset
355 @param from_jid: contact who wrote to the users
a630b94280d5 primitivus: code factorization for user notification
souliane <souliane@mailoo.org>
parents: 638
diff changeset
356 @param msg: the message that has been received
a630b94280d5 primitivus: code factorization for user notification
souliane <souliane@mailoo.org>
parents: 638
diff changeset
357 """
739
7b72d5c30ebc primivitus: do not notify when an empty message is received
souliane <souliane@mailoo.org>
parents: 688
diff changeset
358 if msg == "":
7b72d5c30ebc primivitus: do not notify when an empty message is received
souliane <souliane@mailoo.org>
parents: 688
diff changeset
359 return
678
a630b94280d5 primitivus: code factorization for user notification
souliane <souliane@mailoo.org>
parents: 638
diff changeset
360 if self.text_list.get_focus()[1] == len(self.content) - 2:
1382
b01efa1c0f5e quick_frontend, primitivus: better PEP-8 compliance + remove/rename some (Quick)Chat attributes:
souliane <souliane@mailoo.org>
parents: 1378
diff changeset
361 # 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
362 # as that mean that he is probably watching discussion history
911
b12706d164d7 primitivus: removed deprecated use of set_focus
Goffi <goffi@goffi.org>
parents: 907
diff changeset
363 self.text_list.focus_position = len(self.content) - 1
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff changeset
364 self.host.redraw()
507
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 501
diff changeset
365 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
366 if self.type == C.CHAT_ONE2ONE:
678
a630b94280d5 primitivus: code factorization for user notification
souliane <souliane@mailoo.org>
parents: 638
diff changeset
367 self.host.x_notify.sendNotification(_("Primitivus: %s is talking to you") % from_jid)
1410
e2e75c3c7c7b quick_frontend, primitivus: fixes a couple of issues:
souliane <souliane@mailoo.org>
parents: 1396
diff changeset
368 elif self.nick is not None and self.nick.lower() in msg.lower():
844
f3513c8cc2e6 misc: fix unnamed arguments in format strings
souliane <souliane@mailoo.org>
parents: 812
diff changeset
369 self.host.x_notify.sendNotification(_("Primitivus: %(user)s mentioned you in room '%(room)s'") % {'user': from_jid, 'room': self.target})
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
370
1382
b01efa1c0f5e quick_frontend, primitivus: better PEP-8 compliance + remove/rename some (Quick)Chat attributes:
souliane <souliane@mailoo.org>
parents: 1378
diff changeset
371 # MENU EVENTS #
137
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 130
diff changeset
372 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
373 # 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
374 if len(self.occupants) != 4:
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
375 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
376 else:
1382
b01efa1c0f5e quick_frontend, primitivus: better PEP-8 compliance + remove/rename some (Quick)Chat attributes:
souliane <souliane@mailoo.org>
parents: 1378
diff changeset
377 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
378
176
a50953ac6191 Primitivus: send_file first draft
Goffi <goffi@goffi.org>
parents: 153
diff changeset
379 def onSendFileRequest(self, menu):
1093
11e2bb20e896 core, frontends (menus): MENU_ROOM and MENU_SINGLE are now managed
Goffi <goffi@goffi.org>
parents: 1063
diff changeset
380 # TODO: move this to core with dynamic menus
1580
641cfd2faefe Primitivus: better popups handling:
Goffi <goffi@goffi.org>
parents: 1410
diff changeset
381 pass
641cfd2faefe Primitivus: better popups handling:
Goffi <goffi@goffi.org>
parents: 1410
diff changeset
382 # dialog = FileDialog(ok_cb=self.onFileSelected, cancel_cb=self.host.removePopUp) # FIXME: to be removed
641cfd2faefe Primitivus: better popups handling:
Goffi <goffi@goffi.org>
parents: 1410
diff changeset
383 # self.host.showPopUp(dialog, 80, 80)
176
a50953ac6191 Primitivus: send_file first draft
Goffi <goffi@goffi.org>
parents: 153
diff changeset
384
1382
b01efa1c0f5e quick_frontend, primitivus: better PEP-8 compliance + remove/rename some (Quick)Chat attributes:
souliane <souliane@mailoo.org>
parents: 1378
diff changeset
385 # MISC EVENTS #
1580
641cfd2faefe Primitivus: better popups handling:
Goffi <goffi@goffi.org>
parents: 1410
diff changeset
386 # FIXME: to be removed
641cfd2faefe Primitivus: better popups handling:
Goffi <goffi@goffi.org>
parents: 1410
diff changeset
387 # def onFileSelected(self, filepath):
641cfd2faefe Primitivus: better popups handling:
Goffi <goffi@goffi.org>
parents: 1410
diff changeset
388 # self.host.removePopUp()
641cfd2faefe Primitivus: better popups handling:
Goffi <goffi@goffi.org>
parents: 1410
diff changeset
389 # try:
641cfd2faefe Primitivus: better popups handling:
Goffi <goffi@goffi.org>
parents: 1410
diff changeset
390 # filepath = filepath.decode('utf-8') # FIXME: correctly manage unicode
641cfd2faefe Primitivus: better popups handling:
Goffi <goffi@goffi.org>
parents: 1410
diff changeset
391 # except UnicodeError:
641cfd2faefe Primitivus: better popups handling:
Goffi <goffi@goffi.org>
parents: 1410
diff changeset
392 # log.error("FIXME: filepath with unicode error are not managed yet")
641cfd2faefe Primitivus: better popups handling:
Goffi <goffi@goffi.org>
parents: 1410
diff changeset
393 # self.host.showDialog(_(u"File has a unicode error in its name, it's not yet managed by SàT"), title=_("Can't send file"), type_="error")
641cfd2faefe Primitivus: better popups handling:
Goffi <goffi@goffi.org>
parents: 1410
diff changeset
394 # return
641cfd2faefe Primitivus: better popups handling:
Goffi <goffi@goffi.org>
parents: 1410
diff changeset
395 # # FIXME: check last_resource: what if self.target.resource exists ?
641cfd2faefe Primitivus: better popups handling:
Goffi <goffi@goffi.org>
parents: 1410
diff changeset
396 # last_resource = self.host.bridge.getMainResource(unicode(self.target.bare), self.profile)
641cfd2faefe Primitivus: better popups handling:
Goffi <goffi@goffi.org>
parents: 1410
diff changeset
397 # if last_resource:
641cfd2faefe Primitivus: better popups handling:
Goffi <goffi@goffi.org>
parents: 1410
diff changeset
398 # full_jid = jid.JID("%s/%s" % (self.target.bare, last_resource))
641cfd2faefe Primitivus: better popups handling:
Goffi <goffi@goffi.org>
parents: 1410
diff changeset
399 # else:
641cfd2faefe Primitivus: better popups handling:
Goffi <goffi@goffi.org>
parents: 1410
diff changeset
400 # full_jid = self.target
641cfd2faefe Primitivus: better popups handling:
Goffi <goffi@goffi.org>
parents: 1410
diff changeset
401 # progress_id = self.host.bridge.sendFile(full_jid, filepath, {}, self.profile)
641cfd2faefe Primitivus: better popups handling:
Goffi <goffi@goffi.org>
parents: 1410
diff changeset
402 # self.host.addProgress(progress_id, filepath)
641cfd2faefe Primitivus: better popups handling:
Goffi <goffi@goffi.org>
parents: 1410
diff changeset
403 # self.host.showDialog(_(u"You file request has been sent, we are waiting for your contact answer"), title=_("File request sent"))
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1223
diff changeset
404
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
405 def onDelete(self):
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
406 QuickChat.onDelete(self)
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
407 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
408 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
409
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1223
diff changeset
410
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1223
diff changeset
411 quick_widgets.register(QuickChat, Chat)
1360
8ea8fa13c351 frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents: 1290
diff changeset
412 quick_widgets.register(quick_games.Tarot, game_tarot.TarotGame)