Git commit 9fa113709e476d302e2dd2a8f86447c997209e51 by Jan Kundr?t. Committed on 28/05/2013 at 17:25. Pushed by jkt into branch 'master'.
GUI: filter out \n when performing the raw IMAP search REVIEW: 110680 M +4 -2 src/Gui/Gui.pro M +4 -0 src/Gui/MessageListWidget.cpp A +44 -0 src/Gui/ReplaceCharValidator.cpp [License: GPL (v2/3)] A +46 -0 src/Gui/ReplaceCharValidator.h [License: GPL (v2/3)] http://commits.kde.org/trojita/9fa113709e476d302e2dd2a8f86447c997209e51 diff --git a/src/Gui/Gui.pro b/src/Gui/Gui.pro index d8c6ed7..13bd104 100644 --- a/src/Gui/Gui.pro +++ b/src/Gui/Gui.pro @@ -55,7 +55,8 @@ SOURCES += \ PasswordDialog.cpp \ ProgressPopUp.cpp \ OverlayWidget.cpp \ - EnvelopeView.cpp + EnvelopeView.cpp \ + ReplaceCharValidator.cpp HEADERS += \ ../Imap/Model/ModelTest/modeltest.h \ ComposeWidget.h \ @@ -96,7 +97,8 @@ HEADERS += \ PasswordDialog.h \ ProgressPopUp.h \ OverlayWidget.h \ - EnvelopeView.h + EnvelopeView.h \ + ReplaceCharValidator.h FORMS += CreateMailboxDialog.ui \ ComposeWidget.ui \ SettingsImapPage.ui \ diff --git a/src/Gui/MessageListWidget.cpp b/src/Gui/MessageListWidget.cpp index 53de93a..1c81523 100644 --- a/src/Gui/MessageListWidget.cpp +++ b/src/Gui/MessageListWidget.cpp @@ -33,6 +33,7 @@ #include "IconLoader.h" #include "LineEdit.h" #include "MsgListView.h" +#include "ReplaceCharValidator.h" namespace Gui { @@ -42,6 +43,9 @@ MessageListWidget::MessageListWidget(QWidget *parent) : tree = new MsgListView(this); m_quickSearchText = new LineEdit(this); + // Filter out newline. It will wreak havoc into the direct IMAP passthrough and could lead to data loss. + QValidator *validator = new ReplaceCharValidator(QLatin1Char('\n'), QLatin1Char(' '), m_quickSearchText); + m_quickSearchText->setValidator(validator); #if QT_VERSION >= 0x040700 m_quickSearchText->setPlaceholderText(tr("Quick Search")); #endif diff --git a/src/Gui/ReplaceCharValidator.cpp b/src/Gui/ReplaceCharValidator.cpp new file mode 100644 index 0000000..09456a4 --- /dev/null +++ b/src/Gui/ReplaceCharValidator.cpp @@ -0,0 +1,44 @@ +/* Copyright (C) 2006 - 2013 Jan Kundr?t <jkt at flaska.net> + + This file is part of the Trojita Qt IMAP e-mail client, + http://trojita.flaska.net/ + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of + the License or (at your option) version 3 or any later version + accepted by the membership of KDE e.V. (or its successor approved + by the membership of KDE e.V.), which shall act as a proxy + defined in Section 14 of version 3 of the license. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include "ReplaceCharValidator.h" + +namespace Gui { + +ReplaceCharValidator::ReplaceCharValidator(const QChar replaceWhat, const QChar replaceBy, QObject *parent): + QValidator(parent), m_replaceWhat(replaceWhat), m_replaceBy(replaceBy) +{ +} + +ReplaceCharValidator::~ReplaceCharValidator() +{ +} + +QValidator::State ReplaceCharValidator::validate(QString &input, int &pos) const +{ + Q_UNUSED(pos); + input.replace(m_replaceWhat, m_replaceBy); + return QValidator::Acceptable; +} + +} + diff --git a/src/Gui/ReplaceCharValidator.h b/src/Gui/ReplaceCharValidator.h new file mode 100644 index 0000000..9d39af6 --- /dev/null +++ b/src/Gui/ReplaceCharValidator.h @@ -0,0 +1,46 @@ +/* Copyright (C) 2006 - 2013 Jan Kundr?t <jkt at flaska.net> + + This file is part of the Trojita Qt IMAP e-mail client, + http://trojita.flaska.net/ + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of + the License or (at your option) version 3 or any later version + accepted by the membership of KDE e.V. (or its successor approved + by the membership of KDE e.V.), which shall act as a proxy + defined in Section 14 of version 3 of the license. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef GUI_REPLACECHARVALIDATOR_H +#define GUI_REPLACECHARVALIDATOR_H + +#include <QValidator> + +namespace Gui { + +/** @short Replace forbidden characters with a safe equivalent */ +class ReplaceCharValidator: public QValidator +{ +Q_OBJECT +public: + ReplaceCharValidator(const QChar replaceWhat, const QChar replaceBy, QObject *parent); + ~ReplaceCharValidator(); + + virtual State validate(QString &input, int &pos) const; + +private: + QChar m_replaceWhat, m_replaceBy; +}; + +} + +#endif // GUI_REPLACECHARVALIDATOR_H
