2020-08-05 00:08:41 +00:00
|
|
|
#include "mainwindow.h"
|
2020-08-26 18:58:36 +00:00
|
|
|
#include <historymodel.h>
|
2020-08-05 00:08:41 +00:00
|
|
|
#include "./ui_mainwindow.h"
|
|
|
|
#include <QtGui>
|
2020-08-09 12:07:14 +00:00
|
|
|
#include "networkthread.h"
|
2020-08-05 00:08:41 +00:00
|
|
|
|
|
|
|
MainWindow::MainWindow(QWidget *parent)
|
|
|
|
: QMainWindow(parent),
|
|
|
|
ui(new Ui::MainWindow)
|
|
|
|
{
|
2021-01-01 20:22:03 +00:00
|
|
|
qRegisterMetaType<http::Flow>("httpflow");
|
2020-08-09 12:07:14 +00:00
|
|
|
current_session = new Session();
|
|
|
|
current_session->load("/tmp/littlesnitch.session");
|
|
|
|
|
2020-08-05 00:08:41 +00:00
|
|
|
thread = new QThread;
|
2020-08-09 12:07:14 +00:00
|
|
|
NetworkThread* worker = new NetworkThread();
|
2020-08-05 00:08:41 +00:00
|
|
|
worker->moveToThread(thread);
|
|
|
|
connect(thread, SIGNAL (started()), worker, SLOT (process()));
|
2020-08-09 12:07:14 +00:00
|
|
|
//connect(worker, SIGNAL (error(QString)), this, SLOT (errorString(QString)));
|
2020-08-18 13:13:45 +00:00
|
|
|
connect(worker, SIGNAL (httpMessage(http::Flow)), current_session, SLOT (saveFlow(http::Flow)), Qt::QueuedConnection);
|
2020-08-14 01:37:33 +00:00
|
|
|
connect(worker, SIGNAL (httpMessage(http::Flow)), this, SLOT (updateHistory()), Qt::QueuedConnection);
|
2020-08-05 00:08:41 +00:00
|
|
|
thread->start();
|
|
|
|
|
2020-08-26 18:58:36 +00:00
|
|
|
history_model.update(current_session->getHistoryItems());
|
2020-08-28 23:09:41 +00:00
|
|
|
history_proxy.setSourceModel(&history_model);
|
2020-08-26 18:58:36 +00:00
|
|
|
|
2020-08-05 00:08:41 +00:00
|
|
|
ui->setupUi(this);
|
|
|
|
ui->historyHTTPTable->setShowGrid(true);
|
|
|
|
ui->historyHTTPTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
2020-08-28 23:09:41 +00:00
|
|
|
ui->historyHTTPTable->setModel(&history_proxy);
|
2020-09-01 20:14:49 +00:00
|
|
|
connect(ui->historyHTTPTable->selectionModel(), SIGNAL (selectionChanged(QItemSelection, QItemSelection)), this, SLOT (on_selectionChange(QItemSelection)));
|
2021-01-01 20:22:03 +00:00
|
|
|
|
|
|
|
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());
|
2020-08-05 00:08:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MainWindow::~MainWindow()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
2021-01-01 20:22:03 +00:00
|
|
|
void MainWindow::openEditAndResend() {
|
|
|
|
auto wnd = new EditAndResend(current_selection, this);
|
|
|
|
wnd->show();
|
|
|
|
}
|
2020-08-14 01:37:33 +00:00
|
|
|
void MainWindow::updateHistory() {
|
2020-08-26 18:58:36 +00:00
|
|
|
history_model.update(current_session->getHistoryItems());
|
2020-09-01 12:55:49 +00:00
|
|
|
history_proxy.invalidate();
|
2020-08-18 13:13:45 +00:00
|
|
|
ui->historyHTTPTable->horizontalHeader()->resizeSections(QHeaderView::ResizeToContents);
|
2020-08-14 01:37:33 +00:00
|
|
|
}
|
|
|
|
|
2021-01-01 20:22:03 +00:00
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
2020-09-01 20:14:49 +00:00
|
|
|
void MainWindow::on_selectionChange(const QItemSelection &selection)
|
2020-08-14 01:37:33 +00:00
|
|
|
{
|
2020-09-01 20:14:49 +00:00
|
|
|
if(!selection.indexes().isEmpty()) {
|
2020-09-02 22:23:37 +00:00
|
|
|
auto index = selection.indexes().at(7);
|
2021-01-01 20:22:03 +00:00
|
|
|
auto requestHeader = history_proxy.data(index).toString();
|
2020-09-02 22:23:37 +00:00
|
|
|
index = selection.indexes().at(8);
|
2021-01-01 20:22:03 +00:00
|
|
|
auto requestData = history_proxy.data(index).toString();
|
2020-09-02 22:23:37 +00:00
|
|
|
index = selection.indexes().at(9);
|
2021-01-01 20:22:03 +00:00
|
|
|
auto responseHeader = history_proxy.data(index).toString();
|
2020-09-02 22:23:37 +00:00
|
|
|
index = selection.indexes().at(10);
|
2021-01-01 20:22:03 +00:00
|
|
|
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);
|
2020-09-01 20:14:49 +00:00
|
|
|
}
|
2020-08-05 00:08:41 +00:00
|
|
|
}
|
2020-08-26 18:58:36 +00:00
|
|
|
|
2020-09-01 20:14:49 +00:00
|
|
|
void MainWindow::on_searchEdit_textEdited(const QString &arg1)
|
2020-08-26 18:58:36 +00:00
|
|
|
{
|
|
|
|
}
|