Triage tool usability improvement (#2319)

* gitignore for triage tool

* window header

* Search filename / in files functionallity for triage tool

* small codeclean
This commit is contained in:
Maksim Derbasov 2019-11-01 11:29:00 +03:00 committed by Daniel Marjamäki
parent 3f0ef01154
commit 91a4bcd71e
4 changed files with 250 additions and 3 deletions

6
tools/triage/.gitignore vendored Normal file
View File

@ -0,0 +1,6 @@
moc_*.cpp
moc_*.h
ui_*.h
.qmake.stash
Makefile
triage

View File

@ -5,8 +5,10 @@
#include <QFile>
#include <QTextStream>
#include <QDir>
#include <QDirIterator>
#include <QFileInfo>
#include <QFileDialog>
#include <QMimeDatabase>
#include <ctime>
#include <cstdlib>
@ -25,6 +27,14 @@ MainWindow::MainWindow(QWidget *parent) :
if (!workFolder.exists()) {
workFolder.mkdir(WORK_FOLDER);
}
fsmodel.setRootPath(WORK_FOLDER);
fsmodel.setReadOnly(true);
fsmodel.setFilter(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot);
ui->directoryTree->setModel(&fsmodel);
QHeaderView * header = ui->directoryTree->header();
for(int i = 1; i < header->length(); ++i)
header->hideSection(i);
ui->directoryTree->setRootIndex(fsmodel.index(WORK_FOLDER));
}
MainWindow::~MainWindow()
@ -220,7 +230,11 @@ void MainWindow::showResult(QListWidgetItem *item)
return;
}
}
showSrcFile(fileName, url, lineNumber);
}
void MainWindow::showSrcFile(const QString &fileName, const QString &url, const int lineNumber)
{
// Open file
ui->code->setFocus();
QFile f(fileName);
@ -236,5 +250,59 @@ void MainWindow::showResult(QListWidgetItem *item)
ui->edit1->setText(url);
ui->edit2->setText(fileName);
f.close();
ui->directoryTree->setCurrentIndex(fsmodel.index(fileName));
}
}
void MainWindow::fileTreeFilter(QString str) {
fsmodel.setNameFilters(QStringList{"*" + str + "*"});
fsmodel.setNameFilterDisables(false);
}
void MainWindow::findInFilesClicked() {
ui->tabWidget->setCurrentIndex(1);
ui->inFilesResult->clear();
const QString text = ui->lineEdit->text();
const QStringList filter {
"*.cpp","*.cxx","*.cc","*.c++","*.hpp","*.h","*.hxx","*.hh","*.tpp","*.txx","*.C","*.c","*.cl"
};
QMimeDatabase mimeDatabase;
QDirIterator it(WORK_FOLDER, filter, QDir::AllEntries | QDir::NoSymLinks | QDir::NoDotAndDotDot, QDirIterator::Subdirectories);
while (it.hasNext()) {
const QString fileName = it.next();
const QMimeType mimeType = mimeDatabase.mimeTypeForFile(fileName);
if (mimeType.isValid() && !mimeType.inherits(QStringLiteral("text/plain"))) {
continue;
}
QFile file(fileName);
if (file.open(QIODevice::ReadOnly)) {
QString line;
int lineN = 0;
QTextStream in(&file);
while (!in.atEnd()) {
++lineN;
line = in.readLine();
if (line.contains(text, Qt::CaseInsensitive)) {
ui->inFilesResult->addItem(fileName + ":" + QString::number(lineN));
break;
}
}
}
}
}
void MainWindow::directorytreeDoubleClick() {
showSrcFile(fsmodel.filePath(ui->directoryTree->currentIndex()), "", 1);
}
void MainWindow::searchResultsDoubleClick() {
QString filename = ui->inFilesResult->currentItem()->text();
const auto idx = filename.lastIndexOf(':');
const int line = filename.midRef(idx + 1).toInt();
showSrcFile(filename.left(idx), "", line);
}

View File

@ -5,6 +5,7 @@
#include <QListWidgetItem>
#include <QString>
#include <QTextStream>
#include <QFileSystemModel>
namespace Ui {
class MainWindow;
@ -16,8 +17,8 @@ class MainWindow : public QMainWindow {
public:
explicit MainWindow(QWidget *parent = Q_NULLPTR);
MainWindow(const MainWindow &) = delete;
~MainWindow();
MainWindow &operator=(const MainWindow &) = delete;
~MainWindow();
public slots:
void loadFile();
@ -25,6 +26,10 @@ public slots:
void filter(QString filter);
void showResult(QListWidgetItem *item);
void refreshResults();
void fileTreeFilter(QString str);
void findInFilesClicked();
void directorytreeDoubleClick();
void searchResultsDoubleClick();
private:
Ui::MainWindow *ui;
@ -33,8 +38,10 @@ private:
bool runProcess(const QString &programName, const QStringList & arguments);
bool wget(const QString &url);
bool unpackArchive(const QString &archiveName);
void showSrcFile(const QString &fileName, const QString &url, const int lineNumber);
QStringList mAllErrors;
QFileSystemModel fsmodel;
};
#endif // MAINWINDOW_H

View File

@ -11,7 +11,7 @@
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
<string>daca triage tool</string>
</property>
<widget class="QWidget" name="centralWidget">
<layout class="QHBoxLayout" name="horizontalLayout_2">
@ -122,6 +122,104 @@
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="filesNavigatorLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QLineEdit" name="lineEdit">
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
<property name="placeholderText">
<string>filter</string>
</property>
<property name="clearButtonEnabled">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="inFilesButton">
<property name="text">
<string>In files</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="fsTab">
<attribute name="title">
<string>Filesystem</string>
</attribute>
<widget class="QTreeView" name="directoryTree">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>341</width>
<height>381</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
<property name="itemsExpandable">
<bool>true</bool>
</property>
<attribute name="headerVisible">
<bool>false</bool>
</attribute>
</widget>
</widget>
<widget class="QWidget" name="inFilesTab">
<attribute name="title">
<string>In Files Result</string>
</attribute>
<widget class="QListWidget" name="inFilesResult">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>341</width>
<height>381</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</widget>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<widget class="QMenuBar" name="menuBar">
@ -130,7 +228,7 @@
<x>0</x>
<y>0</y>
<width>1057</width>
<height>25</height>
<height>30</height>
</rect>
</property>
</widget>
@ -234,6 +332,70 @@
</hint>
</hints>
</connection>
<connection>
<sender>lineEdit</sender>
<signal>textChanged(QString)</signal>
<receiver>MainWindow</receiver>
<slot>fileTreeFilter(QString)</slot>
<hints>
<hint type="sourcelabel">
<x>940</x>
<y>275</y>
</hint>
<hint type="destinationlabel">
<x>528</x>
<y>268</y>
</hint>
</hints>
</connection>
<connection>
<sender>inFilesButton</sender>
<signal>clicked()</signal>
<receiver>MainWindow</receiver>
<slot>findInFilesClicked()</slot>
<hints>
<hint type="sourcelabel">
<x>776</x>
<y>68</y>
</hint>
<hint type="destinationlabel">
<x>413</x>
<y>268</y>
</hint>
</hints>
</connection>
<connection>
<sender>directoryTree</sender>
<signal>doubleClicked(QModelIndex)</signal>
<receiver>MainWindow</receiver>
<slot>directorytreeDoubleClick()</slot>
<hints>
<hint type="sourcelabel">
<x>780</x>
<y>314</y>
</hint>
<hint type="destinationlabel">
<x>454</x>
<y>268</y>
</hint>
</hints>
</connection>
<connection>
<sender>inFilesResult</sender>
<signal>doubleClicked(QModelIndex)</signal>
<receiver>MainWindow</receiver>
<slot>searchResultsDoubleClick()</slot>
<hints>
<hint type="sourcelabel">
<x>755</x>
<y>314</y>
</hint>
<hint type="destinationlabel">
<x>454</x>
<y>268</y>
</hint>
</hints>
</connection>
</connections>
<slots>
<slot>loadFile()</slot>
@ -241,5 +403,9 @@
<slot>loadFromClipboard()</slot>
<slot>filter(QString)</slot>
<slot>refreshResults()</slot>
<slot>fileTreeFilter(QString)</slot>
<slot>findInFilesClicked()</slot>
<slot>directorytreeDoubleClick()</slot>
<slot>searchResultsDoubleClick()</slot>
</slots>
</ui>