Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
gajim
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Weblate
gajim
Commits
36cc5bfa
Commit
36cc5bfa
authored
19 years ago
by
nkour
Browse files
Options
Downloads
Patches
Plain Diff
WINAPI: Gajim now can detects file lock and does not allow sending the file.
parent
48dd04a2
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/filetransfers_window.py
+9
-3
9 additions, 3 deletions
src/filetransfers_window.py
src/gtkgui_helpers.py
+32
-2
32 additions, 2 deletions
src/gtkgui_helpers.py
with
41 additions
and
5 deletions
src/filetransfers_window.py
+
9
−
3
View file @
36cc5bfa
...
...
@@ -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
()
...
...
This diff is collapsed.
Click to expand it.
src/gtkgui_helpers.py
+
32
−
2
View file @
36cc5bfa
...
...
@@ -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
_
(
'
e
rror: cannot open %s for reading
'
)
%
xfce_config_file
print
>>
sys
.
stderr
,
_
(
'
E
rror: 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
_
(
'
e
rror: cannot open %s for reading
'
)
%
kde_config_file
print
>>
sys
.
stderr
,
_
(
'
E
rror: 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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment