2018-06-26 14:09:39 +02:00
|
|
|
#include "SearchPopup.hpp"
|
2018-01-05 13:42:23 +01:00
|
|
|
|
|
|
|
#include <QHBoxLayout>
|
|
|
|
#include <QLineEdit>
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
|
2018-06-26 15:33:51 +02:00
|
|
|
#include "common/Channel.hpp"
|
2018-06-26 14:09:39 +02:00
|
|
|
#include "widgets/helper/ChannelView.hpp"
|
2018-01-05 13:42:23 +01:00
|
|
|
|
|
|
|
namespace chatterino {
|
2018-06-26 16:37:59 +02:00
|
|
|
|
2018-01-05 13:42:23 +01:00
|
|
|
SearchPopup::SearchPopup()
|
|
|
|
{
|
|
|
|
this->initLayout();
|
|
|
|
this->resize(400, 600);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SearchPopup::initLayout()
|
|
|
|
{
|
|
|
|
// VBOX
|
|
|
|
{
|
|
|
|
QVBoxLayout *layout1 = new QVBoxLayout(this);
|
|
|
|
layout1->setMargin(0);
|
|
|
|
|
|
|
|
// HBOX
|
|
|
|
{
|
|
|
|
QHBoxLayout *layout2 = new QHBoxLayout(this);
|
|
|
|
layout2->setMargin(6);
|
|
|
|
|
|
|
|
// SEARCH INPUT
|
|
|
|
{
|
|
|
|
this->searchInput = new QLineEdit(this);
|
|
|
|
layout2->addWidget(this->searchInput);
|
|
|
|
QObject::connect(this->searchInput, &QLineEdit::returnPressed,
|
|
|
|
[this] { this->performSearch(); });
|
|
|
|
}
|
|
|
|
|
|
|
|
// SEARCH BUTTON
|
|
|
|
{
|
|
|
|
QPushButton *searchButton = new QPushButton(this);
|
|
|
|
searchButton->setText("Search");
|
|
|
|
layout2->addWidget(searchButton);
|
|
|
|
QObject::connect(searchButton, &QPushButton::clicked,
|
|
|
|
[this] { this->performSearch(); });
|
|
|
|
}
|
|
|
|
|
|
|
|
layout1->addLayout(layout2);
|
|
|
|
}
|
|
|
|
|
|
|
|
// CHANNELVIEW
|
|
|
|
{
|
|
|
|
this->channelView = new ChannelView(this);
|
|
|
|
|
|
|
|
layout1->addWidget(this->channelView);
|
|
|
|
}
|
|
|
|
|
|
|
|
this->setLayout(layout1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-24 13:15:41 +01:00
|
|
|
void SearchPopup::setChannel(ChannelPtr channel)
|
2018-01-05 13:42:23 +01:00
|
|
|
{
|
|
|
|
this->snapshot = channel->getMessageSnapshot();
|
|
|
|
this->performSearch();
|
|
|
|
|
|
|
|
this->setWindowTitle("Searching in " + channel->name + "s history");
|
|
|
|
}
|
|
|
|
|
|
|
|
void SearchPopup::performSearch()
|
|
|
|
{
|
|
|
|
QString text = searchInput->text();
|
|
|
|
|
2018-04-18 09:12:29 +02:00
|
|
|
ChannelPtr channel(new Channel("search", Channel::None));
|
2018-01-05 13:42:23 +01:00
|
|
|
|
|
|
|
for (size_t i = 0; i < this->snapshot.getLength(); i++) {
|
2018-06-26 17:06:17 +02:00
|
|
|
chatterino::MessagePtr message = this->snapshot[i];
|
2018-01-05 13:42:23 +01:00
|
|
|
|
2018-01-28 03:29:42 +01:00
|
|
|
if (text.isEmpty() ||
|
|
|
|
message->searchText.indexOf(this->searchInput->text(), 0, Qt::CaseInsensitive) != -1) {
|
2018-01-05 13:42:23 +01:00
|
|
|
channel->addMessage(message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this->channelView->setChannel(channel);
|
|
|
|
}
|
2018-06-26 16:37:59 +02:00
|
|
|
|
2018-01-14 21:55:36 +01:00
|
|
|
} // namespace chatterino
|