3
## Copyright (C) 2006 Travis Shirk <travis@pobox.com>
5
## This program is free software; you can redistribute it and/or modify
2
## src/message_control.py
4
## Copyright (C) 2006 Dimitur Kirov <dkirov AT gmail.com>
5
## Nikos Kouremenos <kourem AT gmail.com>
6
## Copyright (C) 2006-2007 Jean-Marie Traissard <jim AT lapin.org>
7
## Travis Shirk <travis AT pobox.com>
8
## Copyright (C) 2006-2008 Yann Leboulanger <asterix AT lagaule.org>
9
## Copyright (C) 2007 Julien Pivotto <roidelapluie AT gmail.com>
10
## Stephan Erb <steve-e AT h3c.de>
11
## Copyright (C) 2007-2008 Brendan Taylor <whateley AT gmail.com>
12
## Copyright (C) 2008 Jonathan Schleifer <js-gajim AT webkeks.org>
14
## This file is part of Gajim.
16
## Gajim is free software; you can redistribute it and/or modify
6
17
## it under the terms of the GNU General Public License as published
7
## by the Free Software Foundation; version 2 only.
18
## by the Free Software Foundation; version 3 only.
9
## This program is distributed in the hope that it will be useful,
20
## Gajim is distributed in the hope that it will be useful,
10
21
## but WITHOUT ANY WARRANTY; without even the implied warranty of
11
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
23
## GNU General Public License for more details.
25
## You should have received a copy of the GNU General Public License
26
## along with Gajim. If not, see <http://www.gnu.org/licenses/>.
14
29
import gtkgui_helpers
16
31
from common import gajim
32
from common import helpers
18
34
# Derived types MUST register their type IDs here if custom behavor is required
26
42
'''An abstract base widget that can embed in the gtk.Notebook of a MessageWindow'''
28
44
def __init__(self, type_id, parent_win, widget_name, contact, account, resource = None):
29
# dict { cb id : widget}
45
# dict { cb id : widget}
30
46
# keep all registered callbacks of widgets, created by self.xml
32
48
self.type_id = type_id
33
49
self.parent_win = parent_win
34
50
self.widget_name = widget_name
35
51
self.contact = contact
36
52
self.account = account
37
self.hide_chat_buttons_current = False
53
self.hide_chat_buttons = False
38
54
self.resource = resource
40
58
gajim.last_message_time[self.account][self.get_full_jid()] = 0
42
60
self.xml = gtkgui_helpers.get_glade('message_window.glade', widget_name)
53
71
or inactive (state is False)'''
54
72
pass # Derived classes MUST implement this method
56
def allow_shutdown(self, method):
74
def allow_shutdown(self, method, on_response_yes, on_response_no,
75
on_response_minimize):
57
76
'''Called to check is a control is allowed to shutdown.
58
77
If a control is not in a suitable shutdown state this method
59
should return False'''
78
should call on_response_no, else on_response_yes or
79
on_response_minimize '''
60
80
# NOTE: Derived classes MAY implement this
63
83
def shutdown(self):
64
84
# NOTE: Derived classes MUST implement this
80
100
pass # NOTE: Derived classes SHOULD implement this
82
102
def get_tab_label(self, chatstate):
83
'''Return a suitable the tab label string. Returns a tuple such as:
103
'''Return a suitable tab label string. Returns a tuple such as:
84
104
(label_str, color) either of which can be None
85
105
if chatstate is given that means we have HE SENT US a chatstate and
86
106
we want it displayed'''
110
131
def get_specific_unread(self):
111
return len(gajim.events.get_events(self.account, self.contact.jid))
113
def send_message(self, message, keyID = '', type = 'chat',
132
return len(gajim.events.get_events(self.account,
135
def set_session(self, session):
137
if hasattr(self, 'session'):
138
oldsession = self.session
140
if oldsession and session == oldsession:
143
self.session = session
147
session.control = self
148
new_key = session.thread_id
151
oldsession.control = None
153
jid = self.contact.jid
155
jid += '/' + self.resource
157
crypto_changed = bool(session and session.enable_encryption) != \
158
bool(oldsession and oldsession.enable_encryption)
161
self.print_esession_details()
163
def send_message(self, message, keyID = '', type_ = 'chat',
114
164
chatstate = None, msg_id = None, composing_xep = None, resource = None,
115
165
user_nick = None):
116
'''Send the given message to the active tab. Doesn't return None if error
166
# Send the given message to the active tab.
167
# Doesn't return None if error
118
168
jid = self.contact.jid
170
message = helpers.remove_invalid_xml_chars(message)
172
original_message = message
173
conn = gajim.connections[self.account]
176
sess = conn.find_controlless_session(jid)
179
jid += '/' + self.resource
182
sess = conn.make_new_session(jid)
184
self.set_session(sess)
119
186
# Send and update history
120
return gajim.connections[self.account].send_message(jid, message, keyID,
121
type = type, chatstate = chatstate, msg_id = msg_id,
122
composing_xep = composing_xep, resource = self.resource,
123
user_nick = user_nick)
187
return conn.send_message(jid, message, keyID, type_ = type_,
188
chatstate = chatstate, msg_id = msg_id,
189
composing_xep = composing_xep,
190
resource = self.resource, user_nick = user_nick,
191
session = self.session,
192
original_message = original_message)