## message_window.py ## ## Copyright (C) 2005-2006 Travis Shirk ## ## 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 gtk import gtk.glade import pango import gobject import common from common import gajim #################### # FIXME: Can't this stuff happen once? from common import i18n _ = i18n._ APP = i18n.APP GTKGUI_GLADE = 'gtkgui.glade' #################### class MessageWindow: '''Class for windows which contain message like things; chats, groupchats, etc.''' def __init__(self): self._controls = {} self.widget_name = 'message_window' self.xml = gtk.glade.XML(GTKGUI_GLADE, self.widget_name, APP) self.window = self.xml.get_widget(self.widget_name) self.alignment = self.xml.get_widget('alignment') self.notebook = self.xml.get_widget('notebook') # Remove the glade pages while self.notebook.get_n_pages(): self.notebook.remove_page(0) # Tab customizations pref_pos = gajim.config.get('tabs_position') if pref_pos != 'top': if pref_pos == 'bottom': nb_pos = gtk.POS_BOTTOM elif pref_pos == 'left': nb_pos = gtk.POS_LEFT elif pref_pos == 'right': nb_pos = gtk.POS_RIGHT else: nb_pos = gtk.POS_TOP else: nb_pos = gtk.POS_TOP self.notebook.set_tab_pos(nb_pos) if gajim.config.get('tabs_always_visible'): self.notebook.set_show_tabs(True) self.alignment.set_property('top-padding', 2) else: self.notebook.set_show_tabs(False) self.notebook.set_show_border(gajim.config.get('tabs_border')) self.window.show_all() def new_tab(self, type, contact, acct): pass class MessageWindowMgr: '''A manager and factory for MessageWindow objects''' # These constants map to common.config.opt_one_window_types indices CONFIG_NEVER = 0 CONFIG_ALWAYS = 1 CONFIG_PERACCT = 2 CONFIG_PERTYPE = 3 # A key constant for the main window for all messages MAIN_WIN = 'main' def __init__(self): ''' A dictionary of windows; the key depends on the config: CONFIG_NEVER: The key is the contact JID CONFIG_ALWAYS: The key is MessageWindowMgr.MAIN_WIN CONFIG_PERACCT: The key is the account name CONFIG_PERTYPE: The key is a message type constant''' self._windows = {} # Map the mode to a int constant for frequent compares mode = gajim.config.get('one_message_window') self.mode = common.config.opt_one_window_types.index(mode) assert(self.mode != -1) def _new_window(self): win = MessageWindow() # we track the lifetime of this window win.window.connect('delete-event', self._on_window_delete) win.window.connect('destroy', self._on_window_destroy) return win def _gtkWinToMsgWin(self, gtk_win): for w in self._windows: if w.window == gtk_win: return w return None def _on_window_delete(self, win, event): # FIXME print "MessageWindowMgr._on_window_delete:", win msg_win = self._gtkWinToMsgWin(win) # TODO def _on_window_destroy(self, win): # FIXME print "MessageWindowMgr._on_window_destroy:", win # TODO: Clean up _windows def get_window(self, contact, acct, type): key = None if self.mode == self.CONFIG_NEVER: key = contact.jid elif self.mode == self.CONFIG_ALWAYS: key = self.MAIN_WIN elif self.mode == self.CONFIG_PERACCT: key = acct elif self.mode == self.CONFIG_PERTYPE: key = type win = None try: win = self._windows[key] except KeyError: # FIXME print "Creating tabbed chat window for '%s'" % str(key) win = self._new_window() self._windows[key] = win assert(win) return win class MessageControl(gtk.VBox): '''An abstract base widget that can embed in the gtk.Notebook of a MessageWindow''' def __init__(self, widget_name, contact): gtk.VBox.__init__(self) self.contact = contact self.compact_view = False self.widget_name = widget_name self.xml = gtk.glade.XML(GTKGUI_GLADE, widget_name, APP) self.widget = self.xml.get_widget(widget_name) self.draw_widgets() def draw_banner(self): # TODO pass def draw_widgets(self): self.draw_banner() # NOTE: Derived classes should implement this