summary refs log tree commit diff
path: root/src/timeline
diff options
context:
space:
mode:
Diffstat (limited to 'src/timeline')
-rw-r--r--src/timeline/TimelineView.cc8
-rw-r--r--src/timeline/TimelineViewManager.cc7
-rw-r--r--src/timeline/widgets/AudioItem.cc6
-rw-r--r--src/timeline/widgets/FileItem.cc6
-rw-r--r--src/timeline/widgets/ImageItem.cc17
-rw-r--r--src/timeline/widgets/VideoItem.cc2
6 files changed, 31 insertions, 15 deletions
diff --git a/src/timeline/TimelineView.cc b/src/timeline/TimelineView.cc
index d21f30f0..75ce8141 100644
--- a/src/timeline/TimelineView.cc
+++ b/src/timeline/TimelineView.cc
@@ -510,12 +510,8 @@ TimelineView::sendNextPendingMessage()
         case mtx::events::MessageType::Image:
         case mtx::events::MessageType::File:
                 // FIXME: Improve the API
-                client_->sendRoomMessage(m.ty,
-                                         m.txn_id,
-                                         room_id_,
-                                         QFileInfo(m.filename).fileName(),
-                                         QFileInfo(m.filename),
-                                         m.body);
+                client_->sendRoomMessage(
+                  m.ty, m.txn_id, room_id_, m.filename, QFileInfo(m.filename), m.body);
                 break;
         default:
                 client_->sendRoomMessage(m.ty, m.txn_id, room_id_, m.body, QFileInfo());
diff --git a/src/timeline/TimelineViewManager.cc b/src/timeline/TimelineViewManager.cc
index de1e1e32..65c9ac83 100644
--- a/src/timeline/TimelineViewManager.cc
+++ b/src/timeline/TimelineViewManager.cc
@@ -85,6 +85,7 @@ TimelineViewManager::queueEmoteMessage(const QString &msg)
 
 void
 TimelineViewManager::queueImageMessage(const QString &roomid,
+                                       const QSharedPointer<QIODevice> data,
                                        const QString &filename,
                                        const QString &url)
 {
@@ -95,7 +96,7 @@ TimelineViewManager::queueImageMessage(const QString &roomid,
 
         auto view = views_[roomid];
 
-        view->addUserMessage<ImageItem, mtx::events::MessageType::Image>(url, filename);
+        view->addUserMessage<ImageItem, mtx::events::MessageType::Image>(url, data, filename);
 }
 
 void
@@ -110,7 +111,7 @@ TimelineViewManager::queueFileMessage(const QString &roomid,
 
         auto view = views_[roomid];
 
-        view->addUserMessage<FileItem, mtx::events::MessageType::File>(url, filename);
+        view->addUserMessage<FileItem, mtx::events::MessageType::File>(url, nullptr, filename);
 }
 
 void
@@ -125,7 +126,7 @@ TimelineViewManager::queueAudioMessage(const QString &roomid,
 
         auto view = views_[roomid];
 
-        view->addUserMessage<AudioItem, mtx::events::MessageType::Audio>(url, filename);
+        view->addUserMessage<AudioItem, mtx::events::MessageType::Audio>(url, nullptr, filename);
 }
 
 void
diff --git a/src/timeline/widgets/AudioItem.cc b/src/timeline/widgets/AudioItem.cc
index 5d9dd77b..e84cbb3a 100644
--- a/src/timeline/widgets/AudioItem.cc
+++ b/src/timeline/widgets/AudioItem.cc
@@ -89,14 +89,16 @@ AudioItem::AudioItem(QSharedPointer<MatrixClient> client,
 
 AudioItem::AudioItem(QSharedPointer<MatrixClient> client,
                      const QString &url,
+                     const QSharedPointer<QIODevice> data,
                      const QString &filename,
                      QWidget *parent)
   : QWidget(parent)
   , url_{url}
-  , text_{QFileInfo(filename).fileName()}
+  , text_{QFileInfo{filename}.fileName()}
   , client_{client}
 {
-        readableFileSize_ = calculateFileSize(QFileInfo(filename).size());
+        Q_UNUSED(data);
+        readableFileSize_ = calculateFileSize(QFileInfo{filename}.size());
 
         init();
 }
diff --git a/src/timeline/widgets/FileItem.cc b/src/timeline/widgets/FileItem.cc
index 3c38dc31..a6159309 100644
--- a/src/timeline/widgets/FileItem.cc
+++ b/src/timeline/widgets/FileItem.cc
@@ -76,14 +76,16 @@ FileItem::FileItem(QSharedPointer<MatrixClient> client,
 
 FileItem::FileItem(QSharedPointer<MatrixClient> client,
                    const QString &url,
+                   const QSharedPointer<QIODevice> data,
                    const QString &filename,
                    QWidget *parent)
   : QWidget(parent)
   , url_{url}
-  , text_{QFileInfo(filename).fileName()}
+  , text_{QFileInfo{filename}.fileName()}
   , client_{client}
 {
-        readableFileSize_ = calculateFileSize(QFileInfo(filename).size());
+        Q_UNUSED(data);
+        readableFileSize_ = calculateFileSize(QFileInfo{filename}.size());
 
         init();
 }
diff --git a/src/timeline/widgets/ImageItem.cc b/src/timeline/widgets/ImageItem.cc
index 9038456d..48a4c1eb 100644
--- a/src/timeline/widgets/ImageItem.cc
+++ b/src/timeline/widgets/ImageItem.cc
@@ -61,11 +61,12 @@ ImageItem::ImageItem(QSharedPointer<MatrixClient> client,
 
 ImageItem::ImageItem(QSharedPointer<MatrixClient> client,
                      const QString &url,
+                     const QSharedPointer<QIODevice> data,
                      const QString &filename,
                      QWidget *parent)
   : QWidget(parent)
   , url_{url}
-  , text_{QFileInfo(filename).fileName()}
+  , text_{filename}
   , client_{client}
 {
         setMouseTracking(true);
@@ -83,7 +84,19 @@ ImageItem::ImageItem(QSharedPointer<MatrixClient> client,
         url_                 = QString("%1/_matrix/media/r0/download/%2")
                  .arg(client_.data()->getHomeServer().toString(), media_params);
 
-        setImage(QPixmap(filename));
+        if (data.isNull()) {
+                qWarning() << "No image data to display";
+                return;
+        }
+
+        if (data->reset()) {
+                QPixmap p;
+                p.loadFromData(data->readAll());
+                setImage(p);
+        } else {
+                qWarning() << "Failed to seek to beginning of device:" << data->errorString();
+                return;
+        }
 }
 
 void
diff --git a/src/timeline/widgets/VideoItem.cc b/src/timeline/widgets/VideoItem.cc
index b3987b83..b46dff7b 100644
--- a/src/timeline/widgets/VideoItem.cc
+++ b/src/timeline/widgets/VideoItem.cc
@@ -66,6 +66,7 @@ VideoItem::VideoItem(QSharedPointer<MatrixClient> client,
 
 VideoItem::VideoItem(QSharedPointer<MatrixClient> client,
                      const QString &url,
+                     const QSharedPointer<QIODevice> data,
                      const QString &filename,
                      QWidget *parent)
   : QWidget(parent)
@@ -73,6 +74,7 @@ VideoItem::VideoItem(QSharedPointer<MatrixClient> client,
   , text_{QFileInfo(filename).fileName()}
   , client_{client}
 {
+        Q_UNUSED(data);
         readableFileSize_ = calculateFileSize(QFileInfo(filename).size());
 
         init();