diff --git a/src/Cache.cpp b/src/Cache.cpp index b7862d67..db71a133 100644 --- a/src/Cache.cpp +++ b/src/Cache.cpp @@ -4040,9 +4040,8 @@ Cache::displayName(const QString &room_id, const QString &user_id) static bool isDisplaynameSafe(const std::string &s) { - for (uint32_t cc : QString::fromStdString(s).toStdU32String()) { - auto c = QChar(cc); - if (c.isPrint() && !c.isSpace()) + for (char32_t c : QString::fromStdString(s).toUcs4()) { + if (QChar::isPrint(c) && !QChar::isSpace(c)) return false; } diff --git a/src/main.cpp b/src/main.cpp index 2941c82e..8067768a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -285,15 +285,17 @@ main(int argc, char *argv[]) QLocale::setDefault(QLocale(QLocale::English, QLocale::UnitedKingdom)); QTranslator qtTranslator; - if(qtTranslator.load(QLocale(), - QStringLiteral("qt"), - QStringLiteral("_"), - QLibraryInfo::path(QLibraryInfo::TranslationsPath))) + if (qtTranslator.load(QLocale(), + QStringLiteral("qt"), + QStringLiteral("_"), + QLibraryInfo::path(QLibraryInfo::TranslationsPath))) app.installTranslator(&qtTranslator); QTranslator appTranslator; - if(appTranslator.load( - QLocale(), QStringLiteral("nheko"), QStringLiteral("_"), QStringLiteral(":/translations"))) + if (appTranslator.load(QLocale(), + QStringLiteral("nheko"), + QStringLiteral("_"), + QStringLiteral(":/translations"))) app.installTranslator(&appTranslator); MainWindow w; diff --git a/src/timeline/InputBar.cpp b/src/timeline/InputBar.cpp index 9db20e69..7db9b147 100644 --- a/src/timeline/InputBar.cpp +++ b/src/timeline/InputBar.cpp @@ -5,20 +5,20 @@ #include "InputBar.h" -#include #include #include #include #include #include #include -#include #include #include #include #include #include #include +#include +#include #include #include @@ -753,82 +753,80 @@ MediaUpload::MediaUpload(std::unique_ptr source_, 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); - + mediaPlayer->setAudioOutput(nullptr); if (mimeClass_ == u"video") { auto newSurface = new QVideoSink(this); - connect( - newSurface, &QVideoSink::videoFrameChanged, this, [this, mediaPlayer](const QVideoFrame& frame) { - QImage img = frame.toImage(); + connect(newSurface, + &QVideoSink::videoFrameChanged, + this, + [this, mediaPlayer](const QVideoFrame &frame) { + QImage img = frame.toImage(); - if (img.size().isEmpty()) - return; + if (img.size().isEmpty()) + return; - mediaPlayer->stop(); + mediaPlayer->stop(); - auto orientation = mediaPlayer->metaData().value(QMediaMetaData::Orientation).toInt(); - if (orientation == 90 || orientation == 270 || orientation == 180) { - img = - img.transformed(QTransform().rotate(orientation), Qt::SmoothTransformation); - } + auto orientation = + mediaPlayer->metaData().value(QMediaMetaData::Orientation).toInt(); + if (orientation == 90 || orientation == 270 || orientation == 180) { + img = img.transformed(QTransform().rotate(orientation), + Qt::SmoothTransformation); + } - nhlog::ui()->debug("Got image {}x{}", img.width(), img.height()); + nhlog::ui()->debug("Got image {}x{}", img.width(), img.height()); - this->setThumbnail(img); + this->setThumbnail(img); - if (!dimensions_.isValid()) - this->dimensions_ = img.size(); + if (!dimensions_.isValid()) + this->dimensions_ = img.size(); - if (img.height() > 200 && img.width() > 360) - img = img.scaled(360, 200, Qt::KeepAspectRatioByExpanding); - std::vector data_; - for (int y = 0; y < img.height(); y++) { - for (int x = 0; x < img.width(); x++) { - auto p = img.pixel(x, y); - data_.push_back(static_cast(qRed(p))); - data_.push_back(static_cast(qGreen(p))); - data_.push_back(static_cast(qBlue(p))); - } - } - blurhash_ = QString::fromStdString( - blurhash::encode(data_.data(), img.width(), img.height(), 4, 3)); - }); + if (img.height() > 200 && img.width() > 360) + img = img.scaled(360, 200, Qt::KeepAspectRatioByExpanding); + std::vector data_; + for (int y = 0; y < img.height(); y++) { + for (int x = 0; x < img.width(); x++) { + auto p = img.pixel(x, y); + data_.push_back(static_cast(qRed(p))); + data_.push_back(static_cast(qGreen(p))); + data_.push_back(static_cast(qBlue(p))); + } + } + blurhash_ = QString::fromStdString( + blurhash::encode(data_.data(), img.width(), img.height(), 4, 3)); + }); mediaPlayer->setVideoOutput(newSurface); } - connect(mediaPlayer, - &QMediaPlayer::error, - this, - [mediaPlayer]() { - nhlog::ui()->debug("Media player error {} and errorStr {}", - mediaPlayer->error(), - mediaPlayer->errorString().toStdString()); - }); + connect(mediaPlayer, &QMediaPlayer::errorChanged, this, [mediaPlayer]() { + nhlog::ui()->debug("Media player error {} and errorStr {}", + mediaPlayer->error(), + mediaPlayer->errorString().toStdString()); + }); connect(mediaPlayer, &QMediaPlayer::mediaStatusChanged, [mediaPlayer](QMediaPlayer::MediaStatus status) { nhlog::ui()->debug( "Media player status {} and error {}", status, mediaPlayer->error()); }); - connect(mediaPlayer, - &QMediaPlayer::metaDataChanged, - [this, mediaPlayer]() { - nhlog::ui()->debug("Got metadata"); + connect(mediaPlayer, &QMediaPlayer::metaDataChanged, [this, mediaPlayer]() { + nhlog::ui()->debug("Got metadata"); - if (mediaPlayer->duration() > 0) - this->duration_ = mediaPlayer->duration(); + if (mediaPlayer->duration() > 0) + this->duration_ = mediaPlayer->duration(); - auto dimensions = mediaPlayer->metaData().value(QMediaMetaData::Resolution).toSize(); - if (!dimensions.isEmpty()) { - dimensions_ = dimensions; - auto orientation = - mediaPlayer->metaData().value(QMediaMetaData::Orientation).toInt(); - if (orientation == 90 || orientation == 270) { - dimensions_.transpose(); - } - } - }); + auto dimensions = mediaPlayer->metaData().value(QMediaMetaData::Resolution).toSize(); + if (!dimensions.isEmpty()) { + dimensions_ = dimensions; + auto orientation = + mediaPlayer->metaData().value(QMediaMetaData::Orientation).toInt(); + if (orientation == 90 || orientation == 270) { + dimensions_.transpose(); + } + } + }); connect(mediaPlayer, &QMediaPlayer::durationChanged, [this, mediaPlayer](qint64 duration) { if (duration > 0) { this->duration_ = mediaPlayer->duration(); @@ -841,7 +839,7 @@ MediaUpload::MediaUpload(std::unique_ptr source_, auto originalFile = qobject_cast(source.get()); mediaPlayer->setSourceDevice( - source.get(), QUrl(originalFile ? originalFile->fileName() : originalFilename_) ); + source.get(), QUrl(originalFile ? originalFile->fileName() : originalFilename_)); mediaPlayer->play(); } diff --git a/src/ui/MxcMediaProxy.cpp b/src/ui/MxcMediaProxy.cpp index 007a4148..44e42f7b 100644 --- a/src/ui/MxcMediaProxy.cpp +++ b/src/ui/MxcMediaProxy.cpp @@ -24,27 +24,20 @@ MxcMediaProxy::MxcMediaProxy(QObject *parent) { connect(this, &MxcMediaProxy::eventIdChanged, &MxcMediaProxy::startDownload); connect(this, &MxcMediaProxy::roomChanged, &MxcMediaProxy::startDownload); - connect(this, - &MxcMediaProxy::error, - [this]() { - nhlog::ui()->info("Media player error {} and errorStr {}", - error(), - this->errorString().toStdString()); - }); + connect(this, &MxcMediaProxy::error, [this]() { + nhlog::ui()->info( + "Media player error {} and errorStr {}", error(), this->errorString().toStdString()); + }); connect(this, &MxcMediaProxy::mediaStatusChanged, [this](QMediaPlayer::MediaStatus status) { nhlog::ui()->info("Media player status {} and error {}", status, this->error()); }); - connect(this, - &MxcMediaProxy::metaDataChanged, - [this]() { - emit orientationChanged(); - }); + connect(this, &MxcMediaProxy::metaDataChanged, [this]() { emit orientationChanged(); }); } int MxcMediaProxy::orientation() const { - //nhlog::ui()->debug("metadata: {}", metaData(). + // nhlog::ui()->debug("metadata: {}", metaData(). auto orientation = metaData().value(QMediaMetaData::Orientation).toInt(); nhlog::ui()->debug("Video orientation: {}", orientation); return orientation; @@ -109,7 +102,7 @@ MxcMediaProxy::startDownload() QTimer::singleShot(0, this, [this, filename] { nhlog::ui()->info( "Playing buffer with size: {}, {}", buffer.bytesAvailable(), buffer.isOpen()); - this->setSourceDevice( &buffer, QUrl(filename.fileName())); + this->setSourceDevice(&buffer, QUrl(filename.fileName())); emit loadedChanged(); }); }; diff --git a/src/ui/MxcMediaProxy.h b/src/ui/MxcMediaProxy.h index df67f561..8cb2f8d7 100644 --- a/src/ui/MxcMediaProxy.h +++ b/src/ui/MxcMediaProxy.h @@ -5,15 +5,15 @@ #pragma once -#include #include #include #include #include #include +#include -#include "timeline/TimelineModel.h" #include "Logging.h" +#include "timeline/TimelineModel.h" class TimelineModel; diff --git a/src/voip/CallManager.cpp b/src/voip/CallManager.cpp index 118550e9..529b683d 100644 --- a/src/voip/CallManager.cpp +++ b/src/voip/CallManager.cpp @@ -142,24 +142,21 @@ CallManager::CallManager(QObject *parent) player_.play(); }); - connect(&player_, - &QMediaPlayer::error, - this, - [this]() { - stopRingtone(); - switch (player_.error()) { - case QMediaPlayer::FormatError: - case QMediaPlayer::ResourceError: - nhlog::ui()->error("WebRTC: valid ringtone file not found"); - break; - case QMediaPlayer::AccessDeniedError: - nhlog::ui()->error("WebRTC: access to ringtone file denied"); - break; - default: - nhlog::ui()->error("WebRTC: unable to play ringtone"); - break; - } - }); + connect(&player_, &QMediaPlayer::errorChanged, this, [this]() { + stopRingtone(); + switch (player_.error()) { + case QMediaPlayer::FormatError: + case QMediaPlayer::ResourceError: + nhlog::ui()->error("WebRTC: valid ringtone file not found"); + break; + case QMediaPlayer::AccessDeniedError: + nhlog::ui()->error("WebRTC: access to ringtone file denied"); + break; + default: + nhlog::ui()->error("WebRTC: unable to play ringtone"); + break; + } + }); } void @@ -496,10 +493,9 @@ CallManager::retrieveTurnServer() void CallManager::playRingtone(const QUrl &ringtone, bool repeat) { - player_.setLoops(repeat ? QMediaPlayer::Infinite : - 1); + player_.setLoops(repeat ? QMediaPlayer::Infinite : 1); player_.setSource(ringtone); - //player_.audioOutput()->setVolume(100); + // player_.audioOutput()->setVolume(100); player_.play(); }