[change window icon according to the content (muc, chat). Fixes #4300

This commit is contained in:
Yann Leboulanger 2009-10-23 10:02:45 +02:00
parent f6136a7058
commit 503aebd919
4 changed files with 35 additions and 6 deletions

View File

@ -2045,13 +2045,16 @@ class ChatControl(ChatControlBase):
label_str = '<b>' + unread + label_str + '</b>'
return (label_str, color)
def get_tab_image(self):
def get_tab_image(self, count_unread=True):
if self.resource:
jid = self.contact.get_full_jid()
else:
jid = self.contact.jid
num_unread = len(gajim.events.get_events(self.account, jid,
['printed_' + self.type_id, self.type_id]))
if count_unread:
num_unread = len(gajim.events.get_events(self.account, jid,
['printed_' + self.type_id, self.type_id]))
else:
num_unread = 0
# Set tab image (always 16x16); unread messages show the 'event' image
tab_img = None
@ -2066,7 +2069,7 @@ class ChatControl(ChatControlBase):
# For transient contacts
contact = self.contact
img_16 = gajim.interface.roster.get_appropriate_state_images(
self.contact.jid, icon_name = contact.show)
self.contact.jid, icon_name=contact.show)
tab_img = img_16[contact.show]
return tab_img

View File

@ -535,7 +535,7 @@ class GroupchatControl(ChatControlBase):
label_str = unread + label_str
return (label_str, color)
def get_tab_image(self):
def get_tab_image(self, count_unread=True):
# Set tab image (always 16x16)
tab_image = None
if gajim.gc_connected[self.account][self.room_jid]:

View File

@ -120,7 +120,7 @@ class MessageControl:
#return (label_str, None)
pass
def get_tab_image(self):
def get_tab_image(self, count_unread=True):
# Return a suitable tab image for display.
# None clears any current label.
return None

View File

@ -146,6 +146,7 @@ class MessageWindow(object):
else:
self.notebook.set_show_tabs(False)
self.notebook.set_show_border(gajim.config.get('tabs_border'))
self.show_icon()
def change_account_name(self, old_name, new_name):
if old_name in self._controls:
@ -417,6 +418,29 @@ class MessageWindow(object):
'''When close button is pressed: close a tab'''
self.remove_tab(control, self.CLOSE_CLOSE_BUTTON)
def show_icon(self):
window_mode = gajim.interface.msg_win_mgr.mode
icon = None
if window_mode == MessageWindowMgr.ONE_MSG_WINDOW_NEVER:
ctrl = self.get_active_control()
if not ctrl:
return
icon = ctrl.get_tab_image(count_unread=False)
elif window_mode == MessageWindowMgr.ONE_MSG_WINDOW_ALWAYS:
pass # keep default icon
elif window_mode == MessageWindowMgr.ONE_MSG_WINDOW_ALWAYS_WITH_ROSTER:
pass # keep default icon
elif window_mode == MessageWindowMgr.ONE_MSG_WINDOW_PERACCT:
pass # keep default icon
elif window_mode == MessageWindowMgr.ONE_MSG_WINDOW_PERTYPE:
if self.type_ == 'gc':
icon = gtkgui_helpers.load_icon('muc_active')
else:
# chat, pm
icon = gtkgui_helpers.load_icon('online')
if icon:
self.window.set_icon(icon.get_pixbuf())
def show_title(self, urgent=True, control=None):
'''redraw the window's title'''
if not control:
@ -587,6 +611,8 @@ class MessageWindow(object):
else:
status_img.set_from_pixbuf(tab_img.get_pixbuf())
self.show_icon()
def repaint_themed_widgets(self):
'''Repaint controls in the window with theme color'''
# iterate through controls and repaint