QXmpp Version: 1.5.6
Loading...
Searching...
No Matches
Public Member Functions | List of all members
QXmppHttpUploadManager Class Reference
Inheritance diagram for QXmppHttpUploadManager:
Inheritance graph
[legend]
Collaboration diagram for QXmppHttpUploadManager:
Collaboration graph
[legend]

Public Member Functions

 QXmppHttpUploadManager ()
 
 QXmppHttpUploadManager (QNetworkAccessManager *netManager)
 
std::shared_ptr< QXmppHttpUploaduploadFile (std::unique_ptr< QIODevice > data, const QString &filename, const QMimeType &mimeType, qint64 fileSize=-1, const QString &uploadServiceJid={})
 
std::shared_ptr< QXmppHttpUploaduploadFile (const QFileInfo &fileInfo, const QString &filename={}, const QString &uploadServiceJid={})
 
- Public Member Functions inherited from QXmppClientExtension
 QXmppClientExtension ()
 
virtual QStringList discoveryFeatures () const
 
virtual QList< QXmppDiscoveryIq::IdentitydiscoveryIdentities () const
 
virtual bool handleStanza (const QDomElement &stanza)
 You need to implement this method to process incoming XMPP stanzas.
 
virtual bool handleStanza (const QDomElement &stanza, const std::optional< QXmppE2eeMetadata > &e2eeMetadata)
 You need to implement this method to process incoming XMPP stanzas.
 
- Public Member Functions inherited from QXmppLoggable
 QXmppLoggable (QObject *parent=nullptr)
 

Additional Inherited Members

- Signals inherited from QXmppLoggable
void setGauge (const QString &gauge, double value)
 Sets the given gauge to value.
 
void logMessage (QXmppLogger::MessageType type, const QString &msg)
 This signal is emitted to send logging messages.
 
void updateCounter (const QString &counter, qint64 amount=1)
 Updates the given counter by amount.
 
- Protected Member Functions inherited from QXmppClientExtension
QXmppClientclient ()
 
virtual void setClient (QXmppClient *client)
 
void injectIq (const QDomElement &element, const std::optional< QXmppE2eeMetadata > &e2eeMetadata)
 
bool injectMessage (QXmppMessage &&message)
 
- Protected Member Functions inherited from QXmppLoggable
void debug (const QString &message)
 
void info (const QString &message)
 
void warning (const QString &message)
 
void logReceived (const QString &message)
 
void logSent (const QString &message)
 

Detailed Description

The upload manager allows to upload a file to a server via XEP-0363: HTTP File Upload. This can be used for sending files to other users.

QXmppHttpUploadManager depends on QXmppUploadRequestManager. You can enable them using

QXmppClient * client()
Definition QXmppClientExtension.cpp:78
T * addNewExtension(Args... args)
Definition QXmppClient.h:129
Definition QXmppHttpUploadManager.h:54
The QXmppUploadRequestManager implements the core of XEP-0369: HTTP File Upload.
Definition QXmppUploadRequestManager.h:85
Since
QXmpp 1.5

Constructor & Destructor Documentation

◆ QXmppHttpUploadManager() [1/2]

QXmppHttpUploadManager::QXmppHttpUploadManager ( )

Constructor

Creates and uses a new network access manager.

◆ QXmppHttpUploadManager() [2/2]

QXmppHttpUploadManager::QXmppHttpUploadManager ( QNetworkAccessManager *  netManager)
explicit

Constructor

Parameters
netManagershared network access manager, needs to have at least the lifetime of this manager.

Member Function Documentation

◆ uploadFile() [1/2]

std::shared_ptr< QXmppHttpUpload > QXmppHttpUploadManager::uploadFile ( const QFileInfo &  fileInfo,
const QString &  filename = {},
const QString &  uploadServiceJid = {} 
)

Upload data from a local file.

Parameters
fileInfoQFileInfo about a local file
filenamefilename How the file on the server should be called. This is commonly used as last part of the resulting url.
uploadServiceJidoptionally, the jid from which an upload url can be requested (upload service)
Returns
an object representing the ongoing upload. The object is passed as a shared_ptr, which means it will be stored as long as there is a reference to it. While this avoids errors from accessing it after it was deleted, you should try not store it unneccesarily long to keep the memory usage down. You can for example use std::weak_ptr to not increase the lifetime, for example when capturing in long living lambdas, for example in connects. You should also make sure to use the 4-arg QObject::connect, so the connection and the connected lambda can be deleted after the upload finished.
std::weak_ptr<QXmppHttpUpload> uploadPtr = upload;
connect(upload.get(), &QXmppHttpUpload::progressChanged, this, [uploadPtr]() {
auto upload = uploadPtr.lock();
if (upload) {
qDebug() << upload->progress();
}
});
Q_SIGNAL void progressChanged()

◆ uploadFile() [2/2]

std::shared_ptr< QXmppHttpUpload > QXmppHttpUploadManager::uploadFile ( std::unique_ptr< QIODevice >  data,
const QString &  filename,
const QMimeType &  mimeType,
qint64  fileSize = -1,
const QString &  uploadServiceJid = {} 
)

Uploads the data from a QIODevice.

Parameters
dataQIODevice to read the data from. This can for example be a QFile. It can be sequential or non-sequential.
filenameHow the file on the server should be called. This is commonly used as last part of the resulting url.
fileSizeThe size of the file, in byte. If negative the size from the IO device is used.
mimeTypeThe mime type of the file
uploadServiceJidoptionally, the jid from which an upload url can be requested (upload service)
Returns
an object representing the ongoing upload. The object is passed as a shared_ptr, which means it will be stored as long as there is a reference to it. While this avoids errors from accessing it after it was deleted, you should try not store it unneccesarily long to keep the memory usage down. You can for example use std::weak_ptr to not increase the lifetime, for example when capturing in long living lambdas, for example in connects. You should also make sure to use the 4-arg QObject::connect, so the connection and the connected lambda can be deleted after the upload finished.
std::weak_ptr<QXmppHttpUpload> uploadPtr = upload;
connect(upload.get(), &QXmppHttpUpload::progressChanged, this, [uploadPtr]() {
auto upload = uploadPtr.lock();
if (upload) {
qDebug() << upload->progress();
}
});

The documentation for this class was generated from the following files: