Mercurial > libervia-web
annotate src/browser/sat_browser/chat.py @ 609:ec77c2bc18d3 frontends_multi_profiles
brower side: removed close listener for LiberviaWidget
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 10 Feb 2015 19:10:28 +0100 |
parents | ed6d8f7c6026 |
children | 1c0d5a87c554 |
rev | line source |
---|---|
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1 #!/usr/bin/python |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2 # -*- coding: utf-8 -*- |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
3 |
339
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
334
diff
changeset
|
4 # Libervia: a Salut à Toi frontend |
340 | 5 # Copyright (C) 2011, 2012, 2013, 2014 Jérôme Poisson <goffi@goffi.org> |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
6 |
339
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
334
diff
changeset
|
7 # This program is free software: you can redistribute it and/or modify |
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
334
diff
changeset
|
8 # it under the terms of the GNU Affero General Public License as published by |
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
334
diff
changeset
|
9 # the Free Software Foundation, either version 3 of the License, or |
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
334
diff
changeset
|
10 # (at your option) any later version. |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 |
339
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
334
diff
changeset
|
12 # This program is distributed in the hope that it will be useful, |
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
334
diff
changeset
|
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
334
diff
changeset
|
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
334
diff
changeset
|
15 # GNU Affero General Public License for more details. |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 |
339
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
334
diff
changeset
|
17 # You should have received a copy of the GNU Affero General Public License |
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
334
diff
changeset
|
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 |
439
d52f529a6d42
browser side: use of new log system (first draft):
Goffi <goffi@goffi.org>
parents:
433
diff
changeset
|
20 from sat.core.log import getLogger |
d52f529a6d42
browser side: use of new log system (first draft):
Goffi <goffi@goffi.org>
parents:
433
diff
changeset
|
21 log = getLogger(__name__) |
449
981ed669d3b3
/!\ reorganize all the file hierarchy, move the code and launching script to src:
souliane <souliane@mailoo.org>
parents:
442
diff
changeset
|
22 |
981ed669d3b3
/!\ reorganize all the file hierarchy, move the code and launching script to src:
souliane <souliane@mailoo.org>
parents:
442
diff
changeset
|
23 from sat_frontends.tools.games import SYMBOLS |
589
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
24 from sat_frontends.tools import strings |
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
25 from sat_frontends.tools import jid |
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
26 from sat_frontends.quick_frontend import quick_widgets |
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
27 from sat_frontends.quick_frontend.quick_chat import QuickChat |
449
981ed669d3b3
/!\ reorganize all the file hierarchy, move the code and launching script to src:
souliane <souliane@mailoo.org>
parents:
442
diff
changeset
|
28 from sat.core.i18n import _ |
981ed669d3b3
/!\ reorganize all the file hierarchy, move the code and launching script to src:
souliane <souliane@mailoo.org>
parents:
442
diff
changeset
|
29 |
33 | 30 from pyjamas.ui.AbsolutePanel import AbsolutePanel |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
31 from pyjamas.ui.VerticalPanel import VerticalPanel |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
32 from pyjamas.ui.HorizontalPanel import HorizontalPanel |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
33 from pyjamas.ui.Label import Label |
33 | 34 from pyjamas.ui.HTML import HTML |
589
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
35 from pyjamas.ui.KeyboardListener import KEY_ENTER, KeyboardHandler |
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
36 from pyjamas.ui.HTMLPanel import HTMLPanel |
323
0b7934e75e76
misc: reorganization of the file panels.py + clean the modules import:
souliane <souliane@mailoo.org>
parents:
322
diff
changeset
|
37 |
0b7934e75e76
misc: reorganization of the file panels.py + clean the modules import:
souliane <souliane@mailoo.org>
parents:
322
diff
changeset
|
38 from datetime import datetime |
0b7934e75e76
misc: reorganization of the file panels.py + clean the modules import:
souliane <souliane@mailoo.org>
parents:
322
diff
changeset
|
39 from time import time |
449
981ed669d3b3
/!\ reorganize all the file hierarchy, move the code and launching script to src:
souliane <souliane@mailoo.org>
parents:
442
diff
changeset
|
40 |
467 | 41 import html_tools |
42 import base_panels | |
589
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
43 import panels |
467 | 44 import card_game |
45 import radiocol | |
449
981ed669d3b3
/!\ reorganize all the file hierarchy, move the code and launching script to src:
souliane <souliane@mailoo.org>
parents:
442
diff
changeset
|
46 import base_widget |
589
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
47 import contact_list |
433
bbdbee25123a
import constants.Const as C (according to the coding rules)
souliane <souliane@mailoo.org>
parents:
432
diff
changeset
|
48 from constants import Const as C |
467 | 49 import plugin_xep_0085 |
323
0b7934e75e76
misc: reorganization of the file panels.py + clean the modules import:
souliane <souliane@mailoo.org>
parents:
322
diff
changeset
|
50 |
279
2d6bd975a72d
browser_side: set your own presence status and display those of others
souliane <souliane@mailoo.org>
parents:
276
diff
changeset
|
51 |
589
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
52 class ChatText(HTMLPanel): |
201
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
53 |
589
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
54 def __init__(self, nick, mymess, msg, extra): |
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
55 try: |
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
56 timestamp = float(extra['timestamp']) |
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
57 except KeyError: |
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
58 timestamp=None |
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
59 xhtml = extra.get('xhtml') |
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
60 _date = datetime.fromtimestamp(float(timestamp or time())) |
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
61 _msg_class = ["chat_text_msg"] |
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
62 if mymess: |
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
63 _msg_class.append("chat_text_mymess") |
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
64 HTMLPanel.__init__(self, "<span class='chat_text_timestamp'>%(timestamp)s</span> <span class='chat_text_nick'>%(nick)s</span> <span class='%(msg_class)s'>%(msg)s</span>" % |
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
65 {"timestamp": _date.strftime("%H:%M"), |
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
66 "nick": "[%s]" % html_tools.html_sanitize(nick), |
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
67 "msg_class": ' '.join(_msg_class), |
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
68 "msg": strings.addURLToText(html_tools.html_sanitize(msg)) if not xhtml else html_tools.inlineRoot(xhtml)} # FIXME: images and external links must be removed according to preferences |
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
69 ) |
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
70 self.setStyleName('chatText') |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
71 |
210
3092f6b1710c
browser side: make the OK button title for group selector configureable + few "cosmetic" changes (PEP 8...)
souliane <souliane@mailoo.org>
parents:
206
diff
changeset
|
72 |
589
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
73 class Chat(QuickChat, base_widget.LiberviaWidget, KeyboardHandler): |
230
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
74 |
589
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
75 def __init__(self, host, target, type_=C.CHAT_ONE2ONE, profiles=None): |
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
76 """Panel used for conversation (one 2 one or group chat) |
496
0924710b666a
browser_side: remove the annoying (esp. when editing a message) scrolling each time you select a microblog entry
souliane <souliane@mailoo.org>
parents:
495
diff
changeset
|
77 |
19 | 78 @param host: SatWebFrontend instance |
467 | 79 @param target: entity (jid.JID) with who we have a conversation (contact's jid for one 2 one chat, or MUC room) |
598
ed6d8f7c6026
browser side (blog, chat): fixed dropKey callbacks to adapt them to new widget creation system. Drag'n'Drop should be fixed.
Goffi <goffi@goffi.org>
parents:
589
diff
changeset
|
80 @param type: one2one for simple conversation, group for MUC |
ed6d8f7c6026
browser side (blog, chat): fixed dropKey callbacks to adapt them to new widget creation system. Drag'n'Drop should be fixed.
Goffi <goffi@goffi.org>
parents:
589
diff
changeset
|
81 """ |
589
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
82 QuickChat.__init__(self, host, target, type_, profiles=profiles) |
34 | 83 self.vpanel = VerticalPanel() |
210
3092f6b1710c
browser side: make the OK button title for group selector configureable + few "cosmetic" changes (PEP 8...)
souliane <souliane@mailoo.org>
parents:
206
diff
changeset
|
84 self.vpanel.setSize('100%', '100%') |
536
048ae7314156
browser_side: temporary way to display the OTR state in the LiberviaWidget header
souliane <souliane@mailoo.org>
parents:
534
diff
changeset
|
85 |
048ae7314156
browser_side: temporary way to display the OTR state in the LiberviaWidget header
souliane <souliane@mailoo.org>
parents:
534
diff
changeset
|
86 # FIXME: temporary dirty initialization to display the OTR state |
559
77372641e05d
browser_side (plugin OTR): display the correct icons on opening the window + auto-open on accepted invitation
souliane <souliane@mailoo.org>
parents:
549
diff
changeset
|
87 def header_info_cb(cb): |
77372641e05d
browser_side (plugin OTR): display the correct icons on opening the window + auto-open on accepted invitation
souliane <souliane@mailoo.org>
parents:
549
diff
changeset
|
88 host.plugins['otr'].infoTextCallback(target, cb) |
589
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
89 header_info = header_info_cb if (type_ == C.CHAT_ONE2ONE and 'otr' in host.plugins) else None |
536
048ae7314156
browser_side: temporary way to display the OTR state in the LiberviaWidget header
souliane <souliane@mailoo.org>
parents:
534
diff
changeset
|
90 |
048ae7314156
browser_side: temporary way to display the OTR state in the LiberviaWidget header
souliane <souliane@mailoo.org>
parents:
534
diff
changeset
|
91 base_widget.LiberviaWidget.__init__(self, host, title=target.bare, info=header_info, selectable=True) |
589
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
92 self._body = AbsolutePanel() |
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
93 self._body.setStyleName('chatPanel_body') |
33 | 94 chat_area = HorizontalPanel() |
95 chat_area.setStyleName('chatArea') | |
589
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
96 if type_ == C.CHAT_GROUP: |
467 | 97 self.occupants_list = base_panels.OccupantsList() |
584
0a06cf833f5a
browser_side: various improvements, especially for MUC
souliane <souliane@mailoo.org>
parents:
581
diff
changeset
|
98 self.occupants_initialised = False |
33 | 99 chat_area.add(self.occupants_list) |
589
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
100 self._body.add(chat_area) |
33 | 101 self.content = AbsolutePanel() |
102 self.content.setStyleName('chatContent') | |
195 | 103 self.content_scroll = base_widget.ScrollPanelWrapper(self.content) |
34 | 104 chat_area.add(self.content_scroll) |
105 chat_area.setCellWidth(self.content_scroll, '100%') | |
589
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
106 self.vpanel.add(self._body) |
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
107 self.vpanel.setCellHeight(self._body, '100%') |
84 | 108 self.addStyleName('chatPanel') |
34 | 109 self.setWidget(self.vpanel) |
467 | 110 self.state_machine = plugin_xep_0085.ChatStateMachine(self.host, str(self.target)) |
407
6a6551de4414
browser_side: display chat states (with symbols) for MUC participants
souliane <souliane@mailoo.org>
parents:
404
diff
changeset
|
111 self._state = None |
589
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
112 self.refresh() |
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
113 if type_ == C.CHAT_ONE2ONE: |
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
114 self.historyPrint(profile=self.profile) |
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
115 |
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
116 @property |
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
117 def target(self): |
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
118 # FIXME: for unknow reason, pyjamas doesn't use the method inherited from QuickChat |
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
119 # FIXME: must remove this when either pyjamas is fixed, or we use an alternative |
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
120 if self.type == C.CHAT_GROUP: |
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
121 return self.current_target.bare |
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
122 return self.current_target |
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
123 |
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
124 @property |
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
125 def profile(self): |
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
126 # FIXME: for unknow reason, pyjamas doesn't use the method inherited from QuickWidget |
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
127 # FIXME: must remove this when either pyjamas is fixed, or we use an alternative |
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
128 assert len(self.profiles) == 1 and not self.PROFILES_MULTIPLE and not self.PROFILES_ALLOW_NONE |
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
129 return list(self.profiles)[0] |
195 | 130 |
598
ed6d8f7c6026
browser side (blog, chat): fixed dropKey callbacks to adapt them to new widget creation system. Drag'n'Drop should be fixed.
Goffi <goffi@goffi.org>
parents:
589
diff
changeset
|
131 # @classmethod |
ed6d8f7c6026
browser side (blog, chat): fixed dropKey callbacks to adapt them to new widget creation system. Drag'n'Drop should be fixed.
Goffi <goffi@goffi.org>
parents:
589
diff
changeset
|
132 # def createPanel(cls, host, item, type_=C.CHAT_ONE2ONE): |
ed6d8f7c6026
browser side (blog, chat): fixed dropKey callbacks to adapt them to new widget creation system. Drag'n'Drop should be fixed.
Goffi <goffi@goffi.org>
parents:
589
diff
changeset
|
133 # assert(item) |
ed6d8f7c6026
browser side (blog, chat): fixed dropKey callbacks to adapt them to new widget creation system. Drag'n'Drop should be fixed.
Goffi <goffi@goffi.org>
parents:
589
diff
changeset
|
134 # _contact = item if isinstance(item, jid.JID) else jid.JID(item) |
ed6d8f7c6026
browser side (blog, chat): fixed dropKey callbacks to adapt them to new widget creation system. Drag'n'Drop should be fixed.
Goffi <goffi@goffi.org>
parents:
589
diff
changeset
|
135 # host.contact_panel.setContactMessageWaiting(_contact.bare, False) |
ed6d8f7c6026
browser side (blog, chat): fixed dropKey callbacks to adapt them to new widget creation system. Drag'n'Drop should be fixed.
Goffi <goffi@goffi.org>
parents:
589
diff
changeset
|
136 # _new_panel = Chat(host, _contact, type_) # XXX: pyjamas doesn't seems to support creating with cls directly |
ed6d8f7c6026
browser side (blog, chat): fixed dropKey callbacks to adapt them to new widget creation system. Drag'n'Drop should be fixed.
Goffi <goffi@goffi.org>
parents:
589
diff
changeset
|
137 # _new_panel.historyPrint() |
ed6d8f7c6026
browser side (blog, chat): fixed dropKey callbacks to adapt them to new widget creation system. Drag'n'Drop should be fixed.
Goffi <goffi@goffi.org>
parents:
589
diff
changeset
|
138 # host.setSelected(_new_panel) |
ed6d8f7c6026
browser side (blog, chat): fixed dropKey callbacks to adapt them to new widget creation system. Drag'n'Drop should be fixed.
Goffi <goffi@goffi.org>
parents:
589
diff
changeset
|
139 # _new_panel.refresh() |
ed6d8f7c6026
browser side (blog, chat): fixed dropKey callbacks to adapt them to new widget creation system. Drag'n'Drop should be fixed.
Goffi <goffi@goffi.org>
parents:
589
diff
changeset
|
140 # return _new_panel |
38
7bea2ae0c4fb
Tarot game: center_panel layout + chien can now be showed + fixed click event inheritance + card selection first draft
Goffi <goffi@goffi.org>
parents:
37
diff
changeset
|
141 |
230
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
142 def refresh(self): |
326
36927be51481
browser_side: fixed the behavior regarding "Enable unibox" parameter:
souliane <souliane@mailoo.org>
parents:
323
diff
changeset
|
143 """Refresh the display of this widget. If the unibox is disabled, |
36927be51481
browser_side: fixed the behavior regarding "Enable unibox" parameter:
souliane <souliane@mailoo.org>
parents:
323
diff
changeset
|
144 add a message box at the bottom of the panel""" |
589
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
145 # FIXME: must be checked |
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
146 # self.host.contact_panel.setContactMessageWaiting(self.target.bare, False) |
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
147 # self.content_scroll.scrollToBottom() |
230
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
148 |
326
36927be51481
browser_side: fixed the behavior regarding "Enable unibox" parameter:
souliane <souliane@mailoo.org>
parents:
323
diff
changeset
|
149 enable_box = self.host.uni_box is None |
36927be51481
browser_side: fixed the behavior regarding "Enable unibox" parameter:
souliane <souliane@mailoo.org>
parents:
323
diff
changeset
|
150 if hasattr(self, 'message_box'): |
36927be51481
browser_side: fixed the behavior regarding "Enable unibox" parameter:
souliane <souliane@mailoo.org>
parents:
323
diff
changeset
|
151 self.message_box.setVisible(enable_box) |
589
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
152 elif enable_box: |
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
153 self.message_box = panels.MessageBox(self.host) |
326
36927be51481
browser_side: fixed the behavior regarding "Enable unibox" parameter:
souliane <souliane@mailoo.org>
parents:
323
diff
changeset
|
154 self.message_box.onSelectedChange(self) |
499
ec3f30253040
browser_side: also display the warning banner when writing to a single contact and unibox is disabled
souliane <souliane@mailoo.org>
parents:
498
diff
changeset
|
155 self.message_box.addKeyboardListener(self) |
326
36927be51481
browser_side: fixed the behavior regarding "Enable unibox" parameter:
souliane <souliane@mailoo.org>
parents:
323
diff
changeset
|
156 self.vpanel.add(self.message_box) |
36927be51481
browser_side: fixed the behavior regarding "Enable unibox" parameter:
souliane <souliane@mailoo.org>
parents:
323
diff
changeset
|
157 |
499
ec3f30253040
browser_side: also display the warning banner when writing to a single contact and unibox is disabled
souliane <souliane@mailoo.org>
parents:
498
diff
changeset
|
158 def onKeyDown(self, sender, keycode, modifiers): |
ec3f30253040
browser_side: also display the warning banner when writing to a single contact and unibox is disabled
souliane <souliane@mailoo.org>
parents:
498
diff
changeset
|
159 if keycode == KEY_ENTER: |
ec3f30253040
browser_side: also display the warning banner when writing to a single contact and unibox is disabled
souliane <souliane@mailoo.org>
parents:
498
diff
changeset
|
160 self.host.showWarning(None, None) |
ec3f30253040
browser_side: also display the warning banner when writing to a single contact and unibox is disabled
souliane <souliane@mailoo.org>
parents:
498
diff
changeset
|
161 else: |
ec3f30253040
browser_side: also display the warning banner when writing to a single contact and unibox is disabled
souliane <souliane@mailoo.org>
parents:
498
diff
changeset
|
162 self.host.showWarning(*self.getWarningData()) |
ec3f30253040
browser_side: also display the warning banner when writing to a single contact and unibox is disabled
souliane <souliane@mailoo.org>
parents:
498
diff
changeset
|
163 |
574
b07f0fe2763a
browser_side: safer attributes handling in getOrCreateLiberviaWidget + use it to create MUC panels
souliane <souliane@mailoo.org>
parents:
573
diff
changeset
|
164 def matchEntity(self, item, type_=None): |
230
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
165 """ |
467 | 166 @param entity: target jid as a string or jid.JID instance. |
230
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
167 @return: True if self matches the given entity |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
168 """ |
574
b07f0fe2763a
browser_side: safer attributes handling in getOrCreateLiberviaWidget + use it to create MUC panels
souliane <souliane@mailoo.org>
parents:
573
diff
changeset
|
169 if type_ is None: |
267
a76243c02074
browser_side: changes regarding widgets and tabs:
souliane <souliane@mailoo.org>
parents:
264
diff
changeset
|
170 type_ = self.type |
574
b07f0fe2763a
browser_side: safer attributes handling in getOrCreateLiberviaWidget + use it to create MUC panels
souliane <souliane@mailoo.org>
parents:
573
diff
changeset
|
171 entity = item if isinstance(item, jid.JID) else jid.JID(item) |
230
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
172 try: |
267
a76243c02074
browser_side: changes regarding widgets and tabs:
souliane <souliane@mailoo.org>
parents:
264
diff
changeset
|
173 return self.target.bare == entity.bare and self.type == type_ |
230
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
174 except AttributeError as e: |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
175 e.include_traceback() |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
176 return False |
266e9678eec0
browser_side: added the flag REUSE_EXISTING_LIBERVIA_WIDGETS
souliane <souliane@mailoo.org>
parents:
226
diff
changeset
|
177 |
498
60be99de3808
browser_side: menus refactorization + handle levels > 2
souliane <souliane@mailoo.org>
parents:
496
diff
changeset
|
178 def addMenus(self, menu_bar): |
495
587fe75d1b16
browser_side: handle menus of type ROOM, SINGLE and ROSTER_JID
souliane <souliane@mailoo.org>
parents:
482
diff
changeset
|
179 """Add cached menus to the header. |
587fe75d1b16
browser_side: handle menus of type ROOM, SINGLE and ROSTER_JID
souliane <souliane@mailoo.org>
parents:
482
diff
changeset
|
180 |
587fe75d1b16
browser_side: handle menus of type ROOM, SINGLE and ROSTER_JID
souliane <souliane@mailoo.org>
parents:
482
diff
changeset
|
181 @param menu_bar (GenericMenuBar): menu bar of the widget's header |
587fe75d1b16
browser_side: handle menus of type ROOM, SINGLE and ROSTER_JID
souliane <souliane@mailoo.org>
parents:
482
diff
changeset
|
182 """ |
589
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
183 if self.type == C.CHAT_GROUP: |
495
587fe75d1b16
browser_side: handle menus of type ROOM, SINGLE and ROSTER_JID
souliane <souliane@mailoo.org>
parents:
482
diff
changeset
|
184 menu_bar.addCachedMenus(C.MENU_ROOM, {'room_jid': self.target.bare}) |
589
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
185 elif self.type == C.CHAT_ONE2ONE: |
495
587fe75d1b16
browser_side: handle menus of type ROOM, SINGLE and ROSTER_JID
souliane <souliane@mailoo.org>
parents:
482
diff
changeset
|
186 menu_bar.addCachedMenus(C.MENU_SINGLE, {'jid': self.target}) |
587fe75d1b16
browser_side: handle menus of type ROOM, SINGLE and ROSTER_JID
souliane <souliane@mailoo.org>
parents:
482
diff
changeset
|
187 |
201
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
188 def getWarningData(self): |
589
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
189 if self.type not in [C.CHAT_ONE2ONE, C.CHAT_GROUP]: |
201
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
190 raise Exception("Unmanaged type !") |
589
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
191 if self.type == C.CHAT_ONE2ONE: |
201
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
192 msg = "This message will be sent to your contact <span class='warningTarget'>%s</span>" % self.target |
589
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
193 elif self.type == C.CHAT_GROUP: |
201
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
194 msg = "This message will be sent to all the participants of the multi-user room <span class='warningTarget'>%s</span>" % self.target |
589
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
195 return ("ONE2ONE" if self.type == C.CHAT_ONE2ONE else "GROUP", msg) |
201
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
196 |
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
197 def onTextEntered(self, text): |
589
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
198 self.host.sendMessage(str(self.target), |
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
199 text, |
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
200 mess_type = C.MESS_TYPE_GROUPCHAT if self.type == C.CHAT_GROUP else C.MESS_TYPE_CHAT, |
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
201 errback=self.host.sendError, |
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
202 profile_key=C.PROF_KEY_NONE |
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
203 ) |
223
624a87377412
browser_side, plugin XEP-0085: limit the number of bridge methods calls for "chatStateComposing".
souliane <souliane@mailoo.org>
parents:
218
diff
changeset
|
204 self.state_machine._onEvent("active") |
201
aa76793da353
server + browser: message warning level/sending refactoring:
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
205 |
179
8475a29d7214
closing a group chat widget now leave the muc room (bug 11)
Goffi <goffi@goffi.org>
parents:
178
diff
changeset
|
206 def onQuit(self): |
195 | 207 base_widget.LiberviaWidget.onQuit(self) |
589
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
208 if self.type == C.CHAT_GROUP: |
179
8475a29d7214
closing a group chat widget now leave the muc room (bug 11)
Goffi <goffi@goffi.org>
parents:
178
diff
changeset
|
209 self.host.bridge.call('mucLeave', None, self.target.bare) |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
210 |
19 | 211 def setUserNick(self, nick): |
212 """Set the nick of the user, usefull for e.g. change the color of the user""" | |
213 self.nick = nick | |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
214 |
33 | 215 def setPresents(self, nicks): |
216 """Set the users presents in this room | |
217 @param occupants: list of nicks (string)""" | |
218 for nick in nicks: | |
219 self.occupants_list.addOccupant(nick) | |
584
0a06cf833f5a
browser_side: various improvements, especially for MUC
souliane <souliane@mailoo.org>
parents:
581
diff
changeset
|
220 self.occupants_initialised = True |
33 | 221 |
589
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
222 # def userJoined(self, nick, data): |
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
223 # if self.occupants_list.getOccupantBox(nick): |
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
224 # return # user is already displayed |
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
225 # self.occupants_list.addOccupant(nick) |
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
226 # if self.occupants_initialised: |
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
227 # self.printInfo("=> %s has joined the room" % nick) |
35 | 228 |
589
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
229 # def userLeft(self, nick, data): |
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
230 # self.occupants_list.removeOccupant(nick) |
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
231 # self.printInfo("<= %s has left the room" % nick) |
35 | 232 |
408
ee8ebfe23e16
browser_side: handle the signal "roomUserChangedNick"
souliane <souliane@mailoo.org>
parents:
407
diff
changeset
|
233 def changeUserNick(self, old_nick, new_nick): |
589
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
234 assert(self.type == C.CHAT_GROUP) |
408
ee8ebfe23e16
browser_side: handle the signal "roomUserChangedNick"
souliane <souliane@mailoo.org>
parents:
407
diff
changeset
|
235 self.occupants_list.removeOccupant(old_nick) |
ee8ebfe23e16
browser_side: handle the signal "roomUserChangedNick"
souliane <souliane@mailoo.org>
parents:
407
diff
changeset
|
236 self.occupants_list.addOccupant(new_nick) |
ee8ebfe23e16
browser_side: handle the signal "roomUserChangedNick"
souliane <souliane@mailoo.org>
parents:
407
diff
changeset
|
237 self.printInfo(_("%(old_nick)s is now known as %(new_nick)s") % {'old_nick': old_nick, 'new_nick': new_nick}) |
ee8ebfe23e16
browser_side: handle the signal "roomUserChangedNick"
souliane <souliane@mailoo.org>
parents:
407
diff
changeset
|
238 |
589
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
239 # def historyPrint(self, size=C.HISTORY_LIMIT_DEFAULT): |
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
240 # """Print the initial history""" |
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
241 # def getHistoryCB(history): |
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
242 # # display day change |
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
243 # day_format = "%A, %d %b %Y" |
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
244 # previous_day = datetime.now().strftime(day_format) |
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
245 # for line in history: |
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
246 # timestamp, from_jid_s, to_jid_s, message, mess_type, extra = line |
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
247 # message_day = datetime.fromtimestamp(float(timestamp or time())).strftime(day_format) |
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
248 # if previous_day != message_day: |
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
249 # self.printInfo("* " + message_day) |
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
250 # previous_day = message_day |
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
251 # self.printMessage(jid.JID(from_jid_s), message, extra, timestamp) |
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
252 # self.host.bridge.call('getHistory', getHistoryCB, self.host.whoami.bare, self.target.bare, size, True) |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
253 |
589
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
254 def printInfo(self, msg, type_='normal', extra=None, link_cb=None): |
35 | 255 """Print general info |
256 @param msg: message to print | |
397
6148e9063069
browser_side: radiocol displays who uploaded the file with ChatPanel.printInfo
souliane <souliane@mailoo.org>
parents:
395
diff
changeset
|
257 @param type_: one of: |
534 | 258 "normal": general info like "toto has joined the room" (will be sanitized) |
259 "link": general info that is clickable like "click here to join the main room" (no sanitize done) | |
260 "me": "/me" information like "/me clenches his fist" ==> "toto clenches his fist" (will stay on one line) | |
589
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
261 @param extra (dict): message data |
397
6148e9063069
browser_side: radiocol displays who uploaded the file with ChatPanel.printInfo
souliane <souliane@mailoo.org>
parents:
395
diff
changeset
|
262 @param link_cb: method to call when the info is clicked, ignored if type_ is not 'link' |
35 | 263 """ |
589
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
264 if extra is None: |
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
265 extra = {} |
397
6148e9063069
browser_side: radiocol displays who uploaded the file with ChatPanel.printInfo
souliane <souliane@mailoo.org>
parents:
395
diff
changeset
|
266 if type_ == 'normal': |
589
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
267 _wid = HTML(strings.addURLToText(html_tools.XHTML2Text(msg))) |
35 | 268 _wid.setStyleName('chatTextInfo') |
397
6148e9063069
browser_side: radiocol displays who uploaded the file with ChatPanel.printInfo
souliane <souliane@mailoo.org>
parents:
395
diff
changeset
|
269 elif type_ == 'link': |
534 | 270 _wid = HTML(msg) |
397
6148e9063069
browser_side: radiocol displays who uploaded the file with ChatPanel.printInfo
souliane <souliane@mailoo.org>
parents:
395
diff
changeset
|
271 _wid.setStyleName('chatTextInfo-link') |
6148e9063069
browser_side: radiocol displays who uploaded the file with ChatPanel.printInfo
souliane <souliane@mailoo.org>
parents:
395
diff
changeset
|
272 if link_cb: |
6148e9063069
browser_side: radiocol displays who uploaded the file with ChatPanel.printInfo
souliane <souliane@mailoo.org>
parents:
395
diff
changeset
|
273 _wid.addClickListener(link_cb) |
6148e9063069
browser_side: radiocol displays who uploaded the file with ChatPanel.printInfo
souliane <souliane@mailoo.org>
parents:
395
diff
changeset
|
274 elif type_ == 'me': |
534 | 275 _wid = Label(msg) |
35 | 276 _wid.setStyleName('chatTextMe') |
277 else: | |
534 | 278 raise ValueError("Unknown printInfo type %s" % type_) |
35 | 279 self.content.add(_wid) |
534 | 280 self.content_scroll.scrollToBottom() |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
281 |
589
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
282 def printMessage(self, from_jid, msg, extra=None, profile=C.PROF_KEY_NONE): |
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
283 if extra is None: |
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
284 extra = {} |
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
285 try: |
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
286 nick, mymess = QuickChat.printMessage(self, from_jid, msg, extra, profile) |
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
287 except TypeError: |
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
288 # None is returned, the message is managed |
35 | 289 return |
589
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
290 self.content.add(ChatText(nick, mymess, msg, extra)) |
34 | 291 self.content_scroll.scrollToBottom() |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
292 |
285
4f0c2fea358a
browser_side (plugin radiocol): use the status label to give more information
souliane <souliane@mailoo.org>
parents:
282
diff
changeset
|
293 def startGame(self, game_type, waiting, referee, players, *args): |
36 | 294 """Configure the chat window to start a game""" |
467 | 295 classes = {"Tarot": card_game.CardPanel, "RadioCol": radiocol.RadioColPanel} |
275
a763b2ac5d41
bridge + browser_side: bridge signals for games and their callbacks:
souliane <souliane@mailoo.org>
parents:
273
diff
changeset
|
296 if game_type not in classes.keys(): |
a763b2ac5d41
bridge + browser_side: bridge signals for games and their callbacks:
souliane <souliane@mailoo.org>
parents:
273
diff
changeset
|
297 return # unknown game |
a763b2ac5d41
bridge + browser_side: bridge signals for games and their callbacks:
souliane <souliane@mailoo.org>
parents:
273
diff
changeset
|
298 attr = game_type.lower() |
342
44491e963eee
browser_side: muc user symbols (used for showing who is playing) can also be removed
souliane <souliane@mailoo.org>
parents:
340
diff
changeset
|
299 self.occupants_list.updateSpecials(players, SYMBOLS[attr]) |
275
a763b2ac5d41
bridge + browser_side: bridge signals for games and their callbacks:
souliane <souliane@mailoo.org>
parents:
273
diff
changeset
|
300 if waiting or not self.nick in players: |
a763b2ac5d41
bridge + browser_side: bridge signals for games and their callbacks:
souliane <souliane@mailoo.org>
parents:
273
diff
changeset
|
301 return # waiting for player or not playing |
a763b2ac5d41
bridge + browser_side: bridge signals for games and their callbacks:
souliane <souliane@mailoo.org>
parents:
273
diff
changeset
|
302 attr = "%s_panel" % attr |
a763b2ac5d41
bridge + browser_side: bridge signals for games and their callbacks:
souliane <souliane@mailoo.org>
parents:
273
diff
changeset
|
303 if hasattr(self, attr): |
a763b2ac5d41
bridge + browser_side: bridge signals for games and their callbacks:
souliane <souliane@mailoo.org>
parents:
273
diff
changeset
|
304 return |
439
d52f529a6d42
browser side: use of new log system (first draft):
Goffi <goffi@goffi.org>
parents:
433
diff
changeset
|
305 log.info("%s Game Started \o/" % game_type) |
285
4f0c2fea358a
browser_side (plugin radiocol): use the status label to give more information
souliane <souliane@mailoo.org>
parents:
282
diff
changeset
|
306 panel = classes[game_type](self, referee, self.nick, players, *args) |
275
a763b2ac5d41
bridge + browser_side: bridge signals for games and their callbacks:
souliane <souliane@mailoo.org>
parents:
273
diff
changeset
|
307 setattr(self, attr, panel) |
a763b2ac5d41
bridge + browser_side: bridge signals for games and their callbacks:
souliane <souliane@mailoo.org>
parents:
273
diff
changeset
|
308 self.vpanel.insert(panel, 0) |
a763b2ac5d41
bridge + browser_side: bridge signals for games and their callbacks:
souliane <souliane@mailoo.org>
parents:
273
diff
changeset
|
309 self.vpanel.setCellHeight(panel, panel.getHeight()) |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
310 |
37
b306aa090438
Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
311 def getGame(self, game_type): |
b306aa090438
Tarot game: game launching (first hand showed), and contract selection
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
312 """Return class managing the game type""" |
226
744426c2b699
browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
223
diff
changeset
|
313 # TODO: check that the game is launched, and manage errors |
210
3092f6b1710c
browser side: make the OK button title for group selector configureable + few "cosmetic" changes (PEP 8...)
souliane <souliane@mailoo.org>
parents:
206
diff
changeset
|
314 if game_type == "Tarot": |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
315 return self.tarot_panel |
210
3092f6b1710c
browser side: make the OK button title for group selector configureable + few "cosmetic" changes (PEP 8...)
souliane <souliane@mailoo.org>
parents:
206
diff
changeset
|
316 elif game_type == "RadioCol": |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
317 return self.radiocol_panel |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
318 |
407
6a6551de4414
browser_side: display chat states (with symbols) for MUC participants
souliane <souliane@mailoo.org>
parents:
404
diff
changeset
|
319 def setState(self, state, nick=None): |
6a6551de4414
browser_side: display chat states (with symbols) for MUC participants
souliane <souliane@mailoo.org>
parents:
404
diff
changeset
|
320 """Set the chat state (XEP-0085) of the contact. Leave nick to None |
6a6551de4414
browser_side: display chat states (with symbols) for MUC participants
souliane <souliane@mailoo.org>
parents:
404
diff
changeset
|
321 to set the state for a one2one conversation, or give a nickname or |
433
bbdbee25123a
import constants.Const as C (according to the coding rules)
souliane <souliane@mailoo.org>
parents:
432
diff
changeset
|
322 C.ALL_OCCUPANTS to set the state of a participant within a MUC. |
407
6a6551de4414
browser_side: display chat states (with symbols) for MUC participants
souliane <souliane@mailoo.org>
parents:
404
diff
changeset
|
323 @param state: the new chat state |
584
0a06cf833f5a
browser_side: various improvements, especially for MUC
souliane <souliane@mailoo.org>
parents:
581
diff
changeset
|
324 @param nick: ignored for one2one, otherwise the MUC user nick or C.ALL_OCCUPANTS |
407
6a6551de4414
browser_side: display chat states (with symbols) for MUC participants
souliane <souliane@mailoo.org>
parents:
404
diff
changeset
|
325 """ |
589
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
326 if self.type == C.CHAT_GROUP: |
581
1c1dbe03d3c6
browser_side: fixes issue while getting a chat state for a MUC occupant who already left
souliane <souliane@mailoo.org>
parents:
580
diff
changeset
|
327 assert(nick) |
1c1dbe03d3c6
browser_side: fixes issue while getting a chat state for a MUC occupant who already left
souliane <souliane@mailoo.org>
parents:
580
diff
changeset
|
328 if nick == C.ALL_OCCUPANTS: |
1c1dbe03d3c6
browser_side: fixes issue while getting a chat state for a MUC occupant who already left
souliane <souliane@mailoo.org>
parents:
580
diff
changeset
|
329 occupants = self.occupants_list.occupants_list.keys() |
1c1dbe03d3c6
browser_side: fixes issue while getting a chat state for a MUC occupant who already left
souliane <souliane@mailoo.org>
parents:
580
diff
changeset
|
330 else: |
1c1dbe03d3c6
browser_side: fixes issue while getting a chat state for a MUC occupant who already left
souliane <souliane@mailoo.org>
parents:
580
diff
changeset
|
331 occupants = [nick] if nick in self.occupants_list.occupants_list else [] |
407
6a6551de4414
browser_side: display chat states (with symbols) for MUC participants
souliane <souliane@mailoo.org>
parents:
404
diff
changeset
|
332 for occupant in occupants: |
6a6551de4414
browser_side: display chat states (with symbols) for MUC participants
souliane <souliane@mailoo.org>
parents:
404
diff
changeset
|
333 self.occupants_list.occupants_list[occupant].setState(state) |
6a6551de4414
browser_side: display chat states (with symbols) for MUC participants
souliane <souliane@mailoo.org>
parents:
404
diff
changeset
|
334 else: |
6a6551de4414
browser_side: display chat states (with symbols) for MUC participants
souliane <souliane@mailoo.org>
parents:
404
diff
changeset
|
335 self._state = state |
6a6551de4414
browser_side: display chat states (with symbols) for MUC participants
souliane <souliane@mailoo.org>
parents:
404
diff
changeset
|
336 self.refreshTitle() |
6a6551de4414
browser_side: display chat states (with symbols) for MUC participants
souliane <souliane@mailoo.org>
parents:
404
diff
changeset
|
337 self.state_machine.started = not not state # start to send "composing" state from now |
6a6551de4414
browser_side: display chat states (with symbols) for MUC participants
souliane <souliane@mailoo.org>
parents:
404
diff
changeset
|
338 |
6a6551de4414
browser_side: display chat states (with symbols) for MUC participants
souliane <souliane@mailoo.org>
parents:
404
diff
changeset
|
339 def refreshTitle(self): |
6a6551de4414
browser_side: display chat states (with symbols) for MUC participants
souliane <souliane@mailoo.org>
parents:
404
diff
changeset
|
340 """Refresh the title of this ChatPanel dialog""" |
6a6551de4414
browser_side: display chat states (with symbols) for MUC participants
souliane <souliane@mailoo.org>
parents:
404
diff
changeset
|
341 if self._state: |
6a6551de4414
browser_side: display chat states (with symbols) for MUC participants
souliane <souliane@mailoo.org>
parents:
404
diff
changeset
|
342 self.setTitle(self.target.bare + " (" + self._state + ")") |
6a6551de4414
browser_side: display chat states (with symbols) for MUC participants
souliane <souliane@mailoo.org>
parents:
404
diff
changeset
|
343 else: |
6a6551de4414
browser_side: display chat states (with symbols) for MUC participants
souliane <souliane@mailoo.org>
parents:
404
diff
changeset
|
344 self.setTitle(self.target.bare) |
6a6551de4414
browser_side: display chat states (with symbols) for MUC participants
souliane <souliane@mailoo.org>
parents:
404
diff
changeset
|
345 |
573
12823bcbd05b
browser_side: display MUC occupants presences
souliane <souliane@mailoo.org>
parents:
567
diff
changeset
|
346 def setConnected(self, jid_s, resource, availability, priority, statuses): |
12823bcbd05b
browser_side: display MUC occupants presences
souliane <souliane@mailoo.org>
parents:
567
diff
changeset
|
347 """Set connection status |
12823bcbd05b
browser_side: display MUC occupants presences
souliane <souliane@mailoo.org>
parents:
567
diff
changeset
|
348 @param jid_s (str): JID userhost as unicode |
12823bcbd05b
browser_side: display MUC occupants presences
souliane <souliane@mailoo.org>
parents:
567
diff
changeset
|
349 """ |
12823bcbd05b
browser_side: display MUC occupants presences
souliane <souliane@mailoo.org>
parents:
567
diff
changeset
|
350 assert(jid_s == self.target.bare) |
589
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
351 if self.type != C.CHAT_GROUP: |
573
12823bcbd05b
browser_side: display MUC occupants presences
souliane <souliane@mailoo.org>
parents:
567
diff
changeset
|
352 return |
577
e1a773a64fb6
browser_side: fixes the display of MUC occupants presences
souliane <souliane@mailoo.org>
parents:
574
diff
changeset
|
353 box = self.occupants_list.getOccupantBox(resource) |
e1a773a64fb6
browser_side: fixes the display of MUC occupants presences
souliane <souliane@mailoo.org>
parents:
574
diff
changeset
|
354 if box: |
589
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
355 contact_list.setPresenceStyle(box, availability) |
202
2bc6cf004e61
browser, server: comments handling:
Goffi <goffi@goffi.org>
parents:
201
diff
changeset
|
356 |
589
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
357 def updateChatState(self, from_jid, state): |
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
358 #TODO |
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
359 pass |
33 | 360 |
598
ed6d8f7c6026
browser side (blog, chat): fixed dropKey callbacks to adapt them to new widget creation system. Drag'n'Drop should be fixed.
Goffi <goffi@goffi.org>
parents:
589
diff
changeset
|
361 |
589
a5019e62c3e9
browser side: big refactoring to base Libervia on QuickFrontend, first draft:
Goffi <goffi@goffi.org>
parents:
585
diff
changeset
|
362 quick_widgets.register(QuickChat, Chat) |
598
ed6d8f7c6026
browser side (blog, chat): fixed dropKey callbacks to adapt them to new widget creation system. Drag'n'Drop should be fixed.
Goffi <goffi@goffi.org>
parents:
589
diff
changeset
|
363 base_widget.LiberviaWidget.addDropKey("CONTACT", lambda host, item: host.widgets.getOrCreateWidget(Chat, jid.JID(item), profile=C.PROF_KEY_NONE, on_new_widget=None, on_existing_widget=C.WIDGET_RECREATE)) |