From 3e05279c097b33b09cedcebae4150c839a23af35 Mon Sep 17 00:00:00 2001 From: TriKriSta Date: Wed, 14 Feb 2018 11:30:38 +0200 Subject: [PATCH] fix: add search symbol ' in history --- src/persistence/history.cpp | 6 +++++- src/persistence/history.h | 2 +- src/widget/form/chatform.cpp | 2 +- src/widget/form/genericchatform.cpp | 8 ++++---- src/widget/form/genericchatform.h | 2 +- src/widget/searchform.cpp | 2 +- src/widget/searchform.h | 1 + 7 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/persistence/history.cpp b/src/persistence/history.cpp index 5aaa18ce3..23a52a43e 100644 --- a/src/persistence/history.cpp +++ b/src/persistence/history.cpp @@ -326,13 +326,17 @@ QList History::getChatHistoryCounts(const ToxPk& friendPk return counts; } -QDateTime History::getDateWhereFindPhrase(const QString& friendPk, const QDateTime& from, const QString& phrase) +QDateTime History::getDateWhereFindPhrase(const QString& friendPk, const QDateTime& from, QString phrase) { QList counts; auto rowCallback = [&counts](const QVector& row) { counts.append(QDateTime::fromMSecsSinceEpoch(row[0].toLongLong())); }; + if (phrase.contains("'")) { + phrase.replace("'", "''"); + } + QString queryText = QString("SELECT timestamp " "FROM history " diff --git a/src/persistence/history.h b/src/persistence/history.h index 956129dbc..6fefd0931 100644 --- a/src/persistence/history.h +++ b/src/persistence/history.h @@ -82,7 +82,7 @@ public: const QDateTime& to); QList getChatHistoryCounts(const ToxPk& friendPk, const QDate& from, const QDate& to); - QDateTime getDateWhereFindPhrase(const QString& friendPk, const QDateTime& from, const QString& phrase); + QDateTime getDateWhereFindPhrase(const QString& friendPk, const QDateTime& from, QString phrase); void markAsSent(qint64 messageId); diff --git a/src/widget/form/chatform.cpp b/src/widget/form/chatform.cpp index c370bdf4a..9a172358f 100644 --- a/src/widget/form/chatform.cpp +++ b/src/widget/form/chatform.cpp @@ -492,7 +492,7 @@ void ChatForm::onVolMuteToggle() void ChatForm::onSearchUp(const QString& phrase) { if (phrase.isEmpty()) { - desibleSearchText(); + disableSearchText(); } QVector lines = chatWidget->getLines(); diff --git a/src/widget/form/genericchatform.cpp b/src/widget/form/genericchatform.cpp index d92e70276..cda76b5c9 100644 --- a/src/widget/form/genericchatform.cpp +++ b/src/widget/form/genericchatform.cpp @@ -543,7 +543,7 @@ void GenericChatForm::addSystemDateMessage() insertChatMessage(ChatMessage::createChatInfoMessage(dateText, ChatMessage::INFO, QDateTime())); } -void GenericChatForm::desibleSearchText() +void GenericChatForm::disableSearchText() { if (searchPoint != QPoint(1, -1)) { QVector lines = chatWidget->getLines(); @@ -563,7 +563,7 @@ bool GenericChatForm::searchInText(const QString& phrase, bool searchUp) bool isSearch = false; if (phrase.isEmpty()) { - desibleSearchText(); + disableSearchText(); } QVector lines = chatWidget->getLines(); @@ -799,7 +799,7 @@ void GenericChatForm::onSearchTriggered() if (searchForm->isHidden()) { searchForm->removeSearchPhrase(); - desibleSearchText(); + disableSearchText(); } else { searchPoint = QPoint(1, -1); searchAfterLoadHistory = false; @@ -808,7 +808,7 @@ void GenericChatForm::onSearchTriggered() void GenericChatForm::searchInBegin(const QString& phrase) { - desibleSearchText(); + disableSearchText(); searchPoint = QPoint(1, -1); onSearchUp(phrase); diff --git a/src/widget/form/genericchatform.h b/src/widget/form/genericchatform.h index 0789d00c2..aebd684a0 100644 --- a/src/widget/form/genericchatform.h +++ b/src/widget/form/genericchatform.h @@ -131,7 +131,7 @@ protected: virtual bool event(QEvent*) final override; virtual void resizeEvent(QResizeEvent* event) final override; virtual bool eventFilter(QObject* object, QEvent* event) final override; - void desibleSearchText(); + void disableSearchText(); bool searchInText(const QString& phrase, bool searchUp); int indexForSearchInLine(const QString& txt, const QString& phrase, bool searchUp); diff --git a/src/widget/searchform.cpp b/src/widget/searchform.cpp index e8a405118..69092e61c 100644 --- a/src/widget/searchform.cpp +++ b/src/widget/searchform.cpp @@ -30,7 +30,7 @@ SearchForm::SearchForm(QWidget* parent) : QWidget(parent) upButton = createButton("searchUpButton", "green"); downButton = createButton("searchDownButton", "green"); - hideButton = createButton("hideButton","red"); + hideButton = createButton("hideButton", "red"); layout->setMargin(0); layout->addWidget(searchLine); diff --git a/src/widget/searchform.h b/src/widget/searchform.h index d7a522c85..988d6763d 100644 --- a/src/widget/searchform.h +++ b/src/widget/searchform.h @@ -39,6 +39,7 @@ protected: virtual void showEvent(QShowEvent* event) final override; private: + // TODO: Merge with 'createButton' from chatformheader.cpp QPushButton* createButton(const QString& name, const QString& state); QPushButton* upButton;