diff --git a/src/common/gajim.py b/src/common/gajim.py index 1d7411121..c6182282d 100644 --- a/src/common/gajim.py +++ b/src/common/gajim.py @@ -59,6 +59,7 @@ awaiting_events = {} # list of messages/FT reveived but not printed # if type in ('chat', 'normal'): data = (message, subject, kind, time, # encrypted) # 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 allow_notifications = {} # do we allow notifications for each account ? 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: return ev 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 diff --git a/src/dialogs.py b/src/dialogs.py index 0e90bf0a8..12b294ca8 100644 --- a/src/dialogs.py +++ b/src/dialogs.py @@ -910,8 +910,7 @@ class PopupNotificationWindow: # Get the first single message event 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) + self.plugin.roster.open_event(self.account, self.jid, ev) elif self.msg_type == 'pm': # It's a private message self.plugin.roster.new_chat(contact, self.account) @@ -921,8 +920,7 @@ class PopupNotificationWindow: 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) + self.plugin.roster.open_event(self.account, self.jid, ev) elif self.msg_type == 'file-completed': # file transfer is complete self.plugin.windows['file_transfers'].show_completed(self.jid, diff --git a/src/gajim.py b/src/gajim.py index 01ccdc2b1..11257411e 100755 --- a/src/gajim.py +++ b/src/gajim.py @@ -790,49 +790,9 @@ class Interface: and gajim.config.get('autopopup')) or \ gajim.config.get('autopopupaway'): self.windows['file_transfers'].show_send_error(file_props) - - def handle_event_file_request_error(self, account, array): - jid = array[0] - file_props = array[1] - errno = file_props['error'] - ft = self.windows['file_transfers'] - ft.set_status(file_props['type'], file_props['sid'], 'stop') - if gajim.config.get('notify_on_new_message'): - # check if we should be notified - if errno == -4 or errno == -5: - msg_type = 'file-error' - else: - msg_type = 'file-request-error' - instance = dialogs.PopupNotificationWindow(self, - _('File Transfer Error'), jid, account, msg_type, file_props) - 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): - jid = array[0] - if not gajim.contacts[account].has_key(jid): - return - file_props = array[1] - contact = gajim.contacts[account][jid][0] - - 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 + 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] @@ -840,24 +800,69 @@ class Interface: if not qs.has_key(jid): no_queue = True qs[jid] = [] - qs[jid].append(('file-request', (file_props))) + 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, 'file-request') + self.systray.add_jid(jid, account, typ) - 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 + 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) - if show_notification: + def handle_event_file_request_error(self, account, array): + jid = array[0] + file_props = array[1] + ft = self.windows['file_transfers'] + ft.set_status(file_props['type'], file_props['sid'], 'stop') + + 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 + if errno in (-4, -5): + msg_type = 'file-error' + else: + msg_type = 'file-request-error' + instance = dialogs.PopupNotificationWindow(self, + _('File Transfer Error'), jid, account, msg_type, file_props) + self.roster.popup_notification_windows.append(instance) + + def handle_event_file_request(self, account, array): + jid = array[0] + if not gajim.contacts[account].has_key(jid): + return + file_props = array[1] + contact = gajim.contacts[account][jid][0] + + if gajim.popup_window(account): + self.windows['file_transfers'].show_file_request(account, contact, + file_props) + return + + self.plugin.add_event(account, jid, 'file-request', file_props) + + if gajim.show_notification(account): instance = dialogs.PopupNotificationWindow(self, _('File Transfer Request'), jid, account, 'file-request') self.roster.popup_notification_windows.append(instance) diff --git a/src/roster_window.py b/src/roster_window.py index 484ac38a6..2a795cf0e 100644 --- a/src/roster_window.py +++ b/src/roster_window.py @@ -1799,38 +1799,25 @@ _('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] + def open_event(self, account, jid, event): + '''If an event was handled, return True, else return False''' + typ = event[0] data = event[1] - dialogs.SingleMessageWindow(self.plugin, account, jid, action = 'receive', - from_whom = jid, subject = data[1], message = data[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, 'normal') + ft = self.plugin.windows['file_transfers'] + self.plugin.remove_first_event(account, jid, typ) + if typ == 'normal': + dialogs.SingleMessageWindow(self.plugin, account, jid, + action = 'receive', from_whom = jid, subject = data[1], + message = data[0]) + return True + elif typ == 'file-request': + contact = gajim.get_contact_instance_with_highest_priority(account, jid) + ft.show_file_request(account, contact, data) + 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): '''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: 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) + if self.open_event(account, jid, first_ev): return if self.plugin.windows[account]['chats'].has_key(jid): diff --git a/src/systray.py b/src/systray.py index 1a6157ae8..ebf8bf65f 100644 --- a/src/systray.py +++ b/src/systray.py @@ -274,12 +274,6 @@ class Systray: self.plugin.roster.new_chat( gajim.contacts[account][jid][0], account) 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': if wins['chats'].has_key(jid): w = wins['chats'][jid] @@ -290,11 +284,11 @@ class Systray: show = show, ask = 'none') self.plugin.roster.new_chat(c, account) w = wins['chats'][jid] - elif typ == 'file-request': + elif typ in ('normal', 'file-request', 'file-request-error'): # 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 - self.plugin.roster.open_file_request_from_event(jid, account, ev) + self.plugin.roster.open_event(account, jid, ev) if w: w.set_active_tab(jid) w.window.present()