edit and resend begun

This commit is contained in:
Tim Blume 2021-01-01 21:22:03 +01:00
parent 739a6b7e06
commit 18ca397589
7 changed files with 102 additions and 18 deletions

View file

@ -1,11 +1,18 @@
#include "editandresend.h"
#include "ui_editandresend.h"
EditAndResend::EditAndResend(QWidget *parent) :
EditAndResend::EditAndResend(std::tuple<QString, QString, QString, QString> initial, QWidget *parent) :
QDialog(parent),
ui(new Ui::EditAndResend)
{
ui->setupUi(this);
auto [requestHeader, requestData, responseHeader, responseData] = initial;
ui->requestHeaderEdit->setPlainText(requestHeader);
ui->requestDataEdit->setPlainText(requestData);
ui->responseHeaderEdit->setPlainText(responseHeader);
ui->responseDataEdit->setPlainText(responseData);
}
EditAndResend::~EditAndResend()

View file

@ -11,7 +11,7 @@ class EditAndResend : public QDialog
Q_OBJECT
public:
explicit EditAndResend(QWidget *parent = nullptr);
explicit EditAndResend(std::tuple<QString, QString, QString, QString> initial, QWidget *parent = nullptr);
~EditAndResend();
private:

View file

@ -46,7 +46,7 @@
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<widget class="QPushButton" name="pushButton">
<widget class="QPushButton" name="sendButton">
<property name="geometry">
<rect>
<x>730</x>
@ -56,7 +56,7 @@
</rect>
</property>
<property name="text">
<string>PushButton</string>
<string>Send</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_2">
@ -137,8 +137,8 @@
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<widget class="QPlainTextEdit" name="plainTextEdit"/>
<widget class="QPlainTextEdit" name="plainTextEdit_3"/>
<widget class="QPlainTextEdit" name="requestHeaderEdit"/>
<widget class="QPlainTextEdit" name="requestDataEdit"/>
</widget>
<widget class="QSplitter" name="splitter">
<property name="sizePolicy">
@ -150,8 +150,8 @@
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<widget class="QPlainTextEdit" name="plainTextEdit_2"/>
<widget class="QPlainTextEdit" name="plainTextEdit_4"/>
<widget class="QPlainTextEdit" name="responseHeaderEdit"/>
<widget class="QPlainTextEdit" name="responseDataEdit"/>
</widget>
</widget>
</item>

View file

@ -4,6 +4,7 @@
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();

View file

@ -8,7 +8,7 @@ MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent),
ui(new Ui::MainWindow)
{
int metatype_id = qRegisterMetaType<http::Flow>("httpflow");
qRegisterMetaType<http::Flow>("httpflow");
current_session = new Session();
current_session->load("/tmp/littlesnitch.session");
@ -29,6 +29,23 @@ MainWindow::MainWindow(QWidget *parent)
ui->historyHTTPTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
ui->historyHTTPTable->setModel(&history_proxy);
connect(ui->historyHTTPTable->selectionModel(), SIGNAL (selectionChanged(QItemSelection, QItemSelection)), this, SLOT (on_selectionChange(QItemSelection)));
ui->historyHTTPTable->setContextMenuPolicy(Qt::CustomContextMenu);
ui->requestHeaderEdit->setContextMenuPolicy(Qt::CustomContextMenu);
ui->requestDataEdit->setContextMenuPolicy(Qt::CustomContextMenu);
ui->responseHeaderEdit->setContextMenuPolicy(Qt::CustomContextMenu);
ui->responseDataEdit->setContextMenuPolicy(Qt::CustomContextMenu);
connect(ui->historyHTTPTable, SIGNAL(customContextMenuRequested(QPoint)), SLOT(historyMenuRequested(QPoint)));
connect(ui->requestHeaderEdit, SIGNAL(customContextMenuRequested(QPoint)), SLOT(editMenuRequested(QPoint)));
connect(ui->requestDataEdit, SIGNAL(customContextMenuRequested(QPoint)), SLOT(edit2MenuRequested(QPoint)));
connect(ui->responseHeaderEdit, SIGNAL(customContextMenuRequested(QPoint)), SLOT(edit3MenuRequested(QPoint)));
connect(ui->responseDataEdit, SIGNAL(customContextMenuRequested(QPoint)), SLOT(edit4MenuRequested(QPoint)));
editAndResendMenu = new QAction("Edit and Resend", this);
connect(editAndResendMenu, &QAction::triggered, this, &MainWindow::openEditAndResend);
updateHistory();
std::make_tuple(QString(), QString(), QString(), QString());
}
MainWindow::~MainWindow()
@ -36,23 +53,69 @@ MainWindow::~MainWindow()
delete ui;
}
void MainWindow::openEditAndResend() {
auto wnd = new EditAndResend(current_selection, this);
wnd->show();
}
void MainWindow::updateHistory() {
history_model.update(current_session->getHistoryItems());
history_proxy.invalidate();
ui->historyHTTPTable->horizontalHeader()->resizeSections(QHeaderView::ResizeToContents);
}
void MainWindow::editMenuRequested(QPoint pos)
{
QMenu *menu=new QMenu(this);
menu->addAction(editAndResendMenu);
menu->popup(ui->requestHeaderEdit->viewport()->mapToGlobal(pos));
}
void MainWindow::edit2MenuRequested(QPoint pos)
{
QMenu *menu=new QMenu(this);
menu->addAction(editAndResendMenu);
menu->popup(ui->requestDataEdit->viewport()->mapToGlobal(pos));
}
void MainWindow::edit3MenuRequested(QPoint pos)
{
QMenu *menu=new QMenu(this);
menu->addAction(editAndResendMenu);
menu->popup(ui->responseHeaderEdit->viewport()->mapToGlobal(pos));
}
void MainWindow::edit4MenuRequested(QPoint pos)
{
QMenu *menu=new QMenu(this);
menu->addAction(editAndResendMenu);
menu->popup(ui->responseDataEdit->viewport()->mapToGlobal(pos));
}
void MainWindow::historyMenuRequested(QPoint pos)
{
QMenu *menu=new QMenu(this);
menu->addAction(editAndResendMenu);
menu->popup(ui->historyHTTPTable->viewport()->mapToGlobal(pos));
}
void MainWindow::on_selectionChange(const QItemSelection &selection)
{
if(!selection.indexes().isEmpty()) {
auto index = selection.indexes().at(7);
ui->plainTextEdit->setPlainText(history_proxy.data(index).toString());
auto requestHeader = history_proxy.data(index).toString();
index = selection.indexes().at(8);
ui->plainTextEdit_2->setPlainText(history_proxy.data(index).toString());
auto requestData = history_proxy.data(index).toString();
index = selection.indexes().at(9);
ui->plainTextEdit_3->setPlainText(history_proxy.data(index).toString());
auto responseHeader = history_proxy.data(index).toString();
index = selection.indexes().at(10);
ui->plainTextEdit_4->setPlainText(history_proxy.data(index).toString());
auto responseData = history_proxy.data(index).toString();
ui->requestHeaderEdit->setPlainText(requestHeader);
ui->requestDataEdit->setPlainText(requestData);
ui->responseHeaderEdit->setPlainText(responseHeader);
ui->responseDataEdit->setPlainText(responseData);
current_selection = std::make_tuple(requestHeader, requestData, responseHeader, responseData);
}
}

View file

@ -22,11 +22,24 @@ private:
Session* current_session;
HistoryModel history_model;
HistoryProxyModel history_proxy;
QAction* editAndResendMenu;
QAction* hideHistoryColumn;
QAction* showHistoryColumn;
// hack for supplying the initial data to edit&resend
std::tuple<QString, QString, QString, QString> current_selection;
public:
MainWindow(QWidget *parent = nullptr);
~MainWindow();
void openEditAndResend();
public slots:
void updateHistory();
void editMenuRequested(QPoint pos);
void edit2MenuRequested(QPoint pos);
void edit3MenuRequested(QPoint pos);
void edit4MenuRequested(QPoint pos);
void historyMenuRequested(QPoint pos);
private slots:
void on_selectionChange(const QItemSelection& selection);
void on_searchEdit_textEdited(const QString &arg1);

View file

@ -135,7 +135,7 @@
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<widget class="QPlainTextEdit" name="plainTextEdit">
<widget class="QPlainTextEdit" name="requestHeaderEdit">
<property name="minimumSize">
<size>
<width>100</width>
@ -151,7 +151,7 @@
<bool>true</bool>
</property>
</widget>
<widget class="QPlainTextEdit" name="plainTextEdit_2">
<widget class="QPlainTextEdit" name="requestDataEdit">
<property name="font">
<font>
<family>DejaVu Sans Mono</family>
@ -166,7 +166,7 @@
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<widget class="QPlainTextEdit" name="plainTextEdit_3">
<widget class="QPlainTextEdit" name="responseHeaderEdit">
<property name="font">
<font>
<family>DejaVu Sans Mono</family>
@ -176,7 +176,7 @@
<bool>true</bool>
</property>
</widget>
<widget class="QPlainTextEdit" name="plainTextEdit_4">
<widget class="QPlainTextEdit" name="responseDataEdit">
<property name="font">
<font>
<family>DejaVu Sans Mono</family>
@ -353,7 +353,7 @@
<x>0</x>
<y>0</y>
<width>818</width>
<height>22</height>
<height>20</height>
</rect>
</property>
<widget class="QMenu" name="menuFile">