file-request-error can now be saved in the awaiting_events queue
better code to handle all these events
This commit is contained in:
parent
947c7c59c4
commit
314fd4a8bf
|
@ -59,6 +59,7 @@ awaiting_events = {} # list of messages/FT reveived but not printed
|
||||||
# if type in ('chat', 'normal'): data = (message, subject, kind, time,
|
# if type in ('chat', 'normal'): data = (message, subject, kind, time,
|
||||||
# encrypted)
|
# encrypted)
|
||||||
# kind can be (incoming, error)
|
# kind can be (incoming, error)
|
||||||
|
# if typw in file-request, file-request-error: data = file_props
|
||||||
nicks = {} # list of our nick names in each account
|
nicks = {} # list of our nick names in each account
|
||||||
allow_notifications = {} # do we allow notifications for each account ?
|
allow_notifications = {} # do we allow notifications for each account ?
|
||||||
con_types = {} # type of each connection (ssl, tls, tcp, ...)
|
con_types = {} # type of each connection (ssl, tls, tcp, ...)
|
||||||
|
@ -227,3 +228,19 @@ def get_first_event(account, jid, typ = None):
|
||||||
if ev[0] == typ:
|
if ev[0] == typ:
|
||||||
return ev
|
return ev
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def popup_window(account):
|
||||||
|
autopopup = config.get('autopopup')
|
||||||
|
autopopupaway = config.get('autopopupaway')
|
||||||
|
if autopopup and (autopopupaway or connections[account].connected > 3):
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
def show_notification(account):
|
||||||
|
if config.get('notify_on_new_message'):
|
||||||
|
# check OUR status and if we allow notifications for that status
|
||||||
|
if config.get('autopopupaway'): # always show notification
|
||||||
|
return True
|
||||||
|
if connections[account].connected in (2, 3): # we're online or chat
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
|
@ -910,8 +910,7 @@ class PopupNotificationWindow:
|
||||||
# Get the first single message event
|
# Get the first single message event
|
||||||
ev = gajim.get_first_event(self.account, self.jid, 'normal')
|
ev = gajim.get_first_event(self.account, self.jid, 'normal')
|
||||||
# Open the window
|
# Open the window
|
||||||
self.plugin.roster.open_single_message_window_from_event(self.jid,
|
self.plugin.roster.open_event(self.account, self.jid, ev)
|
||||||
self.account, ev)
|
|
||||||
|
|
||||||
elif self.msg_type == 'pm': # It's a private message
|
elif self.msg_type == 'pm': # It's a private message
|
||||||
self.plugin.roster.new_chat(contact, self.account)
|
self.plugin.roster.new_chat(contact, self.account)
|
||||||
|
@ -921,8 +920,7 @@ class PopupNotificationWindow:
|
||||||
elif self.msg_type == 'file-request': # it's file request
|
elif self.msg_type == 'file-request': # it's file request
|
||||||
# Get the first single message event
|
# Get the first single message event
|
||||||
ev = gajim.get_first_event(self.account, self.jid, 'file-request')
|
ev = gajim.get_first_event(self.account, self.jid, 'file-request')
|
||||||
self.plugin.roster.open_file_request_from_event(self.jid, self.account,
|
self.plugin.roster.open_event(self.account, self.jid, ev)
|
||||||
ev)
|
|
||||||
|
|
||||||
elif self.msg_type == 'file-completed': # file transfer is complete
|
elif self.msg_type == 'file-completed': # file transfer is complete
|
||||||
self.plugin.windows['file_transfers'].show_completed(self.jid,
|
self.plugin.windows['file_transfers'].show_completed(self.jid,
|
||||||
|
|
89
src/gajim.py
89
src/gajim.py
|
@ -791,28 +791,62 @@ class Interface:
|
||||||
gajim.config.get('autopopupaway'):
|
gajim.config.get('autopopupaway'):
|
||||||
self.windows['file_transfers'].show_send_error(file_props)
|
self.windows['file_transfers'].show_send_error(file_props)
|
||||||
|
|
||||||
|
def add_event(self, account, jid, typ, args):
|
||||||
|
'''add an event to the awaiting_events var'''
|
||||||
|
# We add it to the awaiting_events queue
|
||||||
|
# Do we have a queue?
|
||||||
|
qs = gajim.awaiting_events[account]
|
||||||
|
no_queue = False
|
||||||
|
if not qs.has_key(jid):
|
||||||
|
no_queue = True
|
||||||
|
qs[jid] = []
|
||||||
|
qs[jid].append((typ, args))
|
||||||
|
self.roster.nb_unread += 1
|
||||||
|
|
||||||
|
self.roster.show_title()
|
||||||
|
if no_queue: # We didn't have a queue: we change icons
|
||||||
|
self.roster.draw_contact(jid, account)
|
||||||
|
if self.systray_enabled:
|
||||||
|
self.systray.add_jid(jid, account, typ)
|
||||||
|
|
||||||
|
def remove_first_event(self, account, jid, typ = None):
|
||||||
|
qs = gajim.awaiting_events[account]
|
||||||
|
event = gajim.get_first_event(account, jid, typ)
|
||||||
|
qs[jid].remove(event)
|
||||||
|
self.roster.nb_unread -= 1
|
||||||
|
self.roster.show_title()
|
||||||
|
# Is it the last event?
|
||||||
|
if not len(qs[jid]):
|
||||||
|
del qs[jid]
|
||||||
|
self.roster.draw_contact(jid, account)
|
||||||
|
if self.systray_enabled:
|
||||||
|
self.systray.remove_jid(jid, account, typ)
|
||||||
|
|
||||||
def handle_event_file_request_error(self, account, array):
|
def handle_event_file_request_error(self, account, array):
|
||||||
jid = array[0]
|
jid = array[0]
|
||||||
file_props = array[1]
|
file_props = array[1]
|
||||||
errno = file_props['error']
|
|
||||||
ft = self.windows['file_transfers']
|
ft = self.windows['file_transfers']
|
||||||
ft.set_status(file_props['type'], file_props['sid'], 'stop')
|
ft.set_status(file_props['type'], file_props['sid'], 'stop')
|
||||||
if gajim.config.get('notify_on_new_message'):
|
|
||||||
|
if gajim.popup_window(account):
|
||||||
|
errno = file_props['error']
|
||||||
|
if errno in (-4, -5):
|
||||||
|
ft.show_stopped(jid, file_props)
|
||||||
|
else:
|
||||||
|
ft.show_request_error(file_props)
|
||||||
|
return
|
||||||
|
|
||||||
|
self.plugin.add_event(account, jid, 'file-request-error', file_props)
|
||||||
|
|
||||||
|
if gajim.show_notification(account):
|
||||||
# check if we should be notified
|
# check if we should be notified
|
||||||
if errno == -4 or errno == -5:
|
if errno in (-4, -5):
|
||||||
msg_type = 'file-error'
|
msg_type = 'file-error'
|
||||||
else:
|
else:
|
||||||
msg_type = 'file-request-error'
|
msg_type = 'file-request-error'
|
||||||
instance = dialogs.PopupNotificationWindow(self,
|
instance = dialogs.PopupNotificationWindow(self,
|
||||||
_('File Transfer Error'), jid, account, msg_type, file_props)
|
_('File Transfer Error'), jid, account, msg_type, file_props)
|
||||||
self.roster.popup_notification_windows.append(instance)
|
self.roster.popup_notification_windows.append(instance)
|
||||||
elif (gajim.connections[account].connected in (2, 3)
|
|
||||||
and gajim.config.get('autopopup')) or \
|
|
||||||
gajim.config.get('autopopupaway'):
|
|
||||||
if errno == -4 or errno == -5:
|
|
||||||
self.windows['file_transfers'].show_stopped(jid, file_props)
|
|
||||||
else:
|
|
||||||
self.windows['file_transfers'].show_request_error(file_props)
|
|
||||||
|
|
||||||
def handle_event_file_request(self, account, array):
|
def handle_event_file_request(self, account, array):
|
||||||
jid = array[0]
|
jid = array[0]
|
||||||
|
@ -821,43 +855,14 @@ class Interface:
|
||||||
file_props = array[1]
|
file_props = array[1]
|
||||||
contact = gajim.contacts[account][jid][0]
|
contact = gajim.contacts[account][jid][0]
|
||||||
|
|
||||||
autopopup = gajim.config.get('autopopup')
|
if gajim.popup_window(account):
|
||||||
autopopupaway = gajim.config.get('autopopupaway')
|
|
||||||
popup = False
|
|
||||||
if autopopup and (autopopupaway or gajim.connections[account].connected \
|
|
||||||
> 3):
|
|
||||||
popup = True
|
|
||||||
|
|
||||||
if popup:
|
|
||||||
self.windows['file_transfers'].show_file_request(account, contact,
|
self.windows['file_transfers'].show_file_request(account, contact,
|
||||||
file_props)
|
file_props)
|
||||||
return
|
return
|
||||||
|
|
||||||
# We add it to the awaiting_events queue
|
self.plugin.add_event(account, jid, 'file-request', file_props)
|
||||||
# Do we have a queue?
|
|
||||||
qs = gajim.awaiting_events[account]
|
|
||||||
no_queue = False
|
|
||||||
if not qs.has_key(jid):
|
|
||||||
no_queue = True
|
|
||||||
qs[jid] = []
|
|
||||||
qs[jid].append(('file-request', (file_props)))
|
|
||||||
self.roster.nb_unread += 1
|
|
||||||
|
|
||||||
self.roster.show_title()
|
if gajim.show_notification(account):
|
||||||
if no_queue: # We didn't have a queue: we change icons
|
|
||||||
self.roster.draw_contact(jid, account)
|
|
||||||
if self.systray_enabled:
|
|
||||||
self.systray.add_jid(jid, account, 'file-request')
|
|
||||||
|
|
||||||
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 show_notification:
|
|
||||||
instance = dialogs.PopupNotificationWindow(self,
|
instance = dialogs.PopupNotificationWindow(self,
|
||||||
_('File Transfer Request'), jid, account, 'file-request')
|
_('File Transfer Request'), jid, account, 'file-request')
|
||||||
self.roster.popup_notification_windows.append(instance)
|
self.roster.popup_notification_windows.append(instance)
|
||||||
|
|
|
@ -1799,38 +1799,25 @@ _('If "%s" accepts this request you will know his status.') %jid)
|
||||||
self.send_status(acct, 'offline', message, True)
|
self.send_status(acct, 'offline', message, True)
|
||||||
self.quit_gtkgui_plugin()
|
self.quit_gtkgui_plugin()
|
||||||
|
|
||||||
def open_file_request_from_event(self, jid, account, event):
|
def open_event(self, account, jid, event):
|
||||||
qs = gajim.awaiting_events[account]
|
'''If an event was handled, return True, else return False'''
|
||||||
file_props = event[1]
|
typ = event[0]
|
||||||
qs[jid].remove(event)
|
|
||||||
self.nb_unread -= 1
|
|
||||||
self.show_title()
|
|
||||||
# Is it the last event?
|
|
||||||
if not len(qs[jid]):
|
|
||||||
del qs[jid]
|
|
||||||
self.draw_contact(jid, account)
|
|
||||||
if self.plugin.systray_enabled:
|
|
||||||
self.plugin.systray.remove_jid(jid, account, 'file-request')
|
|
||||||
# We remove the event from roster and systray before showing the window
|
|
||||||
# cause it's a dialog, and we wait for answer, so it's long.
|
|
||||||
contact = gajim.get_contact_instance_with_highest_priority(account, jid)
|
|
||||||
self.plugin.windows['file_transfers'].show_file_request(account, contact,
|
|
||||||
file_props)
|
|
||||||
|
|
||||||
def open_single_message_window_from_event(self, jid, account, event):
|
|
||||||
qs = gajim.awaiting_events[account]
|
|
||||||
data = event[1]
|
data = event[1]
|
||||||
dialogs.SingleMessageWindow(self.plugin, account, jid, action = 'receive',
|
ft = self.plugin.windows['file_transfers']
|
||||||
from_whom = jid, subject = data[1], message = data[0])
|
self.plugin.remove_first_event(account, jid, typ)
|
||||||
qs[jid].remove(event)
|
if typ == 'normal':
|
||||||
self.nb_unread -= 1
|
dialogs.SingleMessageWindow(self.plugin, account, jid,
|
||||||
self.show_title()
|
action = 'receive', from_whom = jid, subject = data[1],
|
||||||
# Is it the last event?
|
message = data[0])
|
||||||
if not len(qs[jid]):
|
return True
|
||||||
del qs[jid]
|
elif typ == 'file-request':
|
||||||
self.draw_contact(jid, account)
|
contact = gajim.get_contact_instance_with_highest_priority(account, jid)
|
||||||
if self.plugin.systray_enabled:
|
ft.show_file_request(account, contact, data)
|
||||||
self.plugin.systray.remove_jid(jid, account, 'normal')
|
return True
|
||||||
|
elif typ == 'file-request-error':
|
||||||
|
ft.show_send_error(data)
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
def on_roster_treeview_row_activated(self, widget, path, col = 0):
|
def on_roster_treeview_row_activated(self, widget, path, col = 0):
|
||||||
'''When an iter is double clicked: open the first event window'''
|
'''When an iter is double clicked: open the first event window'''
|
||||||
|
@ -1847,12 +1834,7 @@ _('If "%s" accepts this request you will know his status.') %jid)
|
||||||
else:
|
else:
|
||||||
first_ev = gajim.get_first_event(account, jid)
|
first_ev = gajim.get_first_event(account, jid)
|
||||||
if first_ev:
|
if first_ev:
|
||||||
typ = first_ev[0]
|
if self.open_event(account, jid, first_ev):
|
||||||
if typ == 'normal':
|
|
||||||
self.open_single_message_window_from_event(jid, account, first_ev)
|
|
||||||
return
|
|
||||||
elif typ == 'file-request':
|
|
||||||
self.open_file_request_from_event(jid, account, first_ev)
|
|
||||||
return
|
return
|
||||||
|
|
||||||
if self.plugin.windows[account]['chats'].has_key(jid):
|
if self.plugin.windows[account]['chats'].has_key(jid):
|
||||||
|
|
|
@ -274,12 +274,6 @@ class Systray:
|
||||||
self.plugin.roster.new_chat(
|
self.plugin.roster.new_chat(
|
||||||
gajim.contacts[account][jid][0], account)
|
gajim.contacts[account][jid][0], account)
|
||||||
w = wins['chats'][jid]
|
w = wins['chats'][jid]
|
||||||
elif typ == 'normal': # single message
|
|
||||||
# Get the first single message event
|
|
||||||
ev = gajim.get_first_event(account, jid, 'normal')
|
|
||||||
# Open the window
|
|
||||||
self.plugin.roster.open_single_message_window_from_event(jid,
|
|
||||||
account, ev)
|
|
||||||
elif typ == 'pm':
|
elif typ == 'pm':
|
||||||
if wins['chats'].has_key(jid):
|
if wins['chats'].has_key(jid):
|
||||||
w = wins['chats'][jid]
|
w = wins['chats'][jid]
|
||||||
|
@ -290,11 +284,11 @@ class Systray:
|
||||||
show = show, ask = 'none')
|
show = show, ask = 'none')
|
||||||
self.plugin.roster.new_chat(c, account)
|
self.plugin.roster.new_chat(c, account)
|
||||||
w = wins['chats'][jid]
|
w = wins['chats'][jid]
|
||||||
elif typ == 'file-request':
|
elif typ in ('normal', 'file-request', 'file-request-error'):
|
||||||
# Get the first single message event
|
# Get the first single message event
|
||||||
ev = gajim.get_first_event(account, jid, 'file-request')
|
ev = gajim.get_first_event(account, jid, typ)
|
||||||
# Open the window
|
# Open the window
|
||||||
self.plugin.roster.open_file_request_from_event(jid, account, ev)
|
self.plugin.roster.open_event(account, jid, ev)
|
||||||
if w:
|
if w:
|
||||||
w.set_active_tab(jid)
|
w.set_active_tab(jid)
|
||||||
w.window.present()
|
w.window.present()
|
||||||
|
|
Loading…
Reference in New Issue