summary refs log tree commit diff
path: root/include/timeline/TimelineView.h
diff options
context:
space:
mode:
authorchristarazi <christarazi@users.noreply.github.com>2018-02-18 12:52:31 -0800
committermujx <mujx@users.noreply.github.com>2018-02-18 22:52:31 +0200
commitcd9d1a2ec69bf4c459f9e845293d5fd7dc1398d4 (patch)
treea3669f25c8ecaf716061b3080ae9f9073134da05 /include/timeline/TimelineView.h
parentShow loading indicator while waiting for /login & /logout (diff)
downloadnheko-cd9d1a2ec69bf4c459f9e845293d5fd7dc1398d4.tar.xz
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 
Diffstat (limited to 'include/timeline/TimelineView.h')
-rw-r--r--include/timeline/TimelineView.h22
1 files changed, 15 insertions, 7 deletions
diff --git a/include/timeline/TimelineView.h b/include/timeline/TimelineView.h

index 6e1287c8..782f3afd 100644 --- a/include/timeline/TimelineView.h +++ b/include/timeline/TimelineView.h
@@ -44,6 +44,8 @@ struct PendingMessage int txn_id; QString body; QString filename; + QString mime; + int64_t media_size; QString event_id; TimelineItem *widget; @@ -51,12 +53,16 @@ struct PendingMessage int txn_id, QString body, QString filename, + QString mime, + int64_t media_size, QString event_id, TimelineItem *widget) : ty(ty) , txn_id(txn_id) , body(body) , filename(filename) + , mime(mime) + , media_size(media_size) , event_id(event_id) , widget(widget) {} @@ -87,10 +93,10 @@ public: void addUserMessage(mtx::events::MessageType ty, const QString &msg); template<class Widget, mtx::events::MessageType MsgType> - void addUserMessage( - const QString &url, - const QString &filename, - const QSharedPointer<QIODevice> data = QSharedPointer<QIODevice>(nullptr)); + void addUserMessage(const QString &url, + const QString &filename, + const QString &mime, + const int64_t size); void updatePendingMessage(int txn_id, QString event_id); void scrollDown(); QLabel *createDateSeparator(QDateTime datetime); @@ -236,11 +242,13 @@ template<class Widget, mtx::events::MessageType MsgType> void TimelineView::addUserMessage(const QString &url, const QString &filename, - const QSharedPointer<QIODevice> data) + const QString &mime, + const int64_t size) { auto with_sender = lastSender_ != local_user_; + auto trimmed = QFileInfo{filename}.fileName(); // Trim file path. - auto widget = new Widget(client_, url, data, filename, this); + auto widget = new Widget(client_, url, trimmed, size, this); TimelineItem *view_item = new TimelineItem(widget, local_user_, with_sender, scroll_widget_); @@ -255,7 +263,7 @@ TimelineView::addUserMessage(const QString &url, int txn_id = client_->incrementTransactionId(); - PendingMessage message(MsgType, txn_id, url, filename, "", view_item); + PendingMessage message(MsgType, txn_id, url, trimmed, mime, size, "", view_item); handleNewUserMessage(message); }