summary refs log tree commit diff
path: root/src/timeline
diff options
context:
space:
mode:
authorThulinma <jaron@vietors.com>2021-09-28 01:42:35 +0200
committerThulinma <jaron@vietors.com>2021-09-28 01:42:35 +0200
commit94441e68fde86977a70d60c735b1363c8b61ba08 (patch)
treea9db889c6b1c4f6be2b1261af2023c6f64d381aa /src/timeline
parentFixes for pasting images, especially under windows where the image mime type ... (diff)
downloadnheko-94441e68fde86977a70d60c735b1363c8b61ba08.tar.xz
Support pasting image/svg+xml format straight from supporting applications
Diffstat (limited to 'src/timeline')
-rw-r--r--src/timeline/InputBar.cpp15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/timeline/InputBar.cpp b/src/timeline/InputBar.cpp
index c83bb19c..f518248b 100644
--- a/src/timeline/InputBar.cpp
+++ b/src/timeline/InputBar.cpp
@@ -68,7 +68,11 @@ InputBar::insertMimeData(const QMimeData *md)
     const auto video   = formats.filter("video/", Qt::CaseInsensitive);
 
     if (md->hasImage()) {
-        showPreview(*md, "", image);
+        if (formats.contains("image/svg+xml", Qt::CaseInsensitive)) {
+            showPreview(*md, "", QStringList("image/svg+xml"));
+        } else {
+            showPreview(*md, "", image);
+        }
     } else if (!audio.empty()) {
         showPreview(*md, "", audio);
     } else if (!video.empty()) {
@@ -651,7 +655,8 @@ InputBar::showPreview(const QMimeData &source, QString path, const QStringList &
       new dialogs::PreviewUploadOverlay(ChatPage::instance());
     previewDialog_->setAttribute(Qt::WA_DeleteOnClose);
 
-    if (source.hasImage()) {
+    // Force SVG to _not_ be handled as an image, but as raw data
+    if (source.hasImage() && (!formats.size() || formats.front() != "image/svg+xml")) {
         if (formats.size() && formats.front().startsWith("image/")) {
             // known format, keep as-is
             previewDialog_->setPreview(qvariant_cast<QImage>(source.imageData()), formats.front());
@@ -679,6 +684,12 @@ InputBar::showPreview(const QMimeData &source, QString path, const QStringList &
       &dialogs::PreviewUploadOverlay::confirmUpload,
       this,
       [this](const QByteArray data, const QString &mime, const QString &fn) {
+          if (!data.size()) {
+              nhlog::ui()->warn("Attempted to upload zero-byte file?! Mimetype {}, filename {}",
+                                mime.toStdString(),
+                                fn.toStdString());
+              return;
+          }
           setUploading(true);
 
           setText("");