gajim-plugin: file info added to message
This commit is contained in:
parent
3d3d8a7e03
commit
0885d997f9
1 changed files with 29 additions and 8 deletions
|
@ -65,8 +65,7 @@ except Exception as e:
|
||||||
encryption_available = False
|
encryption_available = False
|
||||||
|
|
||||||
NS_HINTS = 'urn:xmpp:hints'
|
NS_HINTS = 'urn:xmpp:hints'
|
||||||
# XEP-0363 (http://xmpp.org/extensions/xep-0363.html)
|
NS_FILETRANSFER_HTTP = 'urn:xmpp:filetransfer:http'
|
||||||
NS_HTTPUPLOAD = 'urn:xmpp:http:upload'
|
|
||||||
TAGSIZE = 16
|
TAGSIZE = 16
|
||||||
|
|
||||||
jid_to_servers = {}
|
jid_to_servers = {}
|
||||||
|
@ -76,6 +75,8 @@ max_thumbnail_size = 2048
|
||||||
max_thumbnail_dimension = 160
|
max_thumbnail_dimension = 160
|
||||||
httpuploadurls = {}
|
httpuploadurls = {}
|
||||||
|
|
||||||
|
class FileInfo():
|
||||||
|
pass
|
||||||
|
|
||||||
class HttpuploadPlugin(GajimPlugin):
|
class HttpuploadPlugin(GajimPlugin):
|
||||||
|
|
||||||
|
@ -112,7 +113,7 @@ class HttpuploadPlugin(GajimPlugin):
|
||||||
|
|
||||||
def handle_agent_info_received(self, event):
|
def handle_agent_info_received(self, event):
|
||||||
global jid_to_servers
|
global jid_to_servers
|
||||||
if NS_HTTPUPLOAD in event.features and gajim.jid_is_transport(event.jid):
|
if NS_FILETRANSFER_HTTP in event.features and gajim.jid_is_transport(event.jid):
|
||||||
own_jid = gajim.get_jid_without_resource(str(event.stanza.getTo()))
|
own_jid = gajim.get_jid_without_resource(str(event.stanza.getTo()))
|
||||||
jid_to_servers[own_jid] = event.jid # map own jid to upload component's jid
|
jid_to_servers[own_jid] = event.jid # map own jid to upload component's jid
|
||||||
log.info(own_jid + " can do http uploads via component " + event.jid)
|
log.info(own_jid + " can do http uploads via component " + event.jid)
|
||||||
|
@ -130,6 +131,20 @@ class HttpuploadPlugin(GajimPlugin):
|
||||||
if url in httpuploadurls:
|
if url in httpuploadurls:
|
||||||
# httpupload Hint
|
# httpupload Hint
|
||||||
event.msg_iq.addChild('httpupload', namespace=NS_HINTS)
|
event.msg_iq.addChild('httpupload', namespace=NS_HINTS)
|
||||||
|
fileInfo = httpuploadurls[url]
|
||||||
|
fileInfoNode = event.msg_iq.addChild('file-info', namespace=NS_FILETRANSFER_HTTP)
|
||||||
|
filename = fileInfoNode.addChild(
|
||||||
|
name='filename',
|
||||||
|
)
|
||||||
|
filename.addData(fileInfo.filename)
|
||||||
|
size = fileInfoNode.addChild(
|
||||||
|
name='size',
|
||||||
|
)
|
||||||
|
size.addData(fileInfo.filesize)
|
||||||
|
content_type = fileInfoNode.addChild(
|
||||||
|
name='content-type',
|
||||||
|
)
|
||||||
|
content_type.addData(fileInfo.mimeType)
|
||||||
del httpuploadurls[url]
|
del httpuploadurls[url]
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log.error(e)
|
log.error(e)
|
||||||
|
@ -353,6 +368,12 @@ class Base(object):
|
||||||
log.info("Detected MIME Type of file: " + str(mime_type))
|
log.info("Detected MIME Type of file: " + str(mime_type))
|
||||||
progress_messages = Queue(8)
|
progress_messages = Queue(8)
|
||||||
progress_window = ProgressWindow(_('HTTP Upload'), _('Requesting HTTP Upload Slot...'), progress_messages, self.plugin)
|
progress_window = ProgressWindow(_('HTTP Upload'), _('Requesting HTTP Upload Slot...'), progress_messages, self.plugin)
|
||||||
|
|
||||||
|
fileInfo = FileInfo()
|
||||||
|
fileInfo.filename = os.path.basename(path_to_file)
|
||||||
|
fileInfo.filesize = filesize
|
||||||
|
fileInfo.mimeType = mime_type
|
||||||
|
|
||||||
def upload_file(stanza):
|
def upload_file(stanza):
|
||||||
slot = stanza.getTag("slot")
|
slot = stanza.getTag("slot")
|
||||||
if not slot:
|
if not slot:
|
||||||
|
@ -478,7 +499,7 @@ class Base(object):
|
||||||
else:
|
else:
|
||||||
global httpuploadurls
|
global httpuploadurls
|
||||||
url = get.getData()
|
url = get.getData()
|
||||||
httpuploadurls[url] = True
|
httpuploadurls[url] = fileInfo
|
||||||
self.chat_control.send_message(message=url, xhtml=xhtml)
|
self.chat_control.send_message(message=url, xhtml=xhtml)
|
||||||
self.chat_control.msg_textview.grab_focus()
|
self.chat_control.msg_textview.grab_focus()
|
||||||
else:
|
else:
|
||||||
|
@ -534,20 +555,20 @@ class Base(object):
|
||||||
iq.setID(id_)
|
iq.setID(id_)
|
||||||
request = iq.addChild(
|
request = iq.addChild(
|
||||||
name="request",
|
name="request",
|
||||||
namespace=NS_HTTPUPLOAD
|
namespace=NS_FILETRANSFER_HTTP
|
||||||
)
|
)
|
||||||
filename = request.addChild(
|
filename = request.addChild(
|
||||||
name="filename",
|
name="filename",
|
||||||
)
|
)
|
||||||
filename.addData(os.path.basename(path_to_file))
|
filename.addData(fileInfo.filename)
|
||||||
size = request.addChild(
|
size = request.addChild(
|
||||||
name="size",
|
name="size",
|
||||||
)
|
)
|
||||||
size.addData(filesize)
|
size.addData(fileInfo.filesize)
|
||||||
content_type = request.addChild(
|
content_type = request.addChild(
|
||||||
name="content-type",
|
name="content-type",
|
||||||
)
|
)
|
||||||
content_type.addData(mime_type)
|
content_type.addData(fileInfo.mimeType)
|
||||||
request.setAttr("recipient", self.chat_control.contact.jid)
|
request.setAttr("recipient", self.chat_control.contact.jid)
|
||||||
|
|
||||||
# send slot request and register callback
|
# send slot request and register callback
|
||||||
|
|
Loading…
Add table
Reference in a new issue