mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-12-04 16:18:48 +03:00
Enable -Wconversion
This commit is contained in:
parent
5be8298d0a
commit
b28fa86e6a
23 changed files with 102 additions and 78 deletions
|
@ -275,6 +275,7 @@ if(NOT MSVC)
|
||||||
"${CMAKE_CXX_FLAGS} \
|
"${CMAKE_CXX_FLAGS} \
|
||||||
-Wall \
|
-Wall \
|
||||||
-Wextra \
|
-Wextra \
|
||||||
|
-Wconversion \
|
||||||
-pedantic \
|
-pedantic \
|
||||||
-fsized-deallocation \
|
-fsized-deallocation \
|
||||||
-fdiagnostics-color=always \
|
-fdiagnostics-color=always \
|
||||||
|
|
|
@ -191,7 +191,7 @@ AliasEditingModel::makeCanonical(int row)
|
||||||
auto moveAlias = aliases.at(row).alias;
|
auto moveAlias = aliases.at(row).alias;
|
||||||
|
|
||||||
if (!aliasEvent.alias.empty()) {
|
if (!aliasEvent.alias.empty()) {
|
||||||
for (qsizetype i = 0; i < aliases.size(); i++) {
|
for (int i = 0; i < aliases.size(); i++) {
|
||||||
if (moveAlias == aliases[i].alias) {
|
if (moveAlias == aliases[i].alias) {
|
||||||
if (aliases[i].canonical) {
|
if (aliases[i].canonical) {
|
||||||
aliases[i].canonical = false;
|
aliases[i].canonical = false;
|
||||||
|
@ -286,7 +286,7 @@ AliasEditingModel::toggleAdvertize(int row)
|
||||||
void
|
void
|
||||||
AliasEditingModel::updateAlias(std::string alias, std::string target)
|
AliasEditingModel::updateAlias(std::string alias, std::string target)
|
||||||
{
|
{
|
||||||
for (qsizetype i = 0; i < aliases.size(); i++) {
|
for (int i = 0; i < aliases.size(); i++) {
|
||||||
auto &e = aliases[i];
|
auto &e = aliases[i];
|
||||||
if (e.alias == alias) {
|
if (e.alias == alias) {
|
||||||
e.published = (target == room_id);
|
e.published = (target == room_id);
|
||||||
|
@ -300,7 +300,7 @@ AliasEditingModel::updatePublishedAliases(std::vector<std::string> advAliases)
|
||||||
{
|
{
|
||||||
for (const auto &advAlias : advAliases) {
|
for (const auto &advAlias : advAliases) {
|
||||||
bool found = false;
|
bool found = false;
|
||||||
for (qsizetype i = 0; i < aliases.size(); i++) {
|
for (int i = 0; i < aliases.size(); i++) {
|
||||||
auto &alias = aliases[i];
|
auto &alias = aliases[i];
|
||||||
if (alias.alias == advAlias) {
|
if (alias.alias == advAlias) {
|
||||||
alias.published = true;
|
alias.published = true;
|
||||||
|
|
|
@ -3777,9 +3777,9 @@ Cache::spaces()
|
||||||
std::string_view room_data;
|
std::string_view room_data;
|
||||||
if (roomsDb_.get(txn, space_id, room_data)) {
|
if (roomsDb_.get(txn, space_id, room_data)) {
|
||||||
RoomInfo tmp = nlohmann::json::parse(std::move(room_data)).get<RoomInfo>();
|
RoomInfo tmp = nlohmann::json::parse(std::move(room_data)).get<RoomInfo>();
|
||||||
ret.insert(QString::fromUtf8(space_id.data(), (qsizetype)space_id.size()), tmp);
|
ret.insert(QString::fromUtf8(space_id.data(), (int)space_id.size()), tmp);
|
||||||
} else {
|
} else {
|
||||||
ret.insert(QString::fromUtf8(space_id.data(), (qsizetype)space_id.size()),
|
ret.insert(QString::fromUtf8(space_id.data(), (int)space_id.size()),
|
||||||
std::nullopt);
|
std::nullopt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4938,7 +4938,7 @@ to_json(nlohmann::json &obj, const GroupSessionData &msg)
|
||||||
void
|
void
|
||||||
from_json(const nlohmann::json &obj, GroupSessionData &msg)
|
from_json(const nlohmann::json &obj, GroupSessionData &msg)
|
||||||
{
|
{
|
||||||
msg.message_index = obj.at("message_index").get<uint64_t>();
|
msg.message_index = obj.at("message_index").get<uint32_t>();
|
||||||
msg.timestamp = obj.value("ts", 0ULL);
|
msg.timestamp = obj.value("ts", 0ULL);
|
||||||
msg.trusted = obj.value("trust", true);
|
msg.trusted = obj.value("trust", true);
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ struct DeviceKeysToMsgIndex
|
||||||
// map from device key to message_index
|
// map from device key to message_index
|
||||||
// Using the device id is safe because we check for reuse on device list updates
|
// Using the device id is safe because we check for reuse on device list updates
|
||||||
// Using the device id makes our logic much easier to read.
|
// Using the device id makes our logic much easier to read.
|
||||||
std::map<std::string, uint64_t> deviceids;
|
std::map<std::string, uint32_t> deviceids;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SharedWithUsers
|
struct SharedWithUsers
|
||||||
|
@ -45,8 +45,8 @@ struct SharedWithUsers
|
||||||
// Extra information associated with an outbound megolm session.
|
// Extra information associated with an outbound megolm session.
|
||||||
struct GroupSessionData
|
struct GroupSessionData
|
||||||
{
|
{
|
||||||
uint64_t message_index = 0;
|
|
||||||
uint64_t timestamp = 0;
|
uint64_t timestamp = 0;
|
||||||
|
uint32_t message_index = 0;
|
||||||
|
|
||||||
// If we got the session via key sharing or forwarding, we can usually trust it.
|
// If we got the session via key sharing or forwarding, we can usually trust it.
|
||||||
// If it came from asymmetric key backup, it is not trusted.
|
// If it came from asymmetric key backup, it is not trusted.
|
||||||
|
|
|
@ -93,8 +93,8 @@ struct RoomInfo
|
||||||
//! Use the TimelineModel::lastMessage for an accurate timestamp.
|
//! Use the TimelineModel::lastMessage for an accurate timestamp.
|
||||||
uint64_t approximate_last_modification_ts = 0;
|
uint64_t approximate_last_modification_ts = 0;
|
||||||
|
|
||||||
uint16_t highlight_count = 0;
|
uint64_t highlight_count = 0;
|
||||||
uint16_t notification_count = 0;
|
uint64_t notification_count = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -179,7 +179,8 @@ ChatPage::ChatPage(QSharedPointer<UserSettings> userSettings, QObject *parent)
|
||||||
static unsigned int prevNotificationCount = 0;
|
static unsigned int prevNotificationCount = 0;
|
||||||
unsigned int notificationCount = 0;
|
unsigned int notificationCount = 0;
|
||||||
for (const auto &room : sync.rooms.join) {
|
for (const auto &room : sync.rooms.join) {
|
||||||
notificationCount += room.second.unread_notifications.notification_count;
|
notificationCount +=
|
||||||
|
static_cast<unsigned int>(room.second.unread_notifications.notification_count);
|
||||||
}
|
}
|
||||||
|
|
||||||
// HACK: If we had less notifications last time we checked, send an alert if the
|
// HACK: If we had less notifications last time we checked, send an alert if the
|
||||||
|
@ -1064,12 +1065,15 @@ ChatPage::verifyOneTimeKeyCountAfterStartup()
|
||||||
}
|
}
|
||||||
|
|
||||||
std::map<std::string, uint16_t> key_counts;
|
std::map<std::string, uint16_t> key_counts;
|
||||||
auto count = 0;
|
std::uint64_t count = 0;
|
||||||
if (auto c = res.one_time_key_counts.find(mtx::crypto::SIGNED_CURVE25519);
|
if (auto c = res.one_time_key_counts.find(mtx::crypto::SIGNED_CURVE25519);
|
||||||
c == res.one_time_key_counts.end()) {
|
c == res.one_time_key_counts.end()) {
|
||||||
key_counts[mtx::crypto::SIGNED_CURVE25519] = 0;
|
key_counts[mtx::crypto::SIGNED_CURVE25519] = 0;
|
||||||
} else {
|
} else {
|
||||||
key_counts[mtx::crypto::SIGNED_CURVE25519] = c->second;
|
key_counts[mtx::crypto::SIGNED_CURVE25519] =
|
||||||
|
c->second > std::numeric_limits<std::uint16_t>::max()
|
||||||
|
? std::numeric_limits<std::uint16_t>::max()
|
||||||
|
: static_cast<std::uint16_t>(c->second);
|
||||||
count = c->second;
|
count = c->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -104,7 +104,8 @@ JdenticonRunnable::run()
|
||||||
painter.setRenderHint(QPainter::SmoothPixmapTransform, true);
|
painter.setRenderHint(QPainter::SmoothPixmapTransform, true);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
QSvgRenderer renderer{jdenticon->generate(m_key, m_requestedSize.width()).toUtf8()};
|
QSvgRenderer renderer{
|
||||||
|
jdenticon->generate(m_key, static_cast<std::uint16_t>(m_requestedSize.width())).toUtf8()};
|
||||||
renderer.render(&painter);
|
renderer.render(&painter);
|
||||||
} catch (std::exception &e) {
|
} catch (std::exception &e) {
|
||||||
nhlog::ui()->error(
|
nhlog::ui()->error(
|
||||||
|
|
|
@ -169,8 +169,9 @@ MxcImageProvider::download(const QString &id,
|
||||||
|
|
||||||
mtx::http::ThumbOpts opts;
|
mtx::http::ThumbOpts opts;
|
||||||
opts.mxc_url = "mxc://" + id.toStdString();
|
opts.mxc_url = "mxc://" + id.toStdString();
|
||||||
opts.width = requestedSize.width() > 0 ? requestedSize.width() : -1;
|
opts.width = static_cast<uint8_t>(requestedSize.width() > 0 ? requestedSize.width() : -1);
|
||||||
opts.height = requestedSize.height() > 0 ? requestedSize.height() : -1;
|
opts.height =
|
||||||
|
static_cast<uint8_t>(requestedSize.height() > 0 ? requestedSize.height() : -1);
|
||||||
opts.method = crop ? "crop" : "scale";
|
opts.method = crop ? "crop" : "scale";
|
||||||
http::client()->get_thumbnail(
|
http::client()->get_thumbnail(
|
||||||
opts,
|
opts,
|
||||||
|
|
|
@ -85,8 +85,9 @@ ReadReceiptsModel::addUsers(
|
||||||
auto newReceipts = users.size() - readReceipts_.size();
|
auto newReceipts = users.size() - readReceipts_.size();
|
||||||
|
|
||||||
if (newReceipts > 0) {
|
if (newReceipts > 0) {
|
||||||
beginInsertRows(
|
beginInsertRows(QModelIndex{},
|
||||||
QModelIndex{}, readReceipts_.size(), readReceipts_.size() + newReceipts - 1);
|
static_cast<int>(readReceipts_.size()),
|
||||||
|
static_cast<int>(readReceipts_.size() + newReceipts - 1));
|
||||||
|
|
||||||
for (const auto &user : users) {
|
for (const auto &user : users) {
|
||||||
QPair<QString, QDateTime> item = {QString::fromStdString(user.second),
|
QPair<QString, QDateTime> item = {QString::fromStdString(user.second),
|
||||||
|
|
|
@ -354,8 +354,8 @@ utils::scaleImageToPixmap(const QImage &img, int size)
|
||||||
|
|
||||||
// Deprecated in 5.13: const double sz =
|
// Deprecated in 5.13: const double sz =
|
||||||
// std::ceil(QApplication::desktop()->screen()->devicePixelRatioF() * (double)size);
|
// std::ceil(QApplication::desktop()->screen()->devicePixelRatioF() * (double)size);
|
||||||
const double sz =
|
const int sz = static_cast<int>(
|
||||||
std::ceil(QGuiApplication::primaryScreen()->devicePixelRatio() * (double)size);
|
std::ceil(QGuiApplication::primaryScreen()->devicePixelRatio() * (double)size));
|
||||||
return QPixmap::fromImage(img.scaled(sz, sz, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
|
return QPixmap::fromImage(img.scaled(sz, sz, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -376,8 +376,8 @@ utils::scaleDown(uint64_t maxWidth, uint64_t maxHeight, const QPixmap &source)
|
||||||
w = source.width();
|
w = source.width();
|
||||||
h = source.height();
|
h = source.height();
|
||||||
} else {
|
} else {
|
||||||
w = source.width() * minAspectRatio;
|
w = static_cast<int>(static_cast<double>(source.width()) * minAspectRatio);
|
||||||
h = source.height() * minAspectRatio;
|
h = static_cast<int>(static_cast<double>(source.height()) * minAspectRatio);
|
||||||
}
|
}
|
||||||
|
|
||||||
return source.scaled(w, h, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
|
return source.scaled(w, h, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
|
||||||
|
@ -452,7 +452,7 @@ utils::escapeBlacklistedHtml(const QString &rawStr)
|
||||||
const auto end = data.cend();
|
const auto end = data.cend();
|
||||||
for (auto pos = data.cbegin(); pos < end;) {
|
for (auto pos = data.cbegin(); pos < end;) {
|
||||||
auto tagStart = std::find(pos, end, '<');
|
auto tagStart = std::find(pos, end, '<');
|
||||||
buffer.append(pos, tagStart - pos);
|
buffer.append(pos, static_cast<int>(tagStart - pos));
|
||||||
if (tagStart == end)
|
if (tagStart == end)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -460,14 +460,15 @@ utils::escapeBlacklistedHtml(const QString &rawStr)
|
||||||
const auto tagNameEnd =
|
const auto tagNameEnd =
|
||||||
std::find_first_of(tagNameStart, end, tagNameEnds.begin(), tagNameEnds.end());
|
std::find_first_of(tagNameStart, end, tagNameEnds.begin(), tagNameEnds.end());
|
||||||
|
|
||||||
if (allowedTags.find(QByteArray(tagNameStart, tagNameEnd - tagNameStart).toLower()) ==
|
if (allowedTags.find(
|
||||||
|
QByteArray(tagNameStart, static_cast<int>(tagNameEnd - tagNameStart)).toLower()) ==
|
||||||
allowedTags.end()) {
|
allowedTags.end()) {
|
||||||
// not allowed -> escape
|
// not allowed -> escape
|
||||||
buffer.append("<");
|
buffer.append("<");
|
||||||
pos = tagNameStart;
|
pos = tagNameStart;
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
buffer.append(tagStart, tagNameEnd - tagStart);
|
buffer.append(tagStart, static_cast<int>(tagNameEnd - tagStart));
|
||||||
|
|
||||||
pos = tagNameEnd;
|
pos = tagNameEnd;
|
||||||
|
|
||||||
|
@ -492,7 +493,8 @@ utils::escapeBlacklistedHtml(const QString &rawStr)
|
||||||
auto attrEnd = std::find_first_of(
|
auto attrEnd = std::find_first_of(
|
||||||
attrStart, attrsEnd, attrNameEnds.begin(), attrNameEnds.end());
|
attrStart, attrsEnd, attrNameEnds.begin(), attrNameEnds.end());
|
||||||
|
|
||||||
auto attrName = QByteArray(attrStart, attrEnd - attrStart).toLower();
|
auto attrName =
|
||||||
|
QByteArray(attrStart, static_cast<int>(attrEnd - attrStart)).toLower();
|
||||||
|
|
||||||
auto sanitizeValue = [&attrName](QByteArray val) {
|
auto sanitizeValue = [&attrName](QByteArray val) {
|
||||||
if (attrName == QByteArrayLiteral("src") && !val.startsWith("mxc://"))
|
if (attrName == QByteArrayLiteral("src") && !val.startsWith("mxc://"))
|
||||||
|
@ -520,8 +522,8 @@ utils::escapeBlacklistedHtml(const QString &rawStr)
|
||||||
if (valueEnd == attrsEnd)
|
if (valueEnd == attrsEnd)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
auto val =
|
auto val = sanitizeValue(QByteArray(
|
||||||
sanitizeValue(QByteArray(attrStart, valueEnd - attrStart));
|
attrStart, static_cast<int>(valueEnd - attrStart)));
|
||||||
attrStart = consumeSpaces(valueEnd + 1);
|
attrStart = consumeSpaces(valueEnd + 1);
|
||||||
if (!val.isEmpty()) {
|
if (!val.isEmpty()) {
|
||||||
buffer.append(' ');
|
buffer.append(' ');
|
||||||
|
@ -537,8 +539,8 @@ utils::escapeBlacklistedHtml(const QString &rawStr)
|
||||||
if (valueEnd == attrsEnd)
|
if (valueEnd == attrsEnd)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
auto val =
|
auto val = sanitizeValue(QByteArray(
|
||||||
sanitizeValue(QByteArray(attrStart, valueEnd - attrStart));
|
attrStart, static_cast<int>(valueEnd - attrStart)));
|
||||||
attrStart = consumeSpaces(valueEnd + 1);
|
attrStart = consumeSpaces(valueEnd + 1);
|
||||||
if (!val.isEmpty()) {
|
if (!val.isEmpty()) {
|
||||||
buffer.append(' ');
|
buffer.append(' ');
|
||||||
|
@ -553,8 +555,8 @@ utils::escapeBlacklistedHtml(const QString &rawStr)
|
||||||
attrsEnd,
|
attrsEnd,
|
||||||
attrValueEnds.begin(),
|
attrValueEnds.begin(),
|
||||||
attrValueEnds.end());
|
attrValueEnds.end());
|
||||||
auto val =
|
auto val = sanitizeValue(QByteArray(
|
||||||
sanitizeValue(QByteArray(attrStart, valueEnd - attrStart));
|
attrStart, static_cast<int>(valueEnd - attrStart)));
|
||||||
attrStart = consumeSpaces(valueEnd);
|
attrStart = consumeSpaces(valueEnd);
|
||||||
|
|
||||||
if (val.contains('"'))
|
if (val.contains('"'))
|
||||||
|
@ -772,15 +774,15 @@ utils::generateContrastingHexColor(const QString &input, const QColor &backgroun
|
||||||
auto hash = hashQString(input);
|
auto hash = hashQString(input);
|
||||||
// create a hue value based on the hash of the input.
|
// create a hue value based on the hash of the input.
|
||||||
// Adapted to make Nico blue
|
// Adapted to make Nico blue
|
||||||
auto userHue =
|
auto userHue = static_cast<double>(hash - static_cast<uint32_t>(0x60'00'00'00)) /
|
||||||
static_cast<int>(static_cast<double>(hash - static_cast<uint32_t>(0x60'00'00'00)) /
|
std::numeric_limits<uint32_t>::max() * 360.;
|
||||||
std::numeric_limits<uint32_t>::max() * 360.);
|
|
||||||
// start with moderate saturation and lightness values.
|
// start with moderate saturation and lightness values.
|
||||||
auto sat = 230;
|
auto sat = 230.;
|
||||||
auto lightness = 125;
|
auto lightness = 125.;
|
||||||
|
|
||||||
// converting to a QColor makes the luminance calc easier.
|
// converting to a QColor makes the luminance calc easier.
|
||||||
QColor inputColor = QColor::fromHsl(userHue, sat, lightness);
|
QColor inputColor = QColor::fromHsl(
|
||||||
|
static_cast<int>(userHue), static_cast<int>(sat), static_cast<int>(lightness));
|
||||||
|
|
||||||
// calculate the initial luminance and contrast of the
|
// calculate the initial luminance and contrast of the
|
||||||
// generated color. It's possible that no additional
|
// generated color. It's possible that no additional
|
||||||
|
@ -798,7 +800,9 @@ utils::generateContrastingHexColor(const QString &input, const QColor &backgroun
|
||||||
if (lightness >= 242 || lightness <= 13) {
|
if (lightness >= 242 || lightness <= 13) {
|
||||||
qreal newSat = qBound(26.0, sat * 1.25, 242.0);
|
qreal newSat = qBound(26.0, sat * 1.25, 242.0);
|
||||||
|
|
||||||
inputColor.setHsl(userHue, qFloor(newSat), lightness);
|
inputColor.setHsl(static_cast<int>(userHue),
|
||||||
|
static_cast<int>(qFloor(newSat)),
|
||||||
|
static_cast<int>(lightness));
|
||||||
auto tmpLum = luminance(inputColor);
|
auto tmpLum = luminance(inputColor);
|
||||||
auto higherContrast = computeContrast(tmpLum, backgroundLum);
|
auto higherContrast = computeContrast(tmpLum, backgroundLum);
|
||||||
if (higherContrast > contrast) {
|
if (higherContrast > contrast) {
|
||||||
|
@ -806,7 +810,9 @@ utils::generateContrastingHexColor(const QString &input, const QColor &backgroun
|
||||||
sat = newSat;
|
sat = newSat;
|
||||||
} else {
|
} else {
|
||||||
newSat = qBound(26.0, sat / 1.25, 242.0);
|
newSat = qBound(26.0, sat / 1.25, 242.0);
|
||||||
inputColor.setHsl(userHue, qFloor(newSat), lightness);
|
inputColor.setHsl(static_cast<int>(userHue),
|
||||||
|
static_cast<int>(qFloor(newSat)),
|
||||||
|
static_cast<int>(lightness));
|
||||||
tmpLum = luminance(inputColor);
|
tmpLum = luminance(inputColor);
|
||||||
auto lowerContrast = computeContrast(tmpLum, backgroundLum);
|
auto lowerContrast = computeContrast(tmpLum, backgroundLum);
|
||||||
if (lowerContrast > contrast) {
|
if (lowerContrast > contrast) {
|
||||||
|
@ -817,7 +823,9 @@ utils::generateContrastingHexColor(const QString &input, const QColor &backgroun
|
||||||
} else {
|
} else {
|
||||||
qreal newLightness = qBound(13.0, lightness * 1.25, 242.0);
|
qreal newLightness = qBound(13.0, lightness * 1.25, 242.0);
|
||||||
|
|
||||||
inputColor.setHsl(userHue, sat, qFloor(newLightness));
|
inputColor.setHsl(static_cast<int>(userHue),
|
||||||
|
static_cast<int>(sat),
|
||||||
|
static_cast<int>(qFloor(newLightness)));
|
||||||
|
|
||||||
auto tmpLum = luminance(inputColor);
|
auto tmpLum = luminance(inputColor);
|
||||||
auto higherContrast = computeContrast(tmpLum, backgroundLum);
|
auto higherContrast = computeContrast(tmpLum, backgroundLum);
|
||||||
|
@ -829,7 +837,9 @@ utils::generateContrastingHexColor(const QString &input, const QColor &backgroun
|
||||||
// otherwise, try going the other way instead.
|
// otherwise, try going the other way instead.
|
||||||
} else {
|
} else {
|
||||||
newLightness = qBound(13.0, lightness / 1.25, 242.0);
|
newLightness = qBound(13.0, lightness / 1.25, 242.0);
|
||||||
inputColor.setHsl(userHue, sat, qFloor(newLightness));
|
inputColor.setHsl(static_cast<int>(userHue),
|
||||||
|
static_cast<int>(sat),
|
||||||
|
static_cast<int>(qFloor(newLightness)));
|
||||||
tmpLum = luminance(inputColor);
|
tmpLum = luminance(inputColor);
|
||||||
auto lowerContrast = computeContrast(tmpLum, backgroundLum);
|
auto lowerContrast = computeContrast(tmpLum, backgroundLum);
|
||||||
if (lowerContrast > contrast) {
|
if (lowerContrast > contrast) {
|
||||||
|
@ -888,8 +898,8 @@ utils::centerWidget(QWidget *widget, QWindow *parent)
|
||||||
}
|
}
|
||||||
|
|
||||||
auto findCenter = [childRect = widget->rect()](QRect hostRect) -> QPoint {
|
auto findCenter = [childRect = widget->rect()](QRect hostRect) -> QPoint {
|
||||||
return QPoint(hostRect.center().x() - (childRect.width() * 0.5),
|
return QPoint(static_cast<int>(hostRect.center().x() - (childRect.width() * 0.5)),
|
||||||
hostRect.center().y() - (childRect.height() * 0.5));
|
static_cast<int>(hostRect.center().y() - (childRect.height() * 0.5)));
|
||||||
};
|
};
|
||||||
widget->move(findCenter(QGuiApplication::primaryScreen()->geometry()));
|
widget->move(findCenter(QGuiApplication::primaryScreen()->geometry()));
|
||||||
}
|
}
|
||||||
|
|
|
@ -186,7 +186,7 @@ operator<<(QDBusArgument &arg, const QImage &image)
|
||||||
int channels = i.hasAlphaChannel() ? 4 : 3;
|
int channels = i.hasAlphaChannel() ? 4 : 3;
|
||||||
arg << i.depth() / channels;
|
arg << i.depth() / channels;
|
||||||
arg << channels;
|
arg << channels;
|
||||||
arg << QByteArray(reinterpret_cast<const char *>(i.bits()), i.sizeInBytes());
|
arg << QByteArray(reinterpret_cast<const char *>(i.bits()), static_cast<int>(i.sizeInBytes()));
|
||||||
arg.endStructure();
|
arg.endStructure();
|
||||||
|
|
||||||
return arg;
|
return arg;
|
||||||
|
|
|
@ -1144,7 +1144,7 @@ handle_key_request_message(const mtx::events::DeviceEvent<mtx::events::msg::KeyR
|
||||||
}
|
}
|
||||||
|
|
||||||
bool shouldSeeKeys = false;
|
bool shouldSeeKeys = false;
|
||||||
uint64_t minimumIndex = -1;
|
uint32_t minimumIndex = -1;
|
||||||
if (sessionData->currently.keys.count(req.sender)) {
|
if (sessionData->currently.keys.count(req.sender)) {
|
||||||
if (sessionData->currently.keys.at(req.sender)
|
if (sessionData->currently.keys.at(req.sender)
|
||||||
.deviceids.count(req.content.requesting_device_id)) {
|
.deviceids.count(req.content.requesting_device_id)) {
|
||||||
|
|
|
@ -61,7 +61,7 @@ stacktraceHandler(int signum)
|
||||||
// see
|
// see
|
||||||
// https://stackoverflow.com/questions/77005/how-to-automatically-generate-a-stacktrace-when-my-program-crashes/77336#77336
|
// https://stackoverflow.com/questions/77005/how-to-automatically-generate-a-stacktrace-when-my-program-crashes/77336#77336
|
||||||
void *array[50];
|
void *array[50];
|
||||||
size_t size;
|
int size;
|
||||||
|
|
||||||
// get void*'s for all entries on the stack
|
// get void*'s for all entries on the stack
|
||||||
size = backtrace(array, 50);
|
size = backtrace(array, 50);
|
||||||
|
|
|
@ -153,7 +153,8 @@ CommunitiesModel::data(const QModelIndex &index, int role) const
|
||||||
int count = 0;
|
int count = 0;
|
||||||
auto end = spaceOrder_.lastChild(index.row() - 2);
|
auto end = spaceOrder_.lastChild(index.row() - 2);
|
||||||
for (int i = index.row() - 2; i <= end; i++)
|
for (int i = index.row() - 2; i <= end; i++)
|
||||||
count += spaceOrder_.tree[i].notificationCounts.notification_count;
|
count +=
|
||||||
|
static_cast<int>(spaceOrder_.tree[i].notificationCounts.notification_count);
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
case CommunitiesModel::Roles::HasLoudNotification: {
|
case CommunitiesModel::Roles::HasLoudNotification: {
|
||||||
|
|
|
@ -66,24 +66,24 @@ Permissions::canSend(int eventType)
|
||||||
int
|
int
|
||||||
Permissions::defaultLevel()
|
Permissions::defaultLevel()
|
||||||
{
|
{
|
||||||
return pl.users_default;
|
return static_cast<int>(pl.users_default);
|
||||||
}
|
}
|
||||||
int
|
int
|
||||||
Permissions::redactLevel()
|
Permissions::redactLevel()
|
||||||
{
|
{
|
||||||
return pl.redact;
|
return static_cast<int>(pl.redact);
|
||||||
}
|
}
|
||||||
int
|
int
|
||||||
Permissions::changeLevel(int eventType)
|
Permissions::changeLevel(int eventType)
|
||||||
{
|
{
|
||||||
return pl.state_level(to_string(
|
return static_cast<int>(pl.state_level(to_string(
|
||||||
qml_mtx_events::fromRoomEventType(static_cast<qml_mtx_events::EventType>(eventType))));
|
qml_mtx_events::fromRoomEventType(static_cast<qml_mtx_events::EventType>(eventType)))));
|
||||||
}
|
}
|
||||||
int
|
int
|
||||||
Permissions::sendLevel(int eventType)
|
Permissions::sendLevel(int eventType)
|
||||||
{
|
{
|
||||||
return pl.event_level(to_string(
|
return static_cast<int>(pl.event_level(to_string(
|
||||||
qml_mtx_events::fromRoomEventType(static_cast<qml_mtx_events::EventType>(eventType))));
|
qml_mtx_events::fromRoomEventType(static_cast<qml_mtx_events::EventType>(eventType)))));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
|
|
@ -679,7 +679,7 @@ TimelineModel::data(const mtx::events::collections::TimelineEvents &event, int r
|
||||||
if (w == 0)
|
if (w == 0)
|
||||||
w = 1;
|
w = 1;
|
||||||
|
|
||||||
double prop = media_height(event) / (double)w;
|
double prop = (double)media_height(event) / (double)w;
|
||||||
|
|
||||||
return {prop > 0 ? prop : 1.};
|
return {prop > 0 ? prop : 1.};
|
||||||
}
|
}
|
||||||
|
@ -2881,7 +2881,7 @@ TimelineModel::pinnedMessages() const
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
QStringList list;
|
QStringList list;
|
||||||
list.reserve((qsizetype)pinned->content.pinned.size());
|
list.reserve((int)pinned->content.pinned.size());
|
||||||
for (const auto &p : pinned->content.pinned)
|
for (const auto &p : pinned->content.pinned)
|
||||||
list.push_back(QString::fromStdString(p));
|
list.push_back(QString::fromStdString(p));
|
||||||
|
|
||||||
|
@ -2912,7 +2912,7 @@ TimelineModel::widgetLinks() const
|
||||||
theme.clear();
|
theme.clear();
|
||||||
user = QUrl::toPercentEncoding(user);
|
user = QUrl::toPercentEncoding(user);
|
||||||
|
|
||||||
list.reserve((qsizetype)evs.size());
|
list.reserve((int)evs.size());
|
||||||
for (const auto &p : evs) {
|
for (const auto &p : evs) {
|
||||||
auto url = QString::fromStdString(p.content.url);
|
auto url = QString::fromStdString(p.content.url);
|
||||||
|
|
||||||
|
|
|
@ -406,7 +406,7 @@ public slots:
|
||||||
RoomSummary *parentSpace();
|
RoomSummary *parentSpace();
|
||||||
|
|
||||||
bool hasMentions() const { return highlight_count > 0; }
|
bool hasMentions() const { return highlight_count > 0; }
|
||||||
int notificationCount() const { return notification_count; }
|
int notificationCount() const { return static_cast<int>(notification_count); }
|
||||||
|
|
||||||
QString scrollTarget() const;
|
QString scrollTarget() const;
|
||||||
|
|
||||||
|
|
|
@ -82,7 +82,7 @@ MxcAnimatedImage::startDownload()
|
||||||
std::string temp(ba.constData(), ba.size());
|
std::string temp(ba.constData(), ba.size());
|
||||||
temp =
|
temp =
|
||||||
mtx::crypto::to_string(mtx::crypto::decrypt_file(temp, encryptionInfo.value()));
|
mtx::crypto::to_string(mtx::crypto::decrypt_file(temp, encryptionInfo.value()));
|
||||||
buffer.setData(temp.data(), temp.size());
|
buffer.setData(temp.data(), static_cast<int>(temp.size()));
|
||||||
} else {
|
} else {
|
||||||
buffer.setData(device.readAll());
|
buffer.setData(device.readAll());
|
||||||
}
|
}
|
||||||
|
|
|
@ -122,7 +122,7 @@ MxcMediaProxy::startDownload()
|
||||||
QByteArray ba = device.readAll();
|
QByteArray ba = device.readAll();
|
||||||
std::string temp(ba.constData(), ba.size());
|
std::string temp(ba.constData(), ba.size());
|
||||||
temp = mtx::crypto::to_string(mtx::crypto::decrypt_file(temp, encryptionInfo.value()));
|
temp = mtx::crypto::to_string(mtx::crypto::decrypt_file(temp, encryptionInfo.value()));
|
||||||
buffer.setData(temp.data(), temp.size());
|
buffer.setData(temp.data(), static_cast<int>(temp.size()));
|
||||||
} else {
|
} else {
|
||||||
buffer.setData(device.readAll());
|
buffer.setData(device.readAll());
|
||||||
}
|
}
|
||||||
|
|
|
@ -132,7 +132,7 @@ RoomSettings::roomAvatarUrl()
|
||||||
int
|
int
|
||||||
RoomSettings::memberCount() const
|
RoomSettings::memberCount() const
|
||||||
{
|
{
|
||||||
return info_.member_count;
|
return static_cast<int>(info_.member_count);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -180,7 +180,8 @@ QStringList
|
||||||
RoomSettings::allowedRooms() const
|
RoomSettings::allowedRooms() const
|
||||||
{
|
{
|
||||||
QStringList rooms;
|
QStringList rooms;
|
||||||
rooms.reserve(accessRules_.allow.size());
|
assert(accessRules_.allow.size() < std::numeric_limits<int>::max());
|
||||||
|
rooms.reserve(static_cast<int>(accessRules_.allow.size()));
|
||||||
for (const auto &e : accessRules_.allow) {
|
for (const auto &e : accessRules_.allow) {
|
||||||
if (e.type == mtx::events::state::JoinAllowanceType::RoomMembership)
|
if (e.type == mtx::events::state::JoinAllowanceType::RoomMembership)
|
||||||
rooms.push_back(QString::fromStdString(e.room_id));
|
rooms.push_back(QString::fromStdString(e.room_id));
|
||||||
|
|
|
@ -124,10 +124,10 @@ CallManager::CallManager(QObject *parent)
|
||||||
// Request new credentials close to expiry
|
// Request new credentials close to expiry
|
||||||
// See https://tools.ietf.org/html/draft-uberti-behave-turn-rest-00
|
// See https://tools.ietf.org/html/draft-uberti-behave-turn-rest-00
|
||||||
turnURIs_ = getTurnURIs(res);
|
turnURIs_ = getTurnURIs(res);
|
||||||
uint32_t ttl = std::max(res.ttl, UINT32_C(3600));
|
uint32_t ttl = std::max(res.ttl, std::uint32_t{3600});
|
||||||
if (res.ttl < 3600)
|
if (res.ttl < 3600)
|
||||||
nhlog::net()->warn("Setting ttl to 1 hour");
|
nhlog::net()->warn("Setting ttl to 1 hour");
|
||||||
turnServerTimer_.setInterval(ttl * 1000 * 0.9);
|
turnServerTimer_.setInterval(std::chrono::seconds(ttl) * 10 / 9);
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(&session_, &WebRTCSession::stateChanged, this, [this](webrtc::State state) {
|
connect(&session_, &WebRTCSession::stateChanged, this, [this](webrtc::State state) {
|
||||||
|
@ -728,7 +728,8 @@ CallManager::devices(bool isVideo) const
|
||||||
isVideo ? UserSettings::instance()->camera() : UserSettings::instance()->microphone();
|
isVideo ? UserSettings::instance()->camera() : UserSettings::instance()->microphone();
|
||||||
std::vector<std::string> devices =
|
std::vector<std::string> devices =
|
||||||
CallDevices::instance().names(isVideo, defaultDevice.toStdString());
|
CallDevices::instance().names(isVideo, defaultDevice.toStdString());
|
||||||
ret.reserve(devices.size());
|
assert(devices.size() < std::numeric_limits<int>::max());
|
||||||
|
ret.reserve(static_cast<int>(devices.size()));
|
||||||
std::transform(devices.cbegin(), devices.cend(), std::back_inserter(ret), [](const auto &d) {
|
std::transform(devices.cbegin(), devices.cend(), std::back_inserter(ret), [](const auto &d) {
|
||||||
return QString::fromStdString(d);
|
return QString::fromStdString(d);
|
||||||
});
|
});
|
||||||
|
@ -867,7 +868,8 @@ CallManager::windowList()
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
QStringList ret;
|
QStringList ret;
|
||||||
ret.reserve(windows_.size());
|
assert(windows_.size() < std::numeric_limits<int>::max());
|
||||||
|
ret.reserve(static_cast<int>(windows_.size()));
|
||||||
for (const auto &w : windows_)
|
for (const auto &w : windows_)
|
||||||
ret.append(w.first);
|
ret.append(w.first);
|
||||||
|
|
||||||
|
|
|
@ -141,7 +141,8 @@ parseSDP(const std::string &sdp, GstWebRTCSDPType type)
|
||||||
{
|
{
|
||||||
GstSDPMessage *msg;
|
GstSDPMessage *msg;
|
||||||
gst_sdp_message_new(&msg);
|
gst_sdp_message_new(&msg);
|
||||||
if (gst_sdp_message_parse_buffer((guint8 *)sdp.c_str(), sdp.size(), msg) == GST_SDP_OK) {
|
if (gst_sdp_message_parse_buffer((guint8 *)sdp.c_str(), static_cast<guint>(sdp.size()), msg) ==
|
||||||
|
GST_SDP_OK) {
|
||||||
return gst_webrtc_session_description_new(type, msg);
|
return gst_webrtc_session_description_new(type, msg);
|
||||||
} else {
|
} else {
|
||||||
nhlog::ui()->error("WebRTC: failed to parse remote session description");
|
nhlog::ui()->error("WebRTC: failed to parse remote session description");
|
||||||
|
@ -371,9 +372,12 @@ getResolution(GstElement *pipe, const gchar *elementName, const gchar *padName)
|
||||||
std::pair<int, int>
|
std::pair<int, int>
|
||||||
getPiPDimensions(const std::pair<int, int> &resolution, int fullWidth, double scaleFactor)
|
getPiPDimensions(const std::pair<int, int> &resolution, int fullWidth, double scaleFactor)
|
||||||
{
|
{
|
||||||
int pipWidth = fullWidth * scaleFactor;
|
double pipWidth = fullWidth * scaleFactor;
|
||||||
int pipHeight = static_cast<double>(resolution.second) / resolution.first * pipWidth;
|
double pipHeight = static_cast<double>(resolution.second) / resolution.first * pipWidth;
|
||||||
return {pipWidth, pipHeight};
|
return {
|
||||||
|
static_cast<int>(std::ceil(pipWidth)),
|
||||||
|
static_cast<int>(std::ceil(pipHeight)),
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
14
third_party/blurhash/blurhash.cpp
vendored
14
third_party/blurhash/blurhash.cpp
vendored
|
@ -4,6 +4,7 @@
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
#include <numbers>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
#ifdef DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
|
#ifdef DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
|
||||||
|
@ -17,9 +18,6 @@
|
||||||
using namespace std::literals;
|
using namespace std::literals;
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
template<class T>
|
|
||||||
T pi = 3.14159265358979323846;
|
|
||||||
|
|
||||||
constexpr std::array<char, 84> int_to_b83{
|
constexpr std::array<char, 84> int_to_b83{
|
||||||
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz#$%*+,-.:;=?@[]^_{|}~"};
|
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz#$%*+,-.:;=?@[]^_{|}~"};
|
||||||
|
|
||||||
|
@ -93,7 +91,7 @@ decode83(std::string_view value)
|
||||||
float
|
float
|
||||||
decodeMaxAC(int quantizedMaxAC) noexcept
|
decodeMaxAC(int quantizedMaxAC) noexcept
|
||||||
{
|
{
|
||||||
return (quantizedMaxAC + 1) / 166.;
|
return static_cast<float>(quantizedMaxAC + 1) / 166.f;
|
||||||
}
|
}
|
||||||
|
|
||||||
float
|
float
|
||||||
|
@ -123,7 +121,7 @@ srgbToLinear(int value) noexcept
|
||||||
return std::pow((x + 0.055f) / 1.055f, 2.4f);
|
return std::pow((x + 0.055f) / 1.055f, 2.4f);
|
||||||
};
|
};
|
||||||
|
|
||||||
return srgbToLinearF(value / 255.f);
|
return srgbToLinearF(static_cast<float>(value) / 255.f);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@ -234,7 +232,7 @@ std::vector<float>
|
||||||
bases_for(size_t dimension, size_t components)
|
bases_for(size_t dimension, size_t components)
|
||||||
{
|
{
|
||||||
std::vector<float> bases(dimension * components, 0.f);
|
std::vector<float> bases(dimension * components, 0.f);
|
||||||
auto scale = pi<float> / float(dimension);
|
auto scale = std::numbers::pi_v<float> / float(dimension);
|
||||||
for (size_t x = 0; x < dimension; x++) {
|
for (size_t x = 0; x < dimension; x++) {
|
||||||
for (size_t nx = 0; nx < size_t(components); nx++) {
|
for (size_t nx = 0; nx < size_t(components); nx++) {
|
||||||
bases[x * components + nx] = std::cos(scale * float(nx * x));
|
bases[x * components + nx] = std::cos(scale * float(nx * x));
|
||||||
|
@ -323,7 +321,7 @@ encode(unsigned char *image, size_t width, size_t height, int components_x, int
|
||||||
srgbToLinear(image[3 * x + 2 + y * width * 3])};
|
srgbToLinear(image[3 * x + 2 + y * width * 3])};
|
||||||
|
|
||||||
// other half of normalization.
|
// other half of normalization.
|
||||||
linear *= 1.f / width;
|
linear *= 1.f / static_cast<float>(width);
|
||||||
|
|
||||||
for (size_t ny = 0; ny < size_t(components_y); ny++) {
|
for (size_t ny = 0; ny < size_t(components_y); ny++) {
|
||||||
for (size_t nx = 0; nx < size_t(components_x); nx++) {
|
for (size_t nx = 0; nx < size_t(components_x); nx++) {
|
||||||
|
@ -339,7 +337,7 @@ encode(unsigned char *image, size_t width, size_t height, int components_x, int
|
||||||
// too far outside the float range.
|
// too far outside the float range.
|
||||||
for (size_t i = 0; i < factors.size(); i++) {
|
for (size_t i = 0; i < factors.size(); i++) {
|
||||||
float normalisation = (i == 0) ? 1 : 2;
|
float normalisation = (i == 0) ? 1 : 2;
|
||||||
float scale = normalisation / (height);
|
float scale = normalisation / static_cast<float>(height);
|
||||||
factors[i] *= scale;
|
factors[i] *= scale;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue