File indexing completed on 2024-12-15 04:54:36

0001 /*
0002   SPDX-FileCopyrightText: 2015-2024 Laurent Montel <montel@kde.org>
0003 
0004   SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "quicksearchwarning.h"
0008 #include "messagelistsettings.h"
0009 #include <KLocalizedString>
0010 #include <QAction>
0011 using namespace MessageList::Core;
0012 
0013 QuickSearchWarning::QuickSearchWarning(QWidget *parent)
0014     : KMessageWidget(parent)
0015 {
0016     setVisible(false);
0017     setCloseButtonVisible(true);
0018     setMessageType(Warning);
0019     setWordWrap(true);
0020     setPosition(KMessageWidget::Header);
0021     setText(i18n("The words less than 3 letters are ignored."));
0022     auto action = new QAction(i18n("Do not show again"), this);
0023     action->setObjectName(QLatin1StringView("donotshowagain"));
0024     connect(action, &QAction::triggered, this, &QuickSearchWarning::slotDoNotRememberIt);
0025     addAction(action);
0026 }
0027 
0028 QuickSearchWarning::~QuickSearchWarning() = default;
0029 
0030 void QuickSearchWarning::setSearchText(const QString &text)
0031 {
0032     if (!MessageList::MessageListSettings::quickSearchWarningDoNotShowAgain()) {
0033         const QStringList lstText = text.split(QLatin1Char(' '), Qt::SkipEmptyParts);
0034         bool foundLessThanThreeCharacters = false;
0035         for (const QString &splitText : lstText) {
0036             if (splitText.trimmed().size() < 3) {
0037                 foundLessThanThreeCharacters = true;
0038                 break;
0039             }
0040         }
0041         if (foundLessThanThreeCharacters) {
0042             animatedShow();
0043         } else {
0044             animatedHide();
0045         }
0046     }
0047 }
0048 
0049 void QuickSearchWarning::slotDoNotRememberIt()
0050 {
0051     MessageList::MessageListSettings::setQuickSearchWarningDoNotShowAgain(true);
0052     animatedHide();
0053 }
0054 
0055 #include "moc_quicksearchwarning.cpp"