triage: add options 'show 100 random results' and 'version'

This commit is contained in:
Daniel Marjamäki 2019-03-09 11:01:22 +01:00
parent f36ca56e7d
commit 5915fd50a5
3 changed files with 122 additions and 11 deletions

View File

@ -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);

View File

@ -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

View File

@ -51,6 +51,40 @@
<item>
<widget class="QListWidget" name="results"/>
</item>
<item>
<widget class="QCheckBox" name="random100">
<property name="text">
<string>Show 100 random results</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>Version</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="version"/>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</item>
<item>
@ -96,7 +130,7 @@
<x>0</x>
<y>0</y>
<width>1057</width>
<height>21</height>
<height>25</height>
</rect>
</property>
</widget>
@ -168,10 +202,44 @@
</hint>
</hints>
</connection>
<connection>
<sender>version</sender>
<signal>currentIndexChanged(QString)</signal>
<receiver>MainWindow</receiver>
<slot>filter(QString)</slot>
<hints>
<hint type="sourcelabel">
<x>98</x>
<y>489</y>
</hint>
<hint type="destinationlabel">
<x>493</x>
<y>39</y>
</hint>
</hints>
</connection>
<connection>
<sender>random100</sender>
<signal>clicked()</signal>
<receiver>MainWindow</receiver>
<slot>refreshResults()</slot>
<hints>
<hint type="sourcelabel">
<x>30</x>
<y>464</y>
</hint>
<hint type="destinationlabel">
<x>3</x>
<y>460</y>
</hint>
</hints>
</connection>
</connections>
<slots>
<slot>loadFile()</slot>
<slot>showResult(QListWidgetItem*)</slot>
<slot>loadFromClipboard()</slot>
<slot>filter(QString)</slot>
<slot>refreshResults()</slot>
</slots>
</ui>