bigsnitch/mainwindow.cpp
2020-09-03 00:23:37 +02:00

61 lines
2.2 KiB
C++

#include "mainwindow.h"
#include <historymodel.h>
#include "./ui_mainwindow.h"
#include <QtGui>
#include "networkthread.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent),
ui(new Ui::MainWindow)
{
int metatype_id = qRegisterMetaType<http::Flow>("httpflow");
current_session = new Session();
current_session->load("/tmp/littlesnitch.session");
thread = new QThread;
NetworkThread* worker = new NetworkThread();
worker->moveToThread(thread);
connect(thread, SIGNAL (started()), worker, SLOT (process()));
//connect(worker, SIGNAL (error(QString)), this, SLOT (errorString(QString)));
connect(worker, SIGNAL (httpMessage(http::Flow)), current_session, SLOT (saveFlow(http::Flow)), Qt::QueuedConnection);
connect(worker, SIGNAL (httpMessage(http::Flow)), this, SLOT (updateHistory()), Qt::QueuedConnection);
thread->start();
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)));
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::updateHistory() {
history_model.update(current_session->getHistoryItems());
history_proxy.invalidate();
ui->historyHTTPTable->horizontalHeader()->resizeSections(QHeaderView::ResizeToContents);
}
void MainWindow::on_selectionChange(const QItemSelection &selection)
{
if(!selection.indexes().isEmpty()) {
auto index = selection.indexes().at(7);
ui->textEdit->setText(history_proxy.data(index).toString());
index = selection.indexes().at(8);
ui->textEdit_2->setText(history_proxy.data(index).toString());
index = selection.indexes().at(9);
ui->textEdit_3->setText(history_proxy.data(index).toString());
index = selection.indexes().at(10);
ui->textEdit_4->setText(history_proxy.data(index).toString());
}
}
void MainWindow::on_searchEdit_textEdited(const QString &arg1)
{
}