file transfer request can now be stored in awaiting_events queue and recalled from roster / filetransfer / popup notification

This commit is contained in:
Yann Leboulanger 2005-10-18 09:07:52 +00:00
parent 4a824668e1
commit 63c1d3d3f0
5 changed files with 89 additions and 18 deletions

View File

@ -215,4 +215,15 @@ def get_hostname_from_account(account_name):
if config.get_per('accounts', account_name, 'use_custom_host'):
return config.get_per('accounts', account_name, 'custom_host')
return config.get_per('accounts', account_name, 'hostname')
def get_first_event(account, jid, typ = None):
'''returns the first event of the given type from the awaiting_events queue'''
if not awaiting_events[account].has_key(jid):
return None
q = awaiting_events[account][jid]
if not typ:
return q[0]
for ev in q:
if ev[0] == typ:
return ev
return None

View File

@ -908,10 +908,7 @@ class PopupNotificationWindow:
if self.msg_type == 'normal': # it's single message
# Get the first single message event
q = gajim.awaiting_events[self.account][self.jid]
for ev in q:
if ev[0] == 'normal':
break
ev = gajim.get_first_event(self.account, self.jid, 'normal')
# Open the window
self.plugin.roster.open_single_message_window_from_event(self.jid,
self.account, ev)
@ -921,9 +918,11 @@ class PopupNotificationWindow:
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-request': # it's file request
# Get the first single message event
ev = gajim.get_first_event(self.account, self.jid, 'file-request')
self.plugin.roster.open_file_request_from_event(self.jid, self.account,
ev)
elif self.msg_type == 'file-completed': # file transfer is complete
self.plugin.windows['file_transfers'].show_completed(self.jid,

View File

@ -820,9 +820,48 @@ class Interface:
return
file_props = array[1]
contact = gajim.contacts[account][jid][0]
self.windows['file_transfers'].show_file_request(
account, contact, file_props)
autopopup = gajim.config.get('autopopup')
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,
file_props)
return
# 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(('file-request', (file_props)))
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, '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,
_('File Transfer Request'), jid, account, 'file-request')
self.roster.popup_notification_windows.append(instance)
def handle_event_file_progress(self, account, file_props):
self.windows['file_transfers'].set_progress(file_props['type'],
file_props['sid'], file_props['received-len'])

View File

@ -1799,6 +1799,24 @@ _('If "%s" accepts this request you will know his status.') %jid)
self.send_status(acct, 'offline', message, True)
self.quit_gtkgui_plugin()
def open_file_request_from_event(self, jid, account, event):
qs = gajim.awaiting_events[account]
file_props = event[1]
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]
@ -1827,13 +1845,15 @@ _('If "%s" accepts this request you will know his status.') %jid)
else:
self.tree.expand_row(path, False)
else:
qs = gajim.awaiting_events[account]
if qs.has_key(jid):
first_ev = qs[jid][0]
first_ev = gajim.get_first_event(account, jid)
if first_ev:
typ = first_ev[0]
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
if self.plugin.windows[account]['chats'].has_key(jid):
self.plugin.windows[account]['chats'][jid].set_active_tab(jid)

View File

@ -276,10 +276,7 @@ class Systray:
w = wins['chats'][jid]
elif typ == 'normal': # single message
# Get the first single message event
q = gajim.awaiting_events[account][jid]
for ev in q:
if ev[0] == 'normal':
break
ev = gajim.get_first_event(account, jid, 'normal')
# Open the window
self.plugin.roster.open_single_message_window_from_event(jid,
account, ev)
@ -293,6 +290,11 @@ class Systray:
show = show, ask = 'none')
self.plugin.roster.new_chat(c, account)
w = wins['chats'][jid]
elif typ == 'file-request':
# Get the first single message event
ev = gajim.get_first_event(account, jid, 'file-request')
# Open the window
self.plugin.roster.open_file_request_from_event(jid, account, ev)
if w:
w.set_active_tab(jid)
w.window.present()