diff --git a/src/dialogs.py b/src/dialogs.py index e5e3ca202..249a30952 100644 --- a/src/dialogs.py +++ b/src/dialogs.py @@ -945,11 +945,12 @@ _('Without a connection, you can not change your password.')).get_response() class PopupNotificationWindow: - def __init__(self, plugin, event_type, jid, account, msg_type = ''): + def __init__(self, plugin, event_type, jid, account, msg_type = '', file_props = None): self.plugin = plugin self.account = account self.jid = jid self.msg_type = msg_type + self.file_props = file_props xml = gtk.glade.XML(GTKGUI_GLADE, 'popup_notification_window', APP) self.window = xml.get_widget('popup_notification_window') @@ -983,6 +984,11 @@ class PopupNotificationWindow: close_button.modify_bg(gtk.STATE_NORMAL, dodgerblue) eventbox.modify_bg(gtk.STATE_NORMAL, dodgerblue) txt = _('From %s') % txt + elif event_type == _('File Request'): + bg_color = gtk.gdk.color_parse('coral') + close_button.modify_bg(gtk.STATE_NORMAL, bg_color) + eventbox.modify_bg(gtk.STATE_NORMAL, bg_color) + txt = _('From %s') % txt # position the window to bottom-right of screen window_width, self.window_height = self.window.get_size() @@ -1040,6 +1046,11 @@ class PopupNotificationWindow: contact = self.contacts[account][jid][0] dialogs.SingleMessageWindow(self.plugin, self.account, contact, action = 'receive', from_whom = jid, subject = subject, message = msg) + + elif self.msg_type == 'file': # it's file request + self.plugin.roster.show_file_request(self.account, contact, + self.file_props) + else: # 'chat' self.plugin.roster.new_chat(contact, self.account) chats_window = self.plugin.windows[self.account]['chats'][self.jid] diff --git a/src/gajim.py b/src/gajim.py index cea5018d7..14f2ed7f7 100755 --- a/src/gajim.py +++ b/src/gajim.py @@ -696,7 +696,22 @@ class Interface: bm['password']) self.roster.make_menu() - + def handle_event_file_request(self, account, array): + jid = array[0] + #~ print 'handle_event_file_request:', jid, gajim.contacts[account] + if not gajim.contacts[account].has_key(jid): + return + file_props = array[1] + #~ print 'handle_event_file_request:', array + if gajim.config.get('notify_on_new_message'): + # check OUR status and if we allow notifications for that status + if gajim.config.get('autopopupaway') or \ + gajim.connections[account].connected in (2, 3): # we're online or chat + print 'HERE' + instance = dialogs.PopupNotificationWindow(self, + _('File Request'), jid, account, 'file', file_props) + self.roster.popup_notification_windows.append(instance) + def read_sleepy(self): '''Check idle status and change that status if needed''' if not self.sleeper.poll(): @@ -862,6 +877,7 @@ class Interface: con.register_handler('ROSTER_INFO', self.handle_event_roster_info) con.register_handler('BOOKMARKS', self.handle_event_bookmarks) con.register_handler('CON_TYPE', self.handle_event_con_type) + con.register_handler('FILE_REQUEST', self.handle_event_file_request) def process_connections(self): try: diff --git a/src/roster_window.py b/src/roster_window.py index 2811bd4d2..c7a39b01c 100644 --- a/src/roster_window.py +++ b/src/roster_window.py @@ -30,6 +30,7 @@ import groupchat_window import history_window import dialogs import config +import gtkgui_helpers import cell_renderer_image from gajim import Contact @@ -1319,6 +1320,35 @@ _('If "%s" accepts this request you will know his status.') %jid).get_response() self.chg_contact_status(user, 'offline', 'Disconnected', account) self.update_status_comboxbox() self.make_menu() + + def show_file_request(self, account, contact, file_props): + if file_props is None or not file_props.has_key('name'): + return + sec_text = _('\tFile: %s') % file_props['name'] + if file_props.has_key('size'): + sec_text += '\n\t' + _('Size: %s') % \ + gtkgui_helpers.convert_bytes(file_props['size']) + if file_props.has_key('mime-type'): + sec_text += '\n\t' + _('Type: %s') % file_props['mime-type'] + if file_props.has_key('desc'): + sec_text += '\n\t' + _('Description: %s') % file_props['desc'] + prim_text = _(' %s wants to send you file') % contact.jid + dialog = dialogs.ConfirmationDialog(prim_text, sec_text) + if dialog.get_response() == gtk.RESPONSE_OK: + dialog = gtk.FileChooserDialog(title=_('Save File As...'), + action=gtk.FILE_CHOOSER_ACTION_SAVE, + buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, + gtk.STOCK_SAVE, gtk.RESPONSE_OK)) + dialog.set_current_name(file_props['name']) + dialog.set_default_response(gtk.RESPONSE_OK) + response = dialog.run() + if response == gtk.RESPONSE_OK: + file_name = dialog.get_filename() + file_props['file-name'] = file_name + gajim.connections[account].send_file_approval(file_props) + else: + gajim.connections[account].send_file_rejection(file_props) + dialog.destroy() def new_chat(self, user, account): if gajim.config.get('usetabbedchat'):