mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
Merge pull request #1281 from Chatterino/logsGtSearch
Allow searching in LogsPopup
This commit is contained in:
commit
dd996d1b8a
8 changed files with 93 additions and 80 deletions
|
@ -222,6 +222,7 @@ SOURCES += \
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
src/Application.hpp \
|
src/Application.hpp \
|
||||||
|
src/ForwardDecl.hpp \
|
||||||
src/autogenerated/ResourcesAutogen.hpp \
|
src/autogenerated/ResourcesAutogen.hpp \
|
||||||
src/BrowserExtension.hpp \
|
src/BrowserExtension.hpp \
|
||||||
src/common/Aliases.hpp \
|
src/common/Aliases.hpp \
|
||||||
|
|
10
src/ForwardDecl.hpp
Normal file
10
src/ForwardDecl.hpp
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace chatterino {
|
||||||
|
class Channel;
|
||||||
|
class ChannelView;
|
||||||
|
using ChannelPtr = std::shared_ptr<Channel>;
|
||||||
|
|
||||||
|
struct Message;
|
||||||
|
using MessagePtr = std::shared_ptr<const Message>;
|
||||||
|
} // namespace chatterino
|
|
@ -1,3 +1,5 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
# include <fmt/format.h>
|
# include <fmt/format.h>
|
||||||
# include <irccommand.h>
|
# include <irccommand.h>
|
||||||
|
|
|
@ -22,7 +22,7 @@ public:
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
std::size_t size()
|
std::size_t size() const
|
||||||
{
|
{
|
||||||
return this->length_;
|
return this->length_;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#include "common/Channel.hpp"
|
#include "common/Channel.hpp"
|
||||||
#include "common/NetworkRequest.hpp"
|
#include "common/NetworkRequest.hpp"
|
||||||
#include "debug/Log.hpp"
|
#include "debug/Log.hpp"
|
||||||
|
#include "messages/Message.hpp"
|
||||||
#include "providers/twitch/PartialTwitchUser.hpp"
|
#include "providers/twitch/PartialTwitchUser.hpp"
|
||||||
#include "providers/twitch/TwitchChannel.hpp"
|
#include "providers/twitch/TwitchChannel.hpp"
|
||||||
#include "providers/twitch/TwitchMessageBuilder.hpp"
|
#include "providers/twitch/TwitchMessageBuilder.hpp"
|
||||||
|
@ -20,34 +21,30 @@ namespace chatterino {
|
||||||
LogsPopup::LogsPopup()
|
LogsPopup::LogsPopup()
|
||||||
: channel_(Channel::getEmpty())
|
: channel_(Channel::getEmpty())
|
||||||
{
|
{
|
||||||
this->initLayout();
|
|
||||||
this->resize(400, 600);
|
this->resize(400, 600);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LogsPopup::initLayout()
|
void LogsPopup::setChannel(const ChannelPtr &channel)
|
||||||
{
|
|
||||||
QVBoxLayout *layout = new QVBoxLayout(this);
|
|
||||||
layout->setMargin(0);
|
|
||||||
|
|
||||||
this->channelView_ = new ChannelView(this);
|
|
||||||
layout->addWidget(this->channelView_);
|
|
||||||
|
|
||||||
this->setLayout(layout);
|
|
||||||
}
|
|
||||||
|
|
||||||
void LogsPopup::setChannelName(QString channelName)
|
|
||||||
{
|
|
||||||
this->channelName_ = channelName;
|
|
||||||
}
|
|
||||||
|
|
||||||
void LogsPopup::setChannel(std::shared_ptr<Channel> channel)
|
|
||||||
{
|
{
|
||||||
this->channel_ = channel;
|
this->channel_ = channel;
|
||||||
|
this->updateWindowTitle();
|
||||||
}
|
}
|
||||||
|
|
||||||
void LogsPopup::setTargetUserName(QString userName)
|
void LogsPopup::setChannelName(const QString &channelName)
|
||||||
|
{
|
||||||
|
this->channelName_ = channelName;
|
||||||
|
this->updateWindowTitle();
|
||||||
|
}
|
||||||
|
|
||||||
|
void LogsPopup::setTargetUserName(const QString &userName)
|
||||||
{
|
{
|
||||||
this->userName_ = userName;
|
this->userName_ = userName;
|
||||||
|
this->updateWindowTitle();
|
||||||
|
}
|
||||||
|
|
||||||
|
void LogsPopup::updateWindowTitle()
|
||||||
|
{
|
||||||
|
this->setWindowTitle(this->userName_ + "'s logs in #" + this->channelName_);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LogsPopup::getLogs()
|
void LogsPopup::getLogs()
|
||||||
|
@ -60,8 +57,6 @@ void LogsPopup::getLogs()
|
||||||
this->channelName_ = twitchChannel->getName();
|
this->channelName_ = twitchChannel->getName();
|
||||||
this->getLogviewerLogs(twitchChannel->roomId());
|
this->getLogviewerLogs(twitchChannel->roomId());
|
||||||
|
|
||||||
this->setWindowTitle(this->userName_ + "'s logs in #" +
|
|
||||||
this->channelName_);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -83,7 +78,7 @@ void LogsPopup::setMessages(std::vector<MessagePtr> &messages)
|
||||||
ChannelPtr logsChannel(new Channel("logs", Channel::Type::Misc));
|
ChannelPtr logsChannel(new Channel("logs", Channel::Type::Misc));
|
||||||
|
|
||||||
logsChannel->addMessagesAtStart(messages);
|
logsChannel->addMessagesAtStart(messages);
|
||||||
this->channelView_->setChannel(logsChannel);
|
SearchPopup::setChannel(logsChannel);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LogsPopup::getLogviewerLogs(const QString &roomID)
|
void LogsPopup::getLogviewerLogs(const QString &roomID)
|
||||||
|
@ -121,6 +116,8 @@ void LogsPopup::getLogviewerLogs(const QString &roomID)
|
||||||
static_cast<Communi::IrcPrivateMessage *>(ircMessage);
|
static_cast<Communi::IrcPrivateMessage *>(ircMessage);
|
||||||
TwitchMessageBuilder builder(this->channel_.get(), privMsg,
|
TwitchMessageBuilder builder(this->channel_.get(), privMsg,
|
||||||
args);
|
args);
|
||||||
|
builder.message().searchText = message;
|
||||||
|
|
||||||
messages.push_back(builder.build());
|
messages.push_back(builder.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,6 +162,7 @@ void LogsPopup::getOverrustleLogs()
|
||||||
for (auto i : dataMessages)
|
for (auto i : dataMessages)
|
||||||
{
|
{
|
||||||
QJsonObject singleMessage = i.toObject();
|
QJsonObject singleMessage = i.toObject();
|
||||||
|
auto text = singleMessage.value("text").toString();
|
||||||
QTime timeStamp =
|
QTime timeStamp =
|
||||||
QDateTime::fromSecsSinceEpoch(
|
QDateTime::fromSecsSinceEpoch(
|
||||||
singleMessage.value("timestamp").toInt())
|
singleMessage.value("timestamp").toInt())
|
||||||
|
@ -175,9 +173,9 @@ void LogsPopup::getOverrustleLogs()
|
||||||
builder.emplace<TextElement>(this->userName_,
|
builder.emplace<TextElement>(this->userName_,
|
||||||
MessageElementFlag::Username,
|
MessageElementFlag::Username,
|
||||||
MessageColor::System);
|
MessageColor::System);
|
||||||
builder.emplace<TextElement>(
|
builder.emplace<TextElement>(text, MessageElementFlag::Text,
|
||||||
singleMessage.value("text").toString(),
|
MessageColor::Text);
|
||||||
MessageElementFlag::Text, MessageColor::Text);
|
builder.message().searchText = text;
|
||||||
messages.push_back(builder.release());
|
messages.push_back(builder.release());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -191,4 +189,5 @@ void LogsPopup::getOverrustleLogs()
|
||||||
})
|
})
|
||||||
.execute();
|
.execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace chatterino
|
} // namespace chatterino
|
||||||
|
|
|
@ -1,37 +1,29 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "widgets/BaseWindow.hpp"
|
#include "widgets/helper/SearchPopup.hpp"
|
||||||
|
|
||||||
namespace chatterino {
|
namespace chatterino {
|
||||||
|
|
||||||
class Channel;
|
class LogsPopup : public SearchPopup
|
||||||
class ChannelView;
|
|
||||||
|
|
||||||
class Channel;
|
|
||||||
using ChannelPtr = std::shared_ptr<Channel>;
|
|
||||||
|
|
||||||
struct Message;
|
|
||||||
using MessagePtr = std::shared_ptr<const Message>;
|
|
||||||
|
|
||||||
class LogsPopup : public BaseWindow
|
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
LogsPopup();
|
LogsPopup();
|
||||||
|
|
||||||
void setChannelName(QString channelName);
|
void setChannel(const ChannelPtr &channel) override;
|
||||||
void setChannel(std::shared_ptr<Channel> channel);
|
void setChannelName(const QString &channelName);
|
||||||
void setTargetUserName(QString userName);
|
void setTargetUserName(const QString &userName);
|
||||||
|
|
||||||
void getLogs();
|
void getLogs();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void updateWindowTitle() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ChannelView *channelView_ = nullptr;
|
|
||||||
ChannelPtr channel_;
|
ChannelPtr channel_;
|
||||||
|
|
||||||
QString userName_;
|
QString userName_;
|
||||||
QString channelName_;
|
QString channelName_;
|
||||||
|
|
||||||
void initLayout();
|
|
||||||
void setMessages(std::vector<MessagePtr> &messages);
|
void setMessages(std::vector<MessagePtr> &messages);
|
||||||
void getOverrustleLogs();
|
void getOverrustleLogs();
|
||||||
void getLogviewerLogs(const QString &roomID);
|
void getLogviewerLogs(const QString &roomID);
|
||||||
|
|
|
@ -10,6 +10,26 @@
|
||||||
#include "widgets/helper/ChannelView.hpp"
|
#include "widgets/helper/ChannelView.hpp"
|
||||||
|
|
||||||
namespace chatterino {
|
namespace chatterino {
|
||||||
|
namespace {
|
||||||
|
ChannelPtr filter(const QString &text, const QString &channelName,
|
||||||
|
const LimitedQueueSnapshot<MessagePtr> &snapshot)
|
||||||
|
{
|
||||||
|
ChannelPtr channel(new Channel(channelName, Channel::Type::None));
|
||||||
|
|
||||||
|
for (size_t i = 0; i < snapshot.size(); i++)
|
||||||
|
{
|
||||||
|
MessagePtr message = snapshot[i];
|
||||||
|
|
||||||
|
if (text.isEmpty() ||
|
||||||
|
message->searchText.indexOf(text, 0, Qt::CaseInsensitive) != -1)
|
||||||
|
{
|
||||||
|
channel->addMessage(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return channel;
|
||||||
|
}
|
||||||
|
} // namespace
|
||||||
|
|
||||||
SearchPopup::SearchPopup()
|
SearchPopup::SearchPopup()
|
||||||
{
|
{
|
||||||
|
@ -17,13 +37,24 @@ SearchPopup::SearchPopup()
|
||||||
this->resize(400, 600);
|
this->resize(400, 600);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SearchPopup::setChannel(ChannelPtr channel)
|
void SearchPopup::setChannel(const ChannelPtr &channel)
|
||||||
{
|
{
|
||||||
this->channelName_ = channel->getName();
|
this->channelName_ = channel->getName();
|
||||||
this->snapshot_ = channel->getMessageSnapshot();
|
this->snapshot_ = channel->getMessageSnapshot();
|
||||||
this->performSearch();
|
this->search();
|
||||||
|
|
||||||
this->setWindowTitle("Searching in " + channel->getName() + "s history");
|
this->updateWindowTitle();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SearchPopup::updateWindowTitle()
|
||||||
|
{
|
||||||
|
this->setWindowTitle("Searching in " + this->channelName_ + "s history");
|
||||||
|
}
|
||||||
|
|
||||||
|
void SearchPopup::search()
|
||||||
|
{
|
||||||
|
this->channelView_->setChannel(filter(this->searchInput_->text(),
|
||||||
|
this->channelName_, this->snapshot_));
|
||||||
}
|
}
|
||||||
|
|
||||||
void SearchPopup::keyPressEvent(QKeyEvent *e)
|
void SearchPopup::keyPressEvent(QKeyEvent *e)
|
||||||
|
@ -43,18 +74,20 @@ void SearchPopup::initLayout()
|
||||||
{
|
{
|
||||||
QVBoxLayout *layout1 = new QVBoxLayout(this);
|
QVBoxLayout *layout1 = new QVBoxLayout(this);
|
||||||
layout1->setMargin(0);
|
layout1->setMargin(0);
|
||||||
|
layout1->setSpacing(0);
|
||||||
|
|
||||||
// HBOX
|
// HBOX
|
||||||
{
|
{
|
||||||
QHBoxLayout *layout2 = new QHBoxLayout(this);
|
QHBoxLayout *layout2 = new QHBoxLayout(this);
|
||||||
layout2->setMargin(6);
|
layout2->setMargin(8);
|
||||||
|
layout2->setSpacing(8);
|
||||||
|
|
||||||
// SEARCH INPUT
|
// SEARCH INPUT
|
||||||
{
|
{
|
||||||
this->searchInput_ = new QLineEdit(this);
|
this->searchInput_ = new QLineEdit(this);
|
||||||
layout2->addWidget(this->searchInput_);
|
layout2->addWidget(this->searchInput_);
|
||||||
QObject::connect(this->searchInput_, &QLineEdit::returnPressed,
|
QObject::connect(this->searchInput_, &QLineEdit::returnPressed,
|
||||||
[this] { this->performSearch(); });
|
[this] { this->search(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
// SEARCH BUTTON
|
// SEARCH BUTTON
|
||||||
|
@ -63,7 +96,7 @@ void SearchPopup::initLayout()
|
||||||
searchButton->setText("Search");
|
searchButton->setText("Search");
|
||||||
layout2->addWidget(searchButton);
|
layout2->addWidget(searchButton);
|
||||||
QObject::connect(searchButton, &QPushButton::clicked,
|
QObject::connect(searchButton, &QPushButton::clicked,
|
||||||
[this] { this->performSearch(); });
|
[this] { this->search(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
layout1->addLayout(layout2);
|
layout1->addLayout(layout2);
|
||||||
|
@ -80,25 +113,4 @@ void SearchPopup::initLayout()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SearchPopup::performSearch()
|
|
||||||
{
|
|
||||||
QString text = searchInput_->text();
|
|
||||||
|
|
||||||
ChannelPtr channel(new Channel(this->channelName_, Channel::Type::None));
|
|
||||||
|
|
||||||
for (size_t i = 0; i < this->snapshot_.size(); i++)
|
|
||||||
{
|
|
||||||
MessagePtr message = this->snapshot_[i];
|
|
||||||
|
|
||||||
if (text.isEmpty() ||
|
|
||||||
message->searchText.indexOf(this->searchInput_->text(), 0,
|
|
||||||
Qt::CaseInsensitive) != -1)
|
|
||||||
{
|
|
||||||
channel->addMessage(message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this->channelView_->setChannel(channel);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace chatterino
|
} // namespace chatterino
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "ForwardDecl.hpp"
|
||||||
#include "messages/LimitedQueueSnapshot.hpp"
|
#include "messages/LimitedQueueSnapshot.hpp"
|
||||||
#include "widgets/BaseWindow.hpp"
|
#include "widgets/BaseWindow.hpp"
|
||||||
|
|
||||||
|
@ -9,30 +10,26 @@ class QLineEdit;
|
||||||
|
|
||||||
namespace chatterino {
|
namespace chatterino {
|
||||||
|
|
||||||
class Channel;
|
|
||||||
class ChannelView;
|
|
||||||
|
|
||||||
struct Message;
|
|
||||||
using MessagePtr = std::shared_ptr<const Message>;
|
|
||||||
|
|
||||||
class SearchPopup : public BaseWindow
|
class SearchPopup : public BaseWindow
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SearchPopup();
|
SearchPopup();
|
||||||
|
|
||||||
void setChannel(std::shared_ptr<Channel> channel);
|
virtual void setChannel(const ChannelPtr &channel);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void keyPressEvent(QKeyEvent *e) override;
|
void keyPressEvent(QKeyEvent *e) override;
|
||||||
|
|
||||||
|
virtual void updateWindowTitle();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void initLayout();
|
void initLayout();
|
||||||
void performSearch();
|
void search();
|
||||||
|
|
||||||
LimitedQueueSnapshot<MessagePtr> snapshot_;
|
LimitedQueueSnapshot<MessagePtr> snapshot_;
|
||||||
QLineEdit *searchInput_;
|
QLineEdit *searchInput_{};
|
||||||
ChannelView *channelView_;
|
ChannelView *channelView_{};
|
||||||
QString channelName_;
|
QString channelName_{};
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace chatterino
|
} // namespace chatterino
|
||||||
|
|
Loading…
Reference in a new issue