Creating window through the manager, introduced Control types, config stuff, etc.

This commit is contained in:
Travis Shirk 2005-12-29 03:20:06 +00:00
parent 1db1c7eddd
commit 18984fe7cb
3 changed files with 115 additions and 9 deletions

View File

@ -3717,7 +3717,7 @@ Per account
Per type</property>
<property name="add_tearoffs">False</property>
<property name="focus_on_click">True</property>
<signal name="changed" handler="on_single_window_type_combo_changed" last_modification_time="Wed, 28 Dec 2005 01:44:51 GMT"/>
<signal name="changed" handler="on_one_window_type_combo_changed" last_modification_time="Thu, 29 Dec 2005 02:04:46 GMT"/>
</widget>
<packing>
<property name="padding">0</property>

View File

@ -17,6 +17,7 @@ import gtk.glade
import pango
import gobject
import common
from common import gajim
####################
@ -28,10 +29,6 @@ APP = i18n.APP
GTKGUI_GLADE = 'gtkgui.glade'
####################
#import chat_widget
#TYPE_CHAT = 1
#TYPE_MUC = 2
class MessageWindow:
'''Class for windows which contain message like things; chats,
groupchats, etc.'''
@ -45,12 +42,111 @@ class MessageWindow:
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'''
def __init__(self):
self._windows = {}
# 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.widget_name = widget_name
self.contact = contact
self.xml = gtk.glade.XML(GTKGUI_GLADE, widget_name, APP)
self.widget = self.xml.get_widget(widget_name)

View File

@ -33,6 +33,7 @@ import time
import common.sleepy
import tabbed_chat_window
import groupchat_window
import message_window
import history_window
import dialogs
import vcard
@ -46,6 +47,7 @@ from gajim import Contact
from common import gajim
from common import helpers
from common import i18n
from message_window import MessageWindowMgr
_ = i18n._
APP = i18n.APP
@ -1645,6 +1647,10 @@ _('If "%s" accepts this request you will know his or her status.') %jid)
self.make_menu()
def new_chat(self, contact, account):
# Get target window
# FIXME: type arg
mw = self.msg_win_mgr.get_window(contact, account, None)
chats = gajim.interface.instances[account]['chats']
if gajim.config.get('usetabbedchat'):
if not chats.has_key('tabbed'):
@ -2714,10 +2720,14 @@ _('If "%s" accepts this request you will know his or her status.') %jid)
self.window.show_all()
else:
if not gajim.config.get('trayicon'):
# cannot happen via GUI, but I put this incase user touches config
self.window.show_all() # without trayicon, he or she should see the roster!
# cannot happen via GUI, but I put this incase user touches
# config. without trayicon, he or she should see the roster!
self.window.show_all()
gajim.config.set('show_roster_on_startup', True)
if len(gajim.connections) == 0: # if we have no account
gajim.interface.instances['account_creation_wizard'] = \
config.AccountCreationWizardWindow()
# This is the manager and factory of message windows
self.msg_win_mgr = MessageWindowMgr()