diff --git a/src/filetransfers_window.py b/src/filetransfers_window.py index 131e19bef..43ebbb287 100644 --- a/src/filetransfers_window.py +++ b/src/filetransfers_window.py @@ -273,10 +273,16 @@ _('Connection with peer cannot be established.')) def send_file(self, account, contact, file_path): ''' start the real transfer(upload) of the file ''' - if type(contact) == str: + if gtkgui_helpers.file_is_locked(file_path): + pritext = _('Gajim cannot access this file') + sextext = _('This file is being used by another process.') + dialogs.ErrorDialog(pritext, sextext).get_response() + return + + if isinstance(contact, str): if contact.find('/') == -1: return - (jid, resource) = contact.split("/", 1) + (jid, resource) = contact.split('/', 1) contact = gajim.Contact(jid = jid, resource = resource) (file_dir, file_name) = os.path.split(file_path) file_props = self.get_send_file_props(account, contact, @@ -785,7 +791,7 @@ _('Connection with peer cannot be established.')) rect = self.tree.get_cell_area(props[0],props[1]) position = widget.window.get_origin() self.tooltip.show_tooltip(file_props , (pointer[0], rect.height ), - (position[0], position[1] + rect.y + self.height_diff)) + (position[0], position[1] + rect.y + self.height_diff)) else: self.tooltip.hide_tooltip() diff --git a/src/gtkgui_helpers.py b/src/gtkgui_helpers.py index 9e337e20f..43f21986f 100644 --- a/src/gtkgui_helpers.py +++ b/src/gtkgui_helpers.py @@ -24,6 +24,12 @@ import gobject import pango import os import sys + +if os.name == 'nt': + import win32file + import win32con + import pywintypes + from common import i18n i18n.init() _ = i18n._ @@ -83,7 +89,7 @@ def get_default_font(): line[start:line.find('"', start)]) except: #we talk about file - print _('error: cannot open %s for reading') % xfce_config_file + print >> sys.stderr, _('Error: cannot open %s for reading') % xfce_config_file elif os.path.exists(kde_config_file): try: @@ -98,7 +104,7 @@ def get_default_font(): return helpers.ensure_unicode_string(font_string) except: #we talk about file - print _('error: cannot open %s for reading') % kde_config_file + print >> sys.stderr, _('Error: cannot open %s for reading') % kde_config_file return None @@ -344,4 +350,28 @@ def possibly_move_window_in_current_desktop(window): # we are in another VD that the window was # so show it in current VD window.show() + +def file_is_locked(path_to_file): + '''returns True if file is locked (WINDOWS ONLY)''' + if os.name != 'nt': # just in case + return + secur_att = pywintypes.SECURITY_ATTRIBUTES() + secur_att.Initialize() + + try: + # try make a handle for READING the file + hfile = win32file.CreateFile( + path_to_file, # path to file + win32con.GENERIC_READ, # open for reading + 0, # do not share with other proc + secur_att, + win32con.OPEN_EXISTING, # existing file only + win32con.FILE_ATTRIBUTE_NORMAL, # normal file + 0 # no attr. template + ) + except pywintypes.error, e: + return True + else: # in case all went ok, close file handle (go to hell WinAPI) + hfile.Close() + return False