annotate frontends/src/primitivus/chat.py @ 853:c2f6ada7858f

core (sqlite): automatic database update: - new Updater class check database consistency (by calculating a hash on the .schema), and updates base if necessary - database now has a version (1 for current, 0 will be for 0.3's database), for each change this version will be increased - creation statements and update statements are in the form of dict of dict with tuples. There is a help text at the top of the module to explain how it works - if we are on a development version, the updater try to update the database automaticaly (without deleting table or columns). The Updater.generateUpdateData method can be used to ease the creation of update data (i.e. the dictionary at the top, see the one for the key 1 for an example). - if there is an inconsistency, an exception is raised, and a message indicate the SQL statements that should fix the situation. - well... this is rather complicated, a KISS method would maybe have been better. The future will say if we need to simplify it :-/ - new DatabaseError exception
author Goffi <goffi@goffi.org>
date Sun, 23 Feb 2014 23:30:32 +0100
parents f3513c8cc2e6
children cd02f5ef30df
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/python
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff changeset
3
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 607
diff changeset
4 # Primitivus: a SAT frontend
811
1fe00f0c9a91 dates update
Goffi <goffi@goffi.org>
parents: 801
diff changeset
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
bfabeedbf32e core: i18n refactoring:
Goffi <goffi@goffi.org>
parents: 739
diff changeset
20 from sat.core.i18n import _
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff changeset
21 import urwid
222
3198bfd66daa primitivus: refactoring to use urwid-satext which is now a separate project
Goffi <goffi@goffi.org>
parents: 202
diff changeset
22 from urwid_satext import sat_widgets
225
fd9b7834d98a distutils installation script, draft
Goffi <goffi@goffi.org>
parents: 223
diff changeset
23 from urwid_satext.files_management import FileDialog
fd9b7834d98a distutils installation script, draft
Goffi <goffi@goffi.org>
parents: 223
diff changeset
24 from sat_frontends.quick_frontend.quick_chat import QuickChat
fd9b7834d98a distutils installation script, draft
Goffi <goffi@goffi.org>
parents: 223
diff changeset
25 from sat_frontends.primitivus.card_game import CardGame
511
62f7f2403093 Primitivus: present contacts in groups chat can now be clicked
Goffi <goffi@goffi.org>
parents: 510
diff changeset
26 from sat_frontends.quick_frontend.quick_utils import escapePrivate, unescapePrivate
801
02ee9ef95277 plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents: 771
diff changeset
27 from sat_frontends.primitivus.xmlui import XMLUI
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
28 import time
225
fd9b7834d98a distutils installation script, draft
Goffi <goffi@goffi.org>
parents: 223
diff changeset
29 from sat.tools.jid import JID
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
30
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
31
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
32 class ChatText(urwid.FlowWidget):
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
33 """Manage the printing of chat message"""
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
34
531
3bd8f84f920d primitivus: fixed info messages timestamp
Goffi <goffi@goffi.org>
parents: 521
diff changeset
35 def __init__(self, parent, timestamp, nick, my_mess, message, align='left', is_info=False):
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
36 self.parent = parent
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
37 self.timestamp = time.localtime(timestamp)
190
31632472e857 quick_frontend, wix, primitivus: informations in chat window
Goffi <goffi@goffi.org>
parents: 181
diff changeset
38 self.nick = nick
31632472e857 quick_frontend, wix, primitivus: informations in chat window
Goffi <goffi@goffi.org>
parents: 181
diff changeset
39 self.my_mess = my_mess
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
40 self.message = unicode(message)
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
41 self.align = align
531
3bd8f84f920d primitivus: fixed info messages timestamp
Goffi <goffi@goffi.org>
parents: 521
diff changeset
42 self.is_info = is_info
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
43
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
44 def selectable(self):
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
45 return True
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff changeset
46
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
47 def keypress(self, size, key):
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
48 return key
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
49
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
50 def rows(self,size,focus=False):
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
51 return self.display_widget(size, focus).rows(size, focus)
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
52
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
53 def render(self, size, focus=False):
125
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
54 canvas = urwid.CompositeCanvas(self.display_widget(size, focus).render(size, focus))
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
55 if focus:
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
56 canvas.set_cursor(self.get_cursor_coords(size))
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
57 return canvas
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
58
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
59 def get_cursor_coords(self, size):
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
60 #(maxcol,) = size
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
61 return 0, 0
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
62
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
63 def display_widget(self, size, focus):
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
64 render_txt = []
531
3bd8f84f920d primitivus: fixed info messages timestamp
Goffi <goffi@goffi.org>
parents: 521
diff changeset
65 if not self.is_info:
3bd8f84f920d primitivus: fixed info messages timestamp
Goffi <goffi@goffi.org>
parents: 521
diff changeset
66 if self.parent.show_timestamp:
3bd8f84f920d primitivus: fixed info messages timestamp
Goffi <goffi@goffi.org>
parents: 521
diff changeset
67 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
68 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
69 if self.parent.show_short_nick:
3bd8f84f920d primitivus: fixed info messages timestamp
Goffi <goffi@goffi.org>
parents: 521
diff changeset
70 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
71 else:
3bd8f84f920d primitivus: fixed info messages timestamp
Goffi <goffi@goffi.org>
parents: 521
diff changeset
72 render_txt.append(('my_nick' if self.my_mess else 'other_nick',"[%s] " % self.nick))
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
73 render_txt.append(self.message)
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
74 return urwid.Text(render_txt, align=self.align)
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff changeset
75
638
6821fc06a324 misc: a few "cosmetic" changes (PEP 8...)
souliane <souliane@mailoo.org>
parents: 637
diff changeset
76
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff changeset
77 class Chat(urwid.WidgetWrap, QuickChat):
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff changeset
78
812
084b52afdceb frontends: fixed /me usage + renamed a couple of "type" parameters to type_
Goffi <goffi@goffi.org>
parents: 811
diff changeset
79 def __init__(self, target, host, type_='one2one'):
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
80 self.target = target
812
084b52afdceb frontends: fixed /me usage + renamed a couple of "type" parameters to type_
Goffi <goffi@goffi.org>
parents: 811
diff changeset
81 QuickChat.__init__(self, target, host, type_)
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff changeset
82 self.content = urwid.SimpleListWalker([])
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff changeset
83 self.text_list = urwid.ListBox(self.content)
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
84 self.chat_widget = urwid.Frame(self.text_list)
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents: 137
diff changeset
85 self.chat_colums = urwid.Columns([('weight', 8, self.chat_widget)])
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents: 137
diff changeset
86 self.chat_colums = urwid.Columns([('weight', 8, self.chat_widget)])
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents: 137
diff changeset
87 self.pile = urwid.Pile([self.chat_colums])
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents: 137
diff changeset
88 urwid.WidgetWrap.__init__(self, self.__getDecoration(self.pile))
812
084b52afdceb frontends: fixed /me usage + renamed a couple of "type" parameters to type_
Goffi <goffi@goffi.org>
parents: 811
diff changeset
89 self.setType(type_)
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
90 self.day_change = time.strptime(time.strftime("%a %b %d 00:00:00 %Y")) #struct_time of day changing time
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
91 self.show_timestamp = True
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
92 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
93 self.show_title = 1 #0: clip title; 1: full title; 2: no title
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
94 self.subject = None
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
95
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
96 def keypress(self, size, key):
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
97 if key == "meta p": #user wants to (un)hide the presents panel
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
98 if self.type == 'group':
607
c123dddaea6b primitivus: fixed urwid issues with recent urwid versions
Goffi <goffi@goffi.org>
parents: 587
diff changeset
99 widgets = [widget for (widget, options) in self.chat_colums.contents]
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
100 if self.present_panel in widgets:
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
101 self.__removePresentPanel()
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
102 else:
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
103 self.__appendPresentPanel()
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
104 elif key == "meta t": #user wants to (un)hide timestamp
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
105 self.show_timestamp = not self.show_timestamp
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
106 for wid in self.content:
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
107 wid._invalidate()
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
108 elif key == "meta n": #user wants to (not) use short nick
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
109 self.show_short_nick = not self.show_short_nick
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
110 for wid in self.content:
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
111 wid._invalidate()
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
112 elif key == "meta l": #user wants to (un)hide widget decoration
222
3198bfd66daa primitivus: refactoring to use urwid-satext which is now a separate project
Goffi <goffi@goffi.org>
parents: 202
diff changeset
113 show = not isinstance(self._w, sat_widgets.LabelLine)
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
114 self.showDecoration(show)
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
115 self._invalidate()
181
a566f654929e README update:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
116 elif key == "meta s": #user wants to (un)hide group's subject or change its apperance
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
117 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
118 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
119 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
120 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
121 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
122 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
123 elif self.show_title == 2:
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
124 self.chat_widget.header = None
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
125 self._invalidate()
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
126
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
127
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
128 return super(Chat, self).keypress(size, key)
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
129
137
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 130
diff changeset
130 def getMenu(self):
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 130
diff changeset
131 """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
132 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
133 if self.type == 'group':
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 130
diff changeset
134 game = _("Game")
801
02ee9ef95277 plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents: 771
diff changeset
135 muc = _("MUC")
137
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 130
diff changeset
136 menu.addMenu(game, "Tarot", self.onTarotRequest)
801
02ee9ef95277 plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents: 771
diff changeset
137 menu.addMenu(muc, _("Configure room"), self.onConfigureRoom)
176
a50953ac6191 Primitivus: send_file first draft
Goffi <goffi@goffi.org>
parents: 153
diff changeset
138 elif self.type == 'one2one':
a50953ac6191 Primitivus: send_file first draft
Goffi <goffi@goffi.org>
parents: 153
diff changeset
139 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
140 return menu
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
141
812
084b52afdceb frontends: fixed /me usage + renamed a couple of "type" parameters to type_
Goffi <goffi@goffi.org>
parents: 811
diff changeset
142 def setType(self, type_):
084b52afdceb frontends: fixed /me usage + renamed a couple of "type" parameters to type_
Goffi <goffi@goffi.org>
parents: 811
diff changeset
143 QuickChat.setType(self, type_)
084b52afdceb frontends: fixed /me usage + renamed a couple of "type" parameters to type_
Goffi <goffi@goffi.org>
parents: 811
diff changeset
144 if type_ == 'one2one':
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff changeset
145 self.historyPrint(profile=self.host.profile)
812
084b52afdceb frontends: fixed /me usage + renamed a couple of "type" parameters to type_
Goffi <goffi@goffi.org>
parents: 811
diff changeset
146 elif type_ == 'group':
607
c123dddaea6b primitivus: fixed urwid issues with recent urwid versions
Goffi <goffi@goffi.org>
parents: 587
diff changeset
147 if len(self.chat_colums.contents) == 1:
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
148 present_widget = self.__buildPresentList()
222
3198bfd66daa primitivus: refactoring to use urwid-satext which is now a separate project
Goffi <goffi@goffi.org>
parents: 202
diff changeset
149 self.present_panel = sat_widgets.VerticalSeparator(present_widget)
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
150 self.__appendPresentPanel()
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
151
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
152 def __getDecoration(self, widget):
637
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 610
diff changeset
153 return sat_widgets.LabelLine(widget, self.__getSurrendedText())
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 610
diff changeset
154
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 610
diff changeset
155 def __getSurrendedText(self):
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 610
diff changeset
156 """Get the text to be displayed as the dialog title."""
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 610
diff changeset
157 if not hasattr(self, "surrended_text"):
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 610
diff changeset
158 self.__setSurrendedText()
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 610
diff changeset
159 return self.surrended_text
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 610
diff changeset
160
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 610
diff changeset
161 def __setSurrendedText(self, state=None):
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 610
diff changeset
162 """Set the text to be displayed as the dialog title
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 610
diff changeset
163 @param stat: chat state of the contact
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 610
diff changeset
164 """
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 610
diff changeset
165 text = unicode(unescapePrivate(self.target))
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 610
diff changeset
166 if state:
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 610
diff changeset
167 text += " (" + state + ")"
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 610
diff changeset
168 self.surrended_text = sat_widgets.SurroundedText(text)
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
169
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
170 def showDecoration(self, show=True):
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents: 137
diff changeset
171 """Show/Hide the decoration around the chat window"""
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
172 if show:
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents: 137
diff changeset
173 main_widget = self.__getDecoration(self.pile)
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
174 else:
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents: 137
diff changeset
175 main_widget = self.pile
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
176 self._w = main_widget
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
177
637
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 610
diff changeset
178 def updateChatState(self, state):
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 610
diff changeset
179 """Update the chat state of the contact.
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 610
diff changeset
180 @param state: new state to set
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 610
diff changeset
181 """
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 610
diff changeset
182 if (self.type == 'one2one'):
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 610
diff changeset
183 self.__setSurrendedText(state)
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 610
diff changeset
184 self.showDecoration()
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 610
diff changeset
185 self.host.redraw()
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 610
diff changeset
186 elif (self.type == 'group'):
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 610
diff changeset
187 # TODO: chat state for groupchat
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 610
diff changeset
188 pass
3b02554d4c8b primitivus: chat state implementation
souliane <souliane@mailoo.org>
parents: 610
diff changeset
189
511
62f7f2403093 Primitivus: present contacts in groups chat can now be clicked
Goffi <goffi@goffi.org>
parents: 510
diff changeset
190 def _presentClicked(self, list_wid, clicked_wid):
62f7f2403093 Primitivus: present contacts in groups chat can now be clicked
Goffi <goffi@goffi.org>
parents: 510
diff changeset
191 assert(self.type == 'group')
62f7f2403093 Primitivus: present contacts in groups chat can now be clicked
Goffi <goffi@goffi.org>
parents: 510
diff changeset
192 nick = clicked_wid.getValue()
62f7f2403093 Primitivus: present contacts in groups chat can now be clicked
Goffi <goffi@goffi.org>
parents: 510
diff changeset
193 if nick == self.getUserNick():
62f7f2403093 Primitivus: present contacts in groups chat can now be clicked
Goffi <goffi@goffi.org>
parents: 510
diff changeset
194 #We ignore click on our own nick
62f7f2403093 Primitivus: present contacts in groups chat can now be clicked
Goffi <goffi@goffi.org>
parents: 510
diff changeset
195 return
62f7f2403093 Primitivus: present contacts in groups chat can now be clicked
Goffi <goffi@goffi.org>
parents: 510
diff changeset
196 #we have a click on a nick, we add the private conversation to the contact_list
688
f7878ad3c846 tools: renamed tools.jid.JID attribute "short" to "bare"
souliane <souliane@mailoo.org>
parents: 678
diff changeset
197 full_jid = JID("%s/%s" % (self.target.bare, nick))
511
62f7f2403093 Primitivus: present contacts in groups chat can now be clicked
Goffi <goffi@goffi.org>
parents: 510
diff changeset
198 new_jid = escapePrivate(full_jid)
62f7f2403093 Primitivus: present contacts in groups chat can now be clicked
Goffi <goffi@goffi.org>
parents: 510
diff changeset
199 if new_jid not in self.host.contact_list:
62f7f2403093 Primitivus: present contacts in groups chat can now be clicked
Goffi <goffi@goffi.org>
parents: 510
diff changeset
200 self.host.contact_list.add(new_jid)
62f7f2403093 Primitivus: present contacts in groups chat can now be clicked
Goffi <goffi@goffi.org>
parents: 510
diff changeset
201
62f7f2403093 Primitivus: present contacts in groups chat can now be clicked
Goffi <goffi@goffi.org>
parents: 510
diff changeset
202 #now we select the new window
62f7f2403093 Primitivus: present contacts in groups chat can now be clicked
Goffi <goffi@goffi.org>
parents: 510
diff changeset
203 self.host.contact_list.setFocus(full_jid, True)
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
204
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
205 def __buildPresentList(self):
511
62f7f2403093 Primitivus: present contacts in groups chat can now be clicked
Goffi <goffi@goffi.org>
parents: 510
diff changeset
206 self.present_wid = sat_widgets.GenericList([],option_type = sat_widgets.ClickableText, on_click=self._presentClicked)
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
207 return self.present_wid
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
208
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
209 def __appendPresentPanel(self):
607
c123dddaea6b primitivus: fixed urwid issues with recent urwid versions
Goffi <goffi@goffi.org>
parents: 587
diff changeset
210 self.chat_colums.contents.append((self.present_panel,('weight', 2, False)))
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
211
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
212 def __removePresentPanel(self):
607
c123dddaea6b primitivus: fixed urwid issues with recent urwid versions
Goffi <goffi@goffi.org>
parents: 587
diff changeset
213 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
214 if widget is self.present_panel:
c123dddaea6b primitivus: fixed urwid issues with recent urwid versions
Goffi <goffi@goffi.org>
parents: 587
diff changeset
215 self.chat_colums.contents.remove((widget, options))
c123dddaea6b primitivus: fixed urwid issues with recent urwid versions
Goffi <goffi@goffi.org>
parents: 587
diff changeset
216 break
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
217
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents: 137
diff changeset
218 def __appendGamePanel(self, widget):
607
c123dddaea6b primitivus: fixed urwid issues with recent urwid versions
Goffi <goffi@goffi.org>
parents: 587
diff changeset
219 assert (len(self.pile.contents) == 1)
610
c8c07c920e30 Primitivus: fixed xmlui/chat bad contents change
Goffi <goffi@goffi.org>
parents: 609
diff changeset
220 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
221 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
222 self.host.redraw()
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents: 137
diff changeset
223
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents: 137
diff changeset
224 def __removeGamePanel(self):
607
c123dddaea6b primitivus: fixed urwid issues with recent urwid versions
Goffi <goffi@goffi.org>
parents: 587
diff changeset
225 assert (len(self.pile.contents) == 3)
c123dddaea6b primitivus: fixed urwid issues with recent urwid versions
Goffi <goffi@goffi.org>
parents: 587
diff changeset
226 del self.pile.contents[0]
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents: 137
diff changeset
227 self.host.redraw()
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
228
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
229 def setSubject(self, subject, wrap='space'):
120
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
230 """Set title for a group chat"""
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
231 QuickChat.setSubject(self, subject)
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
232 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
233 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
234 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
235 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
236 self.host.redraw()
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
237
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
238 def setPresents(self, param_nicks):
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
239 """Set the users presents in the contact list for a group chat
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
240 @param nicks: list of nicknames
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
241 """
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
242 nicks = [unicode(nick) for nick in param_nicks] #FIXME: should be done in DBus bridge
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
243 nicks.sort()
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
244 QuickChat.setPresents(self, nicks)
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
245 self.present_wid.changeValues(nicks)
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
246 self.host.redraw()
120
1ca5f254ce41 primitivus group chat & misc
Goffi <goffi@goffi.org>
parents: 119
diff changeset
247
507
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 501
diff changeset
248 def replaceUser(self, param_nick, show_info=True):
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
249 """Add user if it is not in the group list"""
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
250 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
251 QuickChat.replaceUser(self, nick, show_info)
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
252 presents = self.present_wid.getAllValues()
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
253 if nick not in presents:
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
254 presents.append(nick)
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
255 presents.sort()
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
256 self.present_wid.changeValues(presents)
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
257 self.host.redraw()
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
258
507
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 501
diff changeset
259 def removeUser(self, param_nick, show_info=True):
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
260 """Remove a user from the group list"""
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
261 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
262 QuickChat.removeUser(self, nick, show_info)
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
263 self.present_wid.deleteValue(nick)
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 120
diff changeset
264 self.host.redraw()
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff changeset
265
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff changeset
266 def printMessage(self, from_jid, msg, profile, timestamp=""):
153
f197b52796ee Primitivus: begining of management for actionResult
Goffi <goffi@goffi.org>
parents: 144
diff changeset
267 assert isinstance(from_jid, JID)
190
31632472e857 quick_frontend, wix, primitivus: informations in chat window
Goffi <goffi@goffi.org>
parents: 181
diff changeset
268 try:
678
a630b94280d5 primitivus: code factorization for user notification
souliane <souliane@mailoo.org>
parents: 638
diff changeset
269 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
270 except TypeError:
31632472e857 quick_frontend, wix, primitivus: informations in chat window
Goffi <goffi@goffi.org>
parents: 181
diff changeset
271 return
520
4d7248f4c577 primitivus: better chat text insertion in chat window
Goffi <goffi@goffi.org>
parents: 518
diff changeset
272
4d7248f4c577 primitivus: better chat text insertion in chat window
Goffi <goffi@goffi.org>
parents: 518
diff changeset
273 new_text = ChatText(self, timestamp or None, nick, mymess, msg)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
274
520
4d7248f4c577 primitivus: better chat text insertion in chat window
Goffi <goffi@goffi.org>
parents: 518
diff changeset
275 if timestamp and self.content:
678
a630b94280d5 primitivus: code factorization for user notification
souliane <souliane@mailoo.org>
parents: 638
diff changeset
276 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
277 current_text = self.content[idx]
4d7248f4c577 primitivus: better chat text insertion in chat window
Goffi <goffi@goffi.org>
parents: 518
diff changeset
278 if new_text.timestamp < current_text.timestamp and idx > 0:
678
a630b94280d5 primitivus: code factorization for user notification
souliane <souliane@mailoo.org>
parents: 638
diff changeset
279 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
280
520
4d7248f4c577 primitivus: better chat text insertion in chat window
Goffi <goffi@goffi.org>
parents: 518
diff changeset
281 #we discard double messages, to avoid backlog / history conflict
678
a630b94280d5 primitivus: code factorization for user notification
souliane <souliane@mailoo.org>
parents: 638
diff changeset
282 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
283 (self.content[idx].message == msg) or
678
a630b94280d5 primitivus: code factorization for user notification
souliane <souliane@mailoo.org>
parents: 638
diff changeset
284 (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
285 return
4d7248f4c577 primitivus: better chat text insertion in chat window
Goffi <goffi@goffi.org>
parents: 518
diff changeset
286
678
a630b94280d5 primitivus: code factorization for user notification
souliane <souliane@mailoo.org>
parents: 638
diff changeset
287 self.content.insert(idx + 1, new_text)
520
4d7248f4c577 primitivus: better chat text insertion in chat window
Goffi <goffi@goffi.org>
parents: 518
diff changeset
288 break
4d7248f4c577 primitivus: better chat text insertion in chat window
Goffi <goffi@goffi.org>
parents: 518
diff changeset
289 else:
4d7248f4c577 primitivus: better chat text insertion in chat window
Goffi <goffi@goffi.org>
parents: 518
diff changeset
290 self.content.append(new_text)
678
a630b94280d5 primitivus: code factorization for user notification
souliane <souliane@mailoo.org>
parents: 638
diff changeset
291 self._notify(from_jid, msg)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
292
678
a630b94280d5 primitivus: code factorization for user notification
souliane <souliane@mailoo.org>
parents: 638
diff changeset
293 def printInfo(self, msg, type_='normal', timestamp=""):
190
31632472e857 quick_frontend, wix, primitivus: informations in chat window
Goffi <goffi@goffi.org>
parents: 181
diff changeset
294 """Print general info
31632472e857 quick_frontend, wix, primitivus: informations in chat window
Goffi <goffi@goffi.org>
parents: 181
diff changeset
295 @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
296 @type_: one of:
190
31632472e857 quick_frontend, wix, primitivus: informations in chat window
Goffi <goffi@goffi.org>
parents: 181
diff changeset
297 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
298 me: "/me" information like "/me clenches his fist" ==> "toto clenches his fist"
31632472e857 quick_frontend, wix, primitivus: informations in chat window
Goffi <goffi@goffi.org>
parents: 181
diff changeset
299 """
531
3bd8f84f920d primitivus: fixed info messages timestamp
Goffi <goffi@goffi.org>
parents: 521
diff changeset
300 _widget = ChatText(self, timestamp or None, None, False, msg, is_info=True)
3bd8f84f920d primitivus: fixed info messages timestamp
Goffi <goffi@goffi.org>
parents: 521
diff changeset
301 self.content.append(_widget)
678
a630b94280d5 primitivus: code factorization for user notification
souliane <souliane@mailoo.org>
parents: 638
diff changeset
302 self._notify(msg=msg)
a630b94280d5 primitivus: code factorization for user notification
souliane <souliane@mailoo.org>
parents: 638
diff changeset
303
a630b94280d5 primitivus: code factorization for user notification
souliane <souliane@mailoo.org>
parents: 638
diff changeset
304 def _notify(self, from_jid="somebody", msg=""):
a630b94280d5 primitivus: code factorization for user notification
souliane <souliane@mailoo.org>
parents: 638
diff changeset
305 """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
306 @param from_jid: contact who wrote to the users
a630b94280d5 primitivus: code factorization for user notification
souliane <souliane@mailoo.org>
parents: 638
diff changeset
307 @param msg: the message that has been received
a630b94280d5 primitivus: code factorization for user notification
souliane <souliane@mailoo.org>
parents: 638
diff changeset
308 """
739
7b72d5c30ebc primivitus: do not notify when an empty message is received
souliane <souliane@mailoo.org>
parents: 688
diff changeset
309 if msg == "":
7b72d5c30ebc primivitus: do not notify when an empty message is received
souliane <souliane@mailoo.org>
parents: 688
diff changeset
310 return
678
a630b94280d5 primitivus: code factorization for user notification
souliane <souliane@mailoo.org>
parents: 638
diff changeset
311 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
312 #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
313 #as that mean that he is probably watching discussion history
678
a630b94280d5 primitivus: code factorization for user notification
souliane <souliane@mailoo.org>
parents: 638
diff changeset
314 self.text_list.set_focus(len(self.content) - 1)
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff changeset
315 self.host.redraw()
507
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 501
diff changeset
316 if not self.host.x_notify.hasFocus():
678
a630b94280d5 primitivus: code factorization for user notification
souliane <souliane@mailoo.org>
parents: 638
diff changeset
317 if self.type == "one2one":
a630b94280d5 primitivus: code factorization for user notification
souliane <souliane@mailoo.org>
parents: 638
diff changeset
318 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
319 elif self.getUserNick().lower() in msg.lower():
844
f3513c8cc2e6 misc: fix unnamed arguments in format strings
souliane <souliane@mailoo.org>
parents: 812
diff changeset
320 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
321
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents: 137
diff changeset
322 def startGame(self, game_type, referee, players):
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents: 137
diff changeset
323 """Configure the chat window to start a game"""
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents: 137
diff changeset
324 if game_type=="Tarot":
501
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 480
diff changeset
325 self.tarot_wid = CardGame(self, referee, players, self.nick)
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 480
diff changeset
326 self.__appendGamePanel(self.tarot_wid)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
327
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents: 137
diff changeset
328 def getGame(self, game_type):
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents: 137
diff changeset
329 """Return class managing the game type"""
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents: 137
diff changeset
330 #TODO: check that the game is launched, and manage errors
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents: 137
diff changeset
331 if game_type=="Tarot":
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
332 return self.tarot_wid
137
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 130
diff changeset
333
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 130
diff changeset
334 #MENU EVENTS#
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 130
diff changeset
335 def onTarotRequest(self, menu):
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 130
diff changeset
336 if len(self.occupants) != 4:
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
337 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
338 else:
227394eb080c Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents: 130
diff changeset
339 self.host.bridge.tarotGameCreate(self.id, list(self.occupants), self.host.profile)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
340
801
02ee9ef95277 plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents: 771
diff changeset
341 def onConfigureRoom(self, menu):
02ee9ef95277 plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents: 771
diff changeset
342 def gotUI(xmlui):
02ee9ef95277 plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents: 771
diff changeset
343 self.host.addWindow(XMLUI(self.host, xmlui))
02ee9ef95277 plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents: 771
diff changeset
344 def configureError(failure):
02ee9ef95277 plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents: 771
diff changeset
345 self.host.showPopUp(sat_widgets.Alert(_("Error"), unicode(failure), ok_cb=self.host.removePopUp))
02ee9ef95277 plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents: 771
diff changeset
346 self.host.bridge.configureRoom(self.id, self.host.profile, callback=gotUI, errback=configureError)
02ee9ef95277 plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents: 771
diff changeset
347
176
a50953ac6191 Primitivus: send_file first draft
Goffi <goffi@goffi.org>
parents: 153
diff changeset
348 def onSendFileRequest(self, menu):
180
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents: 176
diff changeset
349 dialog = FileDialog(ok_cb=self.onFileSelected, cancel_cb=self.host.removePopUp)
176
a50953ac6191 Primitivus: send_file first draft
Goffi <goffi@goffi.org>
parents: 153
diff changeset
350 self.host.showPopUp(dialog, 80, 80)
a50953ac6191 Primitivus: send_file first draft
Goffi <goffi@goffi.org>
parents: 153
diff changeset
351
180
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents: 176
diff changeset
352 #MISC EVENTS#
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents: 176
diff changeset
353 def onFileSelected(self, filepath):
fdb961f27ae9 Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents: 176
diff changeset
354 self.host.removePopUp()
501
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 480
diff changeset
355 #FIXME: check last_resource: what if self.target.resource exists ?
688
f7878ad3c846 tools: renamed tools.jid.JID attribute "short" to "bare"
souliane <souliane@mailoo.org>
parents: 678
diff changeset
356 last_resource = self.host.bridge.getLastResource(unicode(self.target.bare), self.host.profile)
501
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 480
diff changeset
357 if last_resource:
688
f7878ad3c846 tools: renamed tools.jid.JID attribute "short" to "bare"
souliane <souliane@mailoo.org>
parents: 678
diff changeset
358 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
359 else:
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 480
diff changeset
360 full_jid = self.target
542
3eeb6c865e4d frontends: incoming files transfer management:
Goffi <goffi@goffi.org>
parents: 531
diff changeset
361 progress_id = self.host.bridge.sendFile(full_jid, filepath, {}, self.host.profile)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
362 self.host.addProgress(progress_id,filepath)