bigsnitch/mainwindow.cpp

62 lines
2.3 KiB
C++
Raw Normal View History

2020-08-05 00:08:41 +00:00
#include "mainwindow.h"
2020-08-26 18:58:36 +00:00
#include <historymodel.h>
2020-08-05 00:08:41 +00:00
#include "./ui_mainwindow.h"
#include <QtGui>
2020-08-09 12:07:14 +00:00
#include "networkthread.h"
2020-08-05 00:08:41 +00:00
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent),
ui(new Ui::MainWindow)
{
2020-08-13 03:35:22 +00:00
int metatype_id = qRegisterMetaType<http::Flow>("httpflow");
2020-08-09 12:07:14 +00:00
current_session = new Session();
current_session->load("/tmp/littlesnitch.session");
2020-08-05 00:08:41 +00:00
thread = new QThread;
2020-08-09 12:07:14 +00:00
NetworkThread* worker = new NetworkThread();
2020-08-05 00:08:41 +00:00
worker->moveToThread(thread);
connect(thread, SIGNAL (started()), worker, SLOT (process()));
2020-08-09 12:07:14 +00:00
//connect(worker, SIGNAL (error(QString)), this, SLOT (errorString(QString)));
connect(worker, SIGNAL (httpMessage(http::Flow)), current_session, SLOT (saveFlow(http::Flow)), Qt::QueuedConnection);
2020-08-14 01:37:33 +00:00
connect(worker, SIGNAL (httpMessage(http::Flow)), this, SLOT (updateHistory()), Qt::QueuedConnection);
2020-08-05 00:08:41 +00:00
thread->start();
2020-08-26 18:58:36 +00:00
history_model.update(current_session->getHistoryItems());
2020-08-28 23:09:41 +00:00
history_proxy.setSourceModel(&history_model);
2020-08-26 18:58:36 +00:00
2020-08-05 00:08:41 +00:00
ui->setupUi(this);
ui->historyHTTPTable->setShowGrid(true);
ui->historyHTTPTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
2020-08-28 23:09:41 +00:00
ui->historyHTTPTable->setModel(&history_proxy);
2020-09-01 20:14:49 +00:00
connect(ui->historyHTTPTable->selectionModel(), SIGNAL (selectionChanged(QItemSelection, QItemSelection)), this, SLOT (on_selectionChange(QItemSelection)));
2020-08-05 00:08:41 +00:00
}
MainWindow::~MainWindow()
{
delete ui;
}
2020-08-14 01:37:33 +00:00
void MainWindow::updateHistory() {
2020-08-26 18:58:36 +00:00
history_model.update(current_session->getHistoryItems());
2020-09-01 12:55:49 +00:00
history_proxy.invalidate();
ui->historyHTTPTable->horizontalHeader()->resizeSections(QHeaderView::ResizeToContents);
2020-08-14 01:37:33 +00:00
}
2020-09-01 20:14:49 +00:00
void MainWindow::on_selectionChange(const QItemSelection &selection)
2020-08-14 01:37:33 +00:00
{
2020-09-01 20:14:49 +00:00
if(!selection.indexes().isEmpty()) {
2020-09-02 22:23:37 +00:00
auto index = selection.indexes().at(7);
2020-09-02 22:33:17 +00:00
ui->plainTextEdit->setPlainText(history_proxy.data(index).toString());
2020-09-02 22:23:37 +00:00
index = selection.indexes().at(8);
2020-09-02 22:33:17 +00:00
ui->plainTextEdit_2->setPlainText(history_proxy.data(index).toString());
2020-09-02 22:23:37 +00:00
index = selection.indexes().at(9);
2020-09-02 22:33:17 +00:00
ui->plainTextEdit_3->setPlainText(history_proxy.data(index).toString());
2020-09-02 22:23:37 +00:00
index = selection.indexes().at(10);
2020-09-02 22:33:17 +00:00
ui->plainTextEdit_4->setPlainText(history_proxy.data(index).toString());
2020-09-01 20:14:49 +00:00
}
2020-08-05 00:08:41 +00:00
}
2020-08-26 18:58:36 +00:00
2020-09-01 20:14:49 +00:00
void MainWindow::on_searchEdit_textEdited(const QString &arg1)
2020-08-26 18:58:36 +00:00
{
}