gajim-plural/src/message_control.py

127 lines
4.0 KiB
Python
Raw Normal View History

## message_control.py
##
2006-02-03 08:48:10 +01:00
## Copyright (C) 2006 Travis Shirk <travis@pobox.com>
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published
## by the Free Software Foundation; version 2 only.
##
## This program is distributed in the hope that it will be useful,
## 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.
##
import gtkgui_helpers
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 23:08:50 +01:00
class MessageControl:
'''An abstract base widget that can embed in the gtk.Notebook of a MessageWindow'''
2006-03-14 14:10:09 +01:00
def __init__(self, type_id, parent_win, widget_name, display_names, contact, account, resource = None):
'''The display_names argument is a two element tuple containing the desired
display name (pretty string) for the control in both singular and plural form'''
# dict { cb id : widget}
# keep all registered callbacks of widgets, created by self.xml
self.handlers = {}
self.type_id = type_id
self.parent_win = parent_win
self.widget_name = widget_name
self.display_names = display_names
self.contact = contact
self.account = account
self.hide_chat_buttons_always = False
self.hide_chat_buttons_current = False
2006-03-14 14:10:09 +01:00
self.resource = resource
2006-01-08 00:40:37 +01:00
gajim.last_message_time[self.account][self.get_full_jid()] = 0
self.xml = gtkgui_helpers.get_glade('message_window.glade', widget_name)
self.widget = self.xml.get_widget(widget_name)
def get_full_jid(self):
fjid = self.contact.jid
if self.resource:
fjid += '/' + self.resource
2006-03-14 17:58:50 +01:00
return fjid
2006-01-02 10:04:30 +01:00
def set_control_active(self, state):
'''Called when the control becomes active (state is True)
or inactive (state is False)'''
pass # Derived types MUST implement this method
def allow_shutdown(self, method):
'''Called to check is a control is allowed to shutdown.
If a control is not in a suitable shutdown state this method
should return False'''
# NOTE: Derived classes MAY implement this
return True
def shutdown(self):
# NOTE: Derived classes MUST implement this
pass
def repaint_themed_widgets(self, theme):
pass # NOTE: Derived classes SHOULD implement this
def update_ui(self):
pass # NOTE: Derived classes SHOULD implement this
def toggle_emoticons(self):
pass # NOTE: Derived classes MAY implement this
def update_font(self):
pass # NOTE: Derived classes SHOULD implement this
def update_tags(self):
pass # NOTE: Derived classes SHOULD implement this
2006-01-05 03:58:59 +01:00
def get_tab_label(self, chatstate):
'''Return a suitable the tab label string. Returns a tuple such as:
(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'''
# 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-01-05 03:58:59 +01:00
def get_tab_image(self):
'''Return a suitable tab image for display. None clears any current label.'''
return None
def prepare_context_menu(self):
# NOTE: Derived classes SHOULD implement this
return None
def chat_buttons_set_visible(self, state):
# NOTE: Derived classes MAY implement this
self.hide_chat_buttons_current = state
2006-02-04 03:52:36 +01:00
def got_connected(self):
pass
2006-02-04 03:52:36 +01:00
def got_disconnected(self):
pass
def get_specific_unread(self):
return len(gajim.events.get_events(self.account, self.contact.jid))
def send_message(self, message, keyID = '', type = 'chat',
chatstate = None, msg_id = None, composing_jep = None, resource = None,
user_nick = None):
'''Send the given message to the active tab'''
jid = self.contact.jid
# Send and update history
gajim.connections[self.account].send_message(jid, message, keyID,
type = type, chatstate = chatstate, msg_id = msg_id,
composing_jep = composing_jep, resource = self.resource,
user_nick = user_nick)