diff options
| author | Andrew Branson <andrew.branson@jolla.com> | 2026-02-10 10:41:02 +0100 |
|---|---|---|
| committer | Andrew Branson <andrew.branson@jolla.com> | 2026-02-10 17:09:39 +0100 |
| commit | 4351f4627ba9e71775438dd26c9acddd002c7e11 (patch) | |
| tree | 3c72c980c5c81507109087bda67052b7ec8216b6 /transferengine-plugins/mastodontransferplugin/mastodonapi.h | |
Initial commit
Diffstat (limited to 'transferengine-plugins/mastodontransferplugin/mastodonapi.h')
| -rw-r--r-- | transferengine-plugins/mastodontransferplugin/mastodonapi.h | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/transferengine-plugins/mastodontransferplugin/mastodonapi.h b/transferengine-plugins/mastodontransferplugin/mastodonapi.h new file mode 100644 index 0000000..0ec3653 --- /dev/null +++ b/transferengine-plugins/mastodontransferplugin/mastodonapi.h @@ -0,0 +1,56 @@ +#ifndef MASTODONAPI_H +#define MASTODONAPI_H + +#include <QtCore/QMap> +#include <QtCore/QObject> + +#include <QtNetwork/QNetworkAccessManager> +#include <QtNetwork/QNetworkReply> + +class MastodonApi : public QObject +{ + Q_OBJECT + +public: + enum API_CALL { + NONE, + UPLOAD_MEDIA, + POST_STATUS + }; + + explicit MastodonApi(QNetworkAccessManager *qnam, QObject *parent = 0); + ~MastodonApi(); + + bool uploadImage(const QString &filePath, + const QString &statusText, + const QString &mimeType, + const QString &apiHost, + const QString &accessToken); + + void cancelUpload(); + +Q_SIGNALS: + void transferProgressUpdated(qreal progress); + void transferFinished(); + void transferError(); + void transferCanceled(); + void credentialsExpired(); + +private Q_SLOTS: + void replyError(QNetworkReply::NetworkError error); + void finished(); + void uploadProgress(qint64 received, qint64 total); + +private: + static QString normalizeApiHost(const QString &rawHost); + bool postStatus(const QString &mediaId); + void finishTransfer(QNetworkReply::NetworkError error, int httpCode, const QByteArray &data); + + QMap<QNetworkReply*, API_CALL> m_replies; + QNetworkAccessManager *m_qnam; + QString m_accessToken; + QString m_apiHost; + QString m_statusText; +}; + +#endif // MASTODONAPI_H |
