From a13f492e7d587ade54606a77c4e9f497a0fea737 Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Mon, 22 Nov 2021 00:32:49 +0100 Subject: [PATCH] Make clang-format <13 and clang-format >=13 behave the same I think old clang-format is just buggy in those cases, so we should reenable those blocks, once everyone has 13 or up. --- .clang-format | 3 +- src/BlurhashProvider.h | 4 +- src/Cache_p.h | 65 +++++++++++------------ src/CompletionProxyModel.h | 5 +- src/Config.h | 4 +- src/JdenticonProvider.h | 4 +- src/MainWindow.h | 10 ++-- src/MxcImageProvider.h | 4 +- src/encryption/DeviceVerificationFlow.cpp | 7 ++- src/encryption/DeviceVerificationFlow.h | 32 +++++------ src/notifications/Manager.h | 5 +- src/notifications/ManagerWin.cpp | 15 ++++-- src/timeline/EventStore.h | 10 ++-- src/timeline/TimelineModel.cpp | 36 ++++++------- src/ui/FlatButton.cpp | 4 -- src/ui/FlatButton.h | 2 - src/ui/RaisedButton.cpp | 2 - src/ui/RaisedButton.h | 1 - src/ui/ThemeManager.cpp | 2 - src/ui/ThemeManager.h | 2 +- src/voip/CallDevices.h | 4 +- src/voip/WebRTCSession.cpp | 9 +++- 22 files changed, 116 insertions(+), 114 deletions(-) diff --git a/.clang-format b/.clang-format index b5e2f017..e9ebcb6d 100644 --- a/.clang-format +++ b/.clang-format @@ -4,7 +4,7 @@ Standard: c++17 AccessModifierOffset: -4 AlignAfterOpenBracket: Align AlignConsecutiveAssignments: true -AllowShortFunctionsOnASingleLine: true +AllowShortFunctionsOnASingleLine: InlineOnly BasedOnStyle: Mozilla ColumnLimit: 100 IndentCaseLabels: false @@ -12,3 +12,4 @@ IndentWidth: 4 KeepEmptyLinesAtTheStartOfBlocks: false PointerAlignment: Right Cpp11BracedListStyle: true +PenaltyReturnTypeOnItsOwnLine: 0 diff --git a/src/BlurhashProvider.h b/src/BlurhashProvider.h index 1c8351f2..08693673 100644 --- a/src/BlurhashProvider.h +++ b/src/BlurhashProvider.h @@ -42,8 +42,8 @@ class BlurhashProvider { Q_OBJECT public slots: - QQuickImageResponse *requestImageResponse(const QString &id, - const QSize &requestedSize) override + QQuickImageResponse * + requestImageResponse(const QString &id, const QSize &requestedSize) override { BlurhashResponse *response = new BlurhashResponse(id, requestedSize); pool.start(response); diff --git a/src/Cache_p.h b/src/Cache_p.h index 67185298..a48588e1 100644 --- a/src/Cache_p.h +++ b/src/Cache_p.h @@ -47,9 +47,8 @@ public: std::string statusMessage(const std::string &user_id); // user cache stores user keys - std::map> getMembersWithKeys( - const std::string &room_id, - bool verified_only); + std::map> + getMembersWithKeys(const std::string &room_id, bool verified_only); void updateUserKeys(const std::string &sync_token, const mtx::responses::QueryKeys &keyQuery); void markUserKeysOutOfDate(const std::vector &user_ids); void markUserKeysOutOfDate(lmdb::txn &txn, @@ -90,8 +89,8 @@ public: //! Get a specific state event template - std::optional> getStateEvent(const std::string &room_id, - std::string_view state_key = "") + std::optional> + getStateEvent(const std::string &room_id, std::string_view state_key = "") { auto txn = lmdb::txn::begin(env_, nullptr, MDB_RDONLY); return getStateEvent(txn, room_id, state_key); @@ -99,14 +98,12 @@ public: //! retrieve a specific event from account data //! pass empty room_id for global account data - std::optional getAccountData( - mtx::events::EventType type, - const std::string &room_id = ""); + std::optional + getAccountData(mtx::events::EventType type, const std::string &room_id = ""); //! Retrieve member info from a room. - std::vector getMembers(const std::string &room_id, - std::size_t startIndex = 0, - std::size_t len = 30); + std::vector + getMembers(const std::string &room_id, std::size_t startIndex = 0, std::size_t len = 30); std::vector getMembersFromInvite(const std::string &room_id, std::size_t startIndex = 0, @@ -186,8 +183,8 @@ public: uint64_t index = std::numeric_limits::max(), bool forward = false); - std::optional getEvent(const std::string &room_id, - const std::string &event_id); + std::optional + getEvent(const std::string &room_id, const std::string &event_id); void storeEvent(const std::string &room_id, const std::string &event_id, const mtx::events::collections::TimelineEvent &event); @@ -203,9 +200,8 @@ public: std::optional getTimelineRange(const std::string &room_id); std::optional getTimelineIndex(const std::string &room_id, std::string_view event_id); std::optional getEventIndex(const std::string &room_id, std::string_view event_id); - std::optional> lastInvisibleEventAfter( - const std::string &room_id, - std::string_view event_id); + std::optional> + lastInvisibleEventAfter(const std::string &room_id, std::string_view event_id); std::optional getTimelineEventId(const std::string &room_id, uint64_t index); std::optional getArrivalIndex(const std::string &room_id, std::string_view event_id); @@ -213,8 +209,8 @@ public: uint64_t saveOldMessages(const std::string &room_id, const mtx::responses::Messages &res); void savePendingMessage(const std::string &room_id, const mtx::events::collections::TimelineEvent &message); - std::optional firstPendingMessage( - const std::string &room_id); + std::optional + firstPendingMessage(const std::string &room_id); void removePendingStatus(const std::string &room_id, const std::string &txn_id); //! clear timeline keeping only the latest batch @@ -228,14 +224,14 @@ public: std::vector getParentRoomIds(const std::string &room_id); std::vector getChildRoomIds(const std::string &room_id); - std::vector getImagePacks(const std::string &room_id, - std::optional stickers); + std::vector + getImagePacks(const std::string &room_id, std::optional stickers); //! Mark a room that uses e2e encryption. void setEncryptedRoom(lmdb::txn &txn, const std::string &room_id); bool isRoomEncrypted(const std::string &room_id); - std::optional roomEncryptionSettings( - const std::string &room_id); + std::optional + roomEncryptionSettings(const std::string &room_id); //! Check if a user is a member of the room. bool isRoomMember(const std::string &user_id, const std::string &room_id); @@ -273,8 +269,8 @@ public: mtx::crypto::OlmSessionPtr session, uint64_t timestamp); std::vector getOlmSessions(const std::string &curve25519); - std::optional getOlmSession(const std::string &curve25519, - const std::string &session_id); + std::optional + getOlmSession(const std::string &curve25519, const std::string &session_id); std::optional getLatestOlmSession(const std::string &curve25519); void saveOlmAccount(const std::string &pickled); @@ -331,8 +327,8 @@ private: const QList &res); //! Get timeline items that a user was mentions in for a given room - mtx::responses::Notifications getTimelineMentionsForRoom(lmdb::txn &txn, - const std::string &room_id); + mtx::responses::Notifications + getTimelineMentionsForRoom(lmdb::txn &txn, const std::string &room_id); QString getInviteRoomName(lmdb::txn &txn, lmdb::dbi &statesdb, lmdb::dbi &membersdb); QString getInviteRoomTopic(lmdb::txn &txn, lmdb::dbi &statesdb); @@ -447,9 +443,8 @@ private: } template - std::optional> getStateEvent(lmdb::txn &txn, - const std::string &room_id, - std::string_view state_key = "") + std::optional> + getStateEvent(lmdb::txn &txn, const std::string &room_id, std::string_view state_key = "") { try { constexpr auto type = mtx::events::state_content_to_type; @@ -492,8 +487,8 @@ private: } template - std::vector> getStateEventsWithType(lmdb::txn &txn, - const std::string &room_id) + std::vector> + getStateEventsWithType(lmdb::txn &txn, const std::string &room_id) { constexpr auto type = mtx::events::state_content_to_type; @@ -531,16 +526,16 @@ private: return events; } - void saveInvites(lmdb::txn &txn, - const std::map &rooms); + void + saveInvites(lmdb::txn &txn, const std::map &rooms); void savePresence( lmdb::txn &txn, const std::vector> &presenceUpdates); //! Sends signals for the rooms that are removed. - void removeLeftRooms(lmdb::txn &txn, - const std::map &rooms) + void + removeLeftRooms(lmdb::txn &txn, const std::map &rooms) { for (const auto &room : rooms) { removeRoom(txn, room.first); diff --git a/src/CompletionProxyModel.h b/src/CompletionProxyModel.h index c6331a2d..8a485aea 100644 --- a/src/CompletionProxyModel.h +++ b/src/CompletionProxyModel.h @@ -163,9 +163,8 @@ public: QModelIndex mapFromSource(const QModelIndex &sourceIndex) const override; QModelIndex mapToSource(const QModelIndex &proxyIndex) const override; - QModelIndex index(int row, - int column, - const QModelIndex &parent = QModelIndex()) const override; + QModelIndex + index(int row, int column, const QModelIndex &parent = QModelIndex()) const override; QModelIndex parent(const QModelIndex &) const override; public slots: diff --git a/src/Config.h b/src/Config.h index 97669822..4b3fff7b 100644 --- a/src/Config.h +++ b/src/Config.h @@ -61,8 +61,8 @@ const QRegularExpression url_regex( // vvvv atomic match url -> fail if there is a " before or after vvv R"((?((www\.(?!\.)|[a-z][a-z0-9+.-]*://)[^\s<>'"]+[^!,\.\s<>'"\]\)\:]))(?!["']))"); // match any markdown matrix.to link. Capture group 1 is the link name, group 2 is the target. -static const QRegularExpression matrixToMarkdownLink( - R"(\[(.*?)(?(.*?))"); } diff --git a/src/JdenticonProvider.h b/src/JdenticonProvider.h index f4ef6d10..95f3db78 100644 --- a/src/JdenticonProvider.h +++ b/src/JdenticonProvider.h @@ -50,8 +50,8 @@ public: static bool isAvailable() { return Jdenticon::getJdenticonInterface() != nullptr; } public slots: - QQuickImageResponse *requestImageResponse(const QString &id, - const QSize &requestedSize) override + QQuickImageResponse * + requestImageResponse(const QString &id, const QSize &requestedSize) override { auto id_ = id; bool crop = true; diff --git a/src/MainWindow.h b/src/MainWindow.h index b9d2fe5f..7d47d7ce 100644 --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -57,16 +57,16 @@ public: static MainWindow *instance() { return instance_; } void saveCurrentWindowSize(); - void openCreateRoomDialog( - std::function callback); + void + openCreateRoomDialog(std::function callback); void openJoinRoomDialog(std::function callback); void openLogoutDialog(); void hideOverlay(); void showSolidOverlayModal(QWidget *content, QFlags flags = Qt::AlignCenter); - void showTransparentOverlayModal(QWidget *content, - QFlags flags = Qt::AlignTop | - Qt::AlignHCenter); + void + showTransparentOverlayModal(QWidget *content, + QFlags flags = Qt::AlignTop | Qt::AlignHCenter); protected: void closeEvent(QCloseEvent *event) override; diff --git a/src/MxcImageProvider.h b/src/MxcImageProvider.h index 3cf5bbf4..5d5b9c77 100644 --- a/src/MxcImageProvider.h +++ b/src/MxcImageProvider.h @@ -49,8 +49,8 @@ class MxcImageProvider { Q_OBJECT public slots: - QQuickImageResponse *requestImageResponse(const QString &id, - const QSize &requestedSize) override; + QQuickImageResponse * + requestImageResponse(const QString &id, const QSize &requestedSize) override; static void addEncryptionInfo(mtx::crypto::EncryptedFile info); static void download(const QString &id, diff --git a/src/encryption/DeviceVerificationFlow.cpp b/src/encryption/DeviceVerificationFlow.cpp index f05d5c9f..42a0d041 100644 --- a/src/encryption/DeviceVerificationFlow.cpp +++ b/src/encryption/DeviceVerificationFlow.cpp @@ -662,9 +662,12 @@ DeviceVerificationFlow::sendVerificationRequest() } else if (this->type == DeviceVerificationFlow::Type::RoomMsg && model_) { req.to = this->toClient.to_string(); req.msgtype = "m.key.verification.request"; + // clang-format off + // clang-format < 12 is buggy on this req.body = "User is requesting to verify keys with you. However, your client does " - "not support this method, so you will need to use the legacy method of " - "key verification."; + "not support this method, so you will need to use the legacy method of " + "key verification."; + // clang-format on } send(req); diff --git a/src/encryption/DeviceVerificationFlow.h b/src/encryption/DeviceVerificationFlow.h index 537adf31..396421f7 100644 --- a/src/encryption/DeviceVerificationFlow.h +++ b/src/encryption/DeviceVerificationFlow.h @@ -103,22 +103,22 @@ public: }; Q_ENUM(Error) - static QSharedPointer NewInRoomVerification( - QObject *parent_, - TimelineModel *timelineModel_, - const mtx::events::msg::KeyVerificationRequest &msg, - QString other_user_, - QString event_id_); - static QSharedPointer NewToDeviceVerification( - QObject *parent_, - const mtx::events::msg::KeyVerificationRequest &msg, - QString other_user_, - QString txn_id_); - static QSharedPointer NewToDeviceVerification( - QObject *parent_, - const mtx::events::msg::KeyVerificationStart &msg, - QString other_user_, - QString txn_id_); + static QSharedPointer + NewInRoomVerification(QObject *parent_, + TimelineModel *timelineModel_, + const mtx::events::msg::KeyVerificationRequest &msg, + QString other_user_, + QString event_id_); + static QSharedPointer + NewToDeviceVerification(QObject *parent_, + const mtx::events::msg::KeyVerificationRequest &msg, + QString other_user_, + QString txn_id_); + static QSharedPointer + NewToDeviceVerification(QObject *parent_, + const mtx::events::msg::KeyVerificationStart &msg, + QString other_user_, + QString txn_id_); static QSharedPointer InitiateUserVerification(QObject *parent_, TimelineModel *timelineModel_, QString userid); static QSharedPointer diff --git a/src/notifications/Manager.h b/src/notifications/Manager.h index da930296..c5253ecb 100644 --- a/src/notifications/Manager.h +++ b/src/notifications/Manager.h @@ -87,9 +87,8 @@ private: #if defined(Q_OS_WINDOWS) private: - void systemPostNotification(const QString &line1, - const QString &line2, - const QString &iconPath); + void + systemPostNotification(const QString &line1, const QString &line2, const QString &iconPath); #endif // these slots are platform specific (D-Bus only) diff --git a/src/notifications/ManagerWin.cpp b/src/notifications/ManagerWin.cpp index 4376e4d8..e90b4c24 100644 --- a/src/notifications/ManagerWin.cpp +++ b/src/notifications/ManagerWin.cpp @@ -100,10 +100,19 @@ NotificationsManager::systemPostNotification(const QString &line1, WinToast::instance()->showToast(templ, new CustomHandler()); } -void NotificationsManager::actionInvoked(uint, QString) {} -void NotificationsManager::notificationReplied(uint, QString) {} +// clang-format off +// clang-format < 12 is buggy on this +void +NotificationsManager::actionInvoked(uint, QString) +{} -void NotificationsManager::notificationClosed(uint, uint) {} +void +NotificationsManager::notificationReplied(uint, QString) +{} + +void +NotificationsManager::notificationClosed(uint, uint) +{} void NotificationsManager::removeNotification(const QString &, const QString &) diff --git a/src/timeline/EventStore.h b/src/timeline/EventStore.h index 1730f9fd..a60507c2 100644 --- a/src/timeline/EventStore.h +++ b/src/timeline/EventStore.h @@ -79,8 +79,8 @@ public: QVariantList reactions(const std::string &event_id); std::vector edits(const std::string &event_id); olm::DecryptionErrorCode decryptionError(std::string id); - void requestSession(const mtx::events::EncryptedEvent &ev, - bool manual); + void + requestSession(const mtx::events::EncryptedEvent &ev, bool manual); int size() const { @@ -121,9 +121,9 @@ public slots: void enableKeyRequests(bool suppressKeyRequests_); private: - olm::DecryptionResult *decryptEvent( - const IdIndex &idx, - const mtx::events::EncryptedEvent &e); + olm::DecryptionResult * + decryptEvent(const IdIndex &idx, + const mtx::events::EncryptedEvent &e); void handle_room_verification(mtx::events::collections::TimelineEvents event); std::string room_id_; diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp index aa7a68f3..4a81b243 100644 --- a/src/timeline/TimelineModel.cpp +++ b/src/timeline/TimelineModel.cpp @@ -126,43 +126,43 @@ struct RoomEventType { return qml_mtx_events::EventType::VideoMessage; } - qml_mtx_events::EventType operator()( - const mtx::events::Event &) + qml_mtx_events::EventType + operator()(const mtx::events::Event &) { return qml_mtx_events::EventType::KeyVerificationRequest; } - qml_mtx_events::EventType operator()( - const mtx::events::Event &) + qml_mtx_events::EventType + operator()(const mtx::events::Event &) { return qml_mtx_events::EventType::KeyVerificationStart; } - qml_mtx_events::EventType operator()( - const mtx::events::Event &) + qml_mtx_events::EventType + operator()(const mtx::events::Event &) { return qml_mtx_events::EventType::KeyVerificationMac; } - qml_mtx_events::EventType operator()( - const mtx::events::Event &) + qml_mtx_events::EventType + operator()(const mtx::events::Event &) { return qml_mtx_events::EventType::KeyVerificationAccept; } - qml_mtx_events::EventType operator()( - const mtx::events::Event &) + qml_mtx_events::EventType + operator()(const mtx::events::Event &) { return qml_mtx_events::EventType::KeyVerificationReady; } - qml_mtx_events::EventType operator()( - const mtx::events::Event &) + qml_mtx_events::EventType + operator()(const mtx::events::Event &) { return qml_mtx_events::EventType::KeyVerificationCancel; } - qml_mtx_events::EventType operator()( - const mtx::events::Event &) + qml_mtx_events::EventType + operator()(const mtx::events::Event &) { return qml_mtx_events::EventType::KeyVerificationKey; } - qml_mtx_events::EventType operator()( - const mtx::events::Event &) + qml_mtx_events::EventType + operator()(const mtx::events::Event &) { return qml_mtx_events::EventType::KeyVerificationDone; } @@ -182,8 +182,8 @@ struct RoomEventType { return qml_mtx_events::EventType::CallHangUp; } - qml_mtx_events::EventType operator()( - const mtx::events::Event &) + qml_mtx_events::EventType + operator()(const mtx::events::Event &) { return qml_mtx_events::EventType::CallCandidates; } diff --git a/src/ui/FlatButton.cpp b/src/ui/FlatButton.cpp index 4d19c8bb..c80a88dc 100644 --- a/src/ui/FlatButton.cpp +++ b/src/ui/FlatButton.cpp @@ -86,8 +86,6 @@ FlatButton::FlatButton(const QString &text, ui::Role role, QWidget *parent, ui:: setRole(role); } -FlatButton::~FlatButton() {} - void FlatButton::applyPreset(ui::ButtonPreset preset) { @@ -615,8 +613,6 @@ FlatButtonStateMachine::FlatButtonStateMachine(FlatButton *parent) addTransition(button_, QEvent::FocusOut, pressed_state_, hovered_state_); } -FlatButtonStateMachine::~FlatButtonStateMachine() {} - void FlatButtonStateMachine::setOverlayOpacity(qreal opacity) { diff --git a/src/ui/FlatButton.h b/src/ui/FlatButton.h index b39c94ac..3f2c3f05 100644 --- a/src/ui/FlatButton.h +++ b/src/ui/FlatButton.h @@ -22,7 +22,6 @@ class FlatButtonStateMachine : public QStateMachine public: explicit FlatButtonStateMachine(FlatButton *parent); - ~FlatButtonStateMachine() override; void setOverlayOpacity(qreal opacity); void setCheckedOverlayProgress(qreal opacity); @@ -101,7 +100,6 @@ public: ui::Role role, QWidget *parent = nullptr, ui::ButtonPreset preset = ui::ButtonPreset::FlatPreset); - ~FlatButton() override; void applyPreset(ui::ButtonPreset preset); diff --git a/src/ui/RaisedButton.cpp b/src/ui/RaisedButton.cpp index fd0cbd76..42afdd37 100644 --- a/src/ui/RaisedButton.cpp +++ b/src/ui/RaisedButton.cpp @@ -74,8 +74,6 @@ RaisedButton::RaisedButton(const QString &text, QWidget *parent) setText(text); } -RaisedButton::~RaisedButton() {} - bool RaisedButton::event(QEvent *event) { diff --git a/src/ui/RaisedButton.h b/src/ui/RaisedButton.h index 277fa7ff..a93fa000 100644 --- a/src/ui/RaisedButton.h +++ b/src/ui/RaisedButton.h @@ -17,7 +17,6 @@ class RaisedButton : public FlatButton public: explicit RaisedButton(QWidget *parent = nullptr); explicit RaisedButton(const QString &text, QWidget *parent = nullptr); - ~RaisedButton() override; protected: bool event(QEvent *event) override; diff --git a/src/ui/ThemeManager.cpp b/src/ui/ThemeManager.cpp index 0c84777a..05c73aa7 100644 --- a/src/ui/ThemeManager.cpp +++ b/src/ui/ThemeManager.cpp @@ -6,8 +6,6 @@ #include "ThemeManager.h" -ThemeManager::ThemeManager() {} - QColor ThemeManager::themeColor(const QString &key) const { diff --git a/src/ui/ThemeManager.h b/src/ui/ThemeManager.h index 5e86c68f..de5307ed 100644 --- a/src/ui/ThemeManager.h +++ b/src/ui/ThemeManager.h @@ -16,7 +16,7 @@ public: QColor themeColor(const QString &key) const; private: - ThemeManager(); + ThemeManager() {} ThemeManager(ThemeManager const &); void operator=(ThemeManager const &); diff --git a/src/voip/CallDevices.h b/src/voip/CallDevices.h index d30ce644..9b234903 100644 --- a/src/voip/CallDevices.h +++ b/src/voip/CallDevices.h @@ -27,8 +27,8 @@ public: bool haveCamera() const; std::vector names(bool isVideo, const std::string &defaultDevice) const; std::vector resolutions(const std::string &cameraName) const; - std::vector frameRates(const std::string &cameraName, - const std::string &resolution) const; + std::vector + frameRates(const std::string &cameraName, const std::string &resolution) const; signals: void devicesChanged(); diff --git a/src/voip/WebRTCSession.cpp b/src/voip/WebRTCSession.cpp index a01b3a39..27e51d9e 100644 --- a/src/voip/WebRTCSession.cpp +++ b/src/voip/WebRTCSession.cpp @@ -1115,7 +1115,14 @@ WebRTCSession::haveLocalPiP() const return false; } -bool WebRTCSession::createOffer(webrtc::CallType, uint32_t) { return false; } +// clang-format off +// clang-format < 12 is buggy on this +bool +WebRTCSession::createOffer(webrtc::CallType, uint32_t) +{ + return false; +} +// clang-format on bool WebRTCSession::acceptOffer(const std::string &)