#include "mainwindow.h" #include #include "./ui_mainwindow.h" #include MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { qRegisterMetaType("httpflow"); current_session = new Session(); // TODO: make configurable current_session->load("/tmp/littlesnitch.session"); // TODO: use relative paths plugin_handler.loadPlugins(QDir("/home/end/projects/bigsnitch/build/plugins/")); // TODO: fix error string //QObject::connect(plugin_handler, SIGNAL (proxy_error(QString)), this, SLOT ( errorString(QString)), Qt::QueuedConnection); QObject::connect(&plugin_handler, SIGNAL (proxy_message(http::Flow)), this, SLOT (updateHistory()), Qt::QueuedConnection); QObject::connect(&plugin_handler, SIGNAL (proxy_message(http::Flow)), current_session, SLOT (saveFlow(http::Flow)), Qt::QueuedConnection); history_model.update(current_session->getHistoryItems()); history_proxy.setSourceModel(&history_model); ui->setupUi(this); ui->historyHTTPTable->setShowGrid(true); 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() { 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); auto requestHeader = history_proxy.data(index).toString(); index = selection.indexes().at(8); auto requestData = history_proxy.data(index).toString(); index = selection.indexes().at(9); auto responseHeader = history_proxy.data(index).toString(); index = selection.indexes().at(10); 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); } } void MainWindow::on_searchEdit_textEdited(const QString &arg1) { }