bigsnitch/mainwindow.cpp
Tim Blume c4c82988ca foo
2020-09-03 00:33:17 +02:00

61 lines
2.3 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->plainTextEdit->setPlainText(history_proxy.data(index).toString());
index = selection.indexes().at(8);
ui->plainTextEdit_2->setPlainText(history_proxy.data(index).toString());
index = selection.indexes().at(9);
ui->plainTextEdit_3->setPlainText(history_proxy.data(index).toString());
index = selection.indexes().at(10);
ui->plainTextEdit_4->setPlainText(history_proxy.data(index).toString());
}
}
void MainWindow::on_searchEdit_textEdited(const QString &arg1)
{
}