This commit is contained in:
Tim Blume 2020-08-29 01:09:41 +02:00
parent ea0a5e74f2
commit 3b01e35783
10 changed files with 76 additions and 7 deletions

View file

View file

View file

View file

@ -63,16 +63,61 @@ QVariant HistoryModel::data(const QModelIndex &index, int role) const
return QString::number(item.size);
}
}
throw std::out_of_range("history model col");
} catch (std::out_of_range const& exc) {
qDebug() << "historymodel data " << exc.what();
}
return QVariant();
}
QVariant HistoryModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if(role != Qt::DisplayRole) {
return QVariant();
}
if(orientation == Qt::Horizontal) {
switch(section) {
case 0: {
return "id";
}
case 1: {
return "time";
}
case 2: {
return "url";
}
case 3: {
return "code";
}
case 4: {
return "reason";
}
case 5: {
return "rtt";
}
case 6: {
return "size";
}
}
}
return QVariant();
}
void HistoryModel::update(std::vector<HistoryItem> *items)
{
if(current_items) {
delete current_items;
}
current_items = items;
emit layoutChanged();
}
bool HistoryProxyModel::lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const
{
return QSortFilterProxyModel::lessThan(source_left, source_right);
}
bool HistoryProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
{
return true;
}

View file

@ -2,6 +2,7 @@
#include <includes.h>
#include <QAbstractTableModel>
#include <QSortFilterProxyModel>
struct HistoryItem {
int id = -1;
@ -27,5 +28,15 @@ public:
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
void update(std::vector<HistoryItem>* items);
};
class HistoryProxyModel : public QSortFilterProxyModel
{
Q_OBJECT
private:
public:
bool lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const override;
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override;
};

View file

@ -18,16 +18,25 @@ bool json_get(json j, T& value, K key) noexcept {
j[key].get_to(value);
return true;
} catch (nlohmann::detail::type_error& err) {
qDebug() << err.what();
qDebug() << "key " << key << " error " << err.what();
} catch (nlohmann::detail::out_of_range& err) {
qDebug() << err.what();
qDebug() << "key " << key << " error " << err.what();
} catch (nlohmann::detail::other_error& err) {
qDebug() << err.what();
qDebug() << "key " << key << " error " << err.what();
}
return false;
}
template<typename T, typename K, typename... Ks>
bool json_get(json j, T& value, K key, Ks... keys) noexcept {
try {
return json_get(j[key], value, keys...);
} catch (nlohmann::detail::type_error& err) {
qDebug() << "key " << key << " error " << err.what();
} catch (nlohmann::detail::out_of_range& err) {
qDebug() << "key " << key << " error " << err.what();
} catch (nlohmann::detail::other_error& err) {
qDebug() << "key " << key << " error " << err.what();
}
return false;
}

View file

@ -22,11 +22,12 @@ MainWindow::MainWindow(QWidget *parent)
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_model);
ui->historyHTTPTable->setModel(&history_proxy);
}
MainWindow::~MainWindow()

View file

@ -19,6 +19,7 @@ private:
QThread* thread;
Session* current_session;
HistoryModel history_model;
HistoryProxyModel history_proxy;
public:
MainWindow(QWidget *parent = nullptr);
~MainWindow();

View file

@ -134,6 +134,7 @@ std::optional<std::string> Session::getSetting(std::string key) {
}
std::vector<HistoryItem>* Session::getHistoryItems() {
qDebug() << "history items generated";
// todo check reset return code
sqlite3_reset(stmt_get_all_history);
@ -297,6 +298,7 @@ int Session::saveFlow(http::Flow flow) {
return -1;
}
qDebug() << "saved flow";
return sqlite3_last_insert_rowid(db);
}

View file

@ -5,9 +5,9 @@ export mitmpid=$!
./build/littlesnitch &
sleep 5
curl -x http://localhost:1878 -k https://yolo.jetzt
curl -s -x http://localhost:1878 -k https://yolo.jetzt > /dev/null
sleep 2
curl -x http://localhost:1878 -k https://get.yolo.jetzt
curl -s -x http://localhost:1878 -k https://blog.fefe.de > /dev/null
sleep 2
kill -9 $mitmpid