bigsnitch/mainwindow.cpp
2020-08-26 20:58:36 +02:00

49 lines
1.5 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());
ui->setupUi(this);
ui->historyHTTPTable->setShowGrid(true);
ui->historyHTTPTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
ui->historyHTTPTable->setModel(&history_model);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::updateHistory() {
history_model.update(current_session->getHistoryItems());
ui->historyHTTPTable->horizontalHeader()->resizeSections(QHeaderView::ResizeToContents);
}
void MainWindow::on_searchEdit_textEdited(const QString &arg1)
{
emit updateHistory();
}
void MainWindow::on_historyHTTPTable_cellClicked(int row, int column)
{
}