From cd9d1a2ec69bf4c459f9e845293d5fd7dc1398d4 Mon Sep 17 00:00:00 2001 From: christarazi Date: Sun, 18 Feb 2018 12:52:31 -0800 Subject: 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 --- include/TextInputWidget.h | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'include/TextInputWidget.h') diff --git a/include/TextInputWidget.h b/include/TextInputWidget.h index 6d28009e..b89b7753 100644 --- a/include/TextInputWidget.h +++ b/include/TextInputWidget.h @@ -27,12 +27,12 @@ #include "FlatButton.h" #include "LoadingIndicator.h" -#include "dialogs/PreviewImageOverlay.h" +#include "dialogs/PreviewUploadOverlay.h" #include "emoji/PickButton.h" namespace dialogs { -class PreviewImageOverlay; +class PreviewUploadOverlay; } class FilteredTextEdit : public QTextEdit @@ -53,9 +53,13 @@ signals: void heightChanged(int height); void startedTyping(); void stoppedTyping(); + void startedUpload(); void message(QString); void command(QString name, QString args); - void image(const QSharedPointer iodev, const QString &img_name); + void image(QSharedPointer data, const QString &filename); + void audio(QSharedPointer data, const QString &filename); + void video(QSharedPointer data, const QString &filename); + void file(QSharedPointer data, const QString &filename); protected: void keyPressEvent(QKeyEvent *event) override; @@ -67,11 +71,12 @@ private: size_t history_index_; QTimer *typingTimer_; - dialogs::PreviewImageOverlay previewDialog_; + dialogs::PreviewUploadOverlay previewDialog_; void textChanged(); - void receiveImage(const QByteArray img, const QString &img_name); + void uploadData(const QByteArray data, const QString &media, const QString &filename); void afterCompletion(int); + void showPreview(const QMimeData *source, const QStringList &formats); }; class TextInputWidget : public QWidget @@ -95,9 +100,10 @@ signals: void sendTextMessage(QString msg); void sendEmoteMessage(QString msg); - void uploadImage(QSharedPointer data, const QString &filename); - void uploadFile(QSharedPointer data, const QString &filename); - void uploadAudio(QSharedPointer data, const QString &filename); + void uploadImage(const QSharedPointer data, const QString &filename); + void uploadFile(const QSharedPointer data, const QString &filename); + void uploadAudio(const QSharedPointer data, const QString &filename); + void uploadVideo(const QSharedPointer data, const QString &filename); void sendJoinRoomRequest(const QString &room); -- cgit 1.5.1