diff --git a/src/dialogs.py b/src/dialogs.py index 091fe131a..30a0e037c 100644 --- a/src/dialogs.py +++ b/src/dialogs.py @@ -1675,6 +1675,8 @@ _('Connection with peer cannot be established.')).get_response() self.tree.get_selection().unselect_all() def show_file_send_request(self, account, contact): + #FIXME: user better name for this function + #atm it's like it shows popup for incoming file transfer request dialog = gtk.FileChooserDialog(title=_('Choose File to Send...'), action=gtk.FILE_CHOOSER_ACTION_OPEN, buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)) @@ -1688,16 +1690,19 @@ _('Connection with peer cannot be established.')).get_response() response = dialog.run() if response == gtk.RESPONSE_OK: file_path = unicode(dialog.get_filename(), 'utf-8') - (file_dir, file_name) = os.path.split(file_path) if file_dir: self.last_save_dir = file_dir - file_props = self.get_send_file_props(account, contact, - file_path, file_name) dialog.destroy() - self.add_transfer(account, contact, file_props) - gajim.connections[account].send_file_request(file_props) + self.send_file(account, contact, file_path) else: dialog.destroy() + + def send_file(self, account, contact, file_path): + (file_dir, file_name) = os.path.split(file_path) + file_props = self.get_send_file_props(account, contact, + file_path, file_name) + self.add_transfer(account, contact, file_props) + gajim.connections[account].send_file_request(file_props) def show_file_request(self, account, contact, file_props): if file_props is None or not file_props.has_key('name'): diff --git a/src/tabbed_chat_window.py b/src/tabbed_chat_window.py index 998457e11..1af5fd5ba 100644 --- a/src/tabbed_chat_window.py +++ b/src/tabbed_chat_window.py @@ -24,6 +24,7 @@ import gobject import time import urllib import base64 +import os import dialogs import chat @@ -50,6 +51,8 @@ class TabbedChatWindow(chat.Chat): self.possible_paused_timeout_id = {} # keep check for possible inactive timeouts per jid self.possible_inactive_timeout_id = {} + self.TARGET_TYPE_TEXT = 80 + self.dnd_list = [ ( 'text/plain', 0, self.TARGET_TYPE_TEXT ) ] self.new_user(user) self.show_title() @@ -99,6 +102,16 @@ class TabbedChatWindow(chat.Chat): self.mouse_over_in_last_5_secs = True self.mouse_over_in_last_30_secs = True + def on_drag_data_received(self, widget, context, x, y, selection, target_type, +timestamp, contact): + if target_type == self.TARGET_TYPE_TEXT: + path = selection.data.strip() # get path to file + if path.startswith('file://'): + path = path[7:] # 7 is len('file://') + if os.path.isfile(path): # is it file? + self.plugin.windows['file_transfers'].send_file(self.account, + contact, path) + def draw_widgets(self, contact): """draw the widgets in a tab (status_image, contact_button ...) according to the the information in the contact variable""" @@ -341,6 +354,13 @@ class TabbedChatWindow(chat.Chat): self.childs[contact.jid] = self.xmls[contact.jid].get_widget('chats_vbox') self.contacts[contact.jid] = contact + + self.childs[contact.jid].connect('drag_data_received', + self.on_drag_data_received, contact) + self.childs[contact.jid].drag_dest_set( gtk.DEST_DEFAULT_MOTION | + gtk.DEST_DEFAULT_HIGHLIGHT | gtk.DEST_DEFAULT_DROP, + self.dnd_list, gtk.gdk.ACTION_COPY) + message_textview = self.xmls[contact.jid].get_widget('message_textview') message_tv_buffer = message_textview.get_buffer() message_tv_buffer.connect('insert-text',