Reserve size of some containers we are filling

This commit is contained in:
Nicolas Werner 2021-12-29 06:01:38 +01:00
parent 812e3b5f03
commit 19dc6cadea
No known key found for this signature in database
GPG key ID: C8D75E610773F2D9
31 changed files with 317 additions and 209 deletions

View file

@ -224,13 +224,13 @@ Cache::setup()
// Previous location of the cache directory
auto oldCache =
QStringLiteral("%1/%2%3").arg(QStandardPaths::writableLocation(QStandardPaths::CacheLocation),
QString::fromUtf8(localUserId_.toUtf8().toHex()),
QString::fromUtf8(settings->profile().toUtf8().toHex()));
QString::fromUtf8(localUserId_.toUtf8().toHex()),
QString::fromUtf8(settings->profile().toUtf8().toHex()));
cacheDirectory_ =
QStringLiteral("%1/%2%3").arg(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation),
QString::fromUtf8(localUserId_.toUtf8().toHex()),
QString::fromUtf8(settings->profile().toUtf8().toHex()));
cacheDirectory_ = QStringLiteral("%1/%2%3").arg(
QStandardPaths::writableLocation(QStandardPaths::AppDataLocation),
QString::fromUtf8(localUserId_.toUtf8().toHex()),
QString::fromUtf8(settings->profile().toUtf8().toHex()));
bool isInitial = !QFile::exists(cacheDirectory_);

View file

@ -1325,7 +1325,8 @@ ChatPage::handleMatrixUri(QString uri)
if (item.startsWith(QLatin1String("action="))) {
action = item.remove(QStringLiteral("action="));
} else if (item.startsWith(QLatin1String("via="))) {
vias.push_back(QUrl::fromPercentEncoding(item.remove(QStringLiteral("via=")).toUtf8()).toStdString());
vias.push_back(QUrl::fromPercentEncoding(item.remove(QStringLiteral("via=")).toUtf8())
.toStdString());
}
}

View file

@ -56,7 +56,8 @@ CombinedImagePackModel::data(const QModelIndex &index, int role) const
if (hasIndex(index.row(), index.column(), index.parent())) {
switch (role) {
case CompletionModel::CompletionRole:
return QStringLiteral("<img data-mx-emoticon height=32 src=\"%1\" alt=\"%2\" title=\"%2\">")
return QStringLiteral(
"<img data-mx-emoticon height=32 src=\"%1\" alt=\"%2\" title=\"%2\">")
.arg(QString::fromStdString(images[index.row()].image.url).toHtmlEscaped(),
QString::fromStdString(images[index.row()].image.body));
case Roles::Url:

View file

@ -396,7 +396,9 @@ mtx::accessors::formattedBodyWithFallback(const mtx::events::collections::Timeli
if (!formatted.empty())
return QString::fromStdString(formatted);
else
return QString::fromStdString(body(event)).toHtmlEscaped().replace(QLatin1String("\n"), QLatin1String("<br>"));
return QString::fromStdString(body(event))
.toHtmlEscaped()
.replace(QLatin1String("\n"), QLatin1String("<br>"));
}
std::optional<mtx::crypto::EncryptedFile>

View file

@ -15,6 +15,7 @@ ImagePackListModel::ImagePackListModel(const std::string &roomId, QObject *paren
{
auto packs_ = cache::client()->getImagePacks(room_id, std::nullopt);
packs.reserve(packs_.size());
for (const auto &pack : packs_) {
packs.push_back(QSharedPointer<SingleImagePackModel>(new SingleImagePackModel(pack)));
}

View file

@ -76,14 +76,15 @@ QStringList
InviteesModel::mxids()
{
QStringList mxidList;
for (int i = 0; i < invitees_.length(); ++i)
mxidList.push_back(invitees_[i]->mxid_);
mxidList.reserve(invitees_.size());
for (auto &invitee : qAsConst(invitees_))
mxidList.push_back(invitee->mxid_);
return mxidList;
}
Invitee::Invitee(const QString &mxid, QObject *parent)
Invitee::Invitee(QString mxid, QObject *parent)
: QObject{parent}
, mxid_{mxid}
, mxid_{std::move(mxid)}
{
http::client()->get_profile(
mxid_.toStdString(), [this](const mtx::responses::Profile &res, mtx::http::RequestErr err) {

View file

@ -13,7 +13,7 @@ class Invitee : public QObject
Q_OBJECT
public:
Invitee(const QString &mxid, QObject *parent = nullptr);
Invitee(QString mxid, QObject *parent = nullptr);
signals:
void userInfoLoaded();
@ -45,12 +45,13 @@ public:
Q_INVOKABLE void addUser(QString mxid);
Q_INVOKABLE void removeUser(QString mxid);
QHash<int, QByteArray> roleNames() const override;
int rowCount(const QModelIndex & = QModelIndex()) const override
[[nodiscard]] QHash<int, QByteArray> roleNames() const override;
[[nodiscard]] int rowCount(const QModelIndex & = QModelIndex()) const override
{
return (int)invitees_.size();
}
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
[[nodiscard]] QVariant
data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
QStringList mxids();
signals:

View file

@ -261,7 +261,8 @@ void
MainWindow::closeEvent(QCloseEvent *event)
{
if (WebRTCSession::instance().state() != webrtc::State::DISCONNECTED) {
if (QMessageBox::question(this, QStringLiteral("nheko"), QStringLiteral("A call is in progress. Quit?")) !=
if (QMessageBox::question(
this, QStringLiteral("nheko"), QStringLiteral("A call is in progress. Quit?")) !=
QMessageBox::Yes) {
event->ignore();
return;

View file

@ -255,7 +255,8 @@ MxcImageProvider::download(const QString &id,
image = clipRadius(std::move(image), radius);
}
image.setText(QStringLiteral("original filename"), QString::fromStdString(originalFilename));
image.setText(QStringLiteral("original filename"),
QString::fromStdString(originalFilename));
image.setText(QStringLiteral("mxc url"), "mxc://" + id);
then(id, requestedSize, image, fileInfo.absoluteFilePath());
return;
@ -266,7 +267,8 @@ MxcImageProvider::download(const QString &id,
image = clipRadius(std::move(image), radius);
}
image.setText(QStringLiteral("original filename"), QString::fromStdString(originalFilename));
image.setText(QStringLiteral("original filename"),
QString::fromStdString(originalFilename));
image.setText(QStringLiteral("mxc url"), "mxc://" + id);
then(id, requestedSize, image, fileInfo.absoluteFilePath());
});

View file

@ -112,8 +112,9 @@ ReadReceiptsModel::dateFormat(const QDateTime &then) const
else if (days < 7)
//: %1 is the name of the current day, %2 is the time the read receipt was read. The
//: result may look like this: Monday, 7:15
return QStringLiteral("%1, %2").arg(then.toString(QStringLiteral("dddd")),
QLocale::system().toString(then.time(), QLocale::ShortFormat));
return QStringLiteral("%1, %2").arg(
then.toString(QStringLiteral("dddd")),
QLocale::system().toString(then.time(), QLocale::ShortFormat));
return QLocale::system().toString(then.time(), QLocale::ShortFormat);
}

View file

@ -364,7 +364,10 @@ RegisterPage::doRegistration()
disconnect(UIA::instance(), &UIA::error, this, nullptr);
});
http::client()->registration(
username, password, ::UIA::instance()->genericHandler(QStringLiteral("Registration")), registrationCb());
username,
password,
::UIA::instance()->genericHandler(QStringLiteral("Registration")),
registrationCb());
}
}

View file

@ -29,6 +29,7 @@ SingleImagePackModel::SingleImagePackModel(ImagePackInfo pack_, QObject *parent)
if (!pack.pack)
pack.pack = mtx::events::msc2545::ImagePack::PackDescription{};
shortcodes.reserve(pack.images.size());
for (const auto &e : pack.images)
shortcodes.push_back(e.first);

View file

@ -63,55 +63,70 @@ UserSettings::load(std::optional<QString> profile)
tray_ = settings.value(QStringLiteral("user/window/tray"), false).toBool();
startInTray_ = settings.value(QStringLiteral("user/window/start_in_tray"), false).toBool();
roomListWidth_ = settings.value(QStringLiteral("user/sidebar/room_list_width"), -1).toInt();
communityListWidth_ = settings.value(QStringLiteral("user/sidebar/community_list_width"), -1).toInt();
roomListWidth_ = settings.value(QStringLiteral("user/sidebar/room_list_width"), -1).toInt();
communityListWidth_ =
settings.value(QStringLiteral("user/sidebar/community_list_width"), -1).toInt();
hasDesktopNotifications_ = settings.value(QStringLiteral("user/desktop_notifications"), true).toBool();
hasAlertOnNotification_ = settings.value(QStringLiteral("user/alert_on_notification"), false).toBool();
groupView_ = settings.value(QStringLiteral("user/group_view"), true).toBool();
buttonsInTimeline_ = settings.value(QStringLiteral("user/timeline/buttons"), true).toBool();
timelineMaxWidth_ = settings.value(QStringLiteral("user/timeline/max_width"), 0).toInt();
hasDesktopNotifications_ =
settings.value(QStringLiteral("user/desktop_notifications"), true).toBool();
hasAlertOnNotification_ =
settings.value(QStringLiteral("user/alert_on_notification"), false).toBool();
groupView_ = settings.value(QStringLiteral("user/group_view"), true).toBool();
buttonsInTimeline_ = settings.value(QStringLiteral("user/timeline/buttons"), true).toBool();
timelineMaxWidth_ = settings.value(QStringLiteral("user/timeline/max_width"), 0).toInt();
messageHoverHighlight_ =
settings.value(QStringLiteral("user/timeline/message_hover_highlight"), false).toBool();
enlargeEmojiOnlyMessages_ =
settings.value(QStringLiteral("user/timeline/enlarge_emoji_only_msg"), false).toBool();
markdown_ = settings.value(QStringLiteral("user/markdown_enabled"), true).toBool();
animateImagesOnHover_ = settings.value(QStringLiteral("user/animate_images_on_hover"), false).toBool();
typingNotifications_ = settings.value(QStringLiteral("user/typing_notifications"), true).toBool();
sortByImportance_ = settings.value(QStringLiteral("user/sort_by_unread"), true).toBool();
readReceipts_ = settings.value(QStringLiteral("user/read_receipts"), true).toBool();
theme_ = settings.value(QStringLiteral("user/theme"), defaultTheme_).toString();
font_ = settings.value(QStringLiteral("user/font_family"), "default").toString();
avatarCircles_ = settings.value(QStringLiteral("user/avatar_circles"), true).toBool();
useIdenticon_ = settings.value(QStringLiteral("user/use_identicon"), true).toBool();
decryptSidebar_ = settings.value(QStringLiteral("user/decrypt_sidebar"), true).toBool();
privacyScreen_ = settings.value(QStringLiteral("user/privacy_screen"), false).toBool();
privacyScreenTimeout_ = settings.value(QStringLiteral("user/privacy_screen_timeout"), 0).toInt();
mobileMode_ = settings.value(QStringLiteral("user/mobile_mode"), false).toBool();
emojiFont_ = settings.value(QStringLiteral("user/emoji_font_family"), "default").toString();
baseFontSize_ = settings.value(QStringLiteral("user/font_size"), QFont().pointSizeF()).toDouble();
auto tempPresence = settings.value(QStringLiteral("user/presence"), "").toString().toStdString();
auto presenceValue = QMetaEnum::fromType<Presence>().keyToValue(tempPresence.c_str());
markdown_ = settings.value(QStringLiteral("user/markdown_enabled"), true).toBool();
animateImagesOnHover_ =
settings.value(QStringLiteral("user/animate_images_on_hover"), false).toBool();
typingNotifications_ =
settings.value(QStringLiteral("user/typing_notifications"), true).toBool();
sortByImportance_ = settings.value(QStringLiteral("user/sort_by_unread"), true).toBool();
readReceipts_ = settings.value(QStringLiteral("user/read_receipts"), true).toBool();
theme_ = settings.value(QStringLiteral("user/theme"), defaultTheme_).toString();
font_ = settings.value(QStringLiteral("user/font_family"), "default").toString();
avatarCircles_ = settings.value(QStringLiteral("user/avatar_circles"), true).toBool();
useIdenticon_ = settings.value(QStringLiteral("user/use_identicon"), true).toBool();
decryptSidebar_ = settings.value(QStringLiteral("user/decrypt_sidebar"), true).toBool();
privacyScreen_ = settings.value(QStringLiteral("user/privacy_screen"), false).toBool();
privacyScreenTimeout_ =
settings.value(QStringLiteral("user/privacy_screen_timeout"), 0).toInt();
mobileMode_ = settings.value(QStringLiteral("user/mobile_mode"), false).toBool();
emojiFont_ = settings.value(QStringLiteral("user/emoji_font_family"), "default").toString();
baseFontSize_ =
settings.value(QStringLiteral("user/font_size"), QFont().pointSizeF()).toDouble();
auto tempPresence =
settings.value(QStringLiteral("user/presence"), "").toString().toStdString();
auto presenceValue = QMetaEnum::fromType<Presence>().keyToValue(tempPresence.c_str());
if (presenceValue < 0)
presenceValue = 0;
presence_ = static_cast<Presence>(presenceValue);
ringtone_ = settings.value(QStringLiteral("user/ringtone"), "Default").toString();
microphone_ = settings.value(QStringLiteral("user/microphone"), QString()).toString();
camera_ = settings.value(QStringLiteral("user/camera"), QString()).toString();
cameraResolution_ = settings.value(QStringLiteral("user/camera_resolution"), QString()).toString();
cameraFrameRate_ = settings.value(QStringLiteral("user/camera_frame_rate"), QString()).toString();
screenShareFrameRate_ = settings.value(QStringLiteral("user/screen_share_frame_rate"), 5).toInt();
screenSharePiP_ = settings.value(QStringLiteral("user/screen_share_pip"), true).toBool();
screenShareRemoteVideo_ = settings.value(QStringLiteral("user/screen_share_remote_video"), false).toBool();
screenShareHideCursor_ = settings.value(QStringLiteral("user/screen_share_hide_cursor"), false).toBool();
useStunServer_ = settings.value(QStringLiteral("user/use_stun_server"), false).toBool();
presence_ = static_cast<Presence>(presenceValue);
ringtone_ = settings.value(QStringLiteral("user/ringtone"), "Default").toString();
microphone_ = settings.value(QStringLiteral("user/microphone"), QString()).toString();
camera_ = settings.value(QStringLiteral("user/camera"), QString()).toString();
cameraResolution_ =
settings.value(QStringLiteral("user/camera_resolution"), QString()).toString();
cameraFrameRate_ =
settings.value(QStringLiteral("user/camera_frame_rate"), QString()).toString();
screenShareFrameRate_ =
settings.value(QStringLiteral("user/screen_share_frame_rate"), 5).toInt();
screenSharePiP_ = settings.value(QStringLiteral("user/screen_share_pip"), true).toBool();
screenShareRemoteVideo_ =
settings.value(QStringLiteral("user/screen_share_remote_video"), false).toBool();
screenShareHideCursor_ =
settings.value(QStringLiteral("user/screen_share_hide_cursor"), false).toBool();
useStunServer_ = settings.value(QStringLiteral("user/use_stun_server"), false).toBool();
if (profile) // set to "" if it's the default to maintain compatibility
profile_ = (*profile == QLatin1String("default")) ? QLatin1String("") : *profile;
else
profile_ = settings.value(QStringLiteral("user/currentProfile"), "").toString();
QString prefix = (profile_ != QLatin1String("") && profile_ != QLatin1String("default")) ? "profile/" + profile_ + "/" : QLatin1String("");
QString prefix = (profile_ != QLatin1String("") && profile_ != QLatin1String("default"))
? "profile/" + profile_ + "/"
: QLatin1String("");
accessToken_ = settings.value(prefix + "auth/access_token", "").toString();
homeserver_ = settings.value(prefix + "auth/home_server", "").toString();
userId_ = settings.value(prefix + "auth/user_id", "").toString();
@ -714,7 +729,9 @@ UserSettings::save()
settings.endGroup(); // user
QString prefix = (profile_ != QLatin1String("") && profile_ != QLatin1String("default")) ? "profile/" + profile_ + "/" : QLatin1String("");
QString prefix = (profile_ != QLatin1String("") && profile_ != QLatin1String("default"))
? "profile/" + profile_ + "/"
: QLatin1String("");
settings.setValue(prefix + "auth/access_token", accessToken_);
settings.setValue(prefix + "auth/home_server", homeserver_);
settings.setValue(prefix + "auth/user_id", userId_);
@ -730,11 +747,13 @@ UserSettings::save()
settings.setValue(prefix + "user/recent_reactions", recentReactions_);
QVariantList v;
v.reserve(collapsedSpaces_.size());
for (const auto &e : qAsConst(collapsedSpaces_))
v.push_back(e);
settings.setValue(prefix + "user/collapsed_spaces", v);
settings.setValue(QStringLiteral("disable_certificate_validation"), disableCertificateValidation_);
settings.setValue(QStringLiteral("disable_certificate_validation"),
disableCertificateValidation_);
settings.sync();
}
@ -959,20 +978,21 @@ UserSettingsPage::UserSettingsPage(QSharedPointer<UserSettings> settings, QWidge
crossSigningKeysLayout->addWidget(crossSigningRequestBtn, 0, Qt::AlignRight);
crossSigningKeysLayout->addWidget(crossSigningDownloadBtn, 0, Qt::AlignRight);
auto boxWrap = [this, &font](QString labelText, QWidget *field, QString tooltipText = QLatin1String("")) {
auto label = new QLabel{labelText, this};
label->setFont(font);
label->setMargin(OptionMargin);
auto boxWrap =
[this, &font](QString labelText, QWidget *field, QString tooltipText = QLatin1String("")) {
auto label = new QLabel{labelText, this};
label->setFont(font);
label->setMargin(OptionMargin);
if (!tooltipText.isEmpty()) {
label->setToolTip(tooltipText);
}
if (!tooltipText.isEmpty()) {
label->setToolTip(tooltipText);
}
auto layout = new QHBoxLayout;
layout->addWidget(field, 0, Qt::AlignRight);
auto layout = new QHBoxLayout;
layout->addWidget(field, 0, Qt::AlignRight);
formLayout_->addRow(label, layout);
};
formLayout_->addRow(label, layout);
};
formLayout_->addRow(general_);
formLayout_->addRow(new HorizontalLine{this});
@ -1087,7 +1107,8 @@ UserSettingsPage::UserSettingsPage(QSharedPointer<UserSettings> settings, QWidge
ringtoneCombo_->addItem(QStringLiteral("Default"));
ringtoneCombo_->addItem(QStringLiteral("Other..."));
const QString &ringtone = settings_->ringtone();
if (!ringtone.isEmpty() && ringtone != QLatin1String("Mute") && ringtone != QLatin1String("Default"))
if (!ringtone.isEmpty() && ringtone != QLatin1String("Mute") &&
ringtone != QLatin1String("Default"))
ringtoneCombo_->addItem(ringtone);
microphoneCombo_->setSizeAdjustPolicy(QComboBox::AdjustToContents);
cameraCombo_->setSizeAdjustPolicy(QComboBox::AdjustToContents);
@ -1186,32 +1207,32 @@ UserSettingsPage::UserSettingsPage(QSharedPointer<UserSettings> settings, QWidge
this,
[this](const QString &family) { settings_->setEmojiFontFamily(family.trimmed()); });
connect(ringtoneCombo_,
static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::currentTextChanged),
this,
[this](const QString &ringtone) {
if (ringtone == QLatin1String("Other...")) {
QString homeFolder =
QStandardPaths::writableLocation(QStandardPaths::HomeLocation);
auto filepath = QFileDialog::getOpenFileName(
this, tr("Select a file"), homeFolder, tr("All Files (*)"));
if (!filepath.isEmpty()) {
const auto &oldSetting = settings_->ringtone();
if (oldSetting != QLatin1String("Mute") && oldSetting != QLatin1String("Default"))
ringtoneCombo_->removeItem(ringtoneCombo_->findText(oldSetting));
settings_->setRingtone(filepath);
ringtoneCombo_->addItem(filepath);
ringtoneCombo_->setCurrentText(filepath);
} else {
ringtoneCombo_->setCurrentText(settings_->ringtone());
}
} else if (ringtone == QLatin1String("Mute") || ringtone == QLatin1String("Default")) {
const auto &oldSetting = settings_->ringtone();
if (oldSetting != QLatin1String("Mute") && oldSetting != QLatin1String("Default"))
ringtoneCombo_->removeItem(ringtoneCombo_->findText(oldSetting));
settings_->setRingtone(ringtone);
}
});
connect(
ringtoneCombo_,
static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::currentTextChanged),
this,
[this](const QString &ringtone) {
if (ringtone == QLatin1String("Other...")) {
QString homeFolder = QStandardPaths::writableLocation(QStandardPaths::HomeLocation);
auto filepath = QFileDialog::getOpenFileName(
this, tr("Select a file"), homeFolder, tr("All Files (*)"));
if (!filepath.isEmpty()) {
const auto &oldSetting = settings_->ringtone();
if (oldSetting != QLatin1String("Mute") && oldSetting != QLatin1String("Default"))
ringtoneCombo_->removeItem(ringtoneCombo_->findText(oldSetting));
settings_->setRingtone(filepath);
ringtoneCombo_->addItem(filepath);
ringtoneCombo_->setCurrentText(filepath);
} else {
ringtoneCombo_->setCurrentText(settings_->ringtone());
}
} else if (ringtone == QLatin1String("Mute") || ringtone == QLatin1String("Default")) {
const auto &oldSetting = settings_->ringtone();
if (oldSetting != QLatin1String("Mute") && oldSetting != QLatin1String("Default"))
ringtoneCombo_->removeItem(ringtoneCombo_->findText(oldSetting));
settings_->setRingtone(ringtone);
}
});
connect(microphoneCombo_,
static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::currentTextChanged),

View file

@ -291,10 +291,11 @@ signals:
private:
// Default to system theme if QT_QPA_PLATFORMTHEME var is set.
QString defaultTheme_ =
QProcessEnvironment::systemEnvironment().value(QStringLiteral("QT_QPA_PLATFORMTHEME"), QLatin1String("")).isEmpty()
? "light"
: "system";
QString defaultTheme_ = QProcessEnvironment::systemEnvironment()
.value(QStringLiteral("QT_QPA_PLATFORMTHEME"), QLatin1String(""))
.isEmpty()
? "light"
: "system";
QString theme_;
bool messageHoverHighlight_;
bool enlargeEmojiOnlyMessages_;

View file

@ -237,8 +237,8 @@ utils::getMessageDescription(const TimelineEvent &event,
DescInfo info;
info.userid = sender;
info.body =
QStringLiteral(" %1").arg(messageDescription<Encrypted>(username, QLatin1String(""), sender == localUser));
info.body = QStringLiteral(" %1").arg(
messageDescription<Encrypted>(username, QLatin1String(""), sender == localUser));
info.timestamp = msg->origin_server_ts;
info.descriptiveTime = utils::descriptiveTime(ts);
info.event_id = QString::fromStdString(msg->event_id);
@ -402,8 +402,9 @@ utils::linkifyMessage(const QString &body)
// Convert to valid XML.
auto doc = body;
doc.replace(conf::strings::url_regex, conf::strings::url_html);
doc.replace(QRegularExpression(QStringLiteral("\\b(?<![\"'])(?>(matrix:[\\S]{5,}))(?![\"'])\\b")),
conf::strings::url_html);
doc.replace(
QRegularExpression(QStringLiteral("\\b(?<![\"'])(?>(matrix:[\\S]{5,}))(?![\"'])\\b")),
conf::strings::url_html);
return doc;
}
@ -555,7 +556,8 @@ utils::markdownToHtml(const QString &text, bool rainbowify)
auto result = linkifyMessage(escapeBlacklistedHtml(QString::fromStdString(html))).trimmed();
if (result.count(QStringLiteral("<p>")) == 1 && result.startsWith(QLatin1String("<p>")) && result.endsWith(QLatin1String("</p>"))) {
if (result.count(QStringLiteral("<p>")) == 1 && result.startsWith(QLatin1String("<p>")) &&
result.endsWith(QLatin1String("</p>"))) {
result = result.mid(3, result.size() - 3 - 4);
}

View file

@ -1220,6 +1220,7 @@ send_encrypted_to_device_messages(const std::map<std::string, std::vector<std::s
auto deviceTargets = devices;
if (devices.empty()) {
deviceTargets.clear();
deviceTargets.reserve(deviceKeys->device_keys.size());
for (const auto &[device, keys] : deviceKeys->device_keys) {
(void)keys;
deviceTargets.push_back(device);

View file

@ -185,8 +185,7 @@ main(int argc, char *argv[])
// name is set. It only exists to keep Qt from complaining about the --profile/-p
// option and thereby crashing the app.
QCommandLineOption configName(
QStringList() << QStringLiteral("p")
<< QStringLiteral("profile"),
QStringList() << QStringLiteral("p") << QStringLiteral("profile"),
QCoreApplication::tr("Create a unique profile, which allows you to log into several "
"accounts at the same time and start multiple instances of nheko."),
QCoreApplication::tr("profile"),
@ -252,11 +251,15 @@ main(int argc, char *argv[])
QLocale::setDefault(QLocale(QLocale::English, QLocale::UnitedKingdom));
QTranslator qtTranslator;
qtTranslator.load(QLocale(), QStringLiteral("qt"), QStringLiteral("_"), QLibraryInfo::location(QLibraryInfo::TranslationsPath));
qtTranslator.load(QLocale(),
QStringLiteral("qt"),
QStringLiteral("_"),
QLibraryInfo::location(QLibraryInfo::TranslationsPath));
app.installTranslator(&qtTranslator);
QTranslator appTranslator;
appTranslator.load(QLocale(), QStringLiteral("nheko"), QStringLiteral("_"), QStringLiteral(":/translations"));
appTranslator.load(
QLocale(), QStringLiteral("nheko"), QStringLiteral("_"), QStringLiteral(":/translations"));
app.installTranslator(&appTranslator);
MainWindow w;
@ -304,7 +307,8 @@ main(int argc, char *argv[])
QObject::disconnect(uriConnection);
});
}
QDesktopServices::setUrlHandler(QStringLiteral("matrix"), ChatPage::instance(), "handleMatrixUri");
QDesktopServices::setUrlHandler(
QStringLiteral("matrix"), ChatPage::instance(), "handleMatrixUri");
#if defined(Q_OS_MAC)
// Temporary solution for the emoji picker until

View file

@ -108,7 +108,8 @@ NotificationsManager::postNotification(const mtx::responses::Notification &notif
if (hasImages_ &&
mtx::accessors::msg_type(notification.event) == mtx::events::MessageType::Image) {
MxcImageProvider::download(
QString::fromStdString(mtx::accessors::url(notification.event)).remove(QStringLiteral("mxc://")),
QString::fromStdString(mtx::accessors::url(notification.event))
.remove(QStringLiteral("mxc://")),
QSize(200, 80),
[postNotif, notification, template_](QString, QSize, QImage, QString imgPath) {
if (imgPath.isEmpty())
@ -184,9 +185,9 @@ NotificationsManager::systemPostNotification(const QString &room_id,
// TODO(Nico): Look into what to actually put there.
argumentList << (QStringList(QStringLiteral("default"))
<< QLatin1String("") << QStringLiteral("inline-reply")
<< QLatin1String("")); // actions
argumentList << hints; // hints
argumentList << (int)-1; // timeout in ms
<< QLatin1String("")); // actions
argumentList << hints; // hints
argumentList << (int)-1; // timeout in ms
QDBusPendingCall call = dbus.asyncCallWithArgumentList(QStringLiteral("Notify"), argumentList);
auto watcher = new QDBusPendingCallWatcher{call, this};

View file

@ -293,6 +293,7 @@ CommunitiesModel::FlatTree::storeCollapsed()
int depth = -1;
QStringList current;
elements.reserve(static_cast<int>(tree.size()));
for (const auto &e : tree) {
if (e.depth > depth) {

View file

@ -527,6 +527,7 @@ EventStore::reactions(const std::string &event_id)
}
QVariantList temp;
temp.reserve(static_cast<int>(reactions.size()));
for (auto &reaction : reactions) {
const auto &agg = aggregation[reaction.key_.toStdString()];
reaction.count_ = agg.count;

View file

@ -56,7 +56,8 @@ InputBar::insertMimeData(const QMimeData *md)
if (!md)
return;
nhlog::ui()->debug("Got mime formats: {}", md->formats().join(QStringLiteral(", ")).toStdString());
nhlog::ui()->debug("Got mime formats: {}",
md->formats().join(QStringLiteral(", ")).toStdString());
const auto formats = md->formats().filter(QStringLiteral("/"));
const auto image = formats.filter(QStringLiteral("image/"), Qt::CaseInsensitive);
const auto audio = formats.filter(QStringLiteral("audio/"), Qt::CaseInsensitive);
@ -140,7 +141,8 @@ InputBar::updateAtRoom(const QString &t)
auto start = finder.position();
finder.toNextBoundary();
auto end = finder.position();
if (start > 0 && end - start >= 4 && t.mid(start, end - start) == QLatin1String("room") &&
if (start > 0 && end - start >= 4 &&
t.mid(start, end - start) == QLatin1String("room") &&
t.at(start - 1) == QChar('@')) {
roomMention = true;
break;
@ -660,13 +662,15 @@ InputBar::showPreview(const QMimeData &source, const QString &path, const QStrin
previewDialog_->setAttribute(Qt::WA_DeleteOnClose);
// Force SVG to _not_ be handled as an image, but as raw data
if (source.hasImage() && (formats.empty() || formats.front() != QLatin1String("image/svg+xml"))) {
if (source.hasImage() &&
(formats.empty() || formats.front() != QLatin1String("image/svg+xml"))) {
if (!formats.empty() && formats.front().startsWith(QLatin1String("image/"))) {
// known format, keep as-is
previewDialog_->setPreview(qvariant_cast<QImage>(source.imageData()), formats.front());
} else {
// unknown image format, default to image/png
previewDialog_->setPreview(qvariant_cast<QImage>(source.imageData()), QStringLiteral("image/png"));
previewDialog_->setPreview(qvariant_cast<QImage>(source.imageData()),
QStringLiteral("image/png"));
}
} else if (!path.isEmpty())
previewDialog_->setPreview(path);

View file

@ -90,6 +90,7 @@ RoomlistModel::data(const QModelIndex &index, int role) const
if (role == Roles::ParentSpaces) {
auto parents = cache::client()->getParentRoomIds(roomid.toStdString());
QStringList list;
list.reserve(static_cast<int>(parents.size()));
for (const auto &t : parents)
list.push_back(QString::fromStdString(t));
return list;
@ -98,7 +99,8 @@ RoomlistModel::data(const QModelIndex &index, int role) const
} else if (role == Roles::IsDirect) {
return directChatToUser.count(roomid) > 0;
} else if (role == Roles::DirectChatOtherUserId) {
return directChatToUser.count(roomid) ? directChatToUser.at(roomid).front() : QLatin1String("");
return directChatToUser.count(roomid) ? directChatToUser.at(roomid).front()
: QLatin1String("");
}
if (models.contains(roomid)) {
@ -113,7 +115,7 @@ RoomlistModel::data(const QModelIndex &index, int role) const
case Roles::Time:
return room->lastMessage().descriptiveTime;
case Roles::Timestamp:
return QVariant(static_cast<quint64>(room->lastMessage().timestamp));
return QVariant{static_cast<quint64>(room->lastMessage().timestamp)};
case Roles::HasUnreadMessages:
return this->roomReadStatus.count(roomid) && this->roomReadStatus.at(roomid);
case Roles::HasLoudNotification:
@ -129,6 +131,7 @@ RoomlistModel::data(const QModelIndex &index, int role) const
case Roles::Tags: {
auto info = cache::singleRoomInfo(roomid.toStdString());
QStringList list;
list.reserve(static_cast<int>(info.tags.size()));
for (const auto &t : info.tags)
list.push_back(QString::fromStdString(t));
return list;
@ -148,7 +151,7 @@ RoomlistModel::data(const QModelIndex &index, int role) const
case Roles::Time:
return QString();
case Roles::Timestamp:
return QVariant(static_cast<quint64>(0));
return QVariant{static_cast<quint64>(0)};
case Roles::HasUnreadMessages:
case Roles::HasLoudNotification:
return false;
@ -177,7 +180,7 @@ RoomlistModel::data(const QModelIndex &index, int role) const
case Roles::Time:
return QString();
case Roles::Timestamp:
return QVariant(static_cast<quint64>(0));
return QVariant{static_cast<quint64>(0)};
case Roles::HasUnreadMessages:
case Roles::HasLoudNotification:
return false;

View file

@ -159,7 +159,8 @@ public slots:
}
void joinPreview(QString roomid)
{
roomlistmodel->joinPreview(roomid, filterType == FilterBy::Space ? filterStr : QLatin1String(""));
roomlistmodel->joinPreview(roomid,
filterType == FilterBy::Space ? filterStr : QLatin1String(""));
}
void acceptInvite(QString roomid) { roomlistmodel->acceptInvite(roomid); }
void declineInvite(QString roomid) { roomlistmodel->declineInvite(roomid); }

View file

@ -503,7 +503,7 @@ TimelineModel::data(const mtx::events::collections::TimelineEvents &event, int r
switch (role) {
case IsSender:
return QVariant(acc::sender(event) == http::client()->user_id().to_string());
return {acc::sender(event) == http::client()->user_id().to_string()};
case UserId:
return QVariant(QString::fromStdString(acc::sender(event)));
case UserName:
@ -512,12 +512,12 @@ TimelineModel::data(const mtx::events::collections::TimelineEvents &event, int r
case Day: {
QDateTime prevDate = origin_server_ts(event);
prevDate.setTime(QTime());
return QVariant(prevDate.toMSecsSinceEpoch());
return {prevDate.toMSecsSinceEpoch()};
}
case Timestamp:
return QVariant(origin_server_ts(event));
case Type:
return QVariant(toRoomEventType(event));
return {toRoomEventType(event)};
case TypeString:
return QVariant(toRoomEventTypeString(event));
case IsOnlyEmoji: {
@ -530,17 +530,18 @@ TimelineModel::data(const mtx::events::collections::TimelineEvents &event, int r
if (utils::codepointIsEmoji(code)) {
emojiCount++;
} else {
return QVariant(0);
return {0};
}
}
return QVariant(emojiCount);
return {emojiCount};
}
case Body:
return QVariant(utils::replaceEmoji(QString::fromStdString(body(event)).toHtmlEscaped()));
case FormattedBody: {
const static QRegularExpression replyFallback(
QStringLiteral("<mx-reply>.*</mx-reply>"), QRegularExpression::DotMatchesEverythingOption);
QStringLiteral("<mx-reply>.*</mx-reply>"),
QRegularExpression::DotMatchesEverythingOption);
auto ascent = QFontMetrics(UserSettings::instance()->font()).ascent();
@ -574,7 +575,8 @@ TimelineModel::data(const mtx::events::collections::TimelineEvents &event, int r
// Construct image parameters later used by MxcImageProvider.
QString imgParams;
if (curImg.contains(QLatin1String("height"))) {
const static QRegularExpression matchImgHeight(QStringLiteral("height=([\"\']?)(\\d+)([\"\']?)"));
const static QRegularExpression matchImgHeight(
QStringLiteral("height=([\"\']?)(\\d+)([\"\']?)"));
// Make emoticons twice as high as the font.
if (curImg.contains(QLatin1String("data-mx-emoticon"))) {
imgReplacement =
@ -587,11 +589,11 @@ TimelineModel::data(const mtx::events::collections::TimelineEvents &event, int r
// Replace src in current <img>.
const static QRegularExpression matchImgUri(QStringLiteral("src=\"mxc://([^\"]*)\""));
imgReplacement.replace(matchImgUri,
QString("src=\"image://mxcImage/\\1%1\"").arg(imgParams));
QStringLiteral(R"(src="image://mxcImage/\1%1")").arg(imgParams));
// Same regex but for single quotes around the src
const static QRegularExpression matchImgUri2(QStringLiteral("src=\'mxc://([^\']*)\'"));
imgReplacement.replace(matchImgUri2,
QString("src=\'image://mxcImage/\\1%1\'").arg(imgParams));
QStringLiteral("src=\'image://mxcImage/\\1%1\'").arg(imgParams));
// Replace <img> in formattedBody_ with our new <img>.
formattedBody_.replace(curImg, imgReplacement);
@ -623,7 +625,7 @@ TimelineModel::data(const mtx::events::collections::TimelineEvents &event, int r
double prop = media_height(event) / (double)w;
return QVariant(prop > 0 ? prop : 1.);
return {prop > 0 ? prop : 1.};
}
case EventId: {
if (auto replaces = relations(event).replaces())
@ -651,10 +653,10 @@ TimelineModel::data(const mtx::events::collections::TimelineEvents &event, int r
return qml_mtx_events::Received;
}
case IsEdited:
return QVariant(relations(event).replaces().has_value());
return {relations(event).replaces().has_value()};
case IsEditable:
return QVariant(!is_state_event(event) &&
mtx::accessors::sender(event) == http::client()->user_id().to_string());
return {!is_state_event(event) &&
mtx::accessors::sender(event) == http::client()->user_id().to_string()};
case IsEncrypted: {
auto id = event_id(event);
auto encrypted_event = events.get(id, "", false);
@ -693,8 +695,10 @@ TimelineModel::data(const mtx::events::collections::TimelineEvents &event, int r
return QVariant(
utils::replaceEmoji(QString::fromStdString(room_name(event)).toHtmlEscaped()));
case RoomTopic:
return QVariant(utils::replaceEmoji(utils::linkifyMessage(
QString::fromStdString(room_topic(event)).toHtmlEscaped().replace(QLatin1String("\n"), QLatin1String("<br>")))));
return QVariant(utils::replaceEmoji(
utils::linkifyMessage(QString::fromStdString(room_topic(event))
.toHtmlEscaped()
.replace(QLatin1String("\n"), QLatin1String("<br>")))));
case CallType:
return QVariant(QString::fromStdString(call_type(event)));
case Dump: {
@ -736,7 +740,7 @@ TimelineModel::data(const mtx::events::collections::TimelineEvents &event, int r
case RelatedEventCacheBuster:
return relatedEventCacheBuster;
default:
return QVariant();
return {};
}
}
@ -746,7 +750,7 @@ TimelineModel::data(const QModelIndex &index, int role) const
using namespace mtx::accessors;
namespace acc = mtx::accessors;
if (index.row() < 0 && index.row() >= rowCount())
return QVariant();
return {};
// HACK(Nico): fetchMore likes to break with dynamically sized delegates and reuseItems
if (index.row() + 1 == rowCount() && !m_paginationInProgress)
@ -760,10 +764,10 @@ TimelineModel::data(const QModelIndex &index, int role) const
if (role == PreviousMessageDay || role == PreviousMessageUserId) {
int prevIdx = rowCount() - index.row() - 2;
if (prevIdx < 0)
return QVariant();
return {};
auto tempEv = events.get(prevIdx);
if (!tempEv)
return QVariant();
return {};
if (role == PreviousMessageUserId)
return data(*tempEv, UserId);
else
@ -778,7 +782,7 @@ TimelineModel::dataById(const QString &id, int role, const QString &relatedTo)
{
if (auto event = events.get(id.toStdString(), relatedTo.toStdString()))
return data(*event, role);
return QVariant();
return {};
}
bool
@ -1623,7 +1627,7 @@ TimelineModel::cacheMedia(const QString &eventId,
void
TimelineModel::cacheMedia(const QString &eventId)
{
cacheMedia(eventId, NULL);
cacheMedia(eventId, nullptr);
}
void
@ -1739,7 +1743,7 @@ TimelineModel::formatTypingUsers(const std::vector<QString> &users, const QColor
(int)users.size());
if (users.empty()) {
return QString();
return {};
}
QStringList uidWithoutLast;
@ -1774,6 +1778,7 @@ TimelineModel::formatTypingUsers(const std::vector<QString> &users, const QColor
return coloredUsername;
};
uidWithoutLast.reserve(static_cast<int>(users.size()));
for (size_t i = 0; i + 1 < users.size(); i++) {
uidWithoutLast.append(formatUser(users[i]));
}
@ -1786,11 +1791,11 @@ TimelineModel::formatJoinRuleEvent(const QString &id)
{
mtx::events::collections::TimelineEvents *e = events.get(id.toStdString(), "");
if (!e)
return QString();
return {};
auto event = std::get_if<mtx::events::StateEvent<mtx::events::state::JoinRules>>(e);
if (!event)
return QString();
return {};
QString user = QString::fromStdString(event->sender);
QString name = utils::replaceEmoji(displayName(user));
@ -1814,7 +1819,7 @@ TimelineModel::formatJoinRuleEvent(const QString &id)
}
default:
// Currently, knock and private are reserved keywords and not implemented in Matrix.
return QString();
return {};
}
}
@ -1823,11 +1828,11 @@ TimelineModel::formatGuestAccessEvent(const QString &id)
{
mtx::events::collections::TimelineEvents *e = events.get(id.toStdString(), "");
if (!e)
return QString();
return {};
auto event = std::get_if<mtx::events::StateEvent<mtx::events::state::GuestAccess>>(e);
if (!event)
return QString();
return {};
QString user = QString::fromStdString(event->sender);
QString name = utils::replaceEmoji(displayName(user));
@ -1838,7 +1843,7 @@ TimelineModel::formatGuestAccessEvent(const QString &id)
case mtx::events::state::AccessState::Forbidden:
return tr("%1 has closed the room to guest access.").arg(name);
default:
return QString();
return {};
}
}
@ -1847,12 +1852,12 @@ TimelineModel::formatHistoryVisibilityEvent(const QString &id)
{
mtx::events::collections::TimelineEvents *e = events.get(id.toStdString(), "");
if (!e)
return QString();
return {};
auto event = std::get_if<mtx::events::StateEvent<mtx::events::state::HistoryVisibility>>(e);
if (!event)
return QString();
return {};
QString user = QString::fromStdString(event->sender);
QString name = utils::replaceEmoji(displayName(user));
@ -1870,7 +1875,7 @@ TimelineModel::formatHistoryVisibilityEvent(const QString &id)
return tr("%1 set the room history visible to members since they joined the room.")
.arg(name);
default:
return QString();
return {};
}
}
@ -1879,7 +1884,7 @@ TimelineModel::formatPowerLevelEvent(const QString &id)
{
mtx::events::collections::TimelineEvents *e = events.get(id.toStdString(), "");
if (!e)
return QString();
return {};
auto event = std::get_if<mtx::events::StateEvent<mtx::events::state::PowerLevels>>(e);
if (!event)
@ -1924,7 +1929,7 @@ TimelineModel::formatRedactedEvent(const QString &id)
} else {
pair[QStringLiteral("first")] = tr("Removed by %1 because: %2").arg(redactedName, reason);
pair[QStringLiteral("second")] = tr("%1 (%2) removed this message at %3\nReason: %4")
.arg(redactedName, redactedUser, dateTime, reason);
.arg(redactedName, redactedUser, dateTime, reason);
}
return pair;
@ -1980,11 +1985,11 @@ TimelineModel::formatMemberEvent(const QString &id)
{
mtx::events::collections::TimelineEvents *e = events.get(id.toStdString(), "");
if (!e)
return QString();
return {};
auto event = std::get_if<mtx::events::StateEvent<mtx::events::state::Member>>(e);
if (!event)
return QString();
return {};
mtx::events::StateEvent<mtx::events::state::Member> *prevEvent = nullptr;
if (!event->unsigned_data.replaces_state.empty()) {
@ -2038,7 +2043,7 @@ TimelineModel::formatMemberEvent(const QString &id)
break;
case Membership::Leave:
if (!prevEvent) // Should only ever happen temporarily
return QString();
return {};
if (prevEvent->content.membership == Membership::Invite) {
if (event->state_key == event->sender)
@ -2163,7 +2168,7 @@ TimelineModel::roomName() const
auto info = cache::getRoomInfo({room_id_.toStdString()});
if (!info.count(room_id_))
return QString();
return {};
else
return utils::replaceEmoji(QString::fromStdString(info[room_id_].name).toHtmlEscaped());
}
@ -2174,7 +2179,7 @@ TimelineModel::plainRoomName() const
auto info = cache::getRoomInfo({room_id_.toStdString()});
if (!info.count(room_id_))
return QString();
return {};
else
return QString::fromStdString(info[room_id_].name);
}
@ -2185,7 +2190,7 @@ TimelineModel::roomAvatarUrl() const
auto info = cache::getRoomInfo({room_id_.toStdString()});
if (!info.count(room_id_))
return QString();
return {};
else
return QString::fromStdString(info[room_id_].avatar_url);
}
@ -2196,7 +2201,7 @@ TimelineModel::roomTopic() const
auto info = cache::getRoomInfo({room_id_.toStdString()});
if (!info.count(room_id_))
return QString();
return {};
else
return utils::replaceEmoji(
utils::linkifyMessage(QString::fromStdString(info[room_id_].topic).toHtmlEscaped()));
@ -2244,5 +2249,5 @@ TimelineModel::directChatOtherUserId() const
id = member.user_id;
return id;
} else
return QString();
return {};
}

View file

@ -286,6 +286,7 @@ public:
{
auto list = events.reactions(event_id);
std::vector<::Reaction> vec;
vec.reserve(list.size());
for (const auto &r : list)
vec.push_back(r.value<Reaction>());
return vec;

View file

@ -103,10 +103,12 @@ TimelineViewManager::updateColorPalette()
if (ChatPage::instance()->userSettings()->theme() == QLatin1String("light")) {
view->rootContext()->setContextProperty(QStringLiteral("currentActivePalette"), QPalette());
view->rootContext()->setContextProperty(QStringLiteral("currentInactivePalette"), QPalette());
view->rootContext()->setContextProperty(QStringLiteral("currentInactivePalette"),
QPalette());
} else if (ChatPage::instance()->userSettings()->theme() == QLatin1String("dark")) {
view->rootContext()->setContextProperty(QStringLiteral("currentActivePalette"), QPalette());
view->rootContext()->setContextProperty(QStringLiteral("currentInactivePalette"), QPalette());
view->rootContext()->setContextProperty(QStringLiteral("currentInactivePalette"),
QPalette());
} else {
view->rootContext()->setContextProperty(QStringLiteral("currentActivePalette"), QPalette());
view->rootContext()->setContextProperty(QStringLiteral("currentInactivePalette"), nullptr);
@ -161,12 +163,20 @@ TimelineViewManager::TimelineViewManager(CallManager *callManager, ChatPage *par
qRegisterMetaType<std::vector<mtx::responses::PublicRoomsChunk>>();
qmlRegisterUncreatableMetaObject(
qml_mtx_events::staticMetaObject, "im.nheko", 1, 0, "MtxEvent", QStringLiteral("Can't instantiate enum!"));
qmlRegisterUncreatableMetaObject(qml_mtx_events::staticMetaObject,
"im.nheko",
1,
0,
"MtxEvent",
QStringLiteral("Can't instantiate enum!"));
qmlRegisterUncreatableMetaObject(
olm::staticMetaObject, "im.nheko", 1, 0, "Olm", QStringLiteral("Can't instantiate enum!"));
qmlRegisterUncreatableMetaObject(
crypto::staticMetaObject, "im.nheko", 1, 0, "Crypto", QStringLiteral("Can't instantiate enum!"));
qmlRegisterUncreatableMetaObject(crypto::staticMetaObject,
"im.nheko",
1,
0,
"Crypto",
QStringLiteral("Can't instantiate enum!"));
qmlRegisterUncreatableMetaObject(verification::staticMetaObject,
"im.nheko",
1,
@ -181,11 +191,23 @@ TimelineViewManager::TimelineViewManager(CallManager *callManager, ChatPage *par
qmlRegisterType<MxcAnimatedImage>("im.nheko", 1, 0, "MxcAnimatedImage");
qmlRegisterType<MxcMediaProxy>("im.nheko", 1, 0, "MxcMedia");
qmlRegisterUncreatableType<DeviceVerificationFlow>(
"im.nheko", 1, 0, "DeviceVerificationFlow", QStringLiteral("Can't create verification flow from QML!"));
"im.nheko",
1,
0,
"DeviceVerificationFlow",
QStringLiteral("Can't create verification flow from QML!"));
qmlRegisterUncreatableType<UserProfile>(
"im.nheko", 1, 0, "UserProfileModel", QStringLiteral("UserProfile needs to be instantiated on the C++ side"));
"im.nheko",
1,
0,
"UserProfileModel",
QStringLiteral("UserProfile needs to be instantiated on the C++ side"));
qmlRegisterUncreatableType<MemberList>(
"im.nheko", 1, 0, "MemberList", QStringLiteral("MemberList needs to be instantiated on the C++ side"));
"im.nheko",
1,
0,
"MemberList",
QStringLiteral("MemberList needs to be instantiated on the C++ side"));
qmlRegisterUncreatableType<RoomSettings>(
"im.nheko",
1,
@ -207,7 +229,11 @@ TimelineViewManager::TimelineViewManager(CallManager *callManager, ChatPage *par
"SingleImagePackModel",
QStringLiteral("SingleImagePackModel needs to be instantiated on the C++ side"));
qmlRegisterUncreatableType<InviteesModel>(
"im.nheko", 1, 0, "InviteesModel", QStringLiteral("InviteesModel needs to be instantiated on the C++ side"));
"im.nheko",
1,
0,
"InviteesModel",
QStringLiteral("InviteesModel needs to be instantiated on the C++ side"));
qmlRegisterUncreatableType<ReadReceiptsProxy>(
"im.nheko",
1,
@ -270,8 +296,12 @@ TimelineViewManager::TimelineViewManager(CallManager *callManager, ChatPage *par
qmlRegisterType<emoji::EmojiModel>("im.nheko.EmojiModel", 1, 0, "EmojiModel");
qmlRegisterUncreatableType<emoji::Emoji>(
"im.nheko.EmojiModel", 1, 0, "Emoji", QStringLiteral("Used by emoji models"));
qmlRegisterUncreatableMetaObject(
emoji::staticMetaObject, "im.nheko.EmojiModel", 1, 0, "EmojiCategory", QStringLiteral("Error: Only enums"));
qmlRegisterUncreatableMetaObject(emoji::staticMetaObject,
"im.nheko.EmojiModel",
1,
0,
"EmojiCategory",
QStringLiteral("Error: Only enums"));
qmlRegisterType<RoomDirectoryModel>("im.nheko", 1, 0, "RoomDirectoryModel");
@ -404,15 +434,17 @@ TimelineViewManager::openImageOverlay(QString mxcUrl, QString eventId)
return;
}
MxcImageProvider::download(
mxcUrl.remove(QStringLiteral("mxc://")), QSize(), [this, eventId](QString, QSize, QImage img, QString) {
if (img.isNull()) {
nhlog::ui()->error("Error when retrieving image for overlay.");
return;
}
MxcImageProvider::download(mxcUrl.remove(QStringLiteral("mxc://")),
QSize(),
[this, eventId](QString, QSize, QImage img, QString) {
if (img.isNull()) {
nhlog::ui()->error(
"Error when retrieving image for overlay.");
return;
}
emit openImageOverlayInternalCb(eventId, std::move(img));
});
emit openImageOverlayInternalCb(eventId, std::move(img));
});
}
void

View file

@ -28,8 +28,8 @@ void
Nheko::updateUserProfile()
{
if (cache::client() && cache::client()->isInitialized())
currentUser_.reset(
new UserProfile(QLatin1String(""), utils::localUser(), ChatPage::instance()->timelineManager()));
currentUser_.reset(new UserProfile(
QLatin1String(""), utils::localUser(), ChatPage::instance()->timelineManager()));
else
currentUser_.reset();
emit profileChanged();

View file

@ -234,8 +234,10 @@ RoomSettings::roomName() const
QString
RoomSettings::roomTopic() const
{
return utils::replaceEmoji(utils::linkifyMessage(
QString::fromStdString(info_.topic).toHtmlEscaped().replace(QLatin1String("\n"), QLatin1String("<br>"))));
return utils::replaceEmoji(
utils::linkifyMessage(QString::fromStdString(info_.topic)
.toHtmlEscaped()
.replace(QLatin1String("\n"), QLatin1String("<br>"))));
}
QString

View file

@ -232,6 +232,7 @@ UserProfile::updateVerificationStatus()
this->isUserVerified = verificationStatus.user_verified;
emit userStatusChanged();
deviceInfo.reserve(devices.size());
for (const auto &d : devices) {
auto device = d.second;
verification::Status verified =
@ -244,9 +245,9 @@ UserProfile::updateVerificationStatus()
if (isSelf() && device.device_id == ::http::client()->device_id())
verified = verification::Status::SELF;
deviceInfo.push_back({QString::fromStdString(d.first),
QString::fromStdString(device.unsigned_info.device_display_name),
verified});
deviceInfo.emplace_back(QString::fromStdString(d.first),
QString::fromStdString(device.unsigned_info.device_display_name),
verified);
}
// For self, also query devices without keys
@ -270,17 +271,17 @@ UserProfile::updateVerificationStatus()
found = true;
// Gottem! Let's fill in the blanks
e.lastIp = QString::fromStdString(d.last_seen_ip);
e.lastTs = d.last_seen_ts;
e.lastTs = static_cast<qlonglong>(d.last_seen_ts);
break;
}
}
// No entry? Let's add one.
if (!found) {
deviceInfo.push_back({QString::fromStdString(d.device_id),
QString::fromStdString(d.display_name),
verification::NOT_APPLICABLE,
QString::fromStdString(d.last_seen_ip),
d.last_seen_ts});
deviceInfo.emplace_back(QString::fromStdString(d.device_id),
QString::fromStdString(d.display_name),
verification::NOT_APPLICABLE,
QString::fromStdString(d.last_seen_ip),
d.last_seen_ts);
}
}

View file

@ -70,7 +70,8 @@ CallManager::CallManager(QObject *parent)
QTimer::singleShot(timeoutms_, this, [this, callid]() {
if (session_.state() == webrtc::State::OFFERSENT && callid == callid_) {
hangUp(CallHangUp::Reason::InviteTimeOut);
emit ChatPage::instance()->showNotification(QStringLiteral("The remote side failed to pick up."));
emit ChatPage::instance()->showNotification(
QStringLiteral("The remote side failed to pick up."));
}
});
});
@ -177,7 +178,8 @@ CallManager::sendInvite(const QString &roomid, CallType callType, unsigned int w
auto roomInfo = cache::singleRoomInfo(roomid.toStdString());
if (roomInfo.member_count != 2) {
emit ChatPage::instance()->showNotification(QStringLiteral("Calls are limited to 1:1 rooms."));
emit ChatPage::instance()->showNotification(
QStringLiteral("Calls are limited to 1:1 rooms."));
return;
}
@ -291,8 +293,9 @@ CallManager::handleEvent(const RoomEvent<CallInvite> &callInviteEvent)
const QString &ringtone = ChatPage::instance()->userSettings()->ringtone();
if (ringtone != QLatin1String("Mute"))
playRingtone(ringtone == QLatin1String("Default") ? QUrl(QStringLiteral("qrc:/media/media/ring.ogg"))
: QUrl::fromLocalFile(ringtone),
playRingtone(ringtone == QLatin1String("Default")
? QUrl(QStringLiteral("qrc:/media/media/ring.ogg"))
: QUrl::fromLocalFile(ringtone),
true);
roomid_ = QString::fromStdString(callInviteEvent.room_id);
callid_ = callInviteEvent.content.call_id;
@ -370,7 +373,8 @@ CallManager::handleEvent(const RoomEvent<CallAnswer> &callAnswerEvent)
if (callAnswerEvent.sender == utils::localUser().toStdString() &&
callid_ == callAnswerEvent.content.call_id) {
if (!isOnCall()) {
emit ChatPage::instance()->showNotification(QStringLiteral("Call answered on another device."));
emit ChatPage::instance()->showNotification(
QStringLiteral("Call answered on another device."));
stopRingtone();
haveCallInvite_ = false;
emit newInviteState();

View file

@ -44,12 +44,20 @@ WebRTCSession::WebRTCSession()
: devices_(CallDevices::instance())
{
qRegisterMetaType<webrtc::CallType>();
qmlRegisterUncreatableMetaObject(
webrtc::staticMetaObject, "im.nheko", 1, 0, "CallType", QStringLiteral("Can't instantiate enum"));
qmlRegisterUncreatableMetaObject(webrtc::staticMetaObject,
"im.nheko",
1,
0,
"CallType",
QStringLiteral("Can't instantiate enum"));
qRegisterMetaType<webrtc::State>();
qmlRegisterUncreatableMetaObject(
webrtc::staticMetaObject, "im.nheko", 1, 0, "WebRTCState", QStringLiteral("Can't instantiate enum"));
qmlRegisterUncreatableMetaObject(webrtc::staticMetaObject,
"im.nheko",
1,
0,
"WebRTCState",
QStringLiteral("Can't instantiate enum"));
connect(this, &WebRTCSession::stateChanged, this, &WebRTCSession::setState);
init();