root/branches/gajim_0.11/src/message_control.py

Revision 7984, 3.8 kB (checked in by asterix, 19 months ago)

mrege diff from trunk

Line 
1##      message_control.py
2##
3## Copyright (C) 2006 Travis Shirk <travis@pobox.com>
4##
5## This program is free software; you can redistribute it and/or modify
6## it under the terms of the GNU General Public License as published
7## by the Free Software Foundation; version 2 only.
8##
9## This program is distributed in the hope that it will be useful,
10## but WITHOUT ANY WARRANTY; without even the implied warranty of
11## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12## GNU General Public License for more details.
13##
14import gtkgui_helpers
15
16from common import gajim
17
18# Derived types MUST register their type IDs here if custom behavor is required
19TYPE_CHAT = 'chat'
20TYPE_GC = 'gc'
21TYPE_PM = 'pm'
22
23####################
24
25class MessageControl:
26        '''An abstract base widget that can embed in the gtk.Notebook of a MessageWindow'''
27
28        def __init__(self, type_id, parent_win, widget_name, contact, account, resource = None):
29                # dict { cb id : widget}
30                # keep all registered callbacks of widgets, created by self.xml
31                self.handlers = {}
32                self.type_id = type_id
33                self.parent_win = parent_win
34                self.widget_name = widget_name
35                self.contact = contact
36                self.account = account
37                self.hide_chat_buttons_current = False
38                self.resource = resource
39
40                gajim.last_message_time[self.account][self.get_full_jid()] = 0
41
42                self.xml = gtkgui_helpers.get_glade('message_window.glade', widget_name)
43                self.widget = self.xml.get_widget(widget_name)
44
45        def get_full_jid(self):
46                fjid = self.contact.jid
47                if self.resource:
48                        fjid += '/' + self.resource
49                return fjid
50
51        def set_control_active(self, state):
52                '''Called when the control becomes active (state is True)
53                or inactive (state is False)'''
54                pass  # Derived classes MUST implement this method
55
56        def allow_shutdown(self, method):
57                '''Called to check is a control is allowed to shutdown.
58                If a control is not in a suitable shutdown state this method
59                should return False'''
60                # NOTE: Derived classes MAY implement this
61                return True
62
63        def shutdown(self):
64                # NOTE: Derived classes MUST implement this
65                pass
66
67        def repaint_themed_widgets(self):
68                pass # NOTE: Derived classes SHOULD implement this
69
70        def update_ui(self):
71                pass # NOTE: Derived classes SHOULD implement this
72
73        def toggle_emoticons(self):
74                pass # NOTE: Derived classes MAY implement this
75
76        def update_font(self):
77                pass # NOTE: Derived classes SHOULD implement this
78
79        def update_tags(self):
80                pass # NOTE: Derived classes SHOULD implement this
81
82        def get_tab_label(self, chatstate):
83                '''Return a suitable the tab label string.  Returns a tuple such as:
84                (label_str, color) either of which can be None
85                if chatstate is given that means we have HE SENT US a chatstate and
86                we want it displayed'''
87                # NOTE: Derived classes MUST implement this
88                # Return a markup'd label and optional gtk.Color in a tupple like:
89                #return (label_str, None)
90                pass
91
92        def get_tab_image(self):
93                '''Return a suitable tab image for display.  None clears any current label.'''
94                return None
95
96        def prepare_context_menu(self):
97                # NOTE: Derived classes SHOULD implement this
98                return None
99
100        def chat_buttons_set_visible(self, state):
101                # NOTE: Derived classes MAY implement this
102                self.hide_chat_buttons_current = state
103
104        def got_connected(self):
105                pass
106
107        def got_disconnected(self):
108                pass
109
110        def get_specific_unread(self):
111                return len(gajim.events.get_events(self.account, self.contact.jid))
112
113        def send_message(self, message, keyID = '', type = 'chat',
114        chatstate = None, msg_id = None, composing_jep = None, resource = None,
115        user_nick = None):
116                '''Send the given message to the active tab. Doesn't return None if error
117                '''
118                jid = self.contact.jid
119                # 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_jep = composing_jep, resource = self.resource,
123                        user_nick = user_nick)
Note: See TracBrowser for help on using the browser.