groupchat_window now has an on_message function that can hold pm in queues so they are not printed (systray is not handled yet)

This commit is contained in:
Yann Leboulanger 2005-09-23 21:01:42 +00:00
parent 89d170c8b4
commit 8f93012465
6 changed files with 141 additions and 37 deletions

View File

@ -318,7 +318,7 @@ class Chat:
if end_rect.y <= (visible_rect.y + visible_rect.height):
#we are at the end
if self.nb_unread[jid] > 0:
self.nb_unread[jid] = 0
self.nb_unread[jid] = 0 + self.get_specific_unread(jid)
self.show_title()
if self.plugin.systray_enabled:
self.plugin.systray.remove_jid(jid, self.account)

View File

@ -778,12 +778,15 @@ class PopupNotificationWindow:
red = gtk.gdk.color_parse('red')
close_button.modify_bg(gtk.STATE_NORMAL, red)
eventbox.modify_bg(gtk.STATE_NORMAL, red)
elif event_type == _('New Message') or\
event_type == _('New Single Message'):
elif event_type in [_('New Message'), _('New Single Message'),
_('New Private Message')]:
dodgerblue = gtk.gdk.color_parse('dodgerblue')
close_button.modify_bg(gtk.STATE_NORMAL, dodgerblue)
eventbox.modify_bg(gtk.STATE_NORMAL, dodgerblue)
txt = _('From %s') % txt
if event_type == _('New Private Message'):
txt = _('From %s') % jid.split('/', 1)[1] # Nickname
else:
txt = _('From %s') % txt
elif event_type == _('File Transfer Request'):
bg_color = gtk.gdk.color_parse('khaki')
close_button.modify_bg(gtk.STATE_NORMAL, bg_color)
@ -822,7 +825,7 @@ class PopupNotificationWindow:
self.plugin.roster.popups_notification_height += self.window_height
self.window.move(gtk.gdk.screen_width() - window_width,
gtk.gdk.screen_height() - self.plugin.roster.popups_notification_height)
xml.signal_autoconnect(self)
self.window.show_all()
gobject.timeout_add(5000, self.on_timeout)
@ -832,12 +835,12 @@ class PopupNotificationWindow:
def on_timeout(self):
self.adjust_height_and_move_popup_notification_windows()
def adjust_height_and_move_popup_notification_windows(self):
#remove
self.plugin.roster.popups_notification_height -= self.window_height
self.window.destroy()
if len(self.plugin.roster.popup_notification_windows) > 0:
# we want to remove the first window added in the list
self.plugin.roster.popup_notification_windows.pop(0) # remove 1st item
@ -869,21 +872,31 @@ class PopupNotificationWindow:
gajim.contacts[self.account][self.jid] = [contact]
self.plugin.roster.add_contact_to_roster(contact.jid,
self.account)
elif self.msg_type == 'pm':
room_jid, nick = self.jid.split('/', 1)
show = gajim.gc_contacts[self.account][room_jid][nick].show
contact = Contact(jid = self.jid, name = nick, groups = ['none'],
show = show, sub = 'none')
if self.msg_type == 'normal': # it's single message
return # FIXME: I think I should not print here but in new_chat?
contact = get_contact_instance_with_highest_priority(account, jid)
SingleMessageWindow(self.plugin, self.account, contact.jid,
action = 'receive', from_whom = jid, subject = subject, message = msg)
elif self.msg_type == 'pm': # It's a private message
self.plugin.roster.new_chat(contact, self.account)
chats_window = self.plugin.windows[self.account]['chats'][self.jid]
chats_window.set_active_tab(self.jid)
chats_window.window.present()
elif self.msg_type == 'file': # it's file request
self.plugin.windows['file_transfers'].show_file_request(
self.account, contact, self.file_props)
elif self.msg_type == 'file-completed': # file transfer is complete
self.plugin.windows['file_transfers'].show_completed(self.jid,
self.file_props)
elif self.msg_type == 'file-stopped': # file transfer ended unexpectedly
self.plugin.windows['file_transfers'].show_stopped(self.jid,
self.file_props)

View File

@ -373,22 +373,26 @@ class Interface:
if jid.find('@') <= 0:
jid = jid.replace('@', '')
show_notification = False
if gajim.config.get('notify_on_new_message'):
# check OUR status and if we allow notifications for that status
if gajim.config.get('autopopupaway'): # always show notification
show_notification = True
elif gajim.connections[account].connected in (2, 3): # we're online or chat
show_notification = True
if self.windows[account]['gc'].has_key(jid): # it's a Private Message
nick = array[0].split('/', 1)[1]
fjid = jid + '/' + nick
if self.windows[account]['chats'].has_key(fjid):
chat_win = self.windows[account]['chats'][fjid]
chat_win.print_conversation(array[1], fjid, tim = array[2])
return
qs = gajim.awaiting_messages[account]
if not qs.has_key(fjid):
qs[fjid] = []
qs[fjid].append((array[1], 'incoming', array[2], array[3]))
self.roster.nb_unread += 1
show = gajim.gc_contacts[account][jid][nick].show
c = Contact(jid = fjid, name = nick, groups = ['none'], show = show,
ask = 'none')
self.roster.new_chat(c, account)
if not self.windows[account]['chats'].has_key(fjid) and \
not gajim.awaiting_messages[account].has_key(fjid):
if show_notification:
instance = dialogs.PopupNotificationWindow(self,
_('New Private Message'), fjid, account, 'pm')
self.roster.popup_notification_windows.append(instance)
self.windows[account]['gc'][jid].on_private_message(jid, nick,
array[1], array[2])
return
if gajim.config.get('ignore_unknown_contacts') and \
@ -661,19 +665,19 @@ class Interface:
self.remote.raise_signal('GCPresence', (account, array))
def handle_event_gc_msg(self, account, array):
#('GC_MSG', account, (jid, msg, time))
# ('GC_MSG', account, (jid, msg, time))
jids = array[0].split('/', 1)
jid = jids[0]
if not self.windows[account]['gc'].has_key(jid):
room_jid = jids[0]
if not self.windows[account]['gc'].has_key(room_jid):
return
if len(jids) == 1:
#message from server
self.windows[account]['gc'][jid].print_conversation(array[1], jid, \
tim = array[2])
# message from server
nick = ''
else:
#message from someone
self.windows[account]['gc'][jid].print_conversation(array[1], jid, \
jids[1], array[2])
# message from someone
nick = jids[1]
self.windows[account]['gc'][room_jid].on_message(room_jid, nick, array[1],
array[2])
if self.remote and self.remote.is_enabled():
self.remote.raise_signal('GCMessage', (account, array))

View File

@ -333,7 +333,11 @@ class GroupchatWindow(chat.Chat):
nick = model[user_iter][C_NICK].decode('utf-8')
show = gajim.gc_contacts[self.account][room_jid][nick].show
state_images = roster.get_appropriate_state_images(room_jid)
image = state_images[show] #FIXME: always Jabber why?
if gajim.awaiting_messages[self.account].has_key(room_jid + '/'\
+ nick):
image = state_images['message']
else:
image = state_images[show]
model[user_iter][C_IMG] = image
user_iter = model.iter_next(user_iter)
role_iter = model.iter_next(role_iter)
@ -433,7 +437,14 @@ class GroupchatWindow(chat.Chat):
subject = full_subject # tooltip must always hold ALL the subject
self.subject_tooltip[room_jid].set_tip(event_box, subject)
def get_specific_unread(self, room_jid):
nb = 0
for nick in self.get_nick_list(room_jid):
fjid = room_jid + '/' + nick
if gajim.awaiting_messages[self.account].has_key(fjid):
nb += len(gajim.awaiting_messages[self.account][fjid])
return nb
def on_change_subject_menuitem_activate(self, widget):
room_jid = self.get_active_jid()
subject = self.subjects[room_jid]
@ -1222,6 +1233,57 @@ current room topic.') % command, room_jid)
conversation_textview.grab_focus()
self.childs[room_jid].show_all()
def on_message(self, room_jid, nick, msg, tim):
if not nick:
# message from server
self.print_conversation(msg, room_jid, tim = tim)
else:
# message from someone
self.print_conversation(msg, room_jid, nick, tim)
def on_private_message(self, room_jid, nick, msg, tim):
# Do we have a queue?
fjid = room_jid + '/' + nick
qs = gajim.awaiting_messages[self.account]
no_queue = True
if qs.has_key(fjid):
no_queue = False
# We print if window is opened
if self.plugin.windows[self.account]['chats'].has_key(fjid):
chat_win = self.plugin.windows[self.account]['chats'][fjid]
chat_win.print_conversation(msg, fjid, tim = tim)
return
if no_queue:
qs[fjid] = []
qs[fjid].append((msg, 'incoming', tim, False)) # False is for encrypted
self.nb_unread[room_jid] += 1
#FIXME: when we scroll to end we set nb_unread to 0
autopopup = gajim.config.get('autopopup')
autopopupaway = gajim.config.get('autopopupaway')
iter = self.get_contact_iter(room_jid, nick)
path = self.list_treeview[room_jid].get_model().get_path(iter)
if not autopopup or ( not autopopupaway and \
gajim.connections[self.account].connected > 2):
if no_queue: # We didn't have a queue: we change icons
model = self.list_treeview[room_jid].get_model()
state_images = self.plugin.roster.get_appropriate_state_images(room_jid)
image = state_images['message']
model[iter][C_IMG] = image
self.show_title()
else:
show = gajim.gc_contacts[self.account][room_jid][nick].show
c = Contact(jid = fjid, name = nick, groups = ['none'], show = show,
ask = 'none')
self.plugin.roster.new_chat(c, self.account)
# Scroll to line
self.list_treeview[room_jid].expand_row(path[0:1], False)
self.list_treeview[room_jid].scroll_to_cell(path)
self.list_treeview[room_jid].set_cursor(path)
def set_state_image(self, jid):
# FIXME: Tab notifications?
pass

View File

@ -1518,6 +1518,8 @@ _('If "%s" accepts this request you will know his status.') %jid)
no_queue = True
if qs.has_key(jid):
no_queue = False
# We print if window is opened
if self.plugin.windows[account]['chats'].has_key(jid):
typ = ''
if msg_type == 'error':
@ -1534,7 +1536,7 @@ _('If "%s" accepts this request you will know his status.') %jid)
if (not autopopup or ( not autopopupaway and \
gajim.connections[account].connected > 2)) and not \
self.plugin.windows[account]['chats'].has_key(jid):
if no_queue: #We didn't have a queue: we change icons
if no_queue: # We didn't have a queue: we change icons
model = self.tree.get_model()
self.draw_contact(jid, account)
if self.plugin.systray_enabled:

View File

@ -182,6 +182,9 @@ timestamp, contact):
banner_name_label.set_markup(label_text)
self.paint_banner(jid)
def get_specific_unread(self, jid):
return 0
def set_avatar(self, vcard):
if not vcard.has_key('PHOTO'):
return
@ -694,6 +697,12 @@ timestamp, contact):
"""read queue and print messages containted in it"""
l = gajim.awaiting_messages[self.account][jid]
user = self.contacts[jid]
# Is it a pm ?
is_pm = False
room_jid = jid.split('/', 1)[0]
gcs = self.plugin.windows[self.account]['gc']
if gcs.has_key(room_jid):
is_pm = True
for event in l:
ev1 = event[1]
if ev1 != 'error':
@ -702,9 +711,23 @@ timestamp, contact):
ev1 = 'status'
self.print_conversation(event[0], jid, ev1,
tim = event[2], encrypted = event[3])
self.plugin.roster.nb_unread -= 1
self.plugin.roster.show_title()
# remove from gc nb_unread if it's pm or from roster
if is_pm:
gcs[room_jid].nb_unread[room_jid] -= 1
else:
self.plugin.roster.nb_unread -= 1
if is_pm:
gcs[room_jid].show_title()
else:
self.plugin.roster.show_title()
del gajim.awaiting_messages[self.account][jid]
# reset to status image in gc if it is a pm
room_jid = jid.split('/', 1)[0]
gcs = self.plugin.windows[self.account]['gc']
if gcs.has_key(room_jid):
gcs[room_jid].update_state_images()
self.plugin.roster.draw_contact(jid, self.account)
if self.plugin.systray_enabled:
self.plugin.systray.remove_jid(jid, self.account)