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

@ -28,28 +28,32 @@ class QMimeData;
namespace dialogs {
class PreviewImageOverlay : public QWidget
class PreviewUploadOverlay : public QWidget
{
Q_OBJECT
public:
PreviewImageOverlay(QWidget *parent = nullptr);
PreviewUploadOverlay(QWidget *parent = nullptr);
void setImageAndCreate(const QByteArray data, const QString &type);
void setImageAndCreate(const QString &path);
void setPreview(const QByteArray data, const QString &mime);
void setPreview(const QString &path);
signals:
void confirmImageUpload(const QByteArray data, const QString &img_name);
void confirmUpload(const QByteArray data, const QString &media, const QString &filename);
private:
void init();
void setLabels(const QString &type, const QString &mime, const int upload_size);
bool isImage_;
QPixmap image_;
QByteArray imageData_;
QString imagePath_;
QByteArray data_;
QString filePath_;
QString mediaType_;
QLabel titleLabel_;
QLabel imageLabel_;
QLineEdit imageName_;
QLabel infoLabel_;
QLineEdit fileName_;
FlatButton upload_;
FlatButton cancel_;