root/trunk/src/message_control.py

Revision 10648, 5.6 kB (checked in by roidelapluie, 2 weeks ago)

Very basic integration of xHtml GUI

Line 
1# -*- coding:utf-8 -*-
2## src/message_control.py
3##
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>
13##
14## This file is part of Gajim.
15##
16## Gajim is free software; you can redistribute it and/or modify
17## it under the terms of the GNU General Public License as published
18## by the Free Software Foundation; version 3 only.
19##
20## Gajim is distributed in the hope that it will be useful,
21## but WITHOUT ANY WARRANTY; without even the implied warranty of
22## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23## GNU General Public License for more details.
24##
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/>.
27##
28
29import gtkgui_helpers
30
31from common import gajim
32from common import helpers
33
34# Derived types MUST register their type IDs here if custom behavor is required
35TYPE_CHAT = 'chat'
36TYPE_GC = 'gc'
37TYPE_PM = 'pm'
38
39####################
40
41class MessageControl:
42        '''An abstract base widget that can embed in the gtk.Notebook of a MessageWindow'''
43
44        def __init__(self, type_id, parent_win, widget_name, contact, account, resource = None):
45                # dict { cb id : widget}
46                # keep all registered callbacks of widgets, created by self.xml
47                self.handlers = {}
48                self.type_id = type_id
49                self.parent_win = parent_win
50                self.widget_name = widget_name
51                self.contact = contact
52                self.account = account
53                self.hide_chat_buttons = False
54                self.resource = resource
55
56                self.session = None
57
58                gajim.last_message_time[self.account][self.get_full_jid()] = 0
59
60                self.xml = gtkgui_helpers.get_glade('message_window.glade', widget_name)
61                self.widget = self.xml.get_widget(widget_name)
62
63        def get_full_jid(self):
64                fjid = self.contact.jid
65                if self.resource:
66                        fjid += '/' + self.resource
67                return fjid
68
69        def set_control_active(self, state):
70                '''Called when the control becomes active (state is True)
71                or inactive (state is False)'''
72                pass  # Derived classes MUST implement this method
73
74        def allow_shutdown(self, method, on_response_yes, on_response_no,
75        on_response_minimize):
76                '''Called to check is a control is allowed to shutdown.
77                If a control is not in a suitable shutdown state this method
78                should call on_response_no, else on_response_yes or
79                on_response_minimize '''
80                # NOTE: Derived classes MAY implement this
81                on_response_yes(self)
82
83        def shutdown(self):
84                # NOTE: Derived classes MUST implement this
85                pass
86
87        def repaint_themed_widgets(self):
88                pass # NOTE: Derived classes SHOULD implement this
89
90        def update_ui(self):
91                pass # NOTE: Derived classes SHOULD implement this
92
93        def toggle_emoticons(self):
94                pass # NOTE: Derived classes MAY implement this
95
96        def update_font(self):
97                pass # NOTE: Derived classes SHOULD implement this
98
99        def update_tags(self):
100                pass # NOTE: Derived classes SHOULD implement this
101
102        def get_tab_label(self, chatstate):
103                '''Return a suitable tab label string.  Returns a tuple such as:
104                (label_str, color) either of which can be None
105                if chatstate is given that means we have HE SENT US a chatstate and
106                we want it displayed'''
107                # NOTE: Derived classes MUST implement this
108                # Return a markup'd label and optional gtk.Color in a tupple like:
109                #return (label_str, None)
110                pass
111
112        def get_tab_image(self):
113                # Return a suitable tab image for display.
114                # None clears any current label.
115                return None
116
117        def prepare_context_menu(self):
118                # NOTE: Derived classes SHOULD implement this
119                return None
120
121        def chat_buttons_set_visible(self, state):
122                # NOTE: Derived classes MAY implement this
123                self.hide_chat_buttons = state
124
125        def got_connected(self):
126                pass
127
128        def got_disconnected(self):
129                pass
130
131        def get_specific_unread(self):
132                return len(gajim.events.get_events(self.account,
133                        self.contact.jid))
134
135        def set_session(self, session):
136                oldsession = None
137                if hasattr(self, 'session'):
138                        oldsession = self.session
139
140                if oldsession and session == oldsession:
141                        return
142
143                self.session = session
144
145                new_key = None
146                if session:
147                        session.control = self
148                        new_key = session.thread_id
149
150                if oldsession:
151                        oldsession.control = None
152
153                        jid = self.contact.jid
154                        if self.resource:
155                                jid += '/' + self.resource
156
157                crypto_changed = bool(session and session.enable_encryption) != \
158                        bool(oldsession and oldsession.enable_encryption)
159
160                if crypto_changed:
161                        self.print_esession_details()
162
163        def send_message(self, message, keyID = '', type_ = 'chat',
164        chatstate = None, msg_id = None, composing_xep = None, resource = None,
165        user_nick = None, xhtml = None):
166                # Send the given message to the active tab.
167                # Doesn't return None if error
168                jid = self.contact.jid
169
170                message = helpers.remove_invalid_xml_chars(message)
171
172                original_message = message
173                conn = gajim.connections[self.account]
174
175                if not self.session:
176                        sess = conn.find_controlless_session(jid)
177
178                        if self.resource:
179                                jid += '/' + self.resource
180
181                        if not sess:
182                                sess = conn.make_new_session(jid)
183
184                        self.set_session(sess)
185
186                # Send and update history
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, xhtml = xhtml)
193
194# vim: se ts=3:
Note: See TracBrowser for help on using the browser.