Verified Commit 07b87757 authored by Linus Jahn's avatar Linus Jahn Committed by Linus Jahn
Browse files

Send HTTP file upload get Url after uploading

For now this will just send the link into a normal message. This way it is even
already interpreted and displayed as a file (or image) in some clients (but not
in Kaidan :P).
parent dacf240c
......@@ -121,7 +121,7 @@ void ClientThread::run()
vCardManager = new VCardManager(client, avatarStorage, rosterModel);
rosterManager = new RosterManager(kaidan, client, rosterModel, vCardManager);
presenceHandler = new PresenceHandler(client, presenceCache);
uploadHandler = new UploadHandler(client);
uploadHandler = new UploadHandler(client, messageSessionHandler->getMessageHandler());
serviceDiscoveryManager = new ServiceDiscoveryManager(
client, client->disco(), uploadHandler->getUploadManager()
);
......
......@@ -30,7 +30,9 @@
#include "UploadHandler.h"
#include "QtHttpUploader.h"
#include "MessageHandler.h"
// gloox
#include <gloox/message.h>
#include "gloox-extensions/httpuploadmanager.h"
#include "gloox-extensions/reference.h"
#include "gloox-extensions/sims.h"
......@@ -41,8 +43,9 @@
#include <QMimeDatabase>
#include <QDebug>
UploadHandler::UploadHandler(gloox::Client *client, QObject *parent)
: QObject(parent), client(client)
UploadHandler::UploadHandler(gloox::Client *client, MessageHandler *msgHandler,
QObject *parent)
: QObject(parent), client(client), msgHandler(msgHandler)
{
manager = new gloox::HttpUploadManager(client);
uploader = new QtHttpUploader(manager);
......@@ -58,6 +61,17 @@ void UploadHandler::uploadFile(QString jid, QString filePath)
int id = manager->uploadFile(filePath.toStdString(), true,
contentType.toStdString());
if (id < 0) {
// failure
// TODO: send passive notification
} else {
// save for later processing/sending
MediaSharingMeta meta;
meta.jid = jid;
mediaShares[id] = meta;
}
}
void UploadHandler::handleUploadFailed(int id, gloox::HttpUploadError error,
......@@ -74,6 +88,11 @@ void UploadHandler::handleUploadFinished(int id, std::string &name,
{
qDebug() << "[client] A file upload has finished.";
// TODO: send SIMS message (and optionally also create jingle object)
// for now only send a normal text message with the get URL.
msgHandler->sendMessage(mediaShares[id].jid, QString::fromStdString(getUrl));
// the media meta isn't needed anymore, so delete it
mediaShares.remove(id);
}
void UploadHandler::handleUploadProcess(int id, long unsigned int sent,
......
......@@ -42,6 +42,7 @@ namespace gloox {
class Client;
}
class MessageHandler;
class QtHttpUploader;
/**
......@@ -55,7 +56,8 @@ public:
/**
* Default constructor
*/
UploadHandler(gloox::Client *client, QObject *parent = nullptr);
UploadHandler(gloox::Client *client, MessageHandler *msgHandler,
QObject *parent = nullptr);
gloox::HttpUploadManager* getUploadManager()
{
......@@ -126,11 +128,16 @@ protected:
const std::string &stamp = gloox::EmptyString);
private:
struct MediaSharingMeta {
QString jid;
};
gloox::Client *client;
gloox::HttpUploadManager *manager;
MessageHandler* msgHandler;
QtHttpUploader *uploader;
QMap<int, std::string> filePaths;
QMap<int, MediaSharingMeta> mediaShares;
};
#endif // UPLOADHANDLER_H
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment