diff --git a/autotests/server.cpp b/autotests/server.cpp index 013fe03db..e8d1b81e9 100644 --- a/autotests/server.cpp +++ b/autotests/server.cpp @@ -121,7 +121,7 @@ void Server::start() QFile key(QStringLiteral(DATA_DIR) + u"/localhost.key"_s); void(key.open(QFile::ReadOnly)); config.setPrivateKey(QSslKey(&key, QSsl::Rsa)); - config.setLocalCertificate(QSslCertificate::fromPath(QStringLiteral(DATA_DIR) + u"/localhost.crt"_s).front()); + config.setLocalCertificate(QSslCertificate::fromPath(QStringLiteral(DATA_DIR) + u"/localhost.crt"_s).constFirst()); m_sslServer.setSslConfiguration(config); if (!m_sslServer.listen(QHostAddress::LocalHost, 1234) || !m_server.bind(&m_sslServer)) { qFatal() << "Server failed to listen on a port."; @@ -227,7 +227,8 @@ void Server::sync(const QHttpServerRequest &request, QHttpServerResponder &respo QJsonObject joinRooms; auto token = request.query().queryItemValue(u"since"_s).toInt(); - for (const auto &change : m_state.mid(token)) { + const auto changes = m_state.mid(token); + for (const auto &change : changes) { for (const auto &newRoom : change.newRooms) { QJsonArray stateEvents; stateEvents += QJsonObject{ @@ -272,7 +273,7 @@ void Server::sync(const QHttpServerRequest &request, QHttpServerResponder &respo } } - for (const auto &change : m_state.mid(token)) { + for (const auto &change : changes) { for (const auto &invitation : change.invitations) { // TODO: The invitation could be for a room we haven't joined yet. Shouldn't be necessary for now, though. auto stateEvents = joinRooms[invitation.roomId][u"state"_s][u"events"_s].toArray(); @@ -299,7 +300,7 @@ void Server::sync(const QHttpServerRequest &request, QHttpServerResponder &respo } } - for (const auto &change : m_state.mid(token)) { + for (const auto &change : changes) { for (const auto &ban : change.bans) { // TODO: The ban could be for a room we haven't joined yet. Shouldn't be necessary for now, though. auto stateEvents = joinRooms[ban.roomId][u"state"_s][u"events"_s].toArray(); @@ -326,7 +327,7 @@ void Server::sync(const QHttpServerRequest &request, QHttpServerResponder &respo } } - for (const auto &change : m_state.mid(token)) { + for (const auto &change : changes) { for (const auto &join : change.joins) { // TODO: The join could be for a room we haven't joined yet. Shouldn't be necessary for now, though. auto stateEvents = joinRooms[join.roomId][u"state"_s][u"events"_s].toArray(); @@ -353,7 +354,7 @@ void Server::sync(const QHttpServerRequest &request, QHttpServerResponder &respo } } - for (const auto &change : m_state.mid(token)) { + for (const auto &change : changes) { for (const auto &state : change.stateEvents) { const auto &roomId = state.fullJson[u"room_id"_s].toString(); // TODO: The join could be for a room we haven't joined yet. Shouldn't be necessary for now, though. @@ -365,7 +366,7 @@ void Server::sync(const QHttpServerRequest &request, QHttpServerResponder &respo } } - for (const auto &change : m_state.mid(token)) { + for (const auto &change : changes) { for (const auto &event : change.events) { // TODO the room might be in a different join state. auto timeline = joinRooms[event.fullJson[u"room_id"_s].toString()][u"timeline"_s][u"events"_s].toArray(); diff --git a/src/app/roommanager.h b/src/app/roommanager.h index 53e880014..19e8621b3 100644 --- a/src/app/roommanager.h +++ b/src/app/roommanager.h @@ -190,7 +190,7 @@ public: * * @sa Quotient::UriResolverBase::visitResource() */ - Q_INVOKABLE void resolveResource(Uri uri, const QString &action = {}); + Q_INVOKABLE void resolveResource(Quotient::Uri uri, const QString &action = {}); bool hasOpenRoom() const; @@ -235,7 +235,7 @@ public: * @brief Show a context menu for the given event. */ Q_INVOKABLE void - viewEventMenu(QObject *parent, const RoomEvent *event, NeoChatRoom *room, const QString &selectedText = {}, const QString &hoveredLink = {}); + viewEventMenu(QObject *parent, const Quotient::RoomEvent *event, NeoChatRoom *room, const QString &selectedText = {}, const QString &hoveredLink = {}); /** * @brief Set a URL to be loaded as the initial room. @@ -316,7 +316,7 @@ Q_SIGNALS: const QString &plainText, const QString &richtText, const QString &mimeType, - const FileTransferInfo &progressInfo, + const Quotient::FileTransferInfo &progressInfo, const QString &selectedText, const QString &hoveredLink); diff --git a/src/libneochat/accountmanager.cpp b/src/libneochat/accountmanager.cpp index 7c73232c5..5b6cf9be3 100644 --- a/src/libneochat/accountmanager.cpp +++ b/src/libneochat/accountmanager.cpp @@ -39,7 +39,8 @@ Quotient::AccountRegistry *AccountManager::accounts() void AccountManager::loadAccountsFromCache() { - for (const auto &accountId : Quotient::SettingsGroup("Accounts"_L1).childGroups()) { + const auto accounts = Quotient::SettingsGroup("Accounts"_L1).childGroups(); + for (const auto &accountId : accounts) { Quotient::AccountSettings account{accountId}; m_accountsLoading += accountId; Q_EMIT accountsLoadingChanged(); @@ -57,14 +58,14 @@ void AccountManager::loadAccountsFromCache() m_connectionsLoading[accountId] = connection; connect(connection, &NeoChatConnection::connected, this, [this, connection, accountId] { connection->loadState(); - if (connection->allRooms().size() == 0 || connection->allRooms()[0]->currentState().get()) { + if (connection->allRooms().size() == 0 || connection->allRooms().at(0)->currentState().get()) { addConnection(connection); m_accountsLoading.removeAll(connection->userId()); m_connectionsLoading.remove(accountId); Q_EMIT accountsLoadingChanged(); } else { connect( - connection->allRooms()[0], + connection->allRooms().at(0), &NeoChatRoom::baseStateLoaded, this, [this, connection, accountId]() { diff --git a/src/libneochat/chatbarsyntaxhighlighter.cpp b/src/libneochat/chatbarsyntaxhighlighter.cpp index 9dbc43dd9..f6b0854e9 100644 --- a/src/libneochat/chatbarsyntaxhighlighter.cpp +++ b/src/libneochat/chatbarsyntaxhighlighter.cpp @@ -38,7 +38,7 @@ void ChatBarSyntaxHighlighter::highlightBlock(const QString &text) m_errors.clear(); m_checker->setText(text); } - for (const auto &error : m_errors) { + for (const auto &error : std::as_const(m_errors)) { setFormat(error.first, error.second.size(), m_errorFormat); } } diff --git a/src/libneochat/enums/roomsortparameter.h b/src/libneochat/enums/roomsortparameter.h index 1d1e34372..ed43ae42d 100644 --- a/src/libneochat/enums/roomsortparameter.h +++ b/src/libneochat/enums/roomsortparameter.h @@ -46,7 +46,7 @@ public: * * @sa Parameter */ - Q_INVOKABLE static QString parameterName(Parameter parameter) + Q_INVOKABLE static QString parameterName(RoomSortParameter::Parameter parameter) { switch (parameter) { case Parameter::AlphabeticalAscending: @@ -73,7 +73,7 @@ public: * * @sa Parameter */ - Q_INVOKABLE static QString parameterDescription(Parameter parameter) + Q_INVOKABLE static QString parameterDescription(RoomSortParameter::Parameter parameter) { switch (parameter) { case Parameter::AlphabeticalAscending: diff --git a/src/libneochat/models/customemojimodel.cpp b/src/libneochat/models/customemojimodel.cpp index 04a85b985..a5c339f9e 100644 --- a/src/libneochat/models/customemojimodel.cpp +++ b/src/libneochat/models/customemojimodel.cpp @@ -56,7 +56,7 @@ void CustomEmojiModel::fetchEmojis() const auto e = emoji.startsWith(":"_L1) ? emoji : (u":"_s + emoji + u":"_s); - m_emojis << CustomEmoji{e, data.toObject()["url"_L1].toString(), QRegularExpression(e)}; + m_emojis << CustomEmoji{e, data.toObject().value("url"_L1).toString(), QRegularExpression(e)}; } endResetModel(); diff --git a/src/libneochat/models/emojimodel.h b/src/libneochat/models/emojimodel.h index 19eb94890..6498aa06e 100644 --- a/src/libneochat/models/emojimodel.h +++ b/src/libneochat/models/emojimodel.h @@ -151,7 +151,7 @@ public: /** * @brief Return a list of emojis for the given category. */ - Q_INVOKABLE QVariantList emojis(Category category) const; + Q_INVOKABLE QVariantList emojis(EmojiModel::Category category) const; /** * @brief Return a list of emoji tones for the given base emoji. diff --git a/src/libneochat/neochatconnection.cpp b/src/libneochat/neochatconnection.cpp index fcd9edf5d..218b831aa 100644 --- a/src/libneochat/neochatconnection.cpp +++ b/src/libneochat/neochatconnection.cpp @@ -72,7 +72,7 @@ void NeoChatConnection::connectSignals() } }); connect(this, &NeoChatConnection::requestFailed, this, [this](BaseJob *job) { - if (dynamic_cast(job) && job->jsonData()["errcode"_L1].toString() == "M_TOO_LARGE"_L1) { + if (dynamic_cast(job) && job->jsonData().value("errcode"_L1).toString() == "M_TOO_LARGE"_L1) { Q_EMIT showMessage(MessageType::Warning, i18n("File too large to download.
Contact your matrix server administrator for support.")); } }); @@ -168,7 +168,8 @@ int NeoChatConnection::badgeNotificationCount() const void NeoChatConnection::refreshBadgeNotificationCount() { int count = 0; - for (const auto &r : allRooms()) { + const auto rooms = allRooms(); + for (const auto &r : rooms) { if (const auto room = static_cast(r)) { count += room->contextAwareNotificationCount(); @@ -287,7 +288,7 @@ void NeoChatConnection::setLabel(const QString &label) QString NeoChatConnection::label() const { - return accountDataJson("org.kde.neochat.account_label"_L1)["account_label"_L1].toString(); + return accountDataJson("org.kde.neochat.account_label"_L1).value("account_label"_L1).toString(); } void NeoChatConnection::deactivateAccount(const QString &password, const bool erase) @@ -416,7 +417,8 @@ qsizetype NeoChatConnection::directChatNotifications() const { qsizetype notifications = 0; QStringList added; // The same ID can be in the list multiple times. - for (const auto &chatId : directChats()) { + const auto roomIds = directChats(); + for (const auto &chatId : roomIds) { if (!added.contains(chatId)) { if (const auto chat = room(chatId)) { notifications += dynamic_cast(chat)->contextAwareNotificationCount(); @@ -429,7 +431,8 @@ qsizetype NeoChatConnection::directChatNotifications() const bool NeoChatConnection::directChatsHaveHighlightNotifications() const { - for (const auto &childId : directChats()) { + const auto roomIds = directChats(); + for (const auto &childId : roomIds) { if (const auto child = static_cast(room(childId))) { if (child->highlightCount() > 0) { return true; @@ -444,7 +447,8 @@ qsizetype NeoChatConnection::homeNotifications() const qsizetype notifications = 0; QStringList added; const auto &spaceHierarchyCache = SpaceHierarchyCache::instance(); - for (const auto &r : allRooms()) { + const auto rooms = allRooms(); + for (const auto &r : rooms) { if (const auto room = static_cast(r)) { if (!added.contains(room->id()) && !room->isDirectChat() && !spaceHierarchyCache.isChild(room->id())) { notifications += dynamic_cast(room)->contextAwareNotificationCount(); @@ -458,7 +462,8 @@ qsizetype NeoChatConnection::homeNotifications() const bool NeoChatConnection::homeHaveHighlightNotifications() const { const auto &spaceHierarchyCache = SpaceHierarchyCache::instance(); - for (const auto &r : allRooms()) { + const auto rooms = allRooms(); + for (const auto &r : rooms) { if (const auto room = static_cast(r)) { if (!room->isDirectChat() && !spaceHierarchyCache.isChild(room->id()) && room->highlightCount() > 0) { return true; @@ -641,7 +646,7 @@ void NeoChatConnection::setNoteForUser(const QString &userId, const QString ¬ bool NeoChatConnection::blockAllInvites() const { - return accountDataJson("m.invite_permission_config"_L1)["default_action"_L1].toString() == "block"_L1; + return accountDataJson("m.invite_permission_config"_L1).value("default_action"_L1).toString() == "block"_L1; } void NeoChatConnection::setBlockAllInvites(bool block) diff --git a/src/libneochat/neochatroom.cpp b/src/libneochat/neochatroom.cpp index 6255275d1..0540cde79 100644 --- a/src/libneochat/neochatroom.cpp +++ b/src/libneochat/neochatroom.cpp @@ -146,7 +146,7 @@ NeoChatRoom::NeoChatRoom(Connection *c, QString roomId, JoinState joinState) connect(this, &Room::changed, this, [this]() { Q_EMIT defaultUrlPreviewStateChanged(); }); - connect(this, &Room::accountDataChanged, this, [this](QString type) { + connect(this, &Room::accountDataChanged, this, [this](const QString &type) { if (type == "org.matrix.room.preview_urls"_L1) { Q_EMIT urlPreviewEnabledChanged(); } @@ -348,7 +348,7 @@ void NeoChatRoom::forget() } const auto neochatConnection = dynamic_cast(connection()); - for (const auto &id : roomIds) { + for (const auto &id : std::as_const(roomIds)) { neochatConnection->forgetRoom(id); } } @@ -499,7 +499,8 @@ QUrl NeoChatRoom::avatarMediaUrl() const } // Use the first (excluding self) user's avatar for direct chats - for (const auto &member : directChatMembers()) { + const auto members = directChatMembers(); + for (const auto &member : members) { if (member != localMember()) { return member.avatarUrl(); } @@ -763,7 +764,7 @@ bool NeoChatRoom::hasParent() const QList NeoChatRoom::parentIds() const { - auto parentEvents = currentState().eventsOfType("m.space.parent"_L1); + const auto parentEvents = currentState().eventsOfType("m.space.parent"_L1); QList parentIds; for (const auto &parentEvent : parentEvents) { if (parentEvent->contentJson().contains("via"_L1) && !parentEvent->contentPart("via"_L1).isEmpty()) { @@ -776,7 +777,7 @@ QList NeoChatRoom::parentIds() const QList NeoChatRoom::parentObjects(bool multiLevel) const { QList parentObjects; - QList parentIds = this->parentIds(); + const auto parentIds = this->parentIds(); for (const auto &parentId : parentIds) { if (auto parentObject = static_cast(connection()->room(parentId))) { parentObjects += parentObject; @@ -790,7 +791,7 @@ QList NeoChatRoom::parentObjects(bool multiLevel) const QString NeoChatRoom::canonicalParent() const { - auto parentEvents = currentState().eventsOfType("m.space.parent"_L1); + const auto parentEvents = currentState().eventsOfType("m.space.parent"_L1); for (const auto &parentEvent : parentEvents) { if (parentEvent->contentJson().contains("via"_L1) && !parentEvent->contentPart("via"_L1).isEmpty()) { if (parentEvent->contentPart("canonical"_L1)) { @@ -815,7 +816,7 @@ void NeoChatRoom::setCanonicalParent(const QString &parentId) } // Only one canonical parent can exist so make sure others are set false. - auto parentEvents = currentState().eventsOfType("m.space.parent"_L1); + const auto parentEvents = currentState().eventsOfType("m.space.parent"_L1); for (const auto &parentEvent : parentEvents) { if (parentEvent->contentPart("canonical"_L1) && parentEvent->stateKey() != parentId) { auto content = parentEvent->contentJson(); @@ -858,7 +859,7 @@ void NeoChatRoom::addParent(const QString &parentId, bool canonical, bool setPar } if (canonical) { // Only one canonical parent can exist so make sure others are set false. - auto parentEvents = currentState().eventsOfType("m.space.parent"_L1); + const auto parentEvents = currentState().eventsOfType("m.space.parent"_L1); for (const auto &parentEvent : parentEvents) { if (parentEvent->contentPart("canonical"_L1)) { auto content = parentEvent->contentJson(); @@ -938,7 +939,7 @@ void NeoChatRoom::addChild(const QString &childId, bool setChildParent, bool can return; } // Only one canonical parent can exist so make sure others are set to false. - auto parentEvents = child->currentState().eventsOfType("m.space.parent"_L1); + const auto parentEvents = child->currentState().eventsOfType("m.space.parent"_L1); for (const auto &parentEvent : parentEvents) { if (!parentEvent->contentPart("canonical"_L1)) { continue; @@ -1048,7 +1049,7 @@ void NeoChatRoom::setPushNotificationState(PushNotificationState::State state) // For default and mute check for a room rule and remove if found. if (state == PushNotificationState::Default || state == PushNotificationState::Mute) { - QJsonArray roomRuleArray = accountData["global"_L1].toObject()["room"_L1].toArray(); + const auto roomRuleArray = accountData["global"_L1].toObject()["room"_L1].toArray(); for (const auto &i : roomRuleArray) { QJsonObject roomRule = i.toObject(); if (roomRule["rule_id"_L1] == id()) { @@ -1059,7 +1060,7 @@ void NeoChatRoom::setPushNotificationState(PushNotificationState::State state) // For default, all and @mentions and keywords check for an override rule and remove if found. if (state == PushNotificationState::Default || state == PushNotificationState::All || state == PushNotificationState::MentionKeyword) { - QJsonArray overrideRuleArray = accountData["global"_L1].toObject()["override"_L1].toArray(); + const auto overrideRuleArray = accountData["global"_L1].toObject()["override"_L1].toArray(); for (const auto &i : overrideRuleArray) { QJsonObject overrideRule = i.toObject(); if (overrideRule["rule_id"_L1] == id()) { @@ -1191,7 +1192,7 @@ void NeoChatRoom::updatePushNotificationState(QString type) QJsonObject accountData = connection()->accountDataJson("m.push_rules"_L1); // First look for a room rule with the room id - QJsonArray roomRuleArray = accountData["global"_L1].toObject()["room"_L1].toArray(); + const auto roomRuleArray = accountData["global"_L1].toObject()["room"_L1].toArray(); for (const auto &i : roomRuleArray) { QJsonObject roomRule = i.toObject(); if (roomRule["rule_id"_L1] == id()) { @@ -1214,7 +1215,7 @@ void NeoChatRoom::updatePushNotificationState(QString type) } // Check for an override rule with the room id - QJsonArray overrideRuleArray = accountData["global"_L1].toObject()["override"_L1].toArray(); + const auto overrideRuleArray = accountData["global"_L1].toObject()["override"_L1].toArray(); for (const auto &i : overrideRuleArray) { QJsonObject overrideRule = i.toObject(); if (overrideRule["rule_id"_L1] == id()) { @@ -1577,7 +1578,8 @@ void NeoChatRoom::setCanonicalAlias(const QString &newAlias) int NeoChatRoom::maxRoomVersion() const { int maxVersion = 0; - for (auto roomVersion : connection()->availableRoomVersions()) { + const auto availableVersions = connection()->availableRoomVersions(); + for (const auto &roomVersion : availableVersions) { if (roomVersion.id.toInt() > maxVersion) { maxVersion = roomVersion.id.toInt(); } @@ -1591,7 +1593,7 @@ NeochatRoomMember *NeoChatRoom::directChatRemoteMember() qWarning() << "No other member available in this room"; return {}; } - return new NeochatRoomMember(this, directChatMembers()[0].id()); + return new NeochatRoomMember(this, directChatMembers().at(0).id()); } void NeoChatRoom::sendLocation(float lat, float lon, const QString &description) @@ -1898,7 +1900,7 @@ void NeoChatRoom::sortAllMembers() // Build up a temporary cache, because we may be checking the same member over and over while sorting. QHash effectivePowerLevels; effectivePowerLevels.reserve(m_sortedMemberIds.size()); - for (const auto &member : m_sortedMemberIds) { + for (const auto &member : std::as_const(m_sortedMemberIds)) { effectivePowerLevels[member] = memberEffectivePowerLevel(member); } @@ -2002,7 +2004,7 @@ QString NeoChatRoom::getFormattedSelectedMessages() const QString formattedContent; formattedContent.reserve(events.size() * 256); // estimate an average of 256 characters per message - for (const RoomEvent *event : events) { + for (const RoomEvent *event : std::as_const(events)) { formattedContent += EventHandler::authorDisplayName(this, event); formattedContent += u" — "_s; formattedContent += EventHandler::dateTime(this, event).shortDateTime(); @@ -2017,7 +2019,7 @@ QString NeoChatRoom::getFormattedSelectedMessages() const void NeoChatRoom::deleteSelectedMessages(const QString &reason) { QStringList events; - for (const auto &eventId : m_selectedMessageIds) { + for (const auto &eventId : std::as_const(m_selectedMessageIds)) { const auto eventIt = findInTimeline(eventId); if (eventIt == historyEdge()) { continue; diff --git a/src/messagecontent/models/chatbarmessagecontentmodel.cpp b/src/messagecontent/models/chatbarmessagecontentmodel.cpp index bd9ac8b3b..b5a9e1d7d 100644 --- a/src/messagecontent/models/chatbarmessagecontentmodel.cpp +++ b/src/messagecontent/models/chatbarmessagecontentmodel.cpp @@ -46,14 +46,14 @@ ChatBarMessageContentModel::ChatBarMessageContentModel(QObject *parent) m_keyHelper->setTextItem(focusedTextItem()); }); connect(this, &ChatBarMessageContentModel::roomChanged, this, [this]() { - for (const auto &component : m_components) { + for (const auto &component : std::as_const(m_components)) { if (const auto textItem = textItemForComponent(component)) { textItem->setRoom(m_room); } } }); connect(this, &ChatBarMessageContentModel::typeChanged, this, [this](ChatBarType::Type oldType) { - for (const auto &component : m_components) { + for (const auto &component : std::as_const(m_components)) { if (const auto textItem = textItemForComponent(component)) { textItem->setType(m_type); } @@ -361,7 +361,7 @@ void ChatBarMessageContentModel::addAttachment(const QUrl &path) } QString plainText; - for (const auto &component : m_components) { + for (const auto &component : std::as_const(m_components)) { if (const auto textItem = textItemForComponent(component)) { plainText += u"%1%2"_s.arg(plainText.isEmpty() ? u""_s : u"\n"_s, textItem->plainText()); } diff --git a/src/rooms/models/roomtreemodel.cpp b/src/rooms/models/roomtreemodel.cpp index 04792648e..53a33e7de 100644 --- a/src/rooms/models/roomtreemodel.cpp +++ b/src/rooms/models/roomtreemodel.cpp @@ -52,7 +52,8 @@ void RoomTreeModel::resetModel() m_rootItem->insertChild(std::make_unique(NeoChatRoomType::Types(i), m_rootItem.get())); } - for (const auto &r : m_connection->allRooms()) { + const auto rooms = m_connection->allRooms(); + for (const auto &r : rooms) { const auto room = dynamic_cast(r); const auto type = NeoChatRoomType::typeForRoom(room); const auto categoryItem = m_rootItem->child(type); diff --git a/src/rooms/models/sortfilterroomtreemodel.cpp b/src/rooms/models/sortfilterroomtreemodel.cpp index 24a2bc12b..7bbed6683 100644 --- a/src/rooms/models/sortfilterroomtreemodel.cpp +++ b/src/rooms/models/sortfilterroomtreemodel.cpp @@ -57,7 +57,8 @@ bool SortFilterRoomTreeModel::lessThan(const QModelIndex &source_left, const QMo return false; } - for (auto sortRole : RoomSortParameter::currentParameterList()) { + const auto parameters = RoomSortParameter::currentParameterList(); + for (const auto sortRole : parameters) { auto result = RoomSortParameter::compareParameter(sortRole, leftRoom, rightRoom); if (result != 0) { diff --git a/src/timeline/models/searchmodel.h b/src/timeline/models/searchmodel.h index 091f0aaf1..03dbaedc0 100644 --- a/src/timeline/models/searchmodel.h +++ b/src/timeline/models/searchmodel.h @@ -70,7 +70,6 @@ public: Q_SIGNALS: void searchTextChanged(); - void roomChanged(); void searchingChanged(); void senderIdChanged();