From 5915fd50a5457204bf68e53b3652fb7c7572d460 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 9 Mar 2019 11:01:22 +0100 Subject: [PATCH] triage: add options 'show 100 random results' and 'version' --- tools/triage/mainwindow.cpp | 59 +++++++++++++++++++++++++------ tools/triage/mainwindow.h | 4 +++ tools/triage/mainwindow.ui | 70 ++++++++++++++++++++++++++++++++++++- 3 files changed, 122 insertions(+), 11 deletions(-) diff --git a/tools/triage/mainwindow.cpp b/tools/triage/mainwindow.cpp index 056d7b4c6..7d3e4566d 100644 --- a/tools/triage/mainwindow.cpp +++ b/tools/triage/mainwindow.cpp @@ -12,6 +12,8 @@ const QString WORK_FOLDER(QDir::homePath() + "/triage"); const QString DACA2_PACKAGES(QDir::homePath() + "/daca2-packages"); +const int MAX_ERRORS = 100; + MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) @@ -53,8 +55,8 @@ void MainWindow::load(QTextStream &textStream) { QString url; QString errorMessage; - QStringList allErrors; - ui->results->clear(); + QStringList versions; + mAllErrors.clear(); while (true) { QString line = textStream.readLine(); if (line.isNull()) @@ -62,31 +64,68 @@ void MainWindow::load(QTextStream &textStream) if (line.startsWith("ftp://")) { url = line; if (!errorMessage.isEmpty()) - allErrors << errorMessage; + mAllErrors << errorMessage; errorMessage.clear(); } else if (!url.isEmpty() && QRegExp(".*: (error|warning|style|note):.*").exactMatch(line)) { - if (QRegExp("^(head|1.[0-9][0-9]) .*").exactMatch(line)) - line = line.mid(5); + if (QRegExp("^(head|1.[0-9][0-9]) .*").exactMatch(line)) { + const QString version = line.mid(0,4); + if (versions.indexOf(version) < 0) + versions << version; + } if (line.indexOf(": note:") > 0) errorMessage += '\n' + line; else if (errorMessage.isEmpty()) { errorMessage = url + '\n' + line; } else { - allErrors << errorMessage; + mAllErrors << errorMessage; errorMessage = url + '\n' + line; } } } if (!errorMessage.isEmpty()) - allErrors << errorMessage; - if (allErrors.size() > 100) { + mAllErrors << errorMessage; + + ui->version->clear(); + if (versions.size() > 1) + ui->version->addItem(""); + ui->version->addItems(versions); + + filter(""); +} + +void MainWindow::refreshResults() +{ + filter(ui->version->currentText()); +} + +void MainWindow::filter(QString filter) +{ + QStringList allErrors; + + for (const QString errorItem : mAllErrors) { + if (filter.isEmpty()) { + allErrors << errorItem; + continue; + } + + const QStringList lines = errorItem.split("\n"); + if (lines.size() < 2) + continue; + + if (lines[1].startsWith(filter)) + allErrors << errorItem; + } + + ui->results->clear(); + + if (ui->random100->isChecked() && allErrors.size() > MAX_ERRORS) { // remove items in /test/ - for (int i = allErrors.size()-1; i >= 0 && allErrors.size() > 100; --i) { + for (int i = allErrors.size() - 1; i >= 0 && allErrors.size() > MAX_ERRORS; --i) { if (allErrors[i].indexOf("test") > 0) allErrors.removeAt(i); } std::random_shuffle(allErrors.begin(), allErrors.end()); - ui->results->addItems(allErrors.mid(0,100)); + ui->results->addItems(allErrors.mid(0,MAX_ERRORS)); ui->results->sortItems(); } else { ui->results->addItems(allErrors); diff --git a/tools/triage/mainwindow.h b/tools/triage/mainwindow.h index e382c229c..a4dc45252 100644 --- a/tools/triage/mainwindow.h +++ b/tools/triage/mainwindow.h @@ -22,7 +22,9 @@ public: public slots: void loadFile(); void loadFromClipboard(); + void filter(QString f); void showResult(QListWidgetItem *item); + void refreshResults(); private: Ui::MainWindow *ui; @@ -31,6 +33,8 @@ private: bool runProcess(const QString &programName, const QStringList & arguments); bool wget(const QString &url); bool unpackArchive(const QString &archiveName); + + QStringList mAllErrors; }; #endif // MAINWINDOW_H diff --git a/tools/triage/mainwindow.ui b/tools/triage/mainwindow.ui index e7544c955..d3bf5ff52 100644 --- a/tools/triage/mainwindow.ui +++ b/tools/triage/mainwindow.ui @@ -51,6 +51,40 @@ + + + + Show 100 random results + + + + + + + + + Version + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + @@ -96,7 +130,7 @@ 0 0 1057 - 21 + 25 @@ -168,10 +202,44 @@ + + version + currentIndexChanged(QString) + MainWindow + filter(QString) + + + 98 + 489 + + + 493 + 39 + + + + + random100 + clicked() + MainWindow + refreshResults() + + + 30 + 464 + + + 3 + 460 + + + loadFile() showResult(QListWidgetItem*) loadFromClipboard() + filter(QString) + refreshResults()