summary refs log tree commit diff
path: root/src/timeline
diff options
context:
space:
mode:
authorNicolas Werner <nicolas.werner@hotmail.de>2023-06-02 00:24:26 +0200
committerNicolas Werner <nicolas.werner@hotmail.de>2023-06-08 22:32:07 +0200
commitb518f6902e909b22e1623f96249a3ab1424ced59 (patch)
tree97fe4bdf0f2ffb1e35904c1d2111c6e566984d7c /src/timeline
parentSelect Qt6 in cmake (diff)
downloadnheko-b518f6902e909b22e1623f96249a3ab1424ced59.tar.xz
Make Nheko compile on Qt6
Diffstat (limited to 'src/timeline')
-rw-r--r--src/timeline/CommunitiesModel.cpp3
-rw-r--r--src/timeline/DelegateChooser.cpp4
-rw-r--r--src/timeline/DelegateChooser.h4
-rw-r--r--src/timeline/EventStore.cpp14
-rw-r--r--src/timeline/EventStore.h9
-rw-r--r--src/timeline/InputBar.cpp86
-rw-r--r--src/timeline/InputBar.h20
-rw-r--r--src/timeline/RoomlistModel.cpp3
-rw-r--r--src/timeline/TimelineModel.cpp1
-rw-r--r--src/timeline/TimelineModel.h4
-rw-r--r--src/timeline/TimelineViewManager.cpp2
-rw-r--r--src/timeline/TimelineViewManager.h8
12 files changed, 36 insertions, 122 deletions
diff --git a/src/timeline/CommunitiesModel.cpp b/src/timeline/CommunitiesModel.cpp

index c563639b..dc09a95e 100644 --- a/src/timeline/CommunitiesModel.cpp +++ b/src/timeline/CommunitiesModel.cpp
@@ -17,15 +17,12 @@ #include "Utils.h" #include "timeline/TimelineModel.h" -Q_DECLARE_METATYPE(SpaceItem) CommunitiesModel::CommunitiesModel(QObject *parent) : QAbstractListModel(parent) , hiddenTagIds_{UserSettings::instance()->hiddenTags()} , mutedTagIds_{UserSettings::instance()->mutedTags()} { - static auto ignore = qRegisterMetaType<SpaceItem>(); - (void)ignore; } QHash<int, QByteArray> diff --git a/src/timeline/DelegateChooser.cpp b/src/timeline/DelegateChooser.cpp
index 7f80d5f6..91b2194b 100644 --- a/src/timeline/DelegateChooser.cpp +++ b/src/timeline/DelegateChooser.cpp
@@ -77,13 +77,13 @@ DelegateChooser::appendChoice(QQmlListProperty<DelegateChoice> *p, DelegateChoic dc->choices_.append(c); } -int +qsizetype DelegateChooser::choiceCount(QQmlListProperty<DelegateChoice> *p) { return static_cast<DelegateChooser *>(p->object)->choices_.count(); } DelegateChoice * -DelegateChooser::choice(QQmlListProperty<DelegateChoice> *p, int index) +DelegateChooser::choice(QQmlListProperty<DelegateChoice> *p, qsizetype index) { return static_cast<DelegateChooser *>(p->object)->choices_.at(index); } diff --git a/src/timeline/DelegateChooser.h b/src/timeline/DelegateChooser.h
index 8f72e73b..c27f2c43 100644 --- a/src/timeline/DelegateChooser.h +++ b/src/timeline/DelegateChooser.h
@@ -86,7 +86,7 @@ private: DelegateIncubator incubator{*this}; static void appendChoice(QQmlListProperty<DelegateChoice> *, DelegateChoice *); - static int choiceCount(QQmlListProperty<DelegateChoice> *); - static DelegateChoice *choice(QQmlListProperty<DelegateChoice> *, int index); + static qsizetype choiceCount(QQmlListProperty<DelegateChoice> *); + static DelegateChoice *choice(QQmlListProperty<DelegateChoice> *, qsizetype index); static void clearChoices(QQmlListProperty<DelegateChoice> *); }; diff --git a/src/timeline/EventStore.cpp b/src/timeline/EventStore.cpp
index 5cdb372a..d373cf55 100644 --- a/src/timeline/EventStore.cpp +++ b/src/timeline/EventStore.cpp
@@ -15,11 +15,9 @@ #include "EventAccessors.h" #include "Logging.h" #include "MatrixClient.h" -#include "TimelineModel.h" #include "UserSettingsPage.h" #include "Utils.h" -Q_DECLARE_METATYPE(Reaction) QCache<EventStore::IdIndex, olm::DecryptionResult> EventStore::decryptedEvents_{1000}; QCache<EventStore::IdIndex, mtx::events::collections::TimelineEvents> EventStore::events_by_id_{ @@ -29,8 +27,6 @@ QCache<EventStore::Index, mtx::events::collections::TimelineEvents> EventStore:: EventStore::EventStore(std::string room_id, QObject *) : room_id_(std::move(room_id)) { - static auto reactionType = qRegisterMetaType<Reaction>(); - (void)reactionType; auto range = cache::client()->getTimelineRange(room_id_); @@ -293,12 +289,12 @@ EventStore::EventStore(std::string room_id, QObject *) } void -EventStore::addPending(mtx::events::collections::TimelineEvents event) +EventStore::addPending(const mtx::events::collections::TimelineEvents& event) { if (this->thread() != QThread::currentThread()) nhlog::db()->warn("{} called from a different thread!", __func__); - cache::client()->savePendingMessage(this->room_id_, {event}); + cache::client()->savePendingMessage(this->room_id_, event); mtx::responses::Timeline events; events.limited = false; events.events.emplace_back(event); @@ -761,11 +757,11 @@ EventStore::decryptEvent(const IdIndex &idx, } void -EventStore::refetchOnlineKeyBackupKeys(TimelineModel *room) +EventStore::refetchOnlineKeyBackupKeys() { - for (const auto &[session_id, request] : room->events.pending_key_requests) { + for (const auto &[session_id, request] : this->pending_key_requests) { (void)request; - olm::lookup_keybackup(room->events.room_id_, session_id); + olm::lookup_keybackup(this->room_id_, session_id); } } diff --git a/src/timeline/EventStore.h b/src/timeline/EventStore.h
index bf905fc6..f2f9e2d7 100644 --- a/src/timeline/EventStore.h +++ b/src/timeline/EventStore.h
@@ -14,12 +14,11 @@ #include <mtx/events/collections.hpp> #include <mtx/responses/messages.hpp> #include <mtx/responses/sync.hpp> +#include <mtx/common.hpp> #include "Reaction.h" #include "encryption/Olm.h" -class TimelineModel; - class EventStore final : public QObject { Q_OBJECT @@ -27,7 +26,7 @@ class EventStore final : public QObject public: EventStore(std::string room_id, QObject *parent); - static void refetchOnlineKeyBackupKeys(TimelineModel *room); + void refetchOnlineKeyBackupKeys(); // taken from QtPrivate::QHashCombine static uint hashCombine(uint hash, uint seed) @@ -108,7 +107,7 @@ signals: void newEncryptedImage(mtx::crypto::EncryptedFile encryptionInfo); void eventFetched(std::string id, std::string relatedTo, - mtx::events::collections::TimelineEvents timeline); + const mtx::events::collections::TimelineEvents& timeline); void oldMessagesRetrieved(const mtx::responses::Messages &); void fetchedMore(); @@ -120,7 +119,7 @@ signals: void updateFlowEventId(std::string event_id); public slots: - void addPending(mtx::events::collections::TimelineEvents event); + void addPending(const mtx::events::collections::TimelineEvents& event); void receivedSessionKey(const std::string &session_id); void clearTimeline(); void enableKeyRequests(bool suppressKeyRequests_); diff --git a/src/timeline/InputBar.cpp b/src/timeline/InputBar.cpp
index 0c2e3752..2fd2d21a 100644 --- a/src/timeline/InputBar.cpp +++ b/src/timeline/InputBar.cpp
@@ -16,6 +16,8 @@ #include <QMimeDatabase> #include <QStandardPaths> #include <QTextBoundaryFinder> +#include <QVideoFrame> +#include <QVideoSink> #include <QRegularExpression> #include <mtx/responses/common.hpp> @@ -75,55 +77,6 @@ MediaUpload::thumbnailDataUrl() const } bool -InputVideoSurface::present(const QVideoFrame &frame) -{ - QImage::Format format = QVideoFrame::imageFormatFromPixelFormat(frame.pixelFormat()); - - if (format == QImage::Format_Invalid) { - emit newImage({}); - return false; - } else { - QVideoFrame frametodraw(frame); - - if (!frametodraw.map(QAbstractVideoBuffer::ReadOnly)) { - emit newImage({}); - return false; - } - - // this is a shallow operation. it just refer the frame buffer - QImage image(qAsConst(frametodraw).bits(), - frametodraw.width(), - frametodraw.height(), - frametodraw.bytesPerLine(), - format); - image.detach(); - - frametodraw.unmap(); - - emit newImage(std::move(image)); - return true; - } -} - -QList<QVideoFrame::PixelFormat> -InputVideoSurface::supportedPixelFormats(QAbstractVideoBuffer::HandleType type) const -{ - if (type == QAbstractVideoBuffer::NoHandle) { - return { - QVideoFrame::Format_ARGB32, - QVideoFrame::Format_ARGB32_Premultiplied, - QVideoFrame::Format_RGB24, - QVideoFrame::Format_BGR24, - QVideoFrame::Format_RGB32, - QVideoFrame::Format_RGB565, - QVideoFrame::Format_RGB555, - }; - } else { - return {}; - } -} - -bool InputBar::tryPasteAttachment(bool fromMouse) { const QMimeData *md = nullptr; @@ -536,7 +489,7 @@ InputBar::message(const QString &msg, MarkdownOverride useMarkdown, bool rainbow if (!related.quoted_user.startsWith("@room:")) { QString body; bool firstLine = true; - auto lines = related.quoted_body.splitRef(u'\n'); + auto lines = QStringView(related.quoted_body).split(u'\n'); for (auto line : qAsConst(lines)) { if (firstLine) { firstLine = false; @@ -1036,21 +989,20 @@ MediaUpload::MediaUpload(std::unique_ptr<QIODevice> source_, blurhash_ = QString::fromStdString(blurhash::encode(data_.data(), img.width(), img.height(), 4, 3)); } else if (mimeClass_ == u"video" || mimeClass_ == u"audio") { - auto mediaPlayer = new QMediaPlayer( - this, - mimeClass_ == u"video" ? QFlags{QMediaPlayer::VideoSurface} : QMediaPlayer::Flags{}); - mediaPlayer->setMuted(true); + auto mediaPlayer = new QMediaPlayer( this); + mediaPlayer->setAudioOutput(nullptr); if (mimeClass_ == u"video") { - auto newSurface = new InputVideoSurface(this); + auto newSurface = new QVideoSink(this); connect( - newSurface, &InputVideoSurface::newImage, this, [this, mediaPlayer](QImage img) { + newSurface, &QVideoSink::videoFrameChanged, this, [this, mediaPlayer](const QVideoFrame& frame) { + QImage img = frame.toImage(); if (img.size().isEmpty()) return; mediaPlayer->stop(); - auto orientation = mediaPlayer->metaData(QMediaMetaData::Orientation).toInt(); + auto orientation = mediaPlayer->metaData().value(QMediaMetaData::Orientation).toInt(); if (orientation == 90 || orientation == 270 || orientation == 180) { img = img.transformed(QTransform().rotate(orientation), Qt::SmoothTransformation); @@ -1081,11 +1033,11 @@ MediaUpload::MediaUpload(std::unique_ptr<QIODevice> source_, } connect(mediaPlayer, - qOverload<QMediaPlayer::Error>(&QMediaPlayer::error), +&QMediaPlayer::error, this, - [mediaPlayer](QMediaPlayer::Error error) { + [mediaPlayer]() { nhlog::ui()->debug("Media player error {} and errorStr {}", - error, + mediaPlayer->error(), mediaPlayer->errorString().toStdString()); }); connect(mediaPlayer, @@ -1095,19 +1047,19 @@ MediaUpload::MediaUpload(std::unique_ptr<QIODevice> source_, "Media player status {} and error {}", status, mediaPlayer->error()); }); connect(mediaPlayer, - qOverload<const QString &, const QVariant &>(&QMediaPlayer::metaDataChanged), +&QMediaPlayer::metaDataChanged, this, - [this, mediaPlayer](const QString &t, const QVariant &) { - nhlog::ui()->debug("Got metadata {}", t.toStdString()); + [this, mediaPlayer]() { + nhlog::ui()->debug("Got metadata {}"); if (mediaPlayer->duration() > 0) this->duration_ = mediaPlayer->duration(); - auto dimensions = mediaPlayer->metaData(QMediaMetaData::Resolution).toSize(); + auto dimensions = mediaPlayer->metaData().value(QMediaMetaData::Resolution).toSize(); if (!dimensions.isEmpty()) { dimensions_ = dimensions; auto orientation = - mediaPlayer->metaData(QMediaMetaData::Orientation).toInt(); + mediaPlayer->metaData().value(QMediaMetaData::Orientation).toInt(); if (orientation == 90 || orientation == 270) { dimensions_.transpose(); } @@ -1125,8 +1077,8 @@ MediaUpload::MediaUpload(std::unique_ptr<QIODevice> source_, auto originalFile = qobject_cast<QFile *>(source.get()); - mediaPlayer->setMedia( - QMediaContent(originalFile ? originalFile->fileName() : originalFilename_), source.get()); + mediaPlayer->setSourceDevice(source.get(), + QUrl(originalFile ? originalFile->fileName() : originalFilename_)); mediaPlayer->play(); } diff --git a/src/timeline/InputBar.h b/src/timeline/InputBar.h
index 1f1d6fe1..f03e6019 100644 --- a/src/timeline/InputBar.h +++ b/src/timeline/InputBar.h
@@ -4,7 +4,6 @@ #pragma once -#include <QAbstractVideoSurface> #include <QIODevice> #include <QImage> #include <QObject> @@ -41,25 +40,6 @@ enum class MarkdownOverride CMARK, }; -class InputVideoSurface final : public QAbstractVideoSurface -{ - Q_OBJECT - -public: - InputVideoSurface(QObject *parent) - : QAbstractVideoSurface(parent) - { - } - - bool present(const QVideoFrame &frame) override; - - QList<QVideoFrame::PixelFormat> - supportedPixelFormats(QAbstractVideoBuffer::HandleType type) const override; - -signals: - void newImage(QImage img); -}; - class MediaUpload final : public QObject { Q_OBJECT diff --git a/src/timeline/RoomlistModel.cpp b/src/timeline/RoomlistModel.cpp
index 6bd02a17..b55cbabd 100644 --- a/src/timeline/RoomlistModel.cpp +++ b/src/timeline/RoomlistModel.cpp
@@ -28,7 +28,6 @@ RoomlistModel::RoomlistModel(TimelineViewManager *parent) : QAbstractListModel(parent) , manager(parent) { - [[maybe_unused]] static auto id = qRegisterMetaType<RoomPreview>(); connect(ChatPage::instance(), &ChatPage::decryptSidebarChanged, this, [this]() { auto decrypt = ChatPage::instance()->userSettings()->decryptSidebar(); @@ -819,7 +818,7 @@ RoomlistModel::refetchOnlineKeyBackupKeys() auto ptr = i.value(); if (!ptr.isNull()) { - EventStore::refetchOnlineKeyBackupKeys(ptr.data()); + ptr->refetchOnlineKeyBackupKeys(); } } } diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp
index 5996bea8..a4659f33 100644 --- a/src/timeline/TimelineModel.cpp +++ b/src/timeline/TimelineModel.cpp
@@ -31,7 +31,6 @@ #include "Utils.h" #include "encryption/Olm.h" -Q_DECLARE_METATYPE(QModelIndex) namespace std { inline uint // clazy:exclude=qhash-namespace diff --git a/src/timeline/TimelineModel.h b/src/timeline/TimelineModel.h
index b0d81441..02a5ee80 100644 --- a/src/timeline/TimelineModel.h +++ b/src/timeline/TimelineModel.h
@@ -374,6 +374,8 @@ public: return std::nullopt; } + void refetchOnlineKeyBackupKeys() { events.refetchOnlineKeyBackupKeys(); }; + public slots: void setCurrentIndex(int index); int currentIndex() const { return idToIndex(currentId); } @@ -537,8 +539,6 @@ private: std::unique_ptr<RoomSummary, DeleteLaterDeleter> parentSummary = nullptr; bool parentChecked = false; - - friend void EventStore::refetchOnlineKeyBackupKeys(TimelineModel *room); }; Q_DECLARE_OPERATORS_FOR_FLAGS(TimelineModel::SpecialEffects) diff --git a/src/timeline/TimelineViewManager.cpp b/src/timeline/TimelineViewManager.cpp
index e062dde2..a3b91ce7 100644 --- a/src/timeline/TimelineViewManager.cpp +++ b/src/timeline/TimelineViewManager.cpp
@@ -280,7 +280,7 @@ TimelineViewManager::saveMedia(QString mxcUrl) { const QString downloadsFolder = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation); - const QString openLocation = downloadsFolder + "/" + mxcUrl.splitRef(u'/').constLast(); + const QString openLocation = downloadsFolder + "/" + mxcUrl.split(u'/').constLast(); const QString filename = QFileDialog::getSaveFileName(nullptr, {}, openLocation); diff --git a/src/timeline/TimelineViewManager.h b/src/timeline/TimelineViewManager.h
index e3279e21..303e2af2 100644 --- a/src/timeline/TimelineViewManager.h +++ b/src/timeline/TimelineViewManager.h
@@ -131,11 +131,3 @@ private: QHash<QPair<QString, quint64>, QColor> userColors; }; -Q_DECLARE_METATYPE(mtx::events::msg::KeyVerificationAccept) -Q_DECLARE_METATYPE(mtx::events::msg::KeyVerificationCancel) -Q_DECLARE_METATYPE(mtx::events::msg::KeyVerificationDone) -Q_DECLARE_METATYPE(mtx::events::msg::KeyVerificationKey) -Q_DECLARE_METATYPE(mtx::events::msg::KeyVerificationMac) -Q_DECLARE_METATYPE(mtx::events::msg::KeyVerificationReady) -Q_DECLARE_METATYPE(mtx::events::msg::KeyVerificationRequest) -Q_DECLARE_METATYPE(mtx::events::msg::KeyVerificationStart)