Mercurial > libervia-backend
annotate frontends/src/primitivus/chat.py @ 1265:e3a9ea76de35 frontends_multi_profiles
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
This refactoring allow primitivus to manage correctly several profiles at once, with various other improvments:
- profile_manager can now plug several profiles at once, requesting password when needed. No more profile plug specific method is used anymore in backend, instead a "validated" key is used in actions
- Primitivus widget are now based on a common "PrimitivusWidget" classe which mainly manage the decoration so far
- all widgets are treated in the same way (contactList, Chat, Progress, etc), no more chat_wins specific behaviour
- widgets are created in a dedicated manager, with facilities to react on new widget creation or other events
- quick_frontend introduce a new QuickWidget class, which aims to be as generic and flexible as possible. It can manage several targets (jids or something else), and several profiles
- each widget class return a Hash according to its target. For example if given a target jid and a profile, a widget class return a hash like (target.bare, profile), the same widget will be used for all resources of the same jid
- better management of CHAT_GROUP mode for Chat widgets
- some code moved from Primitivus to QuickFrontend, the final goal is to have most non backend code in QuickFrontend, and just graphic code in subclasses
- no more (un)escapePrivate/PRIVATE_PREFIX
- contactList improved a lot: entities not in roster and special entities (private MUC conversations) are better managed
- resources can be displayed in Primitivus, and their status messages
- profiles are managed in QuickFrontend with dedicated managers
This is work in progress, other frontends are broken. Urwid SàText need to be updated. Most of features of Primitivus should work as before (or in a better way ;))
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 10 Dec 2014 19:00:09 +0100 |
parents | 802b7e6bf098 |
children | faa1129559b8 |
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 |
811 | 5 # Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014 Jérôme Poisson (goffi@goffi.org) |
119
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
6 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
607
diff
changeset
|
7 # This program is free software: you can redistribute it and/or modify |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
607
diff
changeset
|
8 # it under the terms of the GNU Affero General Public License as published by |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
607
diff
changeset
|
9 # the Free Software Foundation, either version 3 of the License, or |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
607
diff
changeset
|
10 # (at your option) any later version. |
119
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
607
diff
changeset
|
12 # This program is distributed in the hope that it will be useful, |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
607
diff
changeset
|
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
607
diff
changeset
|
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
607
diff
changeset
|
15 # GNU Affero General Public License for more details. |
119
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
607
diff
changeset
|
17 # You should have received a copy of the GNU Affero General Public License |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
607
diff
changeset
|
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
119
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 |
771 | 20 from sat.core.i18n import _ |
1180
69aace10b46d
Primitivus (file transfer): an error popup is shown when bad unicode is used in path, and an info popup is show to indicate that the file request has been sent
Goffi <goffi@goffi.org>
parents:
1173
diff
changeset
|
21 from sat.core import log as logging |
69aace10b46d
Primitivus (file transfer): an error popup is shown when bad unicode is used in path, and an info popup is show to indicate that the file request has been sent
Goffi <goffi@goffi.org>
parents:
1173
diff
changeset
|
22 log = logging.getLogger(__name__) |
119
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
23 import urwid |
222
3198bfd66daa
primitivus: refactoring to use urwid-satext which is now a separate project
Goffi <goffi@goffi.org>
parents:
202
diff
changeset
|
24 from urwid_satext import sat_widgets |
225
fd9b7834d98a
distutils installation script, draft
Goffi <goffi@goffi.org>
parents:
223
diff
changeset
|
25 from urwid_satext.files_management import FileDialog |
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 |
fd9b7834d98a
distutils installation script, draft
Goffi <goffi@goffi.org>
parents:
223
diff
changeset
|
28 from sat_frontends.primitivus.card_game import CardGame |
1058
0a9986452bba
frontends: fixes bug with private message introduced with revision 1000 (6f1e03068b5f) + display messages from contacts not in roster
souliane <souliane@mailoo.org>
parents:
911
diff
changeset
|
29 from sat_frontends.primitivus.constants import Const as C |
1158
c0f15e52695a
primitivus: use of new keys modules from Urwid SàText
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
30 from sat_frontends.primitivus.keys import action_key_map as a_key |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1223
diff
changeset
|
31 from sat_frontends.primitivus.widget import PrimitivusWidget |
124 | 32 import time |
1139
75025461141f
move sat.tools.jid to sat_frontends.tools.jid
souliane <souliane@mailoo.org>
parents:
1133
diff
changeset
|
33 from sat_frontends.tools.jid import JID |
124 | 34 |
35 | |
36 class ChatText(urwid.FlowWidget): | |
37 """Manage the printing of chat message""" | |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
38 |
531
3bd8f84f920d
primitivus: fixed info messages timestamp
Goffi <goffi@goffi.org>
parents:
521
diff
changeset
|
39 def __init__(self, parent, timestamp, nick, my_mess, message, align='left', is_info=False): |
124 | 40 self.parent = parent |
41 self.timestamp = time.localtime(timestamp) | |
190
31632472e857
quick_frontend, wix, primitivus: informations in chat window
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
42 self.nick = nick |
31632472e857
quick_frontend, wix, primitivus: informations in chat window
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
43 self.my_mess = my_mess |
124 | 44 self.message = unicode(message) |
45 self.align = align | |
531
3bd8f84f920d
primitivus: fixed info messages timestamp
Goffi <goffi@goffi.org>
parents:
521
diff
changeset
|
46 self.is_info = is_info |
124 | 47 |
48 def selectable(self): | |
49 return True | |
119
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
50 |
124 | 51 def keypress(self, size, key): |
52 return key | |
53 | |
54 def rows(self,size,focus=False): | |
55 return self.display_widget(size, focus).rows(size, focus) | |
56 | |
57 def render(self, size, focus=False): | |
125
8d611eb9ae48
primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents:
124
diff
changeset
|
58 canvas = urwid.CompositeCanvas(self.display_widget(size, focus).render(size, focus)) |
8d611eb9ae48
primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents:
124
diff
changeset
|
59 if focus: |
8d611eb9ae48
primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents:
124
diff
changeset
|
60 canvas.set_cursor(self.get_cursor_coords(size)) |
8d611eb9ae48
primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents:
124
diff
changeset
|
61 return canvas |
8d611eb9ae48
primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents:
124
diff
changeset
|
62 |
8d611eb9ae48
primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents:
124
diff
changeset
|
63 def get_cursor_coords(self, size): |
8d611eb9ae48
primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents:
124
diff
changeset
|
64 #(maxcol,) = size |
8d611eb9ae48
primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents:
124
diff
changeset
|
65 return 0, 0 |
124 | 66 |
67 def display_widget(self, size, focus): | |
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: |
3bd8f84f920d
primitivus: fixed info messages timestamp
Goffi <goffi@goffi.org>
parents:
521
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 |
3bd8f84f920d
primitivus: fixed info messages timestamp
Goffi <goffi@goffi.org>
parents:
521
diff
changeset
|
72 render_txt.append(('date',"[%s]" % time.strftime(time_format, self.timestamp).decode('utf-8'))) |
3bd8f84f920d
primitivus: fixed info messages timestamp
Goffi <goffi@goffi.org>
parents:
521
diff
changeset
|
73 if self.parent.show_short_nick: |
3bd8f84f920d
primitivus: fixed info messages timestamp
Goffi <goffi@goffi.org>
parents:
521
diff
changeset
|
74 render_txt.append(('my_nick' if self.my_mess else 'other_nick',"**" if self.my_mess else "*")) |
3bd8f84f920d
primitivus: fixed info messages timestamp
Goffi <goffi@goffi.org>
parents:
521
diff
changeset
|
75 else: |
3bd8f84f920d
primitivus: fixed info messages timestamp
Goffi <goffi@goffi.org>
parents:
521
diff
changeset
|
76 render_txt.append(('my_nick' if self.my_mess else 'other_nick',"[%s] " % self.nick)) |
124 | 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 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1223
diff
changeset
|
86 def __init__(self, host, target, type_='one2one', profiles=None): |
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 | 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 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1223
diff
changeset
|
96 # we must adapt the behavious with the type |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1223
diff
changeset
|
97 if type_ == 'one2one': |
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) |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1223
diff
changeset
|
99 elif type_ == 'group': |
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: |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1223
diff
changeset
|
101 present_widget = self._buildPresentList() |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1223
diff
changeset
|
102 self.present_panel = sat_widgets.VerticalSeparator(present_widget) |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1223
diff
changeset
|
103 self._appendPresentPanel() |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1223
diff
changeset
|
104 |
124 | 105 self.day_change = time.strptime(time.strftime("%a %b %d 00:00:00 %Y")) #struct_time of day changing time |
106 self.show_timestamp = True | |
107 self.show_short_nick = False | |
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
|
108 self.show_title = 1 #0: clip title; 1: full title; 2: no title |
124 | 109 self.subject = None |
110 | |
111 def keypress(self, size, key): | |
1158
c0f15e52695a
primitivus: use of new keys modules from Urwid SàText
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
112 if key == a_key['OCCUPANTS_HIDE']: #user wants to (un)hide the presents panel |
124 | 113 if self.type == 'group': |
607
c123dddaea6b
primitivus: fixed urwid issues with recent urwid versions
Goffi <goffi@goffi.org>
parents:
587
diff
changeset
|
114 widgets = [widget for (widget, options) in self.chat_colums.contents] |
124 | 115 if self.present_panel in widgets: |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1223
diff
changeset
|
116 self._removePresentPanel() |
124 | 117 else: |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1223
diff
changeset
|
118 self._appendPresentPanel() |
1158
c0f15e52695a
primitivus: use of new keys modules from Urwid SàText
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
119 elif key == a_key['TIMESTAMP_HIDE']: #user wants to (un)hide timestamp |
124 | 120 self.show_timestamp = not self.show_timestamp |
121 for wid in self.content: | |
122 wid._invalidate() | |
1158
c0f15e52695a
primitivus: use of new keys modules from Urwid SàText
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
123 elif key == a_key['SHORT_NICKNAME']: #user wants to (not) use short nick |
124 | 124 self.show_short_nick = not self.show_short_nick |
125 for wid in self.content: | |
126 wid._invalidate() | |
1158
c0f15e52695a
primitivus: use of new keys modules from Urwid SàText
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
127 elif key == a_key['SUBJECT_SWITCH']: #user wants to (un)hide group's subject or change its apperance |
124 | 128 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
|
129 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
|
130 if self.show_title == 0: |
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 self.setSubject(self.subject,'clip') |
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
|
132 elif self.show_title == 1: |
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 self.setSubject(self.subject,'space') |
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
|
134 elif self.show_title == 2: |
124 | 135 self.chat_widget.header = None |
136 self._invalidate() | |
137 | |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
138 return super(Chat, self).keypress(size, key) |
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
139 |
137
227394eb080c
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
130
diff
changeset
|
140 def getMenu(self): |
227394eb080c
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
130
diff
changeset
|
141 """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
|
142 menu = sat_widgets.Menu(self.host.loop) |
137
227394eb080c
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
130
diff
changeset
|
143 if self.type == 'group': |
1093
11e2bb20e896
core, frontends (menus): MENU_ROOM and MENU_SINGLE are now managed
Goffi <goffi@goffi.org>
parents:
1063
diff
changeset
|
144 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
|
145 game = _("Game") |
227394eb080c
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
130
diff
changeset
|
146 menu.addMenu(game, "Tarot", self.onTarotRequest) |
176 | 147 elif self.type == 'one2one': |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1223
diff
changeset
|
148 self.host.addMenus(menu, C.MENU_SINGLE, {'jid': self.target}) |
176 | 149 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
|
150 return menu |
124 | 151 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1223
diff
changeset
|
152 def updateChatState(self, from_jid, state): |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1223
diff
changeset
|
153 if self.type == C.CHAT_GROUP: |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1223
diff
changeset
|
154 if from_jid == C.ENTITY_ALL: |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1223
diff
changeset
|
155 occupants = self.occupants |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1223
diff
changeset
|
156 else: |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1223
diff
changeset
|
157 nick = from_jid.resource |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1223
diff
changeset
|
158 if not nick: |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1223
diff
changeset
|
159 log.debug("no nick found for chatstate") |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1223
diff
changeset
|
160 return |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1223
diff
changeset
|
161 occupants = [nick] |
907
cd02f5ef30df
primitivus: display chat states (with symbols) for MUC participants
souliane <souliane@mailoo.org>
parents:
844
diff
changeset
|
162 options = self.present_wid.getAllValues() |
cd02f5ef30df
primitivus: display chat states (with symbols) for MUC participants
souliane <souliane@mailoo.org>
parents:
844
diff
changeset
|
163 for index in xrange(0, len(options)): |
cd02f5ef30df
primitivus: display chat states (with symbols) for MUC participants
souliane <souliane@mailoo.org>
parents:
844
diff
changeset
|
164 nick = options[index].value |
cd02f5ef30df
primitivus: display chat states (with symbols) for MUC participants
souliane <souliane@mailoo.org>
parents:
844
diff
changeset
|
165 if nick in occupants: |
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
|
166 options[index] = (nick, '%s %s' % (C.MUC_USER_STATES[state], nick)) |
907
cd02f5ef30df
primitivus: display chat states (with symbols) for MUC participants
souliane <souliane@mailoo.org>
parents:
844
diff
changeset
|
167 self.present_wid.changeValues(options) |
cd02f5ef30df
primitivus: display chat states (with symbols) for MUC participants
souliane <souliane@mailoo.org>
parents:
844
diff
changeset
|
168 self.host.redraw() |
cd02f5ef30df
primitivus: display chat states (with symbols) for MUC participants
souliane <souliane@mailoo.org>
parents:
844
diff
changeset
|
169 else: |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1223
diff
changeset
|
170 self.title_dynamic = '({})'.format(state) |
637
3b02554d4c8b
primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents:
610
diff
changeset
|
171 |
511
62f7f2403093
Primitivus: present contacts in groups chat can now be clicked
Goffi <goffi@goffi.org>
parents:
510
diff
changeset
|
172 def _presentClicked(self, list_wid, clicked_wid): |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1223
diff
changeset
|
173 assert self.type == 'group' |
907
cd02f5ef30df
primitivus: display chat states (with symbols) for MUC participants
souliane <souliane@mailoo.org>
parents:
844
diff
changeset
|
174 nick = clicked_wid.getValue().value |
511
62f7f2403093
Primitivus: present contacts in groups chat can now be clicked
Goffi <goffi@goffi.org>
parents:
510
diff
changeset
|
175 if nick == self.getUserNick(): |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1223
diff
changeset
|
176 #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
|
177 return |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1223
diff
changeset
|
178 contact_list = self.host.contact_lists[self.profile] |
688
f7878ad3c846
tools: renamed tools.jid.JID attribute "short" to "bare"
souliane <souliane@mailoo.org>
parents:
678
diff
changeset
|
179 full_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
|
180 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1223
diff
changeset
|
181 #we have a click on a nick, we need to create the widget if it doesn't exists |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1223
diff
changeset
|
182 self.getOrCreatePrivateWidget(full_jid) |
511
62f7f2403093
Primitivus: present contacts in groups chat can now be clicked
Goffi <goffi@goffi.org>
parents:
510
diff
changeset
|
183 |
62f7f2403093
Primitivus: present contacts in groups chat can now be clicked
Goffi <goffi@goffi.org>
parents:
510
diff
changeset
|
184 #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
|
185 contact_list.setFocus(full_jid, True) |
124 | 186 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1223
diff
changeset
|
187 def _buildPresentList(self): |
511
62f7f2403093
Primitivus: present contacts in groups chat can now be clicked
Goffi <goffi@goffi.org>
parents:
510
diff
changeset
|
188 self.present_wid = sat_widgets.GenericList([],option_type = sat_widgets.ClickableText, on_click=self._presentClicked) |
124 | 189 return self.present_wid |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
190 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1223
diff
changeset
|
191 def _appendPresentPanel(self): |
607
c123dddaea6b
primitivus: fixed urwid issues with recent urwid versions
Goffi <goffi@goffi.org>
parents:
587
diff
changeset
|
192 self.chat_colums.contents.append((self.present_panel,('weight', 2, False))) |
124 | 193 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1223
diff
changeset
|
194 def _removePresentPanel(self): |
607
c123dddaea6b
primitivus: fixed urwid issues with recent urwid versions
Goffi <goffi@goffi.org>
parents:
587
diff
changeset
|
195 for widget, options in self.chat_colums.contents: |
c123dddaea6b
primitivus: fixed urwid issues with recent urwid versions
Goffi <goffi@goffi.org>
parents:
587
diff
changeset
|
196 if widget is self.present_panel: |
c123dddaea6b
primitivus: fixed urwid issues with recent urwid versions
Goffi <goffi@goffi.org>
parents:
587
diff
changeset
|
197 self.chat_colums.contents.remove((widget, options)) |
c123dddaea6b
primitivus: fixed urwid issues with recent urwid versions
Goffi <goffi@goffi.org>
parents:
587
diff
changeset
|
198 break |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
199 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1223
diff
changeset
|
200 def _appendGamePanel(self, widget): |
607
c123dddaea6b
primitivus: fixed urwid issues with recent urwid versions
Goffi <goffi@goffi.org>
parents:
587
diff
changeset
|
201 assert (len(self.pile.contents) == 1) |
610
c8c07c920e30
Primitivus: fixed xmlui/chat bad contents change
Goffi <goffi@goffi.org>
parents:
609
diff
changeset
|
202 self.pile.contents.insert(0,(widget,('weight', 1))) |
607
c123dddaea6b
primitivus: fixed urwid issues with recent urwid versions
Goffi <goffi@goffi.org>
parents:
587
diff
changeset
|
203 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
|
204 self.host.redraw() |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
205 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1223
diff
changeset
|
206 def _removeGamePanel(self): |
607
c123dddaea6b
primitivus: fixed urwid issues with recent urwid versions
Goffi <goffi@goffi.org>
parents:
587
diff
changeset
|
207 assert (len(self.pile.contents) == 3) |
c123dddaea6b
primitivus: fixed urwid issues with recent urwid versions
Goffi <goffi@goffi.org>
parents:
587
diff
changeset
|
208 del self.pile.contents[0] |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
209 self.host.redraw() |
124 | 210 |
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
|
211 def setSubject(self, subject, wrap='space'): |
120 | 212 """Set title for a group chat""" |
213 QuickChat.setSubject(self, subject) | |
124 | 214 self.subject = 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
|
215 self.subj_wid = urwid.Text(unicode(subject.replace('\n','|') if wrap == 'clip' else subject ), |
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
|
216 align='left' if wrap=='clip' else 'center',wrap=wrap) |
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
|
217 self.chat_widget.header = urwid.AttrMap(self.subj_wid,'title') |
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
|
218 self.host.redraw() |
124 | 219 |
220 def setPresents(self, param_nicks): | |
221 """Set the users presents in the contact list for a group chat | |
222 @param nicks: list of nicknames | |
223 """ | |
224 nicks = [unicode(nick) for nick in param_nicks] #FIXME: should be done in DBus bridge | |
225 nicks.sort() | |
226 QuickChat.setPresents(self, nicks) | |
227 self.present_wid.changeValues(nicks) | |
228 self.host.redraw() | |
120 | 229 |
507
f98bef71a918
frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents:
501
diff
changeset
|
230 def replaceUser(self, param_nick, show_info=True): |
124 | 231 """Add user if it is not in the group list""" |
232 nick = unicode(param_nick) #FIXME: should be done in DBus bridge | |
507
f98bef71a918
frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents:
501
diff
changeset
|
233 QuickChat.replaceUser(self, nick, show_info) |
124 | 234 presents = self.present_wid.getAllValues() |
907
cd02f5ef30df
primitivus: display chat states (with symbols) for MUC participants
souliane <souliane@mailoo.org>
parents:
844
diff
changeset
|
235 if nick not in [present.value for present in presents]: |
124 | 236 presents.append(nick) |
907
cd02f5ef30df
primitivus: display chat states (with symbols) for MUC participants
souliane <souliane@mailoo.org>
parents:
844
diff
changeset
|
237 presents.sort(cmp=lambda a, b: cmp(a.value if hasattr(a, 'value') else a, b.value if hasattr(b, 'value') else b)) |
124 | 238 self.present_wid.changeValues(presents) |
239 self.host.redraw() | |
240 | |
507
f98bef71a918
frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents:
501
diff
changeset
|
241 def removeUser(self, param_nick, show_info=True): |
124 | 242 """Remove a user from the group list""" |
243 nick = unicode(param_nick) #FIXME: should be done in DBus bridge | |
507
f98bef71a918
frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents:
501
diff
changeset
|
244 QuickChat.removeUser(self, nick, show_info) |
124 | 245 self.present_wid.deleteValue(nick) |
246 self.host.redraw() | |
119
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
247 |
1125
d6c3fea5ecfe
quick_frontend, primitivus: add primitivus command ":history [limit]" (default value for limit is 50)
souliane <souliane@mailoo.org>
parents:
1120
diff
changeset
|
248 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
|
249 """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
|
250 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
|
251 |
d6c3fea5ecfe
quick_frontend, primitivus: add primitivus command ":history [limit]" (default value for limit is 50)
souliane <souliane@mailoo.org>
parents:
1120
diff
changeset
|
252 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
|
253 """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
|
254 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
|
255 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
|
256 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
|
257 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1223
diff
changeset
|
258 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
|
259 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
|
260 |
1223
802b7e6bf098
frontends: printInfo and printMessage timestamp attribute defaults to None instead of ''
souliane <souliane@mailoo.org>
parents:
1185
diff
changeset
|
261 def printMessage(self, from_jid, msg, profile, timestamp=None): |
153
f197b52796ee
Primitivus: begining of management for actionResult
Goffi <goffi@goffi.org>
parents:
144
diff
changeset
|
262 assert isinstance(from_jid, JID) |
190
31632472e857
quick_frontend, wix, primitivus: informations in chat window
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
263 try: |
678
a630b94280d5
primitivus: code factorization for user notification
souliane <souliane@mailoo.org>
parents:
638
diff
changeset
|
264 jid, nick, mymess = QuickChat.printMessage(self, from_jid, msg, profile, timestamp) |
190
31632472e857
quick_frontend, wix, primitivus: informations in chat window
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
265 except TypeError: |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1223
diff
changeset
|
266 # 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
|
267 return |
1223
802b7e6bf098
frontends: printInfo and printMessage timestamp attribute defaults to None instead of ''
souliane <souliane@mailoo.org>
parents:
1185
diff
changeset
|
268 new_text = ChatText(self, timestamp, nick, mymess, msg) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
269 |
520
4d7248f4c577
primitivus: better chat text insertion in chat window
Goffi <goffi@goffi.org>
parents:
518
diff
changeset
|
270 if timestamp and self.content: |
678
a630b94280d5
primitivus: code factorization for user notification
souliane <souliane@mailoo.org>
parents:
638
diff
changeset
|
271 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
|
272 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
|
273 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
|
274 if older and idx > 0: |
678
a630b94280d5
primitivus: code factorization for user notification
souliane <souliane@mailoo.org>
parents:
638
diff
changeset
|
275 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
|
276 |
520
4d7248f4c577
primitivus: better chat text insertion in chat window
Goffi <goffi@goffi.org>
parents:
518
diff
changeset
|
277 #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
|
278 # 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
|
279 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
|
280 (self.content[idx].message == msg) or |
678
a630b94280d5
primitivus: code factorization for user notification
souliane <souliane@mailoo.org>
parents:
638
diff
changeset
|
281 (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
|
282 return |
4d7248f4c577
primitivus: better chat text insertion in chat window
Goffi <goffi@goffi.org>
parents:
518
diff
changeset
|
283 |
1126
8870417c8e8c
primitivus (chat): fixes the messages display when opening a new chat window
souliane <souliane@mailoo.org>
parents:
1125
diff
changeset
|
284 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
|
285 break |
4d7248f4c577
primitivus: better chat text insertion in chat window
Goffi <goffi@goffi.org>
parents:
518
diff
changeset
|
286 else: |
4d7248f4c577
primitivus: better chat text insertion in chat window
Goffi <goffi@goffi.org>
parents:
518
diff
changeset
|
287 self.content.append(new_text) |
1120
d1f6b927131e
primitivus: prevent a notification flood when displaying the history
souliane <souliane@mailoo.org>
parents:
1106
diff
changeset
|
288 if not timestamp: |
d1f6b927131e
primitivus: prevent a notification flood when displaying the history
souliane <souliane@mailoo.org>
parents:
1106
diff
changeset
|
289 # 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
|
290 # 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
|
291 # 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
|
292 self._notify(from_jid, msg) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
293 |
1223
802b7e6bf098
frontends: printInfo and printMessage timestamp attribute defaults to None instead of ''
souliane <souliane@mailoo.org>
parents:
1185
diff
changeset
|
294 def printInfo(self, msg, type_='normal', timestamp=None): |
190
31632472e857
quick_frontend, wix, primitivus: informations in chat window
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
295 """Print general info |
31632472e857
quick_frontend, wix, primitivus: informations in chat window
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
296 @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
|
297 @type_: one of: |
190
31632472e857
quick_frontend, wix, primitivus: informations in chat window
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
298 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
|
299 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
|
300 @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
|
301 """ |
1223
802b7e6bf098
frontends: printInfo and printMessage timestamp attribute defaults to None instead of ''
souliane <souliane@mailoo.org>
parents:
1185
diff
changeset
|
302 _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
|
303 self.content.append(_widget) |
678
a630b94280d5
primitivus: code factorization for user notification
souliane <souliane@mailoo.org>
parents:
638
diff
changeset
|
304 self._notify(msg=msg) |
a630b94280d5
primitivus: code factorization for user notification
souliane <souliane@mailoo.org>
parents:
638
diff
changeset
|
305 |
a630b94280d5
primitivus: code factorization for user notification
souliane <souliane@mailoo.org>
parents:
638
diff
changeset
|
306 def _notify(self, from_jid="somebody", msg=""): |
a630b94280d5
primitivus: code factorization for user notification
souliane <souliane@mailoo.org>
parents:
638
diff
changeset
|
307 """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
|
308 @param from_jid: contact who wrote to the users |
a630b94280d5
primitivus: code factorization for user notification
souliane <souliane@mailoo.org>
parents:
638
diff
changeset
|
309 @param msg: the message that has been received |
a630b94280d5
primitivus: code factorization for user notification
souliane <souliane@mailoo.org>
parents:
638
diff
changeset
|
310 """ |
739
7b72d5c30ebc
primivitus: do not notify when an empty message is received
souliane <souliane@mailoo.org>
parents:
688
diff
changeset
|
311 if msg == "": |
7b72d5c30ebc
primivitus: do not notify when an empty message is received
souliane <souliane@mailoo.org>
parents:
688
diff
changeset
|
312 return |
678
a630b94280d5
primitivus: code factorization for user notification
souliane <souliane@mailoo.org>
parents:
638
diff
changeset
|
313 if self.text_list.get_focus()[1] == len(self.content) - 2: |
430
7c7ec2347b56
primitivus: chat window is not scrolled anymore when user is watching history and a new message is received
Goffi <goffi@goffi.org>
parents:
387
diff
changeset
|
314 #we don't change focus if user is not at the bottom |
7c7ec2347b56
primitivus: chat window is not scrolled anymore when user is watching history and a new message is received
Goffi <goffi@goffi.org>
parents:
387
diff
changeset
|
315 #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
|
316 self.text_list.focus_position = len(self.content) - 1 |
119
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
317 self.host.redraw() |
507
f98bef71a918
frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents:
501
diff
changeset
|
318 if not self.host.x_notify.hasFocus(): |
678
a630b94280d5
primitivus: code factorization for user notification
souliane <souliane@mailoo.org>
parents:
638
diff
changeset
|
319 if self.type == "one2one": |
a630b94280d5
primitivus: code factorization for user notification
souliane <souliane@mailoo.org>
parents:
638
diff
changeset
|
320 self.host.x_notify.sendNotification(_("Primitivus: %s is talking to you") % from_jid) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
321 elif self.getUserNick().lower() in msg.lower(): |
844
f3513c8cc2e6
misc: fix unnamed arguments in format strings
souliane <souliane@mailoo.org>
parents:
812
diff
changeset
|
322 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
|
323 |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
324 def startGame(self, game_type, referee, players): |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
325 """Configure the chat window to start a game""" |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
326 if game_type=="Tarot": |
501
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
327 self.tarot_wid = CardGame(self, referee, players, self.nick) |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1223
diff
changeset
|
328 self._appendGamePanel(self.tarot_wid) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
329 |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
330 def getGame(self, game_type): |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
331 """Return class managing the game type""" |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
332 #TODO: check that the game is launched, and manage errors |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
333 if game_type=="Tarot": |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
334 return self.tarot_wid |
137
227394eb080c
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
130
diff
changeset
|
335 |
227394eb080c
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
130
diff
changeset
|
336 #MENU EVENTS# |
227394eb080c
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
130
diff
changeset
|
337 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
|
338 # 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
|
339 if len(self.occupants) != 4: |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
340 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
|
341 else: |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1223
diff
changeset
|
342 self.host.bridge.tarotGameCreate(self.id, list(self.occupants), self.profile) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
343 |
176 | 344 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
|
345 # TODO: move this to core with dynamic menus |
180
fdb961f27ae9
Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents:
176
diff
changeset
|
346 dialog = FileDialog(ok_cb=self.onFileSelected, cancel_cb=self.host.removePopUp) |
176 | 347 self.host.showPopUp(dialog, 80, 80) |
348 | |
180
fdb961f27ae9
Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents:
176
diff
changeset
|
349 #MISC EVENTS# |
fdb961f27ae9
Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents:
176
diff
changeset
|
350 def onFileSelected(self, filepath): |
fdb961f27ae9
Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents:
176
diff
changeset
|
351 self.host.removePopUp() |
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
|
352 try: |
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
|
353 filepath = filepath.decode('utf-8') # FIXME: correctly manage unicode |
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
|
354 except UnicodeError: |
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
|
355 log.error("FIXME: filepath with unicode error are not managed yet") |
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
|
356 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") |
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
|
357 return |
501
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
358 #FIXME: check last_resource: what if self.target.resource exists ? |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1223
diff
changeset
|
359 last_resource = self.host.bridge.getLastResource(unicode(self.target.bare), self.profile) |
501
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
360 if last_resource: |
688
f7878ad3c846
tools: renamed tools.jid.JID attribute "short" to "bare"
souliane <souliane@mailoo.org>
parents:
678
diff
changeset
|
361 full_jid = JID("%s/%s" % (self.target.bare, last_resource)) |
501
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
362 else: |
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
363 full_jid = self.target |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1223
diff
changeset
|
364 progress_id = self.host.bridge.sendFile(full_jid, filepath, {}, self.profile) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
365 self.host.addProgress(progress_id,filepath) |
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
|
366 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
|
367 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1223
diff
changeset
|
368 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1223
diff
changeset
|
369 quick_widgets.register(QuickChat, Chat) |