#include "mainwindow.h" #include "./ui_mainwindow.h" #include #include "networkthread.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { 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(json)), current_session, SLOT (saveRequest(json))); connect(worker, SIGNAL (httpMessage(json)), this, SLOT (updateHistory(json))); thread->start(); ui->setupUi(this); ui->historyHTTPTable->setShowGrid(true); ui->historyHTTPTable->setEditTriggers(QAbstractItemView::NoEditTriggers); ui->historyHTTPTable->setColumnCount(4); ui->historyHTTPTable->setRowCount(1); /* ui->historyHTTPTable->setItem(0,0,new QTableWidgetItem(QString::number(data.index))); ui->historyHTTPTable->setItem(0,1,new QTableWidgetItem(QString::fromStdString(data.method))); ui->historyHTTPTable->setItem(0,2,new QTableWidgetItem(QString::fromStdString(data.url))); ui->historyHTTPTable->setItem(0,3,new QTableWidgetItem(QString::number(data.ttl))); ui->historyHTTPTable->horizontalHeader()->resizeSections(QHeaderView::ResizeToContents); */ } MainWindow::~MainWindow() { delete ui; } void MainWindow::updateHistory(json data) { ui->historyHTTPTable->setItem(0,0,new QTableWidgetItem(QString::fromStdString(data["id"]))); // ui->historyHTTPTable->setItem(0,1,new QTableWidgetItem(QString::fromStdString(data.method))); // ui->historyHTTPTable->setItem(0,2,new QTableWidgetItem(QString::fromStdString(data.url))); // ui->historyHTTPTable->setItem(0,3,new QTableWidgetItem(QString::number(data.ttl))); ui->historyHTTPTable->horizontalHeader()->resizeSections(QHeaderView::ResizeToContents); }