Support audio, video, generic file for pasting (#220)

* Refactor widget items to use same interface

* Support audio, video, generic file for pasting

* Add utils function for human readable file sizes

* Set correct MIME type for media messages

This change also determines the size of the upload once from the
ContentLengthHeader, rather than seeking the QIODevice and asking for
its size. This prevents any future trouble in case the QIODevice is
sequential (cannot be seeked). The MIME type is also determined at
upload once, rather than using the QIODevice and the underlying data
inside.

* Allow for file urls to be used as fall-back

This fixes an issue on macOS which uses `text/uri-list` for copying
files to the clipboard.

fixes #228
This commit is contained in:
christarazi 2018-02-18 12:52:31 -08:00 committed by mujx
parent c8bfb02211
commit cd9d1a2ec6
25 changed files with 552 additions and 399 deletions

View file

@ -48,8 +48,8 @@ public:
AudioItem(QSharedPointer<MatrixClient> client,
const QString &url,
const QSharedPointer<QIODevice> data,
const QString &filename,
const int64_t size,
QWidget *parent = nullptr);
QSize sizeHint() const override;
@ -76,7 +76,6 @@ private slots:
void fileDownloaded(const QString &event_id, const QByteArray &data);
private:
QString calculateFileSize(int nbytes) const;
void init();
enum class AudioState

View file

@ -42,8 +42,8 @@ public:
FileItem(QSharedPointer<MatrixClient> client,
const QString &url,
const QSharedPointer<QIODevice> data,
const QString &filename,
const int64_t size,
QWidget *parent = nullptr);
QSize sizeHint() const override;
@ -64,7 +64,6 @@ private slots:
void fileDownloaded(const QString &event_id, const QByteArray &data);
private:
QString calculateFileSize(int nbytes) const;
void openUrl();
void init();

View file

@ -36,8 +36,8 @@ public:
ImageItem(QSharedPointer<MatrixClient> client,
const QString &url,
const QSharedPointer<QIODevice> data,
const QString &filename,
const int64_t size,
QWidget *parent = nullptr);
void setImage(const QPixmap &image);

View file

@ -37,13 +37,12 @@ public:
VideoItem(QSharedPointer<MatrixClient> client,
const QString &url,
const QSharedPointer<QIODevice> data,
const QString &filename,
const int64_t size,
QWidget *parent = nullptr);
private:
void init();
QString calculateFileSize(int nbytes) const;
QUrl url_;
QString text_;