Creating window through the manager, introduced Control types, config stuff, etc.
This commit is contained in:
parent
1db1c7eddd
commit
18984fe7cb
|
@ -3717,7 +3717,7 @@ Per account
|
||||||
Per type</property>
|
Per type</property>
|
||||||
<property name="add_tearoffs">False</property>
|
<property name="add_tearoffs">False</property>
|
||||||
<property name="focus_on_click">True</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>
|
</widget>
|
||||||
<packing>
|
<packing>
|
||||||
<property name="padding">0</property>
|
<property name="padding">0</property>
|
||||||
|
|
|
@ -17,6 +17,7 @@ import gtk.glade
|
||||||
import pango
|
import pango
|
||||||
import gobject
|
import gobject
|
||||||
|
|
||||||
|
import common
|
||||||
from common import gajim
|
from common import gajim
|
||||||
|
|
||||||
####################
|
####################
|
||||||
|
@ -28,10 +29,6 @@ APP = i18n.APP
|
||||||
GTKGUI_GLADE = 'gtkgui.glade'
|
GTKGUI_GLADE = 'gtkgui.glade'
|
||||||
####################
|
####################
|
||||||
|
|
||||||
#import chat_widget
|
|
||||||
#TYPE_CHAT = 1
|
|
||||||
#TYPE_MUC = 2
|
|
||||||
|
|
||||||
class MessageWindow:
|
class MessageWindow:
|
||||||
'''Class for windows which contain message like things; chats,
|
'''Class for windows which contain message like things; chats,
|
||||||
groupchats, etc.'''
|
groupchats, etc.'''
|
||||||
|
@ -45,12 +42,111 @@ class MessageWindow:
|
||||||
self.alignment = self.xml.get_widget('alignment')
|
self.alignment = self.xml.get_widget('alignment')
|
||||||
self.notebook = self.xml.get_widget('notebook')
|
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):
|
def new_tab(self, type, contact, acct):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
class MessageWindowMgr:
|
class MessageWindowMgr:
|
||||||
'''A manager and factory for MessageWindow objects'''
|
'''A manager and factory for MessageWindow objects'''
|
||||||
|
|
||||||
def __init__(self):
|
# These constants map to common.config.opt_one_window_types indices
|
||||||
self._windows = {}
|
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)
|
||||||
|
|
|
@ -33,6 +33,7 @@ import time
|
||||||
import common.sleepy
|
import common.sleepy
|
||||||
import tabbed_chat_window
|
import tabbed_chat_window
|
||||||
import groupchat_window
|
import groupchat_window
|
||||||
|
import message_window
|
||||||
import history_window
|
import history_window
|
||||||
import dialogs
|
import dialogs
|
||||||
import vcard
|
import vcard
|
||||||
|
@ -46,6 +47,7 @@ from gajim import Contact
|
||||||
from common import gajim
|
from common import gajim
|
||||||
from common import helpers
|
from common import helpers
|
||||||
from common import i18n
|
from common import i18n
|
||||||
|
from message_window import MessageWindowMgr
|
||||||
|
|
||||||
_ = i18n._
|
_ = i18n._
|
||||||
APP = i18n.APP
|
APP = i18n.APP
|
||||||
|
@ -1645,6 +1647,10 @@ _('If "%s" accepts this request you will know his or her status.') %jid)
|
||||||
self.make_menu()
|
self.make_menu()
|
||||||
|
|
||||||
def new_chat(self, contact, account):
|
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']
|
chats = gajim.interface.instances[account]['chats']
|
||||||
if gajim.config.get('usetabbedchat'):
|
if gajim.config.get('usetabbedchat'):
|
||||||
if not chats.has_key('tabbed'):
|
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()
|
self.window.show_all()
|
||||||
else:
|
else:
|
||||||
if not gajim.config.get('trayicon'):
|
if not gajim.config.get('trayicon'):
|
||||||
# cannot happen via GUI, but I put this incase user touches config
|
# cannot happen via GUI, but I put this incase user touches
|
||||||
self.window.show_all() # without trayicon, he or she should see the roster!
|
# config. without trayicon, he or she should see the roster!
|
||||||
|
self.window.show_all()
|
||||||
gajim.config.set('show_roster_on_startup', True)
|
gajim.config.set('show_roster_on_startup', True)
|
||||||
|
|
||||||
if len(gajim.connections) == 0: # if we have no account
|
if len(gajim.connections) == 0: # if we have no account
|
||||||
gajim.interface.instances['account_creation_wizard'] = \
|
gajim.interface.instances['account_creation_wizard'] = \
|
||||||
config.AccountCreationWizardWindow()
|
config.AccountCreationWizardWindow()
|
||||||
|
|
||||||
|
# This is the manager and factory of message windows
|
||||||
|
self.msg_win_mgr = MessageWindowMgr()
|
||||||
|
|
Loading…
Reference in New Issue