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

@ -216,3 +216,14 @@ def get_hostname_from_account(account_name):
return config.get_per('accounts', account_name, 'custom_host') return config.get_per('accounts', account_name, 'custom_host')
return config.get_per('accounts', account_name, 'hostname') 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 if self.msg_type == 'normal': # it's single message
# Get the first single message event # Get the first single message event
q = gajim.awaiting_events[self.account][self.jid] ev = gajim.get_first_event(self.account, self.jid, 'normal')
for ev in q:
if ev[0] == 'normal':
break
# Open the window # Open the window
self.plugin.roster.open_single_message_window_from_event(self.jid, self.plugin.roster.open_single_message_window_from_event(self.jid,
self.account, ev) self.account, ev)
@ -921,9 +918,11 @@ class PopupNotificationWindow:
chats_window = self.plugin.windows[self.account]['chats'][self.jid] chats_window = self.plugin.windows[self.account]['chats'][self.jid]
chats_window.set_active_tab(self.jid) chats_window.set_active_tab(self.jid)
chats_window.window.present() chats_window.window.present()
elif self.msg_type == 'file': # it's file request elif self.msg_type == 'file-request': # it's file request
self.plugin.windows['file_transfers'].show_file_request( # Get the first single message event
self.account, contact, self.file_props) 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 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,

View File

@ -820,8 +820,47 @@ class Interface:
return return
file_props = array[1] file_props = array[1]
contact = gajim.contacts[account][jid][0] 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): def handle_event_file_progress(self, account, file_props):
self.windows['file_transfers'].set_progress(file_props['type'], self.windows['file_transfers'].set_progress(file_props['type'],

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

View File

@ -276,10 +276,7 @@ class Systray:
w = wins['chats'][jid] w = wins['chats'][jid]
elif typ == 'normal': # single message elif typ == 'normal': # single message
# Get the first single message event # Get the first single message event
q = gajim.awaiting_events[account][jid] ev = gajim.get_first_event(account, jid, 'normal')
for ev in q:
if ev[0] == 'normal':
break
# Open the window # Open the window
self.plugin.roster.open_single_message_window_from_event(jid, self.plugin.roster.open_single_message_window_from_event(jid,
account, ev) account, ev)
@ -293,6 +290,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':
# 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: if w:
w.set_active_tab(jid) w.set_active_tab(jid)
w.window.present() w.window.present()