Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
vmj-qt
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kulya
vmj-qt
Commits
4d82d5ee
Commit
4d82d5ee
authored
Jul 07, 2023
by
Tijmen de Mes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Handle link opening if file is in cache
parent
bc3b9411
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
3 deletions
+51
-3
chatwindow.py
blink/chatwindow.py
+17
-2
util.py
blink/util.py
+34
-1
No files found.
blink/chatwindow.py
View file @
4d82d5ee
...
...
@@ -45,7 +45,7 @@ from blink.history import HistoryManager
from
blink.messages
import
MessageManager
,
BlinkMessage
from
blink.resources
import
IconManager
,
Resources
from
blink.sessions
import
ChatSessionModel
,
ChatSessionListView
,
SessionManager
,
StreamDescription
from
blink.util
import
run_in_gui_thread
,
call_later
,
translate
from
blink.util
import
run_in_gui_thread
,
call_later
,
translate
,
copy_transfer_file
from
blink.widgets.color
import
ColorHelperMixin
from
blink.widgets.graph
import
Graph
from
blink.widgets.otr
import
OTRWidget
...
...
@@ -361,7 +361,6 @@ class ChatWebPage(QWebPage):
def
__init__
(
self
,
parent
=
None
):
super
(
ChatWebPage
,
self
)
.
__init__
(
parent
)
self
.
setLinkDelegationPolicy
(
QWebPage
.
DelegateAllLinks
)
self
.
linkClicked
.
connect
(
QDesktopServices
.
openUrl
)
disable_actions
=
{
QWebPage
.
OpenLink
,
QWebPage
.
OpenLinkInNewWindow
,
QWebPage
.
OpenLinkInThisWindow
,
QWebPage
.
DownloadLinkToDisk
,
QWebPage
.
OpenImageInNewWindow
,
QWebPage
.
DownloadImageToDisk
,
QWebPage
.
DownloadMediaToDisk
,
QWebPage
.
Back
,
QWebPage
.
Forward
,
QWebPage
.
Stop
,
QWebPage
.
Reload
}
...
...
@@ -710,6 +709,8 @@ class ChatWidget(base_class, ui_class):
self
.
chat_input
.
lockReleased
.
connect
(
self
.
_SH_ChatInputLockReleased
)
self
.
chat_view
.
sizeChanged
.
connect
(
self
.
_SH_ChatViewSizeChanged
)
self
.
chat_view
.
page
()
.
mainFrame
()
.
contentsSizeChanged
.
connect
(
self
.
_SH_ChatViewFrameContentsSizeChanged
)
self
.
chat_view
.
page
()
.
linkClicked
.
connect
(
self
.
_SH_LinkClicked
)
self
.
chat_view
.
messageShouldRemove
.
connect
(
self
.
_SH_MessageShouldRemove
)
self
.
composing_timer
.
timeout
.
connect
(
self
.
_SH_ComposingTimerTimeout
)
...
...
@@ -932,6 +933,20 @@ class ChatWidget(base_class, ui_class):
self
.
chat_input
.
keyPressEvent
(
QKeyEvent
(
QEvent
.
KeyPress
,
Qt
.
Key_Return
,
Qt
.
NoModifier
,
text
=
'
\r
'
))
self
.
chat_input
.
setHtml
(
user_text
)
def
_SH_LinkClicked
(
self
,
link
):
directory
=
SIPSimpleSettings
()
.
file_transfer
.
directory
.
normalized
try
:
link
=
copy_transfer_file
(
link
,
directory
)
QDesktopServices
.
openUrl
(
link
)
except
FileNotFoundError
:
blink_session
=
self
.
session
.
blink_session
id
=
None
if
link
.
hasFragment
():
id
=
link
.
fragment
()
NotificationCenter
()
.
post_notification
(
'BlinkSessionShouldDownloadFile'
,
sender
=
blink_session
,
data
=
NotificationData
(
filename
=
link
.
fileName
(),
id
=
id
))
def
_SH_MessageShouldRemove
(
self
,
id
):
blink_session
=
self
.
session
.
blink_session
MessageManager
()
.
send_remove_message
(
blink_session
,
id
)
...
...
blink/util.py
View file @
4d82d5ee
import
os
import
shutil
from
PyQt5.QtCore
import
QObject
,
QThread
,
QTimer
,
QCoreApplication
from
PyQt5.QtWidgets
import
QApplication
from
application.python.decorator
import
decorator
,
preserve_signature
from
application.python.descriptor
import
classproperty
from
application.python.types
import
Singleton
from
application.system
import
openfile
from
filecmp
import
cmp
from
functools
import
partial
from
itertools
import
count
from
threading
import
Event
...
...
@@ -12,7 +16,7 @@ from sys import exc_info
from
blink.event
import
CallFunctionEvent
__all__
=
[
'QSingleton'
,
'UniqueFilenameGenerator'
,
'call_in_gui_thread'
,
'call_later'
,
'run_in_gui_thread'
,
'translate'
]
__all__
=
[
'QSingleton'
,
'UniqueFilenameGenerator'
,
'call_in_gui_thread'
,
'call_later'
,
'
copy_transfer_file'
,
'
run_in_gui_thread'
,
'translate'
]
translate
=
QCoreApplication
.
translate
...
...
@@ -30,6 +34,35 @@ class UniqueFilenameGenerator(object):
yield
"
%
s-
%
d
%
s"
%
(
prefix
,
x
,
extension
)
def
copy_transfer_file
(
link
,
directory
):
if
not
link
.
isLocalFile
():
return
link
filename
=
link
.
fileName
()
destination
=
os
.
path
.
join
(
directory
,
filename
)
if
destination
==
link
.
toLocalFile
():
if
cmp
(
link
.
toLocalFile
(),
destination
,
True
):
return
link
raise
FileNotFoundError
is_same_file
=
False
for
name
in
UniqueFilenameGenerator
.
generate
(
destination
):
try
:
openfile
(
name
,
'rb'
)
except
FileNotFoundError
:
destination
=
name
break
else
:
if
cmp
(
link
.
toLocalFile
(),
destination
,
True
):
is_same_file
=
True
break
continue
if
not
is_same_file
:
shutil
.
copy
(
link
.
toLocalFile
(),
directory
)
link
.
setPath
(
destination
)
return
link
def
call_later
(
interval
,
function
,
*
args
,
**
kw
):
QTimer
.
singleShot
(
int
(
interval
*
1000
),
lambda
:
function
(
*
args
,
**
kw
))
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment