Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
G
gajim-plugins
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
Evert Mouw
gajim-plugins
Commits
2cc6f200
Commit
2cc6f200
authored
8 years ago
by
Philipp Hörist
Browse files
Options
Downloads
Patches
Plain Diff
[httpupload] Add request_slot() methode
parent
07edf439
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
httpupload/httpupload.py
+26
-37
26 additions, 37 deletions
httpupload/httpupload.py
with
26 additions
and
37 deletions
httpupload/httpupload.py
+
26
−
37
View file @
2cc6f200
...
@@ -128,6 +128,7 @@ class Base(object):
...
@@ -128,6 +128,7 @@ class Base(object):
self
.
enabled
=
False
self
.
enabled
=
False
self
.
component
=
None
self
.
component
=
None
self
.
controls
=
{}
self
.
controls
=
{}
self
.
conn
=
gajim
.
connections
[
account
].
connection
def
add_button
(
self
,
chat_control
):
def
add_button
(
self
,
chat_control
):
jid
=
chat_control
.
contact
.
jid
jid
=
chat_control
.
contact
.
jid
...
@@ -184,11 +185,6 @@ class Base(object):
...
@@ -184,11 +185,6 @@ class Base(object):
if
not
path_to_file
or
not
os
.
path
.
exists
(
path_to_file
):
if
not
path_to_file
or
not
os
.
path
.
exists
(
path_to_file
):
return
return
encrypted
=
self
.
encryption_activated
(
jid
)
filesize
=
os
.
path
.
getsize
(
path_to_file
)
if
encrypted
:
filesize
+=
TAGSIZE
invalid_file
=
False
invalid_file
=
False
if
os
.
path
.
isfile
(
path_to_file
):
if
os
.
path
.
isfile
(
path_to_file
):
stat
=
os
.
stat
(
path_to_file
)
stat
=
os
.
stat
(
path_to_file
)
...
@@ -203,13 +199,21 @@ class Base(object):
...
@@ -203,13 +199,21 @@ class Base(object):
transient_for
=
chat_control
.
parent_win
.
window
)
transient_for
=
chat_control
.
parent_win
.
window
)
return
return
encrypted
=
self
.
encryption_activated
(
jid
)
filesize
=
os
.
path
.
getsize
(
path_to_file
)
if
encrypted
:
filesize
+=
TAGSIZE
mime_type
=
mimetypes
.
MimeTypes
().
guess_type
(
path_to_file
)[
0
]
mime_type
=
mimetypes
.
MimeTypes
().
guess_type
(
path_to_file
)[
0
]
if
not
mime_type
:
if
not
mime_type
:
mime_type
=
'
application/octet-stream
'
# fallback mime type
mime_type
=
'
application/octet-stream
'
# fallback mime type
log
.
info
(
"
Detected MIME Type of file:
"
+
str
(
mime_type
))
log
.
info
(
"
Detected MIME type of file:
"
,
mime_type
)
progress_messages
=
Queue
(
8
)
progress_messages
=
Queue
(
8
)
progress_window
=
ProgressWindow
(
_
(
'
HTTP Upload
'
),
_
(
'
Requesting HTTP Upload Slot...
'
),
progress_window
=
ProgressWindow
(
_
(
'
HTTP Upload
'
),
_
(
'
Requesting HTTP Upload Slot...
'
),
progress_messages
,
self
.
plugin
,
parent
=
self
.
chat_control
.
parent_win
.
window
)
progress_messages
,
self
.
plugin
,
parent
=
chat_control
.
parent_win
.
window
)
self
.
request_slot
(
path_to_file
,
filesize
,
mime_type
,
encrypted
)
def
upload_file
(
stanza
):
def
upload_file
(
stanza
):
slot
=
stanza
.
getTag
(
"
slot
"
)
slot
=
stanza
.
getTag
(
"
slot
"
)
...
@@ -325,36 +329,6 @@ class Base(object):
...
@@ -325,36 +329,6 @@ class Base(object):
transient_for
=
self
.
chat_control
.
parent_win
.
window
)
transient_for
=
self
.
chat_control
.
parent_win
.
window
)
return
return
# create iq for slot request
id_
=
gajim
.
get_an_id
()
iq
=
nbxmpp
.
Iq
(
typ
=
'
get
'
,
to
=
jid_to_servers
[
gajim
.
get_jid_from_account
(
self
.
chat_control
.
account
)],
queryNS
=
None
)
iq
.
setID
(
id_
)
request
=
iq
.
addChild
(
name
=
"
request
"
,
namespace
=
NS_HTTPUPLOAD
)
filename
=
request
.
addChild
(
name
=
"
filename
"
,
)
filename
.
addData
(
os
.
path
.
basename
(
path_to_file
))
size
=
request
.
addChild
(
name
=
"
size
"
,
)
size
.
addData
(
filesize
)
content_type
=
request
.
addChild
(
name
=
"
content-type
"
,
)
content_type
.
addData
(
mime_type
)
# send slot request and register callback
log
.
debug
(
"
sending httpupload slot request iq...
"
)
iq_ids_to_callbacks
[
str
(
id_
)]
=
upload_file
gajim
.
connections
[
self
.
chat_control
.
account
].
connection
.
send
(
iq
)
self
.
chat_control
.
msg_textview
.
grab_focus
()
self
.
chat_control
.
msg_textview
.
grab_focus
()
def
on_file_button_clicked
(
self
,
widget
,
jid
,
chat_control
):
def
on_file_button_clicked
(
self
,
widget
,
jid
,
chat_control
):
...
@@ -368,6 +342,21 @@ class Base(object):
...
@@ -368,6 +342,21 @@ class Base(object):
default_response
=
Gtk
.
ResponseType
.
OK
,
default_response
=
Gtk
.
ResponseType
.
OK
,
transient_for
=
chat_control
.
parent_win
.
window
)
transient_for
=
chat_control
.
parent_win
.
window
)
def
request_slot
(
self
,
path_to_file
,
filesize
,
mime_type
,
encrypted
):
iq
=
nbxmpp
.
Iq
(
typ
=
'
get
'
,
to
=
self
.
component
)
id_
=
gajim
.
get_an_id
()
iq
.
setID
(
id_
)
request
=
iq
.
setTag
(
name
=
"
request
"
,
namespace
=
NS_HTTPUPLOAD
)
request
.
addChild
(
'
filename
'
,
payload
=
os
.
path
.
basename
(
path_to_file
))
request
.
addChild
(
'
size
'
,
payload
=
filesize
)
request
.
addChild
(
'
content-type
'
,
payload
=
mime_type
)
log
.
info
(
"
Sending request for slot
"
)
IQ_CALLBACK
[
id_
]
=
\
lambda
stanza
:
self
.
upload_file
(
stanza
,
path_to_file
,
filesize
,
mime_type
,
encrypted
)
self
.
conn
.
send
(
iq
)
class
StreamFileWithProgress
:
class
StreamFileWithProgress
:
def
__init__
(
self
,
path
,
mode
,
callback
=
None
,
def
__init__
(
self
,
path
,
mode
,
callback
=
None
,
encrypted_upload
=
False
,
key
=
None
,
iv
=
None
,
*
args
):
encrypted_upload
=
False
,
key
=
None
,
iv
=
None
,
*
args
):
...
...
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