Browse Source

feat: edit load history for search

reviewable/pr4955/r1
TriKriSta 8 years ago
parent
commit
de9c906117
  1. 2
      src/chatlog/chatlog.cpp
  2. 1
      src/chatlog/chatlog.h
  3. 24
      src/persistence/history.cpp
  4. 1
      src/persistence/history.h
  5. 91
      src/widget/form/chatform.cpp
  6. 2
      src/widget/form/chatform.h
  7. 26
      src/widget/searchform.cpp
  8. 22
      src/widget/searchform.h

2
src/chatlog/chatlog.cpp

@ -815,6 +815,8 @@ void ChatLog::onWorkerTimeout() @@ -815,6 +815,8 @@ void ChatLog::onWorkerTimeout()
// hidden during busy screen
verticalScrollBar()->show();
emit workerTimeoutFinished();
}
}

1
src/chatlog/chatlog.h

@ -67,6 +67,7 @@ public: @@ -67,6 +67,7 @@ public:
signals:
void selectionChanged();
void workerTimeoutFinished();
public slots:
void forceRelayout();

24
src/persistence/history.cpp

@ -326,6 +326,30 @@ QList<History::DateMessages> History::getChatHistoryCounts(const ToxPk& friendPk @@ -326,6 +326,30 @@ QList<History::DateMessages> History::getChatHistoryCounts(const ToxPk& friendPk
return counts;
}
QDateTime History::getStartDateChatHistory(const QString& friendPk)
{
QList<QDateTime> counts;
auto rowCallback = [&counts](const QVector<QVariant>& row) {
counts.append(QDateTime::fromMSecsSinceEpoch(row[0].toLongLong()));
};
QString queryText =
QString("SELECT timestamp "
"FROM history "
"LEFT JOIN faux_offline_pending ON history.id = faux_offline_pending.id "
"JOIN peers chat ON chat_id = chat.id "
"WHERE chat.public_key='%1' ORDER BY timestamp ASC LIMIT 1;")
.arg(friendPk);
db->execNow({queryText, rowCallback});
if (!counts.isEmpty()) {
return counts[0];
}
return QDateTime();
}
/**
* @brief Marks a message as sent.
* Removing message from the faux-offline pending messages list.

1
src/persistence/history.h

@ -82,6 +82,7 @@ public: @@ -82,6 +82,7 @@ public:
const QDateTime& to);
QList<DateMessages> getChatHistoryCounts(const ToxPk& friendPk, const QDate& from, const QDate& to);
QDateTime getStartDateChatHistory(const QString& friendPk);
void markAsSent(qint64 messageId);

91
src/widget/form/chatform.cpp

@ -208,6 +208,8 @@ ChatForm::ChatForm(Friend* chatFriend, History* history) @@ -208,6 +208,8 @@ ChatForm::ChatForm(Friend* chatFriend, History* history)
});
connect(headWidget, &ChatFormHeader::callRejected, this, &ChatForm::onRejectCallTriggered);
connect(chatWidget, &ChatLog::workerTimeoutFinished, this, &ChatForm::onContinueSearch);
updateCallButtons();
if (Nexus::getProfile()->isHistoryEnabled()) {
loadHistory(QDateTime::currentDateTime().addDays(-7), true);
@ -500,9 +502,10 @@ void ChatForm::onSearchTrigered() @@ -500,9 +502,10 @@ void ChatForm::onSearchTrigered()
searchForm->setMaximumHeight(50);
headWidget->updateSearchButton(true);
searchPoint = QPoint(1, -1);
searchAfterLoadHistory = false;
} else {
searchForm->setMaximumHeight(0);
searchForm->removeText();
searchForm->removeSearchPhrase();
headWidget->updateSearchButton(false);
desibleSearchText();
@ -529,40 +532,71 @@ void ChatForm::onSearchUp(const QString &phrase) @@ -529,40 +532,71 @@ void ChatForm::onSearchUp(const QString &phrase)
int startLine = numLines - searchPoint.x();
if (startLine == 0) {
QString pk = f->getPublicKey().toString();
QDateTime startDate = history->getStartDateChatHistory(pk);
if (startDate == earliestMessage) {
return;
}
QDateTime newBaseData = earliestMessage.addDays(-1);
if (startDate > newBaseData) {
newBaseData = startDate;
}
searchAfterLoadHistory = true;
loadHistory(newBaseData);
return;
}
for (int i = startLine; i >= 0; --i) {
ChatLine::Ptr l = lines[i];
if (l->getColumnCount() >= 2) {
ChatLineContent* content = l->getContent(1);
Text* text = static_cast<Text*>(content);
QString txt = content->getText();
if (txt.contains(phrase)) {
int startIndex = -1;
if (searchPoint.y() > -1) {
startIndex = searchPoint.y() - 1;
if (searchPoint.y() == 0) {
text->deselectText();
searchPoint.setY(-1);
} else {
QString txt = content->getText();
if (txt.contains(phrase, Qt::CaseInsensitive)) {
int startIndex = -1;
if (searchPoint.y() > -1) {
startIndex = searchPoint.y() - 1;
}
int index = txt.lastIndexOf(phrase, startIndex, Qt::CaseInsensitive);
if ((index == -1 && searchPoint.y() > -1)) {
text->deselectText();
searchPoint.setY(-1);
} else {
chatWidget->scrollToLine(l);
text->deselectText();
text->selectText(phrase, index);
searchPoint = QPoint(numLines - i, index);
break;
}
}
}
int index = txt.lastIndexOf(phrase, startIndex);
if (index == -1 && searchPoint.y() > -1) {
text->deselectText();
searchPoint.setY(-1);
} else {
chatWidget->scrollToLine(l);
text->deselectText();
text->selectText(phrase, index);
searchPoint = QPoint(numLines - i, index);
if (i == 0) {
QString pk = f->getPublicKey().toString();
QDateTime startDate = history->getStartDateChatHistory(pk);
QDateTime newBaseData = earliestMessage.addDays(-1);
break;
if (startDate > newBaseData) {
newBaseData = startDate;
}
}
if (i == 0) {
searchPoint.setX(numLines);
loadHistory(historyBaselineDate.addDays(-1));
onSearchUp(phrase);
searchAfterLoadHistory = true;
loadHistory(newBaseData);
}
}
}
@ -586,13 +620,13 @@ void ChatForm::onSearchDown(const QString &phrase) @@ -586,13 +620,13 @@ void ChatForm::onSearchDown(const QString &phrase)
Text* text = static_cast<Text*>(content);
QString txt = content->getText();
if (txt.contains(phrase)) {
if (txt.contains(phrase, Qt::CaseInsensitive)) {
int startIndex = 0;
if (searchPoint.y() > -1) {
startIndex = searchPoint.y() + 1;
}
int index = txt.indexOf(phrase, startIndex);
int index = txt.indexOf(phrase, startIndex, Qt::CaseInsensitive);
if (index == -1 && searchPoint.y() > -1) {
text->deselectText();
searchPoint.setY(-1);
@ -609,6 +643,15 @@ void ChatForm::onSearchDown(const QString &phrase) @@ -609,6 +643,15 @@ void ChatForm::onSearchDown(const QString &phrase)
}
}
void ChatForm::onContinueSearch()
{
QString phrase = searchForm->getSearchPhrase();
if (!phrase.isEmpty() && searchAfterLoadHistory) {
searchAfterLoadHistory = false;
onSearchUp(phrase);
}
}
void ChatForm::onFileSendFailed(uint32_t friendId, const QString& fname)
{
if (friendId != f->getId()) {
@ -874,6 +917,10 @@ void ChatForm::loadHistory(const QDateTime& since, bool processUndelivered) @@ -874,6 +917,10 @@ void ChatForm::loadHistory(const QDateTime& since, bool processUndelivered)
chatWidget->insertChatlineOnTop(historyMessages);
savedSliderPos = verticalBar->maximum() - savedSliderPos;
verticalBar->setValue(savedSliderPos);
if (searchAfterLoadHistory && historyMessages.isEmpty()) {
onContinueSearch();
}
}
void ChatForm::onScreenshotClicked()

2
src/widget/form/chatform.h

@ -92,6 +92,7 @@ private slots: @@ -92,6 +92,7 @@ private slots:
void earchInBegin(const QString& phrase);
void onSearchUp(const QString& phrase);
void onSearchDown(const QString& phrase);
void onContinueSearch();
void onFileSendFailed(uint32_t friendId, const QString& fname);
void onFriendStatusChanged(quint32 friendId, Status status);
void onFriendTypingChanged(quint32 friendId, bool isTyping);
@ -144,6 +145,7 @@ private: @@ -144,6 +145,7 @@ private:
bool isTyping;
bool lastCallIsVideo;
QPoint searchPoint;
bool searchAfterLoadHistory;
};
#endif // CHATFORM_H

26
src/widget/searchform.cpp

@ -1,3 +1,22 @@ @@ -1,3 +1,22 @@
/*
Copyright © 2015-2016 by The qTox Project Contributors
This file is part of qTox, a Qt-based graphical interface for Tox.
qTox is libre 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 3 of the License, or
(at your option) any later version.
qTox 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 qTox. If not, see <http://www.gnu.org/licenses/>.
*/
#include "searchform.h"
#include "src/widget/style.h"
#include <QHBoxLayout>
@ -31,11 +50,16 @@ SearchForm::SearchForm(QWidget *parent) : QWidget(parent) @@ -31,11 +50,16 @@ SearchForm::SearchForm(QWidget *parent) : QWidget(parent)
connect(downButton, &QPushButton::clicked, this, &SearchForm::clickedDown);
}
void SearchForm::removeText()
void SearchForm::removeSearchPhrase()
{
searchLine->setText("");
}
QString SearchForm::getSearchPhrase() const
{
return searchPhrase;
}
void SearchForm::changedSearchPhrare(const QString &text)
{
searchPhrase = text;

22
src/widget/searchform.h

@ -1,3 +1,22 @@ @@ -1,3 +1,22 @@
/*
Copyright © 2015-2016 by The qTox Project Contributors
This file is part of qTox, a Qt-based graphical interface for Tox.
qTox is libre 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 3 of the License, or
(at your option) any later version.
qTox 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 qTox. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef SEARCHFORM_H
#define SEARCHFORM_H
@ -11,7 +30,8 @@ class SearchForm final : public QWidget @@ -11,7 +30,8 @@ class SearchForm final : public QWidget
Q_OBJECT
public:
explicit SearchForm(QWidget *parent = nullptr);
void removeText();
void removeSearchPhrase();
QString getSearchPhrase() const;
private:
QPushButton* upButton;

Loading…
Cancel
Save