73 lines
3.2 KiB
C++
73 lines
3.2 KiB
C++
#include "mainwindow.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();
|
|
|
|
ui->setupUi(this);
|
|
ui->historyHTTPTable->setShowGrid(true);
|
|
ui->historyHTTPTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
|
ui->historyHTTPTable->setColumnCount(7);
|
|
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() {
|
|
int i = 0;
|
|
auto items = current_session->getHistoryItems();
|
|
for(auto& item : *items) {
|
|
ui->historyHTTPTable->setRowCount(i+1);
|
|
int j = 0;
|
|
ui->historyHTTPTable->setItem(i,j++,new QTableWidgetItem(QString::number(item.id)));
|
|
QDateTime timestamp;
|
|
timestamp.setTime_t(item.timestamp);
|
|
ui->historyHTTPTable->setItem(i,j++,new QTableWidgetItem(timestamp.toString(Qt::SystemLocaleShortDate)));
|
|
std::string url = item.scheme + "://" + item.host + ":" + std::to_string(item.port) + item.path;
|
|
ui->historyHTTPTable->setItem(i,j++,new QTableWidgetItem(QString::fromStdString(url)));
|
|
ui->historyHTTPTable->setItem(i,j++,new QTableWidgetItem(item.status_code));
|
|
ui->historyHTTPTable->setItem(i,j++,new QTableWidgetItem(QString::fromStdString(item.reason)));
|
|
ui->historyHTTPTable->setItem(i,j++,new QTableWidgetItem(item.rtt));
|
|
ui->historyHTTPTable->setItem(i,j++,new QTableWidgetItem(item.size));
|
|
i++;
|
|
}
|
|
delete items;
|
|
//ui->historyHTTPTable->setItem(0,0,new QTableWidgetItem(QString::fromStdString(flow.request.server_conn_id)));
|
|
//ui->historyHTTPTable->setItem(0,1,new QTableWidgetItem(QString::fromStdString(flow.request.method)));
|
|
//ui->historyHTTPTable->setItem(0,2,new QTableWidgetItem(QString::fromStdString(flow.request.host)));
|
|
//ui->historyHTTPTable->setItem(0,3,new QTableWidgetItem(QString::number(data.ttl)));
|
|
ui->historyHTTPTable->horizontalHeader()->resizeSections(QHeaderView::ResizeToContents);
|
|
}
|
|
|
|
void MainWindow::on_searchEdit_textEdited(const QString &arg1)
|
|
{
|
|
emit updateHistory();
|
|
}
|