2006-01-02 02:12:34 +00:00
|
|
|
## message_control.py
|
|
|
|
##
|
Merge one_window branch
Merged revisions 9143,9145-9155,9157-9162,9164-9169,9171-9177 via svnmerge from
svn://88.191.11.156/gajim/branches/one_window
........
r9145 | nicfit | 2007-12-13 21:49:09 -0700 (Thu, 13 Dec 2007) | 2 lines
Implemented the original Nikos patch with an HPaned instead of a HBox and only do this mode when one_message_window == 'always'
........
r9152 | nicfit | 2007-12-15 13:33:56 -0700 (Sat, 15 Dec 2007) | 2 lines
Added config and GUI for one_message_window_with_roster
........
r9153 | nicfit | 2007-12-15 13:41:46 -0700 (Sat, 15 Dec 2007) | 2 lines
Use one_message_window_with_roster and some whitespace cleanup
........
r9154 | nicfit | 2007-12-15 14:04:49 -0700 (Sat, 15 Dec 2007) | 2 lines
Scratch the chckbox for with roster mode, use one_message_window opt and combo
........
r9155 | nicfit | 2007-12-15 17:01:13 -0700 (Sat, 15 Dec 2007) | 2 lines
MessageWindowMgr knows about ONE_MESSAGE_WINDOW_ALWAYS_WITH_ROSTER and MessageWindow can reparent itself rather then the roster having to do so.
........
r9157 | nicfit | 2007-12-15 17:47:20 -0700 (Sat, 15 Dec 2007) | 2 lines
Resizing fixes and make the roster window shrink when last tab is removed
........
r9158 | nicfit | 2007-12-15 19:15:11 -0700 (Sat, 15 Dec 2007) | 2 lines
Added "Show roster" (CTRL+R) to view menu when using always_with_roster to quickly hide/show the roster.
........
r9159 | nicfit | 2007-12-15 19:49:30 -0700 (Sat, 15 Dec 2007) | 2 lines
Handle window title setting in always_with_roster mode.
........
r9160 | nicfit | 2007-12-15 20:13:57 -0700 (Sat, 15 Dec 2007) | 2 lines
Removed FIXME
........
r9167 | nicfit | 2007-12-17 18:40:59 -0700 (Mon, 17 Dec 2007) | 2 lines
When roster is hidden, show it when the number of MessageWindow controls == 0
........
r9168 | nicfit | 2007-12-17 19:07:49 -0700 (Mon, 17 Dec 2007) | 2 lines
Disable hiding roster when there are no message controls open
........
r9169 | nicfit | 2007-12-17 20:41:11 -0700 (Mon, 17 Dec 2007) | 2 lines
Bunch of saved size bugs fixed
........
2007-12-18 23:42:22 +00:00
|
|
|
## Copyright (C) 2006-2007 Travis Shirk <travis@pobox.com>
|
2007-08-31 23:19:23 +00:00
|
|
|
## Copyright (C) 2007 Stephan Erb <steve-e@h3c.de>
|
2006-01-02 02:12:34 +00:00
|
|
|
##
|
2007-10-22 11:13:13 +00:00
|
|
|
## This file is part of Gajim.
|
|
|
|
##
|
|
|
|
## Gajim is free software; you can redistribute it and/or modify
|
2006-01-02 02:12:34 +00:00
|
|
|
## it under the terms of the GNU General Public License as published
|
2007-10-22 11:13:13 +00:00
|
|
|
## by the Free Software Foundation; version 3 only.
|
2006-01-02 02:12:34 +00:00
|
|
|
##
|
2007-10-22 11:13:13 +00:00
|
|
|
## Gajim is distributed in the hope that it will be useful,
|
2006-01-02 02:12:34 +00:00
|
|
|
## but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
## GNU General Public License for more details.
|
|
|
|
##
|
2007-10-22 11:13:13 +00:00
|
|
|
## You should have received a copy of the GNU General Public License
|
|
|
|
## along with Gajim. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
##
|
2006-05-02 15:53:25 +00:00
|
|
|
import gtkgui_helpers
|
2006-01-02 02:12:34 +00:00
|
|
|
|
|
|
|
from common import gajim
|
|
|
|
|
|
|
|
# Derived types MUST register their type IDs here if custom behavor is required
|
|
|
|
TYPE_CHAT = 'chat'
|
|
|
|
TYPE_GC = 'gc'
|
|
|
|
TYPE_PM = 'pm'
|
|
|
|
|
|
|
|
####################
|
|
|
|
|
2006-01-02 22:08:50 +00:00
|
|
|
class MessageControl:
|
2006-01-02 02:12:34 +00:00
|
|
|
'''An abstract base widget that can embed in the gtk.Notebook of a MessageWindow'''
|
|
|
|
|
2007-02-08 18:32:10 +00:00
|
|
|
def __init__(self, type_id, parent_win, widget_name, contact, account, resource = None):
|
2008-05-13 01:59:10 +00:00
|
|
|
# dict { cb id : widget}
|
2006-04-17 21:59:04 +00:00
|
|
|
# keep all registered callbacks of widgets, created by self.xml
|
Merge one_window branch
Merged revisions 9143,9145-9155,9157-9162,9164-9169,9171-9177 via svnmerge from
svn://88.191.11.156/gajim/branches/one_window
........
r9145 | nicfit | 2007-12-13 21:49:09 -0700 (Thu, 13 Dec 2007) | 2 lines
Implemented the original Nikos patch with an HPaned instead of a HBox and only do this mode when one_message_window == 'always'
........
r9152 | nicfit | 2007-12-15 13:33:56 -0700 (Sat, 15 Dec 2007) | 2 lines
Added config and GUI for one_message_window_with_roster
........
r9153 | nicfit | 2007-12-15 13:41:46 -0700 (Sat, 15 Dec 2007) | 2 lines
Use one_message_window_with_roster and some whitespace cleanup
........
r9154 | nicfit | 2007-12-15 14:04:49 -0700 (Sat, 15 Dec 2007) | 2 lines
Scratch the chckbox for with roster mode, use one_message_window opt and combo
........
r9155 | nicfit | 2007-12-15 17:01:13 -0700 (Sat, 15 Dec 2007) | 2 lines
MessageWindowMgr knows about ONE_MESSAGE_WINDOW_ALWAYS_WITH_ROSTER and MessageWindow can reparent itself rather then the roster having to do so.
........
r9157 | nicfit | 2007-12-15 17:47:20 -0700 (Sat, 15 Dec 2007) | 2 lines
Resizing fixes and make the roster window shrink when last tab is removed
........
r9158 | nicfit | 2007-12-15 19:15:11 -0700 (Sat, 15 Dec 2007) | 2 lines
Added "Show roster" (CTRL+R) to view menu when using always_with_roster to quickly hide/show the roster.
........
r9159 | nicfit | 2007-12-15 19:49:30 -0700 (Sat, 15 Dec 2007) | 2 lines
Handle window title setting in always_with_roster mode.
........
r9160 | nicfit | 2007-12-15 20:13:57 -0700 (Sat, 15 Dec 2007) | 2 lines
Removed FIXME
........
r9167 | nicfit | 2007-12-17 18:40:59 -0700 (Mon, 17 Dec 2007) | 2 lines
When roster is hidden, show it when the number of MessageWindow controls == 0
........
r9168 | nicfit | 2007-12-17 19:07:49 -0700 (Mon, 17 Dec 2007) | 2 lines
Disable hiding roster when there are no message controls open
........
r9169 | nicfit | 2007-12-17 20:41:11 -0700 (Mon, 17 Dec 2007) | 2 lines
Bunch of saved size bugs fixed
........
2007-12-18 23:42:22 +00:00
|
|
|
self.handlers = {}
|
2006-01-02 02:12:34 +00:00
|
|
|
self.type_id = type_id
|
|
|
|
self.parent_win = parent_win
|
|
|
|
self.widget_name = widget_name
|
|
|
|
self.contact = contact
|
|
|
|
self.account = account
|
2007-06-25 23:51:44 +00:00
|
|
|
self.hide_chat_buttons = False
|
2006-03-14 13:10:09 +00:00
|
|
|
self.resource = resource
|
2006-01-07 23:40:37 +00:00
|
|
|
|
2006-03-14 17:13:34 +00:00
|
|
|
gajim.last_message_time[self.account][self.get_full_jid()] = 0
|
2006-01-02 02:12:34 +00:00
|
|
|
|
2006-05-02 15:53:25 +00:00
|
|
|
self.xml = gtkgui_helpers.get_glade('message_window.glade', widget_name)
|
2006-01-02 02:12:34 +00:00
|
|
|
self.widget = self.xml.get_widget(widget_name)
|
|
|
|
|
2006-03-14 16:35:17 +00:00
|
|
|
def get_full_jid(self):
|
|
|
|
fjid = self.contact.jid
|
|
|
|
if self.resource:
|
|
|
|
fjid += '/' + self.resource
|
2006-03-14 16:58:50 +00:00
|
|
|
return fjid
|
2006-03-14 16:35:17 +00:00
|
|
|
|
2006-01-02 09:04:30 +00:00
|
|
|
def set_control_active(self, state):
|
|
|
|
'''Called when the control becomes active (state is True)
|
|
|
|
or inactive (state is False)'''
|
2006-12-30 00:53:02 +00:00
|
|
|
pass # Derived classes MUST implement this method
|
2006-01-02 09:04:30 +00:00
|
|
|
|
2006-10-10 15:53:42 +00:00
|
|
|
def allow_shutdown(self, method):
|
2006-01-03 03:34:32 +00:00
|
|
|
'''Called to check is a control is allowed to shutdown.
|
|
|
|
If a control is not in a suitable shutdown state this method
|
2007-06-15 18:30:48 +00:00
|
|
|
should return 'no', else 'yes' or 'minimize' '''
|
2006-01-03 03:34:32 +00:00
|
|
|
# NOTE: Derived classes MAY implement this
|
2007-06-15 18:30:48 +00:00
|
|
|
return 'yes'
|
2006-02-05 12:05:16 +00:00
|
|
|
|
2006-01-02 02:12:34 +00:00
|
|
|
def shutdown(self):
|
|
|
|
# NOTE: Derived classes MUST implement this
|
2006-01-12 08:30:23 +00:00
|
|
|
pass
|
2006-02-05 12:05:16 +00:00
|
|
|
|
2006-11-20 19:11:31 +00:00
|
|
|
def repaint_themed_widgets(self):
|
2006-01-02 02:12:34 +00:00
|
|
|
pass # NOTE: Derived classes SHOULD implement this
|
2006-02-05 12:05:16 +00:00
|
|
|
|
2006-01-10 01:47:24 +00:00
|
|
|
def update_ui(self):
|
2006-01-02 02:12:34 +00:00
|
|
|
pass # NOTE: Derived classes SHOULD implement this
|
2006-02-05 12:05:16 +00:00
|
|
|
|
2006-01-02 02:12:34 +00:00
|
|
|
def toggle_emoticons(self):
|
|
|
|
pass # NOTE: Derived classes MAY implement this
|
2006-02-05 12:05:16 +00:00
|
|
|
|
2006-01-02 02:12:34 +00:00
|
|
|
def update_font(self):
|
|
|
|
pass # NOTE: Derived classes SHOULD implement this
|
2006-02-05 12:05:16 +00:00
|
|
|
|
2006-01-02 02:12:34 +00:00
|
|
|
def update_tags(self):
|
|
|
|
pass # NOTE: Derived classes SHOULD implement this
|
2006-02-05 12:05:16 +00:00
|
|
|
|
2006-01-05 02:58:59 +00:00
|
|
|
def get_tab_label(self, chatstate):
|
2007-12-14 03:25:13 +00:00
|
|
|
'''Return a suitable tab label string. Returns a tuple such as:
|
2006-01-05 02:58:59 +00:00
|
|
|
(label_str, color) either of which can be None
|
|
|
|
if chatstate is given that means we have HE SENT US a chatstate and
|
|
|
|
we want it displayed'''
|
2006-03-24 18:48:26 +00:00
|
|
|
# NOTE: Derived classes MUST implement this
|
|
|
|
# Return a markup'd label and optional gtk.Color in a tupple like:
|
|
|
|
#return (label_str, None)
|
|
|
|
pass
|
2006-02-05 12:05:16 +00:00
|
|
|
|
2006-01-05 02:58:59 +00:00
|
|
|
def get_tab_image(self):
|
2008-05-19 18:48:53 +00:00
|
|
|
# Return a suitable tab image for display.
|
|
|
|
# None clears any current label.
|
2006-01-05 02:58:59 +00:00
|
|
|
return None
|
2006-02-05 12:05:16 +00:00
|
|
|
|
2006-01-02 02:12:34 +00:00
|
|
|
def prepare_context_menu(self):
|
|
|
|
# NOTE: Derived classes SHOULD implement this
|
|
|
|
return None
|
2006-02-05 12:05:16 +00:00
|
|
|
|
2006-04-10 12:09:05 +00:00
|
|
|
def chat_buttons_set_visible(self, state):
|
2006-01-02 02:12:34 +00:00
|
|
|
# NOTE: Derived classes MAY implement this
|
2007-06-25 23:51:44 +00:00
|
|
|
self.hide_chat_buttons = state
|
2006-01-02 02:12:34 +00:00
|
|
|
|
2006-02-04 02:52:36 +00:00
|
|
|
def got_connected(self):
|
|
|
|
pass
|
2006-02-05 12:05:16 +00:00
|
|
|
|
2006-02-04 02:52:36 +00:00
|
|
|
def got_disconnected(self):
|
|
|
|
pass
|
|
|
|
|
2006-01-03 04:44:56 +00:00
|
|
|
def get_specific_unread(self):
|
2008-05-19 18:48:53 +00:00
|
|
|
return len(gajim.events.get_events(self.account,
|
|
|
|
self.contact.jid))
|
2006-01-03 03:34:32 +00:00
|
|
|
|
2007-06-05 23:19:34 +00:00
|
|
|
def set_session(self, session):
|
2008-05-04 00:24:27 +00:00
|
|
|
oldsession = None
|
|
|
|
if hasattr(self, 'session'):
|
|
|
|
oldsession = self.session
|
2008-05-11 13:17:28 +00:00
|
|
|
|
2008-05-04 00:24:27 +00:00
|
|
|
if oldsession and session == oldsession:
|
|
|
|
return
|
2008-05-11 13:17:28 +00:00
|
|
|
|
2007-06-05 23:19:34 +00:00
|
|
|
self.session = session
|
|
|
|
|
2007-12-08 05:49:38 +00:00
|
|
|
if session:
|
|
|
|
session.control = self
|
|
|
|
|
2008-05-04 00:24:27 +00:00
|
|
|
if oldsession:
|
2008-05-19 18:48:53 +00:00
|
|
|
self.parent_win.change_thread_key(
|
|
|
|
self.contact.jid, self.account,
|
2008-05-13 01:59:10 +00:00
|
|
|
oldsession.thread_id, session.thread_id)
|
2008-05-04 00:24:27 +00:00
|
|
|
|
|
|
|
if oldsession.enable_encryption:
|
|
|
|
self.print_esession_details()
|
2007-12-08 05:49:38 +00:00
|
|
|
|
2006-03-03 14:41:55 +00:00
|
|
|
def send_message(self, message, keyID = '', type = 'chat',
|
2007-06-16 21:31:19 +00:00
|
|
|
chatstate = None, msg_id = None, composing_xep = None, resource = None,
|
2006-06-01 15:23:38 +00:00
|
|
|
user_nick = None):
|
2008-05-19 17:41:51 +00:00
|
|
|
# Send the given message to the active tab.
|
|
|
|
# Doesn't return None if error
|
2006-01-02 02:12:34 +00:00
|
|
|
jid = self.contact.jid
|
2008-05-09 12:35:25 +00:00
|
|
|
original_message = message
|
2007-05-31 01:47:08 +00:00
|
|
|
|
2008-05-20 00:44:30 +00:00
|
|
|
if gajim.otr_module and jid not in gajim.otr_dont_append_tag:
|
2008-05-09 12:35:25 +00:00
|
|
|
if type == 'chat' and isinstance(message, unicode):
|
2008-05-19 17:41:51 +00:00
|
|
|
d = {'kwargs': {'keyID': keyID, 'type': type,
|
|
|
|
'chatstate': chatstate,
|
|
|
|
'msg_id': msg_id,
|
|
|
|
'composing_xep': composing_xep,
|
|
|
|
'resource': self.resource,
|
|
|
|
'user_nick': user_nick,
|
|
|
|
'session': self.session,
|
|
|
|
'original_message': original_message},
|
|
|
|
'account': self.account}
|
2008-05-13 01:59:10 +00:00
|
|
|
|
2008-05-09 12:35:25 +00:00
|
|
|
new_msg = gajim.otr_module.otrl_message_sending(
|
2008-05-19 17:41:51 +00:00
|
|
|
self.session.conn.otr_userstates,
|
2008-05-09 12:35:25 +00:00
|
|
|
(gajim.otr_ui_ops, d),
|
2008-05-19 17:41:51 +00:00
|
|
|
gajim.get_jid_from_account(
|
|
|
|
self.account).encode(),
|
|
|
|
gajim.OTR_PROTO,
|
|
|
|
self.contact.get_full_jid().encode(),
|
|
|
|
message.encode(), None,
|
|
|
|
(gajim.otr_add_appdata, self.account))
|
|
|
|
|
|
|
|
ctx = gajim.otr_module.otrl_context_find(
|
|
|
|
self.session.conn.otr_userstates,
|
|
|
|
self.contact.get_full_jid().encode(),
|
|
|
|
gajim.get_jid_from_account(
|
|
|
|
self.account).encode(),
|
|
|
|
gajim.OTR_PROTO, 1,
|
|
|
|
(gajim.otr_add_appdata,
|
|
|
|
self.account))[0]
|
|
|
|
|
|
|
|
# we send all because inject_message can filter
|
|
|
|
# on HTML stuff then
|
2008-05-09 12:35:25 +00:00
|
|
|
gajim.otr_module.otrl_message_fragment_and_send(
|
2008-05-19 17:41:51 +00:00
|
|
|
(gajim.otr_ui_ops, d), ctx, new_msg,
|
|
|
|
gajim.otr_module.OTRL_FRAGMENT_SEND_ALL)
|
2008-05-09 12:35:25 +00:00
|
|
|
return
|
|
|
|
|
2006-01-02 02:12:34 +00:00
|
|
|
# Send and update history
|
2008-05-19 18:48:53 +00:00
|
|
|
return gajim.connections[self.account].send_message(jid,
|
|
|
|
message, keyID, type = type, chatstate = chatstate,
|
|
|
|
msg_id = msg_id, composing_xep = composing_xep,
|
|
|
|
resource = self.resource, user_nick = user_nick,
|
|
|
|
session = self.session,
|
|
|
|
original_message = original_message)
|