Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Local & Remote filters #60

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
82 changes: 79 additions & 3 deletions src/showbootlog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
#include <QRegularExpression>
#include <QCompleter>
#include <QThread>
#include <QColorDialog>
#include <QRandomGenerator>

ShowBootLog::ShowBootLog(QWidget *parent) :
QDialog(parent),
Expand Down Expand Up @@ -111,6 +113,7 @@ void ShowBootLog::updateBootLog(bool keepIdentifiers)
// Reset all previously accepted but also read identifiers (clear the filter but also do a full reload!)
this->allIdentifiers.clear();
this->acceptedIdentifiers.clear();
this->acceptedIdentifiersColors.clear();
identifierFlags = "";

// Also reset the UI parts
Expand Down Expand Up @@ -165,7 +168,10 @@ void ShowBootLog::updateBootLog(bool keepIdentifiers)
}

// Enable filtering by syslog identifiers
command += identifierFlags;
if(ui->remoteFilterCheckBox->isChecked())
{
command += identifierFlags;
}

// As soon as the connection has data available, we want to append it to the boot log.
// If the connection is already open, we close it!
Expand All @@ -182,16 +188,32 @@ void ShowBootLog::updateBootLog(bool keepIdentifiers)

void ShowBootLog::acceptIdentifier(void){
this->acceptedIdentifiers.insert(ui->identifiersLineEdit->text());
this->acceptedIdentifiersColors.insert(ui->identifiersLineEdit->text(), ui->identifiersLineEdit->palette().color(QPalette::Base));
updateBootLog(true);
ui->identifiersLineEdit->clear();
QPalette palette(QPalette::Base, Qt::white);
ui->identifiersLineEdit->setPalette(palette);
ui->identifiersLineEdit->setFocus();
}


void ShowBootLog::appendToBootLog(QString readString)
{
// Append string to the UI and increment byte counter
ui->plainTextEdit->appendPlainText(readString);
QStringList readStringLines = readString.split("\n");

for ( const auto& line : readStringLines )
{
if(!this->acceptedIdentifiers.empty()) // Needs to appy filters
{
// Append the line with style
appendLineWithFilterStyle(line);
}
else
{
ui->plainTextEdit->appendPlainText(line);
}
}
numberOfBytesRead += readString.size();
ui->plainTextEdit->ensureCursorVisible();

Expand Down Expand Up @@ -228,6 +250,39 @@ void ShowBootLog::appendToBootLog(QString readString)
Qt::QueuedConnection);
}

void ShowBootLog::appendLineWithFilterStyle(QString line)
{
QTextCharFormat defaultFormat, format;
QColor defaultColor, color;
bool found;

// Let's find if regex apply for the current line
found = false;
for(const auto& identifier : this->acceptedIdentifiers){
QRegularExpression re(identifier);
QRegularExpressionMatch match = re.match(line);
found = match.hasMatch();
if(found)
{
color = this->acceptedIdentifiersColors.value(identifier);
break;
}
}

format = ui->plainTextEdit->currentCharFormat();
defaultFormat = format;
if(found)
{
format.setBackground(QBrush(color));
}
else
{
format.setForeground(QBrush(QColor("LightGray")));
}
ui->plainTextEdit->setCurrentCharFormat(format);
ui->plainTextEdit->appendPlainText(line);
ui->plainTextEdit->setCurrentCharFormat(defaultFormat);
}

void ShowBootLog::on_sinceCheckBox_clicked()
{
Expand All @@ -253,6 +308,11 @@ void ShowBootLog::on_untilDateTimeEdit_dateTimeChanged()
updateBootLog(true);
}

void ShowBootLog::on_remoteFilterCheckBox_clicked()
{
updateBootLog(true);
}

void ShowBootLog::on_horizontalSlider_sliderMoved(int position)
{
maxPriority = position;
Expand All @@ -268,7 +328,8 @@ void ShowBootLog::on_filterButton_clicked()
{
acceptIdentifier();
ui->identifiersLineEdit->clear();

QPalette palette(QPalette::Base, Qt::white);
ui->identifiersLineEdit->setPalette(palette);
updateBootLog(true);
}

Expand Down Expand Up @@ -376,7 +437,10 @@ void ShowBootLog::on_clearButton_clicked()
{
ui->acceptedIdentifierLabel->setText("");
ui->identifiersLineEdit->clear();
QPalette palette(QPalette::Base, Qt::white);
ui->identifiersLineEdit->setPalette(palette);
this->acceptedIdentifiers.clear();
this->acceptedIdentifiersColors.clear();
updateBootLog(false);
}

Expand All @@ -401,3 +465,15 @@ void ShowBootLog::on_exportSelectionButton_clicked()
writeToExportFile(fileName, selection.toLocal8Bit().data());
}

void ShowBootLog::on_selectColorButton_clicked()
{
QColor color = QColorDialog::getColor(QColor::fromRgb(QRandomGenerator::global()->generate()), this );
QPalette palette;
palette.setColor(QPalette::Base, color);
if( color.isValid() )
{
qDebug() << "Color Choosen : " << color.name();
ui->identifiersLineEdit->setPalette(palette);
}

}
13 changes: 10 additions & 3 deletions src/showbootlog.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ private slots:

void on_untilDateTimeEdit_dateTimeChanged();

void on_remoteFilterCheckBox_clicked();

void on_horizontalSlider_sliderMoved(int position);

void appendToBootLog(QString readString);
Expand All @@ -64,11 +66,15 @@ private slots:

void on_exportSelectionButton_clicked();

void on_horizontalSlider_valueChanged(int value);
void on_horizontalSlider_valueChanged(int value);

void on_selectColorButton_clicked();

private:
void updateBootLog(bool keepIdentifiers=false);

void appendLineWithFilterStyle(QString line);

Ui::ShowBootLog *ui;
Connection *connection;

Expand All @@ -83,8 +89,9 @@ private slots:
// Internal display variables
int numberOfBytesRead=0;
QString identifierFlags="";
QSet<QString> allIdentifiers;
QSet<QString> acceptedIdentifiers;
QSet<QString> allIdentifiers;
QSet<QString> acceptedIdentifiers;
QMap<QString, QColor> acceptedIdentifiersColors;

void execute_find(QRegExp regexp, QTextDocument::FindFlags findFlags);
void execute_find(QString string, QTextDocument::FindFlags findFlags);
Expand Down
20 changes: 20 additions & 0 deletions ui/showbootlog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,16 @@
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="selectColorButton">
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="text">
<string>Set Color</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="filterButton">
<property name="focusPolicy">
Expand All @@ -253,6 +263,16 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="remoteFilterCheckBox">
<property name="text">
<string>Remote Filter</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="clearButton">
<property name="focusPolicy">
Expand Down