From 9027db264ab226901e7b4d660acb6d4d990b61f2 Mon Sep 17 00:00:00 2001 From: Tobias Fella Date: Sat, 13 Nov 2021 14:16:39 +0100 Subject: [PATCH] Don't capture 'this' implicitely --- src/controller.cpp | 24 ++++++++++++------------ src/devicesmodel.cpp | 2 +- src/login.cpp | 16 ++++++++-------- src/messageeventmodel.cpp | 14 +++++++------- src/neochatroom.cpp | 10 +++++----- src/publicroomlistmodel.cpp | 2 +- src/roomlistmodel.cpp | 18 +++++++++--------- src/roommanager.cpp | 2 +- src/userdirectorylistmodel.cpp | 2 +- src/userlistmodel.cpp | 6 +++--- 10 files changed, 48 insertions(+), 48 deletions(-) diff --git a/src/controller.cpp b/src/controller.cpp index 67d32307a..2cc97b564 100644 --- a/src/controller.cpp +++ b/src/controller.cpp @@ -72,7 +72,7 @@ Controller::Controller(QObject *parent) connect(trayIcon, &TrayIcon::showWindow, this, &Controller::showWindow); QGuiApplication::setQuitOnLastWindowClosed(false); } - connect(NeoChatConfig::self(), &NeoChatConfig::SystemTrayChanged, this, [=]() { + connect(NeoChatConfig::self(), &NeoChatConfig::SystemTrayChanged, this, [this, trayIcon]() { if (NeoChatConfig::self()->systemTray()) { trayIcon->show(); connect(trayIcon, &TrayIcon::showWindow, this, &Controller::showWindow); @@ -84,7 +84,7 @@ Controller::Controller(QObject *parent) }); #endif - QTimer::singleShot(0, this, [=] { + QTimer::singleShot(0, this, [this] { invokeLogin(); }); @@ -152,7 +152,7 @@ void Controller::loginWithAccessToken(const QString &serverAddr, const QString & conn->setHomeserver(serverUrl); } - connect(conn, &Connection::connected, this, [=] { + connect(conn, &Connection::connected, this, [this, conn, deviceName] { AccountSettings account(conn->userId()); account.setKeepLoggedIn(true); account.setHomeserver(conn->homeserver()); @@ -165,7 +165,7 @@ void Controller::loginWithAccessToken(const QString &serverAddr, const QString & addConnection(conn); setActiveConnection(conn); }); - connect(conn, &Connection::networkError, this, [=](QString error, const QString &, int, int) { + connect(conn, &Connection::networkError, this, [this](QString error, const QString &, int, int) { Q_EMIT errorOccured(i18n("Network Error: %1", error)); }); conn->assumeIdentity(user, token, deviceName); @@ -210,7 +210,7 @@ void Controller::addConnection(Connection *c) c->setLazyLoading(true); - connect(c, &Connection::syncDone, this, [=] { + connect(c, &Connection::syncDone, this, [this, c] { setBusy(false); Q_EMIT syncDone(); @@ -218,11 +218,11 @@ void Controller::addConnection(Connection *c) c->sync(30000); c->saveState(); }); - connect(c, &Connection::loggedOut, this, [=] { + connect(c, &Connection::loggedOut, this, [this, c] { dropConnection(c); }); - connect(c, &Connection::requestFailed, this, [=](BaseJob *job) { + connect(c, &Connection::requestFailed, this, [this](BaseJob *job) { if (job->error() == BaseJob::UserConsentRequiredError) { Q_EMIT userConsentRequired(job->errorUrl()); } @@ -265,7 +265,7 @@ void Controller::invokeLogin() auto accessToken = loadAccessTokenFromKeyChain(account); auto connection = new Connection(account.homeserver()); - connect(connection, &Connection::connected, this, [=] { + connect(connection, &Connection::connected, this, [this, connection, id] { connection->loadState(); addConnection(connection); if (connection->userId() == id) { @@ -273,7 +273,7 @@ void Controller::invokeLogin() connectSingleShot(connection, &Connection::syncDone, this, &Controller::initiated); } }); - connect(connection, &Connection::loginError, this, [=](const QString &error, const QString &) { + connect(connection, &Connection::loginError, this, [this, connection](const QString &error, const QString &) { if (error == "Unrecognised access token") { Q_EMIT errorOccured(i18n("Login Failed: Access Token invalid or revoked")); logout(connection, false); @@ -283,7 +283,7 @@ void Controller::invokeLogin() } Q_EMIT initiated(); }); - connect(connection, &Connection::networkError, this, [=](const QString &error, const QString &, int, int) { + connect(connection, &Connection::networkError, this, [this](const QString &error, const QString &, int, int) { Q_EMIT errorOccured(i18n("Network Error: %1", error)); }); connection->assumeIdentity(account.userId(), accessToken, account.deviceId()); @@ -386,7 +386,7 @@ void Controller::playAudio(const QUrl &localFile) auto player = new QMediaPlayer; player->setMedia(localFile); player->play(); - connect(player, &QMediaPlayer::stateChanged, [=] { + connect(player, &QMediaPlayer::stateChanged, [player] { player->deleteLater(); }); } @@ -574,7 +574,7 @@ NeochatDeleteDeviceJob::NeochatDeleteDeviceJob(const QString &deviceId, const Om void Controller::createRoom(const QString &name, const QString &topic) { auto createRoomJob = m_connection->createRoom(Connection::PublishRoom, "", name, topic, QStringList()); - Quotient::CreateRoomJob::connect(createRoomJob, &CreateRoomJob::failure, [=] { + Quotient::CreateRoomJob::connect(createRoomJob, &CreateRoomJob::failure, [this, createRoomJob] { Q_EMIT errorOccured(i18n("Room creation failed: \"%1\"", createRoomJob->errorString())); }); } diff --git a/src/devicesmodel.cpp b/src/devicesmodel.cpp index 336b0efce..42d7713c9 100644 --- a/src/devicesmodel.cpp +++ b/src/devicesmodel.cpp @@ -88,7 +88,7 @@ void DevicesModel::setName(int index, const QString &name) beginResetModel(); m_devices[index].displayName = name; endResetModel(); - connect(job, &BaseJob::failure, this, [=]() { + connect(job, &BaseJob::failure, this, [this, index, oldName]() { beginResetModel(); m_devices[index].displayName = oldName; endResetModel(); diff --git a/src/login.cpp b/src/login.cpp index bd4afe58b..8d3843c02 100644 --- a/src/login.cpp +++ b/src/login.cpp @@ -27,7 +27,7 @@ void Login::init() m_supportsPassword = false; m_ssoUrl = QUrl(); - connect(this, &Login::matrixIdChanged, this, [=]() { + connect(this, &Login::matrixIdChanged, this, [this]() { setHomeserverReachable(false); if (m_matrixId == "@") { @@ -40,7 +40,7 @@ void Login::init() m_connection = new Connection(); } m_connection->resolveServer(m_matrixId); - connectSingleShot(m_connection, &Connection::loginFlowsChanged, this, [=]() { + connectSingleShot(m_connection, &Connection::loginFlowsChanged, this, [this]() { setHomeserverReachable(true); m_testing = false; Q_EMIT testingChanged(); @@ -49,7 +49,7 @@ void Login::init() Q_EMIT loginFlowsChanged(); }); }); - connect(m_connection, &Connection::connected, this, [=] { + connect(m_connection, &Connection::connected, this, [this] { Q_EMIT connected(); m_isLoggingIn = false; Q_EMIT isLoggingInChanged(); @@ -67,22 +67,22 @@ void Login::init() Controller::instance().setActiveConnection(m_connection); m_connection = nullptr; }); - connect(m_connection, &Connection::networkError, this, [=](QString error, const QString &, int, int) { + connect(m_connection, &Connection::networkError, this, [this](QString error, const QString &, int, int) { Q_EMIT Controller::instance().globalErrorOccured(i18n("Network Error"), std::move(error)); m_isLoggingIn = false; Q_EMIT isLoggingInChanged(); }); - connect(m_connection, &Connection::loginError, this, [=](QString error, const QString &) { + connect(m_connection, &Connection::loginError, this, [this](QString error, const QString &) { Q_EMIT errorOccured(i18n("Login Failed: %1", error)); m_isLoggingIn = false; Q_EMIT isLoggingInChanged(); }); - connect(m_connection, &Connection::resolveError, this, [=](QString error) { + connect(m_connection, &Connection::resolveError, this, [](QString error) { Q_EMIT Controller::instance().globalErrorOccured(i18n("Network Error"), std::move(error)); }); - connectSingleShot(m_connection, &Connection::syncDone, this, [=]() { + connectSingleShot(m_connection, &Connection::syncDone, this, [this]() { Q_EMIT Controller::instance().initiated(); }); } @@ -160,7 +160,7 @@ QUrl Login::ssoUrl() const void Login::loginWithSso() { m_connection->resolveServer(m_matrixId); - connectSingleShot(m_connection, &Connection::loginFlowsChanged, this, [=]() { + connectSingleShot(m_connection, &Connection::loginFlowsChanged, this, [this]() { SsoSession *session = m_connection->prepareForSso(m_deviceName); m_ssoUrl = session->ssoUrl(); }); diff --git a/src/messageeventmodel.cpp b/src/messageeventmodel.cpp index 11192fc21..512c172b4 100644 --- a/src/messageeventmodel.cpp +++ b/src/messageeventmodel.cpp @@ -58,12 +58,12 @@ MessageEventModel::MessageEventModel(QObject *parent) qmlRegisterAnonymousType("org.kde.neochat", 1); qRegisterMetaType(); - QTimer::singleShot(0, this, [=]() { + QTimer::singleShot(0, this, [this]() { if (!m_currentRoom) { return; } m_currentRoom->getPreviousContent(50); - connect(this, &QAbstractListModel::rowsInserted, this, [=]() { + connect(this, &QAbstractListModel::rowsInserted, this, [this]() { if (m_currentRoom->readMarkerEventId().isEmpty()) { return; } @@ -98,7 +98,7 @@ void MessageEventModel::setRoom(NeoChatRoom *room) lastReadEventId = room->readMarkerEventId(); using namespace Quotient; - connect(m_currentRoom, &Room::aboutToAddNewMessages, this, [=](RoomEventsRange events) { + connect(m_currentRoom, &Room::aboutToAddNewMessages, this, [this](RoomEventsRange events) { if (NeoChatConfig::self()->showFancyEffects()) { for (auto &event : events) { RoomMessageEvent *message = dynamic_cast(event.get()); @@ -134,13 +134,13 @@ void MessageEventModel::setRoom(NeoChatRoom *room) } beginInsertRows({}, timelineBaseIndex(), timelineBaseIndex() + int(events.size()) - 1); }); - connect(m_currentRoom, &Room::aboutToAddHistoricalMessages, this, [=](RoomEventsRange events) { + connect(m_currentRoom, &Room::aboutToAddHistoricalMessages, this, [this](RoomEventsRange events) { if (rowCount() > 0) { rowBelowInserted = rowCount() - 1; // See #312 } beginInsertRows({}, rowCount(), rowCount() + int(events.size()) - 1); }); - connect(m_currentRoom, &Room::addedMessages, this, [=](int lowest, int biggest) { + connect(m_currentRoom, &Room::addedMessages, this, [this](int lowest, int biggest) { endInsertRows(); if (!m_lastReadEventIndex.isValid()) { // no read marker, so see if we need to create one. @@ -184,7 +184,7 @@ void MessageEventModel::setRoom(NeoChatRoom *room) beginRemoveRows({}, i, i); }); connect(m_currentRoom, &Room::pendingEventDiscarded, this, &MessageEventModel::endRemoveRows); - connect(m_currentRoom, &Room::readMarkerMoved, this, [=](const QString &fromEventId, const QString &toEventId) { + connect(m_currentRoom, &Room::readMarkerMoved, this, [this](const QString &fromEventId, const QString &toEventId) { Q_UNUSED(fromEventId); moveReadMarker(toEventId); }); @@ -203,7 +203,7 @@ void MessageEventModel::setRoom(NeoChatRoom *room) #ifndef QUOTIENT_07 connect(m_currentRoom, &Room::fileTransferCancelled, this, &MessageEventModel::refreshEvent); #endif - connect(m_currentRoom->connection(), &Connection::ignoredUsersListChanged, this, [=] { + connect(m_currentRoom->connection(), &Connection::ignoredUsersListChanged, this, [this] { beginResetModel(); endResetModel(); }); diff --git a/src/neochatroom.cpp b/src/neochatroom.cpp index dadfa1024..862dc0b51 100644 --- a/src/neochatroom.cpp +++ b/src/neochatroom.cpp @@ -43,7 +43,7 @@ NeoChatRoom::NeoChatRoom(Connection *connection, QString roomId, JoinState joinS { connect(this, &NeoChatRoom::notificationCountChanged, this, &NeoChatRoom::countChanged); connect(this, &NeoChatRoom::highlightCountChanged, this, &NeoChatRoom::countChanged); - connect(this, &Room::fileTransferCompleted, this, [=] { + connect(this, &Room::fileTransferCompleted, this, [this] { setFileUploadingProgress(0); setHasFileUploading(false); }); @@ -52,7 +52,7 @@ NeoChatRoom::NeoChatRoom(Connection *connection, QString roomId, JoinState joinS connect(this, &Quotient::Room::eventsHistoryJobChanged, this, &NeoChatRoom::lastActiveTimeChanged); - connect(this, &Room::joinStateChanged, this, [=](JoinState oldState, JoinState newState) { + connect(this, &Room::joinStateChanged, this, [this](JoinState oldState, JoinState newState) { if (oldState == JoinState::Invite && newState != JoinState::Invite) { Q_EMIT isInviteChanged(); } @@ -68,19 +68,19 @@ void NeoChatRoom::uploadFile(const QUrl &url, const QString &body) QString txnId = postFile(body.isEmpty() ? url.fileName() : body, url, false); setHasFileUploading(true); - connect(this, &Room::fileTransferCompleted, [=](const QString &id, const QUrl & /*localFile*/, const QUrl & /*mxcUrl*/) { + connect(this, &Room::fileTransferCompleted, [this, txnId](const QString &id, const QUrl & /*localFile*/, const QUrl & /*mxcUrl*/) { if (id == txnId) { setFileUploadingProgress(0); setHasFileUploading(false); } }); - connect(this, &Room::fileTransferFailed, [=](const QString &id, const QString & /*error*/) { + connect(this, &Room::fileTransferFailed, [this, txnId](const QString &id, const QString & /*error*/) { if (id == txnId) { setFileUploadingProgress(0); setHasFileUploading(false); } }); - connect(this, &Room::fileTransferProgress, [=](const QString &id, qint64 progress, qint64 total) { + connect(this, &Room::fileTransferProgress, [this, txnId](const QString &id, qint64 progress, qint64 total) { if (id == txnId) { setFileUploadingProgress(int(float(progress) / float(total) * 100)); } diff --git a/src/publicroomlistmodel.cpp b/src/publicroomlistmodel.cpp index 643dc93c0..8c8a2e1de 100644 --- a/src/publicroomlistmodel.cpp +++ b/src/publicroomlistmodel.cpp @@ -115,7 +115,7 @@ void PublicRoomListModel::next(int count) job = m_connection->callApi(m_server, count, nextBatch, QueryPublicRoomsJob::Filter{m_keyword}); - connect(job, &BaseJob::finished, this, [=] { + connect(job, &BaseJob::finished, this, [this] { attempted = true; if (job->status() == BaseJob::Success) { diff --git a/src/roomlistmodel.cpp b/src/roomlistmodel.cpp index a8ba81953..4ba9b22c9 100644 --- a/src/roomlistmodel.cpp +++ b/src/roomlistmodel.cpp @@ -101,7 +101,7 @@ void RoomListModel::setConnection(Connection *connection) connect(connection, &Connection::joinedRoom, this, &RoomListModel::updateRoom); connect(connection, &Connection::leftRoom, this, &RoomListModel::updateRoom); connect(connection, &Connection::aboutToDeleteRoom, this, &RoomListModel::deleteRoom); - connect(connection, &Connection::directChatsListChanged, this, [=](Quotient::DirectChatsMap additions, Quotient::DirectChatsMap removals) { + connect(connection, &Connection::directChatsListChanged, this, [this, connection](Quotient::DirectChatsMap additions, Quotient::DirectChatsMap removals) { auto refreshRooms = [this, &connection](Quotient::DirectChatsMap rooms) { for (const QString &roomID : qAsConst(rooms)) { auto room = connection->room(roomID); @@ -152,29 +152,29 @@ void RoomListModel::doAddRoom(Room *r) void RoomListModel::connectRoomSignals(NeoChatRoom *room) { - connect(room, &Room::displaynameChanged, this, [=] { + connect(room, &Room::displaynameChanged, this, [this, room] { refresh(room); }); - connect(room, &Room::unreadMessagesChanged, this, [=] { + connect(room, &Room::unreadMessagesChanged, this, [this, room] { refresh(room); }); - connect(room, &Room::notificationCountChanged, this, [=] { + connect(room, &Room::notificationCountChanged, this, [this, room] { refresh(room); }); connect(room, &Room::avatarChanged, this, [this, room] { refresh(room, {AvatarRole}); }); - connect(room, &Room::tagsChanged, this, [=] { + connect(room, &Room::tagsChanged, this, [this, room] { refresh(room); }); - connect(room, &Room::joinStateChanged, this, [=] { + connect(room, &Room::joinStateChanged, this, [this, room] { refresh(room); }); - connect(room, &Room::addedMessages, this, [=] { + connect(room, &Room::addedMessages, this, [this, room] { refresh(room, {LastEventRole}); }); connect(room, &Room::notificationCountChanged, this, &RoomListModel::handleNotifications); - connect(room, &Room::highlightCountChanged, this, [=] { + connect(room, &Room::highlightCountChanged, this, [this, room] { if (room->highlightCount() == 0) { return; } @@ -205,7 +205,7 @@ void RoomListModel::handleNotifications() static QStringList oldNotifications; auto job = m_connection->callApi(); - connect(job, &BaseJob::success, this, [=]() { + connect(job, &BaseJob::success, this, [this, job]() { const auto notifications = job->jsonData()["notifications"].toArray(); if (initial) { initial = false; diff --git a/src/roommanager.cpp b/src/roommanager.cpp index 06a6c82e7..a776d778e 100644 --- a/src/roommanager.cpp +++ b/src/roommanager.cpp @@ -186,7 +186,7 @@ void RoomManager::visitRoom(Room *room, const QString &eventId) void RoomManager::joinRoom(Quotient::Connection *account, const QString &roomAliasOrId, const QStringList &viaServers) { account->joinRoom(QUrl::toPercentEncoding(roomAliasOrId), viaServers); - connectSingleShot(account, &Quotient::Connection::newRoom, this, [=](Quotient::Room *room) { + connectSingleShot(account, &Quotient::Connection::newRoom, this, [this](Quotient::Room *room) { enterRoom(dynamic_cast(room)); }); } diff --git a/src/userdirectorylistmodel.cpp b/src/userdirectorylistmodel.cpp index e1bcae511..0b02fd3a9 100644 --- a/src/userdirectorylistmodel.cpp +++ b/src/userdirectorylistmodel.cpp @@ -75,7 +75,7 @@ void UserDirectoryListModel::search(int count) job = m_connection->callApi(m_keyword, count); - connect(job, &BaseJob::finished, this, [=] { + connect(job, &BaseJob::finished, this, [this] { attempted = true; if (job->status() == BaseJob::Success) { diff --git a/src/userlistmodel.cpp b/src/userlistmodel.cpp index 8b1ab4c55..363c3177f 100644 --- a/src/userlistmodel.cpp +++ b/src/userlistmodel.cpp @@ -49,14 +49,14 @@ void UserListModel::setRoom(Quotient::Room *room) } for (User *user : qAsConst(m_users)) { #ifdef QUOTIENT_07 - connect(user, &User::defaultAvatarChanged, this, [=]() { + connect(user, &User::defaultAvatarChanged, this, [this, user]() { avatarChanged(user, m_currentRoom); }); #else connect(user, &User::avatarChanged, this, &UserListModel::avatarChanged); #endif } - connect(m_currentRoom->connection(), &Connection::loggedOut, this, [=] { + connect(m_currentRoom->connection(), &Connection::loggedOut, this, [this] { setRoom(nullptr); }); qDebug() << m_users.count() << "user(s) in the room"; @@ -154,7 +154,7 @@ void UserListModel::userAdded(Quotient::User *user) m_users.insert(pos, user); endInsertRows(); #ifdef QUOTIENT_07 - connect(user, &User::defaultAvatarChanged, this, [=]() { + connect(user, &User::defaultAvatarChanged, this, [this, user]() { avatarChanged(user, m_currentRoom); }); #else