[network/ruqola] src/widgets/dialogs: Fix unique command + fix generate space etc.
Laurent Montel <[email protected]>
| Newsgroups | gmane.comp.kde.cvs |
|---|---|
| Message-ID | <[email protected]> |
Git commit 4306ac2a93501fab1387af4fcfbb412b2e9003a6 by Laurent Montel.
Committed on 14/08/2026 at 16:22.
Pushed by mlaurent into branch 'master'.
Fix unique command + fix generate space etc.
M +3 -3 src/widgets/dialogs/autotests/searchmessagecommandtest.cpp
M +6 -1 src/widgets/dialogs/searchmessagecommand.cpp
M +1 -0 src/widgets/dialogs/searchmessagecommand.h
M +27 -43 src/widgets/dialogs/searchmessagecommandbuttonwidget.cpp
M +5 -1 src/widgets/dialogs/searchmessagecommandbuttonwidget.h
M +20 -4 src/widgets/dialogs/searchmessagewithdelaylineedit.cpp
M +1 -1 src/widgets/dialogs/searchmessagewithdelaylineedit.h
https://invent.kde.org/network/ruqola/-/commit/4306ac2a93501fab1387af4fcfbb412b2e9003a6
diff --git a/src/widgets/dialogs/autotests/searchmessagecommandtest.cpp b/src/widgets/dialogs/autotests/searchmessagecommandtest.cpp
index 89813626cf..c9a608f9dd 100644
--- a/src/widgets/dialogs/autotests/searchmessagecommandtest.cpp
+++ b/src/widgets/dialogs/autotests/searchmessagecommandtest.cpp
@@ -35,9 +35,9 @@ void SearchMessageCommandTest::shouldVerifyNeedUnique()
QVERIFY(SearchMessageCommand::mustBeUnique(SearchMessageCommand::SearchMessageCommandType::IsPinned));
QVERIFY(SearchMessageCommand::mustBeUnique(SearchMessageCommand::SearchMessageCommandType::HasUrl));
QVERIFY(SearchMessageCommand::mustBeUnique(SearchMessageCommand::SearchMessageCommandType::HasLocation));
- QVERIFY(!SearchMessageCommand::mustBeUnique(SearchMessageCommand::SearchMessageCommandType::Before));
- QVERIFY(!SearchMessageCommand::mustBeUnique(SearchMessageCommand::SearchMessageCommandType::After));
- QVERIFY(!SearchMessageCommand::mustBeUnique(SearchMessageCommand::SearchMessageCommandType::Day));
+ QVERIFY(SearchMessageCommand::mustBeUnique(SearchMessageCommand::SearchMessageCommandType::Before));
+ QVERIFY(SearchMessageCommand::mustBeUnique(SearchMessageCommand::SearchMessageCommandType::After));
+ QVERIFY(SearchMessageCommand::mustBeUnique(SearchMessageCommand::SearchMessageCommandType::Day));
QVERIFY(SearchMessageCommand::mustBeUnique(SearchMessageCommand::SearchMessageCommandType::Order));
QVERIFY(SearchMessageCommand::mustBeUnique(SearchMessageCommand::SearchMessageCommandType::FromMe));
QVERIFY(!SearchMessageCommand::mustBeUnique(SearchMessageCommand::SearchMessageCommandType::FromUserName));
diff --git a/src/widgets/dialogs/searchmessagecommand.cpp b/src/widgets/dialogs/searchmessagecommand.cpp
index f24fd81506..2a2cc54e54 100644
--- a/src/widgets/dialogs/searchmessagecommand.cpp
+++ b/src/widgets/dialogs/searchmessagecommand.cpp
@@ -41,7 +41,12 @@ QString SearchMessageCommand::generateCommandText(SearchMessageCommand::SearchMe
bool SearchMessageCommand::mustBeUnique(SearchMessageCommand::SearchMessageCommandType type)
{
- return type == HasStar || type == IsPinned || type == HasUrl || type == HasLocation || type == Order || type == FromMe;
+ return type == HasStar || type == IsPinned || type == HasUrl || type == HasLocation || type == Order || type == FromMe || type == Before || type == After
+ || type == Day;
}
+bool SearchMessageCommand::needSpace(SearchMessageCommand::SearchMessageCommandType type)
+{
+ return type == HasStar || type == IsPinned || type == HasUrl || type == HasLocation || type == Order || type == FromMe || type == FromUserName;
+}
#include "moc_searchmessagecommand.cpp"
diff --git a/src/widgets/dialogs/searchmessagecommand.h b/src/widgets/dialogs/searchmessagecommand.h
index 4660ab0644..a361eb03ab 100644
--- a/src/widgets/dialogs/searchmessagecommand.h
+++ b/src/widgets/dialogs/searchmessagecommand.h
@@ -31,4 +31,5 @@ public:
[[nodiscard]] static QString generateCommandText(SearchMessageCommand::SearchMessageCommandType type);
[[nodiscard]] static bool mustBeUnique(SearchMessageCommand::SearchMessageCommandType type);
+ [[nodiscard]] static bool needSpace(SearchMessageCommand::SearchMessageCommandType type);
};
diff --git a/src/widgets/dialogs/searchmessagecommandbuttonwidget.cpp b/src/widgets/dialogs/searchmessagecommandbuttonwidget.cpp
index 5e36a77d6f..bf5009125d 100644
--- a/src/widgets/dialogs/searchmessagecommandbuttonwidget.cpp
+++ b/src/widgets/dialogs/searchmessagecommandbuttonwidget.cpp
@@ -5,7 +5,6 @@
*/
#include "searchmessagecommandbuttonwidget.h"
-#include "dialogs/searchmessagecommand.h"
#include <KLocalizedString>
#include <QPushButton>
#include <TextAddonsWidgets/TextAddonsWidgetFlowLayout>
@@ -28,49 +27,33 @@ SearchMessageCommandButtonWidget::SearchMessageCommandButtonWidget(QWidget *pare
SearchMessageCommandButtonWidget::~SearchMessageCommandButtonWidget() = default;
+SearchMessageCommandButtonWidget::ButtonInfo
+SearchMessageCommandButtonWidget::createButtonInfo(SearchMessageCommand::SearchMessageCommandType type, const QString &title, const QString &tooltip) const
+{
+ return {SearchMessageCommand::generateCommandText(type), title, tooltip, SearchMessageCommand::mustBeUnique(type), SearchMessageCommand::needSpace(type)};
+}
+
QList<SearchMessageCommandButtonWidget::ButtonInfo> SearchMessageCommandButtonWidget::fillCommandLineText() const
{
const QList<SearchMessageCommandButtonWidget::ButtonInfo> buttonInfo = {
- {SearchMessageCommand::generateCommandText(SearchMessageCommand::FromMe),
- i18nc("@action:button", "From Me"),
- i18nc("@info:tooltip", "Finds Messages sent by you."),
- SearchMessageCommand::mustBeUnique(SearchMessageCommand::FromMe)},
- {SearchMessageCommand::generateCommandText(SearchMessageCommand::FromUserName),
- i18nc("@action:button", "From"),
- i18nc("@info:tooltip", "Finds Messages from a specific user. (Use the username format without space)"),
- SearchMessageCommand::mustBeUnique(SearchMessageCommand::FromUserName)},
- {SearchMessageCommand::generateCommandText(SearchMessageCommand::Order),
- i18nc("@action:button", "Order:desc"),
- i18nc("@info:tooltip", "Sorts message by descending timestamp"),
- SearchMessageCommand::mustBeUnique(SearchMessageCommand::Order)},
- {SearchMessageCommand::generateCommandText(SearchMessageCommand::Before),
- i18nc("@action:button", "Before"),
- i18nc("@info:tooltip", "Filter by date as %1", u"before:dd/mm/yyyy"_s),
- SearchMessageCommand::mustBeUnique(SearchMessageCommand::Before)},
- {SearchMessageCommand::generateCommandText(SearchMessageCommand::After),
- i18nc("@action:button", "After"),
- i18nc("@info:tooltip", "Filter by date as %1", u"after:dd/mm/yyyy"_s),
- SearchMessageCommand::mustBeUnique(SearchMessageCommand::After)},
- {SearchMessageCommand::generateCommandText(SearchMessageCommand::Day),
- i18nc("@action:button", "Day"),
- i18nc("@info:tooltip", "Filter by date as %1", u"on:dd/mm/yyyy"_s),
- SearchMessageCommand::mustBeUnique(SearchMessageCommand::Day)},
- {SearchMessageCommand::generateCommandText(SearchMessageCommand::HasLocation),
- i18nc("@action:button", "Has Location"),
- i18nc("@info:tooltip", "Finds messages that include a location."),
- SearchMessageCommand::mustBeUnique(SearchMessageCommand::HasLocation)},
- {SearchMessageCommand::generateCommandText(SearchMessageCommand::HasUrl),
- i18nc("@action:button", "Has Url"),
- i18nc("@info:tooltip", "Finds messages that contain a link"),
- SearchMessageCommand::mustBeUnique(SearchMessageCommand::HasUrl)},
- {SearchMessageCommand::generateCommandText(SearchMessageCommand::IsPinned),
- i18nc("@action:button", "Is Pinned"),
- i18nc("@info:tooltip", "Displays pinned messages in the current room."),
- SearchMessageCommand::mustBeUnique(SearchMessageCommand::IsPinned)},
- {SearchMessageCommand::generateCommandText(SearchMessageCommand::HasStar),
- i18nc("@action:button", "Has Star"),
- i18nc("@info:tooltip", "Shows messages you've starred."),
- SearchMessageCommand::mustBeUnique(SearchMessageCommand::HasStar)},
+ createButtonInfo(SearchMessageCommand::FromMe, i18nc("@action:button", "From Me"), i18nc("@info:tooltip", "Finds Messages sent by you.")),
+ createButtonInfo(SearchMessageCommand::FromUserName,
+ i18nc("@action:button", "From"),
+ i18nc("@info:tooltip", "Finds Messages from a specific user. (Use the username format without space)")),
+ createButtonInfo(SearchMessageCommand::Order, i18nc("@action:button", "Order:desc"), i18nc("@info:tooltip", "Sorts message by descending timestamp")),
+ createButtonInfo(SearchMessageCommand::Before,
+ i18nc("@action:button", "Before"),
+ i18nc("@info:tooltip", "Filter by date as %1", u"before:dd/mm/yyyy"_s)),
+ createButtonInfo(SearchMessageCommand::After, i18nc("@action:button", "After"), i18nc("@info:tooltip", "Filter by date as %1", u"after:dd/mm/yyyy"_s)),
+ createButtonInfo(SearchMessageCommand::Day, i18nc("@action:button", "Day"), i18nc("@info:tooltip", "Filter by date as %1", u"on:dd/mm/yyyy"_s)),
+ createButtonInfo(SearchMessageCommand::HasLocation,
+ i18nc("@action:button", "Has Location"),
+ i18nc("@info:tooltip", "Finds messages that include a location.")),
+ createButtonInfo(SearchMessageCommand::HasUrl, i18nc("@action:button", "Has Url"), i18nc("@info:tooltip", "Finds messages that contain a link")),
+ createButtonInfo(SearchMessageCommand::IsPinned,
+ i18nc("@action:button", "Is Pinned"),
+ i18nc("@info:tooltip", "Displays pinned messages in the current room.")),
+ createButtonInfo(SearchMessageCommand::HasStar, i18nc("@action:button", "Has Star"), i18nc("@info:tooltip", "Shows messages you've starred.")),
};
return buttonInfo;
}
@@ -82,8 +65,9 @@ QPushButton *SearchMessageCommandButtonWidget::createPushButton(const SearchMess
pushButton->setToolTip(info.toolTip);
const QString identifier = info.identifier;
const bool needSpace = info.needSpace;
- connect(pushButton, &QPushButton::clicked, this, [this, identifier, needSpace]() {
- Q_EMIT insertSearchString(needSpace ? identifier + u' ' : identifier);
+ const bool unique = info.unique;
+ connect(pushButton, &QPushButton::clicked, this, [this, identifier, needSpace, unique]() {
+ Q_EMIT insertSearchString(needSpace, identifier, unique);
});
return pushButton;
}
diff --git a/src/widgets/dialogs/searchmessagecommandbuttonwidget.h b/src/widgets/dialogs/searchmessagecommandbuttonwidget.h
index cda3029f94..d79568743d 100644
--- a/src/widgets/dialogs/searchmessagecommandbuttonwidget.h
+++ b/src/widgets/dialogs/searchmessagecommandbuttonwidget.h
@@ -5,6 +5,7 @@
*/
#pragma once
+#include "dialogs/searchmessagecommand.h"
#include "libruqolawidgets_private_export.h"
#include <QWidget>
class QPushButton;
@@ -16,15 +17,18 @@ public:
~SearchMessageCommandButtonWidget() override;
Q_SIGNALS:
- void insertSearchString(const QString &);
+ void insertSearchString(bool needSpace, const QString &, bool unique);
private:
struct ButtonInfo {
QString identifier;
QString i18n;
QString toolTip;
+ bool unique = false;
bool needSpace = false;
};
[[nodiscard]] LIBRUQOLAWIDGETS_NO_EXPORT QList<SearchMessageCommandButtonWidget::ButtonInfo> fillCommandLineText() const;
[[nodiscard]] LIBRUQOLAWIDGETS_NO_EXPORT QPushButton *createPushButton(const ButtonInfo &info);
+ [[nodiscard]] LIBRUQOLAWIDGETS_NO_EXPORT SearchMessageCommandButtonWidget::ButtonInfo
+ createButtonInfo(SearchMessageCommand::SearchMessageCommandType type, const QString &title, const QString &tooltip) const;
};
diff --git a/src/widgets/dialogs/searchmessagewithdelaylineedit.cpp b/src/widgets/dialogs/searchmessagewithdelaylineedit.cpp
index 9b1de602e9..749bed945f 100644
--- a/src/widgets/dialogs/searchmessagewithdelaylineedit.cpp
+++ b/src/widgets/dialogs/searchmessagewithdelaylineedit.cpp
@@ -67,12 +67,28 @@ void SearchMessageWithDelayLineEdit::addCompletionItem(const QString &str)
}
}
-void SearchMessageWithDelayLineEdit::insertSearchString(const QString &str)
+void SearchMessageWithDelayLineEdit::insertSearchString(bool needSpace, const QString &str, bool unique)
{
- if (!text().isEmpty()) {
- insert(u' ' + str);
+ const QString currentText = text();
+ if (unique && currentText.contains(str)) {
+ return;
+ }
+ if (!currentText.isEmpty()) {
+ QString newText = currentText;
+ if (!newText.endsWith(QLatin1Char(' '))) {
+ newText += u' ';
+ }
+ newText += str;
+ if (needSpace) {
+ newText += u' ';
+ }
+ setText(newText);
} else {
- insert(str);
+ QString newText = str;
+ if (needSpace) {
+ newText += u' ';
+ }
+ insert(newText);
}
}
diff --git a/src/widgets/dialogs/searchmessagewithdelaylineedit.h b/src/widgets/dialogs/searchmessagewithdelaylineedit.h
index 4fd75c8572..073b296786 100644
--- a/src/widgets/dialogs/searchmessagewithdelaylineedit.h
+++ b/src/widgets/dialogs/searchmessagewithdelaylineedit.h
@@ -22,7 +22,7 @@ public:
~SearchMessageWithDelayLineEdit() override;
void addCompletionItem(const QString &str);
- void insertSearchString(const QString &str);
+ void insertSearchString(bool needSpace, const QString &str, bool unique);
[[nodiscard]] SearchMessageWithDelayLineEdit::SearchRegularExpressionInfo searchRegularExpressionInfo() const;