From b7213ab1794f998a726e66bddaa32b2823606d18 Mon Sep 17 00:00:00 2001 From: Marcus Hoffmann Date: Fri, 3 Dec 2021 01:00:40 +0100 Subject: [PATCH 01/11] add clion/idea dir to gitignore --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index e91866ed..f34f1349 100644 --- a/.gitignore +++ b/.gitignore @@ -59,6 +59,9 @@ ui_*.h *.swo *.swn +# CLion +/.idea + #####=== CMake ===##### CMakeCache.txt From 5441ea8840892f794d19a57de0301bcb232f4425 Mon Sep 17 00:00:00 2001 From: Marcus Hoffmann Date: Fri, 3 Dec 2021 01:01:06 +0100 Subject: [PATCH 02/11] InputBar: remove unused imports --- src/timeline/InputBar.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/timeline/InputBar.cpp b/src/timeline/InputBar.cpp index bd4f59d8..72ac3a32 100644 --- a/src/timeline/InputBar.cpp +++ b/src/timeline/InputBar.cpp @@ -21,19 +21,15 @@ #include "Cache.h" #include "ChatPage.h" #include "CombinedImagePackModel.h" -#include "CompletionProxyModel.h" #include "Config.h" #include "Logging.h" #include "MainWindow.h" #include "MatrixClient.h" -#include "RoomsModel.h" #include "TimelineModel.h" #include "TimelineViewManager.h" #include "UserSettingsPage.h" -#include "UsersModel.h" #include "Utils.h" #include "dialogs/PreviewUploadOverlay.h" -#include "emoji/EmojiModel.h" #include "blurhash.hpp" From abf4b3a0a3b438ecf040a837957e2b2936b1703d Mon Sep 17 00:00:00 2001 From: Marcus Hoffmann Date: Fri, 3 Dec 2021 01:01:24 +0100 Subject: [PATCH 03/11] InputBar: use QFileInfo::exists() Suggested by: Clazy: Use the static QFileInfo::exists() instead. It's documented to be faster. --- src/timeline/InputBar.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/timeline/InputBar.cpp b/src/timeline/InputBar.cpp index 72ac3a32..6fd5c4f9 100644 --- a/src/timeline/InputBar.cpp +++ b/src/timeline/InputBar.cpp @@ -82,7 +82,7 @@ InputBar::insertMimeData(const QMimeData *md) } } - if (!path.isEmpty() && QFileInfo{path}.exists()) { + if (!path.isEmpty() && QFileInfo::exists(path)) { showPreview(*md, path, formats); } else { nhlog::ui()->warn("Clipboard does not contain any valid file paths."); From 6d8d38490a3a71907cc218d1c9257bbbccb6fdb9 Mon Sep 17 00:00:00 2001 From: Marcus Hoffmann Date: Fri, 3 Dec 2021 01:10:27 +0100 Subject: [PATCH 04/11] InputBar: apply clang-tidy const reference suggestions All suggested by: Clang-Tidy: The parameter 'X' is copied for each invocation but only used as a const reference; consider making it a const reference --- src/timeline/InputBar.cpp | 20 ++++++++++---------- src/timeline/InputBar.h | 14 +++++++------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/timeline/InputBar.cpp b/src/timeline/InputBar.cpp index 6fd5c4f9..feec2aa0 100644 --- a/src/timeline/InputBar.cpp +++ b/src/timeline/InputBar.cpp @@ -155,7 +155,7 @@ InputBar::updateAtRoom(const QString &t) } void -InputBar::setText(QString newText) +InputBar::setText(const QString& newText) { if (history_.empty()) history_.push_front(newText); @@ -170,7 +170,7 @@ InputBar::setText(QString newText) emit textChanged(newText); } void -InputBar::updateState(int selectionStart_, int selectionEnd_, int cursorPosition_, QString text_) +InputBar::updateState(int selectionStart_, int selectionEnd_, int cursorPosition_, const QString& text_) { if (text_.isEmpty()) stopTyping(); @@ -288,7 +288,7 @@ InputBar::openFileSelection() } void -InputBar::message(QString msg, MarkdownOverride useMarkdown, bool rainbowify) +InputBar::message(const QString& msg, MarkdownOverride useMarkdown, bool rainbowify) { mtx::events::msg::Text text = {}; text.body = msg.trimmed().toStdString(); @@ -352,7 +352,7 @@ InputBar::message(QString msg, MarkdownOverride useMarkdown, bool rainbowify) } void -InputBar::emote(QString msg, bool rainbowify) +InputBar::emote(const QString& msg, bool rainbowify) { auto html = utils::markdownToHtml(msg, rainbowify); @@ -380,7 +380,7 @@ InputBar::emote(QString msg, bool rainbowify) } void -InputBar::notice(QString msg, bool rainbowify) +InputBar::notice(const QString& msg, bool rainbowify) { auto html = utils::markdownToHtml(msg, rainbowify); @@ -562,7 +562,7 @@ InputBar::sticker(CombinedImagePackModel *model, int row) } void -InputBar::command(QString command, QString args) +InputBar::command(const QString& command, QString args) { if (command == "me") { emote(args, false); @@ -594,7 +594,7 @@ InputBar::command(QString command, QString args) http::client()->send_state_event(room->roomId().toStdString(), http::client()->user_id().to_string(), member, - [](mtx::responses::EventId, mtx::http::RequestErr err) { + [](const mtx::responses::EventId&, mtx::http::RequestErr err) { if (err) nhlog::net()->error( "Failed to set room displayname: {}", @@ -650,7 +650,7 @@ InputBar::command(QString command, QString args) } void -InputBar::showPreview(const QMimeData &source, QString path, const QStringList &formats) +InputBar::showPreview(const QMimeData &source, const QString& path, const QStringList &formats) { dialogs::PreviewUploadOverlay *previewDialog_ = new dialogs::PreviewUploadOverlay(ChatPage::instance()); @@ -668,7 +668,7 @@ InputBar::showPreview(const QMimeData &source, QString path, const QStringList & } else if (!path.isEmpty()) previewDialog_->setPreview(path); else if (!formats.isEmpty()) { - auto mime = formats.first(); + const auto& mime = formats.first(); previewDialog_->setPreview(source.data(mime), mime); } else { setUploading(false); @@ -684,7 +684,7 @@ InputBar::showPreview(const QMimeData &source, QString path, const QStringList & previewDialog_, &dialogs::PreviewUploadOverlay::confirmUpload, this, - [this](const QByteArray data, const QString &mime, const QString &fn) { + [this](const QByteArray& data, const QString &mime, const QString &fn) { if (!data.size()) { nhlog::ui()->warn("Attempted to upload zero-byte file?! Mimetype {}, filename {}", mime.toStdString(), diff --git a/src/timeline/InputBar.h b/src/timeline/InputBar.h index 4a0f4401..3beff0b3 100644 --- a/src/timeline/InputBar.h +++ b/src/timeline/InputBar.h @@ -48,17 +48,17 @@ public slots: QString text() const; QString previousText(); QString nextText(); - void setText(QString newText); + void setText(const QString& newText); bool containsAtRoom() const { return containsAtRoom_; } void send(); void paste(bool fromMouse); void insertMimeData(const QMimeData *data); - void updateState(int selectionStart, int selectionEnd, int cursorPosition, QString text); + void updateState(int selectionStart, int selectionEnd, int cursorPosition, const QString& text); void openFileSelection(); bool uploading() const { return uploading_; } - void message(QString body, + void message(const QString& body, MarkdownOverride useMarkdown = MarkdownOverride::NOT_SPECIFIED, bool rainbowify = false); void reaction(const QString &reactedEvent, const QString &reactionKey); @@ -75,9 +75,9 @@ signals: void containsAtRoomChanged(); private: - void emote(QString body, bool rainbowify); - void notice(QString body, bool rainbowify); - void command(QString name, QString args); + void emote(const QString& body, bool rainbowify); + void notice(const QString& body, bool rainbowify); + void command(const QString& name, QString args); void image(const QString &filename, const std::optional &file, const QString &url, @@ -101,7 +101,7 @@ private: const QString &mime, uint64_t dsize); - void showPreview(const QMimeData &source, QString path, const QStringList &formats); + void showPreview(const QMimeData &source, const QString& path, const QStringList &formats); void setUploading(bool value) { if (value != uploading_) { From 02aa87590b68e9daa5e1925806c27fa974a67208 Mon Sep 17 00:00:00 2001 From: Marcus Hoffmann Date: Fri, 3 Dec 2021 01:14:02 +0100 Subject: [PATCH 05/11] InputBar: use character argument instead of string Suggested-by: Clang-Tidy: 'find' called with a string literal consisting of a single character; consider using the more effective overload accepting a character --- src/timeline/InputBar.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/timeline/InputBar.cpp b/src/timeline/InputBar.cpp index feec2aa0..3e1ab1a1 100644 --- a/src/timeline/InputBar.cpp +++ b/src/timeline/InputBar.cpp @@ -301,7 +301,7 @@ InputBar::message(const QString& msg, MarkdownOverride useMarkdown, bool rainbow text.body = msg.trimmed().replace(conf::strings::matrixToMarkdownLink, "\\1").toStdString(); // Don't send formatted_body, when we don't need to - if (text.formatted_body.find("<") == std::string::npos) + if (text.formatted_body.find('<') == std::string::npos) text.formatted_body = ""; else text.format = "org.matrix.custom.html"; From 313bd649dd6cbdd2bf78387aae3674680079fa98 Mon Sep 17 00:00:00 2001 From: Marcus Hoffmann Date: Fri, 3 Dec 2021 01:19:09 +0100 Subject: [PATCH 06/11] InputBar: use multi-arg string replacement This could actually change the behaviour here (could, because I don't know if we can hit this special case) but this should hopefully the correct way of doing this. There's some detailed explanation of the difference here: https://doc.qt.io/qt-5/qstring.html#arg-14 > This is the same as str.arg(a1).arg(a2), except that the strings > a1 and a2 are replaced in one pass. This can make a difference if > a1 contains e.g. %1: ``` QString str; str = "%1 %2"; str.arg("%1f", "Hello"); // returns "%1f Hello" str.arg("%1f").arg("Hello"); // returns "Hellof %2" ``` Suggested-by: Clazy: Use multi-arg instead --- src/timeline/InputBar.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/timeline/InputBar.cpp b/src/timeline/InputBar.cpp index 3e1ab1a1..6e1733a1 100644 --- a/src/timeline/InputBar.cpp +++ b/src/timeline/InputBar.cpp @@ -324,13 +324,13 @@ InputBar::message(const QString& msg, MarkdownOverride useMarkdown, bool rainbow for (const auto &line : related.quoted_body.split("\n")) { if (firstLine) { firstLine = false; - body = QString("> <%1> %2\n").arg(related.quoted_user).arg(line); + body = QString("> <%1> %2\n").arg(related.quoted_user, line); } else { body += QString("> %1\n").arg(line); } } - text.body = QString("%1\n%2").arg(body).arg(msg).toStdString(); + text.body = QString("%1\n%2").arg(body, msg).toStdString(); // NOTE(Nico): rich replies always need a formatted_body! text.format = "org.matrix.custom.html"; From abcbcecac1cd56cbc19f4d8211b0acddecbd0e87 Mon Sep 17 00:00:00 2001 From: Marcus Hoffmann Date: Fri, 3 Dec 2021 01:26:19 +0100 Subject: [PATCH 07/11] InputBar: use auto type Suggested-by: Clang-Tidy: Use auto when initializing with new to avoid duplicating the type name --- src/timeline/InputBar.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/timeline/InputBar.cpp b/src/timeline/InputBar.cpp index 6e1733a1..2133deb7 100644 --- a/src/timeline/InputBar.cpp +++ b/src/timeline/InputBar.cpp @@ -652,7 +652,7 @@ InputBar::command(const QString& command, QString args) void InputBar::showPreview(const QMimeData &source, const QString& path, const QStringList &formats) { - dialogs::PreviewUploadOverlay *previewDialog_ = + auto *previewDialog_ = new dialogs::PreviewUploadOverlay(ChatPage::instance()); previewDialog_->setAttribute(Qt::WA_DeleteOnClose); From 8aa4a60d12801734462ecb22e146501241fa4683 Mon Sep 17 00:00:00 2001 From: Marcus Hoffmann Date: Fri, 3 Dec 2021 01:28:01 +0100 Subject: [PATCH 08/11] InputBar: use X.empty() instead of !X.size() Suggested-by: Clang-Tidy: The 'empty' method should be used to check for emptiness instead of 'size' --- src/timeline/InputBar.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/timeline/InputBar.cpp b/src/timeline/InputBar.cpp index 2133deb7..16372f59 100644 --- a/src/timeline/InputBar.cpp +++ b/src/timeline/InputBar.cpp @@ -657,8 +657,8 @@ 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.size() || formats.front() != "image/svg+xml")) { - if (formats.size() && formats.front().startsWith("image/")) { + if (source.hasImage() && (formats.empty() || formats.front() != "image/svg+xml")) { + if (!formats.empty() && formats.front().startsWith("image/")) { // known format, keep as-is previewDialog_->setPreview(qvariant_cast(source.imageData()), formats.front()); } else { From 9676b7709d92fd474c29134144a4636a7cb1e30d Mon Sep 17 00:00:00 2001 From: Marcus Hoffmann Date: Fri, 3 Dec 2021 01:29:15 +0100 Subject: [PATCH 09/11] InputBar: mark constrictor as explicit Suggested-By: Clang-Tidy: Single-argument constructors must be marked explicit to avoid unintentional implicit conversions More info: https://clang.llvm.org/extra/clang-tidy/checks/google-explicit-constructor.html --- src/timeline/InputBar.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/timeline/InputBar.h b/src/timeline/InputBar.h index 3beff0b3..399dd116 100644 --- a/src/timeline/InputBar.h +++ b/src/timeline/InputBar.h @@ -32,7 +32,7 @@ class InputBar : public QObject Q_PROPERTY(QString text READ text NOTIFY textChanged) public: - InputBar(TimelineModel *parent) + explicit InputBar(TimelineModel *parent) : QObject() , room(parent) { From a9d8059fb26920402da346f9319dfd1eb117f875 Mon Sep 17 00:00:00 2001 From: Marcus Hoffmann Date: Fri, 3 Dec 2021 01:34:34 +0100 Subject: [PATCH 10/11] InputBar: Mark some functions as [[nodiscard]] This warns when you the return value of those functions isn't used. Suggested-by: Clang-Tidy: Function X should be marked [[nodiscard]] --- src/timeline/InputBar.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/timeline/InputBar.h b/src/timeline/InputBar.h index 399dd116..78f16139 100644 --- a/src/timeline/InputBar.h +++ b/src/timeline/InputBar.h @@ -45,19 +45,19 @@ public: } public slots: - QString text() const; + [[nodiscard]] QString text() const; QString previousText(); QString nextText(); void setText(const QString& newText); - bool containsAtRoom() const { return containsAtRoom_; } + [[nodiscard]] bool containsAtRoom() const { return containsAtRoom_; } void send(); void paste(bool fromMouse); void insertMimeData(const QMimeData *data); void updateState(int selectionStart, int selectionEnd, int cursorPosition, const QString& text); void openFileSelection(); - bool uploading() const { return uploading_; } + [[nodiscard]] bool uploading() const { return uploading_; } void message(const QString& body, MarkdownOverride useMarkdown = MarkdownOverride::NOT_SPECIFIED, bool rainbowify = false); From a01bc14db60158f16f15909b2abf835777993cb2 Mon Sep 17 00:00:00 2001 From: Marcus Hoffmann Date: Fri, 3 Dec 2021 01:54:43 +0100 Subject: [PATCH 11/11] InputBar: run clang-format --- src/timeline/InputBar.cpp | 42 ++++++++++++++++++++------------------- src/timeline/InputBar.h | 14 ++++++------- 2 files changed, 29 insertions(+), 27 deletions(-) diff --git a/src/timeline/InputBar.cpp b/src/timeline/InputBar.cpp index 16372f59..78416135 100644 --- a/src/timeline/InputBar.cpp +++ b/src/timeline/InputBar.cpp @@ -155,7 +155,7 @@ InputBar::updateAtRoom(const QString &t) } void -InputBar::setText(const QString& newText) +InputBar::setText(const QString &newText) { if (history_.empty()) history_.push_front(newText); @@ -170,7 +170,10 @@ InputBar::setText(const QString& newText) emit textChanged(newText); } void -InputBar::updateState(int selectionStart_, int selectionEnd_, int cursorPosition_, const QString& text_) +InputBar::updateState(int selectionStart_, + int selectionEnd_, + int cursorPosition_, + const QString &text_) { if (text_.isEmpty()) stopTyping(); @@ -288,7 +291,7 @@ InputBar::openFileSelection() } void -InputBar::message(const QString& msg, MarkdownOverride useMarkdown, bool rainbowify) +InputBar::message(const QString &msg, MarkdownOverride useMarkdown, bool rainbowify) { mtx::events::msg::Text text = {}; text.body = msg.trimmed().toStdString(); @@ -352,7 +355,7 @@ InputBar::message(const QString& msg, MarkdownOverride useMarkdown, bool rainbow } void -InputBar::emote(const QString& msg, bool rainbowify) +InputBar::emote(const QString &msg, bool rainbowify) { auto html = utils::markdownToHtml(msg, rainbowify); @@ -380,7 +383,7 @@ InputBar::emote(const QString& msg, bool rainbowify) } void -InputBar::notice(const QString& msg, bool rainbowify) +InputBar::notice(const QString &msg, bool rainbowify) { auto html = utils::markdownToHtml(msg, rainbowify); @@ -562,7 +565,7 @@ InputBar::sticker(CombinedImagePackModel *model, int row) } void -InputBar::command(const QString& command, QString args) +InputBar::command(const QString &command, QString args) { if (command == "me") { emote(args, false); @@ -591,15 +594,15 @@ InputBar::command(const QString& command, QString args) .toStdString(); member.membership = mtx::events::state::Membership::Join; - http::client()->send_state_event(room->roomId().toStdString(), - http::client()->user_id().to_string(), - member, - [](const mtx::responses::EventId&, mtx::http::RequestErr err) { - if (err) - nhlog::net()->error( - "Failed to set room displayname: {}", - err->matrix_error.error); - }); + http::client()->send_state_event( + room->roomId().toStdString(), + http::client()->user_id().to_string(), + member, + [](const mtx::responses::EventId &, mtx::http::RequestErr err) { + if (err) + nhlog::net()->error("Failed to set room displayname: {}", + err->matrix_error.error); + }); } else if (command == "shrug") { message("¯\\_(ツ)_/¯" + (args.isEmpty() ? "" : " " + args)); } else if (command == "fliptable") { @@ -650,10 +653,9 @@ InputBar::command(const QString& command, QString args) } void -InputBar::showPreview(const QMimeData &source, const QString& path, const QStringList &formats) +InputBar::showPreview(const QMimeData &source, const QString &path, const QStringList &formats) { - auto *previewDialog_ = - new dialogs::PreviewUploadOverlay(ChatPage::instance()); + auto *previewDialog_ = new dialogs::PreviewUploadOverlay(ChatPage::instance()); previewDialog_->setAttribute(Qt::WA_DeleteOnClose); // Force SVG to _not_ be handled as an image, but as raw data @@ -668,7 +670,7 @@ InputBar::showPreview(const QMimeData &source, const QString& path, const QStrin } else if (!path.isEmpty()) previewDialog_->setPreview(path); else if (!formats.isEmpty()) { - const auto& mime = formats.first(); + const auto &mime = formats.first(); previewDialog_->setPreview(source.data(mime), mime); } else { setUploading(false); @@ -684,7 +686,7 @@ InputBar::showPreview(const QMimeData &source, const QString& path, const QStrin previewDialog_, &dialogs::PreviewUploadOverlay::confirmUpload, this, - [this](const QByteArray& data, const QString &mime, const QString &fn) { + [this](const QByteArray &data, const QString &mime, const QString &fn) { if (!data.size()) { nhlog::ui()->warn("Attempted to upload zero-byte file?! Mimetype {}, filename {}", mime.toStdString(), diff --git a/src/timeline/InputBar.h b/src/timeline/InputBar.h index 78f16139..65593244 100644 --- a/src/timeline/InputBar.h +++ b/src/timeline/InputBar.h @@ -48,17 +48,17 @@ public slots: [[nodiscard]] QString text() const; QString previousText(); QString nextText(); - void setText(const QString& newText); + void setText(const QString &newText); [[nodiscard]] bool containsAtRoom() const { return containsAtRoom_; } void send(); void paste(bool fromMouse); void insertMimeData(const QMimeData *data); - void updateState(int selectionStart, int selectionEnd, int cursorPosition, const QString& text); + void updateState(int selectionStart, int selectionEnd, int cursorPosition, const QString &text); void openFileSelection(); [[nodiscard]] bool uploading() const { return uploading_; } - void message(const QString& body, + void message(const QString &body, MarkdownOverride useMarkdown = MarkdownOverride::NOT_SPECIFIED, bool rainbowify = false); void reaction(const QString &reactedEvent, const QString &reactionKey); @@ -75,9 +75,9 @@ signals: void containsAtRoomChanged(); private: - void emote(const QString& body, bool rainbowify); - void notice(const QString& body, bool rainbowify); - void command(const QString& name, QString args); + void emote(const QString &body, bool rainbowify); + void notice(const QString &body, bool rainbowify); + void command(const QString &name, QString args); void image(const QString &filename, const std::optional &file, const QString &url, @@ -101,7 +101,7 @@ private: const QString &mime, uint64_t dsize); - void showPreview(const QMimeData &source, const QString& path, const QStringList &formats); + void showPreview(const QMimeData &source, const QString &path, const QStringList &formats); void setUploading(bool value) { if (value != uploading_) {