diff --git a/src/showbootlog.cpp b/src/showbootlog.cpp index 1082da5..560fd17 100644 --- a/src/showbootlog.cpp +++ b/src/showbootlog.cpp @@ -31,6 +31,8 @@ #include #include #include +#include +#include ShowBootLog::ShowBootLog(QWidget *parent) : QDialog(parent), @@ -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 @@ -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! @@ -182,8 +188,11 @@ 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(); } @@ -191,7 +200,20 @@ void ShowBootLog::acceptIdentifier(void){ 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(); @@ -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() { @@ -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; @@ -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); } @@ -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); } @@ -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); + } + +} diff --git a/src/showbootlog.h b/src/showbootlog.h index 3abb587..5fc6a64 100644 --- a/src/showbootlog.h +++ b/src/showbootlog.h @@ -42,6 +42,8 @@ private slots: void on_untilDateTimeEdit_dateTimeChanged(); + void on_remoteFilterCheckBox_clicked(); + void on_horizontalSlider_sliderMoved(int position); void appendToBootLog(QString readString); @@ -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; @@ -83,8 +89,9 @@ private slots: // Internal display variables int numberOfBytesRead=0; QString identifierFlags=""; - QSet allIdentifiers; - QSet acceptedIdentifiers; + QSet allIdentifiers; + QSet acceptedIdentifiers; + QMap acceptedIdentifiersColors; void execute_find(QRegExp regexp, QTextDocument::FindFlags findFlags); void execute_find(QString string, QTextDocument::FindFlags findFlags); diff --git a/ui/showbootlog.ui b/ui/showbootlog.ui index e7ab0bf..419d527 100644 --- a/ui/showbootlog.ui +++ b/ui/showbootlog.ui @@ -243,6 +243,16 @@ + + + + Qt::NoFocus + + + Set Color + + + @@ -253,6 +263,16 @@ + + + + Remote Filter + + + true + + +